tor-browser

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

last-private-context-exit.js (1322B)


      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 class LastPrivateContextExitWatcher {
      8  #onAvailable;
      9 
     10  /**
     11   * Start watching for all times where we close a private browsing top level window.
     12   * Meaning we should clear the console for all logs generated from these private browsing contexts.
     13   *
     14   * @param WatcherActor watcherActor
     15   *        The watcher actor in the parent process from which we should
     16   *        observe these events.
     17   * @param Object options
     18   *        Dictionary object with following attributes:
     19   *        - onAvailable: mandatory function
     20   *          This will be called for each resource.
     21   */
     22  async watch(watcherActor, { onAvailable }) {
     23    this.#onAvailable = onAvailable;
     24    Services.obs.addObserver(this, "last-pb-context-exited");
     25  }
     26 
     27  observe(subject, topic) {
     28    if (topic === "last-pb-context-exited") {
     29      this.#onAvailable([
     30        // This resource doesn't transfer any data to the client, it is like a one shot event.
     31        {},
     32      ]);
     33    }
     34  }
     35 
     36  destroy() {
     37    Services.obs.removeObserver(this, "last-pb-context-exited");
     38  }
     39 }
     40 
     41 module.exports = LastPrivateContextExitWatcher;