Skip to content

Commit

Permalink
Bug 1839155 - Remove the PREF_PREFIX handling in various PDF Viewer…
Browse files Browse the repository at this point in the history
… files. r=pdfjs-reviewers,calixte

The `PREF_PREFIX` handling is a left-over from years ago, back when we
built an *old-style* Firefox extension in the PDF.js project.
Given that this was removed over five years ago, see
mozilla/pdf.js#9566, we should be able to slightly simplify preference names now.

Differential Revision: https://phabricator.services.mozilla.com/D181370
  • Loading branch information
Snuffleupagus committed Jun 19, 2023
1 parent bb70353 commit 73d88e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
16 changes: 7 additions & 9 deletions toolkit/components/pdfjs/content/PdfJs.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
* limitations under the License.
*/

const PREF_PREFIX = "pdfjs";
const PREF_DISABLED = PREF_PREFIX + ".disabled";
const PREF_MIGRATION_VERSION = PREF_PREFIX + ".migrationVersion";
const PREF_PREVIOUS_ACTION = PREF_PREFIX + ".previousHandler.preferredAction";
const PREF_PREVIOUS_ASK =
PREF_PREFIX + ".previousHandler.alwaysAskBeforeHandling";
const PREF_ISDEFAULT_CACHE_STATE = PREF_PREFIX + ".enabledCache.state";
const PREF_DISABLED = "pdfjs.disabled";
const PREF_MIGRATION_VERSION = "pdfjs.migrationVersion";
const PREF_PREVIOUS_ACTION = "pdfjs.previousHandler.preferredAction";
const PREF_PREVIOUS_ASK = "pdfjs.previousHandler.alwaysAskBeforeHandling";
const PREF_ISDEFAULT_CACHE_STATE = "pdfjs.enabledCache.state";
const TOPIC_PDFJS_HANDLER_CHANGED = "pdfjs:handlerChanged";
const PDF_CONTENT_TYPE = "application/pdf";

Expand All @@ -44,7 +42,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
});

function initializeDefaultPreferences() {
var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + ".");
var defaultBranch = Services.prefs.getDefaultBranch("pdfjs.");
var defaultValue;
for (var key in lazy.PdfJsDefaultPreferences) {
// Skip prefs that are already defined, so we can enable/disable things
Expand Down Expand Up @@ -142,7 +140,7 @@ export var PdfJs = {
}
if (currentVersion < 2) {
// cleaning up of unused database preference (see #3994)
Services.prefs.clearUserPref(PREF_PREFIX + ".database");
Services.prefs.clearUserPref("pdfjs.database");
}
Services.prefs.setIntPref(PREF_MIGRATION_VERSION, VERSION);
},
Expand Down
27 changes: 12 additions & 15 deletions toolkit/components/pdfjs/content/PdfStreamConverter.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

const PDFJS_EVENT_ID = "pdf.js.message";
const PREF_PREFIX = "pdfjs";
const PDF_VIEWER_ORIGIN = "resource://pdf.js";
const PDF_VIEWER_WEB_PAGE = "resource://pdf.js/web/viewer.html";
const MAX_NUMBER_OF_PREFS = 50;
Expand Down Expand Up @@ -64,7 +63,7 @@ XPCOMUtils.defineLazyGetter(lazy, "gOurBinary", () => {
});

function log(aMsg) {
if (!Services.prefs.getBoolPref(PREF_PREFIX + ".pdfBugEnabled", false)) {
if (!Services.prefs.getBoolPref("pdfjs.pdfBugEnabled", false)) {
return;
}
var msg = "PdfStreamConverter.js: " + (aMsg.join ? aMsg.join("") : aMsg);
Expand Down Expand Up @@ -222,7 +221,7 @@ class ChromeActions {
return res;
}

if (!Services.prefs.getBoolPref(PREF_PREFIX + ".enableScripting", false)) {
if (!Services.prefs.getBoolPref("pdfjs.enableScripting", false)) {
return sendResp(false);
}

Expand Down Expand Up @@ -457,9 +456,8 @@ class ChromeActions {
}

setPreferences(prefs, sendResponse) {
var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + ".");
var defaultBranch = Services.prefs.getDefaultBranch("pdfjs.");
var numberOfPrefs = 0;
var prefValue, prefName;
for (var key in prefs) {
if (++numberOfPrefs > MAX_NUMBER_OF_PREFS) {
log(
Expand All @@ -470,8 +468,8 @@ class ChromeActions {
} else if (!defaultBranch.getPrefType(key)) {
continue;
}
prefValue = prefs[key];
prefName = PREF_PREFIX + "." + key;
const prefName = `pdfjs.${key}`,
prefValue = prefs[key];
switch (typeof prefValue) {
case "boolean":
lazy.AsyncPrefs.set(prefName, prefValue);
Expand All @@ -497,10 +495,9 @@ class ChromeActions {
}

getPreferences(prefs, sendResponse) {
var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + ".");
var defaultBranch = Services.prefs.getDefaultBranch("pdfjs.");
var currentPrefs = {},
numberOfPrefs = 0;
var prefValue, prefName;
for (var key in prefs) {
if (++numberOfPrefs > MAX_NUMBER_OF_PREFS) {
log(
Expand All @@ -511,8 +508,8 @@ class ChromeActions {
} else if (!defaultBranch.getPrefType(key)) {
continue;
}
prefValue = prefs[key];
prefName = PREF_PREFIX + "." + key;
const prefName = `pdfjs.${key}`,
prefValue = prefs[key];
switch (typeof prefValue) {
case "boolean":
currentPrefs[key] = Services.prefs.getBoolPref(prefName, prefValue);
Expand Down Expand Up @@ -983,7 +980,7 @@ PdfStreamConverter.prototype = {
if (
!isPDF ||
!toplevelOctetStream ||
!Services.prefs.getBoolPref(PREF_PREFIX + ".handleOctetStream", false)
!Services.prefs.getBoolPref("pdfjs.handleOctetStream", false)
) {
throw new Components.Exception(
"Ignore PDF.js for this download.",
Expand Down Expand Up @@ -1062,19 +1059,19 @@ PdfStreamConverter.prototype = {

var hash = aRequest.URI.ref;
const isPDFBugEnabled = Services.prefs.getBoolPref(
PREF_PREFIX + ".pdfBugEnabled",
"pdfjs.pdfBugEnabled",
false
);
rangeRequest =
contentEncoding === "identity" &&
acceptRanges === "bytes" &&
aRequest.contentLength >= 0 &&
!Services.prefs.getBoolPref(PREF_PREFIX + ".disableRange", false) &&
!Services.prefs.getBoolPref("pdfjs.disableRange", false) &&
(!isPDFBugEnabled || !hash.toLowerCase().includes("disablerange=true"));
streamRequest =
contentEncoding === "identity" &&
aRequest.contentLength >= 0 &&
!Services.prefs.getBoolPref(PREF_PREFIX + ".disableStream", false) &&
!Services.prefs.getBoolPref("pdfjs.disableStream", false) &&
(!isPDFBugEnabled ||
!hash.toLowerCase().includes("disablestream=true"));
}
Expand Down

0 comments on commit 73d88e1

Please sign in to comment.