tor-browser

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

ExtensionBrowsingData.sys.mjs (1523B)


      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 file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 import { ExtensionUtils } from "resource://gre/modules/ExtensionUtils.sys.mjs";
      6 
      7 const lazy = {};
      8 
      9 ChromeUtils.defineESModuleGetters(lazy, {
     10  EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
     11 });
     12 
     13 const { ExtensionError } = ExtensionUtils;
     14 
     15 export class BrowsingDataDelegate {
     16  constructor(extension) {
     17    this.extension = extension;
     18  }
     19 
     20  async sendRequestForResult(type, data) {
     21    try {
     22      const result = await lazy.EventDispatcher.instance.sendRequestForResult({
     23        type,
     24        extensionId: this.extension.id,
     25        ...data,
     26      });
     27      return result;
     28    } catch (errorMessage) {
     29      throw new ExtensionError(errorMessage);
     30    }
     31  }
     32 
     33  async settings() {
     34    return this.sendRequestForResult("GeckoView:BrowsingData:GetSettings");
     35  }
     36 
     37  async sendClear(dataType, options) {
     38    const { since } = options;
     39    return this.sendRequestForResult("GeckoView:BrowsingData:Clear", {
     40      dataType,
     41      since,
     42    });
     43  }
     44 
     45  // This method returns undefined for all data types that are _not_ handled by
     46  // this delegate.
     47  handleRemoval(dataType, options) {
     48    switch (dataType) {
     49      case "downloads":
     50      case "formData":
     51      case "history":
     52      case "passwords":
     53        return this.sendClear(dataType, options);
     54 
     55      default:
     56        return undefined;
     57    }
     58  }
     59 }