Bug 833292 - prevent social initialization completing after window is unloaded. r=jaws
authorMark Hammond <mhammond@skippinet.com.au>
Wed, 20 Feb 2013 12:23:47 +1100
changeset 122841 3892ce628367d45c2d393b6b09c822d3c12c8ef8
parent 122840 7c9e1c72d9318dbdc4992e9c5cbfbbbfd6a7b7fe
child 122842 37f6664e8f1ed9c17c405f6b2eccbba4f65b7f16
push id1387
push userphilringnalda@gmail.com
push dateTue, 26 Feb 2013 22:32:56 +0000
treeherderfx-team@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs833292
milestone22.0a1
Bug 833292 - prevent social initialization completing after window is unloaded. r=jaws
browser/base/content/browser-social.js
browser/modules/Social.jsm
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -26,45 +26,46 @@ let SocialUI = {
     gBrowser.addEventListener("ActivateSocialFeature", this._activationEventHandler.bind(this), true, true);
 
     // Called when we enter DOM full-screen mode.
     window.addEventListener("mozfullscreenchange", function () {
       SocialSidebar.update();
       SocialChatBar.update();
     });
 
-    Social.init(this._providerReady.bind(this));
+    SocialChatBar.init();
+    SocialShareButton.init();
+    SocialMenu.init();
+    SocialToolbar.init();
+    SocialSidebar.init();
+
+    Social.init();
+    // If social was previously initialized it isn't going to notify observers
+    // about the provider being set or the list of providers changing, so
+    // handle those now.
+    if (Social.provider) {
+      this.observe(null, "social:provider-set", Social.provider.origin);
+      this.observe(null, "social:providers-changed", null);
+    }
   },
 
   // Called on window unload
   uninit: function SocialUI_uninit() {
     Services.obs.removeObserver(this, "social:pref-changed");
     Services.obs.removeObserver(this, "social:ambient-notification-changed");
     Services.obs.removeObserver(this, "social:profile-changed");
     Services.obs.removeObserver(this, "social:recommend-info-changed");
     Services.obs.removeObserver(this, "social:frameworker-error");
     Services.obs.removeObserver(this, "social:provider-set");
     Services.obs.removeObserver(this, "social:providers-changed");
 
     Services.prefs.removeObserver("social.sidebar.open", this);
     Services.prefs.removeObserver("social.toast-notifications.enabled", this);
   },
 
-  // Called once, after window load, once Social.jsm's provider has been set.
-  _providerReady: function SocialUI_providerReady() {
-    this._updateActiveUI();
-    this._updateMenuItems();
-
-    SocialChatBar.update();
-    SocialShareButton.init();
-    SocialMenu.populate();
-    SocialToolbar.init();
-    SocialSidebar.init();
-  },
-
   // Social.provider has changed, update any state that depends on it.
   // Note: this method is not called when Social.provider is first set, during
   // the first window load.
   _updateProvider: function () {
     // XXX audit for handling nullness of social.provider
     this._updateActiveUI();
     this._updateMenuItems();
 
@@ -330,16 +331,18 @@ let SocialUI = {
     if (this._chromeless || PrivateBrowsingUtils.isWindowPrivate(window))
       return false;
     return !!Social.provider;
   },
 
 }
 
 let SocialChatBar = {
+  init: function() {
+  },
   get chatbar() {
     return document.getElementById("pinnedchats");
   },
   // Whether the chatbar is available for this window.  Note that in full-screen
   // mode chats are available, but not shown.
   get isAvailable() {
     return SocialUI.enabled && Social.haveLoggedInUser();
   },
@@ -551,17 +554,16 @@ let SocialFlyout = {
     }
     this.yOffset = yOffset;
   }
 }
 
 let SocialShareButton = {
   // Called once, after window load, when the Social.provider object is initialized
   init: function SSB_init() {
-    this.updateProvider();
   },
 
   // Called when the Social.provider changes
   updateProvider: function () {
     this.updateButtonHiddenState();
     if (!Social.provider)
       return;
     this.updateProfileInfo();
@@ -698,16 +700,19 @@ let SocialShareButton = {
       shareButton.setAttribute("tooltiptext", recommendInfo.messages.shareTooltip);
       imageURL = recommendInfo.images.share;
     }
     shareButton.src = imageURL;
   }
 };
 
 var SocialMenu = {
+  init: function SocialMenu_init() {
+  },
+
   populate: function SocialMenu_populate() {
     let submenu = document.getElementById("menu_social-statusarea-popup");
     let ambientMenuItems = submenu.getElementsByClassName("ambient-menuitem");
     while (ambientMenuItems.length)
       submenu.removeChild(ambientMenuItems.item(0));
 
     let separator = document.getElementById("socialAmbientMenuSeparator");
     separator.hidden = true;
@@ -735,18 +740,16 @@ var SocialMenu = {
 // XXX Need to audit that this is being initialized correctly
 var SocialToolbar = {
   // Called once, after window load, when the Social.provider object is
   // initialized.
   init: function SocialToolbar_init() {
     let accesskey = gNavigatorBundle.getString("social.removeProvider.accesskey");
     let removeCommand = document.getElementById("Social:Remove");
     removeCommand.setAttribute("accesskey", accesskey);
-
-    this.updateProvider();
     this._dynamicResizer = new DynamicResizeWatcher();
   },
 
   // Called when the Social.provider changes
   updateProvider: function () {
     let provider = Social.provider || Social.defaultProvider;
     if (provider) {
       let label = gNavigatorBundle.getFormattedString("social.removeProvider.label",
@@ -1068,17 +1071,16 @@ var SocialToolbar = {
 
 var SocialSidebar = {
   // Called once, after window load, when the Social.provider object is initialized
   init: function SocialSidebar_init() {
     let sbrowser = document.getElementById("social-sidebar-browser");
     Social.setErrorListener(sbrowser, this.setSidebarErrorMessage.bind(this));
     // setting isAppTab causes clicks on untargeted links to open new tabs
     sbrowser.docShell.isAppTab = true;
-    this.update();
   },
 
   // Whether the sidebar can be shown for this window.
   get canShow() {
     return SocialUI.enabled && Social.provider.sidebarURL;
   },
 
   // Whether the user has toggled the sidebar on (for windows where it can appear)
--- a/browser/modules/Social.jsm
+++ b/browser/modules/Social.jsm
@@ -52,23 +52,22 @@ this.Social = {
                                    Ci.nsISupportsString, string);
   },
 
   _provider: null,
   get provider() {
     return this._provider;
   },
   set provider(val) {
-    // Changes triggered by the public setter should notify of an engine change.
-    this._setProvider(val, true);
+    this._setProvider(val);
   },
 
   // Sets the current provider and enables it. Also disables the
-  // previously set provider, and optionally notifies observers of the change.
-  _setProvider: function (provider, notify) {
+  // previously set provider, and notifies observers of the change.
+  _setProvider: function (provider) {
     if (this._provider == provider)
       return;
 
     // Disable the previous provider, if any, since we want only one provider to
     // be enabled at once.
     if (this._provider)
       this._provider.enabled = false;
 
@@ -79,64 +78,58 @@ this.Social = {
       this._currentProviderPref = this._provider.origin;
     }
     let enabled = !!provider;
     if (enabled != SocialService.enabled) {
       SocialService.enabled = enabled;
       Services.prefs.setBoolPref("social.enabled", enabled);
     }
 
-    if (notify) {
-      let origin = this._provider && this._provider.origin;
-      Services.obs.notifyObservers(null, "social:provider-set", origin);
-    }
+    let origin = this._provider && this._provider.origin;
+    Services.obs.notifyObservers(null, "social:provider-set", origin);
   },
 
   get defaultProvider() {
     if (this.providers.length == 0)
       return null;
     let provider = this._getProviderFromOrigin(this._currentProviderPref);
     return provider || this.providers[0];
   },
 
-  init: function Social_init(callback) {
+  init: function Social_init() {
     this._disabledForSafeMode = Services.appinfo.inSafeMode && this.enabled;
 
     if (this.providers) {
-      schedule(callback);
       return;
     }
 
     // Retrieve the current set of providers, and set the current provider.
     SocialService.getProviderList(function (providers) {
-      // We don't want to notify about a provider change when we're setting
-      // this.provider for the first time, so pass false here.
-      this._updateProviderCache(providers, false);
-      callback();
+      this._updateProviderCache(providers);
     }.bind(this));
 
     // Register an observer for changes to the provider list
     SocialService.registerProviderListener(function providerListener(topic, data) {
       // An engine change caused by adding/removing a provider should notify
       if (topic == "provider-added" || topic == "provider-removed") {
-        this._updateProviderCache(data, true);
+        this._updateProviderCache(data);
         Services.obs.notifyObservers(null, "social:providers-changed", null);
       }
     }.bind(this));
   },
 
   // Called to update our cache of providers and set the current provider
-  _updateProviderCache: function (providers, notifyProviderChange) {
+  _updateProviderCache: function (providers) {
     this.providers = providers;
 
     // If social is currently disabled there's nothing else to do.
     if (!SocialService.enabled)
       return;
     // Otherwise set the provider.
-    this._setProvider(this.defaultProvider, notifyProviderChange);
+    this._setProvider(this.defaultProvider);
   },
 
   set enabled(val) {
     // Setting .enabled is just a shortcut for setting the provider to either
     // the default provider or null...
     if (val) {
       if (!this.provider)
         this.provider = this.defaultProvider;