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,
|
appConfig.documentProperties,
|
||||||
this.overlayManager,
|
this.overlayManager,
|
||||||
eventBus,
|
eventBus,
|
||||||
this.l10n
|
this.l10n,
|
||||||
|
/* fileNameLookup = */ () => {
|
||||||
|
return this._docFilename;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.pdfCursorTools = new PDFCursorTools({
|
this.pdfCursorTools = new PDFCursorTools({
|
||||||
@ -1197,7 +1200,7 @@ const PDFViewerApplication = {
|
|||||||
baseDocumentUrl = location.href.split("#")[0];
|
baseDocumentUrl = location.href.split("#")[0];
|
||||||
}
|
}
|
||||||
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
||||||
this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
|
this.pdfDocumentProperties.setDocument(pdfDocument);
|
||||||
|
|
||||||
const pdfViewer = this.pdfViewer;
|
const pdfViewer = this.pdfViewer;
|
||||||
pdfViewer.setDocument(pdfDocument);
|
pdfViewer.setDocument(pdfDocument);
|
||||||
@ -1518,16 +1521,15 @@ const PDFViewerApplication = {
|
|||||||
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
|
`${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` +
|
||||||
`(PDF.js: ${version || "-"})`
|
`(PDF.js: ${version || "-"})`
|
||||||
);
|
);
|
||||||
let pdfTitle = info?.Title;
|
let pdfTitle = info.Title;
|
||||||
|
|
||||||
const metadataTitle = metadata?.get("dc:title");
|
const metadataTitle = metadata?.get("dc:title");
|
||||||
if (metadataTitle) {
|
if (metadataTitle) {
|
||||||
// Ghostscript can produce invalid 'dc:title' Metadata entries:
|
// Ghostscript can produce invalid 'dc:title' Metadata entries:
|
||||||
// - The title may be "Untitled" (fixes bug 1031612).
|
// - The title may be "Untitled" (fixes bug 1031612).
|
||||||
// - The title may contain incorrectly encoded characters, which thus
|
// - The title may contain incorrectly encoded characters, which thus
|
||||||
// looks broken, hence we ignore the Metadata entry when it
|
// looks broken, hence we ignore the Metadata entry when it contains
|
||||||
// contains characters from the Specials Unicode block
|
// characters from the Specials Unicode block (fixes bug 1605526).
|
||||||
// (fixes bug 1605526).
|
|
||||||
if (
|
if (
|
||||||
metadataTitle !== "Untitled" &&
|
metadataTitle !== "Untitled" &&
|
||||||
!/[\uFFF0-\uFFFF]/g.test(metadataTitle)
|
!/[\uFFF0-\uFFFF]/g.test(metadataTitle)
|
||||||
@ -1537,10 +1539,10 @@ const PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
if (pdfTitle) {
|
if (pdfTitle) {
|
||||||
this.setTitle(
|
this.setTitle(
|
||||||
`${pdfTitle} - ${contentDispositionFilename || document.title}`
|
`${pdfTitle} - ${this._contentDispositionFilename || document.title}`
|
||||||
);
|
);
|
||||||
} else if (contentDispositionFilename) {
|
} else if (this._contentDispositionFilename) {
|
||||||
this.setTitle(contentDispositionFilename);
|
this.setTitle(this._contentDispositionFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -13,11 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { createPromiseCapability, PDFDateString } from "pdfjs-lib";
|
||||||
createPromiseCapability,
|
|
||||||
getPdfFilenameFromUrl,
|
|
||||||
PDFDateString,
|
|
||||||
} from "pdfjs-lib";
|
|
||||||
import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";
|
import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";
|
||||||
|
|
||||||
const DEFAULT_FIELD_CONTENT = "-";
|
const DEFAULT_FIELD_CONTENT = "-";
|
||||||
@ -58,12 +54,21 @@ class PDFDocumentProperties {
|
|||||||
* @param {OverlayManager} overlayManager - Manager for the viewer overlays.
|
* @param {OverlayManager} overlayManager - Manager for the viewer overlays.
|
||||||
* @param {EventBus} eventBus - The application event bus.
|
* @param {EventBus} eventBus - The application event bus.
|
||||||
* @param {IL10n} l10n - Localization service.
|
* @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.dialog = dialog;
|
||||||
this.fields = fields;
|
this.fields = fields;
|
||||||
this.overlayManager = overlayManager;
|
this.overlayManager = overlayManager;
|
||||||
this.l10n = l10n;
|
this.l10n = l10n;
|
||||||
|
this._fileNameLookup = fileNameLookup;
|
||||||
|
|
||||||
this.#reset();
|
this.#reset();
|
||||||
// Bind the event listener for the Close button.
|
// Bind the event listener for the Close button.
|
||||||
@ -110,7 +115,7 @@ class PDFDocumentProperties {
|
|||||||
const {
|
const {
|
||||||
info,
|
info,
|
||||||
/* metadata, */
|
/* metadata, */
|
||||||
contentDispositionFilename,
|
/* contentDispositionFilename, */
|
||||||
contentLength,
|
contentLength,
|
||||||
} = await this.pdfDocument.getMetadata();
|
} = await this.pdfDocument.getMetadata();
|
||||||
|
|
||||||
@ -122,7 +127,7 @@ class PDFDocumentProperties {
|
|||||||
pageSize,
|
pageSize,
|
||||||
isLinearized,
|
isLinearized,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
contentDispositionFilename || getPdfFilenameFromUrl(this.url),
|
this._fileNameLookup(),
|
||||||
this.#parseFileSize(contentLength),
|
this.#parseFileSize(contentLength),
|
||||||
this.#parseDate(info.CreationDate),
|
this.#parseDate(info.CreationDate),
|
||||||
this.#parseDate(info.ModDate),
|
this.#parseDate(info.ModDate),
|
||||||
@ -173,15 +178,13 @@ class PDFDocumentProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a reference to the PDF document and the URL in order
|
* Set a reference to the PDF document in order to populate the dialog fields
|
||||||
* to populate the overlay fields with the document properties.
|
* with the document properties. Note that the dialog will contain no
|
||||||
* Note that the overlay will contain no information if this method
|
* information if this method is not called.
|
||||||
* is not called.
|
|
||||||
*
|
*
|
||||||
* @param {PDFDocumentProxy} pdfDocument - A reference to the PDF document.
|
* @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) {
|
if (this.pdfDocument) {
|
||||||
this.#reset();
|
this.#reset();
|
||||||
this.#updateUI(true);
|
this.#updateUI(true);
|
||||||
@ -190,14 +193,12 @@ class PDFDocumentProperties {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.pdfDocument = pdfDocument;
|
this.pdfDocument = pdfDocument;
|
||||||
this.url = url;
|
|
||||||
|
|
||||||
this._dataAvailableCapability.resolve();
|
this._dataAvailableCapability.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
#reset() {
|
#reset() {
|
||||||
this.pdfDocument = null;
|
this.pdfDocument = null;
|
||||||
this.url = null;
|
|
||||||
|
|
||||||
this.#fieldData = null;
|
this.#fieldData = null;
|
||||||
this._dataAvailableCapability = createPromiseCapability();
|
this._dataAvailableCapability = createPromiseCapability();
|
||||||
|
Loading…
Reference in New Issue
Block a user