tor-browser

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

service-worker.js (1211B)


      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 const { Actor } = require("resource://devtools/shared/protocol.js");
      8 const {
      9  serviceWorkerSpec,
     10 } = require("resource://devtools/shared/specs/worker/service-worker.js");
     11 
     12 class ServiceWorkerActor extends Actor {
     13  constructor(conn, worker, origin) {
     14    super(conn, serviceWorkerSpec);
     15    this._worker = worker;
     16    this._origin = origin;
     17  }
     18 
     19  form() {
     20    if (!this._worker) {
     21      return null;
     22    }
     23 
     24    // handlesFetchEvents is not available if the worker's main script is in the
     25    // evaluating state.
     26    const isEvaluating =
     27      this._worker.state == Ci.nsIServiceWorkerInfo.STATE_PARSED;
     28    const fetch = isEvaluating ? undefined : this._worker.handlesFetchEvents;
     29 
     30    return {
     31      actor: this.actorID,
     32      url: this._worker.scriptSpec,
     33      origin: this._origin,
     34      state: this._worker.state,
     35      fetch,
     36      id: this._worker.id,
     37    };
     38  }
     39 
     40  destroy() {
     41    super.destroy();
     42    this._worker = null;
     43  }
     44 }
     45 
     46 exports.ServiceWorkerActor = ServiceWorkerActor;