Remove the Firefox extension building code.
Firefox no longer supports this legacy extension and it is a pain to sync changes from here and mozilla central.
This commit is contained in:
parent
a8e9f6cc29
commit
121e43685f
10
README.md
10
README.md
@ -27,15 +27,9 @@ Feel free to stop by #pdfjs on irc.mozilla.org for questions or guidance.
|
||||
|
||||
### Browser Extensions
|
||||
|
||||
#### Firefox (and Seamonkey)
|
||||
#### Firefox
|
||||
|
||||
PDF.js is built into version 19+ of Firefox, however, one extension is still available:
|
||||
|
||||
+ [Development Version](http://mozilla.github.io/pdf.js/extensions/firefox/pdf.js.xpi) - This extension is mainly intended for developers/testers, and it is updated every time new code is merged into the PDF.js codebase. It should be quite stable but might break from time to time.
|
||||
|
||||
+ Please note that the extension is *not* guaranteed to be compatible with Firefox versions that are *older* than the current Nightly version, see the [Release Calendar](https://wiki.mozilla.org/RapidRelease/Calendar#Past_branch_dates).
|
||||
|
||||
+ The extension *may* also work in Seamonkey, provided that it is based on a Firefox version as above (see [Which version of Firefox does SeaMonkey 2.x correspond with?](https://wiki.mozilla.org/SeaMonkey/FAQ#General)), but we do *not* guarantee compatibility.
|
||||
PDF.js is built into version 19+ of Firefox.
|
||||
|
||||
#### Chrome
|
||||
|
||||
|
171
extensions/firefox/bootstrap.js
vendored
171
extensions/firefox/bootstrap.js
vendored
@ -1,171 +0,0 @@
|
||||
/* Copyright 2012 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.
|
||||
*/
|
||||
/* globals PdfStreamConverter, APP_SHUTDOWN, PdfjsChromeUtils,
|
||||
PdfjsContentUtils */
|
||||
|
||||
"use strict";
|
||||
|
||||
const RESOURCE_NAME = "pdf.js";
|
||||
const EXT_PREFIX = "extensions.uriloader@pdf.js";
|
||||
|
||||
const Cm = Components.manager;
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
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(EXT_PREFIX + ".");
|
||||
var defaultValue;
|
||||
for (var key in DEFAULT_PREFERENCES) {
|
||||
defaultValue = DEFAULT_PREFERENCES[key];
|
||||
switch (typeof defaultValue) {
|
||||
case "boolean":
|
||||
defaultBranch.setBoolPref(key, defaultValue);
|
||||
break;
|
||||
case "number":
|
||||
defaultBranch.setIntPref(key, defaultValue);
|
||||
break;
|
||||
case "string":
|
||||
defaultBranch.setCharPref(key, defaultValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Factory that registers/unregisters a constructor as a component.
|
||||
function Factory() {}
|
||||
|
||||
Factory.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory]),
|
||||
_targetConstructor: null,
|
||||
|
||||
register: function register(targetConstructor) {
|
||||
this._targetConstructor = targetConstructor;
|
||||
var proto = targetConstructor.prototype;
|
||||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(proto.classID, proto.classDescription,
|
||||
proto.contractID, this);
|
||||
|
||||
if (proto.classID2) {
|
||||
this._classID2 = proto.classID2;
|
||||
registrar.registerFactory(proto.classID2, proto.classDescription,
|
||||
proto.contractID2, this);
|
||||
}
|
||||
},
|
||||
|
||||
unregister: function unregister() {
|
||||
var proto = this._targetConstructor.prototype;
|
||||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.unregisterFactory(proto.classID, this);
|
||||
if (this._classID2) {
|
||||
registrar.unregisterFactory(this._classID2, this);
|
||||
}
|
||||
this._targetConstructor = null;
|
||||
},
|
||||
|
||||
// nsIFactory
|
||||
createInstance: function createInstance(aOuter, iid) {
|
||||
if (aOuter !== null) {
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
return (new (this._targetConstructor)()).QueryInterface(iid);
|
||||
},
|
||||
|
||||
// nsIFactory
|
||||
lockFactory: function lockFactory(lock) {
|
||||
// No longer used as of gecko 1.7.
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
};
|
||||
|
||||
var pdfStreamConverterFactory = new Factory();
|
||||
var pdfBaseUrl = null;
|
||||
var e10sEnabled = false;
|
||||
|
||||
// As of Firefox 13 bootstrapped add-ons don't support automatic registering and
|
||||
// unregistering of resource urls and components/contracts. Until then we do
|
||||
// it programatically. See ManifestDirective ManifestParser.cpp for support.
|
||||
|
||||
function startup(aData, aReason) {
|
||||
// Setup the resource url.
|
||||
var ioService = Services.io;
|
||||
var resProt = ioService.getProtocolHandler("resource")
|
||||
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||
var aliasURI = ioService.newURI("content/", "UTF-8", aData.resourceURI);
|
||||
resProt.setSubstitution(RESOURCE_NAME, aliasURI);
|
||||
|
||||
pdfBaseUrl = aData.resourceURI.spec;
|
||||
|
||||
ChromeUtils.import(pdfBaseUrl + "content/PdfjsChromeUtils.jsm");
|
||||
PdfjsChromeUtils.init();
|
||||
ChromeUtils.import(pdfBaseUrl + "content/PdfjsContentUtils.jsm");
|
||||
PdfjsContentUtils.init();
|
||||
|
||||
// Load the component and register it.
|
||||
var pdfStreamConverterUrl = pdfBaseUrl + "content/PdfStreamConverter.jsm";
|
||||
ChromeUtils.import(pdfStreamConverterUrl);
|
||||
pdfStreamConverterFactory.register(PdfStreamConverter);
|
||||
|
||||
try {
|
||||
Services.mm.loadFrameScript("chrome://pdf.js/content/content.js", true);
|
||||
e10sEnabled = true;
|
||||
} catch (ex) {
|
||||
}
|
||||
|
||||
initializeDefaultPreferences();
|
||||
}
|
||||
|
||||
function shutdown(aData, aReason) {
|
||||
if (aReason === APP_SHUTDOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e10sEnabled) {
|
||||
let globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageBroadcaster);
|
||||
globalMM.broadcastAsyncMessage("PDFJS:Child:shutdown");
|
||||
globalMM.removeDelayedFrameScript("chrome://pdf.js/content/content.js");
|
||||
}
|
||||
|
||||
var ioService = Services.io;
|
||||
var resProt = ioService.getProtocolHandler("resource")
|
||||
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||
// Remove the resource url.
|
||||
resProt.setSubstitution(RESOURCE_NAME, null);
|
||||
// Remove the contract/component.
|
||||
pdfStreamConverterFactory.unregister();
|
||||
// Unload the converter
|
||||
var pdfStreamConverterUrl = pdfBaseUrl + "content/PdfStreamConverter.jsm";
|
||||
Cu.unload(pdfStreamConverterUrl);
|
||||
|
||||
PdfjsContentUtils.uninit();
|
||||
Cu.unload(pdfBaseUrl + "content/PdfjsContentUtils.jsm");
|
||||
PdfjsChromeUtils.uninit();
|
||||
Cu.unload(pdfBaseUrl + "content/PdfjsChromeUtils.jsm");
|
||||
}
|
||||
|
||||
function install(aData, aReason) {
|
||||
}
|
||||
|
||||
function uninstall(aData, aReason) {
|
||||
}
|
@ -1 +0,0 @@
|
||||
resource pdf.js content/
|
@ -1,5 +0,0 @@
|
||||
# Additional resources for pdf.js
|
||||
|
||||
content pdf.js chrome/
|
||||
|
||||
# PDFJS_SUPPORTED_LOCALES
|
@ -1,95 +0,0 @@
|
||||
/* Copyright 2014 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.
|
||||
*/
|
||||
/* eslint-env mozilla/frame-script */
|
||||
|
||||
"use strict";
|
||||
|
||||
(function contentScriptClosure() {
|
||||
// we need to use closure here -- we are running in the global context
|
||||
|
||||
const Cm = Components.manager;
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var isRemote = Services.appinfo.processType ===
|
||||
Services.appinfo.PROCESS_TYPE_CONTENT;
|
||||
|
||||
// Factory that registers/unregisters a constructor as a component.
|
||||
function Factory() {
|
||||
}
|
||||
|
||||
Factory.prototype = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory]),
|
||||
_targetConstructor: null,
|
||||
|
||||
register: function register(targetConstructor) {
|
||||
this._targetConstructor = targetConstructor;
|
||||
var proto = targetConstructor.prototype;
|
||||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(proto.classID, proto.classDescription,
|
||||
proto.contractID, this);
|
||||
},
|
||||
|
||||
unregister: function unregister() {
|
||||
var proto = this._targetConstructor.prototype;
|
||||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.unregisterFactory(proto.classID, this);
|
||||
this._targetConstructor = null;
|
||||
},
|
||||
|
||||
// nsIFactory
|
||||
createInstance: function createInstance(aOuter, iid) {
|
||||
if (aOuter !== null) {
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
return (new (this._targetConstructor)()).QueryInterface(iid);
|
||||
},
|
||||
|
||||
// nsIFactory
|
||||
lockFactory: function lockFactory(lock) {
|
||||
// No longer used as of gecko 1.7.
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
};
|
||||
|
||||
var pdfStreamConverterFactory = new Factory();
|
||||
|
||||
function startup() {
|
||||
ChromeUtils.import("resource://pdf.js/PdfjsContentUtils.jsm");
|
||||
PdfjsContentUtils.init();
|
||||
|
||||
ChromeUtils.import("resource://pdf.js/PdfStreamConverter.jsm");
|
||||
pdfStreamConverterFactory.register(PdfStreamConverter);
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
// Remove the contract/component.
|
||||
pdfStreamConverterFactory.unregister();
|
||||
// Unload the converter
|
||||
Cu.unload("resource://pdf.js/PdfStreamConverter.jsm");
|
||||
|
||||
PdfjsContentUtils.uninit();
|
||||
Cu.unload("resource://pdf.js/PdfjsContentUtils.jsm");
|
||||
}
|
||||
|
||||
if (isRemote) {
|
||||
startup();
|
||||
|
||||
addMessageListener("PDFJS:Child:shutdown", function() {
|
||||
shutdown();
|
||||
});
|
||||
}
|
||||
})();
|
@ -1,25 +0,0 @@
|
||||
/* Copyright 2012 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";
|
||||
|
||||
// Don't remove this file!
|
||||
// FF15+ expects `PdfJs` module to be present at `resource://pdf.js/PdfJs.jsm`,
|
||||
// see https://dxr.mozilla.org/mozilla-central/source/browser/components/nsBrowserGlue.js
|
||||
var EXPORTED_SYMBOLS = ["PdfJs"];
|
||||
|
||||
var PdfJs = {
|
||||
init: function PdfJs_init() {},
|
||||
};
|
@ -1,351 +0,0 @@
|
||||
/* Copyright 2012 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 = ["PdfJs"];
|
||||
|
||||
const Cm = Components.manager;
|
||||
|
||||
const PREF_PREFIX = "pdfjs";
|
||||
const PREF_DISABLED = PREF_PREFIX + ".disabled";
|
||||
const PREF_MIGRATION_VERSION = PREF_PREFIX + ".migrationVersion";
|
||||
const PREF_PREVIOUS_ACTION = PREF_PREFIX + ".previousHandler.preferredAction";
|
||||
const PREF_PREVIOUS_ASK = PREF_PREFIX +
|
||||
".previousHandler.alwaysAskBeforeHandling";
|
||||
const PREF_DISABLED_PLUGIN_TYPES = "plugin.disable_full_page_plugin_for_types";
|
||||
const PREF_ENABLED_CACHE_STATE = PREF_PREFIX + ".enabledCache.state";
|
||||
const PREF_ENABLED_CACHE_INITIALIZED = PREF_PREFIX +
|
||||
".enabledCache.initialized";
|
||||
const PREF_APP_UPDATE_POSTUPDATE = "app.update.postupdate";
|
||||
const TOPIC_PDFJS_HANDLER_CHANGED = "pdfjs:handlerChanged";
|
||||
const TOPIC_PLUGINS_LIST_UPDATED = "plugins-list-updated";
|
||||
const TOPIC_PLUGIN_INFO_UPDATED = "plugin-info-updated";
|
||||
const PDF_CONTENT_TYPE = "application/pdf";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var Svc = {};
|
||||
XPCOMUtils.defineLazyServiceGetter(Svc, "mime",
|
||||
"@mozilla.org/mime;1",
|
||||
"nsIMIMEService");
|
||||
XPCOMUtils.defineLazyServiceGetter(Svc, "pluginHost",
|
||||
"@mozilla.org/plugin/host;1",
|
||||
"nsIPluginHost");
|
||||
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 {
|
||||
return Services.prefs.getBoolPref(aPref);
|
||||
} catch (ex) {
|
||||
return aDefaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
function getIntPref(aPref, aDefaultValue) {
|
||||
try {
|
||||
return Services.prefs.getIntPref(aPref);
|
||||
} catch (ex) {
|
||||
return aDefaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
function isDefaultHandler() {
|
||||
if (Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT) {
|
||||
throw new Error("isDefaultHandler should only get called in the parent " +
|
||||
"process.");
|
||||
}
|
||||
return PdfjsChromeUtils.isDefaultHandlerApp();
|
||||
}
|
||||
|
||||
function initializeDefaultPreferences() {
|
||||
var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + ".");
|
||||
var defaultValue;
|
||||
for (var key in PdfJsDefaultPreferences) {
|
||||
defaultValue = PdfJsDefaultPreferences[key];
|
||||
switch (typeof defaultValue) {
|
||||
case "boolean":
|
||||
defaultBranch.setBoolPref(key, defaultValue);
|
||||
break;
|
||||
case "number":
|
||||
defaultBranch.setIntPref(key, defaultValue);
|
||||
break;
|
||||
case "string":
|
||||
defaultBranch.setCharPref(key, defaultValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register/unregister a constructor as a factory.
|
||||
function Factory() {}
|
||||
Factory.prototype = {
|
||||
register: function register(targetConstructor) {
|
||||
var proto = targetConstructor.prototype;
|
||||
this._classID = proto.classID;
|
||||
|
||||
var factory = XPCOMUtils._getFactory(targetConstructor);
|
||||
this._factory = factory;
|
||||
|
||||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(proto.classID, proto.classDescription,
|
||||
proto.contractID, factory);
|
||||
|
||||
if (proto.classID2) {
|
||||
this._classID2 = proto.classID2;
|
||||
registrar.registerFactory(proto.classID2, proto.classDescription,
|
||||
proto.contractID2, factory);
|
||||
}
|
||||
},
|
||||
|
||||
unregister: function unregister() {
|
||||
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.unregisterFactory(this._classID, this._factory);
|
||||
if (this._classID2) {
|
||||
registrar.unregisterFactory(this._classID2, this._factory);
|
||||
}
|
||||
this._factory = null;
|
||||
},
|
||||
};
|
||||
|
||||
var PdfJs = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
||||
_registered: false,
|
||||
_initialized: false,
|
||||
|
||||
init: function init(remote) {
|
||||
if (Services.appinfo.processType !==
|
||||
Services.appinfo.PROCESS_TYPE_DEFAULT) {
|
||||
throw new Error("PdfJs.init should only get called " +
|
||||
"in the parent process.");
|
||||
}
|
||||
PdfjsChromeUtils.init();
|
||||
if (!remote) {
|
||||
PdfjsContentUtils.init();
|
||||
}
|
||||
this.initPrefs();
|
||||
this.updateRegistration();
|
||||
},
|
||||
|
||||
initPrefs: function initPrefs() {
|
||||
if (this._initialized) {
|
||||
return;
|
||||
}
|
||||
this._initialized = true;
|
||||
|
||||
if (!getBoolPref(PREF_DISABLED, true)) {
|
||||
this._migrate();
|
||||
}
|
||||
|
||||
// Listen for when pdf.js is completely disabled or a different pdf handler
|
||||
// is chosen.
|
||||
Services.prefs.addObserver(PREF_DISABLED, this);
|
||||
Services.prefs.addObserver(PREF_DISABLED_PLUGIN_TYPES, this);
|
||||
Services.obs.addObserver(this, TOPIC_PDFJS_HANDLER_CHANGED);
|
||||
Services.obs.addObserver(this, TOPIC_PLUGINS_LIST_UPDATED);
|
||||
Services.obs.addObserver(this, TOPIC_PLUGIN_INFO_UPDATED);
|
||||
|
||||
initializeDefaultPreferences();
|
||||
},
|
||||
|
||||
updateRegistration: function updateRegistration() {
|
||||
if (this.checkEnabled()) {
|
||||
this.ensureRegistered();
|
||||
} else {
|
||||
this.ensureUnregistered();
|
||||
}
|
||||
},
|
||||
|
||||
uninit: function uninit() {
|
||||
if (this._initialized) {
|
||||
Services.prefs.removeObserver(PREF_DISABLED, this);
|
||||
Services.prefs.removeObserver(PREF_DISABLED_PLUGIN_TYPES, this);
|
||||
Services.obs.removeObserver(this, TOPIC_PDFJS_HANDLER_CHANGED);
|
||||
Services.obs.removeObserver(this, TOPIC_PLUGINS_LIST_UPDATED);
|
||||
Services.obs.removeObserver(this, TOPIC_PLUGIN_INFO_UPDATED);
|
||||
this._initialized = false;
|
||||
}
|
||||
this.ensureUnregistered();
|
||||
},
|
||||
|
||||
_migrate: function migrate() {
|
||||
const VERSION = 2;
|
||||
var currentVersion = getIntPref(PREF_MIGRATION_VERSION, 0);
|
||||
if (currentVersion >= VERSION) {
|
||||
return;
|
||||
}
|
||||
// Make pdf.js the default pdf viewer on the first migration.
|
||||
if (currentVersion < 1) {
|
||||
this._becomeHandler();
|
||||
}
|
||||
if (currentVersion < 2) {
|
||||
// cleaning up of unused database preference (see #3994)
|
||||
Services.prefs.clearUserPref(PREF_PREFIX + ".database");
|
||||
}
|
||||
Services.prefs.setIntPref(PREF_MIGRATION_VERSION, VERSION);
|
||||
},
|
||||
|
||||
_becomeHandler: function _becomeHandler() {
|
||||
let handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, "pdf");
|
||||
let prefs = Services.prefs;
|
||||
if (handlerInfo.preferredAction !== Ci.nsIHandlerInfo.handleInternally &&
|
||||
handlerInfo.preferredAction !== false) {
|
||||
// Store the previous settings of preferredAction and
|
||||
// alwaysAskBeforeHandling in case we need to revert them in a hotfix that
|
||||
// would turn pdf.js off.
|
||||
prefs.setIntPref(PREF_PREVIOUS_ACTION, handlerInfo.preferredAction);
|
||||
prefs.setBoolPref(PREF_PREVIOUS_ASK, handlerInfo.alwaysAskBeforeHandling);
|
||||
}
|
||||
|
||||
let handlerService = Cc["@mozilla.org/uriloader/handler-service;1"].
|
||||
getService(Ci.nsIHandlerService);
|
||||
|
||||
// Change and save mime handler settings.
|
||||
handlerInfo.alwaysAskBeforeHandling = false;
|
||||
handlerInfo.preferredAction = Ci.nsIHandlerInfo.handleInternally;
|
||||
handlerService.store(handlerInfo);
|
||||
|
||||
// Also disable any plugins for pdfs.
|
||||
var stringTypes = "";
|
||||
var types = [];
|
||||
if (prefs.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES)) {
|
||||
stringTypes = prefs.getCharPref(PREF_DISABLED_PLUGIN_TYPES);
|
||||
}
|
||||
if (stringTypes !== "") {
|
||||
types = stringTypes.split(",");
|
||||
}
|
||||
|
||||
if (!types.includes(PDF_CONTENT_TYPE)) {
|
||||
types.push(PDF_CONTENT_TYPE);
|
||||
}
|
||||
prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES, types.join(","));
|
||||
|
||||
// Update the category manager in case the plugins are already loaded.
|
||||
let categoryManager = Cc["@mozilla.org/categorymanager;1"];
|
||||
categoryManager.getService(Ci.nsICategoryManager).
|
||||
deleteCategoryEntry("Gecko-Content-Viewers",
|
||||
PDF_CONTENT_TYPE,
|
||||
false);
|
||||
},
|
||||
|
||||
_isEnabled: function _isEnabled() {
|
||||
var disabled = getBoolPref(PREF_DISABLED, true);
|
||||
if (disabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the 'application/pdf' preview handler is configured properly.
|
||||
if (!isDefaultHandler()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have disabled plugin handling of 'application/pdf' in prefs
|
||||
if (Services.prefs.prefHasUserValue(PREF_DISABLED_PLUGIN_TYPES)) {
|
||||
let disabledPluginTypes =
|
||||
Services.prefs.getCharPref(PREF_DISABLED_PLUGIN_TYPES).split(",");
|
||||
if (disabledPluginTypes.includes(PDF_CONTENT_TYPE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if there is an enabled pdf plugin.
|
||||
// Note: this check is performed last because getPluginTags() triggers
|
||||
// costly plugin list initialization (bug 881575)
|
||||
let tags = Cc["@mozilla.org/plugin/host;1"].
|
||||
getService(Ci.nsIPluginHost).
|
||||
getPluginTags();
|
||||
let enabledPluginFound = tags.some(function(tag) {
|
||||
if (tag.disabled) {
|
||||
return false;
|
||||
}
|
||||
let mimeTypes = tag.getMimeTypes();
|
||||
return mimeTypes.some(function(mimeType) {
|
||||
return mimeType === PDF_CONTENT_TYPE;
|
||||
});
|
||||
});
|
||||
|
||||
// Use pdf.js if pdf plugin is not present or disabled
|
||||
return !enabledPluginFound;
|
||||
},
|
||||
|
||||
checkEnabled: function checkEnabled() {
|
||||
let isEnabled = this._isEnabled();
|
||||
// This will be updated any time we observe a dependency changing, since
|
||||
// updateRegistration internally calls enabled.
|
||||
Services.prefs.setBoolPref(PREF_ENABLED_CACHE_STATE, isEnabled);
|
||||
return isEnabled;
|
||||
},
|
||||
|
||||
// nsIObserver
|
||||
observe: function observe(aSubject, aTopic, aData) {
|
||||
if (Services.appinfo.processType !==
|
||||
Services.appinfo.PROCESS_TYPE_DEFAULT) {
|
||||
throw new Error("Only the parent process should be observing PDF " +
|
||||
"handler changes.");
|
||||
}
|
||||
|
||||
this.updateRegistration();
|
||||
let jsm = "resource://pdf.js/PdfjsChromeUtils.jsm";
|
||||
let PdfjsChromeUtils = ChromeUtils.import(jsm, {}).PdfjsChromeUtils;
|
||||
PdfjsChromeUtils.notifyChildOfSettingsChange(this.enabled);
|
||||
},
|
||||
|
||||
/**
|
||||
* pdf.js is only enabled if it is both selected as the pdf viewer and if the
|
||||
* global switch enabling it is true.
|
||||
* @return {boolean} Whether or not it's enabled.
|
||||
*/
|
||||
get enabled() {
|
||||
if (!Services.prefs.getBoolPref(PREF_ENABLED_CACHE_INITIALIZED, false)) {
|
||||
// If we just updated, and the cache hasn't been initialized, then we
|
||||
// can't assume a default state, and need to synchronously initialize
|
||||
// PdfJs
|
||||
if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_POSTUPDATE)) {
|
||||
this.checkEnabled();
|
||||
}
|
||||
|
||||
Services.prefs.setBoolPref(PREF_ENABLED_CACHE_INITIALIZED, true);
|
||||
}
|
||||
return Services.prefs.getBoolPref(PREF_ENABLED_CACHE_STATE, true);
|
||||
},
|
||||
|
||||
ensureRegistered: function ensureRegistered() {
|
||||
if (this._registered) {
|
||||
return;
|
||||
}
|
||||
this._pdfStreamConverterFactory = new Factory();
|
||||
ChromeUtils.import("resource://pdf.js/PdfStreamConverter.jsm");
|
||||
this._pdfStreamConverterFactory.register(PdfStreamConverter);
|
||||
|
||||
this._registered = true;
|
||||
},
|
||||
|
||||
ensureUnregistered: function ensureUnregistered() {
|
||||
if (!this._registered) {
|
||||
return;
|
||||
}
|
||||
this._pdfStreamConverterFactory.unregister();
|
||||
Cu.unload("resource://pdf.js/PdfStreamConverter.jsm");
|
||||
delete this._pdfStreamConverterFactory;
|
||||
|
||||
this._registered = false;
|
||||
},
|
||||
};
|
@ -1,255 +0,0 @@
|
||||
/* Copyright 2012 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";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var EXPORTED_SYMBOLS = ["NetworkManager"];
|
||||
|
||||
function log(aMsg) { // eslint-disable-line no-unused-vars
|
||||
var msg = "PdfJsNetwork.jsm: " + (aMsg.join ? aMsg.join("") : aMsg);
|
||||
Services.console.logStringMessage(msg);
|
||||
}
|
||||
|
||||
var NetworkManager = (function NetworkManagerClosure() {
|
||||
|
||||
const OK_RESPONSE = 200;
|
||||
const PARTIAL_CONTENT_RESPONSE = 206;
|
||||
|
||||
function getArrayBuffer(xhr) {
|
||||
var data = xhr.response;
|
||||
if (typeof data !== "string") {
|
||||
return data;
|
||||
}
|
||||
var length = data.length;
|
||||
var array = new Uint8Array(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
array[i] = data.charCodeAt(i) & 0xFF;
|
||||
}
|
||||
return array.buffer;
|
||||
}
|
||||
|
||||
class NetworkManagerClass {
|
||||
constructor(url, args) {
|
||||
this.url = url;
|
||||
args = args || {};
|
||||
this.isHttp = /^https?:/i.test(url);
|
||||
this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
|
||||
this.withCredentials = args.withCredentials || false;
|
||||
this.getXhr = args.getXhr ||
|
||||
function NetworkManager_getXhr() {
|
||||
return new XMLHttpRequest();
|
||||
};
|
||||
|
||||
this.currXhrId = 0;
|
||||
this.pendingRequests = Object.create(null);
|
||||
this.loadedRequests = Object.create(null);
|
||||
}
|
||||
|
||||
requestRange(begin, end, listeners) {
|
||||
var args = {
|
||||
begin,
|
||||
end,
|
||||
};
|
||||
for (var prop in listeners) {
|
||||
args[prop] = listeners[prop];
|
||||
}
|
||||
return this.request(args);
|
||||
}
|
||||
|
||||
requestFull(listeners) {
|
||||
return this.request(listeners);
|
||||
}
|
||||
|
||||
request(args) {
|
||||
var xhr = this.getXhr();
|
||||
var xhrId = this.currXhrId++;
|
||||
var pendingRequest = this.pendingRequests[xhrId] = {
|
||||
xhr,
|
||||
};
|
||||
|
||||
xhr.open("GET", this.url);
|
||||
xhr.withCredentials = this.withCredentials;
|
||||
for (var property in this.httpHeaders) {
|
||||
var value = this.httpHeaders[property];
|
||||
if (typeof value === "undefined") {
|
||||
continue;
|
||||
}
|
||||
xhr.setRequestHeader(property, value);
|
||||
}
|
||||
if (this.isHttp && "begin" in args && "end" in args) {
|
||||
var rangeStr = args.begin + "-" + (args.end - 1);
|
||||
xhr.setRequestHeader("Range", "bytes=" + rangeStr);
|
||||
pendingRequest.expectedStatus = 206;
|
||||
} else {
|
||||
pendingRequest.expectedStatus = 200;
|
||||
}
|
||||
|
||||
var useMozChunkedLoading = !!args.onProgressiveData;
|
||||
if (useMozChunkedLoading) {
|
||||
xhr.responseType = "moz-chunked-arraybuffer";
|
||||
pendingRequest.onProgressiveData = args.onProgressiveData;
|
||||
pendingRequest.mozChunked = true;
|
||||
} else {
|
||||
xhr.responseType = "arraybuffer";
|
||||
}
|
||||
|
||||
if (args.onError) {
|
||||
xhr.onerror = function(evt) {
|
||||
args.onError(xhr.status);
|
||||
};
|
||||
}
|
||||
xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
|
||||
xhr.onprogress = this.onProgress.bind(this, xhrId);
|
||||
|
||||
pendingRequest.onHeadersReceived = args.onHeadersReceived;
|
||||
pendingRequest.onDone = args.onDone;
|
||||
pendingRequest.onError = args.onError;
|
||||
pendingRequest.onProgress = args.onProgress;
|
||||
|
||||
xhr.send(null);
|
||||
|
||||
return xhrId;
|
||||
}
|
||||
|
||||
onProgress(xhrId, evt) {
|
||||
var pendingRequest = this.pendingRequests[xhrId];
|
||||
if (!pendingRequest) {
|
||||
// Maybe abortRequest was called...
|
||||
return;
|
||||
}
|
||||
|
||||
if (pendingRequest.mozChunked) {
|
||||
var chunk = getArrayBuffer(pendingRequest.xhr);
|
||||
pendingRequest.onProgressiveData(chunk);
|
||||
}
|
||||
|
||||
var onProgress = pendingRequest.onProgress;
|
||||
if (onProgress) {
|
||||
onProgress(evt);
|
||||
}
|
||||
}
|
||||
|
||||
onStateChange(xhrId, evt) {
|
||||
var pendingRequest = this.pendingRequests[xhrId];
|
||||
if (!pendingRequest) {
|
||||
// Maybe abortRequest was called...
|
||||
return;
|
||||
}
|
||||
|
||||
var xhr = pendingRequest.xhr;
|
||||
if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
|
||||
pendingRequest.onHeadersReceived();
|
||||
delete pendingRequest.onHeadersReceived;
|
||||
}
|
||||
|
||||
if (xhr.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(xhrId in this.pendingRequests)) {
|
||||
// The XHR request might have been aborted in onHeadersReceived()
|
||||
// callback, in which case we should abort request
|
||||
return;
|
||||
}
|
||||
|
||||
delete this.pendingRequests[xhrId];
|
||||
|
||||
// success status == 0 can be on ftp, file and other protocols
|
||||
if (xhr.status === 0 && this.isHttp) {
|
||||
if (pendingRequest.onError) {
|
||||
pendingRequest.onError(xhr.status);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var xhrStatus = xhr.status || OK_RESPONSE;
|
||||
|
||||
// From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
|
||||
// "A server MAY ignore the Range header". This means it's possible to
|
||||
// get a 200 rather than a 206 response from a range request.
|
||||
var ok_response_on_range_request =
|
||||
xhrStatus === OK_RESPONSE &&
|
||||
pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
|
||||
|
||||
if (!ok_response_on_range_request &&
|
||||
xhrStatus !== pendingRequest.expectedStatus) {
|
||||
if (pendingRequest.onError) {
|
||||
pendingRequest.onError(xhr.status);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadedRequests[xhrId] = true;
|
||||
|
||||
var chunk = getArrayBuffer(xhr);
|
||||
if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
|
||||
var rangeHeader = xhr.getResponseHeader("Content-Range");
|
||||
var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
|
||||
var begin = parseInt(matches[1], 10);
|
||||
pendingRequest.onDone({
|
||||
begin,
|
||||
chunk,
|
||||
});
|
||||
} else if (pendingRequest.onProgressiveData) {
|
||||
pendingRequest.onDone(null);
|
||||
} else if (chunk) {
|
||||
pendingRequest.onDone({
|
||||
begin: 0,
|
||||
chunk,
|
||||
});
|
||||
} else if (pendingRequest.onError) {
|
||||
pendingRequest.onError(xhr.status);
|
||||
}
|
||||
}
|
||||
|
||||
hasPendingRequests() {
|
||||
for (var xhrId in this.pendingRequests) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getRequestXhr(xhrId) {
|
||||
return this.pendingRequests[xhrId].xhr;
|
||||
}
|
||||
|
||||
isStreamingRequest(xhrId) {
|
||||
return !!(this.pendingRequests[xhrId].onProgressiveData);
|
||||
}
|
||||
|
||||
isPendingRequest(xhrId) {
|
||||
return xhrId in this.pendingRequests;
|
||||
}
|
||||
|
||||
isLoadedRequest(xhrId) {
|
||||
return xhrId in this.loadedRequests;
|
||||
}
|
||||
|
||||
abortAllRequests() {
|
||||
for (var xhrId in this.pendingRequests) {
|
||||
this.abortRequest(xhrId | 0);
|
||||
}
|
||||
}
|
||||
|
||||
abortRequest(xhrId) {
|
||||
var xhr = this.pendingRequests[xhrId].xhr;
|
||||
delete this.pendingRequests[xhrId];
|
||||
xhr.abort();
|
||||
}
|
||||
}
|
||||
|
||||
return NetworkManagerClass;
|
||||
})();
|
@ -1,43 +0,0 @@
|
||||
/* Copyright 2013 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 = ["PdfJsTelemetry"];
|
||||
|
||||
var PdfJsTelemetry = {
|
||||
onViewerIsUsed() {
|
||||
},
|
||||
onFallback() {
|
||||
},
|
||||
onDocumentSize(size) {
|
||||
},
|
||||
onDocumentVersion(versionId) {
|
||||
},
|
||||
onDocumentGenerator(generatorId) {
|
||||
},
|
||||
onEmbed(isObject) {
|
||||
},
|
||||
onFontType(fontTypeId) {
|
||||
},
|
||||
onForm(isAcroform) {
|
||||
},
|
||||
onPrint() {
|
||||
},
|
||||
onStreamType(streamTypeId) {
|
||||
},
|
||||
onTimeToView(ms) {
|
||||
},
|
||||
};
|
@ -1,68 +0,0 @@
|
||||
/* Copyright 2013 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.
|
||||
*/
|
||||
/* eslint max-len: ["error", 100] */
|
||||
|
||||
"use strict";
|
||||
|
||||
var EXPORTED_SYMBOLS = ["PdfJsTelemetry"];
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var PdfJsTelemetry = {
|
||||
onViewerIsUsed() {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_USED");
|
||||
histogram.add(true);
|
||||
},
|
||||
onFallback() {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FALLBACK_SHOWN");
|
||||
histogram.add(true);
|
||||
},
|
||||
onDocumentSize(size) {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_SIZE_KB");
|
||||
histogram.add(size / 1024);
|
||||
},
|
||||
onDocumentVersion(versionId) {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_VERSION");
|
||||
histogram.add(versionId);
|
||||
},
|
||||
onDocumentGenerator(generatorId) {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_DOCUMENT_GENERATOR");
|
||||
histogram.add(generatorId);
|
||||
},
|
||||
onEmbed(isObject) {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_EMBED");
|
||||
histogram.add(isObject);
|
||||
},
|
||||
onFontType(fontTypeId) {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FONT_TYPES");
|
||||
histogram.add(fontTypeId);
|
||||
},
|
||||
onForm(isAcroform) {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_FORM");
|
||||
histogram.add(isAcroform);
|
||||
},
|
||||
onPrint() {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_PRINT");
|
||||
histogram.add(true);
|
||||
},
|
||||
onStreamType(streamTypeId) {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_STREAM_TYPES");
|
||||
histogram.add(streamTypeId);
|
||||
},
|
||||
onTimeToView(ms) {
|
||||
let histogram = Services.telemetry.getHistogramById("PDF_VIEWER_TIME_TO_VIEW_MS");
|
||||
histogram.add(ms);
|
||||
},
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -1,324 +0,0 @@
|
||||
/* Copyright 2012 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 = ["PdfjsChromeUtils"];
|
||||
|
||||
const PREF_PREFIX = "PDFJSSCRIPT_PREF_PREFIX";
|
||||
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");
|
||||
|
||||
var PdfjsChromeUtils = {
|
||||
// For security purposes when running remote, we restrict preferences
|
||||
// content can access.
|
||||
_allowedPrefNames: Object.keys(PdfJsDefaultPreferences),
|
||||
_ppmm: null,
|
||||
_mmg: null,
|
||||
|
||||
/*
|
||||
* Public API
|
||||
*/
|
||||
|
||||
init() {
|
||||
this._browsers = new WeakSet();
|
||||
if (!this._ppmm) {
|
||||
// global parent process message manager (PPMM)
|
||||
this._ppmm = Services.ppmm;
|
||||
this._ppmm.addMessageListener("PDFJS:Parent:clearUserPref", this);
|
||||
this._ppmm.addMessageListener("PDFJS:Parent:setIntPref", this);
|
||||
this._ppmm.addMessageListener("PDFJS:Parent:setBoolPref", this);
|
||||
this._ppmm.addMessageListener("PDFJS:Parent:setCharPref", this);
|
||||
this._ppmm.addMessageListener("PDFJS:Parent:setStringPref", this);
|
||||
this._ppmm.addMessageListener("PDFJS:Parent:isDefaultHandlerApp", this);
|
||||
|
||||
// global dom message manager (MMg)
|
||||
this._mmg = Services.mm;
|
||||
this._mmg.addMessageListener("PDFJS:Parent:displayWarning", this);
|
||||
|
||||
this._mmg.addMessageListener("PDFJS:Parent:addEventListener", this);
|
||||
this._mmg.addMessageListener("PDFJS:Parent:removeEventListener", this);
|
||||
this._mmg.addMessageListener("PDFJS:Parent:updateControlState", this);
|
||||
|
||||
// Observer to handle shutdown.
|
||||
Services.obs.addObserver(this, "quit-application");
|
||||
}
|
||||
},
|
||||
|
||||
uninit() {
|
||||
if (this._ppmm) {
|
||||
this._ppmm.removeMessageListener("PDFJS:Parent:clearUserPref", this);
|
||||
this._ppmm.removeMessageListener("PDFJS:Parent:setIntPref", this);
|
||||
this._ppmm.removeMessageListener("PDFJS:Parent:setBoolPref", this);
|
||||
this._ppmm.removeMessageListener("PDFJS:Parent:setCharPref", this);
|
||||
this._ppmm.removeMessageListener("PDFJS:Parent:setStringPref", this);
|
||||
this._ppmm.removeMessageListener("PDFJS:Parent:isDefaultHandlerApp",
|
||||
this);
|
||||
|
||||
this._mmg.removeMessageListener("PDFJS:Parent:displayWarning", this);
|
||||
|
||||
this._mmg.removeMessageListener("PDFJS:Parent:addEventListener", this);
|
||||
this._mmg.removeMessageListener("PDFJS:Parent:removeEventListener", this);
|
||||
this._mmg.removeMessageListener("PDFJS:Parent:updateControlState", this);
|
||||
|
||||
Services.obs.removeObserver(this, "quit-application");
|
||||
|
||||
this._mmg = null;
|
||||
this._ppmm = null;
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Called by the main module when preference changes are picked up
|
||||
* in the parent process. Observers don't propagate so we need to
|
||||
* instruct the child to refresh its configuration and (possibly)
|
||||
* the module's registration.
|
||||
*/
|
||||
notifyChildOfSettingsChange(enabled) {
|
||||
if (Services.appinfo.processType ===
|
||||
Services.appinfo.PROCESS_TYPE_DEFAULT && this._ppmm) {
|
||||
// XXX kinda bad, we want to get the parent process mm associated
|
||||
// with the content process. _ppmm is currently the global process
|
||||
// manager, which means this is going to fire to every child process
|
||||
// we have open. Unfortunately I can't find a way to get at that
|
||||
// process specific mm from js.
|
||||
this._ppmm.broadcastAsyncMessage("PDFJS:Child:updateSettings",
|
||||
{ enabled, });
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Events
|
||||
*/
|
||||
|
||||
observe(aSubject, aTopic, aData) {
|
||||
if (aTopic === "quit-application") {
|
||||
this.uninit();
|
||||
}
|
||||
},
|
||||
|
||||
receiveMessage(aMsg) {
|
||||
switch (aMsg.name) {
|
||||
case "PDFJS:Parent:clearUserPref":
|
||||
this._clearUserPref(aMsg.data.name);
|
||||
break;
|
||||
case "PDFJS:Parent:setIntPref":
|
||||
this._setIntPref(aMsg.data.name, aMsg.data.value);
|
||||
break;
|
||||
case "PDFJS:Parent:setBoolPref":
|
||||
this._setBoolPref(aMsg.data.name, aMsg.data.value);
|
||||
break;
|
||||
case "PDFJS:Parent:setCharPref":
|
||||
this._setCharPref(aMsg.data.name, aMsg.data.value);
|
||||
break;
|
||||
case "PDFJS:Parent:setStringPref":
|
||||
this._setStringPref(aMsg.data.name, aMsg.data.value);
|
||||
break;
|
||||
case "PDFJS:Parent:isDefaultHandlerApp":
|
||||
return this.isDefaultHandlerApp();
|
||||
case "PDFJS:Parent:displayWarning":
|
||||
this._displayWarning(aMsg);
|
||||
break;
|
||||
|
||||
case "PDFJS:Parent:updateControlState":
|
||||
return this._updateControlState(aMsg);
|
||||
case "PDFJS:Parent:addEventListener":
|
||||
return this._addEventListener(aMsg);
|
||||
case "PDFJS:Parent:removeEventListener":
|
||||
return this._removeEventListener(aMsg);
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
/*
|
||||
* Internal
|
||||
*/
|
||||
|
||||
_findbarFromMessage(aMsg) {
|
||||
let browser = aMsg.target;
|
||||
let tabbrowser = browser.getTabBrowser();
|
||||
let tab = tabbrowser.getTabForBrowser(browser);
|
||||
return tabbrowser.getFindBar(tab);
|
||||
},
|
||||
|
||||
_updateControlState(aMsg) {
|
||||
let data = aMsg.data;
|
||||
this._findbarFromMessage(aMsg)
|
||||
.updateControlState(data.result, data.findPrevious);
|
||||
},
|
||||
|
||||
handleEvent(aEvent) {
|
||||
// To avoid forwarding the message as a CPOW, create a structured cloneable
|
||||
// version of the event for both performance, and ease of usage, reasons.
|
||||
let type = aEvent.type;
|
||||
let detail = {
|
||||
query: aEvent.detail.query,
|
||||
caseSensitive: aEvent.detail.caseSensitive,
|
||||
highlightAll: aEvent.detail.highlightAll,
|
||||
findPrevious: aEvent.detail.findPrevious,
|
||||
};
|
||||
|
||||
let browser = aEvent.currentTarget.browser;
|
||||
if (!this._browsers.has(browser)) {
|
||||
throw new Error("FindEventManager was not bound " +
|
||||
"for the current browser.");
|
||||
}
|
||||
// Only forward the events if the current browser is a registered browser.
|
||||
let mm = browser.messageManager;
|
||||
mm.sendAsyncMessage("PDFJS:Child:handleEvent", { type, detail, });
|
||||
aEvent.preventDefault();
|
||||
},
|
||||
|
||||
_types: ["find",
|
||||
"findagain",
|
||||
"findhighlightallchange",
|
||||
"findcasesensitivitychange"],
|
||||
|
||||
_addEventListener(aMsg) {
|
||||
let browser = aMsg.target;
|
||||
if (this._browsers.has(browser)) {
|
||||
throw new Error("FindEventManager was bound 2nd time " +
|
||||
"without unbinding it first.");
|
||||
}
|
||||
|
||||
// Since this jsm is global, we need to store all the browsers
|
||||
// we have to forward the messages for.
|
||||
this._browsers.add(browser);
|
||||
|
||||
// And we need to start listening to find events.
|
||||
for (var i = 0; i < this._types.length; i++) {
|
||||
var type = this._types[i];
|
||||
this._findbarFromMessage(aMsg)
|
||||
.addEventListener(type, this, true);
|
||||
}
|
||||
},
|
||||
|
||||
_removeEventListener(aMsg) {
|
||||
let browser = aMsg.target;
|
||||
if (!this._browsers.has(browser)) {
|
||||
throw new Error("FindEventManager was unbound without binding it first.");
|
||||
}
|
||||
|
||||
this._browsers.delete(browser);
|
||||
|
||||
// No reason to listen to find events any longer.
|
||||
for (var i = 0; i < this._types.length; i++) {
|
||||
var type = this._types[i];
|
||||
this._findbarFromMessage(aMsg)
|
||||
.removeEventListener(type, this, true);
|
||||
}
|
||||
},
|
||||
|
||||
_ensurePreferenceAllowed(aPrefName) {
|
||||
let unPrefixedName = aPrefName.split(PREF_PREFIX + ".");
|
||||
if (unPrefixedName[0] !== "" ||
|
||||
!this._allowedPrefNames.includes(unPrefixedName[1])) {
|
||||
let msg = "\"" + aPrefName + "\" " +
|
||||
"can't be accessed from content. See PdfjsChromeUtils.";
|
||||
throw new Error(msg);
|
||||
}
|
||||
},
|
||||
|
||||
_clearUserPref(aPrefName) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.clearUserPref(aPrefName);
|
||||
},
|
||||
|
||||
_setIntPref(aPrefName, aPrefValue) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.setIntPref(aPrefName, aPrefValue);
|
||||
},
|
||||
|
||||
_setBoolPref(aPrefName, aPrefValue) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.setBoolPref(aPrefName, aPrefValue);
|
||||
},
|
||||
|
||||
_setCharPref(aPrefName, aPrefValue) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.setCharPref(aPrefName, aPrefValue);
|
||||
},
|
||||
|
||||
_setStringPref(aPrefName, aPrefValue) {
|
||||
this._ensurePreferenceAllowed(aPrefName);
|
||||
Services.prefs.setStringPref(aPrefName, aPrefValue);
|
||||
},
|
||||
|
||||
/*
|
||||
* Svc.mime doesn't have profile information in the child, so
|
||||
* we bounce this pdfjs enabled configuration check over to the
|
||||
* parent.
|
||||
*/
|
||||
isDefaultHandlerApp() {
|
||||
var handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, "pdf");
|
||||
return (!handlerInfo.alwaysAskBeforeHandling &&
|
||||
handlerInfo.preferredAction === Ci.nsIHandlerInfo.handleInternally);
|
||||
},
|
||||
|
||||
/*
|
||||
* Display a notification warning when the renderer isn't sure
|
||||
* a pdf displayed correctly.
|
||||
*/
|
||||
_displayWarning(aMsg) {
|
||||
let data = aMsg.data;
|
||||
let browser = aMsg.target;
|
||||
|
||||
let tabbrowser = browser.getTabBrowser();
|
||||
let notificationBox = tabbrowser.getNotificationBox(browser);
|
||||
|
||||
// Flag so we don't send the message twice, since if the user clicks
|
||||
// "open with different viewer" both the button callback and
|
||||
// eventCallback will be called.
|
||||
let messageSent = false;
|
||||
function sendMessage(download) {
|
||||
let mm = browser.messageManager;
|
||||
mm.sendAsyncMessage("PDFJS:Child:fallbackDownload", { download, });
|
||||
}
|
||||
let buttons = [{
|
||||
label: data.label,
|
||||
accessKey: data.accessKey,
|
||||
callback() {
|
||||
messageSent = true;
|
||||
sendMessage(true);
|
||||
},
|
||||
}];
|
||||
notificationBox.appendNotification(data.message, "pdfjs-fallback", null,
|
||||
notificationBox.PRIORITY_INFO_LOW,
|
||||
buttons,
|
||||
function eventsCallback(eventType) {
|
||||
// Currently there is only one event "removed" but if there are any other
|
||||
// added in the future we still only care about removed at the moment.
|
||||
if (eventType !== "removed") {
|
||||
return;
|
||||
}
|
||||
// Don't send a response again if we already responded when the button was
|
||||
// clicked.
|
||||
if (messageSent) {
|
||||
return;
|
||||
}
|
||||
sendMessage(false);
|
||||
});
|
||||
},
|
||||
};
|
@ -1,137 +0,0 @@
|
||||
/* Copyright 2012 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 = ["PdfjsContentUtils"];
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var PdfjsContentUtils = {
|
||||
_mm: null,
|
||||
|
||||
/*
|
||||
* Public API
|
||||
*/
|
||||
|
||||
get isRemote() {
|
||||
return (Services.appinfo.processType ===
|
||||
Services.appinfo.PROCESS_TYPE_CONTENT);
|
||||
},
|
||||
|
||||
init() {
|
||||
// child *process* mm, or when loaded into the parent for in-content
|
||||
// support the psuedo child process mm 'child PPMM'.
|
||||
if (!this._mm) {
|
||||
this._mm = Services.cpmm;
|
||||
this._mm.addMessageListener("PDFJS:Child:updateSettings", this);
|
||||
|
||||
Services.obs.addObserver(this, "quit-application");
|
||||
}
|
||||
},
|
||||
|
||||
uninit() {
|
||||
if (this._mm) {
|
||||
this._mm.removeMessageListener("PDFJS:Child:updateSettings", this);
|
||||
Services.obs.removeObserver(this, "quit-application");
|
||||
}
|
||||
this._mm = null;
|
||||
},
|
||||
|
||||
/*
|
||||
* prefs utilities - the child does not have write access to prefs.
|
||||
* note, the pref names here are cross-checked against a list of
|
||||
* approved pdfjs prefs in chrome utils.
|
||||
*/
|
||||
|
||||
clearUserPref(aPrefName) {
|
||||
this._mm.sendSyncMessage("PDFJS:Parent:clearUserPref", {
|
||||
name: aPrefName,
|
||||
});
|
||||
},
|
||||
|
||||
setIntPref(aPrefName, aPrefValue) {
|
||||
this._mm.sendSyncMessage("PDFJS:Parent:setIntPref", {
|
||||
name: aPrefName,
|
||||
value: aPrefValue,
|
||||
});
|
||||
},
|
||||
|
||||
setBoolPref(aPrefName, aPrefValue) {
|
||||
this._mm.sendSyncMessage("PDFJS:Parent:setBoolPref", {
|
||||
name: aPrefName,
|
||||
value: aPrefValue,
|
||||
});
|
||||
},
|
||||
|
||||
setCharPref(aPrefName, aPrefValue) {
|
||||
this._mm.sendSyncMessage("PDFJS:Parent:setCharPref", {
|
||||
name: aPrefName,
|
||||
value: aPrefValue,
|
||||
});
|
||||
},
|
||||
|
||||
setStringPref(aPrefName, aPrefValue) {
|
||||
this._mm.sendSyncMessage("PDFJS:Parent:setStringPref", {
|
||||
name: aPrefName,
|
||||
value: aPrefValue,
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
* Request the display of a notification warning in the associated window
|
||||
* when the renderer isn't sure a pdf displayed correctly.
|
||||
*/
|
||||
displayWarning(aWindow, aMessage, aLabel, aAccessKey) {
|
||||
// the child's dom frame mm associated with the window.
|
||||
let winmm = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDocShell)
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIContentFrameMessageManager);
|
||||
winmm.sendAsyncMessage("PDFJS:Parent:displayWarning", {
|
||||
message: aMessage,
|
||||
label: aLabel,
|
||||
accessKey: aAccessKey,
|
||||
});
|
||||
},
|
||||
|
||||
/*
|
||||
* Events
|
||||
*/
|
||||
|
||||
observe(aSubject, aTopic, aData) {
|
||||
if (aTopic === "quit-application") {
|
||||
this.uninit();
|
||||
}
|
||||
},
|
||||
|
||||
receiveMessage(aMsg) {
|
||||
switch (aMsg.name) {
|
||||
case "PDFJS:Child:updateSettings":
|
||||
// Only react to this if we are remote.
|
||||
if (Services.appinfo.processType ===
|
||||
Services.appinfo.PROCESS_TYPE_CONTENT) {
|
||||
let jsm = "resource://pdf.js/PdfJs.jsm";
|
||||
let pdfjs = ChromeUtils.import(jsm, {}).PdfJs;
|
||||
if (aMsg.data.enabled) {
|
||||
pdfjs.ensureRegistered();
|
||||
} else {
|
||||
pdfjs.ensureUnregistered();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
};
|
@ -1,30 +0,0 @@
|
||||
/* Copyright 2014 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";
|
||||
|
||||
/*
|
||||
* pdfjschildbootstrap-enabled.js loads into the content process to
|
||||
* take care of initializing our built-in version of pdfjs when
|
||||
* running remote. It will only be run when PdfJs.enable is true.
|
||||
*/
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.import("resource://pdf.js/PdfJs.jsm");
|
||||
|
||||
if (Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_CONTENT) {
|
||||
// register various pdfjs factories that hook us into content loading.
|
||||
PdfJs.ensureRegistered();
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/* Copyright 2014 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";
|
||||
|
||||
/*
|
||||
* pdfjschildbootstrap.js loads into the content process to take care of
|
||||
* initializing our built-in version of pdfjs when running remote.
|
||||
*/
|
||||
|
||||
ChromeUtils.import("resource://pdf.js/PdfjsContentUtils.jsm");
|
||||
|
||||
// init content utils shim pdfjs will use to access privileged apis.
|
||||
PdfjsContentUtils.init();
|
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.0 KiB |
@ -1,57 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
|
||||
|
||||
<Description about="urn:mozilla:install-manifest">
|
||||
<em:id>viewer@pdf.js</em:id>
|
||||
<!-- PDFJS_LOCALIZED_METADATA -->
|
||||
<em:name>PDF Viewer</em:name>
|
||||
<em:version>PDFJSSCRIPT_VERSION</em:version>
|
||||
|
||||
<!-- Firefox -->
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
|
||||
<em:minVersion>59.0a1</em:minVersion>
|
||||
<em:maxVersion>61.0a1</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
|
||||
<!-- SeaMonkey -->
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id>
|
||||
<em:minVersion>2.46</em:minVersion>
|
||||
<em:maxVersion>2.51a1</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
|
||||
<!-- Android -->
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<em:id>{aa3c5121-dab2-40e2-81ca-7ea25febc110}</em:id>
|
||||
<em:minVersion>59.0a1</em:minVersion>
|
||||
<em:maxVersion>61.0a1</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
|
||||
<!-- Conkeror -->
|
||||
<em:targetApplication>
|
||||
<Description>
|
||||
<em:id>{a79fe89b-6662-4ff4-8e88-09950ad4dfde}</em:id>
|
||||
<em:minVersion>0.1</em:minVersion>
|
||||
<em:maxVersion>9.9</em:maxVersion>
|
||||
</Description>
|
||||
</em:targetApplication>
|
||||
|
||||
<em:bootstrap>true</em:bootstrap>
|
||||
<em:multiprocessCompatible>true</em:multiprocessCompatible>
|
||||
<em:creator>Mozilla</em:creator>
|
||||
<em:description>Uses HTML5 to display PDF files directly in Firefox.</em:description>
|
||||
<em:homepageURL>https://github.com/mozilla/pdf.js/</em:homepageURL>
|
||||
<em:type>2</em:type>
|
||||
<!-- Use the raw link for updates so we we can use SSL. -->
|
||||
<em:updateURL>https://github.com/mozilla/pdf.js/raw/gh-pages/extensions/firefox/update.rdf</em:updateURL>
|
||||
</Description>
|
||||
</RDF>
|
@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
|
||||
|
||||
<RDF:Description about="urn:mozilla:extension:viewer@pdf.js">
|
||||
<em:updates>
|
||||
<RDF:Seq>
|
||||
<RDF:li>
|
||||
<RDF:Description>
|
||||
<em:version>PDFJSSCRIPT_VERSION</em:version>
|
||||
|
||||
<!-- Firefox -->
|
||||
<em:targetApplication>
|
||||
<RDF:Description>
|
||||
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
|
||||
<em:minVersion>59.0a1</em:minVersion>
|
||||
<em:maxVersion>61.0a1</em:maxVersion>
|
||||
<!-- Use the raw link for updates so we we can use SSL. -->
|
||||
<em:updateLink>https://raw.githubusercontent.com/mozilla/pdf.js/gh-pages/extensions/firefox/pdf.js.xpi</em:updateLink>
|
||||
</RDF:Description>
|
||||
</em:targetApplication>
|
||||
|
||||
<!-- Android -->
|
||||
<em:targetApplication>
|
||||
<RDF:Description>
|
||||
<em:id>{aa3c5121-dab2-40e2-81ca-7ea25febc110}</em:id>
|
||||
<em:minVersion>59.0a1</em:minVersion>
|
||||
<em:maxVersion>61.0a1</em:maxVersion>
|
||||
<!-- Use the raw link for updates so we we can use SSL. -->
|
||||
<em:updateLink>https://raw.githubusercontent.com/mozilla/pdf.js/gh-pages/extensions/firefox/pdf.js.xpi</em:updateLink>
|
||||
</RDF:Description>
|
||||
</em:targetApplication>
|
||||
</RDF:Description>
|
||||
</RDF:li>
|
||||
</RDF:Seq>
|
||||
</em:updates>
|
||||
</RDF:Description>
|
||||
</RDF:RDF>
|
173
gulpfile.js
173
gulpfile.js
@ -49,7 +49,6 @@ var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline/';
|
||||
var GENERIC_DIR = BUILD_DIR + 'generic/';
|
||||
var COMPONENTS_DIR = BUILD_DIR + 'components/';
|
||||
var MINIFIED_DIR = BUILD_DIR + 'minified/';
|
||||
var FIREFOX_BUILD_DIR = BUILD_DIR + 'firefox/';
|
||||
var CHROME_BUILD_DIR = BUILD_DIR + 'chromium/';
|
||||
var JSDOC_BUILD_DIR = BUILD_DIR + 'jsdoc/';
|
||||
var GH_PAGES_DIR = BUILD_DIR + 'gh-pages/';
|
||||
@ -175,16 +174,6 @@ function webpack2Stream(config) {
|
||||
return webpackStream(config, webpack2);
|
||||
}
|
||||
|
||||
function stripCommentHeaders(content) {
|
||||
var notEndOfComment = '(?:[^*]|\\*(?!/))+';
|
||||
var reg = new RegExp(
|
||||
'\n/\\* Copyright' + notEndOfComment + '\\*/\\s*' +
|
||||
'(?:/\\*' + notEndOfComment + '\\*/\\s*|//(?!#).*\n\\s*)*' +
|
||||
'\\s*\'use strict\';', 'g');
|
||||
content = content.replace(reg, '');
|
||||
return content;
|
||||
}
|
||||
|
||||
function getVersionJSON() {
|
||||
return JSON.parse(fs.readFileSync(BUILD_DIR + 'version.json').toString());
|
||||
}
|
||||
@ -407,7 +396,7 @@ gulp.task('default', function() {
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('extension', ['firefox', 'chromium']);
|
||||
gulp.task('extension', ['chromium']);
|
||||
|
||||
gulp.task('buildnumber', function (done) {
|
||||
console.log();
|
||||
@ -563,19 +552,6 @@ function preprocessHTML(source, defines) {
|
||||
return createStringSource(source.substr(i + 1), out);
|
||||
}
|
||||
|
||||
function preprocessJS(source, defines, cleanup) {
|
||||
var outName = getTempFile('~preprocess', '.js');
|
||||
builder.preprocess(source, outName, defines);
|
||||
var out = fs.readFileSync(outName).toString();
|
||||
fs.unlinkSync(outName);
|
||||
if (cleanup) {
|
||||
out = stripCommentHeaders(out);
|
||||
}
|
||||
|
||||
var i = source.lastIndexOf('/');
|
||||
return createStringSource(source.substr(i + 1), out);
|
||||
}
|
||||
|
||||
// Builds the generic production viewer that should be compatible with most
|
||||
// modern HTML5 browsers.
|
||||
gulp.task('generic', ['buildnumber', 'locale'], function () {
|
||||
@ -713,118 +689,6 @@ function preprocessDefaultPreferences(content) {
|
||||
return licenseHeader + '\n' + MODIFICATION_WARNING + '\n' + content + '\n';
|
||||
}
|
||||
|
||||
gulp.task('firefox-pre', ['buildnumber', 'locale'], function () {
|
||||
console.log();
|
||||
console.log('### Building Firefox extension');
|
||||
var defines = builder.merge(DEFINES, { FIREFOX: true, SKIP_BABEL: true, });
|
||||
|
||||
var FIREFOX_BUILD_CONTENT_DIR = FIREFOX_BUILD_DIR + '/content/',
|
||||
FIREFOX_EXTENSION_DIR = 'extensions/firefox/',
|
||||
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/',
|
||||
FIREFOX_PREF_PREFIX = 'extensions.uriloader@pdf.js',
|
||||
FIREFOX_STREAM_CONVERTER_ID = '6457a96b-2d68-439a-bcfa-44465fbcdbb1',
|
||||
FIREFOX_STREAM_CONVERTER2_ID = '6457a96b-2d68-439a-bcfa-44465fbcdbb2';
|
||||
|
||||
// Clear out everything in the firefox extension build directory
|
||||
rimraf.sync(FIREFOX_BUILD_DIR);
|
||||
|
||||
var localizedMetadata =
|
||||
fs.readFileSync(FIREFOX_EXTENSION_DIR + 'metadata.inc').toString();
|
||||
var chromeManifestLocales =
|
||||
fs.readFileSync(FIREFOX_EXTENSION_DIR + 'chrome.manifest.inc').toString();
|
||||
var version = getVersionJSON().version;
|
||||
|
||||
return merge([
|
||||
createBundle(defines).pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR + 'build')),
|
||||
createWebBundle(defines).pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR + 'web')),
|
||||
gulp.src(COMMON_WEB_FILES, { base: 'web/', })
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR + 'web')),
|
||||
gulp.src(FIREFOX_EXTENSION_DIR + 'locale/**/*.properties',
|
||||
{ base: FIREFOX_EXTENSION_DIR, })
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_DIR)),
|
||||
gulp.src(['external/bcmaps/*.bcmap', 'external/bcmaps/LICENSE'],
|
||||
{ base: 'external/bcmaps', })
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR + 'web/cmaps')),
|
||||
|
||||
preprocessHTML('web/viewer.html', defines)
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR + 'web')),
|
||||
preprocessCSS('web/viewer.css', 'firefox', defines, true)
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR + 'web')),
|
||||
|
||||
gulp.src(FIREFOX_CONTENT_DIR + 'PdfJs-stub.jsm')
|
||||
.pipe(rename('PdfJs.jsm'))
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR)),
|
||||
gulp.src(FIREFOX_CONTENT_DIR + 'PdfJsTelemetry-stub.jsm')
|
||||
.pipe(rename('PdfJsTelemetry.jsm'))
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR)),
|
||||
gulp.src(FIREFOX_EXTENSION_DIR + '*.png')
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_DIR)),
|
||||
gulp.src(FIREFOX_EXTENSION_DIR + 'chrome.manifest')
|
||||
.pipe(replace(/#.*PDFJS_SUPPORTED_LOCALES.*\n/, chromeManifestLocales))
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_DIR)),
|
||||
gulp.src(FIREFOX_EXTENSION_DIR + '*.rdf')
|
||||
.pipe(replace(/\bPDFJSSCRIPT_VERSION\b/g, version))
|
||||
.pipe(replace(/.*<!--\s*PDFJS_LOCALIZED_METADATA\s*-->.*\n/,
|
||||
localizedMetadata))
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_DIR)),
|
||||
gulp.src(FIREFOX_EXTENSION_DIR + 'chrome/content.js',
|
||||
{ base: FIREFOX_EXTENSION_DIR, })
|
||||
.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))
|
||||
.pipe(replace(/\bPDFJSSCRIPT_STREAM_CONVERTER2_ID\b/g,
|
||||
FIREFOX_STREAM_CONVERTER2_ID))
|
||||
.pipe(replace(/\bPDFJSSCRIPT_PREF_PREFIX\b/g, FIREFOX_PREF_PREFIX))
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfJsNetwork.jsm', defines, true)
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfjsContentUtils.jsm', defines, true)
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfjsChromeUtils.jsm', defines, true)
|
||||
.pipe(replace(/\bPDFJSSCRIPT_PREF_PREFIX\b/g, FIREFOX_PREF_PREFIX))
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_EXTENSION_DIR + 'bootstrap.js', defines, true)
|
||||
.pipe(gulp.dest(FIREFOX_BUILD_DIR)),
|
||||
]);
|
||||
});
|
||||
|
||||
gulp.task('firefox', ['firefox-pre'], function (done) {
|
||||
var FIREFOX_EXTENSION_FILES =
|
||||
['bootstrap.js',
|
||||
'install.rdf',
|
||||
'chrome.manifest',
|
||||
'icon.png',
|
||||
'icon64.png',
|
||||
'content',
|
||||
'chrome',
|
||||
'locale',
|
||||
'LICENSE'],
|
||||
FIREFOX_EXTENSION_NAME = 'pdf.js.xpi';
|
||||
|
||||
var zipExecOptions = {
|
||||
cwd: FIREFOX_BUILD_DIR,
|
||||
// Set timezone to UTC before calling zip to get reproducible results.
|
||||
env: { 'TZ': 'UTC', },
|
||||
};
|
||||
|
||||
exec('zip -r ' + FIREFOX_EXTENSION_NAME + ' ' +
|
||||
FIREFOX_EXTENSION_FILES.join(' '), zipExecOptions, function (err) {
|
||||
if (err) {
|
||||
done(new Error('Cannot exec zip: ' + err));
|
||||
return;
|
||||
}
|
||||
console.log('extension created: ' + FIREFOX_EXTENSION_NAME);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('mozcentral-pre', ['buildnumber', 'locale'], function () {
|
||||
console.log();
|
||||
console.log('### Building mozilla-central extension');
|
||||
@ -835,10 +699,7 @@ gulp.task('mozcentral-pre', ['buildnumber', 'locale'], function () {
|
||||
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_PREF_PREFIX = 'pdfjs',
|
||||
MOZCENTRAL_STREAM_CONVERTER_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2291',
|
||||
MOZCENTRAL_STREAM_CONVERTER2_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2292';
|
||||
FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + '/firefox/content/';
|
||||
|
||||
// Clear out everything in the firefox extension build directory
|
||||
rimraf.sync(MOZCENTRAL_DIR);
|
||||
@ -860,15 +721,6 @@ gulp.task('mozcentral-pre', ['buildnumber', 'locale'], function () {
|
||||
preprocessCSS('web/viewer.css', 'mozcentral', defines, true)
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + 'web')),
|
||||
|
||||
gulp.src(FIREFOX_CONTENT_DIR + 'PdfJsTelemetry.jsm')
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
gulp.src(FIREFOX_CONTENT_DIR + 'pdfjschildbootstrap.js')
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
gulp.src(FIREFOX_CONTENT_DIR + 'pdfjschildbootstrap-enabled.js')
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
gulp.src(FIREFOX_EXTENSION_DIR + 'chrome-mozcentral.manifest')
|
||||
.pipe(rename('chrome.manifest'))
|
||||
.pipe(gulp.dest(MOZCENTRAL_EXTENSION_DIR)),
|
||||
gulp.src(FIREFOX_EXTENSION_DIR + 'locale/en-US/*.properties')
|
||||
.pipe(gulp.dest(MOZCENTRAL_L10N_DIR)),
|
||||
gulp.src(FIREFOX_EXTENSION_DIR + 'README.mozilla')
|
||||
@ -876,27 +728,9 @@ gulp.task('mozcentral-pre', ['buildnumber', 'locale'], function () {
|
||||
.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)),
|
||||
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfJs.jsm', defines, true)
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfStreamConverter.jsm', defines, true)
|
||||
.pipe(replace(/\bPDFJSSCRIPT_STREAM_CONVERTER_ID\b/g,
|
||||
MOZCENTRAL_STREAM_CONVERTER_ID))
|
||||
.pipe(replace(/\bPDFJSSCRIPT_STREAM_CONVERTER2_ID\b/g,
|
||||
MOZCENTRAL_STREAM_CONVERTER2_ID))
|
||||
.pipe(replace(/\bPDFJSSCRIPT_PREF_PREFIX\b/g, MOZCENTRAL_PREF_PREFIX))
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfJsNetwork.jsm', defines, true)
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfjsContentUtils.jsm', defines, true)
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
preprocessJS(FIREFOX_CONTENT_DIR + 'PdfjsChromeUtils.jsm', defines, true)
|
||||
.pipe(replace(/\bPDFJSSCRIPT_PREF_PREFIX\b/g, MOZCENTRAL_PREF_PREFIX))
|
||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR)),
|
||||
]);
|
||||
});
|
||||
|
||||
@ -1233,9 +1067,6 @@ gulp.task('gh-pages-prepare', ['web-pre'], function () {
|
||||
return merge([
|
||||
vfs.src(GENERIC_DIR + '**/*', { base: GENERIC_DIR, stripBOM: false, })
|
||||
.pipe(gulp.dest(GH_PAGES_DIR)),
|
||||
gulp.src([FIREFOX_BUILD_DIR + '*.xpi',
|
||||
FIREFOX_BUILD_DIR + '*.rdf'])
|
||||
.pipe(gulp.dest(GH_PAGES_DIR + EXTENSION_SRC_DIR + 'firefox/')),
|
||||
gulp.src(CHROME_BUILD_DIR + '*.crx')
|
||||
.pipe(gulp.dest(GH_PAGES_DIR + EXTENSION_SRC_DIR + 'chromium/')),
|
||||
gulp.src('test/features/**/*', { base: 'test/', })
|
||||
|
Loading…
Reference in New Issue
Block a user