- 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
27 lines
765 B
JavaScript
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;
|
|
},
|
|
},
|
|
};
|
|
}
|
|
};
|