Files
tubestation/browser/components/extensions/child/ext-menus-child.js
Rob Wu cd1bdb8e47 Bug 1325814 - Add extension API to find menu target r=mixedpuppy
- Add info.targetElementId to menus.onShown event.

- Add info.targetElementId to menus.onClicked event.

- Add menus.getTargetElement API that is available to all contexts,
  including content scripts, which allows extensions to get the DOM
  element for a given targetElementId.

- Add new schema instead of re-using schemas/menus.json to avoid sending
  too much schema data (of the existing menus API) to content processes.

MozReview-Commit-ID: 6Onf7jZlIho
2018-08-04 18:09:49 +02:00

27 lines
765 B
JavaScript

"use strict";
this.menusChild = class extends ExtensionAPI {
getAPI(context) {
return {
menus: {
getTargetElement(targetElementId) {
let tabChildGlobal = context.messageManager;
let {contextMenu} = tabChildGlobal;
let element;
if (contextMenu) {
let {lastMenuTarget} = contextMenu;
if (lastMenuTarget && Math.floor(lastMenuTarget.timeStamp) === targetElementId) {
element = lastMenuTarget.targetRef.get();
}
}
// TODO: Support shadow DOM (now we return null).
if (element && context.contentWindow.document.contains(element)) {
return element;
}
return null;
},
},
};
}
};