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

Implement declarativeNetRequest dynamic and session rules APIs #21462

Conversation

b-weinstein
Copy link
Contributor

@b-weinstein b-weinstein commented Dec 7, 2023

14bd8a4

Implement declarativeNetRequest dynamic and session rules APIs
https://bugs.webkit.org/show_bug.cgi?id=266016
rdar://118476702&;118476774

Reviewed by Timothy Hatcher.

This patch implements:
- declarativeNetRequest.getSessionRules()
- declarativeNetRequest.updateSessionRules()
- declarativeNetRequest.getDynamicRules()
- declarativeNetRequest.updateDynamicRules()

The big difference between these two APIs is that dynamic rules are persisted to disk and will be loaded across
quitting and relaunching the browser. Session rules will go away.

Also, while we are here, fix a typo in an error message and update the localizable strings.

* Source/WebKit/Shared/Extensions/_WKWebExtensionSQLiteStore.h:
* Source/WebKit/Shared/Extensions/_WKWebExtensionSQLiteStore.mm:
(-[_WKWebExtensionSQLiteStore _savepointNameFromUUID:]): Generate a savepoint name based on the UUID.
(-[_WKWebExtensionSQLiteStore createSavepointWithCompletionHandler:]): Create a savepoint in the database.
(-[_WKWebExtensionSQLiteStore commitSavepoint:completionHandler:]): Commit the savepoint to the database.
(-[_WKWebExtensionSQLiteStore rollbackToSavepoint:completionHandler:]): Rollback the database to a given savepoint.
* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIDeclarativeNetRequestCocoa.mm:
(WebKit::WebExtensionContext::declarativeNetRequestDynamicRulesStore): Create and return a _WKWebExtensionDeclarativeNetRequestSQLiteStore for the
dynamic rules. This will only use the in memory database if storage isn't persistent for the extension context.
(WebKit::WebExtensionContext::declarativeNetRequestSessionRulesStore): Create and return a _WKWebExtensionDeclarativeNetRequestSQLiteStore for the
session rules. This will always use the in memory database.
(WebKit::WebExtensionContext::updateDeclarativeNetRequestRulesInStorage): Attempt to perform the given updates to the rules in the database. The flow is:
- Create a savepoint
- Update the rules by removing and adding rules.
    - If this fails, perform a rollback
    - If this succeeds, attempt to load the new rules
        - If this fails, perform a rollback, and attempt to load the old rules
        - If this succeeds, commit the savepoint
(WebKit::WebExtensionContext::declarativeNetRequestGetDynamicRules): Get the rules from the dynamic rules store.
(WebKit::WebExtensionContext::declarativeNetRequestUpdateDynamicRules): Call into updateDeclarativeNetRequestRulesInStorage.
(WebKit::WebExtensionContext::declarativeNetRequestGetSessionRules): Get the rules from the session rules store.
(WebKit::WebExtensionContext::declarativeNetRequestUpdateSessionRules): Call into updateDeclarativeNetRequestRulesInStorage.
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::loadDeclarativeNetRequestRules): Chain together loading rules from the various sources, the order is:
- Session rules
- Dynamic rules
- Static rules
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.messages.in:
* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIDeclarativeNetRequestCocoa.mm:
(WebKit::WebExtensionAPIDeclarativeNetRequest::updateDynamicRules): Call into the UI process after performing argument validation.
(WebKit::WebExtensionAPIDeclarativeNetRequest::getDynamicRules): Call into the UI process.
(WebKit::WebExtensionAPIDeclarativeNetRequest::updateSessionRules): Call into the UI process after performing argument validation.
(WebKit::WebExtensionAPIDeclarativeNetRequest::getSessionRules): Call into the UI process.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIDeclarativeNetRequest.mm:
(TestWebKitAPI::TEST): Add tests for updating dynamic and session rules and verifying that they block content.

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

b4bd2c0

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

@b-weinstein b-weinstein self-assigned this Dec 7, 2023
@b-weinstein b-weinstein added the WebKit Extensions Bugs related to extension support. label Dec 7, 2023
@b-weinstein b-weinstein force-pushed the eng/Implement-declarativeNetRequest-dynamic-and-session-rules-APIs branch from d1bc0e4 to 730fd74 Compare December 8, 2023 00:53
@b-weinstein b-weinstein added the merge-queue Applied to send a pull request to merge-queue label Dec 8, 2023
@b-weinstein b-weinstein removed the merge-queue Applied to send a pull request to merge-queue label Dec 8, 2023
@b-weinstein b-weinstein force-pushed the eng/Implement-declarativeNetRequest-dynamic-and-session-rules-APIs branch from 730fd74 to b4bd2c0 Compare December 8, 2023 01:03
@b-weinstein b-weinstein added the merge-queue Applied to send a pull request to merge-queue label Dec 8, 2023
@webkit-early-warning-system
Copy link
Collaborator

Starting EWS tests for b4bd2c0. Live statuses available at the PR page, #21462

@webkit-commit-queue webkit-commit-queue force-pushed the eng/Implement-declarativeNetRequest-dynamic-and-session-rules-APIs branch from b4bd2c0 to 8242b66 Compare December 8, 2023 03:13
https://bugs.webkit.org/show_bug.cgi?id=266016
rdar://118476702&118476774

Reviewed by Timothy Hatcher.

This patch implements:
- declarativeNetRequest.getSessionRules()
- declarativeNetRequest.updateSessionRules()
- declarativeNetRequest.getDynamicRules()
- declarativeNetRequest.updateDynamicRules()

The big difference between these two APIs is that dynamic rules are persisted to disk and will be loaded across
quitting and relaunching the browser. Session rules will go away.

Also, while we are here, fix a typo in an error message and update the localizable strings.

* Source/WebKit/Shared/Extensions/_WKWebExtensionSQLiteStore.h:
* Source/WebKit/Shared/Extensions/_WKWebExtensionSQLiteStore.mm:
(-[_WKWebExtensionSQLiteStore _savepointNameFromUUID:]): Generate a savepoint name based on the UUID.
(-[_WKWebExtensionSQLiteStore createSavepointWithCompletionHandler:]): Create a savepoint in the database.
(-[_WKWebExtensionSQLiteStore commitSavepoint:completionHandler:]): Commit the savepoint to the database.
(-[_WKWebExtensionSQLiteStore rollbackToSavepoint:completionHandler:]): Rollback the database to a given savepoint.
* Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIDeclarativeNetRequestCocoa.mm:
(WebKit::WebExtensionContext::declarativeNetRequestDynamicRulesStore): Create and return a _WKWebExtensionDeclarativeNetRequestSQLiteStore for the
dynamic rules. This will only use the in memory database if storage isn't persistent for the extension context.
(WebKit::WebExtensionContext::declarativeNetRequestSessionRulesStore): Create and return a _WKWebExtensionDeclarativeNetRequestSQLiteStore for the
session rules. This will always use the in memory database.
(WebKit::WebExtensionContext::updateDeclarativeNetRequestRulesInStorage): Attempt to perform the given updates to the rules in the database. The flow is:
- Create a savepoint
- Update the rules by removing and adding rules.
    - If this fails, perform a rollback
    - If this succeeds, attempt to load the new rules
        - If this fails, perform a rollback, and attempt to load the old rules
        - If this succeeds, commit the savepoint
(WebKit::WebExtensionContext::declarativeNetRequestGetDynamicRules): Get the rules from the dynamic rules store.
(WebKit::WebExtensionContext::declarativeNetRequestUpdateDynamicRules): Call into updateDeclarativeNetRequestRulesInStorage.
(WebKit::WebExtensionContext::declarativeNetRequestGetSessionRules): Get the rules from the session rules store.
(WebKit::WebExtensionContext::declarativeNetRequestUpdateSessionRules): Call into updateDeclarativeNetRequestRulesInStorage.
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::loadDeclarativeNetRequestRules): Chain together loading rules from the various sources, the order is:
- Session rules
- Dynamic rules
- Static rules
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.messages.in:
* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIDeclarativeNetRequestCocoa.mm:
(WebKit::WebExtensionAPIDeclarativeNetRequest::updateDynamicRules): Call into the UI process after performing argument validation.
(WebKit::WebExtensionAPIDeclarativeNetRequest::getDynamicRules): Call into the UI process.
(WebKit::WebExtensionAPIDeclarativeNetRequest::updateSessionRules): Call into the UI process after performing argument validation.
(WebKit::WebExtensionAPIDeclarativeNetRequest::getSessionRules): Call into the UI process.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIDeclarativeNetRequest.mm:
(TestWebKitAPI::TEST): Add tests for updating dynamic and session rules and verifying that they block content.

Canonical link: https://commits.webkit.org/271706@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Implement-declarativeNetRequest-dynamic-and-session-rules-APIs branch from 8242b66 to 14bd8a4 Compare December 8, 2023 03:16
@webkit-commit-queue
Copy link
Collaborator

Committed 271706@main (14bd8a4): https://commits.webkit.org/271706@main

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

@webkit-commit-queue webkit-commit-queue merged commit 14bd8a4 into WebKit:main Dec 8, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Dec 8, 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
4 participants