2014-09-06 07:33:52 +09:00
|
|
|
/* 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.
|
|
|
|
*/
|
2016-05-12 07:58:17 +09:00
|
|
|
/* globals Components, Services, XPCOMUtils */
|
2014-09-06 07:33:52 +09:00
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
"use strict";
|
2014-09-06 07:33:52 +09:00
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
var EXPORTED_SYMBOLS = ["PdfjsChromeUtils"];
|
2014-09-06 07:33:52 +09:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
const PREF_PREFIX = "PDFJSSCRIPT_PREF_PREFIX";
|
|
|
|
const PDF_CONTENT_TYPE = "application/pdf";
|
2014-09-06 07:33:52 +09:00
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2014-09-06 07:33:52 +09:00
|
|
|
|
2015-10-01 16:56:15 +09:00
|
|
|
var Svc = {};
|
2017-01-24 07:41:56 +09:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(Svc, "mime",
|
|
|
|
"@mozilla.org/mime;1",
|
|
|
|
"nsIMIMEService");
|
2014-09-06 07:33:52 +09:00
|
|
|
|
2016-05-12 07:58:17 +09:00
|
|
|
var DEFAULT_PREFERENCES =
|
|
|
|
//#include ../../../web/default_preferences.json
|
|
|
|
//#if false
|
2017-01-24 07:41:56 +09:00
|
|
|
"end of DEFAULT_PREFERENCES";
|
2016-05-12 07:58:17 +09:00
|
|
|
//#endif
|
2014-09-09 05:41:57 +09:00
|
|
|
|
2015-10-05 19:31:53 +09:00
|
|
|
var PdfjsChromeUtils = {
|
2014-09-06 07:33:52 +09:00
|
|
|
// For security purposes when running remote, we restrict preferences
|
|
|
|
// content can access.
|
2014-09-09 05:41:57 +09:00
|
|
|
_allowedPrefNames: Object.keys(DEFAULT_PREFERENCES),
|
2014-09-06 07:33:52 +09:00
|
|
|
_ppmm: null,
|
|
|
|
_mmg: null,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public API
|
|
|
|
*/
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
init() {
|
2016-08-04 06:18:40 +09:00
|
|
|
this._browsers = new WeakSet();
|
2014-09-06 07:33:52 +09:00
|
|
|
if (!this._ppmm) {
|
|
|
|
// global parent process message manager (PPMM)
|
2017-01-24 07:41:56 +09:00
|
|
|
this._ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"].
|
2014-09-18 09:10:03 +09:00
|
|
|
getService(Ci.nsIMessageBroadcaster);
|
2017-01-24 07:41:56 +09:00
|
|
|
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);
|
2014-09-06 07:33:52 +09:00
|
|
|
|
|
|
|
// global dom message manager (MMg)
|
2017-01-24 07:41:56 +09:00
|
|
|
this._mmg = Cc["@mozilla.org/globalmessagemanager;1"].
|
2014-09-18 09:10:03 +09:00
|
|
|
getService(Ci.nsIMessageListenerManager);
|
2017-01-24 07:41:56 +09:00
|
|
|
this._mmg.addMessageListener("PDFJS:Parent:displayWarning", this);
|
2014-09-06 07:33:52 +09:00
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
this._mmg.addMessageListener("PDFJS:Parent:addEventListener", this);
|
|
|
|
this._mmg.addMessageListener("PDFJS:Parent:removeEventListener", this);
|
|
|
|
this._mmg.addMessageListener("PDFJS:Parent:updateControlState", this);
|
2015-02-21 01:47:29 +09:00
|
|
|
|
2014-09-06 07:33:52 +09:00
|
|
|
// observer to handle shutdown
|
2017-01-24 07:41:56 +09:00
|
|
|
Services.obs.addObserver(this, "quit-application", false);
|
2014-09-06 07:33:52 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
uninit() {
|
2014-09-06 07:33:52 +09:00
|
|
|
if (this._ppmm) {
|
2017-01-24 07:41:56 +09:00
|
|
|
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",
|
2014-09-18 09:10:03 +09:00
|
|
|
this);
|
2014-09-06 07:33:52 +09:00
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
this._mmg.removeMessageListener("PDFJS:Parent:displayWarning", this);
|
2014-09-06 07:33:52 +09:00
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
this._mmg.removeMessageListener("PDFJS:Parent:addEventListener", this);
|
|
|
|
this._mmg.removeMessageListener("PDFJS:Parent:removeEventListener", this);
|
|
|
|
this._mmg.removeMessageListener("PDFJS:Parent:updateControlState", this);
|
2015-02-21 01:47:29 +09:00
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
Services.obs.removeObserver(this, "quit-application");
|
2014-09-06 07:33:52 +09:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
notifyChildOfSettingsChange() {
|
2014-09-18 09:10:03 +09:00
|
|
|
if (Services.appinfo.processType ===
|
|
|
|
Services.appinfo.PROCESS_TYPE_DEFAULT && this._ppmm) {
|
2014-09-06 07:33:52 +09:00
|
|
|
// 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.
|
2017-01-24 07:41:56 +09:00
|
|
|
this._ppmm.broadcastAsyncMessage("PDFJS:Child:refreshSettings", {});
|
2014-09-06 07:33:52 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Events
|
|
|
|
*/
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
observe(aSubject, aTopic, aData) {
|
2017-01-24 07:41:56 +09:00
|
|
|
if (aTopic === "quit-application") {
|
2014-09-06 07:33:52 +09:00
|
|
|
this.uninit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
receiveMessage(aMsg) {
|
2014-09-06 07:33:52 +09:00
|
|
|
switch (aMsg.name) {
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:clearUserPref":
|
2014-09-20 05:30:27 +09:00
|
|
|
this._clearUserPref(aMsg.data.name);
|
2014-09-06 07:33:52 +09:00
|
|
|
break;
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:setIntPref":
|
2014-09-20 05:30:27 +09:00
|
|
|
this._setIntPref(aMsg.data.name, aMsg.data.value);
|
2014-09-06 07:33:52 +09:00
|
|
|
break;
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:setBoolPref":
|
2014-09-20 05:30:27 +09:00
|
|
|
this._setBoolPref(aMsg.data.name, aMsg.data.value);
|
2014-09-06 07:33:52 +09:00
|
|
|
break;
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:setCharPref":
|
2014-09-20 05:30:27 +09:00
|
|
|
this._setCharPref(aMsg.data.name, aMsg.data.value);
|
2014-09-06 07:33:52 +09:00
|
|
|
break;
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:setStringPref":
|
2014-09-20 05:30:27 +09:00
|
|
|
this._setStringPref(aMsg.data.name, aMsg.data.value);
|
2014-09-06 07:33:52 +09:00
|
|
|
break;
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:isDefaultHandlerApp":
|
2014-09-06 07:33:52 +09:00
|
|
|
return this.isDefaultHandlerApp();
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:displayWarning":
|
2014-09-06 07:33:52 +09:00
|
|
|
this._displayWarning(aMsg);
|
|
|
|
break;
|
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:updateControlState":
|
2015-02-21 01:47:29 +09:00
|
|
|
return this._updateControlState(aMsg);
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:addEventListener":
|
2015-02-21 01:47:29 +09:00
|
|
|
return this._addEventListener(aMsg);
|
2017-01-24 07:41:56 +09:00
|
|
|
case "PDFJS:Parent:removeEventListener":
|
2015-02-21 01:47:29 +09:00
|
|
|
return this._removeEventListener(aMsg);
|
2014-09-06 07:33:52 +09:00
|
|
|
}
|
2017-01-25 20:47:38 +09:00
|
|
|
return undefined;
|
2014-09-06 07:33:52 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal
|
|
|
|
*/
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_findbarFromMessage(aMsg) {
|
2014-09-06 07:33:52 +09:00
|
|
|
let browser = aMsg.target;
|
2015-02-21 01:47:29 +09:00
|
|
|
let tabbrowser = browser.getTabBrowser();
|
2016-06-10 23:43:39 +09:00
|
|
|
let tab = tabbrowser.getTabForBrowser(browser);
|
2015-02-21 01:47:29 +09:00
|
|
|
return tabbrowser.getFindBar(tab);
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_updateControlState(aMsg) {
|
2015-02-21 01:47:29 +09:00
|
|
|
let data = aMsg.data;
|
|
|
|
this._findbarFromMessage(aMsg)
|
|
|
|
.updateControlState(data.result, data.findPrevious);
|
2014-09-06 07:33:52 +09:00
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
handleEvent(aEvent) {
|
2015-04-06 23:26:23 +09:00
|
|
|
// To avoid forwarding the message as a CPOW, create a structured cloneable
|
|
|
|
// version of the event for both performance, and ease of usage, reasons.
|
2015-02-21 01:47:29 +09:00
|
|
|
let type = aEvent.type;
|
|
|
|
let detail = {
|
|
|
|
query: aEvent.detail.query,
|
|
|
|
caseSensitive: aEvent.detail.caseSensitive,
|
|
|
|
highlightAll: aEvent.detail.highlightAll,
|
|
|
|
findPrevious: aEvent.detail.findPrevious
|
|
|
|
};
|
|
|
|
|
2015-04-06 23:26:23 +09:00
|
|
|
let browser = aEvent.currentTarget.browser;
|
|
|
|
if (!this._browsers.has(browser)) {
|
2017-01-24 07:41:56 +09:00
|
|
|
throw new Error("FindEventManager was not bound " +
|
|
|
|
"for the current browser.");
|
2015-02-21 01:47:29 +09:00
|
|
|
}
|
2015-04-06 23:26:23 +09:00
|
|
|
// Only forward the events if the current browser is a registered browser.
|
|
|
|
let mm = browser.messageManager;
|
2017-01-24 07:41:56 +09:00
|
|
|
mm.sendAsyncMessage("PDFJS:Child:handleEvent", { type, detail, });
|
2015-04-06 23:26:23 +09:00
|
|
|
aEvent.preventDefault();
|
2015-02-21 01:47:29 +09:00
|
|
|
},
|
|
|
|
|
2017-01-24 07:41:56 +09:00
|
|
|
_types: ["find",
|
|
|
|
"findagain",
|
|
|
|
"findhighlightallchange",
|
|
|
|
"findcasesensitivitychange"],
|
2015-02-21 01:47:29 +09:00
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_addEventListener(aMsg) {
|
2014-09-06 07:33:52 +09:00
|
|
|
let browser = aMsg.target;
|
2015-02-21 01:47:29 +09:00
|
|
|
if (this._browsers.has(browser)) {
|
2017-01-24 07:41:56 +09:00
|
|
|
throw new Error("FindEventManager was bound 2nd time " +
|
|
|
|
"without unbinding it first.");
|
2015-02-21 01:47:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_removeEventListener(aMsg) {
|
2015-02-21 01:47:29 +09:00
|
|
|
let browser = aMsg.target;
|
|
|
|
if (!this._browsers.has(browser)) {
|
2017-01-24 07:41:56 +09:00
|
|
|
throw new Error("FindEventManager was unbound without binding it first.");
|
2015-02-21 01:47:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2014-09-06 07:33:52 +09:00
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_ensurePreferenceAllowed(aPrefName) {
|
2017-01-24 07:41:56 +09:00
|
|
|
let unPrefixedName = aPrefName.split(PREF_PREFIX + ".");
|
|
|
|
if (unPrefixedName[0] !== "" ||
|
2014-09-18 08:14:00 +09:00
|
|
|
this._allowedPrefNames.indexOf(unPrefixedName[1]) === -1) {
|
2017-01-24 07:41:56 +09:00
|
|
|
let msg = "\"" + aPrefName + "\" " +
|
|
|
|
"can't be accessed from content. See PdfjsChromeUtils.";
|
2014-09-06 07:33:52 +09:00
|
|
|
throw new Error(msg);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_clearUserPref(aPrefName) {
|
2014-09-18 22:06:34 +09:00
|
|
|
this._ensurePreferenceAllowed(aPrefName);
|
2014-09-06 07:33:52 +09:00
|
|
|
Services.prefs.clearUserPref(aPrefName);
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_setIntPref(aPrefName, aPrefValue) {
|
2014-09-18 22:06:34 +09:00
|
|
|
this._ensurePreferenceAllowed(aPrefName);
|
2014-09-06 07:33:52 +09:00
|
|
|
Services.prefs.setIntPref(aPrefName, aPrefValue);
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_setBoolPref(aPrefName, aPrefValue) {
|
2014-09-18 22:06:34 +09:00
|
|
|
this._ensurePreferenceAllowed(aPrefName);
|
2014-09-06 07:33:52 +09:00
|
|
|
Services.prefs.setBoolPref(aPrefName, aPrefValue);
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_setCharPref(aPrefName, aPrefValue) {
|
2014-09-18 22:06:34 +09:00
|
|
|
this._ensurePreferenceAllowed(aPrefName);
|
2014-09-06 07:33:52 +09:00
|
|
|
Services.prefs.setCharPref(aPrefName, aPrefValue);
|
|
|
|
},
|
|
|
|
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_setStringPref(aPrefName, aPrefValue) {
|
2014-09-18 22:06:34 +09:00
|
|
|
this._ensurePreferenceAllowed(aPrefName);
|
2017-01-24 07:41:56 +09:00
|
|
|
let str = Cc["@mozilla.org/supports-string;1"]
|
2014-09-06 07:33:52 +09:00
|
|
|
.createInstance(Ci.nsISupportsString);
|
|
|
|
str.data = aPrefValue;
|
|
|
|
Services.prefs.setComplexValue(aPrefName, Ci.nsISupportsString, str);
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Svc.mime doesn't have profile information in the child, so
|
|
|
|
* we bounce this pdfjs enabled configuration check over to the
|
|
|
|
* parent.
|
|
|
|
*/
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
isDefaultHandlerApp() {
|
2017-01-24 07:41:56 +09:00
|
|
|
var handlerInfo = Svc.mime.getFromTypeAndExtension(PDF_CONTENT_TYPE, "pdf");
|
2014-09-18 09:10:03 +09:00
|
|
|
return (!handlerInfo.alwaysAskBeforeHandling &&
|
|
|
|
handlerInfo.preferredAction === Ci.nsIHandlerInfo.handleInternally);
|
2014-09-06 07:33:52 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display a notification warning when the renderer isn't sure
|
|
|
|
* a pdf displayed correctly.
|
|
|
|
*/
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
_displayWarning(aMsg) {
|
2015-04-07 06:21:17 +09:00
|
|
|
let data = aMsg.data;
|
2014-09-06 07:33:52 +09:00
|
|
|
let browser = aMsg.target;
|
2015-04-07 06:21:17 +09:00
|
|
|
|
2014-09-06 07:33:52 +09:00
|
|
|
let tabbrowser = browser.getTabBrowser();
|
|
|
|
let notificationBox = tabbrowser.getNotificationBox(browser);
|
2015-04-07 06:21:17 +09:00
|
|
|
|
|
|
|
// Flag so we don't send the message twice, since if the user clicks
|
|
|
|
// "open with different viewer" both the button callback and
|
2014-09-06 07:33:52 +09:00
|
|
|
// eventCallback will be called.
|
2015-04-07 06:21:17 +09:00
|
|
|
let messageSent = false;
|
|
|
|
function sendMessage(download) {
|
|
|
|
let mm = browser.messageManager;
|
2017-01-24 07:41:56 +09:00
|
|
|
mm.sendAsyncMessage("PDFJS:Child:fallbackDownload", { download, });
|
2015-04-07 06:21:17 +09:00
|
|
|
}
|
2014-09-06 07:33:52 +09:00
|
|
|
let buttons = [{
|
2015-04-07 06:21:17 +09:00
|
|
|
label: data.label,
|
|
|
|
accessKey: data.accessKey,
|
[Firefox addon] Convert the code to be ES6 friendly, in order to better agree with mozilla-central coding conventions (issue 7957)
*Please note: ignoring whitespace changes is most likely necessary for the diff to be readable.*
This patch addresses all the current, in `mozilla-central`, linting failures in the addon. It should thus be possible to change the `.eslintignore` entry for PDF.js in `mozilla-central` from `browser/extensions/pdfjs/**` to `browser/extensions/pdfjs/build/**` and `browser/extensions/pdfjs/web/**` instead.
Note that we cannot, for backwards compatibility reason of the general PDF.js library, at this time make similar changes for files residing in the `build` and `web` directories in `mozilla-central`.
The main changes in this patch are that we now use [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) instead of our previous "class-like" functions, and also use the more compact [object shorthand notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).
A couple of functions were also converted to [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), to reduced usages of `bind(this)` and `var self = this`.
One caveat with ES6 classes is that it's not (yet) possible to define private constants/helper functions within them, which is why the `NetworkManagerClosure` was kept to not change the visibility of those constant/functions.
Besides testing in Firefox Nightly 53, this patch has also been tested in Firefox ESR 45 and SeaMonkey 2.46.
However, I'd gladly welcome help with testing the patch more, to ensure that nothing has gone wrong during the refactoring.
Fixes the first bullet point of issue 7957.
2017-01-23 02:07:53 +09:00
|
|
|
callback() {
|
2015-04-07 06:21:17 +09:00
|
|
|
messageSent = true;
|
|
|
|
sendMessage(true);
|
2014-09-06 07:33:52 +09:00
|
|
|
}
|
|
|
|
}];
|
2017-01-24 07:41:56 +09:00
|
|
|
notificationBox.appendNotification(data.message, "pdfjs-fallback", null,
|
2014-09-06 07:33:52 +09:00
|
|
|
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.
|
2017-01-24 07:41:56 +09:00
|
|
|
if (eventType !== "removed") {
|
2014-09-06 07:33:52 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Don't send a response again if we already responded when the button was
|
|
|
|
// clicked.
|
2015-04-07 06:21:17 +09:00
|
|
|
if (messageSent) {
|
2014-09-06 07:33:52 +09:00
|
|
|
return;
|
|
|
|
}
|
2015-04-07 06:21:17 +09:00
|
|
|
sendMessage(false);
|
2014-09-06 07:33:52 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|