From 72645926856ca12cd671d88176dd5128938d9eb3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 22 Jul 2022 11:56:20 +0200 Subject: [PATCH] [Firefox] Generate a default-prefs file that can be used directly in mozilla-central (bug 1780609) --- extensions/firefox/.eslintrc | 22 ----------- .../content/PdfJsDefaultPreferences.sys.mjs | 18 --------- gulpfile.mjs | 37 ++++++++----------- 3 files changed, 16 insertions(+), 61 deletions(-) delete mode 100644 extensions/firefox/.eslintrc delete mode 100644 extensions/firefox/content/PdfJsDefaultPreferences.sys.mjs diff --git a/extensions/firefox/.eslintrc b/extensions/firefox/.eslintrc deleted file mode 100644 index e5ae68046fee78..00000000000000 --- a/extensions/firefox/.eslintrc +++ /dev/null @@ -1,22 +0,0 @@ -{ - // Note: The root .eslintrc file will define the base rules, - // but mozilla/recommended will override them for the rules it sets. Finally, - // the rules in this file will take precedence. - "extends": [ - "plugin:mozilla/recommended", - ], - - "plugins": [ - "mozilla" - ], - - "rules": { - // Other rules mozilla/recommended hasn't enabled yet. - "no-shadow": "error", - "arrow-body-style": ["error", "as-needed"], - "arrow-parens": ["error", "always"], - "constructor-super": "error", - "no-confusing-arrow": "error", - "no-useless-constructor": "error", - }, -} diff --git a/extensions/firefox/content/PdfJsDefaultPreferences.sys.mjs b/extensions/firefox/content/PdfJsDefaultPreferences.sys.mjs deleted file mode 100644 index 738adad80b6da3..00000000000000 --- a/extensions/firefox/content/PdfJsDefaultPreferences.sys.mjs +++ /dev/null @@ -1,18 +0,0 @@ -/* Copyright 2018 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const PdfJsDefaultPreferences = Object.freeze( - PDFJSDev.eval("DEFAULT_PREFERENCES") -); diff --git a/gulpfile.mjs b/gulpfile.mjs index 6cd23af63deecf..8ccf09a313ede6 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -46,7 +46,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/"; @@ -1288,26 +1287,26 @@ gulp.task( ) ); -function preprocessDefaultPreferences(content) { +function createDefaultPrefsFile() { + const fileName = "PdfJsViewerPrefs.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!"; - const bundleDefines = { - ...DEFINES, - DEFAULT_PREFERENCES: getDefaultPreferences("mozcentral/"), - }; + const prefs = getDefaultPreferences("mozcentral/"); + const buf = [licenseHeader]; - 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(MODIFICATION_WARNING, `pref("pdfjs.${name}", ${value});`); + } + + return createStringSource(fileName, buf.join("\n")); } function replaceMozcentralCSS() { @@ -1335,8 +1334,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, @@ -1407,10 +1405,7 @@ gulp.task( gulp.src("l10n/en-US/*.ftl").pipe(gulp.dest(MOZCENTRAL_L10N_DIR)), gulp.src("LICENSE").pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)), - gulp - .src(FIREFOX_CONTENT_DIR + "PdfJsDefaultPreferences.sys.mjs") - .pipe(transform("utf8", preprocessDefaultPreferences)) - .pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)), + createDefaultPrefsFile().pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)), ]); } )