Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: dc0433ce5323618190e4333d0388dcbc8606d917
      
https://github.com/WebKit/WebKit/commit/dc0433ce5323618190e4333d0388dcbc8606d917
  Author: Wenson Hsieh <[email protected]>
  Date:   2024-04-06 (Sat, 06 Apr 2024)

  Changed paths:
    M Source/WebCore/page/ElementTargetingController.cpp
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm
    A Tools/TestWebKitAPI/Tests/WebKitCocoa/element-targeting-4.html

  Log Message:
  -----------
  [Remote Inspection] Targeting heuristic may surface redundant elements in 
shadow roots
https://bugs.webkit.org/show_bug.cgi?id=272283
rdar://121251828

Reviewed by Megan Gardner and Richard Robinson.

Currently, in the case where a targeted element is (or contains a) shadow root 
that encapsulates
other candidates, we end up surfacing both the outer container element as well 
as the inner element
in the shadow root as targeted elements to the WebKit client.

Under normal circumstances, adding the outer element as a target should exclude 
the inner element
from being a candidate. However, it fails in this case because the logic to 
enforce this invariant:

```
candidates.removeAllMatching([&](auto& candidate) {
    if (target.ptr() != candidate.ptr() && !target->contains(candidate))
        return false;
```

...uses `Node::contains(…)`, which does not account for shadow roots into 
account. Fix this by
simply replacing this call with `containsIncludingShadowDOM`.

Test: ElementTargeting.ContentInsideShadowRoot

* Source/WebCore/page/ElementTargetingController.cpp:
(WebCore::selectorsForTarget):

There's also no point in surfacing a CSS selector to match content in shadow 
roots to the client. In
a subsequent patch, we should provide an alternate means to resolve content 
inside of shadow roots
that doesn't rely on (or relies on more than just) CSS selectors.

(WebCore::ElementTargetingController::findTargets):
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm:
(TestWebKitAPI::TEST(ElementTargeting, ContentInsideShadowRoot)):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/element-targeting-4.html: Added.

Add a new API test to cover this scenario.

Canonical link: https://commits.webkit.org/277171@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to