2012-09-01 07:48:21 +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.
|
|
|
|
*/
|
|
|
|
|
2017-05-04 10:05:53 +09:00
|
|
|
import '../extensions/firefox/tools/l10n';
|
2019-09-15 23:43:50 +09:00
|
|
|
import { createObjectURL, PDFDataRangeTransport, shadow } from 'pdfjs-lib';
|
2017-04-17 20:21:11 +09:00
|
|
|
import { BasePreferences } from './preferences';
|
2019-07-17 18:59:56 +09:00
|
|
|
import { DEFAULT_SCALE_VALUE } from './ui_utils';
|
2017-04-15 00:32:36 +09:00
|
|
|
import { PDFViewerApplication } from './app';
|
2017-03-28 08:07:27 +09:00
|
|
|
|
2016-10-15 00:57:53 +09:00
|
|
|
if (typeof PDFJSDev === 'undefined' ||
|
|
|
|
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
|
|
|
throw new Error('Module "pdfjs-web/firefoxcom" shall not be used outside ' +
|
|
|
|
'FIREFOX and MOZCENTRAL builds.');
|
|
|
|
}
|
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
let FirefoxCom = (function FirefoxComClosure() {
|
2012-08-02 07:31:25 +09:00
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Creates an event that the extension is listening for and will
|
|
|
|
* synchronously respond to.
|
|
|
|
* NOTE: It is reccomended to use request() instead since one day we may not
|
|
|
|
* be able to synchronously reply.
|
2019-10-12 22:59:09 +09:00
|
|
|
* @param {string} action The action to trigger.
|
|
|
|
* @param {string} data Optional data to send.
|
2012-08-02 07:31:25 +09:00
|
|
|
* @return {*} The response.
|
|
|
|
*/
|
2017-04-28 19:02:42 +09:00
|
|
|
requestSync(action, data) {
|
2017-08-22 20:16:28 +09:00
|
|
|
let request = document.createTextNode('');
|
2012-08-02 07:31:25 +09:00
|
|
|
document.documentElement.appendChild(request);
|
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
let sender = document.createEvent('CustomEvent');
|
2013-02-06 07:29:36 +09:00
|
|
|
sender.initCustomEvent('pdf.js.message', true, false,
|
2017-04-28 19:02:42 +09:00
|
|
|
{ action, data, sync: true, });
|
2012-08-02 07:31:25 +09:00
|
|
|
request.dispatchEvent(sender);
|
2017-08-22 20:16:28 +09:00
|
|
|
let response = sender.detail.response;
|
2012-08-02 07:31:25 +09:00
|
|
|
document.documentElement.removeChild(request);
|
|
|
|
return response;
|
|
|
|
},
|
2017-08-22 20:16:28 +09:00
|
|
|
|
2012-08-02 07:31:25 +09:00
|
|
|
/**
|
|
|
|
* Creates an event that the extension is listening for and will
|
|
|
|
* asynchronously respond by calling the callback.
|
2019-10-12 22:59:09 +09:00
|
|
|
* @param {string} action The action to trigger.
|
|
|
|
* @param {string} data Optional data to send.
|
2012-08-02 07:31:25 +09:00
|
|
|
* @param {Function} callback Optional response callback that will be called
|
|
|
|
* with one data argument.
|
|
|
|
*/
|
2017-04-28 19:02:42 +09:00
|
|
|
request(action, data, callback) {
|
2017-08-22 20:16:28 +09:00
|
|
|
let request = document.createTextNode('');
|
2012-08-02 07:31:25 +09:00
|
|
|
if (callback) {
|
|
|
|
document.addEventListener('pdf.js.response', function listener(event) {
|
2017-08-22 20:16:28 +09:00
|
|
|
let node = event.target;
|
|
|
|
let response = event.detail.response;
|
2012-08-02 07:31:25 +09:00
|
|
|
|
|
|
|
document.documentElement.removeChild(node);
|
|
|
|
|
2017-01-18 01:45:46 +09:00
|
|
|
document.removeEventListener('pdf.js.response', listener);
|
2012-08-02 07:31:25 +09:00
|
|
|
return callback(response);
|
2017-01-18 01:45:46 +09:00
|
|
|
});
|
2012-08-02 07:31:25 +09:00
|
|
|
}
|
|
|
|
document.documentElement.appendChild(request);
|
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
let sender = document.createEvent('CustomEvent');
|
2014-05-29 00:21:58 +09:00
|
|
|
sender.initCustomEvent('pdf.js.message', true, false, {
|
2017-04-28 19:02:42 +09:00
|
|
|
action,
|
|
|
|
data,
|
2014-05-29 00:21:58 +09:00
|
|
|
sync: false,
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
responseExpected: !!callback,
|
2014-05-29 00:21:58 +09:00
|
|
|
});
|
2012-08-02 07:31:25 +09:00
|
|
|
return request.dispatchEvent(sender);
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
},
|
2012-08-02 07:31:25 +09:00
|
|
|
};
|
|
|
|
})();
|
2013-07-13 03:14:13 +09:00
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
class DownloadManager {
|
2018-02-18 06:51:03 +09:00
|
|
|
constructor(options) {
|
|
|
|
this.disableCreateObjectURL = false;
|
|
|
|
}
|
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
downloadUrl(url, filename) {
|
|
|
|
FirefoxCom.request('download', {
|
|
|
|
originalUrl: url,
|
|
|
|
filename,
|
|
|
|
});
|
|
|
|
}
|
2015-02-03 00:12:52 +09:00
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
downloadData(data, filename, contentType) {
|
2018-02-18 06:51:03 +09:00
|
|
|
let blobUrl = createObjectURL(data, contentType);
|
2014-03-19 05:32:47 +09:00
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
FirefoxCom.request('download', {
|
|
|
|
blobUrl,
|
|
|
|
originalUrl: blobUrl,
|
|
|
|
filename,
|
|
|
|
isAttachment: true,
|
|
|
|
});
|
|
|
|
}
|
2013-07-13 03:14:13 +09:00
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
download(blob, url, filename) {
|
|
|
|
let blobUrl = URL.createObjectURL(blob);
|
|
|
|
let onResponse = (err) => {
|
|
|
|
if (err && this.onerror) {
|
|
|
|
this.onerror(err);
|
|
|
|
}
|
|
|
|
URL.revokeObjectURL(blobUrl);
|
|
|
|
};
|
|
|
|
|
|
|
|
FirefoxCom.request('download', {
|
|
|
|
blobUrl,
|
|
|
|
originalUrl: url,
|
|
|
|
filename,
|
|
|
|
}, onResponse);
|
|
|
|
}
|
|
|
|
}
|
2013-11-19 07:51:06 +09:00
|
|
|
|
2017-04-17 20:21:11 +09:00
|
|
|
class FirefoxPreferences extends BasePreferences {
|
2018-07-30 23:48:16 +09:00
|
|
|
async _writeToStorage(prefObj) {
|
2017-04-17 20:21:11 +09:00
|
|
|
return new Promise(function(resolve) {
|
|
|
|
FirefoxCom.request('setPreferences', prefObj, resolve);
|
|
|
|
});
|
|
|
|
}
|
2013-11-19 07:51:06 +09:00
|
|
|
|
2018-07-30 23:48:16 +09:00
|
|
|
async _readFromStorage(prefObj) {
|
2017-04-17 20:21:11 +09:00
|
|
|
return new Promise(function(resolve) {
|
2017-08-22 20:16:28 +09:00
|
|
|
FirefoxCom.request('getPreferences', prefObj, function(prefStr) {
|
|
|
|
let readPrefs = JSON.parse(prefStr);
|
2017-04-17 20:21:11 +09:00
|
|
|
resolve(readPrefs);
|
|
|
|
});
|
2014-03-27 03:38:56 +09:00
|
|
|
});
|
2017-04-17 20:21:11 +09:00
|
|
|
}
|
|
|
|
}
|
2016-04-09 02:34:27 +09:00
|
|
|
|
2017-05-04 10:05:53 +09:00
|
|
|
class MozL10n {
|
|
|
|
constructor(mozL10n) {
|
|
|
|
this.mozL10n = mozL10n;
|
|
|
|
}
|
|
|
|
|
2018-07-30 23:28:39 +09:00
|
|
|
async getLanguage() {
|
|
|
|
return this.mozL10n.getLanguage();
|
2018-03-20 21:42:45 +09:00
|
|
|
}
|
|
|
|
|
2018-07-30 23:28:39 +09:00
|
|
|
async getDirection() {
|
|
|
|
return this.mozL10n.getDirection();
|
2017-05-04 10:05:53 +09:00
|
|
|
}
|
|
|
|
|
2018-07-30 23:28:39 +09:00
|
|
|
async get(property, args, fallback) {
|
|
|
|
return this.mozL10n.get(property, args, fallback);
|
2017-05-04 10:05:53 +09:00
|
|
|
}
|
|
|
|
|
2018-07-30 23:28:39 +09:00
|
|
|
async translate(element) {
|
2017-05-04 10:05:53 +09:00
|
|
|
this.mozL10n.translate(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 21:11:40 +09:00
|
|
|
(function listenFindEvents() {
|
2017-08-22 20:16:28 +09:00
|
|
|
const events = [
|
2016-04-28 21:11:40 +09:00
|
|
|
'find',
|
|
|
|
'findagain',
|
|
|
|
'findhighlightallchange',
|
2018-09-01 08:28:19 +09:00
|
|
|
'findcasesensitivitychange',
|
|
|
|
'findentirewordchange',
|
2018-09-22 22:31:33 +09:00
|
|
|
'findbarclose',
|
2016-04-28 21:11:40 +09:00
|
|
|
];
|
2019-03-19 18:45:27 +09:00
|
|
|
const handleEvent = function({ type, detail, }) {
|
2016-04-28 21:11:40 +09:00
|
|
|
if (!PDFViewerApplication.initialized) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-22 22:31:33 +09:00
|
|
|
if (type === 'findbarclose') {
|
2019-07-18 21:28:49 +09:00
|
|
|
PDFViewerApplication.eventBus.dispatch(type, { source: window, });
|
2018-09-22 22:31:33 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-04-28 21:11:40 +09:00
|
|
|
PDFViewerApplication.eventBus.dispatch('find', {
|
|
|
|
source: window,
|
2018-09-22 22:31:33 +09:00
|
|
|
type: type.substring('find'.length),
|
|
|
|
query: detail.query,
|
2016-05-26 22:24:58 +09:00
|
|
|
phraseSearch: true,
|
2018-09-22 22:31:33 +09:00
|
|
|
caseSensitive: !!detail.caseSensitive,
|
|
|
|
entireWord: !!detail.entireWord,
|
|
|
|
highlightAll: !!detail.highlightAll,
|
|
|
|
findPrevious: !!detail.findPrevious,
|
2016-04-28 21:11:40 +09:00
|
|
|
});
|
2016-12-10 21:58:06 +09:00
|
|
|
};
|
2016-04-28 21:11:40 +09:00
|
|
|
|
2019-03-19 18:45:27 +09:00
|
|
|
for (const event of events) {
|
|
|
|
window.addEventListener(event, handleEvent);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function listenZoomEvents() {
|
|
|
|
const events = [
|
|
|
|
'zoomin',
|
|
|
|
'zoomout',
|
|
|
|
'zoomreset',
|
|
|
|
];
|
|
|
|
const handleEvent = function({ type, detail, }) {
|
|
|
|
if (!PDFViewerApplication.initialized) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-17 18:59:56 +09:00
|
|
|
// Avoid attempting to needlessly reset the zoom level *twice* in a row,
|
|
|
|
// when using the `Ctrl + 0` keyboard shortcut.
|
|
|
|
if (type === 'zoomreset' && // eslint-disable-next-line max-len
|
|
|
|
PDFViewerApplication.pdfViewer.currentScaleValue === DEFAULT_SCALE_VALUE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PDFViewerApplication.eventBus.dispatch(type, { source: window, });
|
2019-03-19 18:45:27 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const event of events) {
|
2018-09-01 08:28:19 +09:00
|
|
|
window.addEventListener(event, handleEvent);
|
2016-04-28 21:11:40 +09:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
class FirefoxComDataRangeTransport extends PDFDataRangeTransport {
|
|
|
|
requestDataRange(begin, end) {
|
|
|
|
FirefoxCom.request('requestDataRange', { begin, end, });
|
|
|
|
}
|
|
|
|
|
|
|
|
abort() {
|
|
|
|
// Sync call to ensure abort is really started.
|
|
|
|
FirefoxCom.requestSync('abortLoading', null);
|
|
|
|
}
|
2016-04-14 06:21:05 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
PDFViewerApplication.externalServices = {
|
2017-04-28 19:02:42 +09:00
|
|
|
updateFindControlState(data) {
|
2016-04-14 06:21:05 +09:00
|
|
|
FirefoxCom.request('updateFindControlState', data);
|
|
|
|
},
|
|
|
|
|
2018-09-08 21:19:34 +09:00
|
|
|
updateFindMatchesCount(data) {
|
2018-09-13 18:32:12 +09:00
|
|
|
FirefoxCom.request('updateFindMatchesCount', data);
|
2018-09-08 21:19:34 +09:00
|
|
|
},
|
|
|
|
|
2017-04-28 19:02:42 +09:00
|
|
|
initPassiveLoading(callbacks) {
|
2017-08-22 20:16:28 +09:00
|
|
|
let pdfDataRangeTransport;
|
2016-04-14 06:21:05 +09:00
|
|
|
|
|
|
|
window.addEventListener('message', function windowMessage(e) {
|
|
|
|
if (e.source !== null) {
|
|
|
|
// The message MUST originate from Chrome code.
|
|
|
|
console.warn('Rejected untrusted message from ' + e.origin);
|
|
|
|
return;
|
|
|
|
}
|
2017-08-22 20:16:28 +09:00
|
|
|
let args = e.data;
|
2016-04-14 06:21:05 +09:00
|
|
|
|
|
|
|
if (typeof args !== 'object' || !('pdfjsLoadAction' in args)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (args.pdfjsLoadAction) {
|
|
|
|
case 'supportsRangedLoading':
|
|
|
|
pdfDataRangeTransport =
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
new FirefoxComDataRangeTransport(args.length, args.data, args.done);
|
2016-04-14 06:21:05 +09:00
|
|
|
|
|
|
|
callbacks.onOpenWithTransport(args.pdfUrl, args.length,
|
|
|
|
pdfDataRangeTransport);
|
|
|
|
break;
|
|
|
|
case 'range':
|
|
|
|
pdfDataRangeTransport.onDataRange(args.begin, args.chunk);
|
|
|
|
break;
|
|
|
|
case 'rangeProgress':
|
|
|
|
pdfDataRangeTransport.onDataProgress(args.loaded);
|
|
|
|
break;
|
|
|
|
case 'progressiveRead':
|
|
|
|
pdfDataRangeTransport.onDataProgressiveRead(args.chunk);
|
2019-04-06 18:04:44 +09:00
|
|
|
|
|
|
|
// Don't forget to report loading progress as well, since otherwise
|
|
|
|
// the loadingBar won't update when `disableRange=true` is set.
|
|
|
|
pdfDataRangeTransport.onDataProgress(args.loaded, args.total);
|
2016-04-14 06:21:05 +09:00
|
|
|
break;
|
[Firefox regression] Fix `disableRange=true` bug in `PDFDataTransportStream`
Currently if trying to set `disableRange=true` in the built-in PDF Viewer in Firefox, either through `about:config` or via the URL hash, the PDF document will never load. It appears that this has been broken for a couple of years, without anyone noticing.
Obviously it's not a good idea to set `disableRange=true`, however it seems that this bug affects the PDF Viewer in Firefox even with default settings:
- In the case where `initialData` already contains the *entire* file, we're forced to dispatch a range request to re-fetch already available data just so that file loading may complete.
- (In the case where the data arrives, via streaming, before being specifically requested through `requestDataRange`, we're also forced to re-fetch data unnecessarily.) *This part was removed, to reduce the scope/risk of the patch somewhat.*
In the cases outlined above, we're having to re-fetch already available data thus potentially delaying loading/rendering of PDF files in Firefox (and wasting resources in the process).
2019-03-27 00:05:30 +09:00
|
|
|
case 'progressiveDone':
|
|
|
|
if (pdfDataRangeTransport) {
|
|
|
|
pdfDataRangeTransport.onDataProgressiveDone();
|
|
|
|
}
|
|
|
|
break;
|
2016-04-14 06:21:05 +09:00
|
|
|
case 'progress':
|
|
|
|
callbacks.onProgress(args.loaded, args.total);
|
|
|
|
break;
|
|
|
|
case 'complete':
|
|
|
|
if (!args.data) {
|
|
|
|
callbacks.onError(args.errorCode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
callbacks.onOpenWithData(args.data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
FirefoxCom.requestSync('initPassiveLoading', null);
|
|
|
|
},
|
|
|
|
|
2017-04-28 19:02:42 +09:00
|
|
|
fallback(data, callback) {
|
2016-04-14 06:21:05 +09:00
|
|
|
FirefoxCom.request('fallback', data, callback);
|
|
|
|
},
|
|
|
|
|
2017-04-28 19:02:42 +09:00
|
|
|
reportTelemetry(data) {
|
2016-04-14 06:21:05 +09:00
|
|
|
FirefoxCom.request('reportTelemetry', JSON.stringify(data));
|
|
|
|
},
|
|
|
|
|
2018-02-18 06:51:03 +09:00
|
|
|
createDownloadManager(options) {
|
|
|
|
return new DownloadManager(options);
|
2016-04-14 06:21:05 +09:00
|
|
|
},
|
|
|
|
|
2017-04-17 20:21:11 +09:00
|
|
|
createPreferences() {
|
|
|
|
return new FirefoxPreferences();
|
|
|
|
},
|
2017-05-04 10:05:53 +09:00
|
|
|
|
2018-02-13 22:22:14 +09:00
|
|
|
createL10n(options) {
|
2017-08-22 20:16:28 +09:00
|
|
|
let mozL10n = document.mozL10n;
|
2017-05-04 10:05:53 +09:00
|
|
|
// TODO refactor mozL10n.setExternalLocalizerServices
|
|
|
|
return new MozL10n(mozL10n);
|
|
|
|
},
|
2017-04-17 20:21:11 +09:00
|
|
|
|
2016-04-14 06:21:05 +09:00
|
|
|
get supportsIntegratedFind() {
|
2017-08-22 20:16:28 +09:00
|
|
|
let support = FirefoxCom.requestSync('supportsIntegratedFind');
|
2017-03-28 17:15:02 +09:00
|
|
|
return shadow(this, 'supportsIntegratedFind', support);
|
2016-04-14 06:21:05 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
get supportsDocumentFonts() {
|
2017-08-22 20:16:28 +09:00
|
|
|
let support = FirefoxCom.requestSync('supportsDocumentFonts');
|
2017-03-28 17:15:02 +09:00
|
|
|
return shadow(this, 'supportsDocumentFonts', support);
|
2016-04-14 06:21:05 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
get supportsDocumentColors() {
|
2017-08-22 20:16:28 +09:00
|
|
|
let support = FirefoxCom.requestSync('supportsDocumentColors');
|
2017-03-28 17:15:02 +09:00
|
|
|
return shadow(this, 'supportsDocumentColors', support);
|
2016-04-14 06:21:05 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
get supportedMouseWheelZoomModifierKeys() {
|
2017-08-22 20:16:28 +09:00
|
|
|
let support = FirefoxCom.requestSync('supportedMouseWheelZoomModifierKeys');
|
2017-03-28 17:15:02 +09:00
|
|
|
return shadow(this, 'supportedMouseWheelZoomModifierKeys', support);
|
2016-04-14 06:21:05 +09:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-01-20 00:26:32 +09:00
|
|
|
// l10n.js for Firefox extension expects services to be set.
|
2016-04-14 06:21:05 +09:00
|
|
|
document.mozL10n.setExternalLocalizerServices({
|
2017-04-28 19:02:42 +09:00
|
|
|
getLocale() {
|
2016-04-14 06:21:05 +09:00
|
|
|
return FirefoxCom.requestSync('getLocale', null);
|
|
|
|
},
|
|
|
|
|
2017-04-28 19:02:42 +09:00
|
|
|
getStrings(key) {
|
2016-04-14 06:21:05 +09:00
|
|
|
return FirefoxCom.requestSync('getStrings', key);
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
},
|
2016-04-14 06:21:05 +09:00
|
|
|
});
|
|
|
|
|
2017-03-28 08:07:27 +09:00
|
|
|
export {
|
|
|
|
DownloadManager,
|
|
|
|
FirefoxCom,
|
|
|
|
};
|