Bug 1047316 - Don't display panels using docshell swapping in panelviews. r=jaws, a=lmandel
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 21 Aug 2014 07:44:17 -0700
changeset 217619 b6635ee27fbef7208634c63599700b78fbaefa63
parent 217618 e5fdb23a3914fa6d220c42d21fa23fe6a55d7e70
child 217620 7e73d586709b52d8189628ddf40104741d8610fe
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, lmandel
bugs1047316
milestone33.0a2
Bug 1047316 - Don't display panels using docshell swapping in panelviews. r=jaws, a=lmandel
browser/base/content/browser-loop.js
browser/base/content/browser-social.js
browser/modules/PanelFrame.jsm
--- a/browser/base/content/browser-loop.js
+++ b/browser/base/content/browser-loop.js
@@ -22,17 +22,17 @@ XPCOMUtils.defineLazyModuleGetter(this, 
     openCallPanel: function(event) {
       let callback = iframe => {
         iframe.addEventListener("DOMContentLoaded", function documentDOMLoaded() {
           iframe.removeEventListener("DOMContentLoaded", documentDOMLoaded, true);
           injectLoopAPI(iframe.contentWindow);
         }, true);
       };
 
-      PanelFrame.showPopup(window, PanelUI, event.target, "loop", null,
+      PanelFrame.showPopup(window, event.target, "loop", null,
                            "about:looppanel", null, callback);
     },
 
     /**
      * Triggers the initialization of the loop service.  Called by
      * delayedStartup.
      */
     initialize: function() {
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -1277,17 +1277,17 @@ SocialStatus = {
     Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(1);
   },
 
   showPopup: function(aToolbarButton) {
     // attach our notification panel if necessary
     let origin = aToolbarButton.getAttribute("origin");
     let provider = Social._getProviderFromOrigin(origin);
 
-    PanelFrame.showPopup(window, PanelUI, aToolbarButton, "social", origin,
+    PanelFrame.showPopup(window, aToolbarButton, "social", origin,
                          provider.statusURL, provider.getPageSize("status"),
                          (frame) => {
                           frame.addEventListener("close", this._onclose, true);
                           frame.addEventListener("click", this._onclick, true);
                         });
     Services.telemetry.getHistogramById("SOCIAL_TOOLBAR_BUTTONS").add(1);
   },
 
--- a/browser/modules/PanelFrame.jsm
+++ b/browser/modules/PanelFrame.jsm
@@ -106,41 +106,30 @@ let PanelFrame = {
    * @param {String} aType The type of panel this is, e.g. "social" or "loop".
    * @param {String} aOrigin Optional, the origin to use for the iframe.
    * @param {String} aSrc The url to load into the iframe.
    * @param {String} aSize The initial size of the panel (width and height are the same
    *                       if specified).
    * @param {Function} aCallback Optional, callback to be called with the iframe when it is
    *                             set up.
    */
-  showPopup: function(aWindow, aPanelUI, aToolbarButton, aType, aOrigin, aSrc, aSize, aCallback) {
+  showPopup: function(aWindow, aToolbarButton, aType, aOrigin, aSrc, aSize, aCallback) {
     // if we're overflowed, our anchor needs to be the overflow button
     let widgetGroup = CustomizableUI.getWidget(aToolbarButton.getAttribute("id"));
     let widget = widgetGroup.forWindow(aWindow);
+    // if we're a slice in the hamburger, our anchor will be the menu button,
+    // this panel will replace the menu panel when the button is clicked on
     let anchorBtn = widget.anchor;
 
-    // if we're a slice in the hamburger, use that panel instead
-    let panel, showingEvent, hidingEvent;
-    let inMenuPanel = widgetGroup.areaType == CustomizableUI.TYPE_MENU_PANEL;
-    if (inMenuPanel) {
-      panel = aWindow.document.getElementById("PanelUI-" + aType + "api");
-      PanelFrameInternal._attachNotificatonPanel(aWindow, panel, aToolbarButton, aType, aOrigin, aSrc, aSize);
-      widget.node.setAttribute("closemenu", "none");
-      showingEvent = "ViewShowing";
-      hidingEvent = "ViewHiding";
-    } else {
-      panel = aWindow.document.getElementById(aType + "-notification-panel");
-      PanelFrameInternal._attachNotificatonPanel(aWindow, panel, aToolbarButton, aType, aOrigin, aSrc, aSize);
-      showingEvent = "popupshown";
-      hidingEvent = "popuphidden";
-    }
+    let panel = aWindow.document.getElementById(aType + "-notification-panel");
+    PanelFrameInternal._attachNotificatonPanel(aWindow, panel, aToolbarButton, aType, aOrigin, aSrc, aSize);
+
     let notificationFrameId = aToolbarButton.getAttribute("notificationFrameId");
     let notificationFrame = aWindow.document.getElementById(notificationFrameId);
 
-    SharedFrame.setOwner(notificationFrameId, notificationFrame);
 
     // Clear dimensions on all browsers so the panel size will
     // only use the selected browser.
     let frameIter = panel.firstElementChild;
     while (frameIter) {
       frameIter.collapsed = (frameIter != notificationFrame);
       frameIter = frameIter.nextElementSibling;
     }
@@ -148,67 +137,61 @@ let PanelFrame = {
     function dispatchPanelEvent(name) {
       let evt = notificationFrame.contentDocument.createEvent("CustomEvent");
       evt.initCustomEvent(name, true, true, {});
       notificationFrame.contentDocument.documentElement.dispatchEvent(evt);
     }
 
     // we only use a dynamic resizer when we're located the toolbar.
     let dynamicResizer;
-    if (!inMenuPanel && notificationFrame.getAttribute("dynamicresizer") == "true") {
+    if (notificationFrame.getAttribute("dynamicresizer") == "true") {
       dynamicResizer = PanelFrameInternal._dynamicResizer;
     }
-    panel.addEventListener(hidingEvent, function onpopuphiding() {
-      panel.removeEventListener(hidingEvent, onpopuphiding);
-      if (!inMenuPanel)
-        anchorBtn.removeAttribute("open");
+    panel.addEventListener("popuphidden", function onpopuphiding() {
+      panel.removeEventListener("popuphidden", onpopuphiding);
+      anchorBtn.removeAttribute("open");
       if (dynamicResizer)
         dynamicResizer.stop();
       notificationFrame.docShell.isActive = false;
       dispatchPanelEvent(aType + "FrameHide");
     });
 
-    panel.addEventListener(showingEvent, function onpopupshown() {
-      panel.removeEventListener(showingEvent, onpopupshown);
+    panel.addEventListener("popupshown", function onpopupshown() {
+      panel.removeEventListener("popupshown", onpopupshown);
+      SharedFrame.setOwner(notificationFrameId, notificationFrame);
       // This attribute is needed on both the button and the
       // containing toolbaritem since the buttons on OS X have
       // moz-appearance:none, while their container gets
       // moz-appearance:toolbarbutton due to the way that toolbar buttons
       // get combined on OS X.
       let initFrameShow = () => {
         notificationFrame.docShell.isActive = true;
         notificationFrame.docShell.isAppTab = true;
         if (dynamicResizer)
           dynamicResizer.start(panel, notificationFrame);
         dispatchPanelEvent(aType + "FrameShow");
       };
-      if (!inMenuPanel)
-        anchorBtn.setAttribute("open", "true");
+      anchorBtn.setAttribute("open", "true");
       if (notificationFrame.contentDocument &&
           notificationFrame.contentDocument.readyState == "complete") {
         initFrameShow();
       } else {
         // first time load, wait for load and dispatch after load
         notificationFrame.addEventListener("load", function panelBrowserOnload(e) {
           notificationFrame.removeEventListener("load", panelBrowserOnload, true);
           initFrameShow();
         }, true);
       }
     });
 
-    if (inMenuPanel) {
-      aPanelUI.showSubView("PanelUI-" + aType + "api", widget.node,
-                           CustomizableUI.AREA_PANEL);
-    } else {
-      // in overflow, the anchor is a normal toolbarbutton, in toolbar it is a badge button
-      let anchor = aWindow.document.getAnonymousElementByAttribute(anchorBtn, "class", "toolbarbutton-badge-container") ||
-                   aWindow.document.getAnonymousElementByAttribute(anchorBtn, "class", "toolbarbutton-icon");
-      // Bug 849216 - open the popup asynchronously so we avoid the auto-rollup
-      // handling from preventing it being opened in some cases.
-      Services.tm.mainThread.dispatch(function() {
-        panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
-      }, Ci.nsIThread.DISPATCH_NORMAL);
-    }
+    // in overflow, the anchor is a normal toolbarbutton, in toolbar it is a badge button
+    let anchor = aWindow.document.getAnonymousElementByAttribute(anchorBtn, "class", "toolbarbutton-badge-container") ||
+                 aWindow.document.getAnonymousElementByAttribute(anchorBtn, "class", "toolbarbutton-icon");
+    // Bug 849216 - open the popup asynchronously so we avoid the auto-rollup
+    // handling from preventing it being opened in some cases.
+    Services.tm.mainThread.dispatch(function() {
+      panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
+    }, Ci.nsIThread.DISPATCH_NORMAL);
 
     if (aCallback)
       aCallback(notificationFrame);
   }
 };