From fb3dcac40b53dff73c3bef2f92e3d4599539f058 Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Tue, 13 Nov 2018 14:07:36 +0000 Subject: [PATCH] Bug 1498280 - Introduce RootClient.getMainProcess to fetch ParentProcessTargetActor. r=yulia MozReview-Commit-ID: E9OiwqDwNk7 Differential Revision: https://phabricator.services.mozilla.com/D11758 --HG-- extra : moz-landing-system : lando --- .../new/test/mochitest/browser_dbg-chrome-debugging.js | 2 +- .../browser_dbg_promises-chrome-allocation-stack.js | 2 +- devtools/client/framework/connect/connect.js | 2 +- devtools/client/framework/test/head.js | 2 +- devtools/client/framework/toolbox-process-window.js | 2 +- devtools/client/scratchpad/scratchpad.js | 2 +- devtools/client/webconsole/hudservice.js | 2 +- devtools/client/webide/modules/app-manager.js | 2 +- devtools/server/tests/unit/head_dbg.js | 4 ++-- devtools/server/tests/unit/test_xpcshell_debugging.js | 4 ++-- devtools/shared/fronts/root.js | 10 ++++++++++ devtools/shared/webconsole/test/common.js | 2 +- 12 files changed, 23 insertions(+), 13 deletions(-) diff --git a/devtools/client/debugger/new/test/mochitest/browser_dbg-chrome-debugging.js b/devtools/client/debugger/new/test/mochitest/browser_dbg-chrome-debugging.js index 72457d43955d..5190fb97ce81 100644 --- a/devtools/client/debugger/new/test/mochitest/browser_dbg-chrome-debugging.js +++ b/devtools/client/debugger/new/test/mochitest/browser_dbg-chrome-debugging.js @@ -63,7 +63,7 @@ add_task(async function() { const [type] = await gClient.connect(); is(type, "browser", "Root actor should identify itself as a browser."); - const response = await gClient.mainRoot.getProcess(0); + const response = await gClient.mainRoot.getMainProcess(); let actor = response.form.actor; gThreadClient = await attachThread(gClient, actor); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:mozilla"); diff --git a/devtools/client/debugger/test/mochitest/browser_dbg_promises-chrome-allocation-stack.js b/devtools/client/debugger/test/mochitest/browser_dbg_promises-chrome-allocation-stack.js index ce8a013bb28e..14cdf70b9900 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg_promises-chrome-allocation-stack.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg_promises-chrome-allocation-stack.js @@ -29,7 +29,7 @@ function test() { let client = new DebuggerClient(DebuggerServer.connectPipe()); yield connect(client); - let chrome = yield client.mainRoot.getProcess(0); + let chrome = yield client.mainRoot.getMainProcess(); let [, targetFront] = yield attachTarget(client, chrome.form); yield targetFront.attachThread(); diff --git a/devtools/client/framework/connect/connect.js b/devtools/client/framework/connect/connect.js index 5e79da980da8..41822ea3aed4 100644 --- a/devtools/client/framework/connect/connect.js +++ b/devtools/client/framework/connect/connect.js @@ -128,7 +128,7 @@ var onConnectionReady = async function([aType, aTraits]) { const a = document.createElement("a"); a.onclick = function() { if (gClient.mainRoot.traits.allowChromeProcess) { - gClient.mainRoot.getProcess(0) + gClient.mainRoot.getMainProcess() .then(aResponse => { openToolbox(aResponse.form, true); }); diff --git a/devtools/client/framework/test/head.js b/devtools/client/framework/test/head.js index d61208306c62..32ba35543e97 100644 --- a/devtools/client/framework/test/head.js +++ b/devtools/client/framework/test/head.js @@ -34,7 +34,7 @@ function getParentProcessActors(callback) { const client = new DebuggerClient(DebuggerServer.connectPipe()); client.connect() - .then(() => client.mainRoot.getProcess(0)) + .then(() => client.mainRoot.getMainProcess()) .then(response => { callback(client, response.form); }); diff --git a/devtools/client/framework/toolbox-process-window.js b/devtools/client/framework/toolbox-process-window.js index 501f6a055344..a44a16e09eb0 100644 --- a/devtools/client/framework/toolbox-process-window.js +++ b/devtools/client/framework/toolbox-process-window.js @@ -93,7 +93,7 @@ var connect = async function() { const addonTargetActor = addons.filter(addon => addon.id === addonID).pop(); await openToolbox({form: addonTargetActor, chrome: true}); } else { - const response = await gClient.mainRoot.getProcess(0); + const response = await gClient.mainRoot.getMainProcess(); await openToolbox({form: response.form, chrome: true}); } }; diff --git a/devtools/client/scratchpad/scratchpad.js b/devtools/client/scratchpad/scratchpad.js index 6adefa9bc8ef..e82651e7daf3 100644 --- a/devtools/client/scratchpad/scratchpad.js +++ b/devtools/client/scratchpad/scratchpad.js @@ -2071,7 +2071,7 @@ ScratchpadWindow.prototype = extend(ScratchpadTab.prototype, { const client = new DebuggerClient(DebuggerServer.connectPipe()); await client.connect(); - const response = await client.mainRoot.getProcess(0); + const response = await client.mainRoot.getMainProcess(); return { form: response.form, client }; }, }); diff --git a/devtools/client/webconsole/hudservice.js b/devtools/client/webconsole/hudservice.js index b543274d1d25..0b0ab0e26d6a 100644 --- a/devtools/client/webconsole/hudservice.js +++ b/devtools/client/webconsole/hudservice.js @@ -136,7 +136,7 @@ HUDService.prototype = { const client = new DebuggerClient(DebuggerServer.connectPipe()); await client.connect(); - const response = await client.mainRoot.getProcess(0); + const response = await client.mainRoot.getMainProcess(); return { form: response.form, client, chrome: true }; } diff --git a/devtools/client/webide/modules/app-manager.js b/devtools/client/webide/modules/app-manager.js index 8f843af23cc4..c90ccd44eb33 100644 --- a/devtools/client/webide/modules/app-manager.js +++ b/devtools/client/webide/modules/app-manager.js @@ -254,7 +254,7 @@ var AppManager = exports.AppManager = { if (this.selectedProject.type == "mainProcess") { // Fx >=39 exposes a ParentProcessTargetActor to debug the main process if (this.connection.client.mainRoot.traits.allowChromeProcess) { - return this.connection.client.mainRoot.getProcess(0) + return this.connection.client.mainRoot.getMainProcess() .then(aResponse => { return TargetFactory.forRemoteTab({ form: aResponse.form, diff --git a/devtools/server/tests/unit/head_dbg.js b/devtools/server/tests/unit/head_dbg.js index f18c487ebffe..d42aeac99d4f 100644 --- a/devtools/server/tests/unit/head_dbg.js +++ b/devtools/server/tests/unit/head_dbg.js @@ -101,7 +101,7 @@ async function createFullRuntimeMemoryFront() { const client = new DebuggerClient(DebuggerServer.connectPipe()); await client.connect(); - const { form } = await client.mainRoot.getProcess(0); + const { form } = await client.mainRoot.getMainProcess(); const options = { form, client, @@ -405,7 +405,7 @@ async function finishClient(client) { function getParentProcessActors(client, server = DebuggerServer) { server.allowChromeProcess = true; - return client.mainRoot.getProcess(0).then(response => response.form); + return client.mainRoot.getMainProcess().then(response => response.form); } /** diff --git a/devtools/server/tests/unit/test_xpcshell_debugging.js b/devtools/server/tests/unit/test_xpcshell_debugging.js index ce5a0a380931..bef67929031d 100644 --- a/devtools/server/tests/unit/test_xpcshell_debugging.js +++ b/devtools/server/tests/unit/test_xpcshell_debugging.js @@ -25,8 +25,8 @@ add_task(async function() { const desc = await deviceFront.getDescription(); equal(desc.geckobuildid, Services.appinfo.platformBuildID, "device actor works"); - // Even though we have no tabs, getProcess gives us the chromeDebugger. - const response = await client.mainRoot.getProcess(0); + // Even though we have no tabs, getMainProcess gives us the chromeDebugger. + const response = await client.mainRoot.getMainProcess(); const { chromeDebugger } = response.form; const [, threadClient] = await client.attachThread(chromeDebugger); diff --git a/devtools/shared/fronts/root.js b/devtools/shared/fronts/root.js index 803bd68c79ed..11956260ed84 100644 --- a/devtools/shared/fronts/root.js +++ b/devtools/shared/fronts/root.js @@ -136,6 +136,16 @@ const RootFront = protocol.FrontClassWithSpec(rootSpec, { return result; }, + /** + * Fetch the ParentProcessTargetActor for the main process. + * + * `getProcess` requests allows to fetch the target actor for any process + * and the main process is having the process ID zero. + */ + getMainProcess() { + return this.getProcess(0); + }, + /** * Fetch the target actor for the currently selected tab, or for a specific * tab given as first parameter. diff --git a/devtools/shared/webconsole/test/common.js b/devtools/shared/webconsole/test/common.js index 7135efdde3c1..8968c401dbdb 100644 --- a/devtools/shared/webconsole/test/common.js +++ b/devtools/shared/webconsole/test/common.js @@ -78,7 +78,7 @@ var _attachConsole = async function( } if (!attachToTab) { - response = await state.dbgClient.mainRoot.getProcess(0); + response = await state.dbgClient.mainRoot.getMainProcess(); await state.dbgClient.attachTarget(response.form.actor); const consoleActor = response.form.consoleActor; state.actor = consoleActor;