Bug 1220527 - Wait for the first window before showing the upgraded notifications alert. r=MattN
authorKit Cambridge <kcambridge@mozilla.com>
Mon, 02 Nov 2015 14:59:52 -0800
changeset 270847 436f6fab5d4e773138e128c7163238620aa40730
parent 270846 901a0736dd16ba366d2de0ec08cab975429fa4b2
child 270848 4f88fc3bd332751c04df7080982b88042a375258
push id18459
push usercbook@mozilla.com
push dateTue, 03 Nov 2015 11:14:32 +0000
treeherderb2g-inbound@09173d8e6694 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1220527
milestone45.0a1
Bug 1220527 - Wait for the first window before showing the upgraded notifications alert. r=MattN
browser/components/nsBrowserGlue.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -642,16 +642,17 @@ BrowserGlue.prototype = {
     ExtensionManagement.registerScript("chrome://browser/content/ext-browserAction.js");
     ExtensionManagement.registerScript("chrome://browser/content/ext-pageAction.js");
     ExtensionManagement.registerScript("chrome://browser/content/ext-contextMenus.js");
     ExtensionManagement.registerScript("chrome://browser/content/ext-tabs.js");
     ExtensionManagement.registerScript("chrome://browser/content/ext-windows.js");
     ExtensionManagement.registerScript("chrome://browser/content/ext-bookmarks.js");
 
     this._flashHangCount = 0;
+    this._firstWindowReady = new Promise(resolve => this._firstWindowLoaded = resolve);
   },
 
   // cleanup (called on application shutdown)
   _dispose: function BG__dispose() {
     let os = Services.obs;
     os.removeObserver(this, "notifications-open-settings");
     os.removeObserver(this, "prefservice:after-app-defaults");
     os.removeObserver(this, "final-ui-startup");
@@ -1140,16 +1141,17 @@ BrowserGlue.prototype = {
     if (!disableResetPrompt && lastUse &&
         Date.now() - lastUse >= OFFER_PROFILE_RESET_INTERVAL_MS) {
       this._resetUnusedProfileNotification();
     }
 
     this._checkForOldBuildUpdates();
 
     this._firstWindowTelemetry(aWindow);
+    this._firstWindowLoaded();
   },
 
   /**
    * Application shutdown handler.
    */
   _onQuitApplicationGranted: function () {
     // This pref must be set here because SessionStore will use its value
     // on quit-application.
@@ -2208,17 +2210,17 @@ BrowserGlue.prototype = {
     }
 
     if (currentUIVersion < 31) {
       xulStore.removeValue(BROWSER_DOCURL, "bookmarks-menu-button", "class");
       xulStore.removeValue(BROWSER_DOCURL, "home-button", "class");
     }
 
     if (currentUIVersion < 32) {
-      this._notifyNotificationsUpgrade();
+      this._notifyNotificationsUpgrade().catch(Cu.reportError);
     }
 
     // Update the migration version.
     Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
   },
 
   _hasExistingNotificationPermission: function BG__hasExistingNotificationPermission() {
     let enumerator = Services.perms.enumerator;
@@ -2226,39 +2228,35 @@ BrowserGlue.prototype = {
       let permission = enumerator.getNext().QueryInterface(Ci.nsIPermission);
       if (permission.type == "desktop-notification") {
         return true;
       }
     }
     return false;
   },
 
-  _notifyNotificationsUpgrade: function BG__notifyNotificationsUpgrade() {
+  _notifyNotificationsUpgrade: Task.async(function* () {
     if (!this._hasExistingNotificationPermission()) {
       return;
     }
+    yield this._firstWindowReady;
     function clickCallback(subject, topic, data) {
       if (topic != "alertclickcallback")
         return;
       let win = RecentWindow.getMostRecentBrowserWindow();
       win.openUILinkIn(data, "tab");
     }
     let imageURL = "chrome://browser/skin/web-notifications-icon.svg";
     let title = gBrowserBundle.GetStringFromName("webNotifications.upgradeTitle");
     let text = gBrowserBundle.GetStringFromName("webNotifications.upgradeInfo");
     let url = Services.urlFormatter.formatURLPref("browser.push.warning.migrationURL");
 
-    try {
-      AlertsService.showAlertNotification(imageURL, title, text,
-                                          true, url, clickCallback);
-    }
-    catch (e) {
-      Cu.reportError(e);
-    }
-  },
+    AlertsService.showAlertNotification(imageURL, title, text,
+                                        true, url, clickCallback);
+  }),
 
   // ------------------------------
   // public nsIBrowserGlue members
   // ------------------------------
 
   sanitize: function BG_sanitize(aParentWindow) {
     this._sanitizer.sanitize(aParentWindow);
   },