tor-browser

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

storage.js (1893B)


      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 {
      8  FrontClassWithSpec,
      9  registerFront,
     10 } = require("resource://devtools/shared/protocol.js");
     11 const { childSpecs } = require("resource://devtools/shared/specs/storage.js");
     12 
     13 for (const childSpec of Object.values(childSpecs)) {
     14  class ChildStorageFront extends FrontClassWithSpec(childSpec) {
     15    constructor(client, targetFront, parentFront) {
     16      super(client, targetFront, parentFront);
     17 
     18      this.on("single-store-update", this._onStoreUpdate.bind(this));
     19    }
     20 
     21    form(form) {
     22      this.actorID = form.actor;
     23      this.hosts = form.hosts;
     24      this.traits = form.traits || {};
     25      return null;
     26    }
     27 
     28    // Update the storage fronts `hosts` properties with potential new hosts and remove the deleted ones
     29    async _onStoreUpdate({ added, deleted }) {
     30      // `resourceKey` comes from the storage resource and is set by the legacy listener
     31      // -or- the resource transformer.
     32      const { resourceKey } = this;
     33      if (added) {
     34        for (const host in added[resourceKey]) {
     35          if (!this.hosts[host]) {
     36            this.hosts[host] = added[resourceKey][host];
     37          }
     38        }
     39      }
     40      if (deleted) {
     41        // While addition have to be added immediately, before ui.js receive single-store-update event
     42        // Deletions have to be removed after ui.js processed single-store-update.
     43        //
     44        // Unfortunately it makes some tests to fail, for ex: browser_storage_cookies_delete_all.js
     45        //
     46        //setTimeout(()=> {
     47        //  for (const host in deleted[resourceKey]) {
     48        //    delete this.hosts[host];
     49        //  }
     50        //}, 2000);
     51      }
     52    }
     53  }
     54  registerFront(ChildStorageFront);
     55 }