[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");
 | 
					                               "resource://pdf.js/PdfjsChromeUtils.jsm");
 | 
				
			||||||
ChromeUtils.defineModuleGetter(this, "PdfjsContentUtils",
 | 
					ChromeUtils.defineModuleGetter(this, "PdfjsContentUtils",
 | 
				
			||||||
                               "resource://pdf.js/PdfjsContentUtils.jsm");
 | 
					                               "resource://pdf.js/PdfjsContentUtils.jsm");
 | 
				
			||||||
 | 
					ChromeUtils.defineModuleGetter(this, "PdfJsDefaultPreferences",
 | 
				
			||||||
 | 
					  "resource://pdf.js/PdfJsDefaultPreferences.jsm");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getBoolPref(aPref, aDefaultValue) {
 | 
					function getBoolPref(aPref, aDefaultValue) {
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
@ -75,18 +77,10 @@ function isDefaultHandler() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function initializeDefaultPreferences() {
 | 
					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 defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + ".");
 | 
				
			||||||
  var defaultValue;
 | 
					  var defaultValue;
 | 
				
			||||||
  for (var key in DEFAULT_PREFERENCES) {
 | 
					  for (var key in PdfJsDefaultPreferences) {
 | 
				
			||||||
    defaultValue = DEFAULT_PREFERENCES[key];
 | 
					    defaultValue = PdfJsDefaultPreferences[key];
 | 
				
			||||||
    switch (typeof defaultValue) {
 | 
					    switch (typeof defaultValue) {
 | 
				
			||||||
      case "boolean":
 | 
					      case "boolean":
 | 
				
			||||||
        defaultBranch.setBoolPref(key, defaultValue);
 | 
					        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/XPCOMUtils.jsm");
 | 
				
			||||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
 | 
					ChromeUtils.import("resource://gre/modules/Services.jsm");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ChromeUtils.defineModuleGetter(this, "PdfJsDefaultPreferences",
 | 
				
			||||||
 | 
					  "resource://pdf.js/PdfJsDefaultPreferences.jsm");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Svc = {};
 | 
					var Svc = {};
 | 
				
			||||||
XPCOMUtils.defineLazyServiceGetter(Svc, "mime",
 | 
					XPCOMUtils.defineLazyServiceGetter(Svc, "mime",
 | 
				
			||||||
                                   "@mozilla.org/mime;1",
 | 
					                                   "@mozilla.org/mime;1",
 | 
				
			||||||
                                   "nsIMIMEService");
 | 
					                                   "nsIMIMEService");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* eslint-disable semi */
 | 
					 | 
				
			||||||
var DEFAULT_PREFERENCES =
 | 
					 | 
				
			||||||
//#include ../../../web/default_preferences.json
 | 
					 | 
				
			||||||
//#if false
 | 
					 | 
				
			||||||
  "end of DEFAULT_PREFERENCES"
 | 
					 | 
				
			||||||
//#endif
 | 
					 | 
				
			||||||
/* eslint-enable semi */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var PdfjsChromeUtils = {
 | 
					var PdfjsChromeUtils = {
 | 
				
			||||||
  // For security purposes when running remote, we restrict preferences
 | 
					  // For security purposes when running remote, we restrict preferences
 | 
				
			||||||
  // content can access.
 | 
					  // content can access.
 | 
				
			||||||
  _allowedPrefNames: Object.keys(DEFAULT_PREFERENCES),
 | 
					  _allowedPrefNames: Object.keys(PdfJsDefaultPreferences),
 | 
				
			||||||
  _ppmm: null,
 | 
					  _ppmm: null,
 | 
				
			||||||
  _mmg: 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']);
 | 
					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 () {
 | 
					gulp.task('firefox-pre', ['buildnumber', 'locale'], function () {
 | 
				
			||||||
  console.log();
 | 
					  console.log();
 | 
				
			||||||
  console.log('### Building Firefox extension');
 | 
					  console.log('### Building Firefox extension');
 | 
				
			||||||
@ -759,6 +774,10 @@ gulp.task('firefox-pre', ['buildnumber', 'locale'], function () {
 | 
				
			|||||||
        .pipe(gulp.dest(FIREFOX_BUILD_DIR)),
 | 
					        .pipe(gulp.dest(FIREFOX_BUILD_DIR)),
 | 
				
			||||||
    gulp.src('LICENSE').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)
 | 
					    preprocessJS(FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm', defines, true)
 | 
				
			||||||
        .pipe(replace(/\bPDFJSSCRIPT_STREAM_CONVERTER_ID\b/g,
 | 
					        .pipe(replace(/\bPDFJSSCRIPT_STREAM_CONVERTER_ID\b/g,
 | 
				
			||||||
                      FIREFOX_STREAM_CONVERTER_ID))
 | 
					                      FIREFOX_STREAM_CONVERTER_ID))
 | 
				
			||||||
@ -860,6 +879,10 @@ gulp.task('mozcentral-pre', ['buildnumber', 'locale'], function () {
 | 
				
			|||||||
        .pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)),
 | 
					        .pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)),
 | 
				
			||||||
    gulp.src('LICENSE').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)
 | 
					    preprocessJS(FIREFOX_CONTENT_DIR + 'PdfJs.jsm', defines, true)
 | 
				
			||||||
        .pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
 | 
					        .pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
 | 
				
			||||||
    preprocessJS(FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm', defines, true)
 | 
					    preprocessJS(FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm', defines, true)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user