1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 ChromeUtils.defineESModuleGetters(lazy, {
8 WebDriverBiDiConnection:
9 "chrome://remote/content/webdriver-bidi/WebDriverBiDiConnection.sys.mjs",
11 "chrome://remote/content/server/WebSocketHandshake.sys.mjs",
15 * httpd.js JSON handler for direct BiDi connections.
17 export class WebDriverNewSessionHandler {
19 * Construct a new JSON handler.
21 * @param {WebDriverBiDi} webDriverBiDi
22 * Reference to the WebDriver BiDi protocol implementation.
24 constructor(webDriverBiDi) {
25 this.webDriverBiDi = webDriverBiDi;
28 // nsIHttpRequestHandler
31 * Handle new direct WebSocket connection requests.
33 * WebSocket clients not using the WebDriver BiDi opt-in mechanism via the
34 * WebDriver HTTP implementation will attempt to directly connect at
35 * `/session`. Hereby a WebSocket upgrade will automatically be performed.
37 * @param {Request} request
38 * HTTP request (httpd.js)
39 * @param {Response} response
40 * Response to an HTTP request (httpd.js)
42 async handle(request, response) {
43 const webSocket = await lazy.WebSocketHandshake.upgrade(request, response);
44 const conn = new lazy.WebDriverBiDiConnection(
49 this.webDriverBiDi.addSessionlessConnection(conn);
54 get QueryInterface() {
55 return ChromeUtils.generateQI(["nsIHttpRequestHandler"]);