Bug 965607 - [Australis] Show FxA doorhangers only for the most recent non-popup browser window r=markh
authorTim Taubert <ttaubert@mozilla.com>
Thu, 30 Jan 2014 11:15:46 -0800
changeset 166103 48ec899c90a0c82188f47813721c4aa9bd738292
parent 166102 14dcf72485b54145e3c74d4ea51bd65e7f1f6702
child 166104 0fe6a5fc9081dd199bd9bcd3b984d562b837048a
push id4714
push userttaubert@mozilla.com
push dateFri, 31 Jan 2014 02:10:37 +0000
treeherderfx-team@48ec899c90a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs965607
milestone29.0a1
Bug 965607 - [Australis] Show FxA doorhangers only for the most recent non-popup browser window r=markh
browser/base/content/browser-fxaccounts.js
--- a/browser/base/content/browser-fxaccounts.js
+++ b/browser/base/content/browser-fxaccounts.js
@@ -17,32 +17,50 @@ let gFxAccounts = {
   get weave() {
     delete this.weave;
     return this.weave = Cc["@mozilla.org/weave/service;1"]
                           .getService(Ci.nsISupports)
                           .wrappedJSObject;
   },
 
   get topics() {
+    // Do all this dance to lazy-load FxAccountsCommon.
     delete this.topics;
     return this.topics = [
       FxAccountsCommon.ONLOGIN_NOTIFICATION,
       FxAccountsCommon.ONVERIFIED_NOTIFICATION,
       FxAccountsCommon.ONLOGOUT_NOTIFICATION,
       "weave:service:sync:start"
     ];
   },
 
+  // The set of topics that only the active window should handle.
+  get activeWindowTopics() {
+    // Do all this dance to lazy-load FxAccountsCommon.
+    delete this.activeWindowTopics;
+    return this.activeWindowTopics = new Set([
+      "weave:service:sync:start",
+      FxAccountsCommon.ONVERIFIED_NOTIFICATION
+    ]);
+  },
+
   get button() {
     delete this.button;
     return this.button = document.getElementById("PanelUI-fxa-status");
   },
 
+  get isActiveWindow() {
+    let mostRecentNonPopupWindow =
+      RecentWindow.getMostRecentBrowserWindow({allowPopups: false});
+    return window == mostRecentNonPopupWindow;
+  },
+
   init: function () {
-    if (this._initialized) {
+    // Bail out if we're already initialized and for pop-up windows.
+    if (this._initialized || !window.toolbar.visible) {
       return;
     }
 
     for (let topic of this.topics) {
       Services.obs.addObserver(this, topic, false);
     }
 
     gNavToolbox.addEventListener("customizationstarting", this);
@@ -64,16 +82,21 @@ let gFxAccounts = {
     for (let topic of this.topics) {
       Services.obs.removeObserver(this, topic);
     }
 
     this._initialized = false;
   },
 
   observe: function (subject, topic) {
+    // Ignore certain topics if we're not the active window.
+    if (this.activeWindowTopics.has(topic) && !this.isActiveWindow) {
+      return;
+    }
+
     switch (topic) {
       case FxAccountsCommon.ONVERIFIED_NOTIFICATION:
         Services.prefs.setBoolPref(PREF_SYNC_START_DOORHANGER, true);
         break;
       case "weave:service:sync:start":
         this.onSyncStart();
         break;
       default: