Skip to content

Conversation

@elijahsawyers
Copy link

@elijahsawyers elijahsawyers commented Mar 20, 2025

d5d7442

Introduce top-document and child-document content blocking resource types
https://bugs.webkit.org/show_bug.cgi?id=290067
rdar://147442279

Reviewed by Timothy Hatcher and Alex Christensen.

This patch breaks out the Document resource type to be TopDocument and
ChildDocument. The motive behind this change is that currently, a dNR rule that
doesn't specify resource types gets converted into two WebKit content blocking
rules.

E.g.

{
  ...

  trigger = {
    load-context = child-frame
    resource-type = document
  }

  ...
}

{
  ...

  trigger = {
    resource-type = script, ping, ...
  }

  ...
}

By introducing the child-document resource type, those two rules can be
collapsed into one.

* LayoutTests/http/tests/contentextensions/block-child-document-resource-type-expected.txt: Added.
* LayoutTests/http/tests/contentextensions/block-child-document-resource-type.html: Added.
* LayoutTests/http/tests/contentextensions/block-child-document-resource-type.html.json: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type-expected.txt: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type-with-child-document-expected.txt: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type-with-child-document.html: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type-with-child-document.html.json: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type.html: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type.html.json: Added.
Introduce new layout tests to verify that the top-document and child-document
resource types behave as expected.

* Source/WebCore/contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
Update the resourceType check to look for TopDocument or ChildDocument, rather
than Document.

* Source/WebCore/css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::subresourcesAllowReuse const):
Pass in whether or not the frame is the main frame.

* Source/WebCore/loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::handleSubstituteDataLoadNow):
Set the ResourceType to either TopDocument or ChildDocument, rather than
Document.

* Source/WebCore/loader/ResourceLoadInfo.cpp:
(WebCore::ContentExtensions::toResourceType):
Return an option set with either TopDocument or ChildDocument ResourceType if
the cached resource type is a main resource. Also, update this method to take
in a parameter as to whether or not the resource is the main frame, which is
used to decide whether to return TopDocument or ChildDocument.

(WebCore::ContentExtensions::readResourceType):
Return an option set with both TopDocument and ChildDocument ResourceTypes if
the content blocking rule specifies "document" resource type.

Return TopDocument and ChildDocument for their resource type strings.

(WebCore::ContentExtensions::resourceTypeToString):
Return the resource type strings for the TopDocument and ChildDocument
ResourceTypes.

* Source/WebCore/loader/ResourceLoadInfo.h:
Replace the Document ResourceType with TopDocument and ChildDocument, and
update the byte code.

* Source/WebCore/loader/ResourceMonitor.cpp:
(WebCore::ResourceMonitor::setDocumentURL):
Set the ResourceType to either TopDocument or ChildDocument, rather than
Document.

* Source/WebCore/loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::SubresourceLoader):
Pass in whether or not the frame is the main frame.

* Source/WebCore/loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
Pass in whether or not the frame is the main frame.

* Source/WebCore/page/UserContentProvider.cpp:
(WebCore::UserContentProvider::processContentRuleListsForLoad):
Update the resourceType check to look for TopDocument or ChildDocument, rather
than Document.

* Source/WebKit/UIProcess/API/APIContentRuleListStore.h:
Update the content rule list file version since we modified the byte code.

* Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::mainDocumentRequest):
(TestWebKitAPI::subResourceRequest):
(TestWebKitAPI::requestInTopAndFrameURLs):
(TestWebKitAPI::TEST_F(ContentExtensionTest, TopURL)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, LoadType)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, ResourceType)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, ResourceOrLoadTypeMatchingEverything)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, MatchesEverything)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, IfFrameURL)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, UnlessFrameURL)):
Update the tests to use TopDocument and ChildDocument ResourceTypes, since Document
was removed.

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

08a644d

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac 🛠 wpe 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2 🧪 win-tests
✅ 🧪 webkitperl 🧪 ios-wk2 🧪 api-mac 🧪 api-wpe
🧪 ios-wk2-wpt 🧪 mac-wk1 🛠 wpe-cairo
🧪 api-ios 🧪 mac-wk2 🛠 gtk
✅ 🛠 vision 🧪 mac-AS-debug-wk2 🧪 gtk-wk2
✅ 🛠 vision-sim 🧪 mac-wk2-stress 🧪 api-gtk
🧪 vision-wk2 🧪 mac-intel-wk2 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🛠 tv 🛠 mac-safer-cpp
❌ 🛠 tv-sim
🛠 watch
✅ 🛠 watch-sim

@elijahsawyers elijahsawyers self-assigned this Mar 20, 2025
@elijahsawyers elijahsawyers added the WebKit Extensions Bugs related to extension support. label Mar 20, 2025
Copy link
Contributor

@achristensen07 achristensen07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I think it needs a test that verifies that if you use child-document the action will apply to an iframe load but not the main frame load and vice versa.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 20, 2025
@elijahsawyers elijahsawyers removed the merging-blocked Applied to prevent a change from being merged label Mar 20, 2025
@elijahsawyers elijahsawyers added the safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks label Mar 20, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 21, 2025
@webkit-ews-buildbot
Copy link
Collaborator

Failed mac-AS-debug-wk2 checks. Please resolve failures and re-apply safe-merge-queue label.

Rejecting #42722 from merge queue.

@webkit-ews-buildbot webkit-ews-buildbot removed the safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks label Mar 21, 2025
@webkit-ews-buildbot
Copy link
Collaborator

Safe-Merge-Queue: Build #52069.

@elijahsawyers elijahsawyers removed the merging-blocked Applied to prevent a change from being merged label Mar 21, 2025
@elijahsawyers elijahsawyers added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Mar 21, 2025
…ypes

https://bugs.webkit.org/show_bug.cgi?id=290067
rdar://147442279

Reviewed by Timothy Hatcher and Alex Christensen.

This patch breaks out the Document resource type to be TopDocument and
ChildDocument. The motive behind this change is that currently, a dNR rule that
doesn't specify resource types gets converted into two WebKit content blocking
rules.

E.g.

{
  ...

  trigger = {
    load-context = child-frame
    resource-type = document
  }

  ...
}

{
  ...

  trigger = {
    resource-type = script, ping, ...
  }

  ...
}

By introducing the child-document resource type, those two rules can be
collapsed into one.

* LayoutTests/http/tests/contentextensions/block-child-document-resource-type-expected.txt: Added.
* LayoutTests/http/tests/contentextensions/block-child-document-resource-type.html: Added.
* LayoutTests/http/tests/contentextensions/block-child-document-resource-type.html.json: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type-expected.txt: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type-with-child-document-expected.txt: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type-with-child-document.html: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type-with-child-document.html.json: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type.html: Added.
* LayoutTests/http/tests/contentextensions/block-top-document-resource-type.html.json: Added.
Introduce new layout tests to verify that the top-document and child-document
resource types behave as expected.

* Source/WebCore/contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
Update the resourceType check to look for TopDocument or ChildDocument, rather
than Document.

* Source/WebCore/css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::subresourcesAllowReuse const):
Pass in whether or not the frame is the main frame.

* Source/WebCore/loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::handleSubstituteDataLoadNow):
Set the ResourceType to either TopDocument or ChildDocument, rather than
Document.

* Source/WebCore/loader/ResourceLoadInfo.cpp:
(WebCore::ContentExtensions::toResourceType):
Return an option set with either TopDocument or ChildDocument ResourceType if
the cached resource type is a main resource. Also, update this method to take
in a parameter as to whether or not the resource is the main frame, which is
used to decide whether to return TopDocument or ChildDocument.

(WebCore::ContentExtensions::readResourceType):
Return an option set with both TopDocument and ChildDocument ResourceTypes if
the content blocking rule specifies "document" resource type.

Return TopDocument and ChildDocument for their resource type strings.

(WebCore::ContentExtensions::resourceTypeToString):
Return the resource type strings for the TopDocument and ChildDocument
ResourceTypes.

* Source/WebCore/loader/ResourceLoadInfo.h:
Replace the Document ResourceType with TopDocument and ChildDocument, and
update the byte code.

* Source/WebCore/loader/ResourceMonitor.cpp:
(WebCore::ResourceMonitor::setDocumentURL):
Set the ResourceType to either TopDocument or ChildDocument, rather than
Document.

* Source/WebCore/loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::SubresourceLoader):
Pass in whether or not the frame is the main frame.

* Source/WebCore/loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
Pass in whether or not the frame is the main frame.

* Source/WebCore/page/UserContentProvider.cpp:
(WebCore::UserContentProvider::processContentRuleListsForLoad):
Update the resourceType check to look for TopDocument or ChildDocument, rather
than Document.

* Source/WebKit/UIProcess/API/APIContentRuleListStore.h:
Update the content rule list file version since we modified the byte code.

* Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::mainDocumentRequest):
(TestWebKitAPI::subResourceRequest):
(TestWebKitAPI::requestInTopAndFrameURLs):
(TestWebKitAPI::TEST_F(ContentExtensionTest, TopURL)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, LoadType)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, ResourceType)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, ResourceOrLoadTypeMatchingEverything)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, MatchesEverything)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, IfFrameURL)):
(TestWebKitAPI::TEST_F(ContentExtensionTest, UnlessFrameURL)):
Update the tests to use TopDocument and ChildDocument ResourceTypes, since Document
was removed.

Canonical link: https://commits.webkit.org/292482@main
@webkit-commit-queue
Copy link
Collaborator

Committed 292482@main (d5d7442): https://commits.webkit.org/292482@main

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

@webkit-commit-queue webkit-commit-queue merged commit d5d7442 into WebKit:main Mar 21, 2025
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Mar 21, 2025
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

Development

Successfully merging this pull request may close these issues.

6 participants