Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that the correct pdfDocument is still active, before rendering the outline/attachments/layers #13212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1383,14 +1383,23 @@ const PDFViewerApplication = {

onePageRendered.then(() => {
pdfDocument.getOutline().then(outline => {
if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the outline resolved.
}
this.pdfOutlineViewer.render({ outline, pdfDocument });
});
pdfDocument.getAttachments().then(attachments => {
if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the attachments resolved.
}
this.pdfAttachmentViewer.render({ attachments });
});
// Ensure that the layers accurately reflects the current state in the
// viewer itself, rather than the default state provided by the API.
pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
if (pdfDocument !== this.pdfDocument) {
return; // The document was closed while the layers resolved.
}
this.pdfLayerViewer.render({ optionalContentConfig, pdfDocument });
});
if (
Expand Down
28 changes: 26 additions & 2 deletions web/pdf_outline_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ class PDFOutlineViewer extends BaseTreeViewer {
});
this.eventBus._on("pagesloaded", evt => {
this._isPagesLoaded = !!evt.pagesCount;

// If the capability is still pending, note the `_dispatchEvent`-method,
// we know that the `currentOutlineItem`-button should be enabled here.
if (
this._currentOutlineItemCapability &&
!this._currentOutlineItemCapability.settled
) {
this._currentOutlineItemCapability.resolve(/* enabled = */ true);
}
});
this.eventBus._on("sidebarviewchanged", evt => {
this._sidebarView = evt.view;
Expand All @@ -66,17 +75,32 @@ class PDFOutlineViewer extends BaseTreeViewer {
this._pageNumberToDestHashCapability = null;
this._currentPageNumber = 1;
this._isPagesLoaded = false;

if (
this._currentOutlineItemCapability &&
!this._currentOutlineItemCapability.settled
) {
this._currentOutlineItemCapability.resolve(/* enabled = */ false);
}
this._currentOutlineItemCapability = null;
}

/**
* @private
*/
_dispatchEvent(outlineCount) {
this._currentOutlineItemCapability = createPromiseCapability();
if (
outlineCount === 0 ||
this._pdfDocument?.loadingParams.disableAutoFetch
) {
this._currentOutlineItemCapability.resolve(/* enabled = */ false);
}

this.eventBus.dispatch("outlineloaded", {
source: this,
outlineCount,
enableCurrentOutlineItemButton:
outlineCount > 0 && !this._pdfDocument?.loadingParams.disableAutoFetch,
currentOutlineItemPromise: this._currentOutlineItemCapability.promise,
});
}

Expand Down
11 changes: 6 additions & 5 deletions web/pdf_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,12 @@ class PDFSidebar {
this.eventBus._on("outlineloaded", evt => {
onTreeLoaded(evt.outlineCount, this.outlineButton, SidebarView.OUTLINE);

if (evt.enableCurrentOutlineItemButton) {
this.pdfViewer.pagesPromise.then(() => {
this._currentOutlineItemButton.disabled = !this.isInitialViewSet;
});
}
evt.currentOutlineItemPromise.then(enabled => {
if (!this.isInitialViewSet) {
return;
}
this._currentOutlineItemButton.disabled = !enabled;
});
});

this.eventBus._on("attachmentsloaded", evt => {
Expand Down