diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /remote/cdp/targets/Target.sys.mjs | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/cdp/targets/Target.sys.mjs')
-rw-r--r-- | remote/cdp/targets/Target.sys.mjs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/remote/cdp/targets/Target.sys.mjs b/remote/cdp/targets/Target.sys.mjs new file mode 100644 index 0000000000..9264110c37 --- /dev/null +++ b/remote/cdp/targets/Target.sys.mjs @@ -0,0 +1,62 @@ +/* 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/. */ + +const lazy = {}; + +ChromeUtils.defineESModuleGetters(lazy, { + CDPConnection: "chrome://remote/content/cdp/CDPConnection.sys.mjs", + generateUUID: "chrome://remote/content/shared/UUID.sys.mjs", + WebSocketHandshake: + "chrome://remote/content/server/WebSocketHandshake.sys.mjs", +}); + +/** + * Base class for all the targets. + */ +export class Target { + /** + * @param {TargetList} targetList + * @param {Class} sessionClass + */ + constructor(targetList, sessionClass) { + // Save a reference to TargetList instance in order to expose it to: + // domains/parent/Target.jsm + this.targetList = targetList; + + // When a new connection is made to this target, + // we will instantiate a new session based on this given class. + // The session class is specific to each target's kind and is passed + // by the inheriting class. + this.sessionClass = sessionClass; + + // There can be more than one connection if multiple clients connect to the remote agent. + this.connections = new Set(); + this.id = lazy.generateUUID(); + } + + /** + * Close all active connections made to this target. + */ + destructor() { + for (const conn of this.connections) { + conn.close(); + } + } + + // nsIHttpRequestHandler + + async handle(request, response) { + const webSocket = await lazy.WebSocketHandshake.upgrade(request, response); + const conn = new lazy.CDPConnection(webSocket, response._connection); + const session = new this.sessionClass(conn, this); + conn.registerSession(session); + this.connections.add(conn); + } + + // XPCOM + + get QueryInterface() { + return ChromeUtils.generateQI(["nsIHttpRequestHandler"]); + } +} |