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.
|
|
|
|
*/
|
|
|
|
|
2023-10-31 19:39:04 +09:00
|
|
|
import { isPdfFile, PDFDataRangeTransport } from "pdfjs-lib";
|
2024-01-26 22:31:42 +09:00
|
|
|
import { BaseExternalServices } from "./external_services.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
import { BasePreferences } from "./preferences.js";
|
2021-02-24 21:02:58 +09:00
|
|
|
import { DEFAULT_SCALE_VALUE } from "./ui_utils.js";
|
2023-10-13 23:23:17 +09:00
|
|
|
import { L10n } from "./l10n.js";
|
2024-01-26 22:31:42 +09:00
|
|
|
import { PDFViewerApplication } from "./app.js";
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
2020-01-08 21:57:31 +09:00
|
|
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
2016-10-15 00:57:53 +09:00
|
|
|
throw new Error(
|
2020-01-08 21:57:31 +09:00
|
|
|
'Module "./firefoxcom.js" shall not be used outside MOZCENTRAL builds.'
|
2016-10-15 00:57:53 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-01 22:21:47 +09:00
|
|
|
class FirefoxCom {
|
2021-01-01 22:40:46 +09:00
|
|
|
/**
|
|
|
|
* Creates an event that the extension is listening for and will
|
|
|
|
* asynchronously respond to.
|
|
|
|
* @param {string} action - The action to trigger.
|
|
|
|
* @param {Object|string} [data] - The data to send.
|
|
|
|
* @returns {Promise<any>} A promise that is resolved with the response data.
|
|
|
|
*/
|
|
|
|
static requestAsync(action, data) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this.request(action, data, resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-01 22:21:47 +09:00
|
|
|
/**
|
|
|
|
* Creates an event that the extension is listening for and will, optionally,
|
|
|
|
* asynchronously respond to.
|
|
|
|
* @param {string} action - The action to trigger.
|
|
|
|
* @param {Object|string} [data] - The data to send.
|
|
|
|
*/
|
|
|
|
static request(action, data, callback = null) {
|
|
|
|
const request = document.createTextNode("");
|
|
|
|
if (callback) {
|
|
|
|
request.addEventListener(
|
|
|
|
"pdf.js.response",
|
|
|
|
event => {
|
|
|
|
const response = event.detail.response;
|
|
|
|
event.target.remove();
|
2012-08-02 07:31:25 +09:00
|
|
|
|
2021-01-01 22:21:47 +09:00
|
|
|
callback(response);
|
|
|
|
},
|
|
|
|
{ once: true }
|
|
|
|
);
|
|
|
|
}
|
2022-06-12 19:20:25 +09:00
|
|
|
document.documentElement.append(request);
|
2012-08-02 07:31:25 +09:00
|
|
|
|
2023-04-23 20:01:35 +09:00
|
|
|
const sender = new CustomEvent("pdf.js.message", {
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: false,
|
|
|
|
detail: {
|
|
|
|
action,
|
|
|
|
data,
|
|
|
|
responseExpected: !!callback,
|
|
|
|
},
|
2021-01-01 22:21:47 +09:00
|
|
|
});
|
|
|
|
request.dispatchEvent(sender);
|
|
|
|
}
|
|
|
|
}
|
2013-07-13 03:14:13 +09:00
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
class DownloadManager {
|
2022-11-04 23:29:45 +09:00
|
|
|
#openBlobUrls = new WeakMap();
|
2021-02-23 20:58:17 +09:00
|
|
|
|
2023-05-05 22:18:01 +09:00
|
|
|
downloadUrl(url, filename, options = {}) {
|
2017-08-22 20:16:28 +09:00
|
|
|
FirefoxCom.request("download", {
|
|
|
|
originalUrl: url,
|
|
|
|
filename,
|
2023-05-05 22:18:01 +09:00
|
|
|
options,
|
2017-08-22 20:16:28 +09:00
|
|
|
});
|
|
|
|
}
|
2015-02-03 00:12:52 +09:00
|
|
|
|
2017-08-22 20:16:28 +09:00
|
|
|
downloadData(data, filename, contentType) {
|
2020-04-24 18:29:33 +09:00
|
|
|
const blobUrl = URL.createObjectURL(
|
|
|
|
new Blob([data], { type: contentType })
|
|
|
|
);
|
2021-01-01 22:40:46 +09:00
|
|
|
|
2022-05-10 21:15:57 +09:00
|
|
|
FirefoxCom.request("download", {
|
2021-01-01 22:40:46 +09:00
|
|
|
blobUrl,
|
|
|
|
originalUrl: blobUrl,
|
|
|
|
filename,
|
|
|
|
isAttachment: true,
|
|
|
|
});
|
2017-08-22 20:16:28 +09:00
|
|
|
}
|
2013-07-13 03:14:13 +09:00
|
|
|
|
2021-02-23 20:58:17 +09:00
|
|
|
/**
|
|
|
|
* @returns {boolean} Indicating if the data was opened.
|
|
|
|
*/
|
2023-10-16 23:20:46 +09:00
|
|
|
openOrDownloadData(data, filename, dest = null) {
|
2021-02-24 21:02:58 +09:00
|
|
|
const isPdfData = isPdfFile(filename);
|
|
|
|
const contentType = isPdfData ? "application/pdf" : "";
|
2021-02-23 20:58:17 +09:00
|
|
|
|
2021-02-24 21:02:58 +09:00
|
|
|
if (isPdfData) {
|
2023-10-16 23:20:46 +09:00
|
|
|
let blobUrl = this.#openBlobUrls.get(data);
|
2021-02-23 20:58:17 +09:00
|
|
|
if (!blobUrl) {
|
|
|
|
blobUrl = URL.createObjectURL(new Blob([data], { type: contentType }));
|
2023-10-16 23:20:46 +09:00
|
|
|
this.#openBlobUrls.set(data, blobUrl);
|
2021-02-23 20:58:17 +09:00
|
|
|
}
|
|
|
|
// Let Firefox's content handler catch the URL and display the PDF.
|
2023-12-01 20:01:05 +09:00
|
|
|
// NOTE: This cannot use a query string for the filename, see
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1632644#c5
|
|
|
|
let viewerUrl = blobUrl + "#filename=" + encodeURIComponent(filename);
|
2023-10-03 15:01:55 +09:00
|
|
|
if (dest) {
|
2023-12-01 20:01:05 +09:00
|
|
|
viewerUrl += `&filedest=${escape(dest)}`;
|
2023-10-03 15:01:55 +09:00
|
|
|
}
|
2021-02-23 20:58:17 +09:00
|
|
|
|
|
|
|
try {
|
|
|
|
window.open(viewerUrl);
|
|
|
|
return true;
|
|
|
|
} catch (ex) {
|
|
|
|
console.error(`openOrDownloadData: ${ex}`);
|
|
|
|
// Release the `blobUrl`, since opening it failed, and fallback to
|
|
|
|
// downloading the PDF file.
|
|
|
|
URL.revokeObjectURL(blobUrl);
|
2023-10-16 23:20:46 +09:00
|
|
|
this.#openBlobUrls.delete(data);
|
2021-02-23 20:58:17 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.downloadData(data, filename, contentType);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-05 22:18:01 +09:00
|
|
|
download(blob, url, filename, options = {}) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const blobUrl = URL.createObjectURL(blob);
|
2021-01-01 22:40:46 +09:00
|
|
|
|
2022-05-10 21:15:57 +09:00
|
|
|
FirefoxCom.request("download", {
|
2021-01-01 22:40:46 +09:00
|
|
|
blobUrl,
|
|
|
|
originalUrl: url,
|
|
|
|
filename,
|
2023-05-05 22:18:01 +09:00
|
|
|
options,
|
2021-01-01 22:40:46 +09:00
|
|
|
});
|
2017-08-22 20:16:28 +09:00
|
|
|
}
|
|
|
|
}
|
2013-11-19 07:51:06 +09:00
|
|
|
|
2024-01-26 20:04:54 +09:00
|
|
|
class Preferences extends BasePreferences {
|
2018-07-30 23:48:16 +09:00
|
|
|
async _readFromStorage(prefObj) {
|
2023-06-25 01:33:17 +09:00
|
|
|
return FirefoxCom.requestAsync("getPreferences", prefObj);
|
2017-04-17 20:21:11 +09:00
|
|
|
}
|
|
|
|
}
|
2016-04-09 02:34:27 +09:00
|
|
|
|
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",
|
2021-04-19 06:37:22 +09:00
|
|
|
"finddiacriticmatchingchange",
|
2016-04-28 21:11:40 +09:00
|
|
|
];
|
2021-10-03 23:03:51 +09:00
|
|
|
const findLen = "find".length;
|
|
|
|
|
2020-04-14 19:28:14 +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,
|
2021-10-03 23:03:51 +09:00
|
|
|
type: type.substring(findLen),
|
2018-09-22 22:31:33 +09:00
|
|
|
query: detail.query,
|
|
|
|
caseSensitive: !!detail.caseSensitive,
|
|
|
|
entireWord: !!detail.entireWord,
|
|
|
|
highlightAll: !!detail.highlightAll,
|
|
|
|
findPrevious: !!detail.findPrevious,
|
2021-04-19 06:37:22 +09:00
|
|
|
matchDiacritics: !!detail.matchDiacritics,
|
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"];
|
2020-04-14 19:28:14 +09:00
|
|
|
const handleEvent = function ({ type, detail }) {
|
2019-03-19 18:45:27 +09:00
|
|
|
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 (
|
2019-12-26 04:03:46 +09:00
|
|
|
type === "zoomreset" &&
|
2019-07-17 18:59:56 +09:00
|
|
|
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
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2020-08-20 04:19:59 +09:00
|
|
|
(function listenSaveEvent() {
|
|
|
|
const handleEvent = function ({ type, detail }) {
|
|
|
|
if (!PDFViewerApplication.initialized) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-19 19:47:24 +09:00
|
|
|
PDFViewerApplication.eventBus.dispatch("download", { source: window });
|
2020-08-20 04:19:59 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("save", handleEvent);
|
|
|
|
})();
|
|
|
|
|
2022-07-05 01:04:32 +09:00
|
|
|
(function listenEditingEvent() {
|
|
|
|
const handleEvent = function ({ detail }) {
|
|
|
|
if (!PDFViewerApplication.initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PDFViewerApplication.eventBus.dispatch("editingaction", {
|
|
|
|
source: window,
|
|
|
|
name: detail.name,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("editingaction", handleEvent);
|
|
|
|
})();
|
|
|
|
|
2023-08-01 01:45:42 +09:00
|
|
|
if (PDFJSDev.test("GECKOVIEW")) {
|
|
|
|
(function listenQueryEvents() {
|
|
|
|
window.addEventListener("pdf.js.query", async ({ detail: { queryId } }) => {
|
|
|
|
let result = null;
|
|
|
|
if (queryId === "canDownloadInsteadOfPrint") {
|
|
|
|
result = false;
|
|
|
|
const { pdfDocument, pdfViewer } = PDFViewerApplication;
|
|
|
|
if (pdfDocument) {
|
|
|
|
try {
|
|
|
|
const hasUnchangedAnnotations =
|
|
|
|
pdfDocument.annotationStorage.size === 0;
|
|
|
|
// WillPrint is called just before printing the document and could
|
|
|
|
// lead to have modified annotations.
|
|
|
|
const hasWillPrint =
|
|
|
|
pdfViewer.enableScripting &&
|
|
|
|
!!(await pdfDocument.getJSActions())?.WillPrint;
|
|
|
|
const hasUnchangedOptionalContent = (
|
|
|
|
await pdfViewer.optionalContentConfigPromise
|
|
|
|
).hasInitialVisibility;
|
|
|
|
|
|
|
|
result =
|
|
|
|
hasUnchangedAnnotations &&
|
|
|
|
!hasWillPrint &&
|
|
|
|
hasUnchangedOptionalContent;
|
|
|
|
} catch {
|
|
|
|
console.warn("Unable to check if the document can be downloaded.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.dispatchEvent(
|
|
|
|
new CustomEvent("pdf.js.query.answer", {
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: false,
|
|
|
|
detail: {
|
|
|
|
queryId,
|
|
|
|
value: result,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
2018-10-21 00:15:27 +09:00
|
|
|
class FirefoxComDataRangeTransport extends PDFDataRangeTransport {
|
|
|
|
requestDataRange(begin, end) {
|
|
|
|
FirefoxCom.request("requestDataRange", { begin, end });
|
|
|
|
}
|
|
|
|
|
2023-11-26 20:18:17 +09:00
|
|
|
// NOTE: This method is currently not invoked in the Firefox PDF Viewer.
|
2018-10-21 00:15:27 +09:00
|
|
|
abort() {
|
2023-11-26 20:18:17 +09:00
|
|
|
FirefoxCom.request("abortLoading", null);
|
2018-10-21 00:15:27 +09:00
|
|
|
}
|
2016-04-14 06:21:05 +09:00
|
|
|
}
|
|
|
|
|
2020-10-23 19:17:47 +09:00
|
|
|
class FirefoxScripting {
|
Update the events, used with scripting, to use lower-case names and avoid using DOM events internally in the viewer
For DOM events all event names are lower-case, and the newly added PDF.js scripting-events thus "stick out" quite a bit. Even more so, considering that our internal `eventBus`-events follow the same naming convention.
Hence this patch, which changes the "updateFromSandbox"/"dispatchEventInSandbox" events to be lower-case instead.
Furthermore, using DOM events for communication *within* the PDF.js code itself (i.e. between code in `web/app.js` and `src/display/annotation_layer.js/`) feels *really* out of place.
That's exactly the reason that we have the `EventBus` abstraction, since it allowed us to remove prior use of DOM events, and this patch thus re-factors the code to make use of the `EventBus` instead for scripting-related events.
Obviously for events targeting a *specific element* using DOM events is still fine, but the "updatefromsandbox"/"dispatcheventinsandbox" ones should be using the `EventBus` internally.
*Drive-by change:* Use the `BaseViewer.currentScaleValue` setter unconditionally in `PDFViewerApplication._initializeJavaScript`, since it accepts either a string or a number.
2020-12-17 22:10:56 +09:00
|
|
|
static async createSandbox(data) {
|
2021-01-01 22:40:46 +09:00
|
|
|
const success = await FirefoxCom.requestAsync("createSandbox", data);
|
|
|
|
if (!success) {
|
|
|
|
throw new Error("Cannot create sandbox.");
|
|
|
|
}
|
2020-10-23 19:17:47 +09:00
|
|
|
}
|
|
|
|
|
2020-12-04 08:39:50 +09:00
|
|
|
static async dispatchEventInSandbox(event) {
|
|
|
|
FirefoxCom.request("dispatchEventInSandbox", event);
|
2020-10-23 19:17:47 +09:00
|
|
|
}
|
|
|
|
|
2020-12-04 08:39:50 +09:00
|
|
|
static async destroySandbox() {
|
|
|
|
FirefoxCom.request("destroySandbox", null);
|
2020-10-23 19:17:47 +09:00
|
|
|
}
|
|
|
|
}
|
2020-10-01 20:57:23 +09:00
|
|
|
|
2024-01-26 22:31:42 +09:00
|
|
|
class ExternalServices extends BaseExternalServices {
|
|
|
|
updateFindControlState(data) {
|
2016-04-14 06:21:05 +09:00
|
|
|
FirefoxCom.request("updateFindControlState", data);
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
2016-04-14 06:21:05 +09:00
|
|
|
|
2024-01-26 22:31:42 +09:00
|
|
|
updateFindMatchesCount(data) {
|
2018-09-13 18:32:12 +09:00
|
|
|
FirefoxCom.request("updateFindMatchesCount", data);
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
2018-09-08 21:19:34 +09:00
|
|
|
|
2024-01-26 22:31: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;
|
|
|
|
}
|
2019-12-27 08:22:32 +09:00
|
|
|
const args = e.data;
|
2016-04-14 06:21:05 +09:00
|
|
|
|
|
|
|
if (typeof args !== "object" || !("pdfjsLoadAction" in args)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (args.pdfjsLoadAction) {
|
|
|
|
case "supportsRangedLoading":
|
2021-11-02 01:50:49 +09:00
|
|
|
if (args.done && !args.data) {
|
|
|
|
callbacks.onError();
|
|
|
|
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
|
|
|
pdfDataRangeTransport = new FirefoxComDataRangeTransport(
|
2016-04-14 06:21:05 +09:00
|
|
|
args.length,
|
|
|
|
args.data,
|
2021-02-24 21:02:58 +09:00
|
|
|
args.done,
|
|
|
|
args.filename
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
);
|
|
|
|
|
2023-02-01 05:34:42 +09:00
|
|
|
callbacks.onOpenWithTransport(pdfDataRangeTransport);
|
2016-04-14 06:21:05 +09:00
|
|
|
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":
|
2021-11-02 01:50:49 +09:00
|
|
|
pdfDataRangeTransport?.onDataProgressiveDone();
|
[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
|
|
|
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;
|
|
|
|
}
|
2021-02-24 21:02:58 +09:00
|
|
|
callbacks.onOpenWithData(args.data, args.filename);
|
2016-04-14 06:21:05 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2023-11-26 20:18:08 +09:00
|
|
|
FirefoxCom.request("initPassiveLoading", null);
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
2016-04-14 06:21:05 +09:00
|
|
|
|
2024-01-26 22:31:42 +09:00
|
|
|
reportTelemetry(data) {
|
2016-04-14 06:21:05 +09:00
|
|
|
FirefoxCom.request("reportTelemetry", JSON.stringify(data));
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
2016-04-14 06:21:05 +09:00
|
|
|
|
2024-01-26 22:31:42 +09:00
|
|
|
updateEditorStates(data) {
|
2022-07-05 01:04:32 +09:00
|
|
|
FirefoxCom.request("updateEditorStates", data);
|
|
|
|
}
|
|
|
|
|
2024-01-26 22:31:42 +09:00
|
|
|
async createL10n() {
|
2023-10-13 23:23:17 +09:00
|
|
|
const [localeProperties] = await Promise.all([
|
|
|
|
FirefoxCom.requestAsync("getLocaleProperties", null),
|
|
|
|
document.l10n.ready,
|
|
|
|
]);
|
|
|
|
return new L10n(localeProperties, document.l10n);
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
2017-04-17 20:21:11 +09:00
|
|
|
|
2024-01-26 22:31:42 +09:00
|
|
|
createScripting() {
|
2020-10-01 20:57:23 +09:00
|
|
|
return FirefoxScripting;
|
|
|
|
}
|
|
|
|
|
2024-01-26 22:31:42 +09:00
|
|
|
async getNimbusExperimentData() {
|
2024-01-29 19:13:48 +09:00
|
|
|
if (!PDFJSDev.test("GECKOVIEW")) {
|
2024-01-27 21:12:54 +09:00
|
|
|
return null;
|
|
|
|
}
|
2023-05-15 23:13:41 +09:00
|
|
|
const nimbusData = await FirefoxCom.requestAsync(
|
|
|
|
"getNimbusExperimentData",
|
|
|
|
null
|
|
|
|
);
|
|
|
|
return nimbusData && JSON.parse(nimbusData);
|
|
|
|
}
|
2020-01-15 22:26:47 +09:00
|
|
|
}
|
2016-04-14 06:21:05 +09:00
|
|
|
|
2024-01-26 22:31:42 +09:00
|
|
|
export { DownloadManager, ExternalServices, FirefoxCom, Preferences };
|