diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/aboutdebugging/src/modules/runtime-client-factory.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/aboutdebugging/src/modules/runtime-client-factory.js')
-rw-r--r-- | devtools/client/aboutdebugging/src/modules/runtime-client-factory.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/devtools/client/aboutdebugging/src/modules/runtime-client-factory.js b/devtools/client/aboutdebugging/src/modules/runtime-client-factory.js new file mode 100644 index 0000000000..e553416c18 --- /dev/null +++ b/devtools/client/aboutdebugging/src/modules/runtime-client-factory.js @@ -0,0 +1,68 @@ +/* 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 { + prepareTCPConnection, +} = require("resource://devtools/client/shared/remote-debugging/adb/commands/index.js"); +const { + DevToolsClient, +} = require("resource://devtools/client/devtools-client.js"); +const { + DevToolsServer, +} = require("resource://devtools/server/devtools-server.js"); +const { + ClientWrapper, +} = require("resource://devtools/client/aboutdebugging/src/modules/client-wrapper.js"); +const { + remoteClientManager, +} = require("resource://devtools/client/shared/remote-debugging/remote-client-manager.js"); + +const { + RUNTIMES, +} = require("resource://devtools/client/aboutdebugging/src/constants.js"); + +async function createLocalClient() { + DevToolsServer.init(); + DevToolsServer.registerAllActors(); + DevToolsServer.allowChromeProcess = true; + + const client = new DevToolsClient(DevToolsServer.connectPipe()); + await client.connect(); + return new ClientWrapper(client); +} + +async function createNetworkClient(host, port) { + const transport = await DevToolsClient.socketConnect({ host, port }); + const client = new DevToolsClient(transport); + await client.connect(); + return new ClientWrapper(client); +} + +async function createUSBClient(deviceId, socketPath) { + const port = await prepareTCPConnection(deviceId, socketPath); + return createNetworkClient("localhost", port); +} + +async function createClientForRuntime(runtime) { + const { extra, id, type } = runtime; + + if (type === RUNTIMES.THIS_FIREFOX) { + return createLocalClient(); + } else if (remoteClientManager.hasClient(id, type)) { + const client = remoteClientManager.getClient(id, type); + return new ClientWrapper(client); + } else if (type === RUNTIMES.NETWORK) { + const { host, port } = extra.connectionParameters; + return createNetworkClient(host, port); + } else if (type === RUNTIMES.USB) { + const { deviceId, socketPath } = extra.connectionParameters; + return createUSBClient(deviceId, socketPath); + } + + return null; +} + +exports.createClientForRuntime = createClientForRuntime; |