Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 14bd8a42717a351ebe92101b83d757311d20a07e
      
https://github.com/WebKit/WebKit/commit/14bd8a42717a351ebe92101b83d757311d20a07e
  Author: Brian Weinstein <bweinst...@apple.com>
  Date:   2023-12-07 (Thu, 07 Dec 2023)

  Changed paths:
    M Source/WebCore/en.lproj/Localizable.strings
    M Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
    M Source/WebKit/Shared/Extensions/_WKWebExtensionSQLiteStore.h
    M Source/WebKit/Shared/Extensions/_WKWebExtensionSQLiteStore.mm
    M 
Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIDeclarativeNetRequestCocoa.mm
    M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm
    M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm
    M 
Source/WebKit/UIProcess/Extensions/Cocoa/_WKWebExtensionDeclarativeNetRequestSQLiteStore.h
    M 
Source/WebKit/UIProcess/Extensions/Cocoa/_WKWebExtensionDeclarativeNetRequestSQLiteStore.mm
    M Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
    M Source/WebKit/UIProcess/Extensions/WebExtensionContext.messages.in
    M 
Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIDeclarativeNetRequestCocoa.mm
    M 
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIDeclarativeNetRequest.mm

  Log Message:
  -----------
  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


_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to