diff --git a/README.md b/README.md index e2a28ae02ce6d..e49790b9e4bf8 100644 --- a/README.md +++ b/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 diff --git a/extensions/firefox/bootstrap.js b/extensions/firefox/bootstrap.js deleted file mode 100644 index 9fc4819939127..0000000000000 --- a/extensions/firefox/bootstrap.js +++ /dev/null @@ -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) { -} diff --git a/extensions/firefox/chrome-mozcentral.manifest b/extensions/firefox/chrome-mozcentral.manifest deleted file mode 100644 index 1aef83abc48a7..0000000000000 --- a/extensions/firefox/chrome-mozcentral.manifest +++ /dev/null @@ -1 +0,0 @@ -resource pdf.js content/ diff --git a/extensions/firefox/chrome.manifest b/extensions/firefox/chrome.manifest deleted file mode 100644 index 1a92e73ac9080..0000000000000 --- a/extensions/firefox/chrome.manifest +++ /dev/null @@ -1,5 +0,0 @@ -# Additional resources for pdf.js - -content pdf.js chrome/ - -# PDFJS_SUPPORTED_LOCALES diff --git a/extensions/firefox/chrome/content.js b/extensions/firefox/chrome/content.js deleted file mode 100644 index 44bc792af211d..0000000000000 --- a/extensions/firefox/chrome/content.js +++ /dev/null @@ -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(); - }); - } -})(); diff --git a/extensions/firefox/content/PdfJs-stub.jsm b/extensions/firefox/content/PdfJs-stub.jsm deleted file mode 100644 index cea1a6e1b28f6..0000000000000 --- a/extensions/firefox/content/PdfJs-stub.jsm +++ /dev/null @@ -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() {}, -}; diff --git a/extensions/firefox/content/PdfJs.jsm b/extensions/firefox/content/PdfJs.jsm deleted file mode 100644 index fd905086c44c2..0000000000000 --- a/extensions/firefox/content/PdfJs.jsm +++ /dev/null @@ -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; - }, -}; diff --git a/extensions/firefox/content/PdfJsNetwork.jsm b/extensions/firefox/content/PdfJsNetwork.jsm deleted file mode 100644 index 64523aeb11384..0000000000000 --- a/extensions/firefox/content/PdfJsNetwork.jsm +++ /dev/null @@ -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; -})(); diff --git a/extensions/firefox/content/PdfJsTelemetry-stub.jsm b/extensions/firefox/content/PdfJsTelemetry-stub.jsm deleted file mode 100644 index 69f4a18443e88..0000000000000 --- a/extensions/firefox/content/PdfJsTelemetry-stub.jsm +++ /dev/null @@ -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) { - }, -}; diff --git a/extensions/firefox/content/PdfJsTelemetry.jsm b/extensions/firefox/content/PdfJsTelemetry.jsm deleted file mode 100644 index 0436debd20d05..0000000000000 --- a/extensions/firefox/content/PdfJsTelemetry.jsm +++ /dev/null @@ -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); - }, -}; diff --git a/extensions/firefox/content/PdfStreamConverter.jsm b/extensions/firefox/content/PdfStreamConverter.jsm deleted file mode 100644 index 613553c48a2d0..0000000000000 --- a/extensions/firefox/content/PdfStreamConverter.jsm +++ /dev/null @@ -1,1038 +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 = ["PdfStreamConverter"]; - -const PDFJS_EVENT_ID = "pdf.js.message"; -const PREF_PREFIX = "PDFJSSCRIPT_PREF_PREFIX"; -const PDF_VIEWER_WEB_PAGE = "resource://pdf.js/web/viewer.html"; -const MAX_NUMBER_OF_PREFS = 50; -const MAX_STRING_PREF_LENGTH = 128; - -ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -ChromeUtils.import("resource://gre/modules/Services.jsm"); - -ChromeUtils.defineModuleGetter(this, "NetUtil", - "resource://gre/modules/NetUtil.jsm"); - -ChromeUtils.defineModuleGetter(this, "NetworkManager", - "resource://pdf.js/PdfJsNetwork.jsm"); - -ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils", - "resource://gre/modules/PrivateBrowsingUtils.jsm"); - -ChromeUtils.defineModuleGetter(this, "PdfJsTelemetry", - "resource://pdf.js/PdfJsTelemetry.jsm"); - -ChromeUtils.defineModuleGetter(this, "PdfjsContentUtils", - "resource://pdf.js/PdfjsContentUtils.jsm"); - -Cu.importGlobalProperties(["XMLHttpRequest"]); - -var Svc = {}; -XPCOMUtils.defineLazyServiceGetter(Svc, "mime", - "@mozilla.org/mime;1", - "nsIMIMEService"); - -function getContainingBrowser(domWindow) { - return domWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsIDocShell) - .chromeEventHandler; -} - -function getFindBar(domWindow) { - if (PdfjsContentUtils.isRemote) { - throw new Error("FindBar is not accessible from the content process."); - } - try { - var browser = getContainingBrowser(domWindow); - var tabbrowser = browser.getTabBrowser(); - var tab = tabbrowser.getTabForBrowser(browser); - return tabbrowser.getFindBar(tab); - } catch (e) { - // Suppress errors for PDF files opened in the bookmark sidebar, see - // https://bugzilla.mozilla.org/show_bug.cgi?id=1248959. - return null; - } -} - -function getBoolPref(pref, def) { - try { - return Services.prefs.getBoolPref(pref); - } catch (ex) { - return def; - } -} - -function getIntPref(pref, def) { - try { - return Services.prefs.getIntPref(pref); - } catch (ex) { - return def; - } -} - -function getStringPref(pref, def) { - try { - return Services.prefs.getStringPref(pref); - } catch (ex) { - return def; - } -} - -function log(aMsg) { - if (!getBoolPref(PREF_PREFIX + ".pdfBugEnabled", false)) { - return; - } - var msg = "PdfStreamConverter.js: " + (aMsg.join ? aMsg.join("") : aMsg); - Services.console.logStringMessage(msg); - dump(msg + "\n"); -} - -function getDOMWindow(aChannel) { - var requestor = aChannel.notificationCallbacks ? - aChannel.notificationCallbacks : - aChannel.loadGroup.notificationCallbacks; - var win = requestor.getInterface(Ci.nsIDOMWindow); - return win; -} - -function getLocalizedStrings(path) { - var stringBundle = - Services.strings.createBundle("chrome://pdf.js/locale/" + path); - - var map = {}; - var enumerator = stringBundle.getSimpleEnumeration(); - while (enumerator.hasMoreElements()) { - var string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement); - var key = string.key, property = "textContent"; - var i = key.lastIndexOf("."); - if (i >= 0) { - property = key.substring(i + 1); - key = key.substring(0, i); - } - if (!(key in map)) { - map[key] = {}; - } - map[key][property] = string.value; - } - return map; -} -function getLocalizedString(strings, id, property) { - property = property || "textContent"; - if (id in strings) { - return strings[id][property]; - } - return id; -} - -// PDF data storage -function PdfDataListener(length) { - this.length = length; // less than 0, if length is unknown - this.buffers = []; - this.loaded = 0; -} - -PdfDataListener.prototype = { - append: function PdfDataListener_append(chunk) { - // In most of the cases we will pass data as we receive it, but at the - // beginning of the loading we may accumulate some data. - this.buffers.push(chunk); - this.loaded += chunk.length; - if (this.length >= 0 && this.length < this.loaded) { - this.length = -1; // reset the length, server is giving incorrect one - } - this.onprogress(this.loaded, this.length >= 0 ? this.length : void 0); - }, - readData: function PdfDataListener_readData() { - if (this.buffers.length === 0) { - return null; - } - if (this.buffers.length === 1) { - return this.buffers.pop(); - } - // There are multiple buffers that need to be combined into a single - // buffer. - let combinedLength = 0; - for (let buffer of this.buffers) { - combinedLength += buffer.length; - } - let combinedArray = new Uint8Array(combinedLength); - let writeOffset = 0; - while (this.buffers.length) { - let buffer = this.buffers.shift(); - combinedArray.set(buffer, writeOffset); - writeOffset += buffer.length; - } - return combinedArray; - }, - finish: function PdfDataListener_finish() { - this.isDataReady = true; - if (this.oncompleteCallback) { - this.oncompleteCallback(this.readData()); - } - }, - error: function PdfDataListener_error(errorCode) { - this.errorCode = errorCode; - if (this.oncompleteCallback) { - this.oncompleteCallback(null, errorCode); - } - }, - onprogress() {}, - get oncomplete() { - return this.oncompleteCallback; - }, - set oncomplete(value) { - this.oncompleteCallback = value; - if (this.isDataReady) { - value(this.readData()); - } - if (this.errorCode) { - value(null, this.errorCode); - } - }, -}; - -/** - * All the privileged actions. - */ -class ChromeActions { - constructor(domWindow, contentDispositionFilename) { - this.domWindow = domWindow; - this.contentDispositionFilename = contentDispositionFilename; - this.telemetryState = { - documentInfo: false, - firstPageInfo: false, - streamTypesUsed: [], - fontTypesUsed: [], - startAt: Date.now(), - }; - } - - isInPrivateBrowsing() { - return PrivateBrowsingUtils.isContentWindowPrivate(this.domWindow); - } - - download(data, sendResponse) { - var self = this; - var originalUrl = data.originalUrl; - var blobUrl = data.blobUrl || originalUrl; - // The data may not be downloaded so we need just retry getting the pdf with - // the original url. - var originalUri = NetUtil.newURI(originalUrl); - var filename = data.filename; - if (typeof filename !== "string" || - (!/\.pdf$/i.test(filename) && !data.isAttachment)) { - filename = "document.pdf"; - } - var blobUri = NetUtil.newURI(blobUrl); - var extHelperAppSvc = - Cc["@mozilla.org/uriloader/external-helper-app-service;1"]. - getService(Ci.nsIExternalHelperAppService); - - var docIsPrivate = this.isInPrivateBrowsing(); - var netChannel = NetUtil.newChannel({ - uri: blobUri, - loadUsingSystemPrincipal: true, - }); - if ("nsIPrivateBrowsingChannel" in Ci && - netChannel instanceof Ci.nsIPrivateBrowsingChannel) { - netChannel.setPrivate(docIsPrivate); - } - NetUtil.asyncFetch(netChannel, function(aInputStream, aResult) { - if (!Components.isSuccessCode(aResult)) { - if (sendResponse) { - sendResponse(true); - } - return; - } - // Create a nsIInputStreamChannel so we can set the url on the channel - // so the filename will be correct. - var channel = Cc["@mozilla.org/network/input-stream-channel;1"]. - createInstance(Ci.nsIInputStreamChannel); - channel.QueryInterface(Ci.nsIChannel); - try { - // contentDisposition/contentDispositionFilename is readonly before FF18 - channel.contentDisposition = Ci.nsIChannel.DISPOSITION_ATTACHMENT; - if (self.contentDispositionFilename && !data.isAttachment) { - channel.contentDispositionFilename = self.contentDispositionFilename; - } else { - channel.contentDispositionFilename = filename; - } - } catch (e) {} - channel.setURI(originalUri); - channel.loadInfo = netChannel.loadInfo; - channel.contentStream = aInputStream; - if ("nsIPrivateBrowsingChannel" in Ci && - channel instanceof Ci.nsIPrivateBrowsingChannel) { - channel.setPrivate(docIsPrivate); - } - - var listener = { - extListener: null, - onStartRequest(aRequest, aContext) { - var loadContext = self.domWindow - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsILoadContext); - this.extListener = extHelperAppSvc.doContent( - (data.isAttachment ? "application/octet-stream" : - "application/pdf"), - aRequest, loadContext, false); - this.extListener.onStartRequest(aRequest, aContext); - }, - onStopRequest(aRequest, aContext, aStatusCode) { - if (this.extListener) { - this.extListener.onStopRequest(aRequest, aContext, aStatusCode); - } - // Notify the content code we're done downloading. - if (sendResponse) { - sendResponse(false); - } - }, - onDataAvailable(aRequest, aContext, aDataInputStream, aOffset, aCount) { - this.extListener.onDataAvailable(aRequest, aContext, aDataInputStream, - aOffset, aCount); - }, - }; - - channel.asyncOpen2(listener); - }); - } - - getLocale() { - return Services.locale.getRequestedLocale() || "en-US"; - } - - getStrings(data) { - try { - // Lazy initialization of localizedStrings - if (!("localizedStrings" in this)) { - this.localizedStrings = getLocalizedStrings("viewer.properties"); - } - var result = this.localizedStrings[data]; - return JSON.stringify(result || null); - } catch (e) { - log("Unable to retrieve localized strings: " + e); - return "null"; - } - } - - supportsIntegratedFind() { - // Integrated find is only supported when we're not in a frame - if (this.domWindow.frameElement !== null) { - return false; - } - - // ... and we are in a child process - if (PdfjsContentUtils.isRemote) { - return true; - } - - // ... or when the new find events code exists. - var findBar = getFindBar(this.domWindow); - return !!findBar && ("updateControlState" in findBar); - } - - supportsDocumentFonts() { - var prefBrowser = getIntPref("browser.display.use_document_fonts", 1); - var prefGfx = getBoolPref("gfx.downloadable_fonts.enabled", true); - return (!!prefBrowser && prefGfx); - } - - supportsDocumentColors() { - return getIntPref("browser.display.document_color_use", 0) !== 2; - } - - supportedMouseWheelZoomModifierKeys() { - return { - ctrlKey: getIntPref("mousewheel.with_control.action", 3) === 3, - metaKey: getIntPref("mousewheel.with_meta.action", 1) === 3, - }; - } - - reportTelemetry(data) { - var probeInfo = JSON.parse(data); - switch (probeInfo.type) { - case "documentInfo": - if (!this.telemetryState.documentInfo) { - PdfJsTelemetry.onDocumentVersion(probeInfo.version | 0); - PdfJsTelemetry.onDocumentGenerator(probeInfo.generator | 0); - if (probeInfo.formType) { - PdfJsTelemetry.onForm(probeInfo.formType === "acroform"); - } - this.telemetryState.documentInfo = true; - } - break; - case "pageInfo": - if (!this.telemetryState.firstPageInfo) { - var duration = Date.now() - this.telemetryState.startAt; - PdfJsTelemetry.onTimeToView(duration); - this.telemetryState.firstPageInfo = true; - } - break; - case "documentStats": - // documentStats can be called several times for one documents. - // if stream/font types are reported, trying not to submit the same - // enumeration value multiple times. - var documentStats = probeInfo.stats; - if (!documentStats || typeof documentStats !== "object") { - break; - } - var i, streamTypes = documentStats.streamTypes; - if (Array.isArray(streamTypes)) { - var STREAM_TYPE_ID_LIMIT = 20; - for (i = 0; i < STREAM_TYPE_ID_LIMIT; i++) { - if (streamTypes[i] && - !this.telemetryState.streamTypesUsed[i]) { - PdfJsTelemetry.onStreamType(i); - this.telemetryState.streamTypesUsed[i] = true; - } - } - } - var fontTypes = documentStats.fontTypes; - if (Array.isArray(fontTypes)) { - var FONT_TYPE_ID_LIMIT = 20; - for (i = 0; i < FONT_TYPE_ID_LIMIT; i++) { - if (fontTypes[i] && - !this.telemetryState.fontTypesUsed[i]) { - PdfJsTelemetry.onFontType(i); - this.telemetryState.fontTypesUsed[i] = true; - } - } - } - break; - case "print": - PdfJsTelemetry.onPrint(); - break; - } - } - - /** - * @param {Object} args - Object with `featureId` and `url` properties. - * @param {function} sendResponse - Callback function. - */ - fallback(args, sendResponse) { - var featureId = args.featureId; - - var domWindow = this.domWindow; - var strings = getLocalizedStrings("chrome.properties"); - var message; - if (featureId === "forms") { - message = getLocalizedString(strings, "unsupported_feature_forms"); - } else { - message = getLocalizedString(strings, "unsupported_feature"); - } - PdfJsTelemetry.onFallback(); - PdfjsContentUtils.displayWarning(domWindow, message, - getLocalizedString(strings, "open_with_different_viewer"), - getLocalizedString(strings, "open_with_different_viewer", "accessKey")); - - let winmm = domWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDocShell) - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIContentFrameMessageManager); - - winmm.addMessageListener("PDFJS:Child:fallbackDownload", - function fallbackDownload(msg) { - let data = msg.data; - sendResponse(data.download); - - winmm.removeMessageListener("PDFJS:Child:fallbackDownload", - fallbackDownload); - }); - } - - updateFindControlState(data) { - if (!this.supportsIntegratedFind()) { - return; - } - // Verify what we're sending to the findbar. - var result = data.result; - var findPrevious = data.findPrevious; - var findPreviousType = typeof findPrevious; - if ((typeof result !== "number" || result < 0 || result > 3) || - (findPreviousType !== "undefined" && findPreviousType !== "boolean")) { - return; - } - - var winmm = this.domWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDocShell) - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIContentFrameMessageManager); - - winmm.sendAsyncMessage("PDFJS:Parent:updateControlState", data); - } - - setPreferences(prefs, sendResponse) { - var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + "."); - var numberOfPrefs = 0; - var prefValue, prefName; - for (var key in prefs) { - if (++numberOfPrefs > MAX_NUMBER_OF_PREFS) { - log("setPreferences - Exceeded the maximum number of preferences " + - "that is allowed to be set at once."); - break; - } else if (!defaultBranch.getPrefType(key)) { - continue; - } - prefValue = prefs[key]; - prefName = (PREF_PREFIX + "." + key); - switch (typeof prefValue) { - case "boolean": - PdfjsContentUtils.setBoolPref(prefName, prefValue); - break; - case "number": - PdfjsContentUtils.setIntPref(prefName, prefValue); - break; - case "string": - if (prefValue.length > MAX_STRING_PREF_LENGTH) { - log("setPreferences - Exceeded the maximum allowed length " + - "for a string preference."); - } else { - PdfjsContentUtils.setStringPref(prefName, prefValue); - } - break; - } - } - if (sendResponse) { - sendResponse(true); - } - } - - getPreferences(prefs, sendResponse) { - var defaultBranch = Services.prefs.getDefaultBranch(PREF_PREFIX + "."); - var currentPrefs = {}, numberOfPrefs = 0; - var prefValue, prefName; - for (var key in prefs) { - if (++numberOfPrefs > MAX_NUMBER_OF_PREFS) { - log("getPreferences - Exceeded the maximum number of preferences " + - "that is allowed to be fetched at once."); - break; - } else if (!defaultBranch.getPrefType(key)) { - continue; - } - prefValue = prefs[key]; - prefName = (PREF_PREFIX + "." + key); - switch (typeof prefValue) { - case "boolean": - currentPrefs[key] = getBoolPref(prefName, prefValue); - break; - case "number": - currentPrefs[key] = getIntPref(prefName, prefValue); - break; - case "string": - currentPrefs[key] = getStringPref(prefName, prefValue); - break; - } - } - let result = JSON.stringify(currentPrefs); - if (sendResponse) { - sendResponse(result); - } - return result; - } -} - -/** - * This is for range requests. - */ -class RangedChromeActions extends ChromeActions { - constructor(domWindow, contentDispositionFilename, originalRequest, - rangeEnabled, streamingEnabled, dataListener) { - - super(domWindow, contentDispositionFilename); - this.dataListener = dataListener; - this.originalRequest = originalRequest; - this.rangeEnabled = rangeEnabled; - this.streamingEnabled = streamingEnabled; - - this.pdfUrl = originalRequest.URI.spec; - this.contentLength = originalRequest.contentLength; - - // Pass all the headers from the original request through - var httpHeaderVisitor = { - headers: {}, - visitHeader(aHeader, aValue) { - if (aHeader === "Range") { - // When loading the PDF from cache, firefox seems to set the Range - // request header to fetch only the unfetched portions of the file - // (e.g. 'Range: bytes=1024-'). However, we want to set this header - // manually to fetch the PDF in chunks. - return; - } - this.headers[aHeader] = aValue; - }, - }; - if (originalRequest.visitRequestHeaders) { - originalRequest.visitRequestHeaders(httpHeaderVisitor); - } - - var self = this; - var xhr_onreadystatechange = function xhr_onreadystatechange() { - if (this.readyState === 1) { // LOADING - var netChannel = this.channel; - if ("nsIPrivateBrowsingChannel" in Ci && - netChannel instanceof Ci.nsIPrivateBrowsingChannel) { - var docIsPrivate = self.isInPrivateBrowsing(); - netChannel.setPrivate(docIsPrivate); - } - } - }; - var getXhr = function getXhr() { - var xhr = new XMLHttpRequest(); - xhr.addEventListener("readystatechange", xhr_onreadystatechange); - return xhr; - }; - - this.networkManager = new NetworkManager(this.pdfUrl, { - httpHeaders: httpHeaderVisitor.headers, - getXhr, - }); - - // If we are in range request mode, this means we manually issued xhr - // requests, which we need to abort when we leave the page - domWindow.addEventListener("unload", function unload(e) { - domWindow.removeEventListener(e.type, unload); - self.abortLoading(); - }); - } - - initPassiveLoading() { - var data; - if (!this.streamingEnabled) { - this.originalRequest.cancel(Cr.NS_BINDING_ABORTED); - this.originalRequest = null; - data = this.dataListener.readData(); - this.dataListener = null; - } else { - data = this.dataListener.readData(); - - this.dataListener.onprogress = (loaded, total) => { - this.domWindow.postMessage({ - pdfjsLoadAction: "progressiveRead", - loaded, - total, - chunk: this.dataListener.readData(), - }, "*"); - }; - this.dataListener.oncomplete = () => { - this.dataListener = null; - }; - } - - this.domWindow.postMessage({ - pdfjsLoadAction: "supportsRangedLoading", - rangeEnabled: this.rangeEnabled, - streamingEnabled: this.streamingEnabled, - pdfUrl: this.pdfUrl, - length: this.contentLength, - data, - }, "*"); - - return true; - } - - requestDataRange(args) { - if (!this.rangeEnabled) { - return; - } - - var begin = args.begin; - var end = args.end; - var domWindow = this.domWindow; - // TODO(mack): Support error handler. We're not currently not handling - // errors from chrome code for non-range requests, so this doesn't - // seem high-pri - this.networkManager.requestRange(begin, end, { - onDone: function RangedChromeActions_onDone(aArgs) { - domWindow.postMessage({ - pdfjsLoadAction: "range", - begin: aArgs.begin, - chunk: aArgs.chunk, - }, "*"); - }, - onProgress: function RangedChromeActions_onProgress(evt) { - domWindow.postMessage({ - pdfjsLoadAction: "rangeProgress", - loaded: evt.loaded, - }, "*"); - }, - }); - } - - abortLoading() { - this.networkManager.abortAllRequests(); - if (this.originalRequest) { - this.originalRequest.cancel(Cr.NS_BINDING_ABORTED); - this.originalRequest = null; - } - this.dataListener = null; - } -} - -/** - * This is for a single network stream. - */ -class StandardChromeActions extends ChromeActions { - constructor(domWindow, contentDispositionFilename, originalRequest, - dataListener) { - super(domWindow, contentDispositionFilename); - this.originalRequest = originalRequest; - this.dataListener = dataListener; - } - - initPassiveLoading() { - if (!this.dataListener) { - return false; - } - - this.dataListener.onprogress = (loaded, total) => { - this.domWindow.postMessage({ - pdfjsLoadAction: "progress", - loaded, - total, - }, "*"); - }; - - this.dataListener.oncomplete = (data, errorCode) => { - this.domWindow.postMessage({ - pdfjsLoadAction: "complete", - data, - errorCode, - }, "*"); - - this.dataListener = null; - this.originalRequest = null; - }; - - return true; - } - - abortLoading() { - if (this.originalRequest) { - this.originalRequest.cancel(Cr.NS_BINDING_ABORTED); - this.originalRequest = null; - } - this.dataListener = null; - } -} - -/** - * Event listener to trigger chrome privileged code. - */ -class RequestListener { - constructor(actions) { - this.actions = actions; - } - - // Receive an event and synchronously or asynchronously responds. - receive(event) { - var message = event.target; - var doc = message.ownerDocument; - var action = event.detail.action; - var data = event.detail.data; - var sync = event.detail.sync; - var actions = this.actions; - if (!(action in actions)) { - log("Unknown action: " + action); - return; - } - var response; - if (sync) { - response = actions[action].call(this.actions, data); - event.detail.response = Cu.cloneInto(response, doc.defaultView); - } else { - if (!event.detail.responseExpected) { - doc.documentElement.removeChild(message); - response = null; - } else { - response = function sendResponse(aResponse) { - try { - var listener = doc.createEvent("CustomEvent"); - let detail = Cu.cloneInto({ response: aResponse, }, - doc.defaultView); - listener.initCustomEvent("pdf.js.response", true, false, detail); - return message.dispatchEvent(listener); - } catch (e) { - // doc is no longer accessible because the requestor is already - // gone. unloaded content cannot receive the response anyway. - return false; - } - }; - } - actions[action].call(this.actions, data, response); - } - } -} - -/** - * Forwards events from the eventElement to the contentWindow only if the - * content window matches the currently selected browser window. - */ -class FindEventManager { - constructor(contentWindow) { - this.contentWindow = contentWindow; - this.winmm = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDocShell) - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIContentFrameMessageManager); - } - - bind() { - var unload = (evt) => { - this.unbind(); - this.contentWindow.removeEventListener(evt.type, unload); - }; - this.contentWindow.addEventListener("unload", unload); - - // We cannot directly attach listeners to for the find events - // since the FindBar is in the parent process. Instead we're - // asking the PdfjsChromeUtils to do it for us and forward - // all the find events to us. - this.winmm.sendAsyncMessage("PDFJS:Parent:addEventListener"); - this.winmm.addMessageListener("PDFJS:Child:handleEvent", this); - } - - receiveMessage(msg) { - var detail = msg.data.detail; - var type = msg.data.type; - var contentWindow = this.contentWindow; - - detail = Cu.cloneInto(detail, contentWindow); - var forward = contentWindow.document.createEvent("CustomEvent"); - forward.initCustomEvent(type, true, true, detail); - contentWindow.dispatchEvent(forward); - } - - unbind() { - this.winmm.sendAsyncMessage("PDFJS:Parent:removeEventListener"); - } -} - -function PdfStreamConverter() { -} - -PdfStreamConverter.prototype = { - - // properties required for XPCOM registration: - classID: Components.ID("{PDFJSSCRIPT_STREAM_CONVERTER_ID}"), - classDescription: "pdf.js Component", - contractID: "@mozilla.org/streamconv;1?from=application/pdf&to=*/*", - - classID2: Components.ID("{PDFJSSCRIPT_STREAM_CONVERTER2_ID}"), - contractID2: "@mozilla.org/streamconv;1?from=application/pdf&to=text/html", - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsISupports, - Ci.nsIStreamConverter, - Ci.nsIStreamListener, - Ci.nsIRequestObserver - ]), - - /* - * This component works as such: - * 1. asyncConvertData stores the listener - * 2. onStartRequest creates a new channel, streams the viewer - * 3. If range requests are supported: - * 3.1. Leave the request open until the viewer is ready to switch to - * range requests. - * - * If range rquests are not supported: - * 3.1. Read the stream as it's loaded in onDataAvailable to send - * to the viewer - * - * The convert function just returns the stream, it's just the synchronous - * version of asyncConvertData. - */ - - // nsIStreamConverter::convert - convert(aFromStream, aFromType, aToType, aCtxt) { - throw Cr.NS_ERROR_NOT_IMPLEMENTED; - }, - - // nsIStreamConverter::asyncConvertData - asyncConvertData(aFromType, aToType, aListener, aCtxt) { - // Store the listener passed to us - this.listener = aListener; - }, - - // nsIStreamListener::onDataAvailable - onDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount) { - if (!this.dataListener) { - return; - } - - var binaryStream = this.binaryStream; - binaryStream.setInputStream(aInputStream); - let chunk = new ArrayBuffer(aCount); - binaryStream.readArrayBuffer(aCount, chunk); - this.dataListener.append(new Uint8Array(chunk)); - }, - - // nsIRequestObserver::onStartRequest - onStartRequest(aRequest, aContext) { - // Setup the request so we can use it below. - var isHttpRequest = false; - try { - aRequest.QueryInterface(Ci.nsIHttpChannel); - isHttpRequest = true; - } catch (e) {} - - var rangeRequest = false; - var streamRequest = false; - if (isHttpRequest) { - var contentEncoding = "identity"; - try { - contentEncoding = aRequest.getResponseHeader("Content-Encoding"); - } catch (e) {} - - var acceptRanges; - try { - acceptRanges = aRequest.getResponseHeader("Accept-Ranges"); - } catch (e) {} - - var hash = aRequest.URI.ref; - var isPDFBugEnabled = getBoolPref(PREF_PREFIX + ".pdfBugEnabled", false); - rangeRequest = contentEncoding === "identity" && - acceptRanges === "bytes" && - aRequest.contentLength >= 0 && - !getBoolPref(PREF_PREFIX + ".disableRange", false) && - (!isPDFBugEnabled || - !hash.toLowerCase().includes("disablerange=true")); - streamRequest = contentEncoding === "identity" && - aRequest.contentLength >= 0 && - !getBoolPref(PREF_PREFIX + ".disableStream", false) && - (!isPDFBugEnabled || - !hash.toLowerCase().includes("disablestream=true")); - } - - aRequest.QueryInterface(Ci.nsIChannel); - - aRequest.QueryInterface(Ci.nsIWritablePropertyBag); - - var contentDispositionFilename; - try { - contentDispositionFilename = aRequest.contentDispositionFilename; - } catch (e) {} - - // Change the content type so we don't get stuck in a loop. - aRequest.setProperty("contentType", aRequest.contentType); - aRequest.contentType = "text/html"; - if (isHttpRequest) { - // We trust PDF viewer, using no CSP - aRequest.setResponseHeader("Content-Security-Policy", "", false); - aRequest.setResponseHeader("Content-Security-Policy-Report-Only", "", - false); - // The viewer does not need to handle HTTP Refresh header. - aRequest.setResponseHeader("Refresh", "", false); - } - - PdfJsTelemetry.onViewerIsUsed(); - PdfJsTelemetry.onDocumentSize(aRequest.contentLength); - - // Creating storage for PDF data - var contentLength = aRequest.contentLength; - this.dataListener = new PdfDataListener(contentLength); - this.binaryStream = Cc["@mozilla.org/binaryinputstream;1"] - .createInstance(Ci.nsIBinaryInputStream); - - // Create a new channel that is viewer loaded as a resource. - var channel = NetUtil.newChannel({ - uri: PDF_VIEWER_WEB_PAGE, - loadUsingSystemPrincipal: true, - }); - - var listener = this.listener; - var dataListener = this.dataListener; - // Proxy all the request observer calls, when it gets to onStopRequest - // we can get the dom window. We also intentionally pass on the original - // request(aRequest) below so we don't overwrite the original channel and - // trigger an assertion. - var proxy = { - onStartRequest(request, context) { - listener.onStartRequest(aRequest, aContext); - }, - onDataAvailable(request, context, inputStream, offset, count) { - listener.onDataAvailable(aRequest, aContext, inputStream, - offset, count); - }, - onStopRequest(request, context, statusCode) { - // We get the DOM window here instead of before the request since it - // may have changed during a redirect. - var domWindow = getDOMWindow(channel); - var actions; - if (rangeRequest || streamRequest) { - actions = new RangedChromeActions( - domWindow, contentDispositionFilename, aRequest, - rangeRequest, streamRequest, dataListener); - } else { - actions = new StandardChromeActions( - domWindow, contentDispositionFilename, aRequest, dataListener); - } - var requestListener = new RequestListener(actions); - domWindow.addEventListener(PDFJS_EVENT_ID, function(event) { - requestListener.receive(event); - }, false, true); - if (actions.supportsIntegratedFind()) { - var findEventManager = new FindEventManager(domWindow); - findEventManager.bind(); - } - listener.onStopRequest(aRequest, aContext, statusCode); - - if (domWindow.frameElement) { - var isObjectEmbed = domWindow.frameElement.tagName !== "IFRAME" || - domWindow.frameElement.className === "previewPluginContentFrame"; - PdfJsTelemetry.onEmbed(isObjectEmbed); - } - }, - }; - - // Keep the URL the same so the browser sees it as the same. - channel.originalURI = aRequest.URI; - channel.loadGroup = aRequest.loadGroup; - channel.loadInfo.originAttributes = aRequest.loadInfo.originAttributes; - - // We can use the resource principal when data is fetched by the chrome, - // e.g. useful for NoScript. Make make sure we reuse the origin attributes - // from the request channel to keep isolation consistent. - var uri = NetUtil.newURI(PDF_VIEWER_WEB_PAGE); - var resourcePrincipal = - Services.scriptSecurityManager.createCodebasePrincipal(uri, - aRequest.loadInfo.originAttributes); - aRequest.owner = resourcePrincipal; - - channel.asyncOpen2(proxy); - }, - - // nsIRequestObserver::onStopRequest - onStopRequest(aRequest, aContext, aStatusCode) { - if (!this.dataListener) { - // Do nothing - return; - } - - if (Components.isSuccessCode(aStatusCode)) { - this.dataListener.finish(); - } else { - this.dataListener.error(aStatusCode); - } - delete this.dataListener; - delete this.binaryStream; - }, -}; diff --git a/extensions/firefox/content/PdfjsChromeUtils.jsm b/extensions/firefox/content/PdfjsChromeUtils.jsm deleted file mode 100644 index f045d44df3a5a..0000000000000 --- a/extensions/firefox/content/PdfjsChromeUtils.jsm +++ /dev/null @@ -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); - }); - }, -}; diff --git a/extensions/firefox/content/PdfjsContentUtils.jsm b/extensions/firefox/content/PdfjsContentUtils.jsm deleted file mode 100644 index 9b1fff5c5347b..0000000000000 --- a/extensions/firefox/content/PdfjsContentUtils.jsm +++ /dev/null @@ -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; - } - }, -}; diff --git a/extensions/firefox/content/pdfjschildbootstrap-enabled.js b/extensions/firefox/content/pdfjschildbootstrap-enabled.js deleted file mode 100644 index 3e554ac4cd823..0000000000000 --- a/extensions/firefox/content/pdfjschildbootstrap-enabled.js +++ /dev/null @@ -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(); -} diff --git a/extensions/firefox/content/pdfjschildbootstrap.js b/extensions/firefox/content/pdfjschildbootstrap.js deleted file mode 100644 index dce51483146d9..0000000000000 --- a/extensions/firefox/content/pdfjschildbootstrap.js +++ /dev/null @@ -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(); diff --git a/extensions/firefox/icon.png b/extensions/firefox/icon.png deleted file mode 100644 index 755e51880486b..0000000000000 Binary files a/extensions/firefox/icon.png and /dev/null differ diff --git a/extensions/firefox/icon64.png b/extensions/firefox/icon64.png deleted file mode 100644 index ea46b6d295e51..0000000000000 Binary files a/extensions/firefox/icon64.png and /dev/null differ diff --git a/extensions/firefox/install.rdf b/extensions/firefox/install.rdf deleted file mode 100644 index aef00eeb766ac..0000000000000 --- a/extensions/firefox/install.rdf +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - viewer@pdf.js - - PDF Viewer - PDFJSSCRIPT_VERSION - - - - - {ec8030f7-c20a-464f-9b0e-13a3a9e97384} - 59.0a1 - 61.0a1 - - - - - - - {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} - 2.46 - 2.51a1 - - - - - - - {aa3c5121-dab2-40e2-81ca-7ea25febc110} - 59.0a1 - 61.0a1 - - - - - - - {a79fe89b-6662-4ff4-8e88-09950ad4dfde} - 0.1 - 9.9 - - - - true - true - Mozilla - Uses HTML5 to display PDF files directly in Firefox. - https://github.com/mozilla/pdf.js/ - 2 - - https://github.com/mozilla/pdf.js/raw/gh-pages/extensions/firefox/update.rdf - - diff --git a/extensions/firefox/update.rdf b/extensions/firefox/update.rdf deleted file mode 100644 index 0560c8a2090d0..0000000000000 --- a/extensions/firefox/update.rdf +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - PDFJSSCRIPT_VERSION - - - - - {ec8030f7-c20a-464f-9b0e-13a3a9e97384} - 59.0a1 - 61.0a1 - - https://raw.githubusercontent.com/mozilla/pdf.js/gh-pages/extensions/firefox/pdf.js.xpi - - - - - - - {aa3c5121-dab2-40e2-81ca-7ea25febc110} - 59.0a1 - 61.0a1 - - https://raw.githubusercontent.com/mozilla/pdf.js/gh-pages/extensions/firefox/pdf.js.xpi - - - - - - - - \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index e88f67ca9112f..1647f2ffce3c9 100644 --- a/gulpfile.js +++ b/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(/.*.*\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/', })