Bug 1167890 - Cleanup DOM fullscreen state in chrome for MozDOMFullscreen:Exited event. r=dao
authorXidorn Quan <quanxunzhen@gmail.com>
Fri, 29 May 2015 09:55:39 +1200
changeset 246211 df24a0f5a0bc16564490eb906689498a2b730bdb
parent 246210 0256c351bd95d5cd1ba5183d8da7a816abecad33
child 246212 b65d8a1df422eb01c12c5ba413fbc77a309ba2c6
push id28823
push userryanvm@gmail.com
push dateFri, 29 May 2015 13:33:16 +0000
treeherdermozilla-central@9738f055d98c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1167890
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 1167890 - Cleanup DOM fullscreen state in chrome for MozDOMFullscreen:Exited event. r=dao
browser/base/content/browser-fullScreen.js
--- a/browser/base/content/browser-fullScreen.js
+++ b/browser/base/content/browser-fullScreen.js
@@ -10,16 +10,19 @@ var FullScreen = {
     "DOMFullscreen:Entered",
     "DOMFullscreen:NewOrigin",
     "DOMFullscreen:Exited"
   ],
 
   init: function() {
     // called when we go into full screen, even if initiated by a web page script
     window.addEventListener("fullscreen", this, true);
+    window.addEventListener("MozDOMFullscreen:Exited", this,
+                            /* useCapture */ true,
+                            /* wantsUntrusted */ false);
     for (let type of this._MESSAGES) {
       window.messageManager.addMessageListener(type, this);
     }
 
     if (window.fullScreen)
       this.toggle();
   },
 
@@ -92,16 +95,19 @@ var FullScreen = {
         break;
       case "fullscreen":
         this.toggle(event);
         break;
       case "transitionend":
         if (event.propertyName == "opacity")
           this.cancelWarning();
         break;
+      case "MozDOMFullscreen:Exited":
+        this.cleanupDomFullscreen();
+        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
@@ -120,25 +126,17 @@ var FullScreen = {
         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();
-        }
         break;
       }
     }
   },
 
   enterDomFullscreen : function(aBrowser) {
     if (!document.mozFullScreen)
       return;
@@ -184,29 +182,36 @@ var FullScreen = {
   },
 
   cleanup: function () {
     if (window.fullScreen) {
       MousePosTracker.removeListener(this);
       document.removeEventListener("keypress", this._keyToggleCallback, false);
       document.removeEventListener("popupshown", this._setPopupOpen, false);
       document.removeEventListener("popuphidden", this._setPopupOpen, false);
-
-      this.cleanupDomFullscreen();
     }
   },
 
   cleanupDomFullscreen: function () {
     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);
 
+    document.documentElement.removeAttribute("inDOMFullscreen");
+    this.showNavToolbox();
+    // If we are still in fullscreen mode, re-hide
+    // the toolbox with animation.
+    if (window.fullScreen) {
+      this._shouldAnimate = true;
+      this.hideNavToolbox();
+    }
+
     window.messageManager
           .broadcastAsyncMessage("DOMFullscreen:CleanUp");
   },
 
   _isRemoteBrowser: function (aBrowser) {
     return gMultiProcessBrowser && aBrowser.getAttribute("remote") == "true";
   },