Bug 1472491: Part 5m - Add DOMFullscreenChild actor. r=felipe
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 21:20:01 -0700
changeset 486565 1dc5ef9b4bf34df0e28be99e5736f6a744b96696
parent 486564 58587e163a5912cf56164a3f4af43a8d114913be
child 486566 750cdb02923bb544ca7b38e606e87c6d35e0d74b
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1472491
milestone63.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 1472491: Part 5m - Add DOMFullscreenChild actor. r=felipe MozReview-Commit-ID: JwJNUieHp5d
browser/actors/DOMFullscreenChild.jsm
browser/actors/moz.build
browser/base/content/tab-content.js
browser/components/nsBrowserGlue.js
copy from browser/base/content/tab-content.js
copy to browser/actors/DOMFullscreenChild.jsm
--- a/browser/base/content/tab-content.js
+++ b/browser/actors/DOMFullscreenChild.jsm
@@ -1,225 +1,81 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ts=2 sw=2 sts=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* This content script contains code that requires a tab browser. */
-
-/* eslint-env mozilla/frame-script */
-
-ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-ChromeUtils.import("resource://gre/modules/Services.jsm");
-
-ChromeUtils.defineModuleGetter(this, "E10SUtils",
-  "resource://gre/modules/E10SUtils.jsm");
-ChromeUtils.defineModuleGetter(this, "BrowserUtils",
-  "resource://gre/modules/BrowserUtils.jsm");
-
-ChromeUtils.import("resource://gre/modules/ActorManagerChild.jsm");
-
-ActorManagerChild.attach(this, "browsers");
-
-// TabChildGlobal
-var global = this;
-
-addMessageListener("Browser:HideSessionRestoreButton", function(message) {
-  // Hide session restore button on about:home
-  let doc = content.document;
-  let container;
-  if (doc.documentURI.toLowerCase() == "about:home" &&
-      (container = doc.getElementById("sessionRestoreContainer"))) {
-    container.hidden = true;
-  }
-});
+"use strict";
 
-XPCOMUtils.defineLazyProxy(this, "LightweightThemeChildHelper",
-  "resource:///modules/LightweightThemeChildHelper.jsm");
-
-XPCOMUtils.defineLazyProxy(this, "ManifestMessages", () => {
-  let tmp = {};
-  ChromeUtils.import("resource://gre/modules/ManifestMessages.jsm", tmp);
-  return new tmp.ManifestMessages(global);
-});
-
-let themeablePagesWhitelist = new Set([
-  "about:home",
-  "about:newtab",
-  "about:welcome",
-]);
-
-addEventListener("pageshow", function({ originalTarget }) {
-  if (originalTarget.defaultView == content && themeablePagesWhitelist.has(content.document.documentURI)) {
-    LightweightThemeChildHelper.listen(themeablePagesWhitelist);
-    LightweightThemeChildHelper.update(chromeOuterWindowID, content);
-  }
-}, false, true);
-
-// Keep a reference to the translation content handler to avoid it it being GC'ed.
-var trHandler = null;
-if (Services.prefs.getBoolPref("browser.translation.detectLanguage")) {
-  ChromeUtils.import("resource:///modules/translation/TranslationContentHandler.jsm");
-  trHandler = new TranslationContentHandler(global, docShell);
-}
-
-function gKeywordURIFixup(fixupInfo) {
-  fixupInfo.QueryInterface(Ci.nsIURIFixupInfo);
-  if (!fixupInfo.consumer) {
-    return;
-  }
+var EXPORTED_SYMBOLS = ["DOMFullscreenChild"];
 
-  // Ignore info from other docshells
-  let parent = fixupInfo.consumer.QueryInterface(Ci.nsIDocShellTreeItem).sameTypeRootTreeItem;
-  if (parent != docShell)
-    return;
-
-  let data = {};
-  for (let f of Object.keys(fixupInfo)) {
-    if (f == "consumer" || typeof fixupInfo[f] == "function")
-      continue;
-
-    if (fixupInfo[f] && fixupInfo[f] instanceof Ci.nsIURI) {
-      data[f] = fixupInfo[f].spec;
-    } else {
-      data[f] = fixupInfo[f];
-    }
-  }
-
-  sendAsyncMessage("Browser:URIFixup", data);
-}
-Services.obs.addObserver(gKeywordURIFixup, "keyword-uri-fixup");
-addEventListener("unload", () => {
-  Services.obs.removeObserver(gKeywordURIFixup, "keyword-uri-fixup");
-}, false);
-
-var WebBrowserChrome = {
-  onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab) {
-    return BrowserUtils.onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab);
-  },
-
-  // Check whether this URI should load in the current process
-  shouldLoadURI(aDocShell, aURI, aReferrer, aHasPostData, aTriggeringPrincipal) {
-    if (!E10SUtils.shouldLoadURI(aDocShell, aURI, aReferrer, aHasPostData)) {
-      E10SUtils.redirectLoad(aDocShell, aURI, aReferrer, aTriggeringPrincipal, false);
-      return false;
-    }
+ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
 
-    return true;
-  },
-
-  shouldLoadURIInThisProcess(aURI) {
-    return E10SUtils.shouldLoadURIInThisProcess(aURI);
-  },
-
-  // Try to reload the currently active or currently loading page in a new process.
-  reloadInFreshProcess(aDocShell, aURI, aReferrer, aTriggeringPrincipal, aLoadFlags) {
-    E10SUtils.redirectLoad(aDocShell, aURI, aReferrer, aTriggeringPrincipal, true, aLoadFlags);
-    return true;
-  }
-};
-
-if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
-  let tabchild = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsITabChild);
-  tabchild.webBrowserChrome = WebBrowserChrome;
-}
-
-
-var DOMFullscreenHandler = {
-
-  init() {
-    addMessageListener("DOMFullscreen:Entered", this);
-    addMessageListener("DOMFullscreen:CleanUp", this);
-    addEventListener("MozDOMFullscreen:Request", this);
-    addEventListener("MozDOMFullscreen:Entered", this);
-    addEventListener("MozDOMFullscreen:NewOrigin", this);
-    addEventListener("MozDOMFullscreen:Exit", this);
-    addEventListener("MozDOMFullscreen:Exited", this);
-    this.init = null;
-  },
-
+class DOMFullscreenChild extends ActorChild {
   receiveMessage(aMessage) {
-    let windowUtils = content && content.windowUtils;
+    let windowUtils = this.content && this.content.windowUtils;
     switch (aMessage.name) {
       case "DOMFullscreen:Entered": {
         this._lastTransactionId = windowUtils.lastTransactionId;
         if (!windowUtils.handleFullscreenRequests() &&
-            !content.document.fullscreenElement) {
+            !this.content.document.fullscreenElement) {
           // If we don't actually have any pending fullscreen request
           // to handle, neither we have been in fullscreen, tell the
           // parent to just exit.
-          sendAsyncMessage("DOMFullscreen:Exit");
+          this.mm.sendAsyncMessage("DOMFullscreen:Exit");
         }
         break;
       }
       case "DOMFullscreen:CleanUp": {
         // If we've exited fullscreen at this point, no need to record
         // transaction id or call exit fullscreen. This is especially
         // important for non-e10s, since in that case, it is possible
         // that no more paint would be triggered after this point.
-        if (content.document.fullscreenElement && windowUtils) {
+        if (this.content.document.fullscreenElement && windowUtils) {
           this._lastTransactionId = windowUtils.lastTransactionId;
           windowUtils.exitFullscreen();
         }
         break;
       }
     }
-  },
+  }
 
   handleEvent(aEvent) {
     switch (aEvent.type) {
       case "MozDOMFullscreen:Request": {
-        sendAsyncMessage("DOMFullscreen:Request");
+        this.mm.sendAsyncMessage("DOMFullscreen:Request");
         break;
       }
       case "MozDOMFullscreen:NewOrigin": {
-        sendAsyncMessage("DOMFullscreen:NewOrigin", {
+        this.mm.sendAsyncMessage("DOMFullscreen:NewOrigin", {
           originNoSuffix: aEvent.target.nodePrincipal.originNoSuffix,
         });
         break;
       }
       case "MozDOMFullscreen:Exit": {
-        sendAsyncMessage("DOMFullscreen:Exit");
+        this.mm.sendAsyncMessage("DOMFullscreen:Exit");
         break;
       }
       case "MozDOMFullscreen:Entered":
       case "MozDOMFullscreen:Exited": {
-        addEventListener("MozAfterPaint", this);
-        if (!content || !content.document.fullscreenElement) {
+        this.mm.addEventListener("MozAfterPaint", this);
+        if (!this.content || !this.content.document.fullscreenElement) {
           // If we receive any fullscreen change event, and find we are
           // actually not in fullscreen, also ask the parent to exit to
           // ensure that the parent always exits fullscreen when we do.
-          sendAsyncMessage("DOMFullscreen:Exit");
+          this.mm.sendAsyncMessage("DOMFullscreen:Exit");
         }
         break;
       }
       case "MozAfterPaint": {
         // Only send Painted signal after we actually finish painting
         // the transition for the fullscreen change.
         // Note that this._lastTransactionId is not set when in non-e10s
         // mode, so we need to check that explicitly.
         if (!this._lastTransactionId ||
             aEvent.transactionId > this._lastTransactionId) {
-          removeEventListener("MozAfterPaint", this);
-          sendAsyncMessage("DOMFullscreen:Painted");
+          this.mm.removeEventListener("MozAfterPaint", this);
+          this.mm.sendAsyncMessage("DOMFullscreen:Painted");
         }
         break;
       }
     }
   }
-};
-DOMFullscreenHandler.init();
-
-Services.obs.notifyObservers(this, "tab-content-frameloader-created");
-
-// Remove this once bug 1397365 is fixed.
-addEventListener("MozAfterPaint", function onFirstNonBlankPaint() {
-  if (content.document.documentURI == "about:blank" && !content.opener)
-    return;
-  removeEventListener("MozAfterPaint", onFirstNonBlankPaint);
-  sendAsyncMessage("Browser:FirstNonBlankPaint");
-});
-
-addMessageListener("DOM:WebManifest:hasManifestLink", ManifestMessages);
-addMessageListener("DOM:ManifestObtainer:Obtain", ManifestMessages);
-addMessageListener("DOM:Manifest:FireAppInstalledEvent", ManifestMessages);
-addMessageListener("DOM:WebManifest:fetchIcon", ManifestMessages);
+}
--- a/browser/actors/moz.build
+++ b/browser/actors/moz.build
@@ -18,15 +18,16 @@ with Files("PluginChild.jsm"):
 
 FINAL_TARGET_FILES.actors += [
     'AboutReaderChild.jsm',
     'BlockedSiteChild.jsm',
     'BrowserTabChild.jsm',
     'ClickHandlerChild.jsm',
     'ContentSearchChild.jsm',
     'ContextMenuChild.jsm',
+    'DOMFullscreenChild.jsm',
     'LightWeightThemeInstallChild.jsm',
     'NetErrorChild.jsm',
     'OfflineAppsChild.jsm',
     'PageInfoChild.jsm',
     'PageStyleChild.jsm',
     'PluginChild.jsm',
 ]
--- a/browser/base/content/tab-content.js
+++ b/browser/base/content/tab-content.js
@@ -118,102 +118,16 @@ var WebBrowserChrome = {
 };
 
 if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
   let tabchild = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                          .getInterface(Ci.nsITabChild);
   tabchild.webBrowserChrome = WebBrowserChrome;
 }
 
-
-var DOMFullscreenHandler = {
-
-  init() {
-    addMessageListener("DOMFullscreen:Entered", this);
-    addMessageListener("DOMFullscreen:CleanUp", this);
-    addEventListener("MozDOMFullscreen:Request", this);
-    addEventListener("MozDOMFullscreen:Entered", this);
-    addEventListener("MozDOMFullscreen:NewOrigin", this);
-    addEventListener("MozDOMFullscreen:Exit", this);
-    addEventListener("MozDOMFullscreen:Exited", this);
-    this.init = null;
-  },
-
-  receiveMessage(aMessage) {
-    let windowUtils = content && content.windowUtils;
-    switch (aMessage.name) {
-      case "DOMFullscreen:Entered": {
-        this._lastTransactionId = windowUtils.lastTransactionId;
-        if (!windowUtils.handleFullscreenRequests() &&
-            !content.document.fullscreenElement) {
-          // If we don't actually have any pending fullscreen request
-          // to handle, neither we have been in fullscreen, tell the
-          // parent to just exit.
-          sendAsyncMessage("DOMFullscreen:Exit");
-        }
-        break;
-      }
-      case "DOMFullscreen:CleanUp": {
-        // If we've exited fullscreen at this point, no need to record
-        // transaction id or call exit fullscreen. This is especially
-        // important for non-e10s, since in that case, it is possible
-        // that no more paint would be triggered after this point.
-        if (content.document.fullscreenElement && windowUtils) {
-          this._lastTransactionId = windowUtils.lastTransactionId;
-          windowUtils.exitFullscreen();
-        }
-        break;
-      }
-    }
-  },
-
-  handleEvent(aEvent) {
-    switch (aEvent.type) {
-      case "MozDOMFullscreen:Request": {
-        sendAsyncMessage("DOMFullscreen:Request");
-        break;
-      }
-      case "MozDOMFullscreen:NewOrigin": {
-        sendAsyncMessage("DOMFullscreen:NewOrigin", {
-          originNoSuffix: aEvent.target.nodePrincipal.originNoSuffix,
-        });
-        break;
-      }
-      case "MozDOMFullscreen:Exit": {
-        sendAsyncMessage("DOMFullscreen:Exit");
-        break;
-      }
-      case "MozDOMFullscreen:Entered":
-      case "MozDOMFullscreen:Exited": {
-        addEventListener("MozAfterPaint", this);
-        if (!content || !content.document.fullscreenElement) {
-          // If we receive any fullscreen change event, and find we are
-          // actually not in fullscreen, also ask the parent to exit to
-          // ensure that the parent always exits fullscreen when we do.
-          sendAsyncMessage("DOMFullscreen:Exit");
-        }
-        break;
-      }
-      case "MozAfterPaint": {
-        // Only send Painted signal after we actually finish painting
-        // the transition for the fullscreen change.
-        // Note that this._lastTransactionId is not set when in non-e10s
-        // mode, so we need to check that explicitly.
-        if (!this._lastTransactionId ||
-            aEvent.transactionId > this._lastTransactionId) {
-          removeEventListener("MozAfterPaint", this);
-          sendAsyncMessage("DOMFullscreen:Painted");
-        }
-        break;
-      }
-    }
-  }
-};
-DOMFullscreenHandler.init();
-
 Services.obs.notifyObservers(this, "tab-content-frameloader-created");
 
 // Remove this once bug 1397365 is fixed.
 addEventListener("MozAfterPaint", function onFirstNonBlankPaint() {
   if (content.document.documentURI == "about:blank" && !content.opener)
     return;
   removeEventListener("MozAfterPaint", onFirstNonBlankPaint);
   sendAsyncMessage("Browser:FirstNonBlankPaint");
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -97,16 +97,34 @@ let ACTORS = {
         "ContentSearchClient": {capture: true, wantUntrusted: true},
       },
       messages: [
         "ContentSearch",
       ]
     },
   },
 
+  DOMFullscreen: {
+    child: {
+      module: "resource:///actors/DOMFullscreenChild.jsm",
+      group: "browsers",
+      events: {
+        "MozDOMFullscreen:Request": {},
+        "MozDOMFullscreen:Entered": {},
+        "MozDOMFullscreen:NewOrigin": {},
+        "MozDOMFullscreen:Exit": {},
+        "MozDOMFullscreen:Exited": {},
+      },
+      messages: [
+        "DOMFullscreen:Entered",
+        "DOMFullscreen:CleanUp",
+      ]
+    },
+  },
+
   LightWeightThemeInstall: {
     child: {
       module: "resource:///actors/LightWeightThemeInstallChild.jsm",
       events: {
         "InstallBrowserTheme": {wantUntrusted: true},
         "PreviewBrowserTheme": {wantUntrusted: true},
         "ResetBrowserThemePreview": {wantUntrusted: true},
       },