From be012ed1df65183047d0f6bf34c9711a40091d5b Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Mon, 1 Jul 2013 19:09:53 +0200 Subject: [PATCH] [CRX] Don't intercept download of PDF attachment Fixes #3426 --- extensions/chrome/pdfHandler.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/extensions/chrome/pdfHandler.js b/extensions/chrome/pdfHandler.js index c5a1642c9..28ba1a953 100644 --- a/extensions/chrome/pdfHandler.js +++ b/extensions/chrome/pdfHandler.js @@ -22,10 +22,18 @@ limitations under the License. /** * @param {Object} details First argument of the webRequest.onHeadersReceived * event. The property "url" is read. - * @return {boolean} True if the PDF download was initiated by PDF.js + * @return {boolean} True if the PDF file should be downloaded. */ function isPdfDownloadable(details) { - return details.url.indexOf('pdfjs.action=download') >= 0; + if (details.url.indexOf('pdfjs.action=download') >= 0) + return true; + // Display the PDF viewer regardless of the Content-Disposition header + // if the file is displayed in the main frame. + if (details.type == 'main_frame') + return false; + var cdHeader = getHeaderFromHeaders(details.responseHeaders, + 'content-disposition'); + return cdHeader && /^attachment/i.test(cdHeader.value); } /**