tor-browser

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

ext-menus-child.js (1076B)


      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 "use strict";
      6 
      7 ChromeUtils.defineESModuleGetters(this, {
      8  ContextMenuChild: "resource:///actors/ContextMenuChild.sys.mjs",
      9 });
     10 
     11 this.menusChild = class extends ExtensionAPI {
     12  getAPI(context) {
     13    return {
     14      menus: {
     15        getTargetElement(targetElementId) {
     16          let element;
     17          let lastMenuTarget = ContextMenuChild.getLastTarget(
     18            context.contentWindow.docShell.browsingContext
     19          );
     20          if (
     21            lastMenuTarget &&
     22            Math.floor(lastMenuTarget.timeStamp) === targetElementId
     23          ) {
     24            element = lastMenuTarget.targetRef.get();
     25          }
     26          if (
     27            element &&
     28            element.getRootNode({ composed: true }) ===
     29              context.contentWindow.document
     30          ) {
     31            return element;
     32          }
     33          return null;
     34        },
     35      },
     36    };
     37  }
     38 };