Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 1d7b6a797ab4170ebc01a323bb7861ad97e4ba3a
      
https://github.com/WebKit/WebKit/commit/1d7b6a797ab4170ebc01a323bb7861ad97e4ba3a
  Author: Elijah Sawyers <[email protected]>
  Date:   2025-06-05 (Thu, 05 Jun 2025)

  Changed paths:
    M Source/WebCore/contentextensions/ContentExtensionActions.h
    M Source/WebCore/contentextensions/ContentExtensionCompiler.cpp
    M Source/WebCore/contentextensions/ContentExtensionParser.cpp
    M Source/WebCore/contentextensions/ContentExtensionsBackend.cpp
    M Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp

  Log Message:
  -----------
  Introduce ignore-following-rules action type in WebKit Content Blockers
https://bugs.webkit.org/show_bug.cgi?id=294037
rdar://152588124

Reviewed by Timothy Hatcher.

This patch introduces a new content blocker action type, ignore-following-rules,
which does the same thing as ignore-previous-rules but inverted.

We need this action type to be able to correctly fix this dNR bug:
https://bugs.webkit.org/show_bug.cgi?id=293809

To implement this, we just have to follow in the footsteps of how the
ignore-previous-rules action type is implemented. There are two major steps:

1) When compiling the rules, we need to make sure to maintain the position of
   the ignore-future-rules actions so that we know their position when we
   process the actions later.
2) When processing the actions for a load, we need to iterate both directions,
   right-to-left first so that ignore-future-rules actions take priority over
   ignore-previous-rules actions.

It's also worth noting that 2) causes the order in which the actions are added
to the actions struct to be reversed, but order isn't important here.

* Source/WebCore/contentextensions/ContentExtensionActions.h:
Introduce the IgnoreFollowingRulesAction type.

* Source/WebCore/contentextensions/ContentExtensionCompiler.cpp:
(WebCore::ContentExtensions::serializeActions):
When serializing actions, we maintain maps of rules to batch them into groups
until we hit an ignore-previous-rules action, and we need to extend this to also
happen for ignore-following-rules actions. When we hit an ignore-following-rules
action, we need to clear the maps and unconditionally add the action without
trying to combine it with duplicate actions so that we maintain its position in
the vector. This is crucial to do; otherwise, we wouldn't know the action's
position when processing the matched actions for a load later.

* Source/WebCore/contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::loadAction):
Match the "ignore-following-rules" string to the newly added type.

* Source/WebCore/contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsFromContentRuleList
 const):
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForPingLoad):
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForResourceMonitoring):
When processing rules, we first look for ignore-following-rules actions and then
reverse iterate to handle ignore-previous-rules actions.

Again, this does have the affect of reversing the order of the actions in the
actions struct, but it doesn't matter.

* Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::TEST_F(ContentExtensionTest, 
DistinguishableActionInsidePrefixTree)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, DomainTriggers)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, DomainTriggersAlongMergedActions)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, StringParameters)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, 
ResourceOrLoadTypeMatchingEverything)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, MatchesEverything)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, StrictPrefixSeparatedMachines3)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, 
StatesWithDifferentActionsAreNotUnified2)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase3)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase4)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase5)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase6)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase7)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase8)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase9)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase10)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase11)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase12)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase13)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase14)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase15)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, RangeOverlapCase16)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, 
QuantifiedOneOrMoreRangesCase11And13)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, 
QuantifiedOneOrMoreRangesCase11And13InGroups)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase3)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase4)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase5)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase6)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase7)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase8)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase9)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase10)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase11)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase12)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase13)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase14)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase15)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, CombinedRangeOverlapCase16)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, 
CombinedQuantifiedOneOrMoreRangesCase11And13)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, 
CombinedQuantifiedOneOrMoreRangesCase11And13InGroups)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, IfFrameURL)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, UnlessFrameURL)):
Update existing tests to take the new order of the actions into account.

(TestWebKitAPI::TEST_F(ContentExtensionTest, IgnoreFollowingRules)):
Write a new test to validate the new action type.

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to