[Pkg-javascript-commits] [pdf.js] 09/161: Making extensions/chromium/pdfHandler.js adhere to the style guide

David Prévot taffit at moszumanska.debian.org
Sat Apr 19 14:16:16 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit c29350219e05788e0cb1c9b6fb5714b17e9a420e
Author: Tim van der Meij <timvandermeij at gmail.com>
Date:   Sun Mar 9 23:12:12 2014 +0100

    Making extensions/chromium/pdfHandler.js adhere to the style guide
---
 extensions/chromium/pdfHandler.js | 45 +++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/extensions/chromium/pdfHandler.js b/extensions/chromium/pdfHandler.js
index c61373d..99cdbae 100644
--- a/extensions/chromium/pdfHandler.js
+++ b/extensions/chromium/pdfHandler.js
@@ -31,15 +31,17 @@ function getViewerURL(pdf_url) {
  * @return {boolean} True if the PDF file should be downloaded.
  */
 function isPdfDownloadable(details) {
-  if (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')
+  if (details.type == 'main_frame') {
     return false;
-  var cdHeader = details.responseHeaders &&
-    getHeaderFromHeaders(details.responseHeaders, 'content-disposition');
-  return cdHeader && /^attachment/i.test(cdHeader.value);
+  }
+  var cdHeader = (details.responseHeaders &&
+    getHeaderFromHeaders(details.responseHeaders, 'content-disposition'));
+  return (cdHeader && /^attachment/i.test(cdHeader.value));
 }
 
 /**
@@ -67,9 +69,9 @@ function isPdfFile(details) {
   var header = getHeaderFromHeaders(details.responseHeaders, 'content-type');
   if (header) {
     var headerValue = header.value.toLowerCase().split(';',1)[0].trim();
-    return headerValue === 'application/pdf' ||
-      headerValue === 'application/octet-stream' &&
-      details.url.toLowerCase().indexOf('.pdf') > 0;
+    return (headerValue === 'application/pdf' ||
+            headerValue === 'application/octet-stream' &&
+            details.url.toLowerCase().indexOf('.pdf') > 0);
   }
 }
 
@@ -83,16 +85,16 @@ function isPdfFile(details) {
  *                            have been modified, undefined otherwise.
  */
 function getHeadersWithContentDispositionAttachment(details) {
-    var headers = details.responseHeaders;
-    var cdHeader = getHeaderFromHeaders(headers, 'content-disposition');
-    if (!cdHeader) {
-      cdHeader = {name: 'Content-Disposition'};
-      headers.push(cdHeader);
-    }
-    if (!/^attachment/i.test(cdHeader.value)) {
-      cdHeader.value = 'attachment' + cdHeader.value.replace(/^[^;]+/i, '');
-      return { responseHeaders: headers };
-    }
+  var headers = details.responseHeaders;
+  var cdHeader = getHeaderFromHeaders(headers, 'content-disposition');
+  if (!cdHeader) {
+    cdHeader = {name: 'Content-Disposition'};
+    headers.push(cdHeader);
+  }
+  if (!/^attachment/i.test(cdHeader.value)) {
+    cdHeader.value = 'attachment' + cdHeader.value.replace(/^[^;]+/i, '');
+    return { responseHeaders: headers };
+  }
 }
 
 chrome.webRequest.onHeadersReceived.addListener(
@@ -101,9 +103,9 @@ chrome.webRequest.onHeadersReceived.addListener(
       // Don't intercept POST requests until http://crbug.com/104058 is fixed.
       return;
     }
-    if (!isPdfFile(details))
+    if (!isPdfFile(details)) {
       return;
-
+    }
     if (isPdfDownloadable(details)) {
       // Force download by ensuring that Content-Disposition: attachment is set
       return getHeadersWithContentDispositionAttachment(details);
@@ -172,8 +174,9 @@ chrome.webRequest.onHeadersReceived.addListener(
 
 chrome.webRequest.onBeforeRequest.addListener(
   function(details) {
-    if (isPdfDownloadable(details))
+    if (isPdfDownloadable(details)) {
       return;
+    }
 
     // NOTE: The manifest file has declared an empty content script
     // at file://*/* to make sure that the viewer can load the PDF file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list