Bug 1053413 part 4 - Rely on single MozDOMFullscreen:Exited event instead of ask-* notifications on Firefox. r=dao
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 21 May 2015 09:52:26 +1200
changeset 244798 8660faf99370b8b6d5086eeeaaae0b3ce8a36def
parent 244797 cc84953b598d8ad36f9028a79f6a0b412bf3f67f
child 244799 447b220d7c55e528cbedf7cb8b8256e457b04b68
push id60038
push userxquan@mozilla.com
push dateWed, 20 May 2015 21:53:15 +0000
treeherdermozilla-inbound@49ffe4e6b4d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1053413
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1053413 part 4 - Rely on single MozDOMFullscreen:Exited event instead of ask-* notifications on Firefox. r=dao
browser/base/content/browser-fullScreen.js
browser/base/content/tab-content.js
toolkit/content/browser-child.js
toolkit/content/widgets/remote-browser.xml
--- a/browser/base/content/browser-fullScreen.js
+++ b/browser/base/content/browser-fullScreen.js
@@ -96,37 +96,40 @@ var FullScreen = {
       case "transitionend":
         if (event.propertyName == "opacity")
           this.cancelWarning();
         break;
     }
   },
 
   receiveMessage: function(aMessage) {
+    let browser = aMessage.target;
     switch (aMessage.name) {
       case "DOMFullscreen:Entered": {
         // If we're a multiprocess browser, then the request to enter
         // fullscreen did not bubble up to the root browser document -
         // it stopped at the root of the content document. That means
         // we have to kick off the switch to fullscreen here at the
         // operating system level in the parent process ourselves.
-        let browser = aMessage.target;
-        if (gMultiProcessBrowser && browser.getAttribute("remote") == "true") {
-          let windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                                  .getInterface(Ci.nsIDOMWindowUtils);
-          windowUtils.remoteFrameFullscreenChanged(browser);
+        if (this._isRemoteBrowser(browser)) {
+          this._windowUtils.remoteFrameFullscreenChanged(browser);
         }
         this.enterDomFullscreen(browser);
         break;
       }
       case "DOMFullscreen:NewOrigin": {
         this.showWarning(aMessage.data.origin);
         break;
       }
       case "DOMFullscreen:Exited": {
+        // Like entering DOM fullscreen, we also need to exit fullscreen
+        // at the operating system level in the parent process here.
+        if (this._isRemoteBrowser(browser)) {
+          this._windowUtils.remoteFrameFullscreenReverted();
+        }
         document.documentElement.removeAttribute("inDOMFullscreen");
         this.cleanupDomFullscreen();
         this.showNavToolbox();
         // If we are still in fullscreen mode, re-hide
         // the toolbox with animation.
         if (window.fullScreen) {
           this._shouldAnimate = true;
           this.hideNavToolbox();
@@ -195,17 +198,26 @@ var FullScreen = {
     this.cancelWarning();
     gBrowser.tabContainer.removeEventListener("TabOpen", this.exitDomFullScreen);
     gBrowser.tabContainer.removeEventListener("TabClose", this.exitDomFullScreen);
     gBrowser.tabContainer.removeEventListener("TabSelect", this.exitDomFullScreen);
     if (!this.useLionFullScreen)
       window.removeEventListener("activate", this);
 
     window.messageManager
-          .broadcastAsyncMessage("DOMFullscreen:Cleanup");
+          .broadcastAsyncMessage("DOMFullscreen:CleanUp");
+  },
+
+  _isRemoteBrowser: function (aBrowser) {
+    return gMultiProcessBrowser && aBrowser.getAttribute("remote") == "true";
+  },
+
+  get _windowUtils() {
+    return window.QueryInterface(Ci.nsIInterfaceRequestor)
+                 .getInterface(Ci.nsIDOMWindowUtils);
   },
 
   getMouseTargetRect: function()
   {
     return this._mouseTargetRect;
   },
 
   // Event callbacks
--- a/browser/base/content/tab-content.js
+++ b/browser/base/content/tab-content.js
@@ -600,16 +600,19 @@ let DOMFullscreenHandler = {
         if (this._fullscreenDoc) {
           Services.obs.notifyObservers(this._fullscreenDoc,
                                        "fullscreen-approved",
                                        "");
         }
         break;
       }
       case "DOMFullscreen:CleanUp": {
+        let utils = content.QueryInterface(Ci.nsIInterfaceRequestor)
+                           .getInterface(Ci.nsIDOMWindowUtils);
+        utils.exitFullscreen();
         this._fullscreenDoc = null;
         break;
       }
     }
   },
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -496,58 +496,16 @@ addEventListener("unload", () => {
 
 addMessageListener("NetworkPrioritizer:AdjustPriority", (msg) => {
   let webNav = docShell.QueryInterface(Ci.nsIWebNavigation);
   let loadGroup = webNav.QueryInterface(Ci.nsIDocumentLoader)
                         .loadGroup.QueryInterface(Ci.nsISupportsPriority);
   loadGroup.adjustPriority(msg.data.adjustment);
 });
 
-let DOMFullscreenManager = {
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
-                                         Ci.nsISupportsWeakReference]),
-
-  init: function() {
-    Services.obs.addObserver(this, "ask-parent-to-exit-fullscreen", false);
-    Services.obs.addObserver(this, "ask-parent-to-rollback-fullscreen", false);
-    addMessageListener("DOMFullscreen:ChildrenMustExit", () => {
-      let utils = content.QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsIDOMWindowUtils);
-      utils.exitFullscreen();
-    });
-    addEventListener("unload", () => {
-      Services.obs.removeObserver(this, "ask-parent-to-exit-fullscreen");
-      Services.obs.removeObserver(this, "ask-parent-to-rollback-fullscreen");
-    });
-  },
-
-  observe: function(aSubject, aTopic, aData) {
-    // Observer notifications are global, which means that these notifications
-    // might be coming from elements that are not actually children within this
-    // windows' content. We should ignore those. This will not be necessary once
-    // we fix bug 1053413 and stop using observer notifications for this stuff.
-    if (aSubject.defaultView.top !== content) {
-      return;
-    }
-
-    switch (aTopic) {
-      case "ask-parent-to-exit-fullscreen": {
-        sendAsyncMessage("DOMFullscreen:RequestExit");
-        break;
-      }
-      case "ask-parent-to-rollback-fullscreen": {
-        sendAsyncMessage("DOMFullscreen:RequestRollback");
-        break;
-      }
-    }
-  },
-};
-
-DOMFullscreenManager.init();
-
 let AutoCompletePopup = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompletePopup]),
 
   init: function() {
     // Hook up the form fill autocomplete controller.
     let controller = Cc["@mozilla.org/satchel/form-fill-controller;1"]
                        .getService(Ci.nsIFormFillController);
 
--- a/toolkit/content/widgets/remote-browser.xml
+++ b/toolkit/content/widgets/remote-browser.xml
@@ -258,18 +258,16 @@
             this.messageManager.addMessageListener("Forms:HideDropDown", this);
             this.messageManager.loadFrameScript("chrome://global/content/select-child.js", true);
           }
 
           jsm = "resource://gre/modules/RemoteController.jsm";
           let RemoteController = Components.utils.import(jsm, {}).RemoteController;
           this._controller = new RemoteController(this);
           this.controllers.appendController(this._controller);
-
-          Services.obs.addObserver(this, "ask-children-to-exit-fullscreen", false);
         ]]>
       </constructor>
 
       <destructor>
         <![CDATA[
           this.destroy();
         ]]>
       </destructor>
@@ -278,18 +276,16 @@
            we are removed from a tabbrowser. This will be explicitly called by tabbrowser -->
       <method name="destroy">
         <body><![CDATA[
           if (this.mDestroyed)
             return;
           this.mDestroyed = true;
 
           this.controllers.removeController(this._controller);
-
-          Services.obs.removeObserver(this, "ask-children-to-exit-fullscreen");
         ]]></body>
       </method>
 
       <method name="receiveMessage">
         <parameter name="aMessage"/>
         <body><![CDATA[
           let data = aMessage.data;
           switch (aMessage.name) {
@@ -365,29 +361,16 @@
             default:
               // Delegate to browser.xml.
               return this._receiveMessage(aMessage);
               break;
           }
         ]]></body>
       </method>
 
-      <method name="observe">
-        <parameter name="aSubject"/>
-        <parameter name="aTopic"/>
-        <parameter name="aData"/>
-        <body><![CDATA[
-          if (aTopic == "ask-children-to-exit-fullscreen") {
-            if (aSubject == window.document) {
-              this.messageManager.sendAsyncMessage("DOMFullscreen:ChildrenMustExit");
-            }
-          }
-        ]]></body>
-      </method>
-
       <method name="enableDisableCommands">
         <parameter name="aAction"/>
         <parameter name="aEnabledLength"/>
         <parameter name="aEnabledCommands"/>
         <parameter name="aDisabledLength"/>
         <parameter name="aDisabledCommands"/>
         <body>
           if (this._controller) {