Merge pull request #14964 from Snuffleupagus/onOpenWithData-contentDispositionFilename
Ensure that the `contentDispositionFilename` is always respected, when setting the document title (PR 13014 follow-up)
This commit is contained in:
commit
a43a30bb7b
20
web/app.js
20
web/app.js
@ -564,7 +564,10 @@ const PDFViewerApplication = {
|
||||
appConfig.documentProperties,
|
||||
this.overlayManager,
|
||||
eventBus,
|
||||
this.l10n
|
||||
this.l10n,
|
||||
/* fileNameLookup = */ () => {
|
||||
return this._docFilename;
|
||||
}
|
||||
);
|
||||
|
||||
this.pdfCursorTools = new PDFCursorTools({
|
||||
@ -1197,7 +1200,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);
|
||||
@ -1518,16 +1521,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)
|
||||
@ -1537,10 +1539,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 (
|
||||
|
@ -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 = "-";
|
||||
@ -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.
|
||||
@ -110,7 +115,7 @@ class PDFDocumentProperties {
|
||||
const {
|
||||
info,
|
||||
/* metadata, */
|
||||
contentDispositionFilename,
|
||||
/* contentDispositionFilename, */
|
||||
contentLength,
|
||||
} = await this.pdfDocument.getMetadata();
|
||||
|
||||
@ -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),
|
||||
@ -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);
|
||||
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user