Change PDFAttachmentViewer
to only open PDF attachments in the viewer, instead of downloading them, when PDFJS.disableCreateObjectURL = false
This prevents issues with the filename detection being skipped, when trying to download the opened PDF attachment, since `getPDFFileNameFromURL` ignores `data:` URLs for performance reasons.
This commit is contained in:
parent
84472b30ee
commit
7bd8b97dba
@ -79,13 +79,15 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_bindPdfLink:
|
_bindPdfLink(button, content, filename) {
|
||||||
function PDFAttachmentViewer_bindPdfLink(button, content, filename) {
|
if (PDFJS.disableCreateObjectURL) {
|
||||||
|
throw new Error('bindPdfLink: ' +
|
||||||
|
'Unsupported "PDFJS.disableCreateObjectURL" value.');
|
||||||
|
}
|
||||||
var blobUrl;
|
var blobUrl;
|
||||||
button.onclick = function() {
|
button.onclick = function() {
|
||||||
if (!blobUrl) {
|
if (!blobUrl) {
|
||||||
blobUrl = createObjectURL(
|
blobUrl = createObjectURL(content, 'application/pdf');
|
||||||
content, 'application/pdf', PDFJS.disableCreateObjectURL);
|
|
||||||
}
|
}
|
||||||
var viewerUrl;
|
var viewerUrl;
|
||||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||||
@ -97,10 +99,8 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
|||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
viewerUrl = chrome.runtime.getURL('/content/web/viewer.html') +
|
viewerUrl = chrome.runtime.getURL('/content/web/viewer.html') +
|
||||||
'?file=' + encodeURIComponent(blobUrl + '#' + filename);
|
'?file=' + encodeURIComponent(blobUrl + '#' + filename);
|
||||||
} else {
|
} else if (PDFJSDev.test('FIREFOX || 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.
|
||||||
// In Firefox PDFJS.disableCreateObjectURL is always false, so
|
|
||||||
// blobUrl is always a blob:-URL and never a data:-URL.
|
|
||||||
viewerUrl = blobUrl + '?' + encodeURIComponent(filename);
|
viewerUrl = blobUrl + '?' + encodeURIComponent(filename);
|
||||||
}
|
}
|
||||||
window.open(viewerUrl);
|
window.open(viewerUrl);
|
||||||
@ -151,7 +151,7 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
|||||||
div.className = 'attachmentsItem';
|
div.className = 'attachmentsItem';
|
||||||
var button = document.createElement('button');
|
var button = document.createElement('button');
|
||||||
button.textContent = filename;
|
button.textContent = filename;
|
||||||
if (/\.pdf$/i.test(filename)) {
|
if (/\.pdf$/i.test(filename) && !PDFJS.disableCreateObjectURL) {
|
||||||
this._bindPdfLink(button, item.content, filename);
|
this._bindPdfLink(button, item.content, filename);
|
||||||
} else {
|
} else {
|
||||||
this._bindLink(button, item.content, filename);
|
this._bindLink(button, item.content, filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user