Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Firefox] Generate a PDF.js default-prefs file that can be used directly in mozilla-central (bug 1905864) #15209

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions extensions/firefox/.eslintrc

This file was deleted.

18 changes: 0 additions & 18 deletions extensions/firefox/content/PdfJsDefaultPreferences.sys.mjs

This file was deleted.

44 changes: 21 additions & 23 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
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 @@ -1278,26 +1277,31 @@ gulp.task(
)
);

function preprocessDefaultPreferences(content) {
function createDefaultPrefsFile() {
const defaultFileName = "PdfJsDefaultPrefs.js",
overrideFileName = "PdfJsOverridePrefs.js";
const licenseHeader = fs.readFileSync("./src/license_header.js").toString();

const MODIFICATION_WARNING =
"//\n// THIS FILE IS GENERATED AUTOMATICALLY, DO NOT EDIT MANUALLY!\n//\n";
"// THIS FILE IS GENERATED AUTOMATICALLY, DO NOT EDIT MANUALLY!\n//\n" +
`// Any overrides should be placed in \`${overrideFileName}\`.\n`;

const bundleDefines = {
...DEFINES,
DEFAULT_PREFERENCES: getDefaultPreferences("mozcentral/"),
};
const prefs = getDefaultPreferences("mozcentral/");
const buf = [];

content = preprocessPDFJSCode(
{
rootPath: __dirname,
defines: bundleDefines,
},
content
);
for (const name in prefs) {
let value = prefs[name];

return licenseHeader + "\n" + MODIFICATION_WARNING + "\n" + content + "\n";
if (typeof value === "string") {
value = `"${value}"`;
}
buf.push(`pref("pdfjs.${name}", ${value});`);
}
buf.sort();
buf.unshift(licenseHeader, MODIFICATION_WARNING);
buf.push(`\n#include ${overrideFileName}\n`);

return createStringSource(defaultFileName, buf.join("\n"));
}

function replaceMozcentralCSS() {
Expand Down Expand Up @@ -1325,8 +1329,7 @@ gulp.task(
MOZCENTRAL_EXTENSION_DIR = MOZCENTRAL_DIR + "browser/extensions/pdfjs/",
MOZCENTRAL_CONTENT_DIR = MOZCENTRAL_EXTENSION_DIR + "content/",
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 @@ -1401,12 +1404,7 @@ gulp.task(
gulp
.src("LICENSE", { encoding: false })
.pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)),
gulp
.src(FIREFOX_CONTENT_DIR + "PdfJsDefaultPreferences.sys.mjs", {
encoding: false,
})
.pipe(transform("utf8", preprocessDefaultPreferences))
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
createDefaultPrefsFile().pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)),
]);
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/license_header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2023 Mozilla Foundation
/* Copyright 2024 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/license_header_libre.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2023 Mozilla Foundation
* Copyright 2024 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down