tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NewSessionHandler.sys.mjs (1639B)


      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/. */
      4 
      5 const lazy = {};
      6 
      7 ChromeUtils.defineESModuleGetters(lazy, {
      8  WebDriverBiDiConnection:
      9    "chrome://remote/content/webdriver-bidi/WebDriverBiDiConnection.sys.mjs",
     10  WebSocketHandshake:
     11    "chrome://remote/content/server/WebSocketHandshake.sys.mjs",
     12 });
     13 
     14 /**
     15 * httpd.js JSON handler for direct BiDi connections.
     16 */
     17 export class WebDriverNewSessionHandler {
     18  /**
     19   * Construct a new JSON handler.
     20   *
     21   * @param {WebDriverBiDi} webDriverBiDi
     22   *     Reference to the WebDriver BiDi protocol implementation.
     23   */
     24  constructor(webDriverBiDi) {
     25    this.webDriverBiDi = webDriverBiDi;
     26  }
     27 
     28  // nsIHttpRequestHandler
     29 
     30  /**
     31   * Handle new direct WebSocket connection requests.
     32   *
     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.
     36   *
     37   * @param {Request} request
     38   *     HTTP request (httpd.js)
     39   * @param {Response} response
     40   *     Response to an HTTP request (httpd.js)
     41   */
     42  async handle(request, response) {
     43    const webSocket = await lazy.WebSocketHandshake.upgrade(request, response);
     44    const conn = new lazy.WebDriverBiDiConnection(
     45      webSocket,
     46      response._connection
     47    );
     48 
     49    this.webDriverBiDi.addSessionlessConnection(conn);
     50  }
     51 
     52  // XPCOM
     53 
     54  QueryInterface = ChromeUtils.generateQI(["nsIHttpRequestHandler"]);
     55 }