Skip to content

Ensure that the contentDispositionFilename is always respected, when setting the document title (PR 13014 follow-up) #14964

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ const PDFViewerApplication = {
appConfig.documentProperties,
this.overlayManager,
eventBus,
this.l10n
this.l10n,
/* fileNameLookup = */ () => {
return this._docFilename;
}
);

this.pdfCursorTools = new PDFCursorTools({
Expand Down Expand Up @@ -1194,7 +1197,7 @@ const PDFViewerApplication = {
baseDocumentUrl = location.href.split("#")[0];
}
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
this.pdfDocumentProperties.setDocument(pdfDocument);

const pdfViewer = this.pdfViewer;
pdfViewer.setDocument(pdfDocument);
Expand Down Expand Up @@ -1515,16 +1518,15 @@ const PDFViewerApplication = {
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
`(PDF.js: ${version || "-"})`
);
let pdfTitle = info?.Title;
let pdfTitle = info.Title;

const metadataTitle = metadata?.get("dc:title");
if (metadataTitle) {
// Ghostscript can produce invalid 'dc:title' Metadata entries:
// - The title may be "Untitled" (fixes bug 1031612).
// - The title may contain incorrectly encoded characters, which thus
// looks broken, hence we ignore the Metadata entry when it
// contains characters from the Specials Unicode block
// (fixes bug 1605526).
// looks broken, hence we ignore the Metadata entry when it contains
// characters from the Specials Unicode block (fixes bug 1605526).
if (
metadataTitle !== "Untitled" &&
!/[\uFFF0-\uFFFF]/g.test(metadataTitle)
Expand All @@ -1534,10 +1536,10 @@ const PDFViewerApplication = {
}
if (pdfTitle) {
this.setTitle(
`${pdfTitle} - ${contentDispositionFilename || document.title}`
`${pdfTitle} - ${this._contentDispositionFilename || document.title}`
);
} else if (contentDispositionFilename) {
this.setTitle(contentDispositionFilename);
} else if (this._contentDispositionFilename) {
this.setTitle(this._contentDispositionFilename);
}

if (
Expand Down
33 changes: 17 additions & 16 deletions web/pdf_document_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
* limitations under the License.
*/

import {
createPromiseCapability,
getPdfFilenameFromUrl,
PDFDateString,
} from "pdfjs-lib";
import { createPromiseCapability, PDFDateString } from "pdfjs-lib";
import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";

const DEFAULT_FIELD_CONTENT = "-";
Expand Down Expand Up @@ -58,12 +54,21 @@ class PDFDocumentProperties {
* @param {OverlayManager} overlayManager - Manager for the viewer overlays.
* @param {EventBus} eventBus - The application event bus.
* @param {IL10n} l10n - Localization service.
* @param {function} fileNameLookup - The function that is used to lookup
* the document fileName.
*/
constructor({ dialog, fields, closeButton }, overlayManager, eventBus, l10n) {
constructor(
{ dialog, fields, closeButton },
overlayManager,
eventBus,
l10n,
fileNameLookup
) {
this.dialog = dialog;
this.fields = fields;
this.overlayManager = overlayManager;
this.l10n = l10n;
this._fileNameLookup = fileNameLookup;

this.#reset();
// Bind the event listener for the Close button.
Expand Down Expand Up @@ -110,7 +115,7 @@ class PDFDocumentProperties {
const {
info,
/* metadata, */
contentDispositionFilename,
/* contentDispositionFilename, */
contentLength,
} = await this.pdfDocument.getMetadata();

Expand All @@ -122,7 +127,7 @@ class PDFDocumentProperties {
pageSize,
isLinearized,
] = await Promise.all([
contentDispositionFilename || getPdfFilenameFromUrl(this.url),
this._fileNameLookup(),
this.#parseFileSize(contentLength),
this.#parseDate(info.CreationDate),
this.#parseDate(info.ModDate),
Expand Down Expand Up @@ -173,15 +178,13 @@ class PDFDocumentProperties {
}

/**
* Set a reference to the PDF document and the URL in order
* to populate the overlay fields with the document properties.
* Note that the overlay will contain no information if this method
* is not called.
* Set a reference to the PDF document in order to populate the dialog fields
* with the document properties. Note that the dialog will contain no
* information if this method is not called.
*
* @param {PDFDocumentProxy} pdfDocument - A reference to the PDF document.
* @param {string} url - The URL of the document.
*/
setDocument(pdfDocument, url = null) {
setDocument(pdfDocument) {
if (this.pdfDocument) {
this.#reset();
this.#updateUI(true);
Expand All @@ -190,14 +193,12 @@ class PDFDocumentProperties {
return;
}
this.pdfDocument = pdfDocument;
this.url = url;

this._dataAvailableCapability.resolve();
}

#reset() {
this.pdfDocument = null;
this.url = null;

this.#fieldData = null;
this._dataAvailableCapability = createPromiseCapability();
Expand Down