Bug 1730625 - Walk the flat tree to search for links. r=smaug

Also make some other context-menu code a lot more straight-forward, and
remove some enabledness checks now that shadow dom can't be disabled.

Differential Revision: https://phabricator.services.mozilla.com/D125487
This commit is contained in:
Emilio Cobos Álvarez 2021-09-14 10:26:46 +00:00
Родитель 0b513c5331
Коммит 459a0551b8
3 изменённых файлов: 56 добавлений и 82 удалений

Просмотреть файл

@ -778,21 +778,14 @@ class ContextMenuChild extends JSWindowActorChild {
// Set the node to containing <video>/<audio>/<embed>/<object> if the node
// is in the videocontrols UA Widget.
if (this.contentWindow.ShadowRoot) {
let n = node;
while (n) {
if (n instanceof this.contentWindow.ShadowRoot) {
if (node.containingShadowRoot?.isUAWidget()) {
const host = node.containingShadowRoot.host;
if (
n.host instanceof this.contentWindow.HTMLMediaElement ||
n.host instanceof this.contentWindow.HTMLEmbedElement ||
n.host instanceof this.contentWindow.HTMLObjectElement
host instanceof this.contentWindow.HTMLMediaElement ||
host instanceof this.contentWindow.HTMLEmbedElement ||
host instanceof this.contentWindow.HTMLObjectElement
) {
node = n.host;
break;
}
break;
}
n = n.parentNode;
node = host;
}
}
@ -1165,7 +1158,7 @@ class ContextMenuChild extends JSWindowActorChild {
}
}
elem = elem.parentNode;
elem = elem.flattenedTreeParentNode;
}
// See if the user clicked in a frame.

Просмотреть файл

@ -174,8 +174,7 @@ add_task(async function test_plaintext() {
]);
});
add_task(async function test_link() {
await test_contextmenu("#test-link", [
const kLinkItems = [
"context-openlinkintab",
true,
...(hasContainers ? ["context-openlinkinusercontext-menu", true] : []),
@ -201,44 +200,24 @@ add_task(async function test_link() {
true,
"context-searchselect-private",
true,
]);
];
add_task(async function test_link() {
await test_contextmenu("#test-link", kLinkItems);
});
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,
"---",
null,
"context-searchselect",
true,
"context-searchselect-private",
true,
],
{
await test_contextmenu("#shadow-host", kLinkItems, {
offsetX: 6,
offsetY: 6,
}
);
});
});
add_task(async function test_link_over_shadow_dom() {
await test_contextmenu("#shadow-host-in-link", kLinkItems, {
offsetX: 6,
offsetY: 6,
});
});
add_task(async function test_mailto() {

Просмотреть файл

@ -9,12 +9,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>
<a href="http://mozilla.com" style="display: block">
<span id="shadow-host-in-link"></span>
</a>
<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>";
}
document.getElementById("shadow-host").attachShadow({ mode: "closed" }).innerHTML =
"<a href='http://mozilla.com'>Click the monkey!</a>";
document.getElementById("shadow-host-in-link").attachShadow({ mode: "closed" }).innerHTML =
"<span>Click the monkey!</span>";
</script>
<a id="test-mailto" href="mailto:codemonkey@mozilla.com">Mail the monkey!</a><br>
<input id="test-input"><br>