Skip to content

Commit 2772723

Browse files
committed
Split PDFViewerApplication.error into two methods, for PDF document loading/parsing errors vs other errors (PR 11647 follow-up)
With these changes, we can easily unblock the "load" event regardless of where an error occurred.
1 parent 3d33313 commit 2772723

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

web/app.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ const PDFViewerApplication = {
728728
"An error occurred while loading the PDF."
729729
)
730730
.then(msg => {
731-
PDFViewerApplication.error(msg, err);
731+
PDFViewerApplication._documentError(msg, err);
732732
});
733733
},
734734
onProgress(loaded, total) {
@@ -812,6 +812,8 @@ const PDFViewerApplication = {
812812
* destruction is completed.
813813
*/
814814
async close() {
815+
this._unblockDocumentLoadEvent();
816+
815817
const errorWrapper = this.appConfig.errorWrapper.container;
816818
errorWrapper.setAttribute("hidden", "true");
817819

@@ -943,8 +945,6 @@ const PDFViewerApplication = {
943945
this.load(pdfDocument);
944946
},
945947
exception => {
946-
this._unblockDocumentLoadEvent();
947-
948948
if (loadingTask !== this.pdfLoadingTask) {
949949
return undefined; // Ignore errors for previously opened PDF files.
950950
}
@@ -980,7 +980,7 @@ const PDFViewerApplication = {
980980
}
981981

982982
return loadingErrorMessage.then(msg => {
983-
this.error(msg, { message });
983+
this._documentError(msg, { message });
984984
throw exception;
985985
});
986986
}
@@ -1114,13 +1114,24 @@ const PDFViewerApplication = {
11141114
},
11151115

11161116
/**
1117-
* Show the error box.
1117+
* Show the error box; used for errors affecting loading and/or parsing of
1118+
* the entire PDF document.
1119+
*/
1120+
_documentError(message, moreInfo = null) {
1121+
this._unblockDocumentLoadEvent();
1122+
1123+
this._otherError(message, moreInfo);
1124+
},
1125+
1126+
/**
1127+
* Show the error box; used for errors affecting e.g. only a single page.
1128+
*
11181129
* @param {string} message - A message that is human readable.
11191130
* @param {Object} [moreInfo] - Further information about the error that is
11201131
* more technical. Should have a 'message' and
11211132
* optionally a 'stack' property.
11221133
*/
1123-
error(message, moreInfo) {
1134+
_otherError(message, moreInfo = null) {
11241135
const moreInfoText = [
11251136
this.l10n.get(
11261137
"error_version_info",
@@ -2051,7 +2062,7 @@ const PDFViewerApplication = {
20512062
"Warning: Printing is not fully supported by this browser."
20522063
)
20532064
.then(printMessage => {
2054-
this.error(printMessage);
2065+
this._otherError(printMessage);
20552066
});
20562067
return;
20572068
}
@@ -2392,7 +2403,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
23922403
PDFViewerApplication.l10n
23932404
.get("loading_error", null, "An error occurred while loading the PDF.")
23942405
.then(loadingErrorMessage => {
2395-
PDFViewerApplication.error(loadingErrorMessage, {
2406+
PDFViewerApplication._documentError(loadingErrorMessage, {
23962407
message: ex?.message,
23972408
});
23982409
});
@@ -2545,7 +2556,7 @@ function webViewerInitialized() {
25452556
PDFViewerApplication.l10n
25462557
.get("loading_error", null, "An error occurred while loading the PDF.")
25472558
.then(msg => {
2548-
PDFViewerApplication.error(msg, reason);
2559+
PDFViewerApplication._documentError(msg, reason);
25492560
});
25502561
}
25512562
}
@@ -2622,7 +2633,7 @@ function webViewerPageRendered({ pageNumber, timestamp, error }) {
26222633
"An error occurred while rendering the page."
26232634
)
26242635
.then(msg => {
2625-
PDFViewerApplication.error(msg, error);
2636+
PDFViewerApplication._otherError(msg, error);
26262637
});
26272638
}
26282639

web/chromecom.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const ChromeCom = {
8686
// Even without this check, the file load in frames is still blocked,
8787
// but this may change in the future (https://crbug.com/550151).
8888
if (origin && !/^file:|^chrome-extension:/.test(origin)) {
89-
PDFViewerApplication.error(
89+
PDFViewerApplication._documentError(
9090
"Blocked " +
9191
origin +
9292
" from loading " +

0 commit comments

Comments
 (0)