Bug 1257723 - Move to using messagemanager for some events. r=markh, a=lizzard
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 17 Mar 2016 18:44:03 -0700
changeset 332924 f25acdea677c75578e63899934f5f148df02fe9a
parent 332923 dddff4b551b9a4319069b17c3aff29185ae676ac
child 332925 6aa616713eaec74c48ec67b425490ed36881d49d
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh, lizzard
bugs1257723
milestone48.0a2
Bug 1257723 - Move to using messagemanager for some events. r=markh, a=lizzard
browser/base/content/browser-social.js
browser/base/content/content.js
browser/base/content/social-content.js
browser/base/content/socialmarks.xml
browser/base/content/test/social/browser_aboutHome_activation.js
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -348,21 +348,24 @@ SocialFlyout = {
     iframe.setAttribute("flex", "1");
     iframe.setAttribute("message", "true");
     iframe.setAttribute("messagemanagergroup", "social");
     iframe.setAttribute("disablehistory", "true");
     iframe.setAttribute("tooltip", "aHTMLTooltip");
     iframe.setAttribute("context", "contentAreaContextMenu");
     iframe.setAttribute("origin", SocialSidebar.provider.origin);
     panel.appendChild(iframe);
-    // the xbl bindings for the iframe probably don't exist yet, so we can't
+    this.messageManager.sendAsyncMessage("Social:SetErrorURL",
+                        { template: "about:socialerror?mode=compactInfo&origin=%{origin}" });
+  },
+
+  get messageManager() {
+    // The xbl bindings for the iframe may not exist yet, so we can't
     // access iframe.messageManager directly - but can get at it with this dance.
-    let mm = iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
-    mm.sendAsyncMessage("Social:SetErrorURL",
-                        { template: "about:socialerror?mode=compactInfo&origin=%{origin}" });
+    return this.iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
   },
 
   unload: function() {
     let panel = this.panel;
     panel.hidePopup();
     if (!panel.firstChild)
       return
     let iframe = panel.firstChild;
@@ -373,24 +376,25 @@ SocialFlyout = {
     let panel = this.panel;
     let iframe = this.iframe;
     this._dynamicResizer = new DynamicResizeWatcher();
     iframe.docShellIsActive = true;
     if (iframe.contentDocument.readyState == "complete") {
       this._dynamicResizer.start(panel, iframe);
     } else {
       // first time load, wait for load and dispatch after load
-      iframe.addEventListener("load", function panelBrowserOnload(e) {
-        iframe.removeEventListener("load", panelBrowserOnload, true);
+      let mm = this.messageManager;
+      mm.addMessageListener("DOMContentLoaded", function panelBrowserOnload(e) {
+        mm.removeMessageListener("DOMContentLoaded", panelBrowserOnload);
         setTimeout(function() {
           if (SocialFlyout._dynamicResizer) { // may go null if hidden quickly
             SocialFlyout._dynamicResizer.start(panel, iframe);
           }
         }, 0);
-      }, true);
+      });
     }
   },
 
   onHidden: function(aEvent) {
     this._dynamicResizer.stop();
     this._dynamicResizer = null;
     this.iframe.docShellIsActive = false;
   },
@@ -400,20 +404,21 @@ SocialFlyout = {
       return;
 
     this.panel.hidden = false;
     let iframe = this.iframe;
     // same url with only ref difference does not cause a new load, so we
     // want to go right to the callback
     let src = iframe.contentDocument && iframe.contentDocument.documentURIObject;
     if (!src || !src.equalsExceptRef(Services.io.newURI(aURL, null, null))) {
-      iframe.addEventListener("load", function documentLoaded() {
-        iframe.removeEventListener("load", documentLoaded, true);
+      let mm = this.messageManager;
+      mm.addMessageListener("DOMContentLoaded", function documentLoaded(e) {
+        mm.removeMessageListener("DOMContentLoaded", documentLoaded);
         cb();
-      }, true);
+      });
       iframe.setAttribute("src", aURL);
     } else {
       // we still need to set the src to trigger the contents hashchange event
       // for ref changes
       iframe.setAttribute("src", aURL);
       cb();
     }
   },
@@ -469,16 +474,20 @@ SocialShare = {
   get iframe() {
     // panel.firstChild is our toolbar hbox, panel.lastChild is the iframe
     // container hbox used for an interstitial "loading" graphic
     return this.panel.lastChild.firstChild;
   },
 
   uninit: function () {
     if (this.iframe) {
+      let mm = this.messageManager;
+      mm.removeMessageListener("PageVisibility:Show", this);
+      mm.removeMessageListener("PageVisibility:Hide", this);
+      this.iframe.removeEventListener("load", this);
       this.iframe.remove();
     }
   },
 
   _createFrame: function() {
     let panel = this.panel;
     if (this.iframe)
       return;
@@ -489,23 +498,61 @@ SocialShare = {
     iframe.setAttribute("class", "social-share-frame");
     iframe.setAttribute("context", "contentAreaContextMenu");
     iframe.setAttribute("tooltip", "aHTMLTooltip");
     iframe.setAttribute("disableglobalhistory", "true");
     iframe.setAttribute("flex", "1");
     iframe.setAttribute("message", "true");
     iframe.setAttribute("messagemanagergroup", "social");
     panel.lastChild.appendChild(iframe);
-    let mm = iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
+    let mm = this.messageManager;
+    mm.addMessageListener("PageVisibility:Show", this);
+    mm.addMessageListener("PageVisibility:Hide", this);
     mm.sendAsyncMessage("Social:SetErrorURL",
                         { template: "about:socialerror?mode=compactInfo&origin=%{origin}&url=%{url}" });
+    iframe.addEventListener("load", this, true);
 
     this.populateProviderMenu();
   },
 
+  get messageManager() {
+    // The xbl bindings for the iframe may not exist yet, so we can't
+    // access iframe.messageManager directly - but can get at it with this dance.
+    return this.iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
+  },
+
+  receiveMessage: function(aMessage) {
+    let iframe = this.iframe;
+    switch(aMessage.name) {
+      case "PageVisibility:Show":
+        SocialShare._dynamicResizer.start(iframe.parentNode, iframe);
+        break;
+      case "PageVisibility:Hide":
+        SocialShare._dynamicResizer.stop();
+        break;
+    }
+  },
+
+  handleEvent: function(event) {
+    switch (event.type) {
+      case "load": {
+        let iframe = this.iframe;
+        iframe.parentNode.removeAttribute("loading");
+        // to support standard share endpoints mimick window.open by setting
+        // window.opener, some share endpoints rely on w.opener to know they
+        // should close the window when done.
+        iframe.contentWindow.opener = iframe.contentWindow;
+        this.messageManager.sendAsyncMessage("Social:HookWindowCloseForPanelClose");
+        this.messageManager.sendAsyncMessage("Social:DisableDialogs", {});
+        if (this.currentShare)
+          SocialShare.messageManager.sendAsyncMessage("Social:OpenGraphData", this.currentShare);
+      }
+    }
+  },
+
   getSelectedProvider: function() {
     let provider;
     let lastProviderOrigin = this.iframe && this.iframe.getAttribute("origin");
     if (lastProviderOrigin) {
       provider = Social._getProviderFromOrigin(lastProviderOrigin);
     }
     return provider;
   },
@@ -573,17 +620,17 @@ SocialShare = {
 
   onHidden: function() {
     (this._currentAnchor || this.anchor).removeAttribute("open");
     this._currentAnchor = null;
     this.iframe.docShellIsActive = false;
     this.iframe.removeEventListener("click", this._onclick, true);
     this.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
     // make sure that the frame is unloaded after it is hidden
-    this.iframe.docShell.createAboutBlankContentViewer(null);
+    this.messageManager.sendAsyncMessage("Social:ClearFrame");
     this.currentShare = null;
     // share panel use is over, purge any history
     this.iframe.purgeSessionHistory();
   },
 
   sharePage: function(providerOrigin, graphData, target, anchor) {
     // if providerOrigin is undefined, we use the last-used provider, or the
     // current/default provider.  The provider selection in the share panel
@@ -661,40 +708,19 @@ SocialShare = {
     }
 
     // if we've already loaded this provider/page share endpoint, we don't want
     // to add another load event listener.
     let endpointMatch = shareEndpoint == iframe.getAttribute("src");
     if (endpointMatch) {
       this._dynamicResizer.start(iframe.parentNode, iframe, size);
       iframe.docShellIsActive = true;
-      let evt = iframe.contentDocument.createEvent("CustomEvent");
-      evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(pageData));
-      iframe.contentDocument.documentElement.dispatchEvent(evt);
+      SocialShare.messageManager.sendAsyncMessage("Social:OpenGraphData", this.currentShare);
     } else {
       iframe.parentNode.setAttribute("loading", "true");
-      // first time load, wait for load and dispatch after load
-      iframe.addEventListener("load", function panelBrowserOnload(e) {
-        iframe.removeEventListener("load", panelBrowserOnload, true);
-        iframe.docShellIsActive = true;
-        iframe.parentNode.removeAttribute("loading");
-        // to support standard share endpoints mimick window.open by setting
-        // window.opener, some share endpoints rely on w.opener to know they
-        // should close the window when done.
-        iframe.contentWindow.opener = iframe.contentWindow;
-        // disable beforeunload dialogs
-        let mm = iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
-        mm.sendAsyncMessage("Social:DisableDialogs", {});
-
-        SocialShare._dynamicResizer.start(iframe.parentNode, iframe, size);
-
-        let evt = iframe.contentDocument.createEvent("CustomEvent");
-        evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(pageData));
-        iframe.contentDocument.documentElement.dispatchEvent(evt);
-      }, true);
     }
     // if the user switched between share providers we do not want that history
     // available.
     iframe.purgeSessionHistory();
 
     // always ensure that origin belongs to the endpoint
     let uri = Services.io.newURI(shareEndpoint, null, null);
     iframe.setAttribute("origin", provider.origin);
@@ -704,47 +730,36 @@ SocialShare = {
 
   showDirectory: function(anchor) {
     this._createFrame();
     let iframe = this.iframe;
     if (iframe.getAttribute("src") == "about:providerdirectory")
       return;
     iframe.removeAttribute("origin");
     iframe.parentNode.setAttribute("loading", "true");
-    iframe.addEventListener("DOMContentLoaded", function _dcl(e) {
-      iframe.removeEventListener("DOMContentLoaded", _dcl, true);
-      iframe.parentNode.removeAttribute("loading");
-    }, true);
 
-    iframe.addEventListener("load", function panelBrowserOnload(e) {
-      iframe.removeEventListener("load", panelBrowserOnload, true);
-
-      hookWindowCloseForPanelClose(iframe.contentWindow);
-      SocialShare._dynamicResizer.start(iframe.parentNode, iframe);
-
-      iframe.addEventListener("unload", function panelBrowserOnload(e) {
-        iframe.removeEventListener("unload", panelBrowserOnload, true);
-        SocialShare._dynamicResizer.stop();
-      }, true);
-    }, true);
     iframe.setAttribute("src", "about:providerdirectory");
     this._openPanel(anchor);
   },
 
   _openPanel: function(anchor) {
     this._currentAnchor = anchor || this.anchor;
     anchor = document.getAnonymousElementByAttribute(this._currentAnchor, "class", "toolbarbutton-icon");
     this.panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
     Services.telemetry.getHistogramById("SOCIAL_TOOLBAR_BUTTONS").add(0);
   }
 };
 
 SocialSidebar = {
   _openStartTime: 0,
 
+  get browser() {
+    return document.getElementById("social-sidebar-browser");
+  },
+
   // Whether the sidebar can be shown for this window.
   get canShow() {
     if (!SocialUI.enabled || document.fullscreenElement)
       return false;
     return Social.providers.some(p => p.sidebarURL);
   },
 
   // Whether the user has toggled the sidebar on (for windows where it can appear)
@@ -791,28 +806,28 @@ SocialSidebar = {
       } catch(e) {
         // Window is not tracked, which happens on osx if the window is opened
         // from the hidden window. That happens when you close the last window
         // without quiting firefox, then open a new window.
       }
     }
     if (data) {
       data = JSON.parse(data);
-      document.getElementById("social-sidebar-browser").setAttribute("origin", data.origin);
+      this.browser.setAttribute("origin", data.origin);
       if (!data.hidden)
         this.show(data.origin);
     } else if (Services.prefs.prefHasUserValue("social.sidebar.provider")) {
       // no window state, use the global state if it is available
       this.show(Services.prefs.getCharPref("social.sidebar.provider"));
     }
   },
 
   saveWindowState: function() {
     let broadcaster = document.getElementById("socialSidebarBroadcaster");
-    let sidebarOrigin = document.getElementById("social-sidebar-browser").getAttribute("origin");
+    let sidebarOrigin = this.browser.getAttribute("origin");
     let data = {
       "hidden": broadcaster.hidden,
       "origin": sidebarOrigin
     };
     if (broadcaster.hidden) {
       Services.telemetry.getHistogramById("SOCIAL_SIDEBAR_OPEN_DURATION").add(Date.now()  / 1000 - this._openStartTime);
     } else {
       this._openStartTime = Date.now() / 1000;
@@ -860,20 +875,20 @@ SocialSidebar = {
 
     // Hide the sidebar if it cannot appear, or has been toggled off.
     // Also set the command "checked" state accordingly.
     let hideSidebar = !this.canShow || !this.opened;
     let broadcaster = document.getElementById("socialSidebarBroadcaster");
     broadcaster.hidden = hideSidebar;
     command.setAttribute("checked", !hideSidebar);
 
-    let sbrowser = document.getElementById("social-sidebar-browser");
+    let sbrowser = this.browser;
 
     if (hideSidebar) {
-      sbrowser.removeEventListener("load", SocialSidebar._loadListener, true);
+      sbrowser.messageManager.removeMessageListener("DOMContentLoaded", SocialSidebar._loadListener);
       this.setSidebarVisibilityState(false);
       // If we've been disabled, unload the sidebar content immediately;
       // if the sidebar was just toggled to invisible, wait a timeout
       // before unloading.
       if (!this.canShow) {
         this.unloadSidebar();
       } else {
         this._unloadTimeoutId = setTimeout(
@@ -881,72 +896,70 @@ SocialSidebar = {
           Services.prefs.getIntPref("social.sidebar.unload_timeout_ms")
         );
       }
     } else {
       sbrowser.setAttribute("origin", this.provider.origin);
 
       // Make sure the right sidebar URL is loaded
       if (sbrowser.getAttribute("src") != this.provider.sidebarURL) {
-        // we check readyState right after setting src, we need a new content
-        // viewer to ensure we are checking against the correct document.
-        sbrowser.docShell.createAboutBlankContentViewer(null);
         sbrowser.setAttribute("src", this.provider.sidebarURL);
         PopupNotifications.locationChange(sbrowser);
-      }
-
-      // if the document has not loaded, delay until it is
-      if (sbrowser.contentDocument.readyState != "complete") {
         document.getElementById("social-sidebar-button").setAttribute("loading", "true");
-        sbrowser.addEventListener("load", SocialSidebar._loadListener, true);
+        sbrowser.messageManager.addMessageListener("DOMContentLoaded", SocialSidebar._loadListener);
       } else {
-        this.setSidebarVisibilityState(true);
+        // if the document has not loaded, delay until it is
+        if (sbrowser.contentDocument.readyState != "complete") {
+          document.getElementById("social-sidebar-button").setAttribute("loading", "true");
+          sbrowser.messageManager.addMessageListener("DOMContentLoaded", SocialSidebar._loadListener);
+        } else {
+          this.setSidebarVisibilityState(true);
+        }
       }
     }
     this._updateCheckedMenuItems(this.opened && this.provider ? this.provider.origin : null);
   },
 
   _onclick: function() {
     Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(3);
   },
 
   _loadListener: function SocialSidebar_loadListener() {
-    let sbrowser = document.getElementById("social-sidebar-browser");
-    sbrowser.removeEventListener("load", SocialSidebar._loadListener, true);
+    let sbrowser = SocialSidebar.browser;
+    sbrowser.messageManager.removeMessageListener("DOMContentLoaded", SocialSidebar._loadListener);
     document.getElementById("social-sidebar-button").removeAttribute("loading");
     SocialSidebar.setSidebarVisibilityState(true);
     sbrowser.addEventListener("click", SocialSidebar._onclick, true);
   },
 
   unloadSidebar: function SocialSidebar_unloadSidebar() {
-    let sbrowser = document.getElementById("social-sidebar-browser");
+    let sbrowser = SocialSidebar.browser;
     if (!sbrowser.hasAttribute("origin"))
       return;
 
     sbrowser.removeEventListener("click", SocialSidebar._onclick, true);
     sbrowser.stop();
     sbrowser.removeAttribute("origin");
     sbrowser.setAttribute("src", "about:blank");
     // We need to explicitly create a new content viewer because the old one
     // doesn't get destroyed until about:blank has loaded (which does not happen
     // as long as the element is hidden).
-    sbrowser.docShell.createAboutBlankContentViewer(null);
+    sbrowser.messageManager.sendAsyncMessage("Social:ClearFrame");
     SocialFlyout.unload();
   },
 
   _unloadTimeoutId: 0,
 
   _provider: null,
   ensureProvider: function() {
     if (this._provider)
       return;
     // origin for sidebar is persisted, so get the previously selected sidebar
     // first, otherwise fallback to the first provider in the list
-    let sbrowser = document.getElementById("social-sidebar-browser");
-    let origin = sbrowser.getAttribute("origin");
+    let origin = this.browser.getAttribute("origin");
     let providers = Social.providers.filter(p => p.sidebarURL);
     let provider;
     if (origin)
       provider = Social._getProviderFromOrigin(origin);
     if (!provider && providers.length > 0)
       provider = providers[0];
     if (provider)
       this.provider = provider;
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -572,16 +572,23 @@ addMessageListener("webrtc:StartBrowserS
 
 addEventListener("pageshow", function(event) {
   if (event.target == content.document) {
     sendAsyncMessage("PageVisibility:Show", {
       persisted: event.persisted,
     });
   }
 });
+addEventListener("pagehide", function(event) {
+  if (event.target == content.document) {
+    sendAsyncMessage("PageVisibility:Hide", {
+      persisted: event.persisted,
+    });
+  }
+});
 
 var PageMetadataMessenger = {
   init() {
     addMessageListener("PageMetadata:GetPageData", this);
     addMessageListener("PageMetadata:GetMicroformats", this);
   },
   receiveMessage(message) {
     switch(message.name) {
--- a/browser/base/content/social-content.js
+++ b/browser/base/content/social-content.js
@@ -13,42 +13,60 @@ Cu.import("resource://gre/modules/Servic
 
 // Tie `content` to this frame scripts' global scope explicitly. If we don't, then
 // `content` might be out of eval's scope and GC'ed before this script is done.
 // See bug 1229195 for empirical proof.
 var gContent = content;
 
 // social frames are always treated as app tabs
 docShell.isAppTab = true;
+var gHookedWindowCloseForPanelClose = false;
 
 var gDOMContentLoaded = false;
-addEventListener("DOMContentLoaded", function() {
-  gDOMContentLoaded = true;
-  sendAsyncMessage("DOMContentLoaded");
+addEventListener("DOMContentLoaded", function(event) {
+  if (event.target == content.document) {
+    gDOMContentLoaded = true;
+    sendAsyncMessage("DOMContentLoaded");
+  }
 });
+addEventListener("unload", function(event) {
+  if (event.target == content.document) {
+    gDOMContentLoaded = false;
+    gHookedWindowCloseForPanelClose = false;
+  }
+}, true);
+
 var gDOMTitleChangedByUs = false;
 addEventListener("DOMTitleChanged", function(e) {
   if (!gDOMTitleChangedByUs) {
     sendAsyncMessage("Social:DOMTitleChanged", {
       title: e.target.title
     });
   }
   gDOMTitleChangedByUs = false;
 });
-var gHookedWindowCloseForPanelClose = false;
 
 addEventListener("Social:Notification", function(event) {
   let frame = docShell.chromeEventHandler;
   let origin = frame.getAttribute("origin");
   sendAsyncMessage("Social:Notification", {
     "origin": origin,
     "detail": JSON.parse(event.detail)
   });
 });
 
+addMessageListener("Social:OpenGraphData", (message) => {
+  let ev = new content.CustomEvent("OpenGraphData", { detail: JSON.stringify(message.data) });
+  content.dispatchEvent(ev);
+});
+
+addMessageListener("Social:ClearFrame", (message) => {
+  docShell.createAboutBlankContentViewer(null);
+});
+
 // Error handling class used to listen for network errors in the social frames
 // and replace them with a social-specific error page
 const SocialErrorListener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMEventListener,
                                          Ci.nsIWebProgressListener,
                                          Ci.nsISupportsWeakReference,
                                          Ci.nsISupports]),
 
--- a/browser/base/content/socialmarks.xml
+++ b/browser/base/content/socialmarks.xml
@@ -62,16 +62,22 @@
           iframe.setAttribute("style", "width: " + width + "px; height: " + height + "px;");
           this.panel.appendChild(iframe);
 
           this._frame.addEventListener("DOMLinkAdded", this);
           return this._frame;
         ]]></getter>
       </property>
 
+      <property name="messageManager">
+        <getter>
+          return this.content.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
+        </getter>
+      </property>
+
       <property name="contentWindow">
         <getter>
           return this.content.contentWindow;
         </getter>
       </property>
 
       <property name="contentDocument">
         <getter>
@@ -175,36 +181,29 @@
             this.loadPanel(pageData, target);
           });
           gBrowser.selectedBrowser.messageManager.sendAsyncMessage("PageMetadata:GetMicroformats", null, { target });
           return;
         }
         this.pageData = pageData;
 
         let endpoint = OpenGraphBuilder.generateEndpointURL(URLTemplate, this.pageData);
-
         // setup listeners
         let DOMContentLoaded = (event) => {
-          if (event.target != this.contentDocument)
-            return;
           this._loading = false;
-          this.content.removeEventListener("DOMContentLoaded", DOMContentLoaded, true);
+          this.messageManager.removeMessageListener("DOMContentLoaded", DOMContentLoaded);
           // add our resizer after the dom is ready
           if (this._useDynamicResizer) {
             let DynamicResizeWatcher = Cu.import("resource:///modules/Social.jsm", {}).DynamicResizeWatcher;
             this._dynamicResizer = new DynamicResizeWatcher();
             this._dynamicResizer.start(this.panel, this.content);
           } else if (this._dynamicResizer) {
             this._dynamicResizer.stop();
             this._dynamicResizer = null;
           }
-          // send the opengraph data
-          let evt = this.contentDocument.createEvent("CustomEvent");
-          evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(this.pageData));
-          this.contentDocument.documentElement.dispatchEvent(evt);
 
           let contentWindow = this.contentWindow;
           let markUpdate = function(event) {
             // update the annotation based on this event, then update the
             // icon as well
             this.isMarked = JSON.parse(event.detail).marked;
             if (this.isMarked) {
               Social.markURI(provider.origin, gBrowser.currentURI);
@@ -215,18 +214,21 @@
             }
           }.bind(this);
           let unload = () => {
             contentWindow.removeEventListener("unload", unload);
             contentWindow.removeEventListener("socialMarkUpdate", markUpdate);
           }
           contentWindow.addEventListener("socialMarkUpdate", markUpdate);
           contentWindow.addEventListener("unload", unload);
+
+          // send the opengraph data
+          this.messageManager.sendAsyncMessage("Social:OpenGraphData", pageData);
         }
-        this.content.addEventListener("DOMContentLoaded", DOMContentLoaded, true);
+        this.messageManager.addMessageListener("DOMContentLoaded", DOMContentLoaded);
         this._loading = true;
         this.content.setAttribute("src", endpoint);
         ]]></body>
       </method>
 
       <method name="openPanel">
         <parameter name="aResetOnClose"/>
         <body><![CDATA[
@@ -283,28 +285,31 @@
         this.contentDocument.documentElement.dispatchEvent(evt);
         ]]></body>
       </method>
 
       <method name="onShown">
         <body><![CDATA[
         // because the panel may be preloaded, we need to size the panel when
         // showing as well as after load
+        if (!this._useDynamicResizer) {
+          return;
+        }
         let sizeSocialPanelToContent = Cu.import("resource:///modules/Social.jsm", {}).sizeSocialPanelToContent;
         if (!this._loading && this.contentDocument &&
             this.contentDocument.readyState == "complete") {
-          if (this._useDynamicResizer)
-            sizeSocialPanelToContent(this.panel, this.content);
+          sizeSocialPanelToContent(this.panel, this.content);
         } else {
-          let panelBrowserOnload = (e) => {
-            this.content.removeEventListener("load", panelBrowserOnload, true);
-            if (this._useDynamicResizer)
-              sizeSocialPanelToContent(this.panel, this.content);
+          let panelBrowserOnload = (message) => {
+            if (message.target != this.content)
+              return;
+            this.messageManager.removeMessageListener("PageVisibility:Show", panelBrowserOnload, true);
+            sizeSocialPanelToContent(this.panel, this.content);
           };
-          this.content.addEventListener("load", panelBrowserOnload, true);
+          this.messageManager.addMessageListener("PageVisibility:Show", panelBrowserOnload);
         }
         ]]></body>
       </method>
 
       <method name="handleEvent">
         <parameter name="aEvent"/>
         <body><![CDATA[
         if (aEvent.eventPhase != aEvent.BUBBLING_PHASE)
--- a/browser/base/content/test/social/browser_aboutHome_activation.js
+++ b/browser/base/content/test/social/browser_aboutHome_activation.js
@@ -258,22 +258,21 @@ function activateProvider(tab, expectPan
   });
 }
 
 function waitForProviderLoad(cb) {
   Services.obs.addObserver(function providerSet(subject, topic, data) {
     Services.obs.removeObserver(providerSet, "social:provider-enabled");
     info("social:provider-enabled observer was notified");
     waitForCondition(function() {
-      let sbrowser = document.getElementById("social-sidebar-browser");
       let provider = SocialSidebar.provider;
       let postActivation = provider && gBrowser.contentDocument.location.href == provider.origin + "/browser/browser/base/content/test/social/social_postActivation.html";
 
       return provider &&
              postActivation &&
-             sbrowser.docShellIsActive;
+             SocialSidebar.browser.docShellIsActive;
     }, function() {
       // executeSoon to let the browser UI observers run first
       executeSoon(cb);
     },
-    "waitForProviderLoad: provider profile was not set");
+    "waitForProviderLoad: provider sidebar was not set, "+SocialSidebar.provider+", "+SocialSidebar.browser.docShellIsActive);
   }, "social:provider-enabled", false);
 }