Skip to content

Commit a43a30b

Browse files
Merge pull request #14964 from Snuffleupagus/onOpenWithData-contentDispositionFilename
Ensure that the `contentDispositionFilename` is always respected, when setting the document title (PR 13014 follow-up)
2 parents 3e67d97 + 0599ce7 commit a43a30b

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

web/app.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,10 @@ const PDFViewerApplication = {
564564
appConfig.documentProperties,
565565
this.overlayManager,
566566
eventBus,
567-
this.l10n
567+
this.l10n,
568+
/* fileNameLookup = */ () => {
569+
return this._docFilename;
570+
}
568571
);
569572

570573
this.pdfCursorTools = new PDFCursorTools({
@@ -1197,7 +1200,7 @@ const PDFViewerApplication = {
11971200
baseDocumentUrl = location.href.split("#")[0];
11981201
}
11991202
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
1200-
this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
1203+
this.pdfDocumentProperties.setDocument(pdfDocument);
12011204

12021205
const pdfViewer = this.pdfViewer;
12031206
pdfViewer.setDocument(pdfDocument);
@@ -1518,16 +1521,15 @@ const PDFViewerApplication = {
15181521
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
15191522
`(PDF.js: ${version || "-"})`
15201523
);
1521-
let pdfTitle = info?.Title;
1524+
let pdfTitle = info.Title;
15221525

15231526
const metadataTitle = metadata?.get("dc:title");
15241527
if (metadataTitle) {
15251528
// Ghostscript can produce invalid 'dc:title' Metadata entries:
15261529
// - The title may be "Untitled" (fixes bug 1031612).
15271530
// - The title may contain incorrectly encoded characters, which thus
1528-
// looks broken, hence we ignore the Metadata entry when it
1529-
// contains characters from the Specials Unicode block
1530-
// (fixes bug 1605526).
1531+
// looks broken, hence we ignore the Metadata entry when it contains
1532+
// characters from the Specials Unicode block (fixes bug 1605526).
15311533
if (
15321534
metadataTitle !== "Untitled" &&
15331535
!/[\uFFF0-\uFFFF]/g.test(metadataTitle)
@@ -1537,10 +1539,10 @@ const PDFViewerApplication = {
15371539
}
15381540
if (pdfTitle) {
15391541
this.setTitle(
1540-
`${pdfTitle} - ${contentDispositionFilename || document.title}`
1542+
`${pdfTitle} - ${this._contentDispositionFilename || document.title}`
15411543
);
1542-
} else if (contentDispositionFilename) {
1543-
this.setTitle(contentDispositionFilename);
1544+
} else if (this._contentDispositionFilename) {
1545+
this.setTitle(this._contentDispositionFilename);
15441546
}
15451547

15461548
if (

web/pdf_document_properties.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import {
17-
createPromiseCapability,
18-
getPdfFilenameFromUrl,
19-
PDFDateString,
20-
} from "pdfjs-lib";
16+
import { createPromiseCapability, PDFDateString } from "pdfjs-lib";
2117
import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";
2218

2319
const DEFAULT_FIELD_CONTENT = "-";
@@ -58,12 +54,21 @@ class PDFDocumentProperties {
5854
* @param {OverlayManager} overlayManager - Manager for the viewer overlays.
5955
* @param {EventBus} eventBus - The application event bus.
6056
* @param {IL10n} l10n - Localization service.
57+
* @param {function} fileNameLookup - The function that is used to lookup
58+
* the document fileName.
6159
*/
62-
constructor({ dialog, fields, closeButton }, overlayManager, eventBus, l10n) {
60+
constructor(
61+
{ dialog, fields, closeButton },
62+
overlayManager,
63+
eventBus,
64+
l10n,
65+
fileNameLookup
66+
) {
6367
this.dialog = dialog;
6468
this.fields = fields;
6569
this.overlayManager = overlayManager;
6670
this.l10n = l10n;
71+
this._fileNameLookup = fileNameLookup;
6772

6873
this.#reset();
6974
// Bind the event listener for the Close button.
@@ -110,7 +115,7 @@ class PDFDocumentProperties {
110115
const {
111116
info,
112117
/* metadata, */
113-
contentDispositionFilename,
118+
/* contentDispositionFilename, */
114119
contentLength,
115120
} = await this.pdfDocument.getMetadata();
116121

@@ -122,7 +127,7 @@ class PDFDocumentProperties {
122127
pageSize,
123128
isLinearized,
124129
] = await Promise.all([
125-
contentDispositionFilename || getPdfFilenameFromUrl(this.url),
130+
this._fileNameLookup(),
126131
this.#parseFileSize(contentLength),
127132
this.#parseDate(info.CreationDate),
128133
this.#parseDate(info.ModDate),
@@ -173,15 +178,13 @@ class PDFDocumentProperties {
173178
}
174179

175180
/**
176-
* Set a reference to the PDF document and the URL in order
177-
* to populate the overlay fields with the document properties.
178-
* Note that the overlay will contain no information if this method
179-
* is not called.
181+
* Set a reference to the PDF document in order to populate the dialog fields
182+
* with the document properties. Note that the dialog will contain no
183+
* information if this method is not called.
180184
*
181185
* @param {PDFDocumentProxy} pdfDocument - A reference to the PDF document.
182-
* @param {string} url - The URL of the document.
183186
*/
184-
setDocument(pdfDocument, url = null) {
187+
setDocument(pdfDocument) {
185188
if (this.pdfDocument) {
186189
this.#reset();
187190
this.#updateUI(true);
@@ -190,14 +193,12 @@ class PDFDocumentProperties {
190193
return;
191194
}
192195
this.pdfDocument = pdfDocument;
193-
this.url = url;
194196

195197
this._dataAvailableCapability.resolve();
196198
}
197199

198200
#reset() {
199201
this.pdfDocument = null;
200-
this.url = null;
201202

202203
this.#fieldData = null;
203204
this._dataAvailableCapability = createPromiseCapability();

0 commit comments

Comments
 (0)