mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 14:48:08 +02:00
Remove PDFViewerApplication.initPassiveLoading
and directly invoke the open
-method from the extension-specific code
This old method is essentially just adding, a small amount of, unnecessary indirection and we can easily invoke `PDFViewerApplication.open` directly from the extension-specific code instead.
This commit is contained in:
parent
b5e00e1fae
commit
ea1c910a66
4 changed files with 17 additions and 46 deletions
44
web/app.js
44
web/app.js
|
@ -685,7 +685,9 @@ const PDFViewerApplication = {
|
|||
this._hideViewBookmark();
|
||||
}
|
||||
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
|
||||
this.initPassiveLoading(file);
|
||||
this.setTitleUsingUrl(file, /* downloadUrl = */ file);
|
||||
|
||||
this.externalServices.initPassiveLoading();
|
||||
} else {
|
||||
throw new Error("Not implemented: run");
|
||||
}
|
||||
|
@ -815,37 +817,6 @@ const PDFViewerApplication = {
|
|||
this._caretBrowsing.moveCaret(isUp, select);
|
||||
},
|
||||
|
||||
initPassiveLoading(file) {
|
||||
if (
|
||||
typeof PDFJSDev === "undefined" ||
|
||||
!PDFJSDev.test("MOZCENTRAL || CHROME")
|
||||
) {
|
||||
throw new Error("Not implemented: initPassiveLoading");
|
||||
}
|
||||
this.setTitleUsingUrl(file, /* downloadUrl = */ file);
|
||||
|
||||
this.externalServices.initPassiveLoading({
|
||||
onOpenWithTransport: range => {
|
||||
this.open({ range });
|
||||
},
|
||||
onOpenWithData: (data, contentDispositionFilename) => {
|
||||
if (isPdfFile(contentDispositionFilename)) {
|
||||
this._contentDispositionFilename = contentDispositionFilename;
|
||||
}
|
||||
this.open({ data });
|
||||
},
|
||||
onOpenWithURL: (url, length, originalUrl) => {
|
||||
this.open({ url, length, originalUrl });
|
||||
},
|
||||
onError: err => {
|
||||
this._documentError("pdfjs-loading-error", err);
|
||||
},
|
||||
onProgress: (loaded, total) => {
|
||||
this.progress(loaded / total);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
setTitleUsingUrl(url = "", downloadUrl = null) {
|
||||
this.url = url;
|
||||
this.baseUrl = url.split("#", 1)[0];
|
||||
|
@ -987,10 +958,11 @@ const PDFViewerApplication = {
|
|||
const workerParams = AppOptions.getAll(OptionKind.WORKER);
|
||||
Object.assign(GlobalWorkerOptions, workerParams);
|
||||
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
|
||||
args.url
|
||||
) {
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||
if (args.data && isPdfFile(args.filename)) {
|
||||
this._contentDispositionFilename = args.filename;
|
||||
}
|
||||
} else if (args.url) {
|
||||
// The Firefox built-in viewer always calls `setTitleUsingUrl`, before
|
||||
// `initPassiveLoading`, and it never provides an `originalUrl` here.
|
||||
this.setTitleUsingUrl(
|
||||
|
|
|
@ -417,12 +417,11 @@ class Preferences extends BasePreferences {
|
|||
}
|
||||
|
||||
class ExternalServices extends BaseExternalServices {
|
||||
initPassiveLoading(callbacks) {
|
||||
// defaultUrl is set in viewer.js
|
||||
initPassiveLoading() {
|
||||
ChromeCom.resolvePDFFile(
|
||||
AppOptions.get("defaultUrl"),
|
||||
function (url, length, originalUrl) {
|
||||
callbacks.onOpenWithURL(url, length, originalUrl);
|
||||
viewerApp.open({ url, length, originalUrl });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class BaseExternalServices {
|
|||
|
||||
updateFindMatchesCount(data) {}
|
||||
|
||||
initPassiveLoading(callbacks) {}
|
||||
initPassiveLoading() {}
|
||||
|
||||
reportTelemetry(data) {}
|
||||
|
||||
|
|
|
@ -323,7 +323,7 @@ class ExternalServices extends BaseExternalServices {
|
|||
FirefoxCom.request("updateFindMatchesCount", data);
|
||||
}
|
||||
|
||||
initPassiveLoading(callbacks) {
|
||||
initPassiveLoading() {
|
||||
let pdfDataRangeTransport;
|
||||
|
||||
window.addEventListener("message", function windowMessage(e) {
|
||||
|
@ -340,7 +340,7 @@ class ExternalServices extends BaseExternalServices {
|
|||
switch (args.pdfjsLoadAction) {
|
||||
case "supportsRangedLoading":
|
||||
if (args.done && !args.data) {
|
||||
callbacks.onError();
|
||||
viewerApp._documentError(null);
|
||||
break;
|
||||
}
|
||||
pdfDataRangeTransport = new FirefoxComDataRangeTransport(
|
||||
|
@ -350,7 +350,7 @@ class ExternalServices extends BaseExternalServices {
|
|||
args.filename
|
||||
);
|
||||
|
||||
callbacks.onOpenWithTransport(pdfDataRangeTransport);
|
||||
viewerApp.open({ range: pdfDataRangeTransport });
|
||||
break;
|
||||
case "range":
|
||||
pdfDataRangeTransport.onDataRange(args.begin, args.chunk);
|
||||
|
@ -369,14 +369,14 @@ class ExternalServices extends BaseExternalServices {
|
|||
pdfDataRangeTransport?.onDataProgressiveDone();
|
||||
break;
|
||||
case "progress":
|
||||
callbacks.onProgress(args.loaded, args.total);
|
||||
viewerApp.progress(args.loaded / args.total);
|
||||
break;
|
||||
case "complete":
|
||||
if (!args.data) {
|
||||
callbacks.onError(args.errorCode);
|
||||
viewerApp._documentError(null, { message: args.errorCode });
|
||||
break;
|
||||
}
|
||||
callbacks.onOpenWithData(args.data, args.filename);
|
||||
viewerApp.open({ data: args.data, filename: args.filename });
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue