Skip to content

Conversation

burg
Copy link
Contributor

@burg burg commented Aug 21, 2025

19e1927

Web Automation: implement Set Storage Access endpoint
https://bugs.webkit.org/show_bug.cgi?id=297368
rdar://158263193

Reviewed by Charlie Wolfe.

Add new endpoints for setting storage access permission state and
granting storage access to embedded frames for specific origins.

These methods will be called via Automation protocol to implement the
WebDriver Classic endpoints in safaridriver. In a future patch, the
WebAutomationSession methods will be used by the WebDriver BiDi permissions agent.

* Source/WebKit/UIProcess/Automation/Automation.json:
* Source/WebKit/UIProcess/Automation/WebAutomationSession.h:
* Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::setStorageAccessPermissionState):
(WebKit::WebAutomationSession::grantStorageAccess):

[WebDriver BiDi] add support for permissions.setPermission command
https://bugs.webkit.org/show_bug.cgi?id=265621
rdar://119346759

Reviewed by Charlie Wolfe.

Implement the remote end steps for Set Permission.

* Source/WebKit/CMakeLists.txt:
* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/Sources.txt:
* Source/WebKit/UIProcess/Automation/BidiPermissionsAgent.cpp: Added.
(WebKit::BidiPermissionsAgent::BidiPermissionsAgent):
(WebKit::allPageProxiesFor):
(WebKit::BidiPermissionsAgent::setPermission):
Added. Defer to WebSiteDataStore and NetworkProcess for the actual implementation.

* Source/WebKit/UIProcess/Automation/BidiPermissionsAgent.h: Added.
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.cpp:
(WebKit::WebDriverBidiProcessor::WebDriverBidiProcessor):
Add BidiPermissionAgent.
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.h:
* Source/WebKit/UIProcess/Automation/protocol/BidiPermissions.json: Added.

* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
Add new domain and associated derived sources and project entries.

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

a0fdd11

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ✅ 🛠 ios-apple
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 🧪 win-tests ✅ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@burg burg requested a review from cdumez as a code owner August 21, 2025 00:21
@burg burg self-assigned this Aug 21, 2025
@burg burg added the Tools / Tests Tools in the Tools directory, build issues, test infrastructure, and bugs in test cases label Aug 21, 2025
continue;

bool granted = state == Inspector::Protocol::BidiPermissions::PermissionState::Granted;
page->protectedWebsiteDataStore()->setStorageAccessPermissionForTesting(granted, page->identifier(), topFrameOrigin.string(), (embeddedOriginIsWildcard ? topFrameOrigin : embeddedOrigin).string(), [aggregator] () { });
Copy link
Contributor

@the-chenergy the-chenergy Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
page->protectedWebsiteDataStore()->setStorageAccessPermissionForTesting(granted, page->identifier(), topFrameOrigin.string(), (embeddedOriginIsWildcard ? topFrameOrigin : embeddedOrigin).string(), [aggregator] () { });
page->protectedWebsiteDataStore()->setStorageAccessPermissionForTesting(granted, page->identifier(), topFrameOrigin.string(), (embeddedOriginIsWildcard ? topFrameOrigin : embeddedOrigin).string(), [aggregator]() { });

bool embeddedOriginIsWildcard = subFrameURLString == "*"_s;
auto embeddedOrigin = RegistrableDomain { URL { subFrameURLString } };

auto aggregator = WTF::CallbackAggregator::create([callback = WTFMove(callback)]() mutable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should either this lambda or the one below also capture a protectedThis = Ref { *this }?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote that before, but I removed it because the code doesn't actually use this in the callback. We have captured a ref to backendDispatcher in the generated lambda glue code that calls into the agent method.

m_agent->setPermission(in_descriptor.releaseNonNull(), in_origin, *in_state, in_opt_userContext, [backendDispatcher = m_backendDispatcher.copyRef(), 
...

So it shouldn't be necessary to protect this, as BackendDispatcher and FrontendRounter will gracefully stop sending responses when there's no more frontends connected. In the WebDriver BiDi case, the BidiProcessor owns both frontend and backend dispatcher. So, if a callback outlasts the processor itself, sendResponse will dead end at the frontend router that doesn't have any connections.

I did a deep dive on the refcounting situation and i don't see the need to protect the agent as its owned by the processor. Plus, in the WebDriver BiDi case, the processor is used as a fake "connection" so that it can forward events and command responses through to WebAutomationSession::sendBidiMessage.

@burg burg force-pushed the eng/bburg/wk265521-webdriver-bidi-set-permission branch from e7a9ddc to 10c0b6f Compare August 26, 2025 18:41
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Aug 27, 2025
"description": "Simulates user modification of a PermissionDescriptor's permission state.",
"spec": "https://www.w3.org/TR/permissions/#webdriver-bidi-command-permissions-setPermission",
"wpt": "https://github.com/web-platform-tests/wpt/tree/master/webdriver/tests/bidi/permissions/set",
"async": true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: async usually at the bottom

"name": "setPermission",
"description": "Simulates user modification of a PermissionDescriptor's permission state.",
"spec": "https://www.w3.org/TR/permissions/#webdriver-bidi-command-permissions-setPermission",
"wpt": "https://github.com/web-platform-tests/wpt/tree/master/webdriver/tests/bidi/permissions/set",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link seems buggy ? I don't see a permissions bidi suite

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this is the correct link:
https://github.com/web-platform-tests/wpt/tree/master/webdriver/tests/bidi/external/permissions/set_permission

it's in a separate external directory because it's defined externally from the main bidi spec.

@charliewolfe
Copy link
Member

Please also update the title to indicate this includes WebDriver Classic and the set storage access command.

@burg burg removed the merging-blocked Applied to prevent a change from being merged label Aug 28, 2025
@burg burg force-pushed the eng/bburg/wk265521-webdriver-bidi-set-permission branch from 10c0b6f to 4230afb Compare August 28, 2025 18:21
@burg burg changed the title [WebDriver BiDi] add support for permissions.setPermission command Web Automation: add support for permissions.setPermission command Aug 28, 2025
@burg burg added the merge-queue Applied to send a pull request to merge-queue label Aug 28, 2025
@webkit-commit-queue
Copy link
Collaborator

This change contains multiple commits which are not squashed together, blocking PR #49692. Please squash the commits to land.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Aug 28, 2025
@webkit-commit-queue webkit-commit-queue added the merging-blocked Applied to prevent a change from being merged label Aug 28, 2025
@burg burg removed the merging-blocked Applied to prevent a change from being merged label Sep 4, 2025
@burg burg changed the title Web Automation: add support for permissions.setPermission command Web Automation: implement Set Storage Access endpoint Sep 4, 2025
@burg burg force-pushed the eng/bburg/wk265521-webdriver-bidi-set-permission branch from 4230afb to a0fdd11 Compare September 4, 2025 01:56
@burg burg added New Bugs Unclassified bugs are placed in this component until the correct component can be determined. and removed Tools / Tests Tools in the Tools directory, build issues, test infrastructure, and bugs in test cases labels Sep 4, 2025
@burg burg added the merge-queue Applied to send a pull request to merge-queue label Sep 4, 2025
https://bugs.webkit.org/show_bug.cgi?id=297368
rdar://158263193

Reviewed by Charlie Wolfe.

Add new endpoints for setting storage access permission state and
granting storage access to embedded frames for specific origins.

These methods will be called via Automation protocol to implement the
WebDriver Classic endpoints in safaridriver. In a future patch, the
WebAutomationSession methods will be used by the WebDriver BiDi permissions agent.

* Source/WebKit/UIProcess/Automation/Automation.json:
* Source/WebKit/UIProcess/Automation/WebAutomationSession.h:
* Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::setStorageAccessPermissionState):
(WebKit::WebAutomationSession::grantStorageAccess):

[WebDriver BiDi] add support for permissions.setPermission command
https://bugs.webkit.org/show_bug.cgi?id=265621
rdar://119346759

Reviewed by Charlie Wolfe.

Implement the remote end steps for Set Permission.

* Source/WebKit/CMakeLists.txt:
* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/Sources.txt:
* Source/WebKit/UIProcess/Automation/BidiPermissionsAgent.cpp: Added.
(WebKit::BidiPermissionsAgent::BidiPermissionsAgent):
(WebKit::allPageProxiesFor):
(WebKit::BidiPermissionsAgent::setPermission):
Added. Defer to WebSiteDataStore and NetworkProcess for the actual implementation.

* Source/WebKit/UIProcess/Automation/BidiPermissionsAgent.h: Added.
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.cpp:
(WebKit::WebDriverBidiProcessor::WebDriverBidiProcessor):
Add BidiPermissionAgent.
* Source/WebKit/UIProcess/Automation/WebDriverBidiProcessor.h:
* Source/WebKit/UIProcess/Automation/protocol/BidiPermissions.json: Added.

* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
Add new domain and associated derived sources and project entries.

Canonical link: https://commits.webkit.org/299547@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/bburg/wk265521-webdriver-bidi-set-permission branch from a0fdd11 to 19e1927 Compare September 4, 2025 09:07
@webkit-commit-queue
Copy link
Collaborator

Committed 299547@main (19e1927): https://commits.webkit.org/299547@main

Reviewed commits have been landed. Closing PR #49692 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 19e1927 into WebKit:main Sep 4, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Bugs Unclassified bugs are placed in this component until the correct component can be determined.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants