tor-browser

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

window.js (1202B)


      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 "use strict";
      6 
      7 /**
      8 * Returns the `nsIDOMWindow` toplevel window for any child/inner window
      9 */
     10 function getTopLevelWindow(window) {
     11  return window.browsingContext.topChromeWindow;
     12 }
     13 exports.getTopLevelWindow = getTopLevelWindow;
     14 
     15 function getDOMWindowUtils(window) {
     16  return window.windowUtils;
     17 }
     18 exports.getDOMWindowUtils = getDOMWindowUtils;
     19 
     20 /**
     21 * Check if the given browser window has finished the startup.
     22 *
     23 * @param {nsIDOMWindow} window
     24 */
     25 const isStartupFinished = window => window.gBrowserInit?.delayedStartupFinished;
     26 
     27 function startup(window) {
     28  return new Promise(resolve => {
     29    if (isStartupFinished(window)) {
     30      resolve(window);
     31      return;
     32    }
     33    Services.obs.addObserver(function listener({ subject }) {
     34      if (subject === window) {
     35        Services.obs.removeObserver(
     36          listener,
     37          "browser-delayed-startup-finished"
     38        );
     39        resolve(window);
     40      }
     41    }, "browser-delayed-startup-finished");
     42  });
     43 }
     44 exports.startup = startup;