[Firefox addon] Refactor bundling of the default_preferences.json
file
This commit is contained in:
parent
6662985a20
commit
76250b923f
@ -49,6 +49,8 @@ ChromeUtils.defineModuleGetter(this, "PdfjsChromeUtils",
|
||||
"resource://pdf.js/PdfjsChromeUtils.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "PdfjsContentUtils",
|
||||
"resource://pdf.js/PdfjsContentUtils.jsm");
|
||||
ChromeUtils.defineModuleGetter(this, "PdfJsDefaultPreferences",
|
||||
"resource://pdf.js/PdfJsDefaultPreferences.jsm");
|
||||
|
||||
function getBoolPref(aPref, aDefaultValue) {
|
||||
try {
|
||||
@ -75,18 +77,10 @@ function isDefaultHandler() {
|
||||
}
|
||||
|
||||
function initializeDefaultPreferences() {
|
||||
/* eslint-disable semi */
|
||||
var DEFAULT_PREFERENCES =
|
||||
//#include ../../../web/default_preferences.json
|
||||
//#if false
|
||||
"end of DEFAULT_PREFERENCES"
|
||||
//#endif
|
||||
/* eslint-enable semi */
|
||||
|
||||
var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + ".");
|
||||
var defaultValue;
|
||||
for (var key in DEFAULT_PREFERENCES) {
|
||||
defaultValue = DEFAULT_PREFERENCES[key];
|
||||
for (var key in PdfJsDefaultPreferences) {
|
||||
defaultValue = PdfJsDefaultPreferences[key];
|
||||
switch (typeof defaultValue) {
|
||||
case "boolean":
|
||||
defaultBranch.setBoolPref(key, defaultValue);
|
||||
|
21
extensions/firefox/content/PdfJsDefaultPreferences.jsm
Normal file
21
extensions/firefox/content/PdfJsDefaultPreferences.jsm
Normal file
@ -0,0 +1,21 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
var EXPORTED_SYMBOLS = ["PdfJsDefaultPreferences"];
|
||||
|
||||
var PdfJsDefaultPreferences =
|
||||
Object.freeze(PDFJSDev.json("$ROOT/web/default_preferences.json"));
|
@ -23,23 +23,18 @@ const PDF_CONTENT_TYPE = "application/pdf";
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
ChromeUtils.defineModuleGetter(this, "PdfJsDefaultPreferences",
|
||||
"resource://pdf.js/PdfJsDefaultPreferences.jsm");
|
||||
|
||||
var Svc = {};
|
||||
XPCOMUtils.defineLazyServiceGetter(Svc, "mime",
|
||||
"@mozilla.org/mime;1",
|
||||
"nsIMIMEService");
|
||||
|
||||
/* eslint-disable semi */
|
||||
var DEFAULT_PREFERENCES =
|
||||
//#include ../../../web/default_preferences.json
|
||||
//#if false
|
||||
"end of DEFAULT_PREFERENCES"
|
||||
//#endif
|
||||
/* eslint-enable semi */
|
||||
|
||||
var PdfjsChromeUtils = {
|
||||
// For security purposes when running remote, we restrict preferences
|
||||
// content can access.
|
||||
_allowedPrefNames: Object.keys(DEFAULT_PREFERENCES),
|
||||
_allowedPrefNames: Object.keys(PdfJsDefaultPreferences),
|
||||
_ppmm: null,
|
||||
_mmg: null,
|
||||
|
||||
|
23
gulpfile.js
23
gulpfile.js
@ -700,6 +700,21 @@ gulp.task('minified-post', ['minified-pre'], function () {
|
||||
|
||||
gulp.task('minified', ['minified-post']);
|
||||
|
||||
function preprocessDefaultPreferences(content) {
|
||||
var preprocessor2 = require('./external/builder/preprocessor2.js');
|
||||
var licenseHeader = fs.readFileSync('./src/license_header.js').toString();
|
||||
|
||||
var MODIFICATION_WARNING =
|
||||
'//\n// THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT MANUALLY!\n//\n';
|
||||
|
||||
content = preprocessor2.preprocessPDFJSCode({
|
||||
rootPath: __dirname,
|
||||
defines: DEFINES,
|
||||
}, content);
|
||||
|
||||
return licenseHeader + '\n' + MODIFICATION_WARNING + '\n' + content;
|
||||
}
|
||||
|
||||
gulp.task('firefox-pre', ['buildnumber', 'locale'], function () {
|
||||
console.log();
|
||||
console.log('### Building Firefox extension');
|
||||
@ -759,6 +774,10 @@ gulp.task('firefox-pre', ['buildnumber', 'locale'], function () {
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_DIR)),
|
||||
gulp.src('LICENSE').pipe(gulp.dest(FIREFOX_BUILD_DIR)),
|
||||
|
||||
gulp.src(FIREFOX_CONTENT_DIR + 'PdfJsDefaultPreferences.jsm')
|
||||
.pipe(transform('utf8', preprocessDefaultPreferences))
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR)),
|
||||
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm', defines, true)
|
||||
.pipe(replace(/\bPDFJSSCRIPT_STREAM_CONVERTER_ID\b/g,
|
||||
FIREFOX_STREAM_CONVERTER_ID))
|
||||
@ -860,6 +879,10 @@ gulp.task('mozcentral-pre', ['buildnumber', 'locale'], function () {
|
||||
.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)),
|
||||
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfJs.jsm', defines, true)
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm', defines, true)
|
||||
|
Loading…
Reference in New Issue
Block a user