Bug 852530 - NotificationBox is not visible on Linux. r=Mossop, a=bajaj
authorYury Delendik <ydelendik@mozilla.com>
Tue, 19 Mar 2013 12:44:33 -0500
changeset 128707 7fb5d55e62dfacbadf6ba33d2cad2ad746009599
parent 128706 b8ceed3fed5de2332c8264821d5d786fc2af0526
child 128708 90b3c33b1eddc019ea175940ac908cdf88111cf6
push id3564
push userryanvm@gmail.com
push dateThu, 28 Mar 2013 14:51:16 +0000
treeherdermozilla-aurora@ac5ed16b6a74 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop, bajaj
bugs852530
milestone21.0a2
Bug 852530 - NotificationBox is not visible on Linux. r=Mossop, a=bajaj
browser/extensions/pdfjs/components/PdfStreamConverter.js
--- a/browser/extensions/pdfjs/components/PdfStreamConverter.js
+++ b/browser/extensions/pdfjs/components/PdfStreamConverter.js
@@ -380,31 +380,29 @@ ChromeActions.prototype = {
   },
   fallback: function(url, sendResponse) {
     var self = this;
     var domWindow = this.domWindow;
     var strings = getLocalizedStrings('chrome.properties');
     var message = getLocalizedString(strings, 'unsupported_feature');
 
     var notificationBox = null;
-    // Multiple browser windows can be opened, finding one for notification box
-    var windowsEnum = Services.wm
-                      .getZOrderDOMWindowEnumerator('navigator:browser', true);
-    while (windowsEnum.hasMoreElements()) {
-      var win = windowsEnum.getNext();
-      if (win.closed)
-        continue;
-      var browser = win.gBrowser.getBrowserForDocument(domWindow.top.document);
-      if (browser) {
-        // right window/browser is found, getting the notification box
-        notificationBox = win.gBrowser.getNotificationBox(browser);
-        break;
-      }
-    }
-    if (!notificationBox) {
+    try {
+      // Based on MDN's "Working with windows in chrome code"
+      var mainWindow = domWindow
+        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+        .getInterface(Components.interfaces.nsIWebNavigation)
+        .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
+        .rootTreeItem
+        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+        .getInterface(Components.interfaces.nsIDOMWindow);
+      var browser = mainWindow.gBrowser
+                              .getBrowserForDocument(domWindow.top.document);
+      notificationBox = mainWindow.gBrowser.getNotificationBox(browser);
+    } catch (e) {
       log('Unable to get a notification box for the fallback message');
       return;
     }
 
     // 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;