]> git.parisson.com Git - pdf.js.git/commitdiff
Fix fallback after new download.
authorBrendan Dahl <brendan.dahl@gmail.com>
Tue, 5 Jun 2012 00:33:27 +0000 (17:33 -0700)
committerBrendan Dahl <brendan.dahl@gmail.com>
Tue, 5 Jun 2012 00:33:27 +0000 (17:33 -0700)
extensions/firefox/components/PdfStreamConverter.js
web/viewer.js

index 8980fccc53f42ec0147d108c88bb3861ad671897..a0057ebb68b89bae713fd18340ed7b284113c151 100644 (file)
@@ -216,7 +216,7 @@ ChromeActions.prototype = {
   searchEnabled: function() {
     return getBoolPref(PREF_PREFIX + '.searchEnabled', false);
   },
-  fallback: function(url) {
+  fallback: function(url, sendResponse) {
     var self = this;
     var domWindow = this.domWindow;
     var strings = getLocalizedStrings('chrome.properties');
@@ -225,17 +225,32 @@ ChromeActions.prototype = {
     var win = Services.wm.getMostRecentWindow('navigator:browser');
     var browser = win.gBrowser.getBrowserForDocument(domWindow.top.document);
     var notificationBox = win.gBrowser.getNotificationBox(browser);
+    // Flag so we don't call the response callback twice, since if the user
+    // clicks open with different viewer both the button callback and
+    // eventCallback will be called.
+    var sentResponse = false;
     var buttons = [{
       label: getLocalizedString(strings, 'open_with_different_viewer'),
       accessKey: getLocalizedString(strings, 'open_with_different_viewer',
                                     'accessKey'),
       callback: function() {
-        self.download(url);
+        sentResponse = true;
+        sendResponse(true);
       }
     }];
     notificationBox.appendNotification(message, 'pdfjs-fallback', null,
                                        notificationBox.PRIORITY_WARNING_LOW,
-                                       buttons);
+                                       buttons,
+                                       function eventsCallback(eventType) {
+      // Currently there is only one event "removed" but if there are any other
+      // added in the future we still only care about removed at the moment.
+      if (eventType !== 'removed')
+        return;
+      // Don't send a response again if we already responded when the button was
+      // clicked.
+      if (!sentResponse)
+        sendResponse(false);
+    });
   }
 };
 
index 991a64e16e236d290a5b853cde18f45bc6c8534b..751f2deff17be71c356fa7bd4bc1078965fbce4c 100644 (file)
@@ -468,7 +468,11 @@ var PDFView = {
       return;
     this.fellback = true;
     var url = this.url.split('#')[0];
-    FirefoxCom.request('fallback', url);
+    FirefoxCom.request('fallback', url, function response(download) {
+      if (!download)
+        return;
+      PDFView.download();
+    });
   },
 
   navigateTo: function pdfViewNavigateTo(dest) {