Skip to content

Commit

Permalink
[Firefox] Generate a default-prefs file that can used directly in moz…
Browse files Browse the repository at this point in the history
…illa-central (bug 1780609)
  • Loading branch information
Snuffleupagus committed Jul 22, 2022
1 parent 6138e16 commit b89cd95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 51 deletions.
22 changes: 0 additions & 22 deletions extensions/firefox/content/PdfJsDefaultPreferences.jsm

This file was deleted.

45 changes: 16 additions & 29 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const through = require("through2");
const BUILD_DIR = "build/";
const L10N_DIR = "l10n/";
const TEST_DIR = "test/";
const EXTENSION_SRC_DIR = "extensions/";

const BASELINE_DIR = BUILD_DIR + "baseline/";
const MOZCENTRAL_BASELINE_DIR = BUILD_DIR + "mozcentral.baseline/";
Expand Down Expand Up @@ -1218,35 +1217,27 @@ gulp.task(
)
);

function preprocessDefaultPreferences(content) {
const preprocessor2 = require("./external/builder/preprocessor2.js");
function createDefaultPrefsFile() {
const fileName = "PdfJsViewerPrefs.js";
const licenseHeader = fs.readFileSync("./src/license_header.js").toString();

const GLOBALS = "/* eslint-disable */\n";
const MODIFICATION_WARNING =
"//\n// THIS FILE IS GENERATED AUTOMATICALLY, DO NOT EDIT MANUALLY!\n//\n";

const bundleDefines = builder.merge(DEFINES, {
DEFAULT_PREFERENCES: getDefaultPreferences("mozcentral/"),
});
const prefs = getDefaultPreferences("mozcentral/");
const buf = [];
for (const name in prefs) {
let value = prefs[name];

content = preprocessor2.preprocessPDFJSCode(
{
rootPath: __dirname,
defines: bundleDefines,
},
content
);
if (typeof value === "string") {
value = `"${value}"`;
}
buf.push(`pref("pdfjs.${name}", ${value});`);
}

return (
licenseHeader +
"\n" +
GLOBALS +
"\n" +
MODIFICATION_WARNING +
"\n" +
content +
"\n"
return createStringSource(
fileName,
`${licenseHeader}\n${MODIFICATION_WARNING}\n${buf.join("\n")}\n`
);
}

Expand All @@ -1268,8 +1259,7 @@ gulp.task(
MOZCENTRAL_CONTENT_DIR = MOZCENTRAL_EXTENSION_DIR + "content/",
FIREFOX_EXTENSION_DIR = "extensions/firefox/",
MOZCENTRAL_L10N_DIR =
MOZCENTRAL_DIR + "browser/locales/en-US/pdfviewer/",
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + "/firefox/content/";
MOZCENTRAL_DIR + "browser/locales/en-US/pdfviewer/";

const MOZCENTRAL_WEB_FILES = [
...COMMON_WEB_FILES,
Expand Down Expand Up @@ -1331,10 +1321,7 @@ gulp.task(
.pipe(replace(/\bPDFJSSCRIPT_COMMIT\b/g, commit))
.pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)),
gulp.src("LICENSE").pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)),
gulp
.src(FIREFOX_CONTENT_DIR + "PdfJsDefaultPreferences.jsm")
.pipe(transform("utf8", preprocessDefaultPreferences))
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
createDefaultPrefsFile().pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
]);
}
)
Expand Down

0 comments on commit b89cd95

Please sign in to comment.