[webkit-changes] [WebKit/WebKit] f9309f: Augment the content rule list allowlist mechanism ...

Wenson Hsieh noreply at github.com
Thu Feb 9 14:21:24 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: f9309fb655519c8b3aa0c2ea92813f5c97c44ee7
      https://github.com/WebKit/WebKit/commit/f9309fb655519c8b3aa0c2ea92813f5c97c44ee7
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2023-02-09 (Thu, 09 Feb 2023)

  Changed paths:
    M Source/WebCore/loader/DocumentLoader.h
    M Source/WebCore/loader/FrameLoader.cpp
    M Source/WebCore/page/UserContentProvider.cpp
    M Source/WebKit/Shared/WebsitePoliciesData.cpp
    M Source/WebKit/Shared/WebsitePoliciesData.h
    M Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
    M Source/WebKit/UIProcess/API/APIWebsitePolicies.h
    M Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp
    M Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h
    M Source/WebKit/UIProcess/WebPageProxy.cpp
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm
    M Tools/TestWebKitAPI/cocoa/TestWKWebView.h
    M Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

  Log Message:
  -----------
  Augment the content rule list allowlist mechanism introduced in 259930 at main
https://bugs.webkit.org/show_bug.cgi?id=251922
rdar://104453682

Reviewed by Alex Christensen.

The previous change in https://commits.webkit.org/259930@main added a way to configure content rule
list enablement in the following three ways, as a per-navigation switch:

1. Unconditionally enable all content rule lists.
2. Unconditionally disable all content rule lists.
3. Enable a specific subset of content rule lists (by identifier).

Unfortunately, this turned out to be insufficient to fulfill the internal client's use case, which
requires a fourth enablement configuration that's not (easily) expressible through existing means:

4. Disable a specific subset of content rule lists (by identifier).

To make it possible to configure all 4 of the above on a per-navigation basis, we replace both the
existing `-_contentBlockersEnabled` flag and the newer `-_disabledContentRuleListIdentifiers`
property with a single SPI:

```
- (void)_setContentRuleListsEnabled:(BOOL)enabled exceptions:(NSSet<NSString *> *)exceptions;
```

* Source/WebCore/loader/DocumentLoader.h:
(WebCore::DocumentLoader::contentExtensionEnablement const):
(WebCore::DocumentLoader::setContentExtensionEnablement):
(WebCore::DocumentLoader::disabledContentExtensions const): Deleted.
(WebCore::DocumentLoader::setDisabledContentExtensions): Deleted.

Rename `DisabledContentExtensions` to `ContentExtensionEnablement`, and change it from a variant to
a pair (now that *both* the enum type and `HashSet` are required in order to express all potential
configurations).

* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::FrameLoader::reload):
* Source/WebCore/page/UserContentProvider.cpp:
(WebCore::ruleListFilter):
(WebCore::UserContentProvider::processContentRuleListsForLoad):
(WebCore::contentRuleListsEnabled): Deleted.
* Source/WebKit/Shared/WebsitePoliciesData.cpp:
(WebKit::WebsitePoliciesData::encode const):
(WebKit::WebsitePoliciesData::decode):

More renaming: `WebCore::DisabledContentExtensions` -> `WebCore::ContentExtensionEnablement`.

(WebKit::WebsitePoliciesData::applyToDocumentLoader):
* Source/WebKit/Shared/WebsitePoliciesData.h:
* Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp:
(API::WebsitePolicies::copy const):
(API::WebsitePolicies::data):
(API::WebsitePolicies::contentBlockersEnabled const): Deleted.
(API::WebsitePolicies::setContentBlockersEnabled): Deleted.
(API::WebsitePolicies::setDisabledContentRuleListIdentifiers): Deleted.
(API::WebsitePolicies::disabledContentRuleListIdentifiers const): Deleted.
* Source/WebKit/UIProcess/API/APIWebsitePolicies.h:
* Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp:
(WKWebsitePoliciesSetContentBlockersEnabled):
(WKWebsitePoliciesGetContentBlockersEnabled):
* Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm:
(-[WKWebpagePreferences _setContentBlockersEnabled:]):
(-[WKWebpagePreferences _contentBlockersEnabled]):

Reimplement these in terms of the new SPI, by treating these as default-enablement (or default-
disablement) with no rule list exceptions.

(-[WKWebpagePreferences _setContentRuleListsEnabled:exceptions:]):
(-[WKWebpagePreferences _setDisabledContentRuleListIdentifiers:]): Deleted.
(-[WKWebpagePreferences _disabledContentRuleListIdentifiers]): Deleted.

Replace the property added in 259930 at main with a set-only method instead.

* Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::receivedNavigationPolicyDecision):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:

Adjust an existing API test to check for both default-enablement (with an exception rule list ID to
disable), as well as default-disablement (with an exception rule list ID to enable).

* Tools/TestWebKitAPI/cocoa/TestWKWebView.h:
* Tools/TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[WKWebView synchronouslyLoadRequest:preferences:]):

Add a new API test helper method on `TestWKWebView`.

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




More information about the webkit-changes mailing list