]> git.parisson.com Git - pdf.js.git/commitdiff
Merge upstream.
authorBrendan Dahl <brendan.dahl@gmail.com>
Mon, 4 Jun 2012 18:16:02 +0000 (11:16 -0700)
committerBrendan Dahl <brendan.dahl@gmail.com>
Mon, 4 Jun 2012 18:16:02 +0000 (11:16 -0700)
1  2 
extensions/firefox/components/PdfStreamConverter.js

index 9e5dcbe61a1980cbbc8c1bafd27eed054b4b7cbf,691aec6c7ba58ce655e49cd64aea2ec7cecd1946..8980fccc53f42ec0147d108c88bb3861ad671897
@@@ -128,37 -123,65 +128,58 @@@ function ChromeActions(domWindow) 
  }
  
  ChromeActions.prototype = {
-   download: function(data) {
-     var handlerInfo = Svc.mime
-                          .getFromTypeAndExtension('application/pdf', 'pdf');
-     var uri = NetUtil.newURI(data);
+   download: function(data, sendResponse) {
+     var originalUrl = data.originalUrl;
+     // The data may not be downloaded so we need just retry getting the pdf with
+     // the original url.
+     var blobUrl = data.blobUrl || originalUrl;
 -
+     var originalUri = NetUtil.newURI(originalUrl);
+     var blobUri = NetUtil.newURI(blobUrl);
 -
 -    let mimeService = Cc['@mozilla.org/mime;1'].getService(Ci.nsIMIMEService);
 -    var handlerInfo = mimeService.
 -                        getFromTypeAndExtension('application/pdf', 'pdf');
 -
      var extHelperAppSvc =
            Cc['@mozilla.org/uriloader/external-helper-app-service;1'].
--            getService(Ci.nsIExternalHelperAppService);
++             getService(Ci.nsIExternalHelperAppService);
      var frontWindow = Cc['@mozilla.org/embedcomp/window-watcher;1'].
--                        getService(Ci.nsIWindowWatcher).activeWindow;
++                         getService(Ci.nsIWindowWatcher).activeWindow;
      var ioService = Services.io;
-     var channel = ioService.newChannel(data, null, null);
-     var listener = {
-       extListener: null,
-       onStartRequest: function(aRequest, aContext) {
-         this.extListener = extHelperAppSvc.doContent('application/pdf',
-                               aRequest, frontWindow, false);
-         this.extListener.onStartRequest(aRequest, aContext);
-       },
-       onStopRequest: function(aRequest, aContext, aStatusCode) {
-         if (this.extListener)
-           this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
-       },
-       onDataAvailable: function(aRequest, aContext, aInputStream, aOffset,
-                                 aCount) {
-         this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
-                                          aOffset, aCount);
+     var channel = ioService.newChannel(originalUrl, null, null);
 -
+     NetUtil.asyncFetch(blobUri, function(aInputStream, aResult) {
+       if (!Components.isSuccessCode(aResult)) {
+         if (sendResponse)
+           sendResponse(true);
+         return;
        }
-     };
+       // Create a nsIInputStreamChannel so we can set the url on the channel
+       // so the filename will be correct.
+       let channel = Cc['@mozilla.org/network/input-stream-channel;1'].
 -                      createInstance(Ci.nsIInputStreamChannel);
++                       createInstance(Ci.nsIInputStreamChannel);
+       channel.setURI(originalUri);
+       channel.contentStream = aInputStream;
+       channel.QueryInterface(Ci.nsIChannel);
+       var listener = {
+         extListener: null,
+         onStartRequest: function(aRequest, aContext) {
+           this.extListener = extHelperAppSvc.doContent('application/pdf',
+                                 aRequest, frontWindow, false);
+           this.extListener.onStartRequest(aRequest, aContext);
+         },
+         onStopRequest: function(aRequest, aContext, aStatusCode) {
+           if (this.extListener)
+             this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
+           // Notify the content code we're done downloading.
+           if (sendResponse)
+             sendResponse(false);
+         },
+         onDataAvailable: function(aRequest, aContext, aInputStream, aOffset,
+                                   aCount) {
+           this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
+                                            aOffset, aCount);
+         }
+       };
  
-     channel.asyncOpen(listener, null);
+       channel.asyncOpen(listener, null);
+     });
    },
    setDatabase: function(data) {
      if (inPrivateBrowsing)