Remove the PDFPageView.error
property, and simply include Errors in the "pagerendered" event instead
The way that rendering errors are handled in `PDFPageView` is *very* old, and predates e.g. the introduction of the `EventBus` by several years. Hence we should be able to simplify things a bit here, by including the Error (when it exists) in the "pagerendered" event and thus avoid having to reach into `PDFPageView` for it.
This commit is contained in:
parent
7b15094cdf
commit
9efc1784b2
@ -2126,8 +2126,7 @@ function webViewerResetPermissions() {
|
|||||||
appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
function webViewerPageRendered(evt) {
|
function webViewerPageRendered({ pageNumber, timestamp, error }) {
|
||||||
const pageNumber = evt.pageNumber;
|
|
||||||
const pageIndex = pageNumber - 1;
|
const pageIndex = pageNumber - 1;
|
||||||
const pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
const pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
|
||||||
|
|
||||||
@ -2155,7 +2154,7 @@ function webViewerPageRendered(evt) {
|
|||||||
Stats.add(pageNumber, pageView.stats);
|
Stats.add(pageNumber, pageView.stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageView.error) {
|
if (error) {
|
||||||
PDFViewerApplication.l10n
|
PDFViewerApplication.l10n
|
||||||
.get(
|
.get(
|
||||||
"rendering_error",
|
"rendering_error",
|
||||||
@ -2163,13 +2162,13 @@ function webViewerPageRendered(evt) {
|
|||||||
"An error occurred while rendering the page."
|
"An error occurred while rendering the page."
|
||||||
)
|
)
|
||||||
.then(msg => {
|
.then(msg => {
|
||||||
PDFViewerApplication.error(msg, pageView.error);
|
PDFViewerApplication.error(msg, error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFViewerApplication.externalServices.reportTelemetry({
|
PDFViewerApplication.externalServices.reportTelemetry({
|
||||||
type: "pageInfo",
|
type: "pageInfo",
|
||||||
timestamp: evt.timestamp,
|
timestamp,
|
||||||
});
|
});
|
||||||
// It is a good time to report stream and font types.
|
// It is a good time to report stream and font types.
|
||||||
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
|
||||||
|
@ -114,7 +114,7 @@ class PDFPageView {
|
|||||||
this.paintedViewportMap = new WeakMap();
|
this.paintedViewportMap = new WeakMap();
|
||||||
this.renderingState = RenderingStates.INITIAL;
|
this.renderingState = RenderingStates.INITIAL;
|
||||||
this.resume = null;
|
this.resume = null;
|
||||||
this.error = null;
|
this._renderError = null;
|
||||||
|
|
||||||
this.annotationLayer = null;
|
this.annotationLayer = null;
|
||||||
this.textLayer = null;
|
this.textLayer = null;
|
||||||
@ -265,6 +265,7 @@ class PDFPageView {
|
|||||||
pageNumber: this.id,
|
pageNumber: this.id,
|
||||||
cssTransform: true,
|
cssTransform: true,
|
||||||
timestamp: performance.now(),
|
timestamp: performance.now(),
|
||||||
|
error: this._renderError,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -293,6 +294,7 @@ class PDFPageView {
|
|||||||
pageNumber: this.id,
|
pageNumber: this.id,
|
||||||
cssTransform: true,
|
cssTransform: true,
|
||||||
timestamp: performance.now(),
|
timestamp: performance.now(),
|
||||||
|
error: this._renderError,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -500,7 +502,7 @@ class PDFPageView {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const finishPaintTask = async error => {
|
const finishPaintTask = async (error = null) => {
|
||||||
// The paintTask may have been replaced by a new one, so only remove
|
// The paintTask may have been replaced by a new one, so only remove
|
||||||
// the reference to the paintTask if it matches the one that is
|
// the reference to the paintTask if it matches the one that is
|
||||||
// triggering this callback.
|
// triggering this callback.
|
||||||
@ -509,9 +511,10 @@ class PDFPageView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (error instanceof RenderingCancelledException) {
|
if (error instanceof RenderingCancelledException) {
|
||||||
this.error = null;
|
this._renderError = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this._renderError = error;
|
||||||
|
|
||||||
this.renderingState = RenderingStates.FINISHED;
|
this.renderingState = RenderingStates.FINISHED;
|
||||||
|
|
||||||
@ -521,7 +524,6 @@ class PDFPageView {
|
|||||||
}
|
}
|
||||||
this._resetZoomLayer(/* removeFromDOM = */ true);
|
this._resetZoomLayer(/* removeFromDOM = */ true);
|
||||||
|
|
||||||
this.error = error;
|
|
||||||
this.stats = pdfPage.stats;
|
this.stats = pdfPage.stats;
|
||||||
|
|
||||||
this.eventBus.dispatch("pagerendered", {
|
this.eventBus.dispatch("pagerendered", {
|
||||||
@ -529,6 +531,7 @@ class PDFPageView {
|
|||||||
pageNumber: this.id,
|
pageNumber: this.id,
|
||||||
cssTransform: false,
|
cssTransform: false,
|
||||||
timestamp: performance.now(),
|
timestamp: performance.now(),
|
||||||
|
error: this._renderError,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -317,7 +317,7 @@ class PDFThumbnailView {
|
|||||||
this.renderingState = RenderingStates.RUNNING;
|
this.renderingState = RenderingStates.RUNNING;
|
||||||
|
|
||||||
const renderCapability = createPromiseCapability();
|
const renderCapability = createPromiseCapability();
|
||||||
const finishRenderTask = error => {
|
const finishRenderTask = (error = null) => {
|
||||||
// The renderTask may have been replaced by a new one, so only remove
|
// The renderTask may have been replaced by a new one, so only remove
|
||||||
// the reference to the renderTask if it matches the one that is
|
// the reference to the renderTask if it matches the one that is
|
||||||
// triggering this callback.
|
// triggering this callback.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user