tor-browser

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

GeckoViewAutoFillParent.sys.mjs (2221B)


      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 import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
      6 
      7 const lazy = {};
      8 
      9 ChromeUtils.defineESModuleGetters(lazy, {
     10  gAutofillManager: "resource://gre/modules/GeckoViewAutofill.sys.mjs",
     11 });
     12 
     13 export class GeckoViewAutoFillParent extends GeckoViewActorParent {
     14  constructor() {
     15    super();
     16    this.sessionId = Services.uuid.generateUUID().toString().slice(1, -1); // discard the surrounding curly braces
     17  }
     18 
     19  get rootActor() {
     20    return this.browsingContext.top.currentWindowGlobal.getActor(
     21      "GeckoViewAutoFill"
     22    );
     23  }
     24 
     25  get autofill() {
     26    return lazy.gAutofillManager.get(this.sessionId);
     27  }
     28 
     29  add(node) {
     30    // We will start a new session if the current one does not exist.
     31    const autofill = lazy.gAutofillManager.ensure(
     32      this.sessionId,
     33      this.eventDispatcher
     34    );
     35    return autofill?.add(node);
     36  }
     37 
     38  focus(node) {
     39    this.autofill?.focus(node);
     40  }
     41 
     42  commit(node) {
     43    this.autofill?.commit(node);
     44  }
     45 
     46  update(node) {
     47    this.autofill?.update(node);
     48  }
     49 
     50  clear() {
     51    lazy.gAutofillManager.delete(this.sessionId);
     52  }
     53 
     54  async receiveMessage(aMessage) {
     55    const { name } = aMessage;
     56    debug`receiveMessage ${name}`;
     57 
     58    // We need to re-route all messages through the root actor to ensure that we
     59    // have a consistent sessionId for the entire browsingContext tree.
     60    switch (name) {
     61      case "Add": {
     62        return this.rootActor.add(aMessage.data.node);
     63      }
     64      case "Focus": {
     65        this.rootActor.focus(aMessage.data.node);
     66        break;
     67      }
     68      case "Update": {
     69        this.rootActor.update(aMessage.data.node);
     70        break;
     71      }
     72      case "Commit": {
     73        this.rootActor.commit(aMessage.data.node);
     74        break;
     75      }
     76      case "Clear": {
     77        if (this.browsingContext === this.browsingContext.top) {
     78          this.clear();
     79        }
     80        break;
     81      }
     82    }
     83 
     84    return null;
     85  }
     86 }
     87 
     88 const { debug, warn } =
     89  GeckoViewAutoFillParent.initLogging("GeckoViewAutoFill");