tor-browser

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

GeckoViewServiceWorker.sys.mjs (1109B)


      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  EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
      9  GeckoViewUtils: "resource://gre/modules/GeckoViewUtils.sys.mjs",
     10 });
     11 
     12 export async function openWindow(uri, aOpenWindowInfo) {
     13  const message = {
     14    type: "GeckoView:ServiceWorkerOpenWindow",
     15    url: uri.spec,
     16  };
     17  const info =
     18    await lazy.EventDispatcher.instance.sendRequestForResult(message);
     19  if (!info) {
     20    throw Components.Exception("", Cr.NS_ERROR_FAILURE);
     21  }
     22 
     23  if (info.isOpen) {
     24    const bc = Services.ww.getWindowByName(info.sessionId)?.browser
     25      ?.browsingContext;
     26    if (bc) {
     27      return bc;
     28    }
     29    throw Components.Exception(
     30      "Unable to find GeckoView session with ID",
     31      Cr.NS_ERROR_NOT_AVAILABLE
     32    );
     33  }
     34 
     35  await lazy.GeckoViewUtils.waitAndSetupWindow(
     36    info.sessionId,
     37    aOpenWindowInfo,
     38    null
     39  );
     40  return null;
     41 }