From 9f9a8d9b3e3256ec8c666302c10cd14b91b04776 Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Wed, 12 Aug 2020 16:49:21 +0000 Subject: [PATCH] Bug 1657105 - Use constants to define target types on the server and set targetType on all targets. r=jdescottes Differential Revision: https://phabricator.services.mozilla.com/D86632 --- .../server/actors/targets/browsing-context.js | 6 ++---- .../server/actors/targets/content-process.js | 3 +++ devtools/server/actors/targets/index.js | 12 ++++++++++++ devtools/server/actors/targets/moz.build | 1 + devtools/server/actors/watcher.js | 16 +++++++--------- .../watcher/target-helpers/frame-helper.js | 3 ++- devtools/server/startup/worker.js | 3 +++ devtools/server/tests/xpcshell/testactors.js | 3 +++ 8 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 devtools/server/actors/targets/index.js diff --git a/devtools/server/actors/targets/browsing-context.js b/devtools/server/actors/targets/browsing-context.js index 03d5bb1f08d6..a4337adf4a74 100644 --- a/devtools/server/actors/targets/browsing-context.js +++ b/devtools/server/actors/targets/browsing-context.js @@ -33,6 +33,7 @@ var { assert } = DevToolsUtils; var { TabSources } = require("devtools/server/actors/utils/TabSources"); var makeDebugger = require("devtools/server/actors/utils/make-debugger"); const InspectorUtils = require("InspectorUtils"); +const Targets = require("devtools/server/actors/targets/index"); const { TargetActorRegistry } = ChromeUtils.import( "resource://devtools/server/actors/targets/target-actor-registry.jsm" ); @@ -394,10 +395,7 @@ const browsingContextTargetPrototype = { _targetScopedActorPool: null, - /** - * A constant prefix that will be used to form the actor ID by the server. - */ - typeName: "browsingContextTarget", + targetType: Targets.TYPES.FRAME, /** * An object on which listen for DOMWindowCreated and pageshow events. diff --git a/devtools/server/actors/targets/content-process.js b/devtools/server/actors/targets/content-process.js index 5ab837cba714..a6c99c55c3fa 100644 --- a/devtools/server/actors/targets/content-process.js +++ b/devtools/server/actors/targets/content-process.js @@ -24,6 +24,7 @@ const { ActorClassWithSpec, Actor } = require("devtools/shared/protocol"); const { contentProcessTargetSpec, } = require("devtools/shared/specs/targets/content-process"); +const Targets = require("devtools/server/actors/targets/index"); loader.lazyRequireGetter( this, @@ -86,6 +87,8 @@ const ContentProcessTargetActor = ActorClassWithSpec(contentProcessTargetSpec, { Services.obs.addObserver(this.destroyObserver, "xpcom-shutdown"); }, + targetType: Targets.TYPES.FRAME, + get isRootActor() { return true; }, diff --git a/devtools/server/actors/targets/index.js b/devtools/server/actors/targets/index.js new file mode 100644 index 000000000000..aced44845936 --- /dev/null +++ b/devtools/server/actors/targets/index.js @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const TYPES = { + FRAME: "frame", + PROCESS: "process", + WORKER: "worker", +}; +exports.TYPES = TYPES; diff --git a/devtools/server/actors/targets/moz.build b/devtools/server/actors/targets/moz.build index 14a9c9974d3d..4e4e10c9e93e 100644 --- a/devtools/server/actors/targets/moz.build +++ b/devtools/server/actors/targets/moz.build @@ -9,6 +9,7 @@ DevToolsModules( 'chrome-window.js', 'content-process.js', 'frame.js', + 'index.js', 'parent-process.js', 'target-actor-registry.jsm', 'webextension.js', diff --git a/devtools/server/actors/watcher.js b/devtools/server/actors/watcher.js index c3c366dd04f4..7b0e85548c95 100644 --- a/devtools/server/actors/watcher.js +++ b/devtools/server/actors/watcher.js @@ -15,14 +15,12 @@ const { const { WatcherRegistry, } = require("devtools/server/actors/watcher/WatcherRegistry.jsm"); +const Targets = require("devtools/server/actors/targets/index"); -const TARGET_TYPES = { - FRAME: "frame", -}; const TARGET_HELPERS = {}; loader.lazyRequireGetter( TARGET_HELPERS, - TARGET_TYPES.FRAME, + Targets.TYPES.FRAME, "devtools/server/actors/watcher/target-helpers/frame-helper" ); @@ -65,7 +63,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, { destroy: function() { // Force unwatching for all types, even if we weren't watching. // This is fine as unwatchTarget is NOOP if we weren't already watching for this target type. - for (const targetType of Object.values(TARGET_TYPES)) { + for (const targetType of Object.values(Targets.TYPES)) { this.unwatchTargets(targetType); } this.unwatchResources(Object.values(Resources.TYPES)); @@ -133,7 +131,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, { * resolves. * * @param {string} targetType - * Type of context to observe. See TARGET_TYPES object. + * Type of context to observe. See Targets.TYPES object. */ async watchTargets(targetType) { WatcherRegistry.watchTargets(this, targetType); @@ -148,7 +146,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, { * Stop watching for a given target type. * * @param {string} targetType - * Type of context to observe. See TARGET_TYPES object. + * Type of context to observe. See Targets.TYPES object. */ unwatchTargets(targetType) { const isWatchingTargets = WatcherRegistry.unwatchTargets(this, targetType); @@ -253,7 +251,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, { // so we should always process it. It does a second check to isWatchingTargets. if ( !WatcherRegistry.isWatchingTargets(this, targetType) && - targetType != TARGET_TYPES.FRAME + targetType != Targets.TYPES.FRAME ) { continue; } @@ -328,7 +326,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, { // so we should always process it. It does a second check to isWatchingTargets. if ( !WatcherRegistry.isWatchingTargets(this, targetType) && - targetType != TARGET_TYPES.FRAME + targetType != Targets.TYPES.FRAME ) { continue; } diff --git a/devtools/server/actors/watcher/target-helpers/frame-helper.js b/devtools/server/actors/watcher/target-helpers/frame-helper.js index 3553889e8f3e..748f9a50cc23 100644 --- a/devtools/server/actors/watcher/target-helpers/frame-helper.js +++ b/devtools/server/actors/watcher/target-helpers/frame-helper.js @@ -8,6 +8,7 @@ const Services = require("Services"); const { WatcherRegistry, } = require("devtools/server/actors/watcher/WatcherRegistry.jsm"); +const Targets = require("devtools/server/actors/targets/index"); /** * Force creating targets for all existing BrowsingContext, that, for a given Watcher Actor. @@ -145,7 +146,7 @@ function getWatchingBrowsingContexts(watcher) { // either via devtools.contenttoolbox.fission or devtools.browsertoolbox.fission pref. const watchingAdditionalTargets = WatcherRegistry.isWatchingTargets( watcher, - "frame" + Targets.TYPES.FRAME ); const { browserElement } = watcher; const browsingContexts = watchingAdditionalTargets diff --git a/devtools/server/startup/worker.js b/devtools/server/startup/worker.js index b9a4addd2d0b..ec0d8d947346 100644 --- a/devtools/server/startup/worker.js +++ b/devtools/server/startup/worker.js @@ -43,6 +43,7 @@ var { WebConsoleActor } = worker.require("devtools/server/actors/webconsole"); var { TabSources } = worker.require("devtools/server/actors/utils/TabSources"); var makeDebugger = worker.require("devtools/server/actors/utils/make-debugger"); var { DevToolsServer } = worker.require("devtools/server/devtools-server"); +var Targets = worker.require("devtools/server/actors/targets/index"); DevToolsServer.init(); DevToolsServer.createRootActor = function() { @@ -81,6 +82,8 @@ this.addEventListener("message", function(event) { Object.assign(targetActorMock, { actorID: packet.id, + targetType: Targets.TYPES.FRAME, + // threadActor is needed from the webconsole for grip previewing threadActor, workerGlobal: global, diff --git a/devtools/server/tests/xpcshell/testactors.js b/devtools/server/tests/xpcshell/testactors.js index 57a4adb00631..30f440afd841 100644 --- a/devtools/server/tests/xpcshell/testactors.js +++ b/devtools/server/tests/xpcshell/testactors.js @@ -20,6 +20,7 @@ const { browsingContextTargetSpec, } = require("devtools/shared/specs/targets/browsing-context"); const { tabDescriptorSpec } = require("devtools/shared/specs/descriptors/tab"); +const Targets = require("devtools/server/actors/targets/index"); var gTestGlobals = new Set(); DevToolsServer.addTestGlobal = function(global) { @@ -166,6 +167,8 @@ const TestTargetActor = protocol.ActorClassWithSpec(browsingContextTargetSpec, { this.notifyResourceAvailable = this.notifyResourceAvailable.bind(this); }, + targetType: Targets.TYPES.FRAME, + get window() { return this._global; },