Merge pull request #11917 from Snuffleupagus/bug-1632644

[Firefox] Allow PDF attachments to, once again, be opened directly in the browser (bug 1632644)
This commit is contained in:
Tim van der Meij 2020-05-20 12:55:20 +02:00 committed by GitHub
commit 0960e6c0b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 4 deletions

View File

@ -1858,7 +1858,7 @@ function webViewerInitialized() {
file = "file" in params ? params.file : AppOptions.get("defaultUrl"); file = "file" in params ? params.file : AppOptions.get("defaultUrl");
validateFileURL(file); validateFileURL(file);
} else if (PDFJSDev.test("MOZCENTRAL")) { } else if (PDFJSDev.test("MOZCENTRAL")) {
file = window.location.href.split("#")[0]; file = window.location.href;
} else if (PDFJSDev.test("CHROME")) { } else if (PDFJSDev.test("CHROME")) {
file = AppOptions.get("defaultUrl"); file = AppOptions.get("defaultUrl");
} }

View File

@ -95,7 +95,7 @@ class PDFAttachmentViewer {
viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename); viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
} else if (PDFJSDev.test("MOZCENTRAL")) { } else if (PDFJSDev.test("MOZCENTRAL")) {
// Let Firefox's content handler catch the URL and display the PDF. // Let Firefox's content handler catch the URL and display the PDF.
viewerUrl = blobUrl + "?" + encodeURIComponent(filename); viewerUrl = blobUrl + "#filename=" + encodeURIComponent(filename);
} else if (PDFJSDev.test("CHROME")) { } else if (PDFJSDev.test("CHROME")) {
// In the Chrome extension, the URL is rewritten using the history API // In the Chrome extension, the URL is rewritten using the history API
// in viewer.js, so an absolute URL must be generated. // in viewer.js, so an absolute URL must be generated.

View File

@ -132,7 +132,7 @@ class PDFDocumentProperties {
return Promise.all([ return Promise.all([
info, info,
metadata, metadata,
contentDispositionFilename || getPDFFileNameFromURL(this.url || ""), contentDispositionFilename || getPDFFileNameFromURL(this.url),
this._parseFileSize(this.maybeFileSize), this._parseFileSize(this.maybeFileSize),
this._parseDate(info.CreationDate), this._parseDate(info.CreationDate),
this._parseDate(info.ModDate), this._parseDate(info.ModDate),

View File

@ -610,7 +610,7 @@ function getPDFFileNameFromURL(url, defaultFilename = "document.pdf") {
return defaultFilename; return defaultFilename;
} }
const reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/; const reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
// SCHEME HOST 1.PATH 2.QUERY 3.REF // SCHEME HOST 1.PATH 2.QUERY 3.REF
// Pattern to get last matching NAME.pdf // Pattern to get last matching NAME.pdf
const reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i; const reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
const splitURI = reURI.exec(url); const splitURI = reURI.exec(url);