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:
Tim van der Meij 2022-05-29 13:26:23 +02:00 committed by GitHub
commit a43a30bb7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 25 deletions

View file

@ -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 (