]> git.parisson.com Git - pdf.js.git/commitdiff
Make the 'download' button behavior more robust
authorVivien Nicolas <21@vingtetun.org>
Wed, 19 Oct 2011 04:29:14 +0000 (06:29 +0200)
committerVivien Nicolas <21@vingtetun.org>
Wed, 19 Oct 2011 04:29:14 +0000 (06:29 +0200)
extensions/firefox/components/pdfContentHandler.js
web/viewer.js

index a04b717a2d5659e8fa90560bb26f36036110d018..d5f466e3fa08e1b4996df7471cf2b1f8cfd77cf0 100644 (file)
@@ -48,16 +48,12 @@ pdfContentHandler.prototype = {
       throw NS_ERROR_WONT_HANDLE_CONTENT;
     }
 
-    // To allow a Download feature we need to ensure pdf.js
-    // is not opened again if the request for opening an
-    // application/pdf document has been done by itself.
-    let location = window.location.toString();
-    if (location.indexOf(url.replace('%s', '')) == 0)
+    let targetUrl = aRequest.URI.spec;
+    if (targetUrl.indexOf('?pdfjs.action=download') >= 0)
       throw NS_ERROR_WONT_HANDLE_CONTENT;
 
     aRequest.cancel(Cr.NS_BINDING_ABORTED);
-    let uri = aRequest.URI;
-    window.location = url.replace('%s', uri.spec);
+    window.location = url.replace('%s', targetUrl);
   },
 
   classID: Components.ID('{2278dfd0-b75c-11e0-8257-1ba3d93c9f1a}'),
index 27211ce1c67bdbe61a668cfca690aeeca1d9b69d..12d0a3f37dd9c08df38b013cfe4533a8bd851ac6 100644 (file)
@@ -85,10 +85,6 @@ var PDFView = {
     this.setScale(newScale, true);
   },
 
-  download: function pdfViewDownload() {
-    window.open(document.title, '_parent', 'pdf=yes');
-  },
-
   set page(val) {
     var pages = this.pages;
     var input = document.getElementById('pageNumber');
@@ -119,7 +115,7 @@ var PDFView = {
   },
 
   open: function pdfViewOpen(url, scale) {
-    document.title = url;
+    document.title = this.url = url;
 
     getPdf(
       {
@@ -135,6 +131,10 @@ var PDFView = {
       });
   },
 
+  download: function pdfViewDownload() {
+    window.open(this.url + '?pdfjs.action=download', '_parent');
+  },
+
   navigateTo: function pdfViewNavigateTo(dest) {
     if (typeof dest === 'string')
       dest = this.destinations[dest];