[webkit-changes] [WebKit/WebKit] c318bf: [Remote Inspection] Add support for targets in nes...
Wenson Hsieh
noreply at github.com
Tue Apr 23 18:17:53 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: c318bffec39ae54ee6bcfefaf129d1ab52790bde
https://github.com/WebKit/WebKit/commit/c318bffec39ae54ee6bcfefaf129d1ab52790bde
Author: Wenson Hsieh <wenson_hsieh at apple.com>
Date: 2024-04-23 (Tue, 23 Apr 2024)
Changed paths:
M Source/WebCore/loader/DocumentLoader.h
M Source/WebCore/page/ElementTargetingController.cpp
M Source/WebCore/page/ElementTargetingController.h
M Source/WebCore/page/ElementTargetingTypes.h
M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
M Source/WebKit/Shared/WebsitePoliciesData.h
M Source/WebKit/Shared/WebsitePoliciesData.serialization.in
M Source/WebKit/UIProcess/API/APITargetedElementInfo.h
M Source/WebKit/UIProcess/API/APIWebsitePolicies.h
M Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm
M Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h
M Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.h
M Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.mm
M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
M Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm
A Tools/TestWebKitAPI/Tests/WebKitCocoa/element-targeting-8.html
Log Message:
-----------
[Remote Inspection] Add support for targets in nested shadow roots
https://bugs.webkit.org/show_bug.cgi?id=273076
rdar://123160948
Reviewed by Tim Horton, Abrar Protyasha and Aditya Keerthi.
Currently, `visibilityAdjustmentSelectors` is a flattened list of CSS selectors, which correspond to
an arbitrary number of targeted elements. This has a couple of drawbacks:
1. We might resolve more targets than there originally were (in the case where a targeted element
had multiple potential selectors, but one of them now maps to something else).
2. It's unable to resolve targeted elements inside of shadow roots.
I previously worked around this in 277171 at main by just returning an empty list in the case where the
element is inside of a shadow tree, but that only fixed the case where the targeted element itself
contained a shadow root (rather than being inside of the shadow DOM). This patch actually fixes this
issue, by revamping how we both surface and ingest CSS selectors corresponding to targeted elements:
• `TargetedElementInfo` now contains a array of array of selectors. Each element in the outer
array corresponds to an enclosing shadow host element that contains the targeted element (such
that the final array maps to the targeted element itself). For targets that are not inside
shadow roots, this simply means that there's a single outer array. The inner array, like before,
represents a array of selectors (sorted by length) that can be used to resolve the target (or
shadow host containing the target) within its tree scope.
• `WKWebpagePreferences` now has a `_visibilityAdjustmentSelectorsIncludingShadowHosts` property,
which consists of an array of array of sets of strings. To unpack this:
1. Each array in the outermost (first) array represents a single targeted element.
2. Each set in the second array represents a targeted element or shadow host containing the
targeted element. The last element is the targeted element itself, and the first element (if
the targeted element is inside of a shadow root) is the outermost shadow host element in the
document.
3. Each string in the set represents a CSS selector that can potentially be used to resolve the
targeted element or one of its hosts, within its tree scope.
To make this work, we:
(a) Make `TargetedElementController` recursively ascend the DOM by shadow host, to construct a
`Vector<Vector<String>>` for each targeted element.
(b) Teach `TargetedElementController` to ingest the array of array of sets described above to
resolve targeted elements that reside inside shadow trees.
There is no change in behavior for the case where targeted elements aren't inside the shadow DOM.
Test: ElementTargeting.AdjustVisibilityForTargetsInShadowRoot
* Source/WebCore/loader/DocumentLoader.h:
(WebCore::DocumentLoader::visibilityAdjustmentSelectors const):
(WebCore::DocumentLoader::setVisibilityAdjustmentSelectors):
* Source/WebCore/page/ElementTargetingController.cpp:
(WebCore::querySelectorMatchesOneElement):
(WebCore::computeIDSelector):
(WebCore::selectorsForTarget):
For elements inside of shadow roots, teach this to recursively find selectors that resolve to shadow
hosts, and return a list of lists of selectors.
(WebCore::targetedElementInfo):
(WebCore::ElementTargetingController::applyVisibilityAdjustmentFromSelectors):
Teach this to apply visibility adjustment to content inside of shadow roots.
* Source/WebCore/page/ElementTargetingController.h:
* Source/WebCore/page/ElementTargetingTypes.h:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
Turn the list of selectors for each targeted element into a list of lists instead. See comments
above for more detail.
* Source/WebKit/Shared/WebsitePoliciesData.h:
* Source/WebKit/Shared/WebsitePoliciesData.serialization.in:
Turn the set of selectors into a list of list of sets. See comments above for more detail.
* Source/WebKit/UIProcess/API/APITargetedElementInfo.h:
* Source/WebKit/UIProcess/API/APIWebsitePolicies.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm:
(-[WKWebpagePreferences _setVisibilityAdjustmentSelectorsIncludingShadowHosts:]):
(-[WKWebpagePreferences _visibilityAdjustmentSelectorsIncludingShadowHosts]):
(-[WKWebpagePreferences _setVisibilityAdjustmentSelectors:]):
(-[WKWebpagePreferences _visibilityAdjustmentSelectors]):
Implement these on top of the new `_visibilityAdjustmentSelectorsIncludingShadowHosts` property.
Once no internal client relies on this anymore, we can simply remove it.
* Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.mm:
(-[_WKTargetedElementInfo selectors]):
(-[_WKTargetedElementInfo selectorsIncludingShadowHosts]):
(-[_WKTargetedElementInfo isInShadowTree]):
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm:
(TestWebKitAPI::TEST(ElementTargeting, AdjustVisibilityFromPseudoSelectors)):
(TestWebKitAPI::TEST(ElementTargeting, AdjustVisibilityForTargetsInShadowRoot)):
(TestWebKitAPI::TEST(ElementTargeting, TargetContainsShadowRoot)):
(TestWebKitAPI::TEST(ElementTargeting, ContentInsideShadowRoot)): Deleted.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/element-targeting-8.html: Added.
Add an API test to exercise all three of the new SPIs. Also rename `ContentInsideShadowRoot` to
`TargetContainsShadowRoot`, the latter of which is a more accurate name (since the targeted element
itself isn't inside the shadow DOM).
Canonical link: https://commits.webkit.org/277907@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list