Bug 1446222 - Move DevTools content process startup to new dir. r=jdescottes
Move and rename the server's process script (and accompanying JSM) that starts
DevTools for an entire content process from `content-process-debugger-server.js`
to `startup/content-process.js`. `connectToContent` also becomes the more
specific `connectToContentProcess`.
These code paths will likely change more as Site Isolation work continues, but
for now, we have this light cleanup to gather startup-related paths together.
MozReview-Commit-ID: 1evbZMB8T7r
--- a/devtools/server/actors/root.js
+++ b/devtools/server/actors/root.js
@@ -519,17 +519,17 @@ RootActor.prototype = {
};
},
onProcessListChanged: function() {
this.conn.send({ from: this.actorID, type: "processListChanged" });
this._parameters.processList.onListChanged = null;
},
- onGetProcess: function(request) {
+ async onGetProcess(request) {
if (!DebuggerServer.allowChromeProcess) {
return { error: "forbidden",
message: "You are not allowed to debug chrome." };
}
if (("id" in request) && typeof (request.id) != "number") {
return { error: "wrongParameter",
message: "getProcess requires a valid `id` attribute." };
}
@@ -554,20 +554,19 @@ RootActor.prototype = {
}
let form = this._processActors.get(id);
if (form) {
return { form };
}
let onDestroy = () => {
this._processActors.delete(id);
};
- return DebuggerServer.connectToContent(this.conn, mm, onDestroy).then(formResult => {
- this._processActors.set(id, formResult);
- return { form: formResult };
- });
+ form = await DebuggerServer.connectToContentProcess(this.conn, mm, onDestroy);
+ this._processActors.set(id, form);
+ return { form };
},
/* This is not in the spec, but it's used by tests. */
onEcho: function(request) {
/*
* Request packets are frozen. Copy request, so that
* DebuggerServerConnection.onPacket can attach a 'from' property.
*/
--- a/devtools/server/main.js
+++ b/devtools/server/main.js
@@ -47,18 +47,18 @@ if (isWorker) {
const VERBOSE_PREF = "devtools.debugger.log.verbose";
flags.wantLogging = Services.prefs.getBoolPref(LOG_PREF);
flags.wantVerbose =
Services.prefs.getPrefType(VERBOSE_PREF) !== Services.prefs.PREF_INVALID &&
Services.prefs.getBoolPref(VERBOSE_PREF);
}
-const CONTENT_PROCESS_DBG_SERVER_SCRIPT =
- "resource://devtools/server/content-process-debugger-server.js";
+const CONTENT_PROCESS_SERVER_STARTUP_SCRIPT =
+ "resource://devtools/server/startup/content-process.js";
function loadSubScript(url) {
try {
Services.scriptloader.loadSubScript(url, this);
} catch (e) {
let errorStr = "Error loading: " + url + ":\n" +
(e.fileName ? "at " + e.fileName + " : " + e.lineNumber + "\n" : "") +
e + " - " + e.stack + "\n";
@@ -122,24 +122,24 @@ function ModuleAPI() {
for (let factory of activeGlobalActors) {
DebuggerServer.removeGlobalActor(factory);
}
activeGlobalActors = null;
}
};
}
-/** *
+/**
* Public API
*/
var DebuggerServer = {
_listeners: [],
_initialized: false,
- // Flag to check if the content process debugger server script was already loaded.
- _contentProcessScriptLoaded: false,
+ // Flag to check if the content process server startup script was already loaded.
+ _contentProcessServerStartupScriptLoaded: false,
// Map of global actor names to actor constructors provided by extensions.
globalActorFactories: {},
// Map of tab actor names to actor constructors provided by extensions.
tabActorFactories: {},
LONG_STRING_LENGTH: 10000,
LONG_STRING_INITIAL_LENGTH: 1000,
LONG_STRING_READ_LENGTH: 65 * 1024,
@@ -694,17 +694,21 @@ var DebuggerServer = {
let transport = isWorker ?
new WorkerDebuggerTransport(scopeOrManager, prefix) :
new ChildDebuggerTransport(scopeOrManager, prefix);
return this._onConnection(transport, prefix, true);
},
- connectToContent(connection, mm, onDestroy) {
+ /**
+ * Start a DevTools server in a content process (representing the entire process, not
+ * just a single frame) and add it as a child server for an active connection.
+ */
+ connectToContentProcess(connection, mm, onDestroy) {
return new Promise(resolve => {
let prefix = connection.allocID("content-process");
let actor, childTransport;
mm.addMessageListener("debug:content-process-actor", function listener(msg) {
// Arbitrarily choose the first content process to reply
// XXX: This code needs to be updated if we use more than one content process
mm.removeMessageListener("debug:content-process-actor", listener);
@@ -714,31 +718,31 @@ var DebuggerServer = {
childTransport.hooks = {
onPacket: connection.send.bind(connection),
onClosed() {}
};
childTransport.ready();
connection.setForwarding(prefix, childTransport);
- dumpn("establishing forwarding for process with prefix " + prefix);
+ dumpn(`Start forwarding for process with prefix ${prefix}`);
actor = msg.json.actor;
resolve(actor);
});
- // Load the content process debugger server script only once.
- if (!this._contentProcessScriptLoaded) {
+ // Load the content process server startup script only once.
+ if (!this._contentProcessServerStartupScriptLoaded) {
// Load the process script that will receive the debug:init-content-server message
- Services.ppmm.loadProcessScript(CONTENT_PROCESS_DBG_SERVER_SCRIPT, true);
- this._contentProcessScriptLoaded = true;
+ Services.ppmm.loadProcessScript(CONTENT_PROCESS_SERVER_STARTUP_SCRIPT, true);
+ this._contentProcessServerStartupScriptLoaded = true;
}
- // Send a message to the content process debugger server script to forward it the
+ // Send a message to the content process server startup script to forward it the
// prefix.
mm.sendAsyncMessage("debug:init-content-server", {
prefix: prefix
});
function onClose() {
Services.obs.removeObserver(onMessageManagerClose, "message-manager-close");
EventEmitter.off(connection, "closed", onClose);
@@ -1341,22 +1345,22 @@ var DebuggerServer = {
for (let connID of Object.getOwnPropertyNames(this._connections)) {
this._connections[connID].rootActor.removeActorByName(name);
}
}
}
},
/**
- * Called when DevTools are unloaded to remove the contend process server script for the
- * list of scripts loaded for each new content process. Will also remove message
+ * Called when DevTools are unloaded to remove the contend process server startup script
+ * for the list of scripts loaded for each new content process. Will also remove message
* listeners from already loaded scripts.
*/
removeContentServerScript() {
- Services.ppmm.removeDelayedProcessScript(CONTENT_PROCESS_DBG_SERVER_SCRIPT);
+ Services.ppmm.removeDelayedProcessScript(CONTENT_PROCESS_SERVER_STARTUP_SCRIPT);
try {
Services.ppmm.broadcastAsyncMessage("debug:close-content-server");
} catch (e) {
// Nothing to do
}
},
/**
--- a/devtools/server/moz.build
+++ b/devtools/server/moz.build
@@ -13,17 +13,15 @@ DIRS += [
'startup',
]
BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
MOCHITEST_CHROME_MANIFESTS += ['tests/mochitest/chrome.ini']
XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
DevToolsModules(
- 'content-process-debugger-server.js',
- 'content-server.jsm',
'main.js',
'service-worker-child.js',
'worker.js'
)
with Files('**'):
BUG_COMPONENT = ('Firefox', 'Developer Tools')
rename from devtools/server/content-process-debugger-server.js
rename to devtools/server/startup/content-process.js
--- a/devtools/server/content-process-debugger-server.js
+++ b/devtools/server/startup/content-process.js
@@ -1,22 +1,30 @@
/* 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/. */
/* global addMessageListener, removeMessageListener */
"use strict";
+/*
+ * Process script that listens for requests to start a `DebuggerServer` for an entire
+ * content process. Loaded into content processes by the main process during
+ * `DebuggerServer.connectToContentProcess`.
+ *
+ * The actual server startup itself is in a JSM so that code can be cached.
+ */
+
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm", {});
function onInit(message) {
// Only reply if we are in a real content process
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
- let {init} = ChromeUtils.import("resource://devtools/server/content-server.jsm", {});
+ let {init} = ChromeUtils.import("resource://devtools/server/startup/content-process.jsm", {});
init(message);
}
}
function onClose() {
removeMessageListener("debug:init-content-server", onInit);
removeMessageListener("debug:close-content-server", onClose);
}
rename from devtools/server/content-server.jsm
rename to devtools/server/startup/content-process.jsm
--- a/devtools/server/content-server.jsm
+++ b/devtools/server/startup/content-process.jsm
@@ -1,14 +1,22 @@
/* 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";
+/*
+ * Module that listens for requests to start a `DebuggerServer` for an entire content
+ * process. Loaded into content processes by the main process during
+ * `DebuggerServer.connectToContentProcess` via the process script `content-process.js`.
+ *
+ * The actual server startup itself is in this JSM so that code can be cached.
+ */
+
/* exported init */
this.EXPORTED_SYMBOLS = ["init"];
let gLoader;
function setupServer(mm) {
// Prevent spawning multiple server per process, even if the caller call us
// multiple times
--- a/devtools/server/startup/moz.build
+++ b/devtools/server/startup/moz.build
@@ -1,9 +1,11 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DevToolsModules(
+ 'content-process.js',
+ 'content-process.jsm',
'frame.js',
)
--- a/tools/lint/eslint/modules.json
+++ b/tools/lint/eslint/modules.json
@@ -27,17 +27,16 @@
"CertUtils.jsm": ["BadCertHandler", "checkCert", "readCertPrefs", "validateCert"],
"clients.js": ["ClientEngine", "ClientsRec"],
"collection_repair.js": ["getRepairRequestor", "getAllRepairRequestors", "CollectionRepairRequestor", "getRepairResponder", "CollectionRepairResponder"],
"collection_validator.js": ["CollectionValidator", "CollectionProblemData"],
"Console.jsm": ["console", "ConsoleAPI"],
"constants.js": ["WEAVE_VERSION", "SYNC_API_VERSION", "STORAGE_VERSION", "PREFS_BRANCH", "DEFAULT_KEYBUNDLE_NAME", "SYNC_KEY_ENCODED_LENGTH", "SYNC_KEY_DECODED_LENGTH", "NO_SYNC_NODE_INTERVAL", "MAX_ERROR_COUNT_BEFORE_BACKOFF", "MINIMUM_BACKOFF_INTERVAL", "MAXIMUM_BACKOFF_INTERVAL", "HMAC_EVENT_INTERVAL", "MASTER_PASSWORD_LOCKED_RETRY_INTERVAL", "DEFAULT_GUID_FETCH_BATCH_SIZE", "DEFAULT_DOWNLOAD_BATCH_SIZE", "SINGLE_USER_THRESHOLD", "MULTI_DEVICE_THRESHOLD", "SCORE_INCREMENT_SMALL", "SCORE_INCREMENT_MEDIUM", "SCORE_INCREMENT_XLARGE", "SCORE_UPDATE_DELAY", "IDLE_OBSERVER_BACK_DELAY", "URI_LENGTH_MAX", "MAX_HISTORY_UPLOAD", "MAX_HISTORY_DOWNLOAD", "STATUS_OK", "SYNC_FAILED", "LOGIN_FAILED", "SYNC_FAILED_PARTIAL", "CLIENT_NOT_CONFIGURED", "STATUS_DISABLED", "MASTER_PASSWORD_LOCKED", "LOGIN_SUCCEEDED", "SYNC_SUCCEEDED", "ENGINE_SUCCEEDED", "LOGIN_FAILED_NO_USERNAME", "LOGIN_FAILED_NO_PASSPHRASE", "LOGIN_FAILED_NETWORK_ERROR", "LOGIN_FAILED_SERVER_ERROR", "LOGIN_FAILED_INVALID_PASSPHRASE", "LOGIN_FAILED_LOGIN_REJECTED", "METARECORD_DOWNLOAD_FAIL", "VERSION_OUT_OF_DATE", "CREDENTIALS_CHANGED", "ABORT_SYNC_COMMAND", "NO_SYNC_NODE_FOUND", "OVER_QUOTA", "SERVER_MAINTENANCE", "RESPONSE_OVER_QUOTA", "ENGINE_UPLOAD_FAIL", "ENGINE_DOWNLOAD_FAIL", "ENGINE_UNKNOWN_FAIL", "ENGINE_APPLY_FAIL", "ENGINE_BATCH_INTERRUPTED", "kSyncMasterPasswordLocked", "kSyncWeaveDisabled", "kSyncNetworkOffline", "kSyncBackoffNotMet", "kFirstSyncChoiceNotMade", "kSyncNotConfigured", "kFirefoxShuttingDown", "DEVICE_TYPE_DESKTOP", "DEVICE_TYPE_MOBILE", "SQLITE_MAX_VARIABLE_NUMBER"],
"Constants.jsm": ["Roles", "Events", "Relations", "Filters", "States", "Prefilters"],
"ContactDB.jsm": ["ContactDB", "DB_NAME", "STORE_NAME", "SAVED_GETALL_STORE_NAME", "REVISION_STORE", "DB_VERSION"],
- "content-server.jsm": ["init"],
"content.jsm": ["registerContentFrame"],
"ContentCrashHandlers.jsm": ["TabCrashHandler", "PluginCrashReporter", "UnsubmittedCrashHandler"],
"ContentObservers.js": [],
"ContentPrefUtils.jsm": ["ContentPref", "cbHandleResult", "cbHandleError", "cbHandleCompletion", "safeCallback", "_methodsCallableFromChild"],
"cookies.js": ["Cookies"],
"CoverageUtils.jsm": ["CoverageCollector"],
"CrashManagerTest.jsm": ["configureLogging", "getManager", "sleep", "TestingCrashManager"],
"dbg-client.jsm": ["DebuggerTransport", "DebuggerClient", "RootClient", "LongStringClient", "EnvironmentClient", "ObjectClient"],