Bug 1364444 - Open sent tabs new windows using WindowWatcher. r?markh draft
authorEdouard Oger <eoger@fastmail.com>
Wed, 24 May 2017 13:48:20 -0400
changeset 585130 3ebfd03cec4270d25c1b6737203c8a2b3598cfce
parent 585129 43b0fdd5b94a28a6b8f4da567b9e6af46a6b5d8e
child 630639 2bc8d21e899e6104c3008daecb0b52c5f559e528
push id61019
push userbmo:eoger@fastmail.com
push dateFri, 26 May 2017 15:44:11 +0000
reviewersmarkh
bugs1364444
milestone55.0a1
Bug 1364444 - Open sent tabs new windows using WindowWatcher. r?markh MozReview-Commit-ID: 6WyU1atGDKf
browser/components/nsBrowserGlue.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -2175,46 +2175,54 @@ BrowserGlue.prototype = {
       Services.appShell.hiddenDOMWindow.openPreferences(...args);
       return;
     }
 
     let chromeWindow = RecentWindow.getMostRecentBrowserWindow();
     chromeWindow.openPreferences(...args);
   },
 
+  _openURLInNewWindow(url) {
+    let urlString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
+    urlString.data = url;
+    return new Promise(resolve => {
+      let win = Services.ww.openWindow(null, Services.prefs.getCharPref("browser.chromeURL"),
+                                       "_blank", "chrome,all,dialog=no", urlString);
+      win.addEventListener("load", () => { resolve(win); }, {once: true});
+    });
+  },
+
   /**
    * Called as an observer when Sync's "display URIs" notification is fired.
    *
    * We open the received URIs in background tabs.
    */
-  _onDisplaySyncURIs: function _onDisplaySyncURIs(data) {
+  async _onDisplaySyncURIs(data) {
     try {
       // The payload is wrapped weirdly because of how Sync does notifications.
       const URIs = data.wrappedJSObject.object;
 
-      const findWindow = () => RecentWindow.getMostRecentBrowserWindow({private: false});
+      // win can be null, but it's ok, we'll assign it later in openTab()
+      let win = RecentWindow.getMostRecentBrowserWindow({private: false});
 
-      // win can be null, but it's ok, we'll assign it later in openTab()
-      let win = findWindow();
-
-      const openTab = URI => {
+      const openTab = async (URI) => {
         let tab;
         if (!win) {
-          Services.appShell.hiddenDOMWindow.open(URI.uri);
-          win = findWindow();
-          tab = win.gBrowser.tabs[0];
+          win = await this._openURLInNewWindow(URI.uri);
+          let tabs = win.gBrowser.tabs;
+          tab = tabs[tabs.length - 1];
         } else {
           tab = win.gBrowser.addTab(URI.uri);
         }
         tab.setAttribute("attention", true);
         return tab;
       };
 
-      const firstTab = openTab(URIs[0]);
-      URIs.slice(1).forEach(URI => openTab(URI));
+      const firstTab = await openTab(URIs[0]);
+      await Promise.all(URIs.slice(1).map(URI => openTab(URI)));
 
       let title, body;
       const deviceName = Weave.Service.clientsEngine.getClientName(URIs[0].clientId);
       const bundle = Services.strings.createBundle("chrome://browser/locale/accounts.properties");
       if (URIs.length == 1) {
         // Due to bug 1305895, tabs from iOS may not have device information, so
         // we have separate strings to handle those cases. (See Also
         // unnamedTabsArrivingNotificationNoDevice.body below)
@@ -2275,17 +2283,17 @@ BrowserGlue.prototype = {
                                                    [deviceName], 1);
 
     let clickCallback = async (subject, topic, data) => {
       if (topic != "alertclickcallback")
         return;
       let url = await this.fxAccounts.promiseAccountsManageDevicesURI("device-connected-notification");
       let win = RecentWindow.getMostRecentBrowserWindow({private: false});
       if (!win) {
-        Services.appShell.hiddenDOMWindow.open(url);
+        this._openURLInNewWindow(url);
       } else {
         win.gBrowser.addTab(url);
       }
     };
 
     try {
       AlertsService.showAlertNotification(null, title, body, true, null, clickCallback);
     } catch (ex) {