Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Web Extensions permissions.request() API. #8333

Conversation

kiaraarose
Copy link
Contributor

@kiaraarose kiaraarose commented Jan 7, 2023

65e4c3d

Add support for Web Extensions permissions.request() API.
https://bugs.webkit.org/show_bug.cgi?id=250135
Reviewed by Timothy Hatcher.

This patch implements the permissions.request() API. This includes delegating the action of requesting
permissions from the users to the browsers. Once that action has been fulfilled and the user grants
all requested permissions, we add them to the extension's granted permissions and match pattern sets.

* Source/WebKit/Platform/cocoa/CocoaHelpers.h:
* Source/WebKit/Platform/cocoa/CocoaHelpers.mm:
(WebKit::toAPI): Helper method to convert from HashSet<String> to NSSet<String>.
(WebKit::toAPIArray):Helper method to convert from HashSet<String> to NSArray<String>.

* Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionControllerDelegate.h:
Define the delegate methods used to prompt users to grant permissions.

* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIEventCocoa.mm:
Remove unnecessary file import.

* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIPermissionsCocoa.mm:
(WebKit::WebExtensionContext::permissionsContains):

(WebKit::WebExtensionContext::permissionsRequest):
Call delegate methods to determine if permissions should be granted.

(WebKit::WebExtensionContext::permissionsRemove):

(WebKit::WebExtensionContext::firePermissionsEventListenerIfNecessary):
Fire permissions onAdded or onRemoved events if permissions are granted or removed.

(WebKit::WebExtensionContext::parseMatchPatterns): Deleted.

* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::postAsyncNotification):
Call firePermissionsEventListenerIfNecessary whenever a notification is posted for a change in an
extension's permissions.

(WebKit::WebExtensionContext::hasPermissions):
(WebKit::WebExtensionContext::wakeUpBackgroundContentIfNecessaryToFireEvents):
`fireEvents` isn’t an accurate name for this method since it doesn’t actually fire any events.
We should rename this to better describe what’s happening in this method
(WebKit::WebExtensionContext::fireEvents): Deleted.

* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionControllerCocoa.mm:
(WebKit::WebExtensionController::didStartProvisionalLoadForFrame):
(WebKit::WebExtensionController::didCommitLoadForFrame):
(WebKit::WebExtensionController::didFinishLoadForFrame):
(WebKit::WebExtensionController::didFailLoadForFrame):

* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionMatchPatternCocoa.mm:
(WebKit::WebExtensionMatchPattern::matchPatternStrings):
(WebKit::WebExtensionMatchPattern::matchPatternsForOrigins):

* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
* Source/WebKit/UIProcess/Extensions/WebExtensionMatchPattern.h:
* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIPermissionsCocoa.mm:
Validate permissions details for these APIs.
(WebKit::WebExtensionAPIPermissions::contains):
(WebKit::WebExtensionAPIPermissions::request):
(WebKit::WebExtensionAPIPermissions::remove):
(WebKit::WebExtensionAPIPermissions::verifyRequestedPermissions):

(WebKit::WebExtensionAPIPermissions::onAdded):
(WebKit::WebExtensionAPIPermissions::onRemoved):
Pass in the WebExtensionEventListenerType when creating these events.

* Source/WebKit/WebProcess/Extensions/Cocoa/WebExtensionContextProxyCocoa.mm:
(WebKit::WebExtensionContextProxy::dispatchPermissionsEvent):
Enumerate through the namespace objects and invoke the listeners for the event listener.

* Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.h:
* Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.messages.in:
* Tools/TestWebKitAPI/SourcesCocoa.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIPermissions.mm: Added.
(TestWebKitAPI::runScriptWithUserGesture):
(TestWebKitAPI::TEST):
Add WebKit tests for Permissions API.

* Tools/TestWebKitAPI/cocoa/TestWebExtensionsDelegate.h:
Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionControllerDelegate.h.

* Tools/TestWebKitAPI/cocoa/TestWebExtensionsDelegate.mm:
Copied from Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.messages.in.
(-[TestWebExtensionsDelegate
webExtensionController:promptForPermissions:inTab:forExtensionContext:completionHandler:]):
(-[TestWebExtensionsDelegate
webExtensionController:promptForPermissionMatchPatterns:inTab:forExtensionContext:completionHandler:]):

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

be41e1e

Misc iOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 wincairo
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🛠 gtk
✅ 🧪 webkitperl 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 gtk-wk2
✅ 🧪 api-ios ✅ 🧪 mac-wk1 🧪 api-gtk
✅ 🛠 tv ✅ 🧪 mac-wk2
✅ 🛠 tv-sim ✅ 🧪 mac-AS-debug-wk2
✅ 🛠 watch ✅ 🧪 mac-wk2-stress
✅ 🛠 watch-sim
✅ 🛠 🧪 unsafe-merge

@kiaraarose kiaraarose self-assigned this Jan 7, 2023
@kiaraarose kiaraarose added the WebKit Extensions Bugs related to extension support. label Jan 7, 2023
@kiaraarose kiaraarose force-pushed the eng/Add-Support-For-Permissions-Request-API branch from f8c5572 to 0765783 Compare January 7, 2023 01:02
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 7, 2023
@kiaraarose kiaraarose removed the merging-blocked Applied to prevent a change from being merged label Feb 8, 2023
@kiaraarose kiaraarose force-pushed the eng/Add-Support-For-Permissions-Request-API branch from 0765783 to 8f0ef66 Compare February 8, 2023 00:23
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Feb 8, 2023
@kiaraarose kiaraarose removed the merging-blocked Applied to prevent a change from being merged label Feb 8, 2023
@kiaraarose kiaraarose force-pushed the eng/Add-Support-For-Permissions-Request-API branch from 8f0ef66 to d7a1e9a Compare February 8, 2023 22:49
@kiaraarose kiaraarose force-pushed the eng/Add-Support-For-Permissions-Request-API branch 2 times, most recently from 179f4f6 to 55335cd Compare February 14, 2023 18:16
@kiaraarose kiaraarose force-pushed the eng/Add-Support-For-Permissions-Request-API branch from 55335cd to bc1cd3d Compare February 15, 2023 17:58
@kiaraarose kiaraarose force-pushed the eng/Add-Support-For-Permissions-Request-API branch 2 times, most recently from 8c8e91e to 160b4c5 Compare February 15, 2023 21:41
@kiaraarose kiaraarose force-pushed the eng/Add-Support-For-Permissions-Request-API branch from 160b4c5 to be41e1e Compare February 15, 2023 23:16
@kiaraarose kiaraarose added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Feb 16, 2023
https://bugs.webkit.org/show_bug.cgi?id=250135
Reviewed by Timothy Hatcher.

This patch implements the permissions.request() API. This includes delegating the action of requesting
permissions from the users to the browsers. Once that action has been fulfilled and the user grants
all requested permissions, we add them to the extension's granted permissions and match pattern sets.

* Source/WebKit/Platform/cocoa/CocoaHelpers.h:
* Source/WebKit/Platform/cocoa/CocoaHelpers.mm:
(WebKit::toAPI): Helper method to convert from HashSet<String> to NSSet<String>.
(WebKit::toAPIArray):Helper method to convert from HashSet<String> to NSArray<String>.

* Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionControllerDelegate.h:
Define the delegate methods used to prompt users to grant permissions.

* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIEventCocoa.mm:
Remove unnecessary file import.

* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIPermissionsCocoa.mm:
(WebKit::WebExtensionContext::permissionsContains):

(WebKit::WebExtensionContext::permissionsRequest):
Call delegate methods to determine if permissions should be granted.

(WebKit::WebExtensionContext::permissionsRemove):

(WebKit::WebExtensionContext::firePermissionsEventListenerIfNecessary):
Fire permissions onAdded or onRemoved events if permissions are granted or removed.

(WebKit::WebExtensionContext::parseMatchPatterns): Deleted.

* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::postAsyncNotification):
Call firePermissionsEventListenerIfNecessary whenever a notification is posted for a change in an
extension's permissions.

(WebKit::WebExtensionContext::hasPermissions):
(WebKit::WebExtensionContext::wakeUpBackgroundContentIfNecessaryToFireEvents):
`fireEvents` isn’t an accurate name for this method since it doesn’t actually fire any events.
We should rename this to better describe what’s happening in this method
(WebKit::WebExtensionContext::fireEvents): Deleted.

* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionControllerCocoa.mm:
(WebKit::WebExtensionController::didStartProvisionalLoadForFrame):
(WebKit::WebExtensionController::didCommitLoadForFrame):
(WebKit::WebExtensionController::didFinishLoadForFrame):
(WebKit::WebExtensionController::didFailLoadForFrame):

* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionMatchPatternCocoa.mm:
(WebKit::WebExtensionMatchPattern::matchPatternStrings):
(WebKit::WebExtensionMatchPattern::matchPatternsForOrigins):

* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
* Source/WebKit/UIProcess/Extensions/WebExtensionMatchPattern.h:
* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIPermissionsCocoa.mm:
Validate permissions details for these APIs.
(WebKit::WebExtensionAPIPermissions::contains):
(WebKit::WebExtensionAPIPermissions::request):
(WebKit::WebExtensionAPIPermissions::remove):
(WebKit::WebExtensionAPIPermissions::verifyRequestedPermissions):

(WebKit::WebExtensionAPIPermissions::onAdded):
(WebKit::WebExtensionAPIPermissions::onRemoved):
Pass in the WebExtensionEventListenerType when creating these events.

* Source/WebKit/WebProcess/Extensions/Cocoa/WebExtensionContextProxyCocoa.mm:
(WebKit::WebExtensionContextProxy::dispatchPermissionsEvent):
Enumerate through the namespace objects and invoke the listeners for the event listener.

* Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.h:
* Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.messages.in:
* Tools/TestWebKitAPI/SourcesCocoa.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIPermissions.mm: Added.
(TestWebKitAPI::runScriptWithUserGesture):
(TestWebKitAPI::TEST):
Add WebKit tests for Permissions API.

* Tools/TestWebKitAPI/cocoa/TestWebExtensionsDelegate.h:
Copied from Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionControllerDelegate.h.

* Tools/TestWebKitAPI/cocoa/TestWebExtensionsDelegate.mm:
Copied from Source/WebKit/WebProcess/Extensions/WebExtensionContextProxy.messages.in.
(-[TestWebExtensionsDelegate
webExtensionController:promptForPermissions:inTab:forExtensionContext:completionHandler:]):
(-[TestWebExtensionsDelegate
webExtensionController:promptForPermissionMatchPatterns:inTab:forExtensionContext:completionHandler:]):

Canonical link: https://commits.webkit.org/260370@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/Add-Support-For-Permissions-Request-API branch from be41e1e to 65e4c3d Compare February 16, 2023 16:53
@webkit-commit-queue
Copy link
Collaborator

Committed 260370@main (65e4c3d): https://commits.webkit.org/260370@main

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

@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Feb 16, 2023
@webkit-early-warning-system webkit-early-warning-system merged commit 65e4c3d into WebKit:main Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Extensions Bugs related to extension support.
Projects
None yet
5 participants