From 30986431c775122c6f1b55f7f485bfcbb7f6a47c Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 29 Jul 2018 19:42:46 -0700 Subject: [PATCH] Bug 1472491: Part 5a - Add BrowserTabChild actor. r=felipe MozReview-Commit-ID: 38Y1xwkgxCx --HG-- extra : rebase_source : 61a85af58f9f16b8e39b716e3df2d09b788fcb1a --- browser/actors/BrowserTabChild.jsm | 112 ++++++++++++++++++ browser/actors/moz.build | 9 ++ browser/base/content/tab-content.js | 92 -------------- .../performance/browser_startup_content.js | 1 + browser/components/nsBrowserGlue.js | 23 ++++ browser/installer/package-manifest.in | 1 + browser/moz.build | 1 + python/mozbuild/mozpack/packager/formats.py | 1 + toolkit/content/browser-content.js | 16 --- 9 files changed, 148 insertions(+), 108 deletions(-) create mode 100644 browser/actors/BrowserTabChild.jsm create mode 100644 browser/actors/moz.build diff --git a/browser/actors/BrowserTabChild.jsm b/browser/actors/BrowserTabChild.jsm new file mode 100644 index 000000000000..61292b8c0871 --- /dev/null +++ b/browser/actors/BrowserTabChild.jsm @@ -0,0 +1,112 @@ +/* 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/. */ +"use strict"; + +var EXPORTED_SYMBOLS = ["BrowserTabChild"]; + +ChromeUtils.import("resource://gre/modules/ActorChild.jsm"); + +ChromeUtils.defineModuleGetter(this, "E10SUtils", + "resource://gre/modules/E10SUtils.jsm"); + +class BrowserTabChild extends ActorChild { + handleEvent(event) { + switch (event.type) { + case "DOMWindowCreated": + let loadContext = this.mm.docShell.QueryInterface(Ci.nsILoadContext); + let userContextId = loadContext.originAttributes.userContextId; + + this.mm.sendAsyncMessage("Browser:WindowCreated", { userContextId }); + break; + + case "MozAfterPaint": + this.mm.sendAsyncMessage("Browser:FirstPaint"); + break; + + case "MozDOMPointerLock:Entered": + this.mm.sendAsyncMessage("PointerLock:Entered", { + originNoSuffix: event.target.nodePrincipal.originNoSuffix + }); + break; + + case "MozDOMPointerLock:Exited": + this.mm.sendAsyncMessage("PointerLock:Exited"); + break; + } + } + + switchDocumentDirection(window = this.content) { + // document.dir can also be "auto", in which case it won't change + if (window.document.dir == "ltr" || window.document.dir == "") { + window.document.dir = "rtl"; + } else if (window.document.dir == "rtl") { + window.document.dir = "ltr"; + } + for (let i = 0; i < window.frames.length; i++) { + this.switchDocumentDirection(window.frames[i]); + } + } + + receiveMessage(message) { + switch (message.name) { + case "AllowScriptsToClose": + this.content.windowUtils.allowScriptsToClose(); + break; + + case "Browser:AppTab": + if (this.docShell) { + this.docShell.isAppTab = message.data.isAppTab; + } + break; + + case "Browser:HasSiblings": + try { + let tabChild = this.docShell.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsITabChild); + let hasSiblings = message.data; + tabChild.hasSiblings = hasSiblings; + } catch (e) { + } + break; + + // XXX(nika): Should we try to call this in the parent process instead? + case "Browser:Reload": + /* First, we'll try to use the session history object to reload so + * that framesets are handled properly. If we're in a special + * window (such as view-source) that has no session history, fall + * back on using the web navigation's reload method. + */ + + let webNav = this.docShell.QueryInterface(Ci.nsIWebNavigation); + try { + if (webNav.sessionHistory) { + webNav = webNav.sessionHistory; + } + } catch (e) { + } + + let reloadFlags = message.data.flags; + try { + E10SUtils.wrapHandlingUserInput(this.content, message.data.handlingUserInput, + () => webNav.reload(reloadFlags)); + } catch (e) { + } + break; + + case "MixedContent:ReenableProtection": + this.docShell.mixedContentChannel = null; + break; + + case "SwitchDocumentDirection": + this.switchDocumentDirection(); + break; + + case "UpdateCharacterSet": + this.docShell.charset = message.data.value; + this.docShell.gatherCharsetMenuTelemetry(); + break; + } + } +} diff --git a/browser/actors/moz.build b/browser/actors/moz.build new file mode 100644 index 000000000000..fa57eb00ddf6 --- /dev/null +++ b/browser/actors/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +FINAL_TARGET_FILES.actors += [ + 'BrowserTabChild.jsm', +] diff --git a/browser/base/content/tab-content.js b/browser/base/content/tab-content.js index a6556649306f..3272b89e20e1 100644 --- a/browser/base/content/tab-content.js +++ b/browser/base/content/tab-content.js @@ -28,18 +28,6 @@ ActorManagerChild.attach(this, "browsers"); // TabChildGlobal var global = this; - -addEventListener("MozDOMPointerLock:Entered", function(aEvent) { - sendAsyncMessage("PointerLock:Entered", { - originNoSuffix: aEvent.target.nodePrincipal.originNoSuffix - }); -}); - -addEventListener("MozDOMPointerLock:Exited", function(aEvent) { - sendAsyncMessage("PointerLock:Exited"); -}); - - addMessageListener("Browser:HideSessionRestoreButton", function(message) { // Hide session restore button on about:home let doc = content.document; @@ -50,43 +38,6 @@ addMessageListener("Browser:HideSessionRestoreButton", function(message) { } }); -if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) { - addMessageListener("Browser:HasSiblings", function(message) { - let tabChild = docShell.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsITabChild); - let hasSiblings = message.data; - tabChild.hasSiblings = hasSiblings; - }); -} - -// XXX(nika): Should we try to call this in the parent process instead? -addMessageListener("Browser:Reload", function(message) { - /* First, we'll try to use the session history object to reload so - * that framesets are handled properly. If we're in a special - * window (such as view-source) that has no session history, fall - * back on using the web navigation's reload method. - */ - - let webNav = docShell.QueryInterface(Ci.nsIWebNavigation); - try { - if (webNav.sessionHistory) { - webNav = webNav.sessionHistory; - } - } catch (e) { - } - - let reloadFlags = message.data.flags; - try { - E10SUtils.wrapHandlingUserInput(content, message.data.handlingUserInput, - () => webNav.reload(reloadFlags)); - } catch (e) { - } -}); - -addMessageListener("MixedContent:ReenableProtection", function() { - docShell.mixedContentChannel = null; -}); - XPCOMUtils.defineLazyProxy(this, "LightweightThemeChildHelper", "resource:///modules/LightweightThemeChildHelper.jsm"); @@ -353,12 +304,6 @@ addEventListener("unload", () => { Services.obs.removeObserver(gKeywordURIFixup, "keyword-uri-fixup"); }, false); -addMessageListener("Browser:AppTab", function(message) { - if (docShell) { - docShell.isAppTab = message.data.isAppTab; - } -}); - var WebBrowserChrome = { onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab) { return BrowserUtils.onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab); @@ -477,45 +422,8 @@ var DOMFullscreenHandler = { }; DOMFullscreenHandler.init(); -var UserContextIdNotifier = { - init() { - addEventListener("DOMWindowCreated", this); - this.init = null; - }, - - uninit() { - removeEventListener("DOMWindowCreated", this); - }, - - handleEvent(aEvent) { - // When the window is created, we want to inform the tabbrowser about - // the userContextId in use in order to update the UI correctly. - // Just because we cannot change the userContextId from an active docShell, - // we don't need to check DOMContentLoaded again. - this.uninit(); - - // We use the docShell because content.document can have been loaded before - // setting the originAttributes. - let loadContext = docShell.QueryInterface(Ci.nsILoadContext); - let userContextId = loadContext.originAttributes.userContextId; - - sendAsyncMessage("Browser:WindowCreated", { userContextId }); - } -}; - -UserContextIdNotifier.init(); - Services.obs.notifyObservers(this, "tab-content-frameloader-created"); -addMessageListener("AllowScriptsToClose", () => { - content.windowUtils.allowScriptsToClose(); -}); - -addEventListener("MozAfterPaint", function onFirstPaint() { - removeEventListener("MozAfterPaint", onFirstPaint); - sendAsyncMessage("Browser:FirstPaint"); -}); - // Remove this once bug 1397365 is fixed. addEventListener("MozAfterPaint", function onFirstNonBlankPaint() { if (content.document.documentURI == "about:blank" && !content.opener) diff --git a/browser/base/content/test/performance/browser_startup_content.js b/browser/base/content/test/performance/browser_startup_content.js index 576c41b7572e..837b8f0cd5d2 100644 --- a/browser/base/content/test/performance/browser_startup_content.js +++ b/browser/base/content/test/performance/browser_startup_content.js @@ -48,6 +48,7 @@ const whitelist = { "resource://formautofill/FormAutofillContent.jsm", // Browser front-end + "resource:///actors/BrowserTabChild.jsm", "resource:///modules/ContentLinkHandler.jsm", "resource:///modules/ContentMetaHandler.jsm", "resource:///modules/PageStyleHandler.jsm", diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 1670cc3d75bf..c0f7bb22542d 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -12,6 +12,29 @@ ChromeUtils.defineModuleGetter(this, "ActorManagerParent", "resource://gre/modules/ActorManagerParent.jsm"); let ACTORS = { + BrowserTab: { + child: { + module: "resource:///actors/BrowserTabChild.jsm", + group: "browsers", + + events: { + "DOMWindowCreated": {once: true}, + "MozAfterPaint": {once: true}, + "MozDOMPointerLock:Entered": {}, + "MozDOMPointerLock:Exited": {}, + }, + + messages: [ + "AllowScriptsToClose", + "Browser:AppTab", + "Browser:HasSiblings", + "Browser:Reload", + "MixedContent:ReenableProtection", + "SwitchDocumentDirection", + "UpdateCharacterSet", + ], + }, + }, }; (function earlyBlankFirstPaint() { diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index 6818e0c9b417..ba9b41eaf6cc 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -381,6 +381,7 @@ ; Modules @RESPATH@/browser/modules/* @RESPATH@/modules/* +@RESPATH@/browser/actors/* ; Safe Browsing @RESPATH@/components/nsURLClassifier.manifest diff --git a/browser/moz.build b/browser/moz.build index d2818b71b88f..15e11f45ff4a 100644 --- a/browser/moz.build +++ b/browser/moz.build @@ -12,6 +12,7 @@ with Files('docs/**'): SCHEDULES.exclusive = ['docs'] DIRS += [ + 'actors', 'base', 'components', 'fonts', diff --git a/python/mozbuild/mozpack/packager/formats.py b/python/mozbuild/mozpack/packager/formats.py index 95bcda0681fd..1cf30c694051 100644 --- a/python/mozbuild/mozpack/packager/formats.py +++ b/python/mozbuild/mozpack/packager/formats.py @@ -336,6 +336,7 @@ class OmniJarSubFormatter(PiecemealFormatter): path[1] in ['pref', 'preferences']) return path[0] in [ 'modules', + 'actors', 'dictionaries', 'greprefs.js', 'hyphenation', diff --git a/toolkit/content/browser-content.js b/toolkit/content/browser-content.js index 0deba22f81e3..a8f0891a4f6d 100644 --- a/toolkit/content/browser-content.js +++ b/toolkit/content/browser-content.js @@ -121,22 +121,6 @@ var Printing = { }; Printing.init(); -function SwitchDocumentDirection(aWindow) { - // document.dir can also be "auto", in which case it won't change - if (aWindow.document.dir == "ltr" || aWindow.document.dir == "") { - aWindow.document.dir = "rtl"; - } else if (aWindow.document.dir == "rtl") { - aWindow.document.dir = "ltr"; - } - for (let run = 0; run < aWindow.frames.length; run++) { - SwitchDocumentDirection(aWindow.frames[run]); - } -} - -addMessageListener("SwitchDocumentDirection", () => { - SwitchDocumentDirection(content.window); -}); - var FindBar = { /** * _findKey and _findModifiers are used to determine whether a keypress