mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 13:55:43 +00:00
Bug 1441647 - update contextmenu code to deal with Shadow DOM, r=jaws
--HG-- extra : rebase_source : 127543b4efe1f7c2ee6712a259ef4f2acc7b2c6d
This commit is contained in:
parent
71145a2b80
commit
b1f43848f2
@ -57,6 +57,8 @@ add_task(async function test_xul_text_link_label() {
|
||||
// Below are test cases for HTML element
|
||||
|
||||
add_task(async function test_setup_html() {
|
||||
await pushPrefs(["dom.webcomponents.shadowdom.enabled", true]);
|
||||
|
||||
let url = example_base + "subtst_contextmenu.html";
|
||||
|
||||
await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
|
||||
@ -131,6 +133,31 @@ add_task(async function test_link() {
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_link_in_shadow_dom() {
|
||||
await test_contextmenu("#shadow-host",
|
||||
["context-openlinkintab", true,
|
||||
...(hasContainers ? ["context-openlinkinusercontext-menu", true] : []),
|
||||
// We need a blank entry here because the containers submenu is
|
||||
// dynamically generated with no ids.
|
||||
...(hasContainers ? ["", null] : []),
|
||||
"context-openlink", true,
|
||||
"context-openlinkprivate", true,
|
||||
"---", null,
|
||||
"context-bookmarklink", true,
|
||||
"context-savelink", true,
|
||||
...(hasPocket ? ["context-savelinktopocket", true] : []),
|
||||
"context-copylink", true,
|
||||
"context-searchselect", true,
|
||||
"---", null,
|
||||
"context-sendlinktodevice", true, [], null,
|
||||
],
|
||||
{
|
||||
offsetX: 6,
|
||||
offsetY: 6
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_mailto() {
|
||||
await test_contextmenu("#test-mailto",
|
||||
["context-copyemail", true,
|
||||
|
@ -8,6 +8,14 @@ Browser context menu subtest.
|
||||
|
||||
<div id="test-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</div>
|
||||
<a id="test-link" href="http://mozilla.com">Click the monkey!</a>
|
||||
<div id="shadow-host"></div>
|
||||
<script>
|
||||
// Create the shadow DOM in case shadow DOM is enabled.
|
||||
if ("ShadowRoot" in this) {
|
||||
var sr = document.getElementById("shadow-host").attachShadow({mode: "closed"});
|
||||
sr.innerHTML = "<a href='http://mozilla.com'>Click the monkey!</a>";
|
||||
}
|
||||
</script>
|
||||
<a id="test-mailto" href="mailto:codemonkey@mozilla.com">Mail the monkey!</a><br>
|
||||
<input id="test-input"><br>
|
||||
<img id="test-image" src="ctxmenu-image.png">
|
||||
|
@ -494,7 +494,7 @@ class ContextMenu {
|
||||
let plugin = null;
|
||||
|
||||
try {
|
||||
plugin = aEvent.target.QueryInterface(Ci.nsIObjectLoadingContent);
|
||||
plugin = aEvent.composedTarget.QueryInterface(Ci.nsIObjectLoadingContent);
|
||||
} catch (e) {}
|
||||
|
||||
if (plugin && plugin.displayedType == Ci.nsIObjectLoadingContent.TYPE_PLUGIN) {
|
||||
@ -509,7 +509,7 @@ class ContextMenu {
|
||||
return;
|
||||
}
|
||||
|
||||
let doc = aEvent.target.ownerDocument;
|
||||
let doc = aEvent.composedTarget.ownerDocument;
|
||||
let {
|
||||
mozDocumentURIIfNotForErrorPages: docLocation,
|
||||
characterSet: charSet,
|
||||
@ -519,14 +519,15 @@ class ContextMenu {
|
||||
} = doc;
|
||||
docLocation = docLocation && docLocation.spec;
|
||||
let frameOuterWindowID = WebNavigationFrames.getFrameId(doc.defaultView);
|
||||
let loginFillInfo = LoginManagerContent.getFieldContext(aEvent.target);
|
||||
let loginFillInfo = LoginManagerContent.getFieldContext(aEvent.composedTarget);
|
||||
|
||||
// The same-origin check will be done in nsContextMenu.openLinkInTab.
|
||||
let parentAllowsMixedContent = !!this.global.docShell.mixedContentChannel;
|
||||
|
||||
// Get referrer attribute from clicked link and parse it
|
||||
let referrerAttrValue = Services.netUtils.parseAttributePolicyString(aEvent.target.
|
||||
getAttribute("referrerpolicy"));
|
||||
let referrerAttrValue =
|
||||
Services.netUtils.parseAttributePolicyString(aEvent.composedTarget.
|
||||
getAttribute("referrerpolicy"));
|
||||
|
||||
if (referrerAttrValue !== Ci.nsIHttpChannel.REFERRER_POLICY_UNSET) {
|
||||
referrerPolicy = referrerAttrValue;
|
||||
@ -537,17 +538,17 @@ class ContextMenu {
|
||||
// Media related cache info parent needs for saving
|
||||
let contentType = null;
|
||||
let contentDisposition = null;
|
||||
if (aEvent.target.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
||||
aEvent.target instanceof Ci.nsIImageLoadingContent &&
|
||||
aEvent.target.currentURI) {
|
||||
disableSetDesktopBg = this._disableSetDesktopBackground(aEvent.target);
|
||||
if (aEvent.composedTarget.nodeType == Ci.nsIDOMNode.ELEMENT_NODE &&
|
||||
aEvent.composedTarget instanceof Ci.nsIImageLoadingContent &&
|
||||
aEvent.composedTarget.currentURI) {
|
||||
disableSetDesktopBg = this._disableSetDesktopBackground(aEvent.composedTarget);
|
||||
|
||||
try {
|
||||
let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
|
||||
.getImgCacheForDocument(doc);
|
||||
// The image cache's notion of where this image is located is
|
||||
// the currentURI of the image loading content.
|
||||
let props = imageCache.findEntryProperties(aEvent.target.currentURI, doc);
|
||||
let props = imageCache.findEntryProperties(aEvent.composedTarget.currentURI, doc);
|
||||
|
||||
try {
|
||||
contentType = props.get("type", Ci.nsISupportsCString).data;
|
||||
@ -562,7 +563,7 @@ class ContextMenu {
|
||||
let selectionInfo = BrowserUtils.getSelectionDetails(this.content);
|
||||
let loadContext = this.global.docShell.QueryInterface(Ci.nsILoadContext);
|
||||
let userContextId = loadContext.originAttributes.userContextId;
|
||||
let popupNodeSelectors = this._getNodeSelectors(aEvent.target);
|
||||
let popupNodeSelectors = this._getNodeSelectors(aEvent.composedTarget);
|
||||
|
||||
this._setContext(aEvent);
|
||||
let context = this.context;
|
||||
@ -581,7 +582,7 @@ class ContextMenu {
|
||||
let isRemote = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
|
||||
|
||||
if (isRemote) {
|
||||
editFlags = SpellCheckHelper.isEditable(aEvent.target, this.content);
|
||||
editFlags = SpellCheckHelper.isEditable(aEvent.composedTarget, this.content);
|
||||
|
||||
if (editFlags & SpellCheckHelper.SPELLCHECKABLE) {
|
||||
spellInfo = InlineSpellCheckerContent.initContextMenu(aEvent, editFlags, this.global);
|
||||
@ -591,10 +592,10 @@ class ContextMenu {
|
||||
// determine what was context-clicked on. Then, update the state of the
|
||||
// commands on the context menu.
|
||||
this.global.docShell.contentViewer.QueryInterface(Ci.nsIContentViewerEdit)
|
||||
.setCommandNode(aEvent.target);
|
||||
aEvent.target.ownerGlobal.updateCommands("contentcontextmenu");
|
||||
.setCommandNode(aEvent.composedTarget);
|
||||
aEvent.composedTarget.ownerGlobal.updateCommands("contentcontextmenu");
|
||||
|
||||
customMenuItems = PageMenuChild.build(aEvent.target);
|
||||
customMenuItems = PageMenuChild.build(aEvent.composedTarget);
|
||||
principal = doc.nodePrincipal;
|
||||
}
|
||||
|
||||
@ -707,7 +708,7 @@ class ContextMenu {
|
||||
context.screenY = aEvent.screenY;
|
||||
context.mozInputSource = aEvent.mozInputSource;
|
||||
|
||||
const node = aEvent.target;
|
||||
const node = aEvent.composedTarget;
|
||||
|
||||
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user