[webkit-changes] [WebKit/WebKit] d8024c: Allow WKWebpagePreferences to pass a list of conte...

Wenson Hsieh noreply at github.com
Mon Feb 6 18:20:31 PST 2023


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

  Changed paths:
    M Source/WebCore/contentextensions/ContentExtensionsBackend.cpp
    M Source/WebCore/contentextensions/ContentExtensionsBackend.h
    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/Cocoa/WKWebpagePreferences.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm
    A Tools/TestWebKitAPI/Tests/WebKitCocoa/load-image.html

  Log Message:
  -----------
  Allow WKWebpagePreferences to pass a list of content rule list identifiers to be disabled
https://bugs.webkit.org/show_bug.cgi?id=251645
rdar://104453682

Reviewed by Alex Christensen.

Add a new property to provide a fine-grained way to disable `WKContentRuleList`s by identifier, in
the case when content blockers are not disabled using the extant SPI `-_contentBlockersEnabled`. See
below for more details.

Test: WebpagePreferences.DisableContentRuleListsByIdentifier

* Source/WebCore/contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad const):

Add an argument to take a filter function that can be used to skip processing content rule lists
given the rule list identifier; use this to skip content rule lists that are explicitly disabled via
the new SPI.

(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
* Source/WebCore/contentextensions/ContentExtensionsBackend.h:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
* Source/WebCore/loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::setDisabledContentExtensions):
(WebCore::DocumentLoader::disabledContentExtensions const):

Add a getter and setter for the new variant that determines whether (and which) content rule lists
we should disable.

* Source/WebCore/loader/DocumentLoader.h:
(WebCore::DocumentLoader::userContentExtensionsEnabled const): Deleted.
(WebCore::DocumentLoader::setUserContentExtensionsEnabled): Deleted.

Merge the existing bit for `m_userContentExtensionsEnabled` and the new set of disabled content
rule list identifiers into a single `std::variant`, which contains one of the two following
alternatives:

1. An enum flag indicating that content rule lists should be enabled or disabled globally.
2. A `HashSet` of content rule list identifiers to disable.

We also add a typedef, `DisabledContentExtensions`, to more cleanly encapsulate this data structure.

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

Change the state here to also match that of `DocumentLoader`, by replacing the current boolean
`m_contentBlockersEnabled` flag with `DisabledContentExtensions` state instead, which determines
whether or not we want to globally enable, globally disable or selectively disable content
extensions for this navigation.

* Source/WebKit/Shared/WebsitePoliciesData.h:
* Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp:
(API::WebsitePolicies::copy const):
(API::WebsitePolicies::contentBlockersEnabled const):
(API::WebsitePolicies::setContentBlockersEnabled):

Set `DisabledContentExtensions` to either `DisabledContentExtensionsMode::None` or
`DisabledContentExtensionsMode::All`.

(API::WebsitePolicies::setDisabledContentRuleListIdentifiers):

Set `DisabledContentExtensions` to the given set of rule list identifiers.

(API::WebsitePolicies::disabledContentRuleListIdentifiers const):
(API::WebsitePolicies::data):
* Source/WebKit/UIProcess/API/APIWebsitePolicies.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm:
(-[WKWebpagePreferences _setDisabledContentRuleListIdentifiers:]):
(-[WKWebpagePreferences _disabledContentRuleListIdentifiers]):
* Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferencesPrivate.h:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/load-image.html: Added.

Add an API test to exercise this new SPI.

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




More information about the webkit-changes mailing list