From 3a10644021c6009b7023aae5f8fd24d8a9bcb4f8 Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Thu, 1 Mar 2018 11:51:09 +0200 Subject: [PATCH] Backed out 6 changesets (bug 888600) for beta simulation failures: build bustage on Linux and Windows opt (bug 1442036) and devtools failure browser_net_view-source-debugger.js (bug 1441961). a=backout Backed out changeset 83c87140dc3d (bug 888600) Backed out changeset 2efb9b1753f6 (bug 888600) Backed out changeset af5303781961 (bug 888600) Backed out changeset 79ef59047e63 (bug 888600) Backed out changeset 30d568d628dd (bug 888600) Backed out changeset c7bd4c6c9741 (bug 888600) --HG-- extra : histedit_source : 791b22f6770f4fead2f909478a93d65d85829fe0%2Cbb387309e90f53e1dde45dcf8cf4ebedcc6e5c5e --- .../content/test/general/contentSearchUI.js | 3 +- ...er_devices_get_user_media_multi_process.js | 15 +- .../browser/browser_ext_tabs_executeScript.js | 6 + browser/components/nsBrowserGlue.js | 5 +- browser/components/sessionstore/test/head.js | 7 +- .../pdfjs/content/PdfjsChromeUtils.jsm | 6 +- .../pdfjs/content/PdfjsContentUtils.jsm | 3 +- browser/extensions/pocket/bootstrap.js | 4 +- browser/modules/AboutHome.jsm | 3 +- browser/modules/ContentCrashHandlers.jsm | 8 +- browser/modules/ContentSearch.jsm | 4 +- devtools/client/jsonview/converter-child.js | 7 +- .../test/browser_net_view-source-debugger.js | 2 +- .../browser_wa_properties-view-media-nodes.js | 6 +- devtools/server/actors/process.js | 5 +- devtools/server/actors/root.js | 8 +- devtools/server/actors/storage.js | 12 +- .../webconsole/content-process-forward.js | 10 +- devtools/server/content-server.jsm | 1 + .../server/tests/mochitest/setup-in-child.js | 5 +- .../mochitest/test_setupInParentChild.html | 6 +- docshell/base/nsDocShell.cpp | 5 +- dom/base/ChildProcessMessageManager.h | 42 - dom/base/ChromeMessageBroadcaster.cpp | 47 - dom/base/ChromeMessageBroadcaster.h | 95 -- dom/base/ChromeMessageSender.cpp | 41 - dom/base/ChromeMessageSender.h | 60 -- dom/base/ContentFrameMessageManager.h | 95 -- dom/base/DOMMatrix.cpp | 2 - dom/base/DOMRequestHelper.jsm | 17 +- dom/base/MessageListenerManager.cpp | 55 -- dom/base/MessageListenerManager.h | 53 -- dom/base/MessageManagerGlobal.h | 181 ---- dom/base/MessageSender.cpp | 33 - dom/base/MessageSender.h | 31 - dom/base/ProcessGlobal.cpp | 63 +- dom/base/ProcessGlobal.h | 58 +- dom/base/SyncMessageSender.h | 27 - dom/base/TextInputProcessor.cpp | 1 - dom/base/TimeoutExecutor.cpp | 1 - dom/base/TimeoutManager.h | 1 - dom/base/moz.build | 12 - dom/base/nsCCUncollectableMarker.cpp | 10 +- dom/base/nsContentIterator.cpp | 1 - dom/base/nsDOMClassInfo.cpp | 88 ++ dom/base/nsDOMClassInfo.h | 25 + dom/base/nsDOMClassInfoID.h | 5 + dom/base/nsFrameLoader.cpp | 25 +- dom/base/nsFrameLoader.h | 9 +- dom/base/nsFrameMessageManager.cpp | 819 ++++++++---------- dom/base/nsFrameMessageManager.h | 213 ++--- dom/base/nsGlobalWindowInner.cpp | 20 +- dom/base/nsGlobalWindowInner.h | 19 +- dom/base/nsGlobalWindowOuter.h | 2 +- dom/base/nsIMessageManager.idl | 20 +- dom/base/nsInProcessTabChildGlobal.cpp | 71 +- dom/base/nsInProcessTabChildGlobal.h | 79 +- dom/base/nsJSUtils.cpp | 1 - dom/base/nsWrapperCache.h | 4 + ...rowser_messagemanager_loadprocessscript.js | 38 +- dom/base/test/chrome/file_bug1139964.xul | 3 +- dom/base/test/chrome/file_bug549682.xul | 9 +- dom/base/test/chrome/file_bug990812-1.xul | 3 +- dom/base/test/chrome/file_bug990812-2.xul | 3 +- dom/base/test/chrome/file_bug990812-3.xul | 3 +- dom/base/test/chrome/file_bug990812-4.xul | 3 +- dom/base/test/chrome/file_bug990812-5.xul | 3 +- dom/base/test/chrome/file_bug990812.xul | 3 +- ...t_bug1098074_throw_from_ReceiveMessage.xul | 3 +- dom/base/test/test_domrequesthelper.xul | 3 +- dom/bindings/BindingUtils.cpp | 18 +- dom/bindings/BindingUtils.h | 35 +- dom/bindings/Bindings.conf | 25 +- dom/bindings/Codegen.py | 190 +--- dom/bindings/ToJSValue.h | 59 +- dom/bindings/WebIDLGlobalNameHash.cpp | 6 +- dom/bindings/WebIDLGlobalNameHash.h | 4 +- .../tests/test_ipc_messagemanager_blob.html | 8 +- dom/indexedDB/test/head.js | 5 +- .../test/test_message_manager_ipc.html | 18 +- dom/interfaces/base/nsIContentProcess.idl | 3 +- dom/interfaces/base/nsITabChild.idl | 3 +- dom/ipc/ContentBridgeParent.cpp | 1 - dom/ipc/ContentChild.cpp | 1 - dom/ipc/ContentParent.cpp | 2 +- dom/ipc/TabChild.cpp | 160 ++-- dom/ipc/TabChild.h | 86 +- dom/ipc/TabParent.cpp | 1 - dom/ipc/nsIContentChild.cpp | 1 - dom/ipc/nsIContentParent.cpp | 2 +- dom/ipc/nsIContentParent.h | 5 +- dom/ipc/remote-test.js | 3 +- dom/ipc/test.xul | 6 +- .../test_blob_sliced_from_child_process.html | 18 +- .../test_blob_sliced_from_parent_process.html | 8 +- dom/ipc/tests/test_bug1086684.html | 3 +- dom/ipc/tests/test_cpow_cookies.html | 3 +- dom/media/PeerConnection.js | 5 +- dom/notification/NotificationDB.jsm | 8 +- dom/notification/NotificationStorage.js | 14 +- .../test/unit/common_test_notificationdb.js | 10 +- .../test/unit/test_notificationdb.js | 22 +- .../test_presentation_dc_receiver_oop.html | 4 +- dom/push/PushComponents.js | 9 +- dom/quota/test/head.js | 5 +- dom/webidl/FrameLoader.webidl | 3 +- dom/webidl/LegacyQueryInterface.webidl | 5 - dom/webidl/MessageManager.webidl | 378 -------- dom/webidl/Window.webidl | 5 +- dom/webidl/moz.build | 1 - js/xpconnect/src/nsXPConnect.cpp | 5 - .../extensions/tps/resource/modules/tabs.jsm | 4 +- testing/marionette/driver.js | 3 +- testing/marionette/proxy.js | 7 +- .../BrowserTestUtils/BrowserTestUtils.jsm | 4 +- testing/mochitest/ShutdownLeaksCollector.jsm | 8 +- testing/mochitest/browser-test.js | 7 +- .../content/SpecialPowersObserver.jsm | 3 +- testing/xpcshell/head.js | 8 +- .../addoncompat/RemoteAddonsChild.jsm | 23 +- .../addoncompat/RemoteAddonsParent.jsm | 33 +- .../contentprefs/ContentPrefServiceParent.jsm | 6 +- .../mochitest/test_remoteContentPrefs.html | 23 +- .../passwordmgr/test/pwmgr_common.js | 3 +- .../components/satchel/FormHistoryStartup.js | 9 +- .../components/telemetry/TelemetrySession.jsm | 20 +- toolkit/modules/Services.jsm | 14 +- toolkit/modules/WebChannel.jsm | 2 +- .../extensions/ChromeManifestParser.jsm | 3 +- .../extensions/internal/GMPProvider.jsm | 7 +- .../test/mochitest/test_bug687194.html | 4 +- .../lib/rules/use-services.js | 5 +- tools/quitter/QuitterObserver.js | 6 +- tools/quitter/install.rdf | 6 +- tools/quitter/quitter@mozilla.org.xpi | Bin 2658 -> 6903 bytes xpcom/ds/nsClassHashtable.h | 19 - xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp | 4 - 137 files changed, 1264 insertions(+), 2646 deletions(-) delete mode 100644 dom/base/ChildProcessMessageManager.h delete mode 100644 dom/base/ChromeMessageBroadcaster.cpp delete mode 100644 dom/base/ChromeMessageBroadcaster.h delete mode 100644 dom/base/ChromeMessageSender.cpp delete mode 100644 dom/base/ChromeMessageSender.h delete mode 100644 dom/base/ContentFrameMessageManager.h delete mode 100644 dom/base/MessageListenerManager.cpp delete mode 100644 dom/base/MessageListenerManager.h delete mode 100644 dom/base/MessageManagerGlobal.h delete mode 100644 dom/base/MessageSender.cpp delete mode 100644 dom/base/MessageSender.h delete mode 100644 dom/base/SyncMessageSender.h delete mode 100644 dom/webidl/MessageManager.webidl diff --git a/browser/base/content/test/general/contentSearchUI.js b/browser/base/content/test/general/contentSearchUI.js index 5cbef68582479..b4a0f96204d08 100644 --- a/browser/base/content/test/general/contentSearchUI.js +++ b/browser/base/content/test/general/contentSearchUI.js @@ -168,7 +168,8 @@ function waitForSuggestions(cb) { } function waitForContentSearchEvent(messageType, cb) { - let mm = content.SpecialPowers.Cc["@mozilla.org/globalmessagemanager;1"].getService(); + let mm = content.SpecialPowers.Cc["@mozilla.org/globalmessagemanager;1"]. + getService(content.SpecialPowers.Ci.nsIMessageListenerManager); mm.addMessageListener("ContentSearch", function listener(aMsg) { if (aMsg.data.type != messageType) { return; diff --git a/browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.js index 4125c099b8b39..935940ae84d24 100644 --- a/browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.js +++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.js @@ -42,7 +42,10 @@ var gTests = [ // If we have reached the max process count already, increase it to ensure // our new tab can have its own content process. - let childCount = Services.ppmm.childCount; + var ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIMessageBroadcaster); + ppmm.QueryInterface(Ci.nsIProcessScriptLoader); + let childCount = ppmm.childCount; let maxContentProcess = Services.prefs.getIntPref("dom.ipc.processCount"); // The first check is because if we are on a branch where e10s-multi is // disabled, we want to keep testing e10s with a single content process. @@ -143,7 +146,10 @@ var gTests = [ // If we have reached the max process count already, increase it to ensure // our new tab can have its own content process. - let childCount = Services.ppmm.childCount; + var ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIMessageBroadcaster); + ppmm.QueryInterface(Ci.nsIProcessScriptLoader); + let childCount = ppmm.childCount; let maxContentProcess = Services.prefs.getIntPref("dom.ipc.processCount"); // The first check is because if we are on a branch where e10s-multi is // disabled, we want to keep testing e10s with a single content process. @@ -249,7 +255,10 @@ var gTests = [ // If we have reached the max process count already, increase it to ensure // our new tab can have its own content process. - let childCount = Services.ppmm.childCount; + var ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIMessageBroadcaster); + ppmm.QueryInterface(Ci.nsIProcessScriptLoader); + let childCount = ppmm.childCount; let maxContentProcess = Services.prefs.getIntPref("dom.ipc.processCount"); // The first check is because if we are on a branch where e10s-multi is // disabled, we want to keep testing e10s with a single content process. diff --git a/browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js b/browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js index a1794a9cba9f3..a5937a9fadd27 100644 --- a/browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js +++ b/browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js @@ -19,6 +19,12 @@ add_task(async function testExecuteScript() { Services.ppmm.getChildAt(0), ]; for (let mm of messageManagerMap.keys()) { + // Sanity check: mm is a message manager. + try { + mm.QueryInterface(Ci.nsIMessageSender); + } catch (e) { + mm.QueryInterface(Ci.nsIMessageBroadcaster); + } if (!globalMMs.includes(mm)) { ++count; } diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 08b1a9562a15f..a11003dab7094 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -3188,13 +3188,14 @@ this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components); // Listen for UITour messages. // Do it here instead of the UITour module itself so that the UITour module is lazy loaded // when the first message is received. -Services.mm.addMessageListener("UITour:onPageEvent", function(aMessage) { +var globalMM = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager); +globalMM.addMessageListener("UITour:onPageEvent", function(aMessage) { UITour.onPageEvent(aMessage, aMessage.data); }); // Listen for HybridContentTelemetry messages. // Do it here instead of HybridContentTelemetry.init() so that // the module can be lazily loaded on the first message. -Services.mm.addMessageListener("HybridContentTelemetry:onTelemetryMessage", aMessage => { +globalMM.addMessageListener("HybridContentTelemetry:onTelemetryMessage", aMessage => { HybridContentTelemetry.onTelemetryMessage(aMessage, aMessage.data); }); diff --git a/browser/components/sessionstore/test/head.js b/browser/components/sessionstore/test/head.js index a1518a4fe7304..ab52551402403 100644 --- a/browser/components/sessionstore/test/head.js +++ b/browser/components/sessionstore/test/head.js @@ -15,13 +15,16 @@ const FRAME_SCRIPTS = [ ROOT + "content-forms.js" ]; +var globalMM = Cc["@mozilla.org/globalmessagemanager;1"] + .getService(Ci.nsIMessageListenerManager); + for (let script of FRAME_SCRIPTS) { - Services.mm.loadFrameScript(script, true); + globalMM.loadFrameScript(script, true); } registerCleanupFunction(() => { for (let script of FRAME_SCRIPTS) { - Services.mm.removeDelayedFrameScript(script, true); + globalMM.removeDelayedFrameScript(script, true); } }); diff --git a/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm b/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm index fcc82d2f130ed..264a9031b0dba 100644 --- a/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm +++ b/browser/extensions/pdfjs/content/PdfjsChromeUtils.jsm @@ -68,7 +68,8 @@ var PdfjsChromeUtils = { this._browsers = new WeakSet(); if (!this._ppmm) { // global parent process message manager (PPMM) - this._ppmm = Services.ppmm; + this._ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]. + getService(Ci.nsIMessageBroadcaster); this._ppmm.addMessageListener("PDFJS:Parent:clearUserPref", this); this._ppmm.addMessageListener("PDFJS:Parent:setIntPref", this); this._ppmm.addMessageListener("PDFJS:Parent:setBoolPref", this); @@ -77,7 +78,8 @@ var PdfjsChromeUtils = { this._ppmm.addMessageListener("PDFJS:Parent:isDefaultHandlerApp", this); // global dom message manager (MMg) - this._mmg = Services.mm; + this._mmg = Cc["@mozilla.org/globalmessagemanager;1"]. + getService(Ci.nsIMessageListenerManager); this._mmg.addMessageListener("PDFJS:Parent:displayWarning", this); this._mmg.addMessageListener("PDFJS:Parent:addEventListener", this); diff --git a/browser/extensions/pdfjs/content/PdfjsContentUtils.jsm b/browser/extensions/pdfjs/content/PdfjsContentUtils.jsm index 3fcd584f643ba..71c797fd22890 100644 --- a/browser/extensions/pdfjs/content/PdfjsContentUtils.jsm +++ b/browser/extensions/pdfjs/content/PdfjsContentUtils.jsm @@ -35,7 +35,8 @@ var PdfjsContentUtils = { // child *process* mm, or when loaded into the parent for in-content // support the psuedo child process mm 'child PPMM'. if (!this._mm) { - this._mm = Services.cpmm; + this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"]. + getService(Ci.nsISyncMessageSender); this._mm.addMessageListener("PDFJS:Child:updateSettings", this); Services.obs.addObserver(this, "quit-application"); diff --git a/browser/extensions/pocket/bootstrap.js b/browser/extensions/pocket/bootstrap.js index 003552fd3c985..a015039c4a341 100644 --- a/browser/extensions/pocket/bootstrap.js +++ b/browser/extensions/pocket/bootstrap.js @@ -408,7 +408,9 @@ var PocketOverlay = { } }, shutdown(reason) { - Services.ppmm.broadcastAsyncMessage("PocketShuttingDown"); + let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIMessageBroadcaster); + ppmm.broadcastAsyncMessage("PocketShuttingDown"); Services.obs.removeObserver(this, "browser-delayed-startup-finished"); // Although the ppmm loads the scripts into the chrome process as well, // we need to manually unregister here anyway to ensure these aren't part diff --git a/browser/modules/AboutHome.jsm b/browser/modules/AboutHome.jsm index 589155907e075..51266de9ebdb0 100644 --- a/browser/modules/AboutHome.jsm +++ b/browser/modules/AboutHome.jsm @@ -178,7 +178,8 @@ var AboutHome = { if (target && target.messageManager) { target.messageManager.sendAsyncMessage("AboutHome:Update", data); } else { - Services.mm.broadcastAsyncMessage("AboutHome:Update", data); + let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager); + mm.broadcastAsyncMessage("AboutHome:Update", data); } }).catch(function onError(x) { Cu.reportError("Error in AboutHome.sendAboutHomeData: " + x); diff --git a/browser/modules/ContentCrashHandlers.jsm b/browser/modules/ContentCrashHandlers.jsm index f8d4afab8bba5..152405367757b 100644 --- a/browser/modules/ContentCrashHandlers.jsm +++ b/browser/modules/ContentCrashHandlers.jsm @@ -995,10 +995,12 @@ var PluginCrashReporter = { // Only the parent process gets the gmp-plugin-crash observer // notification, so we need to inform any content processes that // the GMP has crashed. - if (Services.ppmm) { + if (Cc["@mozilla.org/parentprocessmessagemanager;1"]) { let pluginName = propertyBag.getPropertyAsAString("pluginName"); - Services.ppmm.broadcastAsyncMessage("gmp-plugin-crash", - { pluginName, pluginID }); + let mm = Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIMessageListenerManager); + mm.broadcastAsyncMessage("gmp-plugin-crash", + { pluginName, pluginID }); } break; } diff --git a/browser/modules/ContentSearch.jsm b/browser/modules/ContentSearch.jsm index 18cbcc9fe7533..4e20714eba227 100644 --- a/browser/modules/ContentSearch.jsm +++ b/browser/modules/ContentSearch.jsm @@ -489,7 +489,9 @@ var ContentSearch = { }, _broadcast(type, data) { - Services.mm.broadcastAsyncMessage(...this._msgArgs(type, data)); + Cc["@mozilla.org/globalmessagemanager;1"]. + getService(Ci.nsIMessageListenerManager). + broadcastAsyncMessage(...this._msgArgs(type, data)); }, _msgArgs(type, data) { diff --git a/devtools/client/jsonview/converter-child.js b/devtools/client/jsonview/converter-child.js index f757e5f240e88..b609eb48783e5 100644 --- a/devtools/client/jsonview/converter-child.js +++ b/devtools/client/jsonview/converter-child.js @@ -6,7 +6,7 @@ "use strict"; -const {Ci, Cu, CC} = require("chrome"); +const {Cc, Ci, Cu, CC} = require("chrome"); const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); const Services = require("Services"); @@ -17,6 +17,9 @@ loader.lazyGetter(this, "debug", function () { return !!(AppConstants.DEBUG || AppConstants.DEBUG_JS_MODULES); }); +const childProcessMessageManager = + Cc["@mozilla.org/childprocessmessagemanager;1"] + .getService(Ci.nsISyncMessageSender); const BinaryInput = CC("@mozilla.org/binaryinputstream;1", "nsIBinaryInputStream", "setInputStream"); const BufferStream = CC("@mozilla.org/io/arraybuffer-input-stream;1", @@ -301,7 +304,7 @@ function onContentMessage(e) { let value = e.detail.value; switch (e.detail.type) { case "save": - Services.cpmm.sendAsyncMessage( + childProcessMessageManager.sendAsyncMessage( "devtools:jsonview:save", value); } } diff --git a/devtools/client/netmonitor/test/browser_net_view-source-debugger.js b/devtools/client/netmonitor/test/browser_net_view-source-debugger.js index 1391f39b1ae95..973f65c24e2f2 100644 --- a/devtools/client/netmonitor/test/browser_net_view-source-debugger.js +++ b/devtools/client/netmonitor/test/browser_net_view-source-debugger.js @@ -23,7 +23,7 @@ add_task(async function () { await waitForContentRequests; info("Clicking stack-trace tab and waiting for stack-trace panel to open"); - let wait = waitForDOM(document, "#stack-trace-panel .frame-link", 5); + let wait = waitForDOM(document, "#stack-trace-panel .frame-link", 4); // Click on the first request EventUtils.sendMouseEvent({ type: "mousedown" }, document.querySelector(".request-list-item")); diff --git a/devtools/client/webaudioeditor/test/browser_wa_properties-view-media-nodes.js b/devtools/client/webaudioeditor/test/browser_wa_properties-view-media-nodes.js index 7d48a4d584d16..2a4e09274cf5d 100644 --- a/devtools/client/webaudioeditor/test/browser_wa_properties-view-media-nodes.js +++ b/devtools/client/webaudioeditor/test/browser_wa_properties-view-media-nodes.js @@ -20,10 +20,12 @@ function waitForDeviceClosed() { return new Promise((resolve, reject) => { const message = "webrtc:UpdateGlobalIndicators"; - Services.ppmm.addMessageListener(message, function listener(aMessage) { + let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIMessageBroadcaster); + ppmm.addMessageListener(message, function listener(aMessage) { info("Received " + message + " message"); if (!aMessage.data.showGlobalIndicator) { - Services.ppmm.removeMessageListener(message, listener); + ppmm.removeMessageListener(message, listener); resolve(); } }); diff --git a/devtools/server/actors/process.js b/devtools/server/actors/process.js index fed94934ba01a..e8eff08aa16bb 100644 --- a/devtools/server/actors/process.js +++ b/devtools/server/actors/process.js @@ -4,10 +4,11 @@ "use strict"; -var { Cc } = require("chrome"); +var { Cc, Ci } = require("chrome"); loader.lazyGetter(this, "ppmm", () => { - return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(); + return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService( + Ci.nsIMessageBroadcaster); }); function ProcessActorList() { diff --git a/devtools/server/actors/root.js b/devtools/server/actors/root.js index 939592e651305..ccef4e9047179 100644 --- a/devtools/server/actors/root.js +++ b/devtools/server/actors/root.js @@ -6,11 +6,15 @@ "use strict"; -const { Cu } = require("chrome"); +const { Cc, Ci, Cu } = require("chrome"); const Services = require("Services"); const { ActorPool, appendExtraActors, createExtraActors } = require("devtools/server/actors/common"); const { DebuggerServer } = require("devtools/server/main"); +loader.lazyGetter(this, "ppmm", () => { + return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService( + Ci.nsIMessageBroadcaster); +}); loader.lazyRequireGetter(this, "WindowActor", "devtools/server/actors/window", true); @@ -543,7 +547,7 @@ RootActor.prototype = { } let { id } = request; - let mm = Services.ppmm.getChildAt(id); + let mm = ppmm.getChildAt(id); if (!mm) { return { error: "noProcess", message: "There is no process with id '" + id + "'." }; diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js index 36a4a612a588e..ea99d7ed5e3ce 100644 --- a/devtools/server/actors/storage.js +++ b/devtools/server/actors/storage.js @@ -4,7 +4,7 @@ "use strict"; -const {Ci, Cu, CC} = require("chrome"); +const {Cc, Ci, Cu, CC} = require("chrome"); const protocol = require("devtools/shared/protocol"); const {LongStringActor} = require("devtools/server/actors/string"); const {DebuggerServer} = require("devtools/server/main"); @@ -1938,14 +1938,20 @@ StorageActors.createActor({ var indexedDBHelpers = { backToChild(...args) { - Services.mm.broadcastAsyncMessage("debug:storage-indexedDB-request-child", { + let mm = Cc["@mozilla.org/globalmessagemanager;1"] + .getService(Ci.nsIMessageListenerManager); + + mm.broadcastAsyncMessage("debug:storage-indexedDB-request-child", { method: "backToChild", args: args }); }, onItemUpdated(action, host, path) { - Services.mm.broadcastAsyncMessage("debug:storage-indexedDB-request-child", { + let mm = Cc["@mozilla.org/globalmessagemanager;1"] + .getService(Ci.nsIMessageListenerManager); + + mm.broadcastAsyncMessage("debug:storage-indexedDB-request-child", { method: "onItemUpdated", args: [ action, host, path ] }); diff --git a/devtools/server/actors/webconsole/content-process-forward.js b/devtools/server/actors/webconsole/content-process-forward.js index 157d25114306c..340a5d7c11e1a 100644 --- a/devtools/server/actors/webconsole/content-process-forward.js +++ b/devtools/server/actors/webconsole/content-process-forward.js @@ -7,6 +7,9 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm", {}); const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {}); +XPCOMUtils.defineLazyServiceGetter(this, "cpmm", + "@mozilla.org/childprocessmessagemanager;1", + "nsIMessageSender"); ChromeUtils.defineModuleGetter(this, "E10SUtils", "resource://gre/modules/E10SUtils.jsm"); @@ -34,7 +37,7 @@ const MSG_MGR_CONSOLE_INFO_MAX = 1024; function ContentProcessForward() { Services.obs.addObserver(this, "console-api-log-event"); Services.obs.addObserver(this, "xpcom-shutdown"); - Services.cpmm.addMessageListener("DevTools:StopForwardingContentProcessMessage", this); + cpmm.addMessageListener("DevTools:StopForwardingContentProcessMessage", this); } ContentProcessForward.prototype = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, @@ -105,7 +108,7 @@ ContentProcessForward.prototype = { } } - Services.cpmm.sendAsyncMessage("Console:Log", msgData); + cpmm.sendAsyncMessage("Console:Log", msgData); break; } @@ -118,8 +121,7 @@ ContentProcessForward.prototype = { uninit() { Services.obs.removeObserver(this, "console-api-log-event"); Services.obs.removeObserver(this, "xpcom-shutdown"); - Services.cpmm.removeMessageListener("DevTools:StopForwardingContentProcessMessage", - this); + cpmm.removeMessageListener("DevTools:StopForwardingContentProcessMessage", this); } }; diff --git a/devtools/server/content-server.jsm b/devtools/server/content-server.jsm index 813e869d98774..a006a251a56f3 100644 --- a/devtools/server/content-server.jsm +++ b/devtools/server/content-server.jsm @@ -49,6 +49,7 @@ function setupServer(mm) { function init(msg) { let mm = msg.target; + mm.QueryInterface(Ci.nsISyncMessageSender); let prefix = msg.data.prefix; // Using the JS debugger causes problems when we're trying to diff --git a/devtools/server/tests/mochitest/setup-in-child.js b/devtools/server/tests/mochitest/setup-in-child.js index 494d94b63c0c4..b5614ab1e19ca 100644 --- a/devtools/server/tests/mochitest/setup-in-child.js +++ b/devtools/server/tests/mochitest/setup-in-child.js @@ -1,7 +1,8 @@ "use strict"; -const {Cc} = require("chrome"); -const cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(); +const {Cc, Ci} = require("chrome"); +const cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"] + .getService(Ci.nsIMessageListenerManager); const { DebuggerServer } = require("devtools/server/main"); exports.setupChild = function (a, b, c) { diff --git a/devtools/server/tests/mochitest/test_setupInParentChild.html b/devtools/server/tests/mochitest/test_setupInParentChild.html index 01298b22d4a01..42f6465ccdde7 100644 --- a/devtools/server/tests/mochitest/test_setupInParentChild.html +++ b/devtools/server/tests/mochitest/test_setupInParentChild.html @@ -49,8 +49,10 @@ let client = new DebuggerClient(transport); // Wait for a response from setupInChild + const ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"] + .getService(Ci.nsIMessageListenerManager); let onChild = msg => { - Services.ppmm.removeMessageListener("test:setupChild", onChild); + ppmm.removeMessageListener("test:setupChild", onChild); let args = msg.json; is(args[0], 1, "Got first numeric argument"); @@ -63,7 +65,7 @@ setupChild: "callParent" }); }; - Services.ppmm.addMessageListener("test:setupChild", onChild); + ppmm.addMessageListener("test:setupChild", onChild); // Wait also for a reponse from setupInParent called from setup-in-child.js let onParent = (_, topic, args) => { diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index fd0bbd5fcae0f..27dffe68cee57 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -649,10 +649,11 @@ nsDocShell::GetInterface(const nsIID& aIID, void** aSink) *aSink = GetTabChild().take(); return *aSink ? NS_OK : NS_ERROR_FAILURE; } else if (aIID.Equals(NS_GET_IID(nsIContentFrameMessageManager))) { - RefPtr tabChild = TabChild::GetFrom(this); + nsCOMPtr tabChild = + do_GetInterface(static_cast(this)); nsCOMPtr mm; if (tabChild) { - mm = tabChild->GetMessageManager(); + tabChild->GetMessageManager(getter_AddRefs(mm)); } else { if (nsPIDOMWindowOuter* win = GetWindow()) { mm = do_QueryInterface(win->GetParentTarget()); diff --git a/dom/base/ChildProcessMessageManager.h b/dom/base/ChildProcessMessageManager.h deleted file mode 100644 index a280f95aed3dc..0000000000000 --- a/dom/base/ChildProcessMessageManager.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#ifndef mozilla_dom_ChildProcessMessageManager_h -#define mozilla_dom_ChildProcessMessageManager_h - -#include "mozilla/dom/SyncMessageSender.h" -#include "mozilla/dom/MessageManagerBinding.h" - -namespace mozilla { -namespace dom { - -class ChildProcessMessageManager final : public SyncMessageSender -{ -public: - explicit ChildProcessMessageManager(ipc::MessageManagerCallback* aCallback) - : SyncMessageSender(aCallback, - MessageManagerFlags::MM_PROCESSMANAGER | - MessageManagerFlags::MM_OWNSCALLBACK) - { - mozilla::HoldJSObjects(this); - } - - virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override - { - return ChildProcessMessageManagerBinding::Wrap(aCx, this, aGivenProto); - } - -protected: - virtual ~ChildProcessMessageManager() - { - mozilla::DropJSObjects(this); - } -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_ChildProcessMessageManager_h diff --git a/dom/base/ChromeMessageBroadcaster.cpp b/dom/base/ChromeMessageBroadcaster.cpp deleted file mode 100644 index 677f8a793126a..0000000000000 --- a/dom/base/ChromeMessageBroadcaster.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#include "mozilla/dom/ChromeMessageBroadcaster.h" -#include "AccessCheck.h" -#include "mozilla/HoldDropJSObjects.h" -#include "mozilla/dom/MessageManagerBinding.h" - -namespace mozilla { -namespace dom { - -ChromeMessageBroadcaster::ChromeMessageBroadcaster(nsFrameMessageManager* aParentManager, - MessageManagerFlags aFlags) - : MessageListenerManager(nullptr, aParentManager, - aFlags | - MessageManagerFlags::MM_BROADCASTER | - MessageManagerFlags::MM_CHROME) -{ - if (mIsProcessManager) { - mozilla::HoldJSObjects(this); - } - if (aParentManager) { - aParentManager->AddChildManager(this); - } -} - -ChromeMessageBroadcaster::~ChromeMessageBroadcaster() -{ - if (mIsProcessManager) { - mozilla::DropJSObjects(this); - } -} - -JSObject* -ChromeMessageBroadcaster::WrapObject(JSContext* aCx, - JS::Handle aGivenProto) -{ - MOZ_ASSERT(nsContentUtils::IsSystemCaller(aCx)); - - return ChromeMessageBroadcasterBinding::Wrap(aCx, this, aGivenProto); -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/base/ChromeMessageBroadcaster.h b/dom/base/ChromeMessageBroadcaster.h deleted file mode 100644 index d531a7986a379..0000000000000 --- a/dom/base/ChromeMessageBroadcaster.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#ifndef mozilla_dom_ChromeMessageBroadcaster_h -#define mozilla_dom_ChromeMessageBroadcaster_h - -#include "mozilla/dom/MessageListenerManager.h" - -namespace mozilla { -namespace dom { - -class ChromeMessageBroadcaster final : public MessageListenerManager -{ -public: - explicit ChromeMessageBroadcaster(MessageManagerFlags aFlags) - : ChromeMessageBroadcaster(nullptr, aFlags) - { - MOZ_ASSERT(!(aFlags & ~(MessageManagerFlags::MM_GLOBAL | - MessageManagerFlags::MM_PROCESSMANAGER | - MessageManagerFlags::MM_OWNSCALLBACK))); - } - explicit ChromeMessageBroadcaster(nsFrameMessageManager* aParentManager) - : ChromeMessageBroadcaster(aParentManager, MessageManagerFlags::MM_NONE) - {} - - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - - using nsFrameMessageManager::BroadcastAsyncMessage; - void BroadcastAsyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - mozilla::ErrorResult& aError) - { - DispatchAsyncMessage(aCx, aMessageName, aObj, aObjects, nullptr, - JS::UndefinedHandleValue, aError); - } - uint32_t ChildCount() - { - return mChildManagers.Length(); - } - using nsFrameMessageManager::GetChildAt; - MessageListenerManager* GetChildAt(uint32_t aIndex) - { - return mChildManagers.SafeElementAt(aIndex); - } - // XPCOM ReleaseCachedProcesses is OK - - // ProcessScriptLoader - using nsFrameMessageManager::LoadProcessScript; - void LoadProcessScript(const nsAString& aUrl, bool aAllowDelayedLoad, - mozilla::ErrorResult& aError) - { - LoadScript(aUrl, aAllowDelayedLoad, false, aError); - } - // XPCOM RemoveDelayedProcessScript is OK - using nsFrameMessageManager::GetDelayedProcessScripts; - void GetDelayedProcessScripts(JSContext* aCx, - nsTArray>& aScripts, - mozilla::ErrorResult& aError) - { - GetDelayedScripts(aCx, aScripts, aError); - } - - // GlobalProcessScriptLoader - // XPCOM GetInitialProcessData is OK - - // FrameScriptLoader - using nsFrameMessageManager::LoadFrameScript; - void LoadFrameScript(const nsAString& aUrl, bool aAllowDelayedLoad, - bool aRunInGlobalScope, mozilla::ErrorResult& aError) - { - LoadScript(aUrl, aAllowDelayedLoad, aRunInGlobalScope, aError); - } - using nsFrameMessageManager::GetDelayedFrameScripts; - void GetDelayedFrameScripts(JSContext* aCx, - nsTArray>& aScripts, - mozilla::ErrorResult& aError) - { - GetDelayedScripts(aCx, aScripts, aError); - } - -private: - ChromeMessageBroadcaster(nsFrameMessageManager* aParentManager, - MessageManagerFlags aFlags); - virtual ~ChromeMessageBroadcaster(); -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_ChromeMessageBroadcaster_h diff --git a/dom/base/ChromeMessageSender.cpp b/dom/base/ChromeMessageSender.cpp deleted file mode 100644 index cb617913fcd7e..0000000000000 --- a/dom/base/ChromeMessageSender.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#include "mozilla/dom/ChromeMessageSender.h" -#include "mozilla/dom/MessageManagerBinding.h" - -namespace mozilla { -namespace dom { - -ChromeMessageSender::ChromeMessageSender(ipc::MessageManagerCallback* aCallback, - nsFrameMessageManager* aParentManager, - MessageManagerFlags aFlags) - : MessageSender(aCallback, aParentManager, aFlags | MessageManagerFlags::MM_CHROME) -{ - MOZ_ASSERT(!(aFlags & ~(MessageManagerFlags::MM_GLOBAL | - MessageManagerFlags::MM_PROCESSMANAGER | - MessageManagerFlags::MM_OWNSCALLBACK))); - - // This is a bit hackish. We attach to the parent, but only if we have a callback. We - // don't have a callback for the frame message manager, and for parent process message - // managers (except the parent in-process message manager). In those cases we wait until - // the child process is running (see MessageSender::InitWithCallback). - if (aParentManager && mCallback) { - aParentManager->AddChildManager(this); - } -} - -JSObject* -ChromeMessageSender::WrapObject(JSContext* aCx, - JS::Handle aGivenProto) -{ - MOZ_ASSERT(nsContentUtils::IsSystemCaller(aCx)); - - return ChromeMessageSenderBinding::Wrap(aCx, this, aGivenProto); -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/base/ChromeMessageSender.h b/dom/base/ChromeMessageSender.h deleted file mode 100644 index db55f66c21ac5..0000000000000 --- a/dom/base/ChromeMessageSender.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#ifndef mozilla_dom_ChromeMessageSender_h -#define mozilla_dom_ChromeMessageSender_h - -#include "mozilla/dom/MessageSender.h" - -namespace mozilla { -namespace dom { - -class ChromeMessageSender final : public MessageSender -{ -public: - ChromeMessageSender(ipc::MessageManagerCallback* aCallback, - nsFrameMessageManager* aParentManager, - MessageManagerFlags aFlags=MessageManagerFlags::MM_NONE); - - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - - // ProcessScriptLoader - using nsFrameMessageManager::LoadProcessScript; - void LoadProcessScript(const nsAString& aUrl, bool aAllowDelayedLoad, - mozilla::ErrorResult& aError) - { - LoadScript(aUrl, aAllowDelayedLoad, false, aError); - } - // XPCOM RemoveDelayedProcessScript is OK - using nsFrameMessageManager::GetDelayedProcessScripts; - void GetDelayedProcessScripts(JSContext* aCx, - nsTArray>& aScripts, - mozilla::ErrorResult& aError) - { - GetDelayedScripts(aCx, aScripts, aError); - } - - // FrameScriptLoader - using nsFrameMessageManager::LoadFrameScript; - void LoadFrameScript(const nsAString& aUrl, bool aAllowDelayedLoad, - bool aRunInGlobalScope, mozilla::ErrorResult& aError) - { - LoadScript(aUrl, aAllowDelayedLoad, aRunInGlobalScope, aError); - } - using nsFrameMessageManager::GetDelayedFrameScripts; - void GetDelayedFrameScripts(JSContext* aCx, - nsTArray>& aScripts, - mozilla::ErrorResult& aError) - { - GetDelayedScripts(aCx, aScripts, aError); - } -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_ChromeMessageSender_h diff --git a/dom/base/ContentFrameMessageManager.h b/dom/base/ContentFrameMessageManager.h deleted file mode 100644 index 440c017028314..0000000000000 --- a/dom/base/ContentFrameMessageManager.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#ifndef mozilla_dom_ContentFrameMessageManager_h -#define mozilla_dom_ContentFrameMessageManager_h - -#include "mozilla/DOMEventTargetHelper.h" -#include "mozilla/dom/MessageManagerGlobal.h" -#include "mozilla/dom/ResolveSystemBinding.h" -#include "nsContentUtils.h" - -namespace mozilla { -namespace dom { - -/** - * Base class for implementing the WebIDL ContentFrameMessageManager class. - */ -class ContentFrameMessageManager : public DOMEventTargetHelper, - public MessageManagerGlobal -{ -public: - using DOMEventTargetHelper::AddRef; - using DOMEventTargetHelper::Release; - - bool DoResolve(JSContext* aCx, JS::Handle aObj, - JS::Handle aId, - JS::MutableHandle aDesc) - { - bool found; - if (!SystemGlobalResolve(aCx, aObj, aId, &found)) { - return false; - } - if (found) { - FillPropertyDescriptor(aDesc, aObj, JS::UndefinedValue(), false); - } - return true; - } - static bool MayResolve(jsid aId) - { - return MayResolveAsSystemBindingName(aId); - } - void GetOwnPropertyNames(JSContext* aCx, JS::AutoIdVector& aNames, - bool aEnumerableOnly, mozilla::ErrorResult& aRv) - { - JS::Rooted thisObj(aCx, GetWrapper()); - GetSystemBindingNames(aCx, thisObj, aNames, aEnumerableOnly, aRv); - } - - nsresult AddEventListener(const nsAString& aType, - nsIDOMEventListener* aListener, - bool aUseCapture) - { - // By default add listeners only for trusted events! - return DOMEventTargetHelper::AddEventListener(aType, aListener, - aUseCapture, false, 2); - } - using DOMEventTargetHelper::AddEventListener; - NS_IMETHOD AddEventListener(const nsAString& aType, - nsIDOMEventListener* aListener, - bool aUseCapture, bool aWantsUntrusted, - uint8_t optional_argc) override - { - return DOMEventTargetHelper::AddEventListener(aType, aListener, - aUseCapture, - aWantsUntrusted, - optional_argc); - } - - virtual already_AddRefed GetContent(ErrorResult& aError) = 0; - virtual already_AddRefed GetDocShell(ErrorResult& aError) = 0; - virtual already_AddRefed GetTabEventTarget() = 0; - - nsFrameMessageManager* GetMessageManager() - { - return mMessageManager; - } - void DisconnectMessageManager() - { - mMessageManager->Disconnect(); - mMessageManager = nullptr; - } - -protected: - explicit ContentFrameMessageManager(nsFrameMessageManager* aMessageManager) - : MessageManagerGlobal(aMessageManager) - {} -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_ContentFrameMessageManager_h diff --git a/dom/base/DOMMatrix.cpp b/dom/base/DOMMatrix.cpp index 4244a14182ce8..d1dc8ae2d58c7 100644 --- a/dom/base/DOMMatrix.cpp +++ b/dom/base/DOMMatrix.cpp @@ -12,10 +12,8 @@ #include "mozilla/dom/DOMPointBinding.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/ToJSValue.h" -#include "mozilla/RuleNodeCacheConditions.h" #include "mozilla/ServoCSSParser.h" #include "nsCSSParser.h" -#include "nsGlobalWindowInner.h" #include "nsStyleTransformMatrix.h" #include diff --git a/dom/base/DOMRequestHelper.jsm b/dom/base/DOMRequestHelper.jsm index f6b8cf41f852c..a5323f4c147e6 100644 --- a/dom/base/DOMRequestHelper.jsm +++ b/dom/base/DOMRequestHelper.jsm @@ -21,6 +21,10 @@ var EXPORTED_SYMBOLS = ["DOMRequestIpcHelper"]; ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); ChromeUtils.import("resource://gre/modules/Services.jsm"); +XPCOMUtils.defineLazyServiceGetter(this, "cpmm", + "@mozilla.org/childprocessmessagemanager;1", + "nsIMessageListenerManager"); + function DOMRequestIpcHelper() { // _listeners keeps a list of messages for which we added a listener and the // kind of listener that we added (strong or weak). It's an object of this @@ -85,8 +89,8 @@ DOMRequestIpcHelper.prototype = { } } - aMsg.weakRef ? Services.cpmm.addWeakMessageListener(name, this) - : Services.cpmm.addMessageListener(name, this); + aMsg.weakRef ? cpmm.addWeakMessageListener(name, this) + : cpmm.addMessageListener(name, this); this._listeners[name] = { weakRef: !!aMsg.weakRef, count: 1 @@ -116,8 +120,8 @@ DOMRequestIpcHelper.prototype = { // be waiting on a message. if (!--this._listeners[aName].count) { this._listeners[aName].weakRef ? - Services.cpmm.removeWeakMessageListener(aName, this) - : Services.cpmm.removeMessageListener(aName, this); + cpmm.removeWeakMessageListener(aName, this) + : cpmm.removeMessageListener(aName, this); delete this._listeners[aName]; } }); @@ -177,9 +181,8 @@ DOMRequestIpcHelper.prototype = { if (this._listeners) { Object.keys(this._listeners).forEach((aName) => { - this._listeners[aName].weakRef ? - Services.cpmm.removeWeakMessageListener(aName, this) - : Services.cpmm.removeMessageListener(aName, this); + this._listeners[aName].weakRef ? cpmm.removeWeakMessageListener(aName, this) + : cpmm.removeMessageListener(aName, this); }); } diff --git a/dom/base/MessageListenerManager.cpp b/dom/base/MessageListenerManager.cpp deleted file mode 100644 index 413afb00969cc..0000000000000 --- a/dom/base/MessageListenerManager.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#include "mozilla/dom/MessageListenerManager.h" - -namespace mozilla { -namespace dom { - -MessageListenerManager::MessageListenerManager(ipc::MessageManagerCallback* aCallback, - nsFrameMessageManager* aParentManager, - ipc::MessageManagerFlags aFlags) - : nsFrameMessageManager(aCallback, aFlags), - mParentManager(aParentManager) -{ -} - -MessageListenerManager::~MessageListenerManager() -{ -} - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MessageListenerManager) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY -NS_INTERFACE_MAP_END_INHERITING(nsFrameMessageManager) -NS_IMPL_ADDREF_INHERITED(MessageListenerManager, nsFrameMessageManager) -NS_IMPL_RELEASE_INHERITED(MessageListenerManager, nsFrameMessageManager) - -NS_IMPL_CYCLE_COLLECTION_CLASS(MessageListenerManager) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MessageListenerManager, - nsFrameMessageManager) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentManager) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(MessageListenerManager, - nsFrameMessageManager) - NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER -NS_IMPL_CYCLE_COLLECTION_TRACE_END -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MessageListenerManager, - nsFrameMessageManager) - NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER - NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentManager) -NS_IMPL_CYCLE_COLLECTION_UNLINK_END - -void -MessageListenerManager::ClearParentManager(bool aRemove) -{ - if (aRemove && mParentManager) { - mParentManager->RemoveChildManager(this); - } - mParentManager = nullptr; -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/base/MessageListenerManager.h b/dom/base/MessageListenerManager.h deleted file mode 100644 index fc632c5a11aa5..0000000000000 --- a/dom/base/MessageListenerManager.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#ifndef mozilla_dom_MessageListenerManager_h -#define mozilla_dom_MessageListenerManager_h - -#include "nsCycleCollectionNoteChild.h" -#include "nsFrameMessageManager.h" -#include "nsWrapperCache.h" - -namespace mozilla { -namespace dom { - -class MessageListenerManager : public nsFrameMessageManager, - public nsWrapperCache -{ -public: - NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(MessageListenerManager, - nsFrameMessageManager) - - nsISupports* GetParentObject() - { - return ToSupports(mParentManager.get()); - } - - virtual nsFrameMessageManager* GetParentManager() override - { - return mParentManager; - } - - /** - * If aRemove is true then RemoveChildManager(this) will be called on the parent manager - * first. - */ - virtual void ClearParentManager(bool aRemove) override; - -protected: - MessageListenerManager(ipc::MessageManagerCallback* aCallback, - nsFrameMessageManager* aParentManager, - MessageManagerFlags aFlags); - virtual ~MessageListenerManager(); - - RefPtr mParentManager; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_MessageListenerManager_h diff --git a/dom/base/MessageManagerGlobal.h b/dom/base/MessageManagerGlobal.h deleted file mode 100644 index 00d9a1ae64a04..0000000000000 --- a/dom/base/MessageManagerGlobal.h +++ /dev/null @@ -1,181 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#ifndef mozilla_dom_MessageManagerGlobal_h -#define mozilla_dom_MessageManagerGlobal_h - -#include "nsFrameMessageManager.h" -#include "mozilla/ErrorResult.h" - -namespace mozilla { -namespace dom { - -/** - * Base class for implementing the WebIDL MessageManagerGlobal class. - */ -class MessageManagerGlobal -{ -public: - // MessageListenerManager - void AddMessageListener(const nsAString& aMessageName, - MessageListener& aListener, - bool aListenWhenClosed, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->AddMessageListener(aMessageName, aListener, - aListenWhenClosed, aError); - } - void RemoveMessageListener(const nsAString& aMessageName, - MessageListener& aListener, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->RemoveMessageListener(aMessageName, aListener, aError); - } - void AddWeakMessageListener(const nsAString& aMessageName, - MessageListener& aListener, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->AddWeakMessageListener(aMessageName, aListener, aError); - } - void RemoveWeakMessageListener(const nsAString& aMessageName, - MessageListener& aListener, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->RemoveWeakMessageListener(aMessageName, aListener, aError); - } - - // MessageSender - void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - JS::Handle aTransfers, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->SendAsyncMessage(aCx, aMessageName, aObj, aObjects, - aPrincipal, aTransfers, aError); - } - already_AddRefed GetProcessMessageManager(mozilla::ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return nullptr; - } - return mMessageManager->GetProcessMessageManager(aError); - } - - void GetRemoteType(nsAString& aRemoteType, mozilla::ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->GetRemoteType(aRemoteType, aError); - } - - // SyncMessageSender - void SendSyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - nsTArray& aResult, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->SendSyncMessage(aCx, aMessageName, aObj, aObjects, - aPrincipal, aResult, aError); - } - void SendRpcMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - nsTArray& aResult, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->SendRpcMessage(aCx, aMessageName, aObj, aObjects, - aPrincipal, aResult, aError); - } - - // MessageManagerGlobal - void Dump(const nsAString& aStr, ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - aError = mMessageManager->Dump(aStr); - } - void PrivateNoteIntentionalCrash(ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - aError = mMessageManager->PrivateNoteIntentionalCrash(); - } - void Atob(const nsAString& aAsciiString, nsAString& aBase64Data, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - aError = mMessageManager->Atob(aAsciiString, aBase64Data); - } - void Btoa(const nsAString& aBase64Data, nsAString& aAsciiString, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - aError = mMessageManager->Btoa(aBase64Data, aAsciiString); - } - - bool MarkForCC() - { - return mMessageManager && mMessageManager->MarkForCC(); - } - -protected: - explicit MessageManagerGlobal(nsFrameMessageManager* aMessageManager) - : mMessageManager(aMessageManager) - {} - - RefPtr mMessageManager; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_MessageManagerGlobal_h diff --git a/dom/base/MessageSender.cpp b/dom/base/MessageSender.cpp deleted file mode 100644 index d16455e9d4b3d..0000000000000 --- a/dom/base/MessageSender.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#include "mozilla/dom/MessageSender.h" - -namespace mozilla { -namespace dom { - -void -MessageSender::InitWithCallback(ipc::MessageManagerCallback* aCallback) -{ - if (mCallback) { - // Initialization should only happen once. - return; - } - - SetCallback(aCallback); - - // First load parent scripts by adding this to parent manager. - if (mParentManager) { - mParentManager->AddChildManager(this); - } - - for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) { - LoadFrameScript(mPendingScripts[i], false, mPendingScriptsGlobalStates[i]); - } -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/base/MessageSender.h b/dom/base/MessageSender.h deleted file mode 100644 index 3ad1c7905e7ca..0000000000000 --- a/dom/base/MessageSender.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#ifndef mozilla_dom_MessageSender_h -#define mozilla_dom_MessageSender_h - -#include "mozilla/dom/MessageListenerManager.h" - -namespace mozilla { -namespace dom { - -class MessageSender : public MessageListenerManager -{ -public: - void InitWithCallback(ipc::MessageManagerCallback* aCallback); - -protected: - MessageSender(ipc::MessageManagerCallback* aCallback, - nsFrameMessageManager* aParentManager, - MessageManagerFlags aFlags) - : MessageListenerManager(aCallback, aParentManager, aFlags) - {} -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_MessageSender_h diff --git a/dom/base/ProcessGlobal.cpp b/dom/base/ProcessGlobal.cpp index e19cc08716518..1c7579003eb57 100644 --- a/dom/base/ProcessGlobal.cpp +++ b/dom/base/ProcessGlobal.cpp @@ -7,16 +7,17 @@ #include "ProcessGlobal.h" #include "nsContentCID.h" -#include "mozilla/dom/MessageManagerBinding.h" -#include "mozilla/dom/ResolveSystemBinding.h" +#include "nsDOMClassInfoID.h" +#include "mozilla/HoldDropJSObjects.h" using namespace mozilla; using namespace mozilla::dom; ProcessGlobal::ProcessGlobal(nsFrameMessageManager* aMessageManager) - : MessageManagerGlobal(aMessageManager), - mInitialized(false) + : mInitialized(false), + mMessageManager(aMessageManager) { + SetIsNotDOMBinding(); mozilla::HoldJSObjects(this); } @@ -26,36 +27,6 @@ ProcessGlobal::~ProcessGlobal() mozilla::DropJSObjects(this); } -bool -ProcessGlobal::DoResolve(JSContext* aCx, JS::Handle aObj, - JS::Handle aId, - JS::MutableHandle aDesc) -{ - bool found; - if (!SystemGlobalResolve(aCx, aObj, aId, &found)) { - return false; - } - if (found) { - FillPropertyDescriptor(aDesc, aObj, JS::UndefinedValue(), false); - } - return true; -} - -/* static */ -bool -ProcessGlobal::MayResolve(jsid aId) -{ - return MayResolveAsSystemBindingName(aId); -} - -void -ProcessGlobal::GetOwnPropertyNames(JSContext* aCx, JS::AutoIdVector& aNames, - bool aEnumerableOnly, ErrorResult& aRv) -{ - JS::Rooted thisObj(aCx, GetWrapper()); - GetSystemBindingNames(aCx, thisObj, aNames, aEnumerableOnly, aRv); -} - ProcessGlobal* ProcessGlobal::Get() { @@ -72,7 +43,7 @@ NS_IMETHODIMP_(bool) ProcessGlobal::MarkForCC() { MarkScopesForCC(); - return MessageManagerGlobal::MarkForCC(); + return mMessageManager ? mMessageManager->MarkForCC() : false; } NS_IMPL_CYCLE_COLLECTION_CLASS(ProcessGlobal) @@ -104,6 +75,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ProcessGlobal) NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal) NS_INTERFACE_MAP_ENTRY(nsIGlobalObject) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ContentProcessMessageManager) NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTING_ADDREF(ProcessGlobal) @@ -117,30 +89,15 @@ ProcessGlobal::Init() } mInitialized = true; - return InitChildGlobalInternal(NS_LITERAL_CSTRING("processChildGlobal")); -} - -bool -ProcessGlobal::WrapGlobalObject(JSContext* aCx, - JS::CompartmentOptions& aOptions, - JS::MutableHandle aReflector) -{ - bool ok = ContentProcessMessageManagerBinding::Wrap(aCx, this, this, aOptions, - nsJSPrincipals::get(mPrincipal), - true, aReflector); - if (ok) { - // Since we can't rewrap we have to preserve the global's wrapper here. - PreserveWrapper(ToSupports(this)); - } - return ok; + nsISupports* scopeSupports = NS_ISUPPORTS_CAST(nsIContentProcessMessageManager*, this); + return InitChildGlobalInternal(scopeSupports, NS_LITERAL_CSTRING("processChildGlobal")); } void ProcessGlobal::LoadScript(const nsAString& aURL) { Init(); - JS::Rooted global(mozilla::dom::RootingCx(), GetWrapper()); - LoadScriptInternal(global, aURL, false); + LoadScriptInternal(aURL, false); } void diff --git a/dom/base/ProcessGlobal.h b/dom/base/ProcessGlobal.h index 5544166dba420..2b46246837176 100644 --- a/dom/base/ProcessGlobal.h +++ b/dom/base/ProcessGlobal.h @@ -8,7 +8,6 @@ #define mozilla_dom_ProcessGlobal_h #include "mozilla/Attributes.h" -#include "mozilla/dom/MessageManagerGlobal.h" #include "nsCOMPtr.h" #include "nsFrameMessageManager.h" #include "nsIScriptContext.h" @@ -26,26 +25,18 @@ namespace mozilla { namespace dom { class ProcessGlobal : - public nsIContentProcessMessageManager, public nsMessageManagerScriptExecutor, + public nsIContentProcessMessageManager, public nsIGlobalObject, public nsIScriptObjectPrincipal, public nsSupportsWeakReference, - public ipc::MessageManagerCallback, - public MessageManagerGlobal, + public mozilla::dom::ipc::MessageManagerCallback, public nsWrapperCache { public: explicit ProcessGlobal(nsFrameMessageManager* aMessageManager); - bool DoResolve(JSContext* aCx, JS::Handle aObj, - JS::Handle aId, - JS::MutableHandle aDesc); - static bool MayResolve(jsid aId); - void GetOwnPropertyNames(JSContext* aCx, JS::AutoIdVector& aNames, - bool aEnumerableOnly, ErrorResult& aRv); - - using ipc::MessageManagerCallback::GetProcessMessageManager; + using mozilla::dom::ipc::MessageManagerCallback::GetProcessMessageManager; bool Init(); @@ -54,41 +45,6 @@ class ProcessGlobal : NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(ProcessGlobal, nsIContentProcessMessageManager) - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override - { - MOZ_CRASH("We should never get here!"); - } - virtual bool WrapGlobalObject(JSContext* aCx, - JS::CompartmentOptions& aOptions, - JS::MutableHandle aReflector) override; - - using MessageManagerGlobal::AddMessageListener; - using MessageManagerGlobal::RemoveMessageListener; - using MessageManagerGlobal::AddWeakMessageListener; - using MessageManagerGlobal::RemoveWeakMessageListener; - using MessageManagerGlobal::SendAsyncMessage; - using MessageManagerGlobal::GetProcessMessageManager; - using MessageManagerGlobal::GetRemoteType; - using MessageManagerGlobal::SendSyncMessage; - using MessageManagerGlobal::SendRpcMessage; - using MessageManagerGlobal::Dump; - using MessageManagerGlobal::PrivateNoteIntentionalCrash; - using MessageManagerGlobal::Atob; - using MessageManagerGlobal::Btoa; - - // ContentProcessMessageManager - void GetInitialProcessData(JSContext* aCx, - JS::MutableHandle aInitialProcessData, - ErrorResult& aError) - { - if (!mMessageManager) { - aError.Throw(NS_ERROR_NULL_POINTER); - return; - } - mMessageManager->GetInitialProcessData(aCx, aInitialProcessData, aError); - } - NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager) NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) NS_FORWARD_SAFE_NSISYNCMESSAGESENDER(mMessageManager) @@ -99,10 +55,15 @@ class ProcessGlobal : virtual JSObject* GetGlobalJSObject() override { - return GetWrapper(); + return mGlobal; } virtual nsIPrincipal* GetPrincipal() override { return mPrincipal; } + virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override + { + MOZ_CRASH("ProcessGlobal doesn't use DOM bindings!"); + } + void SetInitialProcessData(JS::HandleValue aInitialData); protected: @@ -110,6 +71,7 @@ class ProcessGlobal : private: bool mInitialized; + RefPtr mMessageManager; }; } // namespace dom diff --git a/dom/base/SyncMessageSender.h b/dom/base/SyncMessageSender.h deleted file mode 100644 index b715029ed31a4..0000000000000 --- a/dom/base/SyncMessageSender.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 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/. */ - -#ifndef mozilla_dom_SyncMessageSender_h -#define mozilla_dom_SyncMessageSender_h - -#include "mozilla/dom/MessageSender.h" - -namespace mozilla { -namespace dom { - -class SyncMessageSender : public MessageSender -{ -protected: - SyncMessageSender(ipc::MessageManagerCallback* aCallback, - MessageManagerFlags aFlags) - : MessageSender(aCallback, nullptr, aFlags) - {} -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_SyncMessageSender_h diff --git a/dom/base/TextInputProcessor.cpp b/dom/base/TextInputProcessor.cpp index bcb5b2d30e0cb..fdff3e3c5a15f 100644 --- a/dom/base/TextInputProcessor.cpp +++ b/dom/base/TextInputProcessor.cpp @@ -18,7 +18,6 @@ #include "nsPIDOMWindow.h" #include "nsPresContext.h" -using mozilla::dom::KeyboardEvent; using namespace mozilla::widget; namespace mozilla { diff --git a/dom/base/TimeoutExecutor.cpp b/dom/base/TimeoutExecutor.cpp index 0364602515586..b2e8e59992f7b 100644 --- a/dom/base/TimeoutExecutor.cpp +++ b/dom/base/TimeoutExecutor.cpp @@ -8,7 +8,6 @@ #include "mozilla/dom/TimeoutManager.h" #include "nsComponentManagerUtils.h" -#include "nsIEventTarget.h" #include "nsString.h" namespace mozilla { diff --git a/dom/base/TimeoutManager.h b/dom/base/TimeoutManager.h index 6040f1ec29712..378741c2427c2 100644 --- a/dom/base/TimeoutManager.h +++ b/dom/base/TimeoutManager.h @@ -12,7 +12,6 @@ class nsIEventTarget; class nsITimeoutHandler; -class nsITimer; class nsGlobalWindowInner; namespace mozilla { diff --git a/dom/base/moz.build b/dom/base/moz.build index 16fe210658cd1..f56ca8883a738 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -156,13 +156,9 @@ EXPORTS.mozilla.dom += [ 'BodyUtil.h', 'BorrowedAttrInfo.h', 'ChildIterator.h', - 'ChildProcessMessageManager.h', - 'ChromeMessageBroadcaster.h', - 'ChromeMessageSender.h', 'ChromeNodeList.h', 'ChromeUtils.h', 'Comment.h', - 'ContentFrameMessageManager.h', 'CustomElementRegistry.h', 'DirectionalityUtils.h', 'DispatcherTrait.h', @@ -199,9 +195,6 @@ EXPORTS.mozilla.dom += [ 'IntlUtils.h', 'Link.h', 'Location.h', - 'MessageListenerManager.h', - 'MessageManagerGlobal.h', - 'MessageSender.h', 'NameSpaceConstants.h', 'Navigator.h', 'NodeInfo.h', @@ -219,7 +212,6 @@ EXPORTS.mozilla.dom += [ 'StructuredCloneTags.h', 'StyleSheetList.h', 'SubtleCrypto.h', - 'SyncMessageSender.h', 'TabGroup.h', 'Text.h', 'Timeout.h', @@ -242,8 +234,6 @@ UNIFIED_SOURCES += [ 'BodyUtil.cpp', 'BorrowedAttrInfo.cpp', 'ChildIterator.cpp', - 'ChromeMessageBroadcaster.cpp', - 'ChromeMessageSender.cpp', 'ChromeNodeList.cpp', 'ChromeUtils.cpp', 'Comment.cpp', @@ -279,8 +269,6 @@ UNIFIED_SOURCES += [ 'IntlUtils.cpp', 'Link.cpp', 'Location.cpp', - 'MessageListenerManager.cpp', - 'MessageSender.cpp', 'Navigator.cpp', 'NodeInfo.cpp', 'NodeIterator.cpp', diff --git a/dom/base/nsCCUncollectableMarker.cpp b/dom/base/nsCCUncollectableMarker.cpp index 632111f2ce332..01f7dafa3e79e 100644 --- a/dom/base/nsCCUncollectableMarker.cpp +++ b/dom/base/nsCCUncollectableMarker.cpp @@ -17,6 +17,7 @@ #include "nsISHistory.h" #include "nsISHEntry.h" #include "nsISHContainer.h" +#include "nsITabChild.h" #include "nsIWindowWatcher.h" #include "mozilla/Services.h" #include "nsIXULWindow.h" @@ -32,7 +33,6 @@ #include "mozilla/EventListenerManager.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/ProcessGlobal.h" -#include "mozilla/dom/TabChild.h" #include "mozilla/dom/TimeoutManager.h" #include "xpcpublic.h" #include "nsObserverService.h" @@ -311,9 +311,11 @@ MarkWindowList(nsISimpleEnumerator* aWindowList, bool aCleanupJS, MarkDocShell(rootDocShell, aCleanupJS, aPrepareForCC); - RefPtr tabChild = TabChild::GetFrom(rootDocShell); + nsCOMPtr tabChild = + rootDocShell ? rootDocShell->GetTabChild() : nullptr; if (tabChild) { - nsCOMPtr mm = tabChild->GetMessageManager(); + nsCOMPtr mm; + tabChild->GetMessageManager(getter_AddRefs(mm)); if (mm) { // MarkForCC ends up calling UnmarkGray on message listeners, which // TraceBlackJS can't do yet. @@ -531,7 +533,7 @@ mozilla::dom::TraceBlackJS(JSTracer* aTrc, bool aIsShutdownGC) if (ds) { nsCOMPtr tabChild = ds->GetTabChild(); if (tabChild) { - nsCOMPtr mm; + nsCOMPtr mm; tabChild->GetMessageManager(getter_AddRefs(mm)); nsCOMPtr et = do_QueryInterface(mm); if (et) { diff --git a/dom/base/nsContentIterator.cpp b/dom/base/nsContentIterator.cpp index 7f0939ffc619d..4966e4dbcc535 100644 --- a/dom/base/nsContentIterator.cpp +++ b/dom/base/nsContentIterator.cpp @@ -18,7 +18,6 @@ #include "nsElementTable.h" using mozilla::DebugOnly; -using mozilla::Move; using mozilla::RawRangeBoundary; // couple of utility static functs diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 21eb41a7cf623..797d95ea54cca 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -73,6 +73,7 @@ // includes needed for the prototype chain interfaces #include "nsIEventListenerService.h" +#include "nsIMessageManager.h" #include "mozilla/dom/TouchEvent.h" @@ -130,6 +131,9 @@ using namespace mozilla::dom; #define NS_DEFINE_CLASSINFO_DATA(_class, _helper, _flags) \ NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, false, false) +#define NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(_class, _helper, _flags) \ + NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, true, false) + #define NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(_class, _helper, _flags) \ NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, true, true) @@ -164,6 +168,22 @@ static nsDOMClassInfoData sClassInfoData[] = { // Misc Core related classes + NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentFrameMessageManager, + nsMessageManagerSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + XPC_SCRIPTABLE_WANT_ENUMERATE | + XPC_SCRIPTABLE_IS_GLOBAL_OBJECT) + NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentProcessMessageManager, + nsMessageManagerSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + XPC_SCRIPTABLE_WANT_ENUMERATE | + XPC_SCRIPTABLE_IS_GLOBAL_OBJECT) + NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageBroadcaster, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageSender, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + + NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControlElement, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULLabeledControlElement, nsDOMGenericSH, @@ -405,6 +425,36 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor) DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ContentFrameMessageManager, nsISupports) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) + DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager) + DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) + DOM_CLASSINFO_MAP_ENTRY(nsISyncMessageSender) + DOM_CLASSINFO_MAP_ENTRY(nsIContentFrameMessageManager) + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ContentProcessMessageManager, nsISupports) + DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager) + DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) + DOM_CLASSINFO_MAP_ENTRY(nsISyncMessageSender) + DOM_CLASSINFO_MAP_ENTRY(nsIContentProcessMessageManager) + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ChromeMessageBroadcaster, nsISupports) + DOM_CLASSINFO_MAP_ENTRY(nsIFrameScriptLoader) + DOM_CLASSINFO_MAP_ENTRY(nsIProcessScriptLoader) + DOM_CLASSINFO_MAP_ENTRY(nsIGlobalProcessScriptLoader) + DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager) + DOM_CLASSINFO_MAP_ENTRY(nsIMessageBroadcaster) + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ChromeMessageSender, nsISupports) + DOM_CLASSINFO_MAP_ENTRY(nsIFrameScriptLoader) + DOM_CLASSINFO_MAP_ENTRY(nsIProcessScriptLoader) + DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager) + DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) + DOM_CLASSINFO_MAP_END + DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULControlElement, nsIDOMXULControlElement) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULControlElement) DOM_CLASSINFO_MAP_END @@ -1872,3 +1922,41 @@ nsDOMConstructorSH::HasInstance(nsIXPConnectWrappedNative *wrapper, return wrapped->HasInstance(wrapper, cx, obj, val, bp, _retval); } + +// nsContentFrameMessageManagerSH + +template +NS_IMETHODIMP +nsMessageManagerSH::Resolve(nsIXPConnectWrappedNative* wrapper, + JSContext* cx, JSObject* obj_, + jsid id_, bool* resolvedp, + bool* _retval) +{ + JS::Rooted obj(cx, obj_); + JS::Rooted id(cx, id_); + + *_retval = SystemGlobalResolve(cx, obj, id, resolvedp); + NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE); + + if (*resolvedp) { + return NS_OK; + } + + return Super::Resolve(wrapper, cx, obj, id, resolvedp, _retval); +} + +template +NS_IMETHODIMP +nsMessageManagerSH::Enumerate(nsIXPConnectWrappedNative* wrapper, + JSContext* cx, JSObject* obj_, + bool* _retval) +{ + JS::Rooted obj(cx, obj_); + + *_retval = SystemGlobalEnumerate(cx, obj); + NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE); + + // Don't call up to our superclass, since neither nsDOMGenericSH nor + // nsEventTargetSH have WANT_ENUMERATE. + return NS_OK; +} diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index d0844a64d032d..c6df9c2c73a69 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -212,4 +212,29 @@ class nsDOMConstructorSH : public nsDOMGenericSH } }; +template +class nsMessageManagerSH : public Super +{ +protected: + explicit nsMessageManagerSH(nsDOMClassInfoData* aData) + : Super(aData) + { + } + + virtual ~nsMessageManagerSH() + { + } +public: + NS_IMETHOD Resolve(nsIXPConnectWrappedNative* wrapper, JSContext* cx, + JSObject* obj_, jsid id_, bool* resolvedp, + bool* _retval) override; + NS_IMETHOD Enumerate(nsIXPConnectWrappedNative* wrapper, JSContext* cx, + JSObject* obj_, bool* _retval) override; + + static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) + { + return new nsMessageManagerSH(aData); + } +}; + #endif /* nsDOMClassInfo_h___ */ diff --git a/dom/base/nsDOMClassInfoID.h b/dom/base/nsDOMClassInfoID.h index 62ff599bcc443..8e32c82a678fa 100644 --- a/dom/base/nsDOMClassInfoID.h +++ b/dom/base/nsDOMClassInfoID.h @@ -19,6 +19,11 @@ enum nsDOMClassInfoID eDOMClassInfo_DOMPrototype_id, eDOMClassInfo_DOMConstructor_id, + eDOMClassInfo_ContentFrameMessageManager_id, + eDOMClassInfo_ContentProcessMessageManager_id, + eDOMClassInfo_ChromeMessageBroadcaster_id, + eDOMClassInfo_ChromeMessageSender_id, + eDOMClassInfo_XULControlElement_id, eDOMClassInfo_XULLabeledControlElement_id, eDOMClassInfo_XULButtonElement_id, diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index 7d6a1589b7a29..029c4632f89d0 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -79,7 +79,6 @@ #include "mozilla/HTMLEditor.h" #include "mozilla/Preferences.h" #include "mozilla/Unused.h" -#include "mozilla/dom/ChromeMessageSender.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/FrameLoaderBinding.h" #include "mozilla/jsipc/CrossProcessObjectWrappers.h" @@ -1643,12 +1642,14 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther, RefPtr otherMessageManager = aOther->mMessageManager; // Swap pointers in child message managers. if (mChildMessageManager) { - nsInProcessTabChildGlobal* tabChild = mChildMessageManager; + nsInProcessTabChildGlobal* tabChild = + static_cast(mChildMessageManager.get()); tabChild->SetOwner(otherContent); tabChild->SetChromeMessageManager(otherMessageManager); } if (aOther->mChildMessageManager) { - nsInProcessTabChildGlobal* otherTabChild = aOther->mChildMessageManager; + nsInProcessTabChildGlobal* otherTabChild = + static_cast(aOther->mChildMessageManager.get()); otherTabChild->SetOwner(ourContent); otherTabChild->SetChromeMessageManager(ourMessageManager); } @@ -1883,7 +1884,7 @@ nsFrameLoader::DestroyDocShell() // Fire the "unload" event if we're in-process. if (mChildMessageManager) { - mChildMessageManager->FireUnloadEvent(); + static_cast(mChildMessageManager.get())->FireUnloadEvent(); } // Destroy the docshell. @@ -1895,7 +1896,7 @@ nsFrameLoader::DestroyDocShell() if (mChildMessageManager) { // Stop handling events in the in-process frame script. - mChildMessageManager->DisconnectEventListeners(); + static_cast(mChildMessageManager.get())->DisconnectEventListeners(); } } @@ -1930,7 +1931,7 @@ nsFrameLoader::DestroyComplete() } if (mChildMessageManager) { - mChildMessageManager->Disconnect(); + static_cast(mChildMessageManager.get())->Disconnect(); } mMessageManager = nullptr; @@ -2986,11 +2987,12 @@ class nsAsyncMessageToChild : public nsSameProcessAsyncMessageBase, NS_IMETHOD Run() override { - nsInProcessTabChildGlobal* tabChild = mFrameLoader->mChildMessageManager; + nsInProcessTabChildGlobal* tabChild = + static_cast(mFrameLoader->mChildMessageManager.get()); // Since bug 1126089, messages can arrive even when the docShell is destroyed. // Here we make sure that those messages are not delivered. if (tabChild && tabChild->GetInnerManager() && mFrameLoader->GetExistingDocShell()) { - JS::Rooted kungFuDeathGrip(dom::RootingCx(), tabChild->GetWrapper()); + JS::Rooted kungFuDeathGrip(dom::RootingCx(), tabChild->GetGlobal()); ReceiveMessage(static_cast(tabChild), mFrameLoader, tabChild->GetInnerManager()); } @@ -3104,8 +3106,9 @@ nsFrameLoader::EnsureMessageManager() parentManager = do_GetService("@mozilla.org/globalmessagemanager;1"); } - mMessageManager = new ChromeMessageSender(nullptr, - static_cast(parentManager.get())); + mMessageManager = new nsFrameMessageManager(nullptr, + static_cast(parentManager.get()), + MM_CHROME); if (!IsRemoteFrame()) { nsresult rv = MaybeCreateDocShell(); if (NS_FAILED(rv)) { @@ -3138,7 +3141,7 @@ nsFrameLoader::ReallyLoadFrameScripts() EventTarget* nsFrameLoader::GetTabChildGlobalAsEventTarget() { - return mChildMessageManager.get(); + return static_cast(mChildMessageManager.get()); } already_AddRefed diff --git a/dom/base/nsFrameLoader.h b/dom/base/nsFrameLoader.h index 8e8cdc7e131d1..367b89b2db346 100644 --- a/dom/base/nsFrameLoader.h +++ b/dom/base/nsFrameLoader.h @@ -32,7 +32,7 @@ class nsIURI; class nsSubDocumentFrame; class nsView; -class nsInProcessTabChildGlobal; +class nsIInProcessContentFrameMessageManager; class AutoResetInShow; class AutoResetInFrameSwap; class nsITabParent; @@ -44,7 +44,6 @@ namespace mozilla { class OriginAttributes; namespace dom { -class ChromeMessageSender; class ContentParent; class PBrowserParent; class Promise; @@ -269,7 +268,7 @@ class nsFrameLoader final : public nsIFrameLoader, */ RenderFrameParent* GetCurrentRenderFrame() const; - mozilla::dom::ChromeMessageSender* GetFrameMessageManager() { return mMessageManager; } + nsFrameMessageManager* GetFrameMessageManager() { return mMessageManager; } mozilla::dom::Element* GetOwnerContent() { return mOwnerContent; } bool ShouldClipSubdocument() { return mClipSubdocument; } @@ -320,8 +319,8 @@ class nsFrameLoader final : public nsIFrameLoader, virtual nsIMessageSender* GetProcessMessageManager() const override; // public because a callback needs these. - RefPtr mMessageManager; - RefPtr mChildMessageManager; + RefPtr mMessageManager; + nsCOMPtr mChildMessageManager; virtual JSObject* WrapObject(JSContext* cx, JS::Handle aGivenProto) override; diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index 60766a60bddc6..e63db36a99377 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -12,6 +12,7 @@ #include "GeckoProfiler.h" #include "nsASCIIMask.h" #include "nsContentUtils.h" +#include "nsDOMClassInfoID.h" #include "nsError.h" #include "nsIXPConnect.h" #include "jsapi.h" @@ -28,6 +29,7 @@ #include "nsIMemoryReporter.h" #include "nsIProtocolHandler.h" #include "nsIScriptSecurityManager.h" +#include "nsIDOMClassInfo.h" #include "xpcpublic.h" #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/IntentionalCrash.h" @@ -35,26 +37,19 @@ #include "mozilla/ScriptPreloader.h" #include "mozilla/Telemetry.h" #include "mozilla/dom/DOMPrefs.h" -#include "mozilla/dom/ChildProcessMessageManager.h" -#include "mozilla/dom/ChromeMessageBroadcaster.h" -#include "mozilla/dom/ChromeMessageSender.h" #include "mozilla/dom/File.h" -#include "mozilla/dom/MessageManagerBinding.h" #include "mozilla/dom/MessagePort.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/ProcessGlobal.h" -#include "mozilla/dom/ResolveSystemBinding.h" #include "mozilla/dom/SameProcessMessageQueue.h" #include "mozilla/dom/ScriptSettings.h" -#include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/ipc/StructuredCloneData.h" #include "mozilla/dom/DOMStringList.h" #include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "nsPrintfCString.h" #include "nsXULAppAPI.h" #include "nsQueryObject.h" -#include "xpcprivate.h" #include #include "chrome/common/ipc_channel.h" // for IPC::Channel::kMaximumMessageSize @@ -76,20 +71,33 @@ using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::dom::ipc; -nsFrameMessageManager::nsFrameMessageManager(MessageManagerCallback* aCallback, - MessageManagerFlags aFlags) - : mChrome(aFlags & MessageManagerFlags::MM_CHROME), - mGlobal(aFlags & MessageManagerFlags::MM_GLOBAL), - mIsProcessManager(aFlags & MessageManagerFlags::MM_PROCESSMANAGER), - mIsBroadcaster(aFlags & MessageManagerFlags::MM_BROADCASTER), - mOwnsCallback(aFlags & MessageManagerFlags::MM_OWNSCALLBACK), - mHandlingMessage(false), - mClosed(false), - mDisconnected(false), - mCallback(aCallback) -{ +nsFrameMessageManager::nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback, + nsFrameMessageManager* aParentManager, + /* mozilla::dom::ipc::MessageManagerFlags */ uint32_t aFlags) + : mChrome(!!(aFlags & mozilla::dom::ipc::MM_CHROME)), + mGlobal(!!(aFlags & mozilla::dom::ipc::MM_GLOBAL)), + mIsProcessManager(!!(aFlags & mozilla::dom::ipc::MM_PROCESSMANAGER)), + mIsBroadcaster(!!(aFlags & mozilla::dom::ipc::MM_BROADCASTER)), + mOwnsCallback(!!(aFlags & mozilla::dom::ipc::MM_OWNSCALLBACK)), + mHandlingMessage(false), + mClosed(false), + mDisconnected(false), + mCallback(aCallback), + mParentManager(aParentManager) +{ + NS_ASSERTION(mChrome || !aParentManager, "Should not set parent manager!"); NS_ASSERTION(!mIsBroadcaster || !mCallback, "Broadcasters cannot have callbacks!"); + if (mIsProcessManager && (!mChrome || IsBroadcaster())) { + mozilla::HoldJSObjects(this); + } + // This is a bit hackish. When parent manager is global, we want + // to attach the message manager to it immediately. + // Is it just the frame message manager which waits until the + // content process is running. + if (mParentManager && (mCallback || IsBroadcaster())) { + mParentManager->AddChildManager(this); + } if (mOwnsCallback) { mOwnedCallback = aCallback; } @@ -97,8 +105,12 @@ nsFrameMessageManager::nsFrameMessageManager(MessageManagerCallback* aCallback, nsFrameMessageManager::~nsFrameMessageManager() { - for (int32_t i = mChildManagers.Length(); i > 0; --i) { - mChildManagers[i - 1]->Disconnect(false); + if (mIsProcessManager && (!mChrome || IsBroadcaster())) { + mozilla::DropJSObjects(this); + } + for (int32_t i = mChildManagers.Count(); i > 0; --i) { + static_cast(mChildManagers[i - 1])-> + Disconnect(false); } if (mIsProcessManager) { if (this == sParentProcessManager) { @@ -117,8 +129,16 @@ nsFrameMessageManager::~nsFrameMessageManager() NS_IMPL_CYCLE_COLLECTION_CLASS(nsFrameMessageManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFrameMessageManager) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListeners) + for (auto iter = tmp->mListeners.Iter(); !iter.Done(); iter.Next()) { + nsAutoTObserverArray* listeners = iter.UserData(); + uint32_t count = listeners->Length(); + for (uint32_t i = 0; i < count; ++i) { + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "listeners[i] mStrongListener"); + cb.NoteXPCOMChild(listeners->ElementAt(i).mStrongListener.get()); + } + } NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildManagers) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsFrameMessageManager) @@ -126,11 +146,13 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsFrameMessageManager) NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFrameMessageManager) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mListeners) - for (int32_t i = tmp->mChildManagers.Length(); i > 0; --i) { - tmp->mChildManagers[i - 1]->Disconnect(false); + tmp->mListeners.Clear(); + for (int32_t i = tmp->mChildManagers.Count(); i > 0; --i) { + static_cast(tmp->mChildManagers[i - 1])-> + Disconnect(false); } NS_IMPL_CYCLE_COLLECTION_UNLINK(mChildManagers) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentManager) tmp->mInitialProcessData.setNull(); NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -173,6 +195,10 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFrameMessageManager) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIGlobalProcessScriptLoader, mChrome && mIsProcessManager && mIsBroadcaster) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(ChromeMessageBroadcaster, + mChrome && mIsBroadcaster) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(ChromeMessageSender, + mChrome && !mIsBroadcaster) NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameMessageManager) @@ -222,28 +248,10 @@ SameProcessCpowHolder::ToObject(JSContext* aCx, // nsIMessageListenerManager -void -nsFrameMessageManager::AddMessageListener(const nsAString& aMessageName, - MessageListener& aListener, - bool aListenWhenClosed, - ErrorResult& aError) -{ - AddMessageListener(aMessageName, MessageListenerHolder(&aListener), aListenWhenClosed); -} - NS_IMETHODIMP nsFrameMessageManager::AddMessageListener(const nsAString& aMessage, nsIMessageListener* aListener, bool aListenWhenClosed) -{ - AddMessageListener(aMessage, MessageListenerHolder(aListener), aListenWhenClosed); - return NS_OK; -} - -void -nsFrameMessageManager::AddMessageListener(const nsAString& aMessage, - MessageListenerHolder&& aListener, - bool aListenWhenClosed) { auto listeners = mListeners.LookupForAdd(aMessage).OrInsert([]() { return new nsAutoTObserverArray(); @@ -251,66 +259,35 @@ nsFrameMessageManager::AddMessageListener(const nsAString& aMessage, uint32_t len = listeners->Length(); for (uint32_t i = 0; i < len; ++i) { if (listeners->ElementAt(i).mStrongListener == aListener) { - return; + return NS_OK; } } nsMessageListenerInfo* entry = listeners->AppendElement(); - entry->mStrongListener = Move(aListener); + NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY); + entry->mStrongListener = aListener; entry->mListenWhenClosed = aListenWhenClosed; -} - -void -nsFrameMessageManager::RemoveMessageListener(const nsAString& aMessageName, - MessageListener& aListener, - ErrorResult& aError) -{ - RemoveMessageListener(aMessageName, MessageListenerHolder(&aListener)); + return NS_OK; } NS_IMETHODIMP nsFrameMessageManager::RemoveMessageListener(const nsAString& aMessage, nsIMessageListener* aListener) -{ - RemoveMessageListener(aMessage, MessageListenerHolder(aListener)); - return NS_OK; -} - -void -nsFrameMessageManager::RemoveMessageListener(const nsAString& aMessage, - const MessageListenerHolder& aListener) { nsAutoTObserverArray* listeners = mListeners.Get(aMessage); - if (listeners) { - uint32_t len = listeners->Length(); - for (uint32_t i = 0; i < len; ++i) { - if (listeners->ElementAt(i).mStrongListener == aListener) { - listeners->RemoveElementAt(i); - return; - } - } + if (!listeners) { + return NS_OK; } -} -static already_AddRefed -ToXPCOMMessageListener(MessageListener& aListener) -{ - return MessageListenerHolder(&aListener).ToXPCOMCallback(); -} - -void -nsFrameMessageManager::AddWeakMessageListener(const nsAString& aMessageName, - MessageListener& aListener, - ErrorResult& aError) -{ - nsCOMPtr listener(ToXPCOMMessageListener(aListener)); - if (!listener) { - aError.Throw(NS_ERROR_FAILURE); - return; + uint32_t len = listeners->Length(); + for (uint32_t i = 0; i < len; ++i) { + if (listeners->ElementAt(i).mStrongListener == aListener) { + listeners->RemoveElementAt(i); + return NS_OK; + } } - - aError = AddWeakMessageListener(aMessageName, listener); + return NS_OK; } NS_IMETHODIMP @@ -355,20 +332,6 @@ nsFrameMessageManager::AddWeakMessageListener(const nsAString& aMessage, return NS_OK; } -void -nsFrameMessageManager::RemoveWeakMessageListener(const nsAString& aMessageName, - MessageListener& aListener, - ErrorResult& aError) -{ - nsCOMPtr listener(ToXPCOMMessageListener(aListener)); - if (!listener) { - aError.Throw(NS_ERROR_FAILURE); - return; - } - - aError = RemoveWeakMessageListener(aMessageName, listener); -} - NS_IMETHODIMP nsFrameMessageManager::RemoveWeakMessageListener(const nsAString& aMessage, nsIMessageListener* aListener) @@ -395,11 +358,10 @@ nsFrameMessageManager::RemoveWeakMessageListener(const nsAString& aMessage, // nsIFrameScriptLoader -void +NS_IMETHODIMP nsFrameMessageManager::LoadScript(const nsAString& aURL, bool aAllowDelayedLoad, - bool aRunInGlobalScope, - ErrorResult& aError) + bool aRunInGlobalScope) { if (aAllowDelayedLoad) { // Cache for future windows or frames @@ -411,23 +373,23 @@ nsFrameMessageManager::LoadScript(const nsAString& aURL, #ifdef DEBUG_smaug printf("Will load %s \n", NS_ConvertUTF16toUTF8(aURL).get()); #endif - if (!mCallback->DoLoadMessageManagerScript(aURL, aRunInGlobalScope)) { - aError.Throw(NS_ERROR_FAILURE); - return; - } + NS_ENSURE_TRUE(mCallback->DoLoadMessageManagerScript(aURL, aRunInGlobalScope), + NS_ERROR_FAILURE); } - for (uint32_t i = 0; i < mChildManagers.Length(); ++i) { - RefPtr mm = mChildManagers[i]; + for (int32_t i = 0; i < mChildManagers.Count(); ++i) { + RefPtr mm = + static_cast(mChildManagers[i]); if (mm) { // Use false here, so that child managers don't cache the script, which // is already cached in the parent. - mm->LoadScript(aURL, false, aRunInGlobalScope, IgnoreErrors()); + mm->LoadScript(aURL, false, aRunInGlobalScope); } } + return NS_OK; } -void +NS_IMETHODIMP nsFrameMessageManager::RemoveDelayedScript(const nsAString& aURL) { for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) { @@ -437,55 +399,41 @@ nsFrameMessageManager::RemoveDelayedScript(const nsAString& aURL) break; } } + return NS_OK; } -void -nsFrameMessageManager::GetDelayedScripts(JSContext* aCx, - nsTArray>& aList, - ErrorResult& aError) +NS_IMETHODIMP +nsFrameMessageManager::GetDelayedScripts(JSContext* aCx, JS::MutableHandle aList) { // Frame message managers may return an incomplete list because scripts // that were loaded after it was connected are not added to the list. if (!IsGlobal() && !IsBroadcaster()) { NS_WARNING("Cannot retrieve list of pending frame scripts for frame" "message managers as it may be incomplete"); - aError.Throw(NS_ERROR_NOT_IMPLEMENTED); - return; + return NS_ERROR_NOT_IMPLEMENTED; } - aError.MightThrowJSException(); + JS::Rooted array(aCx, JS_NewArrayObject(aCx, mPendingScripts.Length())); + NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY); - aList.SetCapacity(mPendingScripts.Length()); + JS::Rooted url(aCx); + JS::Rooted pair(aCx); for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) { - JS::Rooted url(aCx); - if (!ToJSValue(aCx, mPendingScripts[i], &url)) { - aError.NoteJSContextException(aCx); - return; - } + url = JS_NewUCStringCopyN(aCx, mPendingScripts[i].get(), mPendingScripts[i].Length()); + NS_ENSURE_TRUE(url, NS_ERROR_OUT_OF_MEMORY); - nsTArray* array = aList.AppendElement(2); - array->AppendElement(url); - array->AppendElement(JS::BooleanValue(mPendingScriptsGlobalStates[i])); - } -} + JS::AutoValueArray<2> pairElts(aCx); + pairElts[0].setString(url); + pairElts[1].setBoolean(mPendingScriptsGlobalStates[i]); -nsresult -nsFrameMessageManager::GetDelayedScripts(JSContext* aCx, - JS::MutableHandle aList) -{ - ErrorResult rv; - nsTArray> list; - SequenceRooter> listRooter(aCx, &list); - GetDelayedScripts(aCx, list, rv); - rv.WouldReportJSException(); - if (rv.Failed()) { - return rv.StealNSResult(); - } + pair = JS_NewArrayObject(aCx, pairElts); + NS_ENSURE_TRUE(pair, NS_ERROR_OUT_OF_MEMORY); - if (!ToJSValue(aCx, list, aList)) { - return NS_ERROR_OUT_OF_MEMORY; + NS_ENSURE_TRUE(JS_DefineElement(aCx, array, i, pair, JSPROP_ENUMERATE), + NS_ERROR_OUT_OF_MEMORY); } + aList.setObject(*array); return NS_OK; } @@ -496,16 +444,13 @@ nsFrameMessageManager::LoadFrameScript(const nsAString& aURL, bool aAllowDelayedLoad, bool aRunInGlobalScope) { - ErrorResult rv; - LoadScript(aURL, aAllowDelayedLoad, aRunInGlobalScope, rv); - return rv.StealNSResult(); + return LoadScript(aURL, aAllowDelayedLoad, aRunInGlobalScope); } NS_IMETHODIMP nsFrameMessageManager::RemoveDelayedFrameScript(const nsAString& aURL) { - RemoveDelayedScript(aURL); - return NS_OK; + return RemoveDelayedScript(aURL); } NS_IMETHODIMP @@ -520,16 +465,13 @@ NS_IMETHODIMP nsFrameMessageManager::LoadProcessScript(const nsAString& aURL, bool aAllowDelayedLoad) { - ErrorResult rv; - LoadScript(aURL, aAllowDelayedLoad, false, rv); - return rv.StealNSResult(); + return LoadScript(aURL, aAllowDelayedLoad, false); } NS_IMETHODIMP nsFrameMessageManager::RemoveDelayedProcessScript(const nsAString& aURL) { - RemoveDelayedScript(aURL); - return NS_OK; + return RemoveDelayedScript(aURL); } NS_IMETHODIMP @@ -662,7 +604,12 @@ nsFrameMessageManager::SendMessage(const nsAString& aMessageName, AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING( "nsFrameMessageManager::SendMessage", EVENTS, aMessageName); + NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome"); + NS_ASSERTION(!IsBroadcaster(), "Should not call SendSyncMessage in chrome"); + NS_ASSERTION(!mParentManager, "Should not have parent manager in content!"); + aRetval.setUndefined(); + NS_ENSURE_TRUE(mCallback, NS_ERROR_NOT_INITIALIZED); if (sSendingSyncMessage && aIsSync) { // No kind of blocking send should be issued on top of a sync message. @@ -674,98 +621,30 @@ nsFrameMessageManager::SendMessage(const nsAString& aMessageName, return NS_ERROR_DOM_DATA_CLONE_ERR; } - JS::Rooted objects(aCx); - if (aArgc >= 3 && aObjects.isObject()) { - objects = &aObjects.toObject(); - } - - nsTArray result; - SequenceRooter resultRooter(aCx, &result); - ErrorResult rv; - SendMessage(aCx, aMessageName, data, objects, aPrincipal, aIsSync, result, rv); - rv.WouldReportJSException(); - if (rv.Failed()) { - return rv.StealNSResult(); - } - - JS::Rooted dataArray(aCx); - if (!ToJSValue(aCx, result, aRetval)) { - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -void -nsFrameMessageManager::SendMessage(JSContext* aCx, - const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - bool aIsSync, - nsTArray& aResult, - ErrorResult& aError) -{ - AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING( - "nsFrameMessageManager::SendMessage", EVENTS, aMessageName); - - if (sSendingSyncMessage && aIsSync) { - // No kind of blocking send should be issued on top of a sync message. - aError.Throw(NS_ERROR_UNEXPECTED); - return; - } - - StructuredCloneData data; - if (!aObj.isUndefined() && - !GetParamsForMessage(aCx, aObj, JS::UndefinedHandleValue, data)) { - aError.Throw(NS_ERROR_DOM_DATA_CLONE_ERR); - return; - } - - SendMessage(aCx, aMessageName, data, aObjects, aPrincipal, aIsSync, aResult, - aError); -} - -void -nsFrameMessageManager::SendMessage(JSContext* aCx, - const nsAString& aMessageName, - StructuredCloneData& aData, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - bool aIsSync, - nsTArray& aResult, - ErrorResult& aError) -{ - NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome"); - NS_ASSERTION(!IsBroadcaster(), "Should not call SendSyncMessage in chrome"); - NS_ASSERTION(!GetParentManager(), - "Should not have parent manager in content!"); - - if (!AllowMessage(aData.DataLength(), aMessageName)) { - aError.Throw(NS_ERROR_FAILURE); - return; - } - #ifdef FUZZING - if (aData.DataLength() > 0) { + if (data.DataLength() > 0) { MessageManagerFuzzer::TryMutate( aCx, aMessageName, - &aData, + &data, JS::UndefinedHandleValue); } #endif - if (!mCallback) { - aError.Throw(NS_ERROR_NOT_INITIALIZED); - return; + if (!AllowMessage(data.DataLength(), aMessageName)) { + return NS_ERROR_FAILURE; + } + + JS::Rooted objects(aCx); + if (aArgc >= 3 && aObjects.isObject()) { + objects = &aObjects.toObject(); } nsTArray retval; TimeStamp start = TimeStamp::Now(); sSendingSyncMessage |= aIsSync; - bool ok = mCallback->DoSendBlockingMessage(aCx, aMessageName, aData, aObjects, + bool ok = mCallback->DoSendBlockingMessage(aCx, aMessageName, data, objects, aPrincipal, &retval, aIsSync); if (aIsSync) { sSendingSyncMessage = false; @@ -783,20 +662,29 @@ nsFrameMessageManager::SendMessage(JSContext* aCx, } if (!ok) { - return; + return NS_OK; } uint32_t len = retval.Length(); - aResult.SetCapacity(len); + JS::Rooted dataArray(aCx, JS_NewArrayObject(aCx, len)); + NS_ENSURE_TRUE(dataArray, NS_ERROR_OUT_OF_MEMORY); + for (uint32_t i = 0; i < len; ++i) { JS::Rooted ret(aCx); - retval[i].Read(aCx, &ret, aError); - if (aError.Failed()) { + ErrorResult rv; + retval[i].Read(aCx, &ret, rv); + if (rv.Failed()) { MOZ_ASSERT(false, "Unable to read structured clone in SendMessage"); - return; + rv.SuppressException(); + return NS_ERROR_UNEXPECTED; } - aResult.AppendElement(ret); + + NS_ENSURE_TRUE(JS_DefineElement(aCx, dataArray, i, ret, JSPROP_ENUMERATE), + NS_ERROR_OUT_OF_MEMORY); } + + aRetval.setObject(*dataArray); + return NS_OK; } nsresult @@ -807,9 +695,9 @@ nsFrameMessageManager::DispatchAsyncMessageInternal(JSContext* aCx, nsIPrincipal* aPrincipal) { if (mIsBroadcaster) { - uint32_t len = mChildManagers.Length(); - for (uint32_t i = 0; i < len; ++i) { - mChildManagers[i]-> + int32_t len = mChildManagers.Count(); + for (int32_t i = 0; i < len; ++i) { + static_cast(mChildManagers[i])-> DispatchAsyncMessageInternal(aCx, aMessage, aData, aCpows, aPrincipal); } return NS_OK; @@ -859,25 +747,6 @@ nsFrameMessageManager::DispatchAsyncMessage(const nsAString& aMessageName, aPrincipal); } -void -nsFrameMessageManager::DispatchAsyncMessage(JSContext* aCx, - const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - JS::Handle aTransfers, - ErrorResult& aError) -{ - StructuredCloneData data; - if (!aObj.isUndefined() && !GetParamsForMessage(aCx, aObj, aTransfers, data)) { - aError.Throw(NS_ERROR_DOM_DATA_CLONE_ERR); - return; - } - - aError = DispatchAsyncMessageInternal(aCx, aMessageName, data, aObjects, - aPrincipal); -} - // nsIMessageSender NS_IMETHODIMP @@ -910,7 +779,7 @@ nsFrameMessageManager::BroadcastAsyncMessage(const nsAString& aMessageName, NS_IMETHODIMP nsFrameMessageManager::GetChildCount(uint32_t* aChildCount) { - *aChildCount = mChildManagers.Length(); + *aChildCount = static_cast(mChildManagers.Count()); return NS_OK; } @@ -918,12 +787,10 @@ NS_IMETHODIMP nsFrameMessageManager::GetChildAt(uint32_t aIndex, nsIMessageListenerManager** aMM) { - MessageListenerManager* mm = mChildManagers.SafeElementAt(aIndex); - if (mm) { - CallQueryInterface(mm, aMM); - } else { - *aMM = nullptr; - } + *aMM = nullptr; + nsCOMPtr mm = + do_QueryInterface(mChildManagers.SafeObjectAt(static_cast(aIndex))); + mm.swap(*aMM); return NS_OK; } @@ -1052,8 +919,6 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, nsIPrincipal* aPrincipal, nsTArray* aRetVal) { - MOZ_ASSERT(aTarget); - nsAutoTObserverArray* listeners = mListeners.Get(aMessage); if (listeners) { @@ -1078,41 +943,33 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, continue; } - JS::RootingContext* rcx = RootingCx(); - JS::Rooted object(rcx); - - RefPtr webIDLListener; - if (!weakListener && listener.mStrongListener.HasWebIDLCallback()) { - webIDLListener = listener.mStrongListener.GetWebIDLCallback(); + nsCOMPtr wrappedJS; + if (weakListener) { + wrappedJS = do_QueryInterface(weakListener); } else { - webIDLListener = nullptr; + wrappedJS = do_QueryInterface(listener.mStrongListener); } - if (webIDLListener) { - object = webIDLListener->CallbackOrNull(); - } else { - nsCOMPtr wrappedJS; - if (weakListener) { - wrappedJS = do_QueryInterface(weakListener); - } else { - wrappedJS = do_QueryInterface(listener.mStrongListener.GetXPCOMCallback()); - } - - if (!wrappedJS) { - continue; - } - - object = wrappedJS->GetJSObject(); + if (!wrappedJS) { + continue; } - if (!object) { + if (!wrappedJS->GetJSObject()) { continue; } - AutoEntryScript aes(object, "message manager handler"); + AutoEntryScript aes(wrappedJS->GetJSObject(), "message manager handler"); JSContext* cx = aes.cx(); + JS::Rooted object(cx, wrappedJS->GetJSObject()); - RootedDictionary argument(cx); + // The parameter for the listener function. + JS::Rooted param(cx, JS_NewPlainObject(cx)); + NS_ENSURE_TRUE(param, NS_ERROR_OUT_OF_MEMORY); + + JS::Rooted targetv(cx); + js::AssertSameCompartment(cx, object); + nsresult rv = nsContentUtils::WrapNative(cx, aTarget, &targetv); + NS_ENSURE_SUCCESS(rv, rv); JS::Rooted cpows(cx); if (aCpows) { @@ -1127,7 +984,8 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, return NS_ERROR_UNEXPECTED; } } - argument.mObjects = cpows; + + JS::Rooted cpowsv(cx, JS::ObjectValue(*cpows)); JS::Rooted json(cx, JS::NullValue()); if (aCloneData && aCloneData->DataLength()) { @@ -1139,29 +997,70 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, return NS_OK; } } - argument.mData = json; - argument.mJson = json; // Get cloned MessagePort from StructuredCloneData. + nsTArray> ports; if (aCloneData) { - Sequence> ports; - if (!aCloneData->TakeTransferredPortsAsSequence(ports)) { - return NS_ERROR_FAILURE; - } - argument.mPorts.Construct(Move(ports)); + ports = aCloneData->TakeTransferredPorts(); + } + + JS::Rooted transferredList(cx); + if (NS_WARN_IF(!ToJSValue(cx, ports, &transferredList))) { + return NS_ERROR_UNEXPECTED; } - argument.mName = aMessage; - argument.mPrincipal = aPrincipal; - argument.mSync = aIsSync; - argument.mTarget = aTarget; + JS::Rooted jsMessage(cx, + JS_NewUCStringCopyN(cx, + static_cast(aMessage.BeginReading()), + aMessage.Length())); + NS_ENSURE_TRUE(jsMessage, NS_ERROR_OUT_OF_MEMORY); + JS::Rooted syncv(cx, JS::BooleanValue(aIsSync)); + bool ok = JS_DefineProperty(cx, param, "target", targetv, JSPROP_ENUMERATE) && + JS_DefineProperty(cx, param, "name", jsMessage, JSPROP_ENUMERATE) && + JS_DefineProperty(cx, param, "sync", syncv, JSPROP_ENUMERATE) && + JS_DefineProperty(cx, param, "json", json, JSPROP_ENUMERATE) && // deprecated + JS_DefineProperty(cx, param, "data", json, JSPROP_ENUMERATE) && + JS_DefineProperty(cx, param, "objects", cpowsv, JSPROP_ENUMERATE) && + JS_DefineProperty(cx, param, "ports", transferredList, JSPROP_ENUMERATE); + + NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED); + if (aTargetFrameLoader) { - argument.mTargetFrameLoader.Construct(aTargetFrameLoader); + JS::Rooted targetFrameLoaderv(cx); + nsresult rv = nsContentUtils::WrapNative(cx, aTargetFrameLoader, &targetFrameLoaderv); + NS_ENSURE_SUCCESS(rv, rv); + + ok = JS_DefineProperty(cx, param, "targetFrameLoader", targetFrameLoaderv, + JSPROP_ENUMERATE); + NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED); + } + + // message.principal == null + if (!aPrincipal) { + bool ok = JS_DefineProperty(cx, param, "principal", + JS::UndefinedHandleValue, JSPROP_ENUMERATE); + NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED); + } + + // message.principal = the principal + else { + JS::Rooted principalValue(cx); + nsresult rv = nsContentUtils::WrapNative(cx, aPrincipal, + &NS_GET_IID(nsIPrincipal), + &principalValue); + NS_ENSURE_SUCCESS(rv, rv); + bool ok = JS_DefineProperty(cx, param, "principal", principalValue, + JSPROP_ENUMERATE); + NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED); } JS::Rooted thisValue(cx, JS::UndefinedValue()); + JS::Rooted funval(cx); if (JS::IsCallable(object)) { + // If the listener is a JS function: + funval.setObject(*object); + // A small hack to get 'this' value right on content side where // messageManager is wrapped in TabChildGlobal. nsCOMPtr defaultThisValue; @@ -1173,77 +1072,58 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, js::AssertSameCompartment(cx, object); nsresult rv = nsContentUtils::WrapNative(cx, defaultThisValue, &thisValue); NS_ENSURE_SUCCESS(rv, rv); + } else { + // If the listener is a JS object which has receiveMessage function: + if (!JS_GetProperty(cx, object, "receiveMessage", &funval) || + !funval.isObject()) { + return NS_ERROR_UNEXPECTED; + } + + // Check if the object is even callable. + NS_ENSURE_STATE(JS::IsCallable(&funval.toObject())); + thisValue.setObject(*object); } JS::Rooted rval(cx, JS::UndefinedValue()); - if (webIDLListener) { - ErrorResult rv; - webIDLListener->ReceiveMessage(thisValue, argument, &rval, rv); - if (rv.Failed()) { - // At this point the call to ReceiveMessage will have reported any exceptions - // (we kept the default of eReportExceptions). We suppress the failure in the - // ErrorResult and continue. - rv.SuppressException(); - continue; - } - } else { - JS::Rooted funval(cx); - if (JS::IsCallable(object)) { - // If the listener is a JS function: - funval.setObject(*object); - } else { - // If the listener is a JS object which has receiveMessage function: - if (!JS_GetProperty(cx, object, "receiveMessage", &funval) || - !funval.isObject()) { - return NS_ERROR_UNEXPECTED; - } + JS::Rooted argv(cx, JS::ObjectValue(*param)); - // Check if the object is even callable. - NS_ENSURE_STATE(JS::IsCallable(&funval.toObject())); - thisValue.setObject(*object); - } + { + JS::Rooted thisObject(cx, thisValue.toObjectOrNull()); - JS::Rooted argv(cx); - if (!ToJSValue(cx, argument, &argv)) { + JSAutoCompartment tac(cx, thisObject); + if (!JS_WrapValue(cx, &argv)) { return NS_ERROR_UNEXPECTED; } - { - JS::Rooted thisObject(cx, thisValue.toObjectOrNull()); - js::AssertSameCompartment(cx, thisObject); - if (!JS_CallFunctionValue(cx, thisObject, funval, - JS::HandleValueArray(argv), &rval)) { - // Because the AutoEntryScript is inside the loop this continue will make us - // report any exceptions (after which we'll move on to the next listener). - continue; - } + if (!JS_CallFunctionValue(cx, thisObject, funval, + JS::HandleValueArray(argv), &rval)) { + continue; } - } - - if (aRetVal) { - ErrorResult rv; - StructuredCloneData* data = aRetVal->AppendElement(); - data->Write(cx, rval, rv); - if (NS_WARN_IF(rv.Failed())) { - aRetVal->RemoveElementAt(aRetVal->Length() - 1); - nsString msg = aMessage + NS_LITERAL_STRING(": message reply cannot be cloned. Are you trying to send an XPCOM object?"); - - nsCOMPtr console(do_GetService(NS_CONSOLESERVICE_CONTRACTID)); - if (console) { - nsCOMPtr error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID)); - error->Init(msg, EmptyString(), EmptyString(), - 0, 0, nsIScriptError::warningFlag, "chrome javascript"); - console->LogMessage(error); + if (aRetVal) { + ErrorResult rv; + StructuredCloneData* data = aRetVal->AppendElement(); + data->Write(cx, rval, rv); + if (NS_WARN_IF(rv.Failed())) { + aRetVal->RemoveElementAt(aRetVal->Length() - 1); + nsString msg = aMessage + NS_LITERAL_STRING(": message reply cannot be cloned. Are you trying to send an XPCOM object?"); + + nsCOMPtr console(do_GetService(NS_CONSOLESERVICE_CONTRACTID)); + if (console) { + nsCOMPtr error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID)); + error->Init(msg, EmptyString(), EmptyString(), + 0, 0, nsIScriptError::warningFlag, "chrome javascript"); + console->LogMessage(error); + } + + JS_ClearPendingException(cx); + continue; } - - JS_ClearPendingException(cx); - continue; } } } } - RefPtr kungFuDeathGrip = GetParentManager(); + RefPtr kungFuDeathGrip = mParentManager; if (kungFuDeathGrip) { return kungFuDeathGrip->ReceiveMessage(aTarget, aTargetFrameLoader, aTargetClosed, aMessage, @@ -1255,9 +1135,9 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget, } void -nsFrameMessageManager::AddChildManager(MessageListenerManager* aManager) +nsFrameMessageManager::AddChildManager(nsFrameMessageManager* aManager) { - mChildManagers.AppendElement(aManager); + mChildManagers.AppendObject(aManager); RefPtr kungfuDeathGrip = this; RefPtr kungfuDeathGrip2 = aManager; @@ -1265,12 +1145,6 @@ nsFrameMessageManager::AddChildManager(MessageListenerManager* aManager) LoadPendingScripts(this, aManager); } -void -nsFrameMessageManager::RemoveChildManager(MessageListenerManager* aManager) -{ - mChildManagers.RemoveElement(aManager); -} - void nsFrameMessageManager::LoadPendingScripts(nsFrameMessageManager* aManager, nsFrameMessageManager* aChildMM) @@ -1279,9 +1153,8 @@ nsFrameMessageManager::LoadPendingScripts(nsFrameMessageManager* aManager, // In that case we want to load the pending scripts from all parent // message managers in the hierarchy. Process the parent first so // that pending scripts higher up in the hierarchy are loaded before others. - nsFrameMessageManager* parentManager = aManager->GetParentManager(); - if (parentManager) { - LoadPendingScripts(parentManager, aChildMM); + if (aManager->mParentManager) { + LoadPendingScripts(aManager->mParentManager, aChildMM); } for (uint32_t i = 0; i < aManager->mPendingScripts.Length(); ++i) { @@ -1311,6 +1184,37 @@ nsFrameMessageManager::SetCallback(MessageManagerCallback* aCallback) } } +void +nsFrameMessageManager::InitWithCallback(MessageManagerCallback* aCallback) +{ + if (mCallback) { + // Initialization should only happen once. + return; + } + + SetCallback(aCallback); + + // First load parent scripts by adding this to parent manager. + if (mParentManager) { + mParentManager->AddChildManager(this); + } + + for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) { + LoadFrameScript(mPendingScripts[i], false, mPendingScriptsGlobalStates[i]); + } +} + +void +nsFrameMessageManager::RemoveFromParent() +{ + if (mParentManager) { + mParentManager->RemoveChildManager(this); + } + mParentManager = nullptr; + mCallback = nullptr; + mOwnedCallback = nullptr; +} + void nsFrameMessageManager::Close() { @@ -1339,10 +1243,11 @@ nsFrameMessageManager::Disconnect(bool aRemoveFromParent) "message-manager-disconnect", nullptr); } } - - ClearParentManager(aRemoveFromParent); - + if (mParentManager && aRemoveFromParent) { + mParentManager->RemoveChildManager(this); + } mDisconnected = true; + mParentManager = nullptr; if (!mHandlingMessage) { mListeners.Clear(); } @@ -1353,14 +1258,11 @@ nsFrameMessageManager::SetInitialProcessData(JS::HandleValue aInitialData) { MOZ_ASSERT(!mChrome); MOZ_ASSERT(mIsProcessManager); - MOZ_ASSERT(aInitialData.isObject()); mInitialProcessData = aInitialData; } -void -nsFrameMessageManager::GetInitialProcessData(JSContext* aCx, - JS::MutableHandle aInitialProcessData, - ErrorResult& aError) +NS_IMETHODIMP +nsFrameMessageManager::GetInitialProcessData(JSContext* aCx, JS::MutableHandleValue aResult) { MOZ_ASSERT(mIsProcessManager); MOZ_ASSERT_IF(mChrome, IsBroadcaster()); @@ -1374,8 +1276,7 @@ nsFrameMessageManager::GetInitialProcessData(JSContext* aCx, JS::RootedObject obj(aCx, JS_NewPlainObject(aCx)); if (!obj) { - aError.NoteJSContextException(aCx); - return; + return NS_ERROR_OUT_OF_MEMORY; } mInitialProcessData.setObject(*obj); @@ -1391,53 +1292,31 @@ nsFrameMessageManager::GetInitialProcessData(JSContext* aCx, } if (!JS_WrapValue(aCx, &init)) { - aError.NoteJSContextException(aCx); - return; + return NS_ERROR_OUT_OF_MEMORY; } - aInitialProcessData.set(init); + aResult.set(init); + return NS_OK; } NS_IMETHODIMP -nsFrameMessageManager::GetInitialProcessData(JSContext* aCx, JS::MutableHandleValue aResult) -{ - ErrorResult rv; - GetInitialProcessData(aCx, aResult, rv); - return rv.StealNSResult(); -} - -already_AddRefed -nsFrameMessageManager::GetProcessMessageManager(ErrorResult& aError) +nsFrameMessageManager::GetProcessMessageManager(nsIMessageSender** aPMM) { - nsCOMPtr pmm; + *aPMM = nullptr; if (mCallback) { - pmm = mCallback->GetProcessMessageManager(); + nsCOMPtr pmm = mCallback->GetProcessMessageManager(); + pmm.swap(*aPMM); } - return pmm.forget(); + return NS_OK; } NS_IMETHODIMP -nsFrameMessageManager::GetProcessMessageManager(nsIMessageSender** aPMM) -{ - ErrorResult rv; - *aPMM = GetProcessMessageManager(rv).take(); - return rv.StealNSResult(); -} - -void -nsFrameMessageManager::GetRemoteType(nsAString& aRemoteType, ErrorResult& aError) const +nsFrameMessageManager::GetRemoteType(nsAString& aRemoteType) { aRemoteType.Truncate(); if (mCallback) { - aError = mCallback->DoGetRemoteType(aRemoteType); + return mCallback->DoGetRemoteType(aRemoteType); } -} - -NS_IMETHODIMP -nsFrameMessageManager::GetRemoteType(nsAString& aRemoteType) -{ - ErrorResult rv; - GetRemoteType(aRemoteType, rv); - return rv.StealNSResult(); + return NS_OK; } namespace { @@ -1516,7 +1395,8 @@ MessageManagerReporter::CountReferents(nsFrameMessageManager* aMessageManager, // Add referent count in child managers because the listeners // participate in messages dispatched from parent message manager. for (uint32_t i = 0; i < aMessageManager->mChildManagers.Length(); ++i) { - RefPtr mm = aMessageManager->mChildManagers[i]; + RefPtr mm = + static_cast(aMessageManager->mChildManagers[i]); CountReferents(mm, aReferentCount); } } @@ -1604,8 +1484,9 @@ NS_NewGlobalMessageManager(nsIMessageBroadcaster** aResult) { NS_ENSURE_TRUE(XRE_IsParentProcess(), NS_ERROR_NOT_AVAILABLE); - RefPtr mm = - new ChromeMessageBroadcaster(MessageManagerFlags::MM_GLOBAL); + RefPtr mm = new nsFrameMessageManager(nullptr, + nullptr, + MM_CHROME | MM_GLOBAL | MM_BROADCASTER); RegisterStrongMemoryReporter(new MessageManagerReporter()); mm.forget(aResult); return NS_OK; @@ -1618,6 +1499,7 @@ StaticRefPtr nsMessageManagerScriptExecutor::sScriptCacheC void nsMessageManagerScriptExecutor::DidCreateGlobal() { + NS_ASSERTION(mGlobal, "Should have mGlobal!"); if (!sCachedScripts) { sCachedScripts = new nsDataHashtable; @@ -1652,14 +1534,13 @@ nsMessageManagerScriptExecutor::Shutdown() } void -nsMessageManagerScriptExecutor::LoadScriptInternal(JS::Handle aGlobal, - const nsAString& aURL, +nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL, bool aRunInGlobalScope) { AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING( "nsMessageManagerScriptExecutor::LoadScriptInternal", OTHER, aURL); - if (!sCachedScripts) { + if (!mGlobal || !sCachedScripts) { return; } @@ -1677,18 +1558,21 @@ nsMessageManagerScriptExecutor::LoadScriptInternal(JS::Handle aGlobal shouldCache, &script); } - AutoEntryScript aes(aGlobal, "message manager script load"); - JSContext* cx = aes.cx(); - if (script) { - if (aRunInGlobalScope) { - JS::RootedValue rval(cx); - JS::CloneAndExecuteScript(cx, script, &rval); - } else { - JS::Rooted scope(cx); - bool ok = js::ExecuteInGlobalAndReturnScope(cx, aGlobal, script, &scope); - if (ok) { - // Force the scope to stay alive. - mAnonymousGlobalScopes.AppendElement(scope); + JS::Rooted global(rcx, mGlobal); + if (global) { + AutoEntryScript aes(global, "message manager script load"); + JSContext* cx = aes.cx(); + if (script) { + if (aRunInGlobalScope) { + JS::RootedValue rval(cx); + JS::CloneAndExecuteScript(cx, script, &rval); + } else { + JS::Rooted scope(cx); + bool ok = js::ExecuteInGlobalAndReturnScope(cx, global, script, &scope); + if (ok) { + // Force the scope to stay alive. + mAnonymousGlobalScopes.AppendElement(scope); + } } } } @@ -1809,38 +1693,45 @@ nsMessageManagerScriptExecutor::Trace(const TraceCallbacks& aCallbacks, void* aC for (size_t i = 0, length = mAnonymousGlobalScopes.Length(); i < length; ++i) { aCallbacks.Trace(&mAnonymousGlobalScopes[i], "mAnonymousGlobalScopes[i]", aClosure); } + aCallbacks.Trace(&mGlobal, "mGlobal", aClosure); } void nsMessageManagerScriptExecutor::Unlink() { ImplCycleCollectionUnlink(mAnonymousGlobalScopes); + mGlobal = nullptr; } bool -nsMessageManagerScriptExecutor::InitChildGlobalInternal(const nsACString& aID) +nsMessageManagerScriptExecutor::InitChildGlobalInternal( + nsISupports* aScope, + const nsACString& aID) { AutoSafeJSContext cx; - if (!SystemBindingInitIds(cx)) { - return false; - } - nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal)); + const uint32_t flags = xpc::INIT_JS_STANDARD_CLASSES; + JS::CompartmentOptions options; options.creationOptions().setSystemZone(); - xpc::InitGlobalObjectOptions(options, mPrincipal); - JS::Rooted global(cx); - if (!WrapGlobalObject(cx, options, &global)) { - return false; + if (xpc::SharedMemoryEnabled()) { + options.creationOptions().setSharedMemoryAndAtomicsEnabled(true); } - xpc::InitGlobalObject(cx, global, 0); + JS::Rooted global(cx); + nsresult rv = xpc::InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal, + flags, options, + &global); + NS_ENSURE_SUCCESS(rv, false); + + mGlobal = global; + NS_ENSURE_TRUE(mGlobal, false); // Set the location information for the new global, so that tools like // about:memory may use that information. - xpc::SetLocationForGlobal(global, aID); + xpc::SetLocationForGlobal(mGlobal, aID); DidCreateGlobal(); return true; @@ -1856,7 +1747,7 @@ nsMessageManagerScriptExecutor::MarkScopesForCC() NS_IMPL_ISUPPORTS(nsScriptCacheCleaner, nsIObserver) -ChildProcessMessageManager* nsFrameMessageManager::sChildProcessManager = nullptr; +nsFrameMessageManager* nsFrameMessageManager::sChildProcessManager = nullptr; nsFrameMessageManager* nsFrameMessageManager::sParentProcessManager = nullptr; nsFrameMessageManager* nsFrameMessageManager::sSameProcessParentManager = nullptr; @@ -2077,8 +1968,9 @@ NS_NewParentProcessMessageManager(nsIMessageBroadcaster** aResult) { NS_ASSERTION(!nsFrameMessageManager::sParentProcessManager, "Re-creating sParentProcessManager"); - RefPtr mm = - new ChromeMessageBroadcaster(MessageManagerFlags::MM_PROCESSMANAGER); + RefPtr mm = new nsFrameMessageManager(nullptr, + nullptr, + MM_CHROME | MM_PROCESSMANAGER | MM_BROADCASTER); nsFrameMessageManager::sParentProcessManager = mm; nsFrameMessageManager::NewProcessMessageManager(false); // Create same process message manager. mm.forget(aResult); @@ -2086,7 +1978,7 @@ NS_NewParentProcessMessageManager(nsIMessageBroadcaster** aResult) } -ChromeMessageSender* +nsFrameMessageManager* nsFrameMessageManager::NewProcessMessageManager(bool aIsRemote) { if (!nsFrameMessageManager::sParentProcessManager) { @@ -2096,18 +1988,17 @@ nsFrameMessageManager::NewProcessMessageManager(bool aIsRemote) MOZ_ASSERT(nsFrameMessageManager::sParentProcessManager, "parent process manager not created"); - ChromeMessageSender* mm; + nsFrameMessageManager* mm; if (aIsRemote) { // Callback is set in ContentParent::InitInternal so that the process has // already started when we send pending scripts. - mm = new ChromeMessageSender(nullptr, - nsFrameMessageManager::sParentProcessManager, - MessageManagerFlags::MM_PROCESSMANAGER); + mm = new nsFrameMessageManager(nullptr, + nsFrameMessageManager::sParentProcessManager, + MM_CHROME | MM_PROCESSMANAGER); } else { - mm = new ChromeMessageSender(new SameParentProcessMessageManagerCallback(), - nsFrameMessageManager::sParentProcessManager, - MessageManagerFlags::MM_PROCESSMANAGER | - MessageManagerFlags::MM_OWNSCALLBACK); + mm = new nsFrameMessageManager(new SameParentProcessMessageManagerCallback(), + nsFrameMessageManager::sParentProcessManager, + MM_CHROME | MM_PROCESSMANAGER | MM_OWNSCALLBACK); sSameProcessParentManager = mm; } return mm; @@ -2126,7 +2017,8 @@ NS_NewChildProcessMessageManager(nsISyncMessageSender** aResult) cb = new ChildProcessMessageManagerCallback(); RegisterStrongMemoryReporter(new MessageManagerReporter()); } - auto* mm = new ChildProcessMessageManager(cb); + auto* mm = new nsFrameMessageManager(cb, nullptr, + MM_PROCESSMANAGER | MM_OWNSCALLBACK); nsFrameMessageManager::SetChildProcessManager(mm); RefPtr global = new ProcessGlobal(mm); NS_ENSURE_TRUE(global->Init(), NS_ERROR_UNEXPECTED); @@ -2141,13 +2033,10 @@ nsFrameMessageManager::MarkForCC() nsAutoTObserverArray* listeners = iter.UserData(); uint32_t count = listeners->Length(); for (uint32_t i = 0; i < count; i++) { - MessageListenerHolder& strongListener = listeners->ElementAt(i).mStrongListener; + nsCOMPtr strongListener = + listeners->ElementAt(i).mStrongListener; if (strongListener) { - if (strongListener.HasWebIDLCallback()) { - strongListener.GetWebIDLCallback()->MarkForCC(); - } else { - xpc_TryUnmarkWrappedGrayObject(strongListener.GetXPCOMCallback()); - } + xpc_TryUnmarkWrappedGrayObject(strongListener); } } } diff --git a/dom/base/nsFrameMessageManager.h b/dom/base/nsFrameMessageManager.h index 4bd216878b137..b49ec7490f314 100644 --- a/dom/base/nsFrameMessageManager.h +++ b/dom/base/nsFrameMessageManager.h @@ -28,8 +28,6 @@ #include "mozilla/Attributes.h" #include "js/RootingAPI.h" #include "nsTObserverArray.h" -#include "mozilla/TypedEnumBits.h" -#include "mozilla/dom/CallbackObject.h" #include "mozilla/dom/SameProcessMessageQueue.h" #include "mozilla/dom/ipc/StructuredCloneData.h" #include "mozilla/jsipc/CpowHolder.h" @@ -41,13 +39,8 @@ namespace dom { class nsIContentParent; class nsIContentChild; -class ChildProcessMessageManager; -class ChromeMessageSender; class ClonedMessageData; -class MessageListener; -class MessageListenerManager; class MessageManagerReporter; -template class Optional; namespace ipc { @@ -55,15 +48,14 @@ namespace ipc { // of 1 ms actually captures from 500us and above. static const uint32_t kMinTelemetrySyncMessageManagerLatencyMs = 1; -enum class MessageManagerFlags { - MM_NONE = 0, +enum MessageManagerFlags { + MM_CHILD = 0, MM_CHROME = 1, MM_GLOBAL = 2, MM_PROCESSMANAGER = 4, MM_BROADCASTER = 8, MM_OWNSCALLBACK = 16 }; -MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MessageManagerFlags); class MessageManagerCallback { @@ -126,10 +118,6 @@ void UnpackClonedMessageDataForChild(const ClonedMessageData& aClonedData, StructuredCloneData& aData); } // namespace ipc - -typedef CallbackObjectHolder MessageListenerHolder; - } // namespace dom } // namespace mozilla @@ -140,22 +128,12 @@ struct nsMessageListenerInfo return &aOther == this; } - // If mWeakListener is null then mStrongListener holds either a MessageListener or an - // nsIMessageListener. If mWeakListener is non-null then mStrongListener contains null. - mozilla::dom::MessageListenerHolder mStrongListener; + // Exactly one of mStrongListener and mWeakListener must be non-null. + nsCOMPtr mStrongListener; nsWeakPtr mWeakListener; bool mListenWhenClosed; }; -inline void -ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, - nsMessageListenerInfo& aField, - const char* aName, - uint32_t aFlags = 0) -{ - ImplCycleCollectionTraverse(aCallback, aField.mStrongListener, aName, aFlags); - ImplCycleCollectionTraverse(aCallback, aField.mWeakListener, aName, aFlags); -} class MOZ_STACK_CLASS SameProcessCpowHolder : public mozilla::jsipc::CpowHolder { @@ -172,86 +150,25 @@ class MOZ_STACK_CLASS SameProcessCpowHolder : public mozilla::jsipc::CpowHolder JS::Rooted mObj; }; -class nsFrameMessageManager : public nsIContentFrameMessageManager, - public nsIMessageBroadcaster, - public nsIFrameScriptLoader, - public nsIGlobalProcessScriptLoader +class nsFrameMessageManager final : public nsIContentFrameMessageManager, + public nsIMessageBroadcaster, + public nsIFrameScriptLoader, + public nsIGlobalProcessScriptLoader { friend class mozilla::dom::MessageManagerReporter; typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData; - -protected: - typedef mozilla::dom::ipc::MessageManagerFlags MessageManagerFlags; - +public: nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback, - MessageManagerFlags aFlags); + nsFrameMessageManager* aParentManager, + /* mozilla::dom::ipc::MessageManagerFlags */ uint32_t aFlags); - virtual ~nsFrameMessageManager(); +private: + ~nsFrameMessageManager(); public: - explicit nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback) - : nsFrameMessageManager(aCallback, MessageManagerFlags::MM_NONE) - {} - NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFrameMessageManager, nsIContentFrameMessageManager) - - // MessageListenerManager - void AddMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListener& aListener, - bool aListenWhenClosed, - mozilla::ErrorResult& aError); - void RemoveMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListener& aListener, - mozilla::ErrorResult& aError); - void AddWeakMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListener& aListener, - mozilla::ErrorResult& aError); - void RemoveWeakMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListener& aListener, - mozilla::ErrorResult& aError); - - // MessageSender - void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - JS::Handle aTransfers, - mozilla::ErrorResult& aError) - { - DispatchAsyncMessage(aCx, aMessageName, aObj, aObjects, aPrincipal, aTransfers, - aError); - } - already_AddRefed - GetProcessMessageManager(mozilla::ErrorResult& aError); - void GetRemoteType(nsAString& aRemoteType, mozilla::ErrorResult& aError) const; - - // SyncMessageSender - void SendSyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - nsTArray& aResult, - mozilla::ErrorResult& aError) - { - SendMessage(aCx, aMessageName, aObj, aObjects, aPrincipal, true, aResult, aError); - } - void SendRpcMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - nsTArray& aResult, - mozilla::ErrorResult& aError) - { - SendMessage(aCx, aMessageName, aObj, aObjects, aPrincipal, false, aResult, aError); - } - - // GlobalProcessScriptLoader - void GetInitialProcessData(JSContext* aCx, - JS::MutableHandle aInitialProcessData, - mozilla::ErrorResult& aError); - NS_DECL_NSIMESSAGELISTENERMANAGER NS_DECL_NSIMESSAGESENDER NS_DECL_NSIMESSAGEBROADCASTER @@ -262,7 +179,7 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, NS_DECL_NSIPROCESSSCRIPTLOADER NS_DECL_NSIGLOBALPROCESSSCRIPTLOADER - static mozilla::dom::ChromeMessageSender* + static nsFrameMessageManager* NewProcessMessageManager(bool aIsRemote); nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader, @@ -271,11 +188,15 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal, nsTArray* aRetVal); - void AddChildManager(mozilla::dom::MessageListenerManager* aManager); - void RemoveChildManager(mozilla::dom::MessageListenerManager* aManager); + void AddChildManager(nsFrameMessageManager* aManager); + void RemoveChildManager(nsFrameMessageManager* aManager) + { + mChildManagers.RemoveObject(aManager); + } void Disconnect(bool aRemoveFromParent = true); void Close(); + void InitWithCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback); void SetCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback); mozilla::dom::ipc::MessageManagerCallback* GetCallback() @@ -296,6 +217,14 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, StructuredCloneData& aData, JS::Handle aCpows, nsIPrincipal* aPrincipal); + void RemoveFromParent(); + nsFrameMessageManager* GetParentManager() { return mParentManager; } + void SetParentManager(nsFrameMessageManager* aParent) + { + NS_ASSERTION(!mParentManager, "We have parent manager already!"); + NS_ASSERTION(mChrome, "Should not set parent manager!"); + mParentManager = aParent; + } bool IsGlobal() { return mGlobal; } bool IsBroadcaster() { return mIsBroadcaster; } @@ -303,11 +232,11 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, { return sParentProcessManager; } - static mozilla::dom::ChildProcessMessageManager* GetChildProcessManager() + static nsFrameMessageManager* GetChildProcessManager() { return sChildProcessManager; } - static void SetChildProcessManager(mozilla::dom::ChildProcessMessageManager* aManager) + static void SetChildProcessManager(nsFrameMessageManager* aManager) { sChildProcessManager = aManager; } @@ -316,24 +245,7 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, void LoadPendingScripts(); -protected: - friend class MMListenerRemover; - - virtual nsFrameMessageManager* GetParentManager() - { - return nullptr; - } - virtual void ClearParentManager(bool aRemove) - { - } - - void DispatchAsyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, - JS::Handle aObjects, - nsIPrincipal* aPrincipal, - JS::Handle aTransfers, - mozilla::ErrorResult& aError); - +private: nsresult SendMessage(const nsAString& aMessageName, JS::Handle aJSON, JS::Handle aObjects, @@ -342,14 +254,6 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, uint8_t aArgc, JS::MutableHandle aRetval, bool aIsSync); - void SendMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle aObj, JS::Handle aObjects, - nsIPrincipal* aPrincipal, bool aIsSync, nsTArray& aResult, - mozilla::ErrorResult& aError); - void SendMessage(JSContext* aCx, const nsAString& aMessageName, - StructuredCloneData& aData, JS::Handle aObjects, - nsIPrincipal* aPrincipal, bool aIsSync, - nsTArray& aResult, mozilla::ErrorResult& aError); nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader, bool aTargetClosed, const nsAString& aMessage, @@ -357,28 +261,19 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal, nsTArray* aRetVal); - void LoadScript(const nsAString& aURL, bool aAllowDelayedLoad, - bool aRunInGlobalScope, mozilla::ErrorResult& aError); - void RemoveDelayedScript(const nsAString& aURL); - nsresult GetDelayedScripts(JSContext* aCx, - JS::MutableHandle aList); - void GetDelayedScripts(JSContext* aCx, nsTArray>& aList, - mozilla::ErrorResult& aError); - - enum ProcessCheckerType { - PROCESS_CHECKER_PERMISSION, - PROCESS_CHECKER_MANIFEST_URL, - ASSERT_APP_HAS_PERMISSION - }; - bool AssertProcessInternal(ProcessCheckerType aType, - const nsAString& aCapability, - mozilla::ErrorResult& aError); + NS_IMETHOD LoadScript(const nsAString& aURL, + bool aAllowDelayedLoad, + bool aRunInGlobalScope); + NS_IMETHOD RemoveDelayedScript(const nsAString& aURL); + NS_IMETHOD GetDelayedScripts(JSContext* aCx, JS::MutableHandle aList); +protected: + friend class MMListenerRemover; // We keep the message listeners as arrays in a hastable indexed by the // message name. That gives us fast lookups in ReceiveMessage(). nsClassHashtable> mListeners; - nsTArray> mChildManagers; + nsCOMArray mChildManagers; bool mChrome; // true if we're in the chrome process bool mGlobal; // true if we're the global frame message manager bool mIsProcessManager; // true if the message manager belongs to the process realm @@ -389,6 +284,7 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, bool mDisconnected; mozilla::dom::ipc::MessageManagerCallback* mCallback; nsAutoPtr mOwnedCallback; + RefPtr mParentManager; nsTArray mPendingScripts; nsTArray mPendingScriptsGlobalStates; JS::Heap mInitialProcessData; @@ -400,13 +296,15 @@ class nsFrameMessageManager : public nsIContentFrameMessageManager, static nsFrameMessageManager* sSameProcessParentManager; static nsTArray >* sPendingSameProcessAsyncMessages; private: - void AddMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListenerHolder&& aListener, - bool aListenWhenClosed); - void RemoveMessageListener(const nsAString& aMessageName, - const mozilla::dom::MessageListenerHolder& aListener); - - static mozilla::dom::ChildProcessMessageManager* sChildProcessManager; + static nsFrameMessageManager* sChildProcessManager; + enum ProcessCheckerType { + PROCESS_CHECKER_PERMISSION, + PROCESS_CHECKER_MANIFEST_URL, + ASSERT_APP_HAS_PERMISSION + }; + nsresult AssertProcessInternal(ProcessCheckerType aType, + const nsAString& aCapability, + bool* aValid); }; /* A helper class for taking care of many details for async message sending @@ -476,6 +374,10 @@ class nsMessageManagerScriptExecutor public: static void PurgeCache(); static void Shutdown(); + JSObject* GetGlobal() + { + return mGlobal; + } void MarkScopesForCC(); protected: @@ -484,20 +386,17 @@ class nsMessageManagerScriptExecutor ~nsMessageManagerScriptExecutor() { MOZ_COUNT_DTOR(nsMessageManagerScriptExecutor); } void DidCreateGlobal(); - void LoadScriptInternal(JS::Handle aGlobal, const nsAString& aURL, - bool aRunInGlobalScope); + void LoadScriptInternal(const nsAString& aURL, bool aRunInGlobalScope); void TryCacheLoadAndCompileScript(const nsAString& aURL, bool aRunInGlobalScope, bool aShouldCache, JS::MutableHandle aScriptp); void TryCacheLoadAndCompileScript(const nsAString& aURL, bool aRunInGlobalScope); - bool InitChildGlobalInternal(const nsACString& aID); - virtual bool WrapGlobalObject(JSContext* aCx, - JS::CompartmentOptions& aOptions, - JS::MutableHandle aReflector) = 0; + bool InitChildGlobalInternal(nsISupports* aScope, const nsACString& aID); void Trace(const TraceCallbacks& aCallbacks, void* aClosure); void Unlink(); + JS::TenuredHeap mGlobal; nsCOMPtr mPrincipal; AutoTArray, 2> mAnonymousGlobalScopes; diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index c70e9b32d0109..57c0dce4c0dc4 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -1246,7 +1246,8 @@ nsGlobalWindowInner::CleanUp() if (mCleanMessageManager) { MOZ_ASSERT(mIsChrome, "only chrome should have msg manager cleaned"); if (mChromeFields.mMessageManager) { - mChromeFields.mMessageManager->Disconnect(); + static_cast( + mChromeFields.mMessageManager.get())->Disconnect(); } } @@ -7592,7 +7593,7 @@ nsGlobalWindowInner::GetMessageManager(nsIMessageBroadcaster** aManager) return rv.StealNSResult(); } -ChromeMessageBroadcaster* +nsIMessageBroadcaster* nsGlobalWindowInner::GetMessageManager(ErrorResult& aError) { MOZ_ASSERT(IsChromeWindow()); @@ -7600,7 +7601,9 @@ nsGlobalWindowInner::GetMessageManager(ErrorResult& aError) nsCOMPtr globalMM = do_GetService("@mozilla.org/globalmessagemanager;1"); mChromeFields.mMessageManager = - new ChromeMessageBroadcaster(static_cast(globalMM.get())); + new nsFrameMessageManager(nullptr, + static_cast(globalMM.get()), + MM_CHROME | MM_BROADCASTER); } return mChromeFields.mMessageManager; } @@ -7615,18 +7618,21 @@ nsGlobalWindowInner::GetGroupMessageManager(const nsAString& aGroup, return rv.StealNSResult(); } -ChromeMessageBroadcaster* +nsIMessageBroadcaster* nsGlobalWindowInner::GetGroupMessageManager(const nsAString& aGroup, ErrorResult& aError) { MOZ_ASSERT(IsChromeWindow()); - RefPtr messageManager = + nsCOMPtr messageManager = mChromeFields.mGroupMessageManagers.LookupForAdd(aGroup).OrInsert( [this, &aError] () { - nsFrameMessageManager* parent = GetMessageManager(aError); + nsFrameMessageManager* parent = + static_cast(GetMessageManager(aError)); - return new ChromeMessageBroadcaster(parent); + return new nsFrameMessageManager(nullptr, + parent, + MM_CHROME | MM_BROADCASTER); }); return messageManager; } diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index f0f71757e595f..e7943734427bd 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -37,11 +37,11 @@ #include "prclist.h" #include "mozilla/dom/DOMPrefs.h" #include "mozilla/dom/BindingDeclarations.h" -#include "mozilla/dom/ChromeMessageBroadcaster.h" #include "mozilla/dom/StorageEvent.h" #include "mozilla/dom/StorageEventBinding.h" #include "mozilla/dom/UnionTypes.h" #include "mozilla/ErrorResult.h" +#include "nsFrameMessageManager.h" #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" #include "mozilla/LinkedList.h" @@ -941,11 +941,9 @@ class nsGlobalWindowInner : public mozilla::dom::EventTarget, void Restore(); void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton, mozilla::ErrorResult& aError); - mozilla::dom::ChromeMessageBroadcaster* - GetMessageManager(mozilla::ErrorResult& aError); - mozilla::dom::ChromeMessageBroadcaster* - GetGroupMessageManager(const nsAString& aGroup, - mozilla::ErrorResult& aError); + nsIMessageBroadcaster* GetMessageManager(mozilla::ErrorResult& aError); + nsIMessageBroadcaster* GetGroupMessageManager(const nsAString& aGroup, + mozilla::ErrorResult& aError); void BeginWindowMove(mozilla::dom::Event& aMouseDownEvent, mozilla::dom::Element* aPanel, mozilla::ErrorResult& aError); @@ -1273,9 +1271,9 @@ class nsGlobalWindowInner : public mozilla::dom::EventTarget, { MOZ_RELEASE_ASSERT(IsChromeWindow()); for (auto iter = mChromeFields.mGroupMessageManagers.Iter(); !iter.Done(); iter.Next()) { - mozilla::dom::ChromeMessageBroadcaster* mm = iter.UserData(); + nsIMessageBroadcaster* mm = iter.UserData(); if (mm) { - mm->Disconnect(); + static_cast(mm)->Disconnect(); } } mChromeFields.mGroupMessageManagers.Clear(); @@ -1475,9 +1473,8 @@ class nsGlobalWindowInner : public mozilla::dom::EventTarget, : mGroupMessageManagers(1) {} - RefPtr mMessageManager; - nsRefPtrHashtable mGroupMessageManagers; + nsCOMPtr mMessageManager; + nsInterfaceHashtable mGroupMessageManagers; } mChromeFields; // These fields are used by the inner and outer windows to prevent diff --git a/dom/base/nsGlobalWindowOuter.h b/dom/base/nsGlobalWindowOuter.h index dc32d0f5a42fb..23f0a95542a3b 100644 --- a/dom/base/nsGlobalWindowOuter.h +++ b/dom/base/nsGlobalWindowOuter.h @@ -37,11 +37,11 @@ #include "mozilla/FlushType.h" #include "prclist.h" #include "mozilla/dom/BindingDeclarations.h" -#include "mozilla/dom/ChromeMessageBroadcaster.h" #include "mozilla/dom/StorageEvent.h" #include "mozilla/dom/StorageEventBinding.h" #include "mozilla/dom/UnionTypes.h" #include "mozilla/ErrorResult.h" +#include "nsFrameMessageManager.h" #include "mozilla/Attributes.h" #include "mozilla/GuardObjects.h" #include "mozilla/LinkedList.h" diff --git a/dom/base/nsIMessageManager.idl b/dom/base/nsIMessageManager.idl index 0e256f369a757..1f20aa261feab 100644 --- a/dom/base/nsIMessageManager.idl +++ b/dom/base/nsIMessageManager.idl @@ -203,7 +203,7 @@ interface nsIMessageListener : nsISupports void receiveMessage(); }; -[uuid(b949bfec-bb7d-47bc-b387-ac6a9b655072)] +[scriptable, builtinclass, uuid(b949bfec-bb7d-47bc-b387-ac6a9b655072)] interface nsIMessageListenerManager : nsISupports { /** @@ -261,7 +261,7 @@ interface nsIMessageListenerManager : nsISupports * messages that are only delivered to its one parent-process message * manager. */ -[uuid(bb5d79e4-e73c-45e7-9651-4d718f4b994c)] +[scriptable, builtinclass, uuid(bb5d79e4-e73c-45e7-9651-4d718f4b994c)] interface nsIMessageSender : nsIMessageListenerManager { /** @@ -309,7 +309,7 @@ interface nsIMessageSender : nsIMessageListenerManager * manager will broadcast the message to all frame message managers * within its window. */ -[uuid(4d7d62ad-4725-4f39-86cf-8fb22bf9c1d8)] +[scriptable, builtinclass, uuid(4d7d62ad-4725-4f39-86cf-8fb22bf9c1d8)] interface nsIMessageBroadcaster : nsIMessageListenerManager { /** @@ -342,7 +342,7 @@ interface nsIMessageBroadcaster : nsIMessageListenerManager void releaseCachedProcesses(); }; -[uuid(0e602c9e-1977-422a-a8e4-fe0d4a4f78d0)] +[scriptable, builtinclass, uuid(0e602c9e-1977-422a-a8e4-fe0d4a4f78d0)] interface nsISyncMessageSender : nsIMessageSender { /** @@ -372,7 +372,7 @@ interface nsISyncMessageSender : nsIMessageSender [optional] in nsIPrincipal principal); }; -[uuid(13f3555f-769e-44ea-b607-5239230c3162)] +[scriptable, builtinclass, uuid(13f3555f-769e-44ea-b607-5239230c3162)] interface nsIMessageManagerGlobal : nsISyncMessageSender { /** @@ -393,7 +393,7 @@ interface nsIMessageManagerGlobal : nsISyncMessageSender DOMString btoa(in DOMString aBase64Data); }; -[uuid(694e367c-aa25-4446-8499-2c527c4bd838)] +[scriptable, builtinclass, uuid(694e367c-aa25-4446-8499-2c527c4bd838)] interface nsIContentFrameMessageManager : nsIMessageManagerGlobal { /** @@ -420,7 +420,7 @@ interface nsIInProcessContentFrameMessageManager : nsIContentFrameMessageManager [notxpcom] void cacheFrameLoader(in nsIFrameLoader aFrameLoader); }; -[uuid(6d12e467-2446-46db-9965-e4e93cb87ca5)] +[scriptable, builtinclass, uuid(6d12e467-2446-46db-9965-e4e93cb87ca5)] interface nsIContentProcessMessageManager : nsIMessageManagerGlobal { /** @@ -431,7 +431,7 @@ interface nsIContentProcessMessageManager : nsIMessageManagerGlobal readonly attribute jsval initialProcessData; }; -[uuid(bf61446b-ba24-4b1d-88c7-4f94724b9ce1)] +[scriptable, builtinclass, uuid(bf61446b-ba24-4b1d-88c7-4f94724b9ce1)] interface nsIFrameScriptLoader : nsISupports { /** @@ -458,7 +458,7 @@ interface nsIFrameScriptLoader : nsISupports jsval getDelayedFrameScripts(); }; -[uuid(7e1e1a20-b24f-11e4-ab27-0800200c9a66)] +[scriptable, builtinclass, uuid(7e1e1a20-b24f-11e4-ab27-0800200c9a66)] interface nsIProcessScriptLoader : nsISupports { /** @@ -483,7 +483,7 @@ interface nsIProcessScriptLoader : nsISupports jsval getDelayedProcessScripts(); }; -[uuid(5b390753-abb3-49b0-ae3b-b803dab58144)] +[scriptable, builtinclass, uuid(5b390753-abb3-49b0-ae3b-b803dab58144)] interface nsIGlobalProcessScriptLoader : nsIProcessScriptLoader { /** diff --git a/dom/base/nsInProcessTabChildGlobal.cpp b/dom/base/nsInProcessTabChildGlobal.cpp index 5f13593293b2a..a334ef10388a5 100644 --- a/dom/base/nsInProcessTabChildGlobal.cpp +++ b/dom/base/nsInProcessTabChildGlobal.cpp @@ -14,9 +14,8 @@ #include "nsFrameLoader.h" #include "xpcpublic.h" #include "nsIMozBrowserFrame.h" +#include "nsDOMClassInfoID.h" #include "mozilla/EventDispatcher.h" -#include "mozilla/dom/ChromeMessageSender.h" -#include "mozilla/dom/MessageManagerBinding.h" #include "mozilla/dom/SameProcessMessageQueue.h" #include "mozilla/dom/ScriptLoader.h" @@ -90,11 +89,11 @@ nsInProcessTabChildGlobal::DoSendAsyncMessage(JSContext* aCx, nsInProcessTabChildGlobal::nsInProcessTabChildGlobal(nsIDocShell* aShell, nsIContent* aOwner, nsFrameMessageManager* aChrome) -: ContentFrameMessageManager(aChrome), - mDocShell(aShell), mInitialized(false), mLoadingScript(false), +: mDocShell(aShell), mInitialized(false), mLoadingScript(false), mPreventEventsEscaping(false), mOwner(aOwner), mChromeMessageManager(aChrome) { + SetIsNotDOMBinding(); mozilla::HoldJSObjects(this); // If owner corresponds to an