]> git.parisson.com Git - pdf.js.git/commitdiff
Fix the download button.
authorBrendan Dahl <brendan.dahl@gmail.com>
Wed, 25 Jan 2012 05:33:03 +0000 (21:33 -0800)
committerBrendan Dahl <brendan.dahl@gmail.com>
Wed, 25 Jan 2012 05:33:03 +0000 (21:33 -0800)
extensions/firefox/components/pdfContentHandler.js
web/viewer.js

index fc42b926003778e3ec5154f3105c1307e0ed6215..320d69d303ccc77a9469888acbd485b61932ad13 100644 (file)
@@ -70,6 +70,17 @@ pdfContentHandler.prototype = {
   onStartRequest: function(aRequest, aContext) {
     // Setup the request so we can use it below.
     aRequest.QueryInterface(Ci.nsIChannel);
+    // Cancel the request so the viewer can handle it.
+    aRequest.cancel(Cr.NS_BINDING_ABORTED);
+
+    // Check if we should download.
+    var targetUrl = aRequest.originalURI.spec;
+    var downloadHash = targetUrl.indexOf('?#pdfjs.action=download');
+    if (downloadHash >= 0) {
+      targetUrl = targetUrl.substring(0, downloadHash);
+      Services.wm.getMostRecentWindow("navigator:browser").saveURL(targetUrl);
+      return;
+    }
 
     // Create a new channel that is viewer loaded as a resource.
     var ioService = Cc['@mozilla.org/network/io-service;1']
@@ -79,9 +90,6 @@ pdfContentHandler.prototype = {
     // Keep the URL the same so the browser sees it as the same.
     channel.originalURI = aRequest.originalURI;
     channel.asyncOpen(this.listener, aContext);
-
-    // Cancel the request so the viewer can handle it.
-    aRequest.cancel(Cr.NS_BINDING_ABORTED);
   },
 
   // nsIRequestObserver::onStopRequest
index b784e6f5ad710fa6949425e88d66630d76ff83e7..55d0a595ce0a21099ebafdd40989582ed3ac0d70 100644 (file)
@@ -249,7 +249,14 @@ var PDFView = {
   },
 
   download: function pdfViewDownload() {
-    window.open(this.url + '#pdfjs.action=download', '_parent');
+    var url = this.url.split('#')[0];
+    // For the extension we add an extra '?' to force the page to reload, its
+    // stripped off by the extension.
+    if (PDFJS.isFirefoxExtension)
+      url += '?#pdfjs.action=download';
+    else
+      url += '#pdfjs.action=download', '_parent';
+    window.open(url, '_parent');
   },
 
   navigateTo: function pdfViewNavigateTo(dest) {