<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[287010] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/287010">287010</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2021-12-13 20:26:34 -0800 (Mon, 13 Dec 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow WKContentRuleList to run regexes on current frame's URL, not just top frame's URL
https://bugs.webkit.org/show_bug.cgi?id=233889

Patch by Alex Christensen <achristensen@webkit.org> on 2021-12-13
Reviewed by Timothy Hatcher.

Source/WebCore:

In 2015, my younger self implemented if-top-url and unless-top-url by running the current URL
through multiple sets of regexes, those with and those without such conditions.  This wasn't
really able to be expanded.  In order to implement if-frame-url, I moved the condition type to
the set of flags stored in the bytecode itself.  Now, we only interpret the bytecode once on the
currently-requested URL, up to once on the frame URL, and up to once on the top URL, and the latter
two can be cached because they don't change as often.

Covered by existing and additional API and layout tests.

* contentextensions/CompiledContentExtension.h:
* contentextensions/ContentExtension.cpp:
(WebCore::ContentExtensions::ContentExtension::ContentExtension):
(WebCore::ContentExtensions::ContentExtension::compileGlobalDisplayNoneStyleSheet):
(WebCore::ContentExtensions::ContentExtension::populateTopURLActionCacheIfNeeded const):
(WebCore::ContentExtensions::ContentExtension::populateFrameURLActionCacheIfNeeded const):
(WebCore::ContentExtensions::ContentExtension::topURLActions const):
(WebCore::ContentExtensions::ContentExtension::frameURLActions const):
(WebCore::ContentExtensions::ContentExtension::populateConditionCacheIfNeeded): Deleted.
(WebCore::ContentExtensions::ContentExtension::topURLActions): Deleted.
(WebCore::ContentExtensions::ContentExtension::universalActionsWithConditions): Deleted.
* contentextensions/ContentExtension.h:
(WebCore::ContentExtensions::ContentExtension::universalActions const):
(WebCore::ContentExtensions::ContentExtension::universalActionsWithoutConditions): Deleted.
* contentextensions/ContentExtensionCompiler.cpp:
(WebCore::ContentExtensions::serializeActions):
(WebCore::ContentExtensions::compileRuleList):
* contentextensions/ContentExtensionCompiler.h:
* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::loadTrigger):
* contentextensions/ContentExtensionRule.cpp:
(WebCore::ContentExtensions::Trigger::isolatedCopy const):
* contentextensions/ContentExtensionRule.h:
(WebCore::ContentExtensions::Trigger::~Trigger):
(WebCore::ContentExtensions::Trigger::isEmpty const):
(WebCore::ContentExtensions::Trigger::operator== const):
* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsFromContentRuleList const):
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad const):
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForPingLoad):
* contentextensions/ContentExtensionsBackend.h:
* contentextensions/DFABytecode.h:
* contentextensions/DFABytecodeCompiler.cpp:
(WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction):
* contentextensions/DFABytecodeInterpreter.cpp:
(WebCore::ContentExtensions::getBits):
(WebCore::ContentExtensions::hasFlags):
(WebCore::ContentExtensions::hasAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::actionsMatchingEverything):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
(WebCore::ContentExtensions::matchesCondition): Deleted.
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretWithConditions): Deleted.
* contentextensions/DFABytecodeInterpreter.h:
(): Deleted.
* loader/ResourceLoadInfo.cpp:
* loader/ResourceLoadInfo.h:

Source/WebKit:

* NetworkProcess/NetworkLoadChecker.cpp:
(WebKit::NetworkLoadChecker::processContentRuleListsForLoad):
* NetworkProcess/NetworkLoadChecker.h:
(WebKit::NetworkLoadChecker::setContentExtensionController):
* NetworkProcess/NetworkResourceLoadParameters.h:
* NetworkProcess/NetworkResourceLoader.cpp:
* NetworkProcess/PingLoad.cpp:
(WebKit::PingLoad::initialize):
* Shared/WebCompiledContentRuleList.cpp:
(WebKit::WebCompiledContentRuleList::urlFiltersBytecode const):
(WebKit::WebCompiledContentRuleList::filtersWithoutConditionsBytecode const): Deleted.
(WebKit::WebCompiledContentRuleList::filtersWithConditionsBytecode const): Deleted.
* Shared/WebCompiledContentRuleList.h:
* Shared/WebCompiledContentRuleListData.cpp:
(WebKit::WebCompiledContentRuleListData::encode const):
(WebKit::WebCompiledContentRuleListData::decode):
* Shared/WebCompiledContentRuleListData.h:
(WebKit::WebCompiledContentRuleListData::WebCompiledContentRuleListData):
* UIProcess/API/APIContentRuleListStore.cpp:
(API::ContentRuleListMetaData::fileSize const):
(API::encodeContentRuleListMetaData):
(API::decodeContentRuleListMetaData):
(API::compiledToFile):
(API::createExtension):
(API::getContentRuleListSourceFromMappedFile):
* UIProcess/API/APIContentRuleListStore.h:
* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::scheduleLoadFromNetworkProcess):
(WebKit::WebLoaderStrategy::startPingLoad):

Tools:

* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::mainDocumentRequest):
(TestWebKitAPI::subResourceRequest):
(TestWebKitAPI::TEST_F):

LayoutTests:

* http/tests/contentextensions/frame-url-expected.txt: Added.
* http/tests/contentextensions/frame-url.html: Added.
* http/tests/contentextensions/frame-url.html.json: Added.
* http/tests/contentextensions/resources/iframe.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsCompiledContentExtensionh">trunk/Source/WebCore/contentextensions/CompiledContentExtension.h</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensioncpp">trunk/Source/WebCore/contentextensions/ContentExtension.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionh">trunk/Source/WebCore/contentextensions/ContentExtension.h</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionCompilercpp">trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionCompilerh">trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.h</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionParsercpp">trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionRulecpp">trunk/Source/WebCore/contentextensions/ContentExtensionRule.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionRuleh">trunk/Source/WebCore/contentextensions/ContentExtensionRule.h</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionsBackendcpp">trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsContentExtensionsBackendh">trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsDFABytecodeh">trunk/Source/WebCore/contentextensions/DFABytecode.h</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsDFABytecodeCompilercpp">trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsDFABytecodeInterpretercpp">trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp</a></li>
<li><a href="#trunkSourceWebCorecontentextensionsDFABytecodeInterpreterh">trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadInfocpp">trunk/Source/WebCore/loader/ResourceLoadInfo.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadInfoh">trunk/Source/WebCore/loader/ResourceLoadInfo.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessNetworkLoadCheckercpp">trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessNetworkLoadCheckerh">trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.h</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessNetworkResourceLoadParametersh">trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessNetworkResourceLoadercpp">trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessPingLoadcpp">trunk/Source/WebKit/NetworkProcess/PingLoad.cpp</a></li>
<li><a href="#trunkSourceWebKitSharedWebCompiledContentRuleListcpp">trunk/Source/WebKit/Shared/WebCompiledContentRuleList.cpp</a></li>
<li><a href="#trunkSourceWebKitSharedWebCompiledContentRuleListh">trunk/Source/WebKit/Shared/WebCompiledContentRuleList.h</a></li>
<li><a href="#trunkSourceWebKitSharedWebCompiledContentRuleListDatacpp">trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp</a></li>
<li><a href="#trunkSourceWebKitSharedWebCompiledContentRuleListDatah">trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIAPIContentRuleListStorecpp">trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIAPIContentRuleListStoreh">trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessNetworkWebLoaderStrategycpp">trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebCoreContentExtensionscpp">trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestscontentextensionsframeurlexpectedtxt">trunk/LayoutTests/http/tests/contentextensions/frame-url-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestscontentextensionsframeurlhtml">trunk/LayoutTests/http/tests/contentextensions/frame-url.html</a></li>
<li><a href="#trunkLayoutTestshttptestscontentextensionsframeurlhtmljson">trunk/LayoutTests/http/tests/contentextensions/frame-url.html.json</a></li>
<li><a href="#trunkLayoutTestshttptestscontentextensionsresourcesiframehtml">trunk/LayoutTests/http/tests/contentextensions/resources/iframe.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/LayoutTests/ChangeLog 2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2021-12-13  Alex Christensen  <achristensen@webkit.org>
+
+        Allow WKContentRuleList to run regexes on current frame's URL, not just top frame's URL
+        https://bugs.webkit.org/show_bug.cgi?id=233889
+
+        Reviewed by Timothy Hatcher.
+
+        * http/tests/contentextensions/frame-url-expected.txt: Added.
+        * http/tests/contentextensions/frame-url.html: Added.
+        * http/tests/contentextensions/frame-url.html.json: Added.
+        * http/tests/contentextensions/resources/iframe.html: Added.
+
</ins><span class="cx"> 2021-12-13  Commit Queue  <commit-queue@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, reverting r286993.
</span></span></pre></div>
<a id="trunkLayoutTestshttptestscontentextensionsframeurlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/contentextensions/frame-url-expected.txt (0 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/contentextensions/frame-url-expected.txt                            (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/frame-url-expected.txt       2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+CONSOLE MESSAGE: Content blocker prevented frame displaying http://127.0.0.1:8000/contentextensions/frame-url.html from loading a resource from http://127.0.0.1:8000/contentextensions/resources/iframe.html
+CONSOLE MESSAGE: Resource blocked by content blocker
+CONSOLE MESSAGE: Fetch API cannot load http://127.0.0.1:8000/contentextensions/resources/iframe.html due to access control checks.
+ALERT: fetch was blocked
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscontentextensionsframeurlhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/contentextensions/frame-url.html (0 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/contentextensions/frame-url.html                            (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/frame-url.html       2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+<script>
+    if (window.testRunner) {
+        testRunner.waitUntilDone();
+        testRunner.dumpAsText();
+    }
+    window.addEventListener("message", (event) => {
+        alert(event.data);
+        if (window.testRunner) {
+            testRunner.notifyDone();
+        }
+    });
+</script>
+<iframe src="resources/iframe.html"></iframe>
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscontentextensionsframeurlhtmljson"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/contentextensions/frame-url.html.json (0 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/contentextensions/frame-url.html.json                               (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/frame-url.html.json  2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+[
+    {
+        "action": {
+            "type": "block"
+        },
+        "trigger": {
+            "url-filter": ".*",
+            "if-frame-url": ["iframe.html"]
+        }
+    }
+]
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestscontentextensionsresourcesiframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/contentextensions/resources/iframe.html (0 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/contentextensions/resources/iframe.html                             (rev 0)
+++ trunk/LayoutTests/http/tests/contentextensions/resources/iframe.html        2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+<script>
+    fetch("iframe.html").then(()=>{
+        window.parent.postMessage("fetch was not blocked", "*");
+    }).catch(()=>{
+        window.parent.postMessage("fetch was blocked", "*");
+    });
+</script>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/ChangeLog      2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -1,3 +1,69 @@
</span><ins>+2021-12-13  Alex Christensen  <achristensen@webkit.org>
+
+        Allow WKContentRuleList to run regexes on current frame's URL, not just top frame's URL
+        https://bugs.webkit.org/show_bug.cgi?id=233889
+
+        Reviewed by Timothy Hatcher.
+
+        In 2015, my younger self implemented if-top-url and unless-top-url by running the current URL
+        through multiple sets of regexes, those with and those without such conditions.  This wasn't
+        really able to be expanded.  In order to implement if-frame-url, I moved the condition type to
+        the set of flags stored in the bytecode itself.  Now, we only interpret the bytecode once on the
+        currently-requested URL, up to once on the frame URL, and up to once on the top URL, and the latter
+        two can be cached because they don't change as often.
+
+        Covered by existing and additional API and layout tests.
+
+        * contentextensions/CompiledContentExtension.h:
+        * contentextensions/ContentExtension.cpp:
+        (WebCore::ContentExtensions::ContentExtension::ContentExtension):
+        (WebCore::ContentExtensions::ContentExtension::compileGlobalDisplayNoneStyleSheet):
+        (WebCore::ContentExtensions::ContentExtension::populateTopURLActionCacheIfNeeded const):
+        (WebCore::ContentExtensions::ContentExtension::populateFrameURLActionCacheIfNeeded const):
+        (WebCore::ContentExtensions::ContentExtension::topURLActions const):
+        (WebCore::ContentExtensions::ContentExtension::frameURLActions const):
+        (WebCore::ContentExtensions::ContentExtension::populateConditionCacheIfNeeded): Deleted.
+        (WebCore::ContentExtensions::ContentExtension::topURLActions): Deleted.
+        (WebCore::ContentExtensions::ContentExtension::universalActionsWithConditions): Deleted.
+        * contentextensions/ContentExtension.h:
+        (WebCore::ContentExtensions::ContentExtension::universalActions const):
+        (WebCore::ContentExtensions::ContentExtension::universalActionsWithoutConditions): Deleted.
+        * contentextensions/ContentExtensionCompiler.cpp:
+        (WebCore::ContentExtensions::serializeActions):
+        (WebCore::ContentExtensions::compileRuleList):
+        * contentextensions/ContentExtensionCompiler.h:
+        * contentextensions/ContentExtensionParser.cpp:
+        (WebCore::ContentExtensions::loadTrigger):
+        * contentextensions/ContentExtensionRule.cpp:
+        (WebCore::ContentExtensions::Trigger::isolatedCopy const):
+        * contentextensions/ContentExtensionRule.h:
+        (WebCore::ContentExtensions::Trigger::~Trigger):
+        (WebCore::ContentExtensions::Trigger::isEmpty const):
+        (WebCore::ContentExtensions::Trigger::operator== const):
+        * contentextensions/ContentExtensionsBackend.cpp:
+        (WebCore::ContentExtensions::ContentExtensionsBackend::actionsFromContentRuleList const):
+        (WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad const):
+        (WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
+        (WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForPingLoad):
+        * contentextensions/ContentExtensionsBackend.h:
+        * contentextensions/DFABytecode.h:
+        * contentextensions/DFABytecodeCompiler.cpp:
+        (WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction):
+        * contentextensions/DFABytecodeInterpreter.cpp:
+        (WebCore::ContentExtensions::getBits):
+        (WebCore::ContentExtensions::hasFlags):
+        (WebCore::ContentExtensions::hasAction):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::actionsMatchingEverything):
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):
+        (WebCore::ContentExtensions::matchesCondition): Deleted.
+        (WebCore::ContentExtensions::DFABytecodeInterpreter::interpretWithConditions): Deleted.
+        * contentextensions/DFABytecodeInterpreter.h:
+        (): Deleted.
+        * loader/ResourceLoadInfo.cpp:
+        * loader/ResourceLoadInfo.h:
+
</ins><span class="cx"> 2021-12-13  Brady Eidson  <beidson@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Teach webpushtool to register and "host" the daemon.
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsCompiledContentExtensionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/CompiledContentExtension.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/CompiledContentExtension.h        2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/CompiledContentExtension.h   2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -38,8 +38,7 @@
</span><span class="cx"> public:
</span><span class="cx">     virtual ~CompiledContentExtension();
</span><span class="cx"> 
</span><del>-    virtual Span<const uint8_t> filtersWithoutConditionsBytecode() const = 0;
-    virtual Span<const uint8_t> filtersWithConditionsBytecode() const = 0;
</del><ins>+    virtual Span<const uint8_t> urlFiltersBytecode() const = 0;
</ins><span class="cx">     virtual Span<const uint8_t> topURLFiltersBytecode() const = 0;
</span><span class="cx">     virtual Span<const uint8_t> frameURLFiltersBytecode() const = 0;
</span><span class="cx">     virtual Span<const uint8_t> serializedActions() const = 0;
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtension.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtension.cpp      2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtension.cpp 2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -45,21 +45,13 @@
</span><span class="cx">     , m_compiledExtension(WTFMove(compiledExtension))
</span><span class="cx">     , m_extensionBaseURL(WTFMove(extensionBaseURL))
</span><span class="cx"> {
</span><del>-    DFABytecodeInterpreter withoutConditions(m_compiledExtension->filtersWithoutConditionsBytecode());
-    DFABytecodeInterpreter withConditions(m_compiledExtension->filtersWithConditionsBytecode());
-    for (uint64_t action : withoutConditions.actionsMatchingEverything()) {
-        ASSERT(static_cast<uint32_t>(action) == action);
-        m_universalActionsWithoutConditions.append(static_cast<uint32_t>(action));
-    }
-    for (uint64_t action : withConditions.actionsMatchingEverything()) {
-        ASSERT((action & ~IfConditionFlag) == static_cast<uint32_t>(action));
-        m_universalActionsWithConditions.append(action);
-    }
</del><ins>+    DFABytecodeInterpreter interpreter(m_compiledExtension->urlFiltersBytecode());
+    for (uint64_t action : interpreter.actionsMatchingEverything())
+        m_universalActions.append(action);
</ins><span class="cx"> 
</span><span class="cx">     if (shouldCompileCSS == ShouldCompileCSS::Yes)
</span><span class="cx">         compileGlobalDisplayNoneStyleSheet();
</span><del>-    m_universalActionsWithoutConditions.shrinkToFit();
-    m_universalActionsWithConditions.shrinkToFit();
</del><ins>+    m_universalActions.shrinkToFit();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> uint32_t ContentExtension::findFirstIgnorePreviousRules() const
</span><span class="lines">@@ -91,7 +83,7 @@
</span><span class="cx">     };
</span><span class="cx">     
</span><span class="cx">     StringBuilder css;
</span><del>-    for (uint32_t universalActionLocation : m_universalActionsWithoutConditions) {
</del><ins>+    for (uint64_t universalActionLocation : m_universalActions) {
</ins><span class="cx">         if (inGlobalDisplayNoneStyleSheet(universalActionLocation)) {
</span><span class="cx">             if (!css.isEmpty())
</span><span class="cx">                 css.append(',');
</span><span class="lines">@@ -113,44 +105,53 @@
</span><span class="cx">         m_globalDisplayNoneStyleSheet = nullptr;
</span><span class="cx"> 
</span><span class="cx">     // These actions don't need to be applied individually any more. They will all be applied to every page as a precompiled style sheet.
</span><del>-    m_universalActionsWithoutConditions.removeAllMatching(inGlobalDisplayNoneStyleSheet);
</del><ins>+    m_universalActions.removeAllMatching(inGlobalDisplayNoneStyleSheet);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ContentExtension::populateConditionCacheIfNeeded(const URL& topURL)
</del><ins>+void ContentExtension::populateTopURLActionCacheIfNeeded(const URL& topURL) const
</ins><span class="cx"> {
</span><del>-    if (m_cachedTopURL != topURL) {
-        DFABytecodeInterpreter interpreter(m_compiledExtension->topURLFiltersBytecode());
-        constexpr ResourceFlags allLoadTypesAndResourceTypes = LoadTypeMask | ResourceTypeMask | LoadContextMask;
-        String string = topURL.string();
-        auto topURLActions = interpreter.interpret(string.utf8(), allLoadTypesAndResourceTypes);
-        
-        m_cachedTopURLActions.clear();
-        for (uint64_t action : topURLActions)
-            m_cachedTopURLActions.add(action);
-        for (uint64_t action : interpreter.actionsMatchingEverything())
-            m_cachedTopURLActions.add(action);
-        
-        m_cachedUniversalConditionedActions.clear();
-        for (uint64_t action : m_universalActionsWithConditions) {
-        ASSERT_WITH_MESSAGE((action & ~IfConditionFlag) == static_cast<uint32_t>(action), "Universal actions with conditions should not have flags.");
-            if (!!(action & IfConditionFlag) == m_cachedTopURLActions.contains(action))
-                m_cachedUniversalConditionedActions.append(static_cast<uint32_t>(action));
-        }
-        m_cachedUniversalConditionedActions.shrinkToFit();
-        m_cachedTopURL = topURL;
-    }
</del><ins>+    if (m_cachedTopURL == topURL)
+        return;
+
+    DFABytecodeInterpreter interpreter(m_compiledExtension->topURLFiltersBytecode());
+    auto topURLActions = interpreter.interpret(topURL.string().utf8(), AllResourceFlags);
+
+    m_cachedTopURLActions.clear();
+    for (uint64_t action : topURLActions)
+        m_cachedTopURLActions.add(action);
+    for (uint64_t action : interpreter.actionsMatchingEverything())
+        m_cachedTopURLActions.add(action);
+
+    m_cachedTopURL = topURL;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-const DFABytecodeInterpreter::Actions& ContentExtension::topURLActions(const URL& topURL)
</del><ins>+void ContentExtension::populateFrameURLActionCacheIfNeeded(const URL& frameURL) const
</ins><span class="cx"> {
</span><del>-    populateConditionCacheIfNeeded(topURL);
</del><ins>+    if (m_cachedFrameURL == frameURL)
+        return;
+
+    DFABytecodeInterpreter interpreter(m_compiledExtension->frameURLFiltersBytecode());
+    auto frameURLActions = interpreter.interpret(frameURL.string().utf8(), AllResourceFlags);
+
+    m_cachedFrameURLActions.clear();
+    for (uint64_t action : frameURLActions)
+        m_cachedFrameURLActions.add(action);
+    for (uint64_t action : interpreter.actionsMatchingEverything())
+        m_cachedFrameURLActions.add(action);
+
+    m_cachedFrameURL = frameURL;
+}
+
+const DFABytecodeInterpreter::Actions& ContentExtension::topURLActions(const URL& topURL) const
+{
+    populateTopURLActionCacheIfNeeded(topURL);
</ins><span class="cx">     return m_cachedTopURLActions;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-const Vector<uint32_t>& ContentExtension::universalActionsWithConditions(const URL& topURL)
</del><ins>+const DFABytecodeInterpreter::Actions& ContentExtension::frameURLActions(const URL& frameURL) const
</ins><span class="cx"> {
</span><del>-    populateConditionCacheIfNeeded(topURL);
-    return m_cachedUniversalConditionedActions;
</del><ins>+    populateFrameURLActionCacheIfNeeded(frameURL);
+    return m_cachedFrameURLActions;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore::ContentExtensions
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtension.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtension.h        2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtension.h   2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -41,7 +41,7 @@
</span><span class="cx"> 
</span><span class="cx"> class ContentExtension : public RefCounted<ContentExtension> {
</span><span class="cx"> public:
</span><del>-    enum class ShouldCompileCSS { No, Yes };
</del><ins>+    enum class ShouldCompileCSS : bool { No, Yes };
</ins><span class="cx">     static Ref<ContentExtension> create(const String& identifier, Ref<CompiledContentExtension>&&, URL&&, ShouldCompileCSS);
</span><span class="cx"> 
</span><span class="cx">     const String& identifier() const { return m_identifier; }
</span><span class="lines">@@ -48,9 +48,9 @@
</span><span class="cx">     const URL& extensionBaseURL() const { return m_extensionBaseURL; }
</span><span class="cx">     const CompiledContentExtension& compiledExtension() const { return m_compiledExtension.get(); }
</span><span class="cx">     StyleSheetContents* globalDisplayNoneStyleSheet();
</span><del>-    const DFABytecodeInterpreter::Actions& topURLActions(const URL& topURL);
-    const Vector<uint32_t>& universalActionsWithoutConditions() { return m_universalActionsWithoutConditions; }
-    const Vector<uint32_t>& universalActionsWithConditions(const URL& topURL);
</del><ins>+    const DFABytecodeInterpreter::Actions& topURLActions(const URL& topURL) const;
+    const DFABytecodeInterpreter::Actions& frameURLActions(const URL& frameURL) const;
+    const Vector<uint64_t>& universalActions() const { return m_universalActions; }
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     ContentExtension(const String& identifier, Ref<CompiledContentExtension>&&, URL&&, ShouldCompileCSS);
</span><span class="lines">@@ -63,13 +63,15 @@
</span><span class="cx">     RefPtr<StyleSheetContents> m_globalDisplayNoneStyleSheet;
</span><span class="cx">     void compileGlobalDisplayNoneStyleSheet();
</span><span class="cx"> 
</span><del>-    URL m_cachedTopURL;
-    void populateConditionCacheIfNeeded(const URL& topURL);
-    DFABytecodeInterpreter::Actions m_cachedTopURLActions;
-    Vector<uint32_t> m_cachedUniversalConditionedActions;
</del><ins>+    void populateTopURLActionCacheIfNeeded(const URL& topURL) const;
+    mutable URL m_cachedTopURL;
+    mutable DFABytecodeInterpreter::Actions m_cachedTopURLActions;
</ins><span class="cx"> 
</span><del>-    Vector<uint32_t> m_universalActionsWithoutConditions;
-    Vector<uint64_t> m_universalActionsWithConditions;
</del><ins>+    void populateFrameURLActionCacheIfNeeded(const URL& frameURL) const;
+    mutable URL m_cachedFrameURL;
+    mutable DFABytecodeInterpreter::Actions m_cachedFrameURLActions;
+
+    Vector<uint64_t> m_universalActions;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace ContentExtensions
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionCompilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp      2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.cpp 2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -44,8 +44,7 @@
</span><span class="cx"> #include <wtf/text/CString.h>
</span><span class="cx"> #include <wtf/text/StringBuilder.h>
</span><span class="cx"> 
</span><del>-namespace WebCore {
-namespace ContentExtensions {
</del><ins>+namespace WebCore::ContentExtensions {
</ins><span class="cx"> 
</span><span class="cx"> // css-display-none combining is special because we combine the string arguments with commas because we know they are css selectors.
</span><span class="cx"> struct PendingDisplayNoneActions {
</span><span class="lines">@@ -87,9 +86,7 @@
</span><span class="cx">     RedirectActionMap redirectActionMap;
</span><span class="cx">     ModifyHeadersActionMap modifyHeadersActionMap;
</span><span class="cx"> 
</span><del>-    for (unsigned ruleIndex = 0; ruleIndex < ruleList.size(); ++ruleIndex) {
-        const ContentExtensionRule& rule = ruleList[ruleIndex];
-
</del><ins>+    for (auto& rule : ruleList) {
</ins><span class="cx">         auto& actionData = rule.action().data();
</span><span class="cx">         if (std::holds_alternative<IgnorePreviousRulesAction>(actionData)) {
</span><span class="cx">             resolvePendingDisplayNoneActions(actions, actionLocations, cssDisplayNoneActionsMap);
</span><span class="lines">@@ -173,7 +170,7 @@
</span><span class="cx">     return actionLocations;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-typedef HashSet<uint64_t, DefaultHash<uint64_t>, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>> UniversalActionSet;
</del><ins>+using UniversalActionSet = HashSet<uint64_t, DefaultHash<uint64_t>, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>>;
</ins><span class="cx"> 
</span><span class="cx"> static void addUniversalActionsToDFA(DFA& dfa, UniversalActionSet&& universalActions)
</span><span class="cx"> {
</span><span class="lines">@@ -290,18 +287,19 @@
</span><span class="cx">     LOG_LARGE_STRUCTURES(actions, actions.capacity() * sizeof(SerializedActionByte));
</span><span class="cx">     client.writeActions(WTFMove(actions));
</span><span class="cx"> 
</span><del>-    UniversalActionSet universalActionsWithoutConditions;
-    UniversalActionSet universalActionsWithConditions;
-    UniversalActionSet universalTopURLActions;
</del><ins>+    // FIXME: These don't all need to be in memory at the same time.
+    CombinedURLFilters urlFilters;
+    UniversalActionSet universalActions;
+    URLFilterParser urlFilterParser(urlFilters);
</ins><span class="cx"> 
</span><del>-    // FIXME: These don't all need to be in memory at the same time.
-    CombinedURLFilters filtersWithoutConditions;
-    CombinedURLFilters filtersWithConditions;
</del><span class="cx">     CombinedURLFilters topURLFilters;
</span><del>-    URLFilterParser filtersWithoutConditionParser(filtersWithoutConditions);
-    URLFilterParser filtersWithConditionParser(filtersWithConditions);
</del><ins>+    UniversalActionSet topURLUniversalActions;
</ins><span class="cx">     URLFilterParser topURLFilterParser(topURLFilters);
</span><del>-    
</del><ins>+
+    CombinedURLFilters frameURLFilters;
+    UniversalActionSet frameURLUniversalActions;
+    URLFilterParser frameURLFilterParser(frameURLFilters);
+
</ins><span class="cx">     for (unsigned ruleIndex = 0; ruleIndex < parsedRuleList.size(); ++ruleIndex) {
</span><span class="cx">         const ContentExtensionRule& contentExtensionRule = parsedRuleList[ruleIndex];
</span><span class="cx">         const Trigger& trigger = contentExtensionRule.trigger();
</span><span class="lines">@@ -312,41 +310,37 @@
</span><span class="cx">         ASSERT(!(~ActionFlagMask & (static_cast<uint64_t>(trigger.flags) << 32)));
</span><span class="cx">         uint64_t actionLocationAndFlags = (static_cast<uint64_t>(trigger.flags) << 32) | static_cast<uint64_t>(actionLocations[ruleIndex]);
</span><span class="cx">         URLFilterParser::ParseStatus status = URLFilterParser::Ok;
</span><del>-        if (trigger.conditions.isEmpty()) {
-            ASSERT(trigger.conditionType == Trigger::ConditionType::None);
-            status = filtersWithoutConditionParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocationAndFlags);
-            if (status == URLFilterParser::MatchesEverything) {
-                universalActionsWithoutConditions.add(actionLocationAndFlags);
-                status = URLFilterParser::Ok;
-            }
-            if (status != URLFilterParser::Ok) {
-                dataLogF("Error while parsing %s: %s\n", trigger.urlFilter.utf8().data(), URLFilterParser::statusString(status).utf8().data());
-                return ContentExtensionError::JSONInvalidRegex;
-            }
-        } else {
-            switch (trigger.conditionType) {
-            case Trigger::ConditionType::IfTopURL:
-                actionLocationAndFlags |= IfConditionFlag;
</del><ins>+        status = urlFilterParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocationAndFlags);
+        if (status == URLFilterParser::MatchesEverything) {
+            universalActions.add(actionLocationAndFlags);
+            status = URLFilterParser::Ok;
+        }
+        if (status != URLFilterParser::Ok) {
+            dataLogF("Error while parsing %s: %s\n", trigger.urlFilter.utf8().data(), URLFilterParser::statusString(status).utf8().data());
+            return ContentExtensionError::JSONInvalidRegex;
+        }
+
+        for (const String& condition : trigger.conditions) {
+            switch (static_cast<ActionCondition>(trigger.flags & ActionConditionMask)) {
+            case ActionCondition::None:
+                ASSERT_NOT_REACHED();
</ins><span class="cx">                 break;
</span><del>-            case Trigger::ConditionType::None:
-            case Trigger::ConditionType::UnlessTopURL:
-                ASSERT(!(actionLocationAndFlags & IfConditionFlag));
</del><ins>+            case ActionCondition::IfTopURL:
+            case ActionCondition::UnlessTopURL:
+                status = topURLFilterParser.addPattern(condition, trigger.topURLFilterIsCaseSensitive, actionLocationAndFlags);
+                if (status == URLFilterParser::MatchesEverything) {
+                    topURLUniversalActions.add(actionLocationAndFlags);
+                    status = URLFilterParser::Ok;
+                }
+                if (status != URLFilterParser::Ok) {
+                    dataLogF("Error while parsing %s: %s\n", condition.utf8().data(), URLFilterParser::statusString(status).utf8().data());
+                    return ContentExtensionError::JSONInvalidRegex;
+                }
</ins><span class="cx">                 break;
</span><del>-            }
-            
-            status = filtersWithConditionParser.addPattern(trigger.urlFilter, trigger.urlFilterIsCaseSensitive, actionLocationAndFlags);
-            if (status == URLFilterParser::MatchesEverything) {
-                universalActionsWithConditions.add(actionLocationAndFlags);
-                status = URLFilterParser::Ok;
-            }
-            if (status != URLFilterParser::Ok) {
-                dataLogF("Error while parsing %s: %s\n", trigger.urlFilter.utf8().data(), URLFilterParser::statusString(status).utf8().data());
-                return ContentExtensionError::JSONInvalidRegex;
-            }
-            for (const String& condition : trigger.conditions) {
-                status = topURLFilterParser.addPattern(condition, trigger.topURLConditionIsCaseSensitive, actionLocationAndFlags);
</del><ins>+            case ActionCondition::IfFrameURL:
+                status = frameURLFilterParser.addPattern(condition, trigger.frameURLFilterIsCaseSensitive, actionLocationAndFlags);
</ins><span class="cx">                 if (status == URLFilterParser::MatchesEverything) {
</span><del>-                    universalTopURLActions.add(actionLocationAndFlags);
</del><ins>+                    frameURLUniversalActions.add(actionLocationAndFlags);
</ins><span class="cx">                     status = URLFilterParser::Ok;
</span><span class="cx">                 }
</span><span class="cx">                 if (status != URLFilterParser::Ok) {
</span><span class="lines">@@ -353,6 +347,7 @@
</span><span class="cx">                     dataLogF("Error while parsing %s: %s\n", condition.utf8().data(), URLFilterParser::statusString(status).utf8().data());
</span><span class="cx">                     return ContentExtensionError::JSONInvalidRegex;
</span><span class="cx">                 }
</span><ins>+                break;
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx">         ASSERT(status == URLFilterParser::Ok);
</span><span class="lines">@@ -370,23 +365,24 @@
</span><span class="cx">     LOG_LARGE_STRUCTURES(filtersWithoutConditions, filtersWithoutConditions.memoryUsed());
</span><span class="cx">     LOG_LARGE_STRUCTURES(filtersWithConditions, filtersWithConditions.memoryUsed());
</span><span class="cx">     LOG_LARGE_STRUCTURES(topURLFilters, topURLFilters.memoryUsed());
</span><ins>+    LOG_LARGE_STRUCTURES(frameURLFilters, frameURLFilters.memoryUsed());
</ins><span class="cx"> 
</span><span class="cx"> #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
</span><span class="cx">     MonotonicTime totalNFAToByteCodeBuildTimeStart = MonotonicTime::now();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    bool success = compileToBytecode(WTFMove(filtersWithoutConditions), WTFMove(universalActionsWithoutConditions), [&](Vector<DFABytecode>&& bytecode) {
-        client.writeFiltersWithoutConditionsBytecode(WTFMove(bytecode));
</del><ins>+    bool success = compileToBytecode(WTFMove(urlFilters), WTFMove(universalActions), [&](Vector<DFABytecode>&& bytecode) {
+        client.writeURLFiltersBytecode(WTFMove(bytecode));
</ins><span class="cx">     });
</span><span class="cx">     if (!success)
</span><span class="cx">         return ContentExtensionError::ErrorWritingSerializedNFA;
</span><del>-    success = compileToBytecode(WTFMove(filtersWithConditions), WTFMove(universalActionsWithConditions), [&](Vector<DFABytecode>&& bytecode) {
-        client.writeFiltersWithConditionsBytecode(WTFMove(bytecode));
</del><ins>+    success = compileToBytecode(WTFMove(topURLFilters), WTFMove(topURLUniversalActions), [&](Vector<DFABytecode>&& bytecode) {
+        client.writeTopURLFiltersBytecode(WTFMove(bytecode));
</ins><span class="cx">     });
</span><span class="cx">     if (!success)
</span><span class="cx">         return ContentExtensionError::ErrorWritingSerializedNFA;
</span><del>-    success = compileToBytecode(WTFMove(topURLFilters), WTFMove(universalTopURLActions), [&](Vector<DFABytecode>&& bytecode) {
-        client.writeTopURLFiltersBytecode(WTFMove(bytecode));
</del><ins>+    success = compileToBytecode(WTFMove(frameURLFilters), WTFMove(frameURLUniversalActions), [&](Vector<DFABytecode>&& bytecode) {
+        client.writeFrameURLFiltersBytecode(WTFMove(bytecode));
</ins><span class="cx">     });
</span><span class="cx">     if (!success)
</span><span class="cx">         return ContentExtensionError::ErrorWritingSerializedNFA;
</span><span class="lines">@@ -401,7 +397,6 @@
</span><span class="cx">     return { };
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-} // namespace ContentExtensions
-} // namespace WebCore
</del><ins>+} // namespace WebCore::ContentExtensions
</ins><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(CONTENT_EXTENSIONS)
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionCompilerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.h        2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionCompiler.h   2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -41,9 +41,9 @@
</span><span class="cx">     // Functions should be called in this order. All except writeActions and finalize can be called multiple times, though.
</span><span class="cx">     virtual void writeSource(String&&) = 0;
</span><span class="cx">     virtual void writeActions(Vector<SerializedActionByte>&&) = 0;
</span><del>-    virtual void writeFiltersWithoutConditionsBytecode(Vector<DFABytecode>&&) = 0;
-    virtual void writeFiltersWithConditionsBytecode(Vector<DFABytecode>&&) = 0;
</del><ins>+    virtual void writeURLFiltersBytecode(Vector<DFABytecode>&&) = 0;
</ins><span class="cx">     virtual void writeTopURLFiltersBytecode(Vector<DFABytecode>&&) = 0;
</span><ins>+    virtual void writeFrameURLFiltersBytecode(Vector<DFABytecode>&&) = 0;
</ins><span class="cx">     virtual void finalize() = 0;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp        2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp   2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -134,8 +134,11 @@
</span><span class="cx">         trigger.urlFilterIsCaseSensitive = *urlFilterCaseSensitiveValue;
</span><span class="cx"> 
</span><span class="cx">     if (std::optional<bool> topURLFilterCaseSensitiveValue = triggerObject->getBoolean("top-url-filter-is-case-sensitive"))
</span><del>-        trigger.topURLConditionIsCaseSensitive = *topURLFilterCaseSensitiveValue;
</del><ins>+        trigger.topURLFilterIsCaseSensitive = *topURLFilterCaseSensitiveValue;
</ins><span class="cx"> 
</span><ins>+    if (std::optional<bool> frameURLFilterCaseSensitiveValue = triggerObject->getBoolean("frame-url-filter-is-case-sensitive"))
+        trigger.frameURLFilterIsCaseSensitive = *frameURLFilterCaseSensitiveValue;
+
</ins><span class="cx">     if (auto resourceTypeValue = triggerObject->getValue("resource-type")) {
</span><span class="cx">         auto resourceTypeArray = resourceTypeValue->asArray();
</span><span class="cx">         if (!resourceTypeArray)
</span><span class="lines">@@ -160,9 +163,9 @@
</span><span class="cx">             return makeUnexpected(error);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    auto checkCondition = [&] (ASCIILiteral key, Expected<Vector<String>, std::error_code> (*listReader)(const JSON::Array&), Trigger::ConditionType conditionType) -> std::error_code {
</del><ins>+    auto checkCondition = [&] (ASCIILiteral key, Expected<Vector<String>, std::error_code> (*listReader)(const JSON::Array&), ActionCondition actionCondition) -> std::error_code {
</ins><span class="cx">         if (auto value = triggerObject->getValue(key)) {
</span><del>-            if (trigger.conditionType != Trigger::ConditionType::None)
</del><ins>+            if (trigger.flags & ActionConditionMask)
</ins><span class="cx">                 return ContentExtensionError::JSONMultipleConditions;
</span><span class="cx">             auto array = value->asArray();
</span><span class="cx">             if (!array)
</span><span class="lines">@@ -173,24 +176,26 @@
</span><span class="cx">             trigger.conditions = WTFMove(list.value());
</span><span class="cx">             if (trigger.conditions.isEmpty())
</span><span class="cx">                 return ContentExtensionError::JSONInvalidConditionList;
</span><del>-            ASSERT(trigger.conditionType == Trigger::ConditionType::None);
-            trigger.conditionType = conditionType;
</del><ins>+            trigger.flags |= static_cast<ResourceFlags>(actionCondition);
</ins><span class="cx">         }
</span><span class="cx">         return { };
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    if (auto error = checkCondition("if-domain"_s, getDomainList, Trigger::ConditionType::IfTopURL))
</del><ins>+    if (auto error = checkCondition("if-domain"_s, getDomainList, ActionCondition::IfTopURL))
</ins><span class="cx">         return makeUnexpected(error);
</span><span class="cx"> 
</span><del>-    if (auto error = checkCondition("unless-domain"_s, getDomainList, Trigger::ConditionType::UnlessTopURL))
</del><ins>+    if (auto error = checkCondition("unless-domain"_s, getDomainList, ActionCondition::UnlessTopURL))
</ins><span class="cx">         return makeUnexpected(error);
</span><span class="cx"> 
</span><del>-    if (auto error = checkCondition("if-top-url"_s, getStringList, Trigger::ConditionType::IfTopURL))
</del><ins>+    if (auto error = checkCondition("if-top-url"_s, getStringList, ActionCondition::IfTopURL))
</ins><span class="cx">         return makeUnexpected(error);
</span><span class="cx"> 
</span><del>-    if (auto error = checkCondition("unless-top-url"_s, getStringList, Trigger::ConditionType::UnlessTopURL))
</del><ins>+    if (auto error = checkCondition("unless-top-url"_s, getStringList, ActionCondition::UnlessTopURL))
</ins><span class="cx">         return makeUnexpected(error);
</span><span class="cx"> 
</span><ins>+    if (auto error = checkCondition("if-frame-url"_s, getStringList, ActionCondition::IfFrameURL))
+        return makeUnexpected(error);
+
</ins><span class="cx">     return trigger;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionRulecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtensionRule.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtensionRule.cpp  2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionRule.cpp     2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -100,10 +100,10 @@
</span><span class="cx">     return {
</span><span class="cx">         urlFilter.isolatedCopy(),
</span><span class="cx">         urlFilterIsCaseSensitive,
</span><del>-        topURLConditionIsCaseSensitive,
</del><ins>+        topURLFilterIsCaseSensitive,
+        frameURLFilterIsCaseSensitive,
</ins><span class="cx">         flags,
</span><del>-        conditions.isolatedCopy(),
-        conditionType
</del><ins>+        conditions.isolatedCopy()
</ins><span class="cx">     };
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionRuleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtensionRule.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtensionRule.h    2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionRule.h       2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -32,10 +32,8 @@
</span><span class="cx"> #include <wtf/Hasher.h>
</span><span class="cx"> #include <wtf/text/WTFString.h>
</span><span class="cx"> 
</span><del>-namespace WebCore {
</del><ins>+namespace WebCore::ContentExtensions {
</ins><span class="cx"> 
</span><del>-namespace ContentExtensions {
-
</del><span class="cx"> // A ContentExtensionRule is the smallest unit in a ContentExtension.
</span><span class="cx"> //
</span><span class="cx"> // It is composed of a trigger and an action. The trigger defines on what kind of content this extension should apply.
</span><span class="lines">@@ -44,22 +42,21 @@
</span><span class="cx"> struct Trigger {
</span><span class="cx">     String urlFilter;
</span><span class="cx">     bool urlFilterIsCaseSensitive { false };
</span><del>-    bool topURLConditionIsCaseSensitive { false };
</del><ins>+    bool topURLFilterIsCaseSensitive { false };
+    bool frameURLFilterIsCaseSensitive { false };
</ins><span class="cx">     ResourceFlags flags { 0 };
</span><span class="cx">     Vector<String> conditions;
</span><del>-    enum class ConditionType : uint8_t {
-        None,
-        IfTopURL,
-        UnlessTopURL,
-    } conditionType { ConditionType::None };
</del><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT Trigger isolatedCopy() const;
</span><span class="cx">     
</span><span class="cx">     ~Trigger()
</span><span class="cx">     {
</span><del>-        ASSERT(conditions.isEmpty() == (conditionType == ConditionType::None));
-        if (topURLConditionIsCaseSensitive)
-            ASSERT(conditionType == ConditionType::IfTopURL || conditionType == ConditionType::UnlessTopURL);
</del><ins>+        auto actionCondition = static_cast<ActionCondition>(flags & ActionConditionMask);
+        ASSERT_UNUSED(actionCondition, conditions.isEmpty() == (actionCondition == ActionCondition::None));
+        if (topURLFilterIsCaseSensitive)
+            ASSERT(actionCondition == ActionCondition::IfTopURL || actionCondition == ActionCondition::UnlessTopURL);
+        if (frameURLFilterIsCaseSensitive)
+            ASSERT(actionCondition == ActionCondition::IfFrameURL);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     bool isEmpty() const
</span><span class="lines">@@ -66,10 +63,10 @@
</span><span class="cx">     {
</span><span class="cx">         return urlFilter.isEmpty()
</span><span class="cx">             && !urlFilterIsCaseSensitive
</span><del>-            && !topURLConditionIsCaseSensitive
</del><ins>+            && !topURLFilterIsCaseSensitive
+            && !frameURLFilterIsCaseSensitive
</ins><span class="cx">             && !flags
</span><del>-            && conditions.isEmpty()
-            && conditionType == ConditionType::None;
</del><ins>+            && conditions.isEmpty();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     bool operator==(const Trigger& other) const
</span><span class="lines">@@ -76,10 +73,10 @@
</span><span class="cx">     {
</span><span class="cx">         return urlFilter == other.urlFilter
</span><span class="cx">             && urlFilterIsCaseSensitive == other.urlFilterIsCaseSensitive
</span><del>-            && topURLConditionIsCaseSensitive == other.topURLConditionIsCaseSensitive
</del><ins>+            && topURLFilterIsCaseSensitive == other.topURLFilterIsCaseSensitive
+            && frameURLFilterIsCaseSensitive == other.frameURLFilterIsCaseSensitive
</ins><span class="cx">             && flags == other.flags
</span><del>-            && conditions == other.conditions
-            && conditionType == other.conditionType;
</del><ins>+            && conditions == other.conditions;
</ins><span class="cx">     }
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -86,7 +83,7 @@
</span><span class="cx"> struct TriggerHash {
</span><span class="cx">     static unsigned hash(const Trigger& trigger)
</span><span class="cx">     {
</span><del>-        return computeHash(trigger.urlFilterIsCaseSensitive, trigger.urlFilter, trigger.flags, trigger.conditions, trigger.conditionType);
</del><ins>+        return computeHash(trigger.urlFilterIsCaseSensitive, trigger.urlFilter, trigger.flags, trigger.conditions);
</ins><span class="cx">     }
</span><span class="cx">     static bool equal(const Trigger& a, const Trigger& b)
</span><span class="cx">     {
</span><span class="lines">@@ -170,7 +167,6 @@
</span><span class="cx">     const Action m_action;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-} // namespace ContentExtensions
-} // namespace WebCore
</del><ins>+} // namespace WebCore::ContentExtensions
</ins><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(CONTENT_EXTENSIONS)
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionsBackendcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp      2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.cpp 2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -50,10 +50,8 @@
</span><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><span class="cx"> #include <wtf/text/CString.h>
</span><span class="cx"> 
</span><del>-namespace WebCore {
</del><ins>+namespace WebCore::ContentExtensions {
</ins><span class="cx"> 
</span><del>-namespace ContentExtensions {
-
</del><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> #import <WebKitAdditions/ContentRuleListAdditions.mm>
</span><span class="cx"> #else
</span><span class="lines">@@ -98,6 +96,60 @@
</span><span class="cx">     m_contentExtensions.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+auto ContentExtensionsBackend::actionsFromContentRuleList(const ContentExtension& contentExtension, const CString& urlString, const ResourceLoadInfo& resourceLoadInfo, ResourceFlags flags) const -> ActionsFromContentRuleList
+{
+    ActionsFromContentRuleList actionsStruct;
+    actionsStruct.contentRuleListIdentifier = contentExtension.identifier();
+
+    const auto& compiledExtension = contentExtension.compiledExtension();
+
+    DFABytecodeInterpreter interpreter(compiledExtension.urlFiltersBytecode());
+    auto actionLocations = interpreter.interpret(urlString, flags);
+    auto& topURLActions = contentExtension.topURLActions(resourceLoadInfo.mainDocumentURL);
+    auto& frameURLActions = contentExtension.frameURLActions(resourceLoadInfo.frameURL);
+
+    actionLocations.removeIf([&](uint64_t actionAndFlags) {
+        ResourceFlags flags = actionAndFlags >> 32;
+        auto actionCondition = static_cast<ActionCondition>(flags & ActionConditionMask);
+        switch (actionCondition) {
+        case ActionCondition::None:
+            return false;
+        case ActionCondition::IfTopURL:
+            return !topURLActions.contains(actionAndFlags);
+        case ActionCondition::UnlessTopURL:
+            return topURLActions.contains(actionAndFlags);
+        case ActionCondition::IfFrameURL:
+            return !frameURLActions.contains(actionAndFlags);
+        }
+        ASSERT_NOT_REACHED();
+        return false;
+    });
+
+    auto serializedActions = compiledExtension.serializedActions();
+
+    const auto& universalActions = contentExtension.universalActions();
+    if (auto totalActionCount = actionLocations.size() + universalActions.size()) {
+        Vector<uint32_t> vector;
+        vector.reserveInitialCapacity(totalActionCount);
+        for (uint64_t actionLocation : actionLocations)
+            vector.uncheckedAppend(static_cast<uint32_t>(actionLocation));
+        for (uint64_t actionLocation : universalActions)
+            vector.uncheckedAppend(static_cast<uint32_t>(actionLocation));
+        std::sort(vector.begin(), vector.end());
+
+        // Add actions in reverse order to properly deal with IgnorePreviousRules.
+        for (auto i = vector.size(); i; i--) {
+            auto action = DeserializedAction::deserialize(serializedActions, vector[i - 1]);
+            if (std::holds_alternative<IgnorePreviousRulesAction>(action.data())) {
+                actionsStruct.sawIgnorePreviousRules = true;
+                break;
+            }
+            actionsStruct.actions.append(WTFMove(action));
+        }
+    }
+    return actionsStruct;
+}
+
</ins><span class="cx"> auto ContentExtensionsBackend::actionsForResourceLoad(const ResourceLoadInfo& resourceLoadInfo) const -> Vector<ActionsFromContentRuleList>
</span><span class="cx"> {
</span><span class="cx"> #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
</span><span class="lines">@@ -110,53 +162,16 @@
</span><span class="cx"> 
</span><span class="cx">     const String& urlString = resourceLoadInfo.resourceURL.string();
</span><span class="cx">     ASSERT_WITH_MESSAGE(urlString.isAllASCII(), "A decoded URL should only contain ASCII characters. The matching algorithm assumes the input is ASCII.");
</span><ins>+    // FIXME: UTF-8 conversion should only be necessary with UTF-16 String based URLs, which are rare.
+    // DFABytecodeInterpreter::interpret should take a Span<char> instead of a CString and we can avoid this allocation almost all of the time.
</ins><span class="cx">     const auto urlCString = urlString.utf8();
</span><span class="cx"> 
</span><span class="cx">     Vector<ActionsFromContentRuleList> actionsVector;
</span><span class="cx">     actionsVector.reserveInitialCapacity(m_contentExtensions.size());
</span><del>-    const ResourceFlags flags = resourceLoadInfo.getResourceFlags();
-    for (auto& contentExtension : m_contentExtensions.values()) {
-        ActionsFromContentRuleList actionsStruct;
-        actionsStruct.contentRuleListIdentifier = contentExtension->identifier();
-
-        const CompiledContentExtension& compiledExtension = contentExtension->compiledExtension();
-        
-        DFABytecodeInterpreter withoutConditionsInterpreter(compiledExtension.filtersWithoutConditionsBytecode());
-        DFABytecodeInterpreter::Actions withoutConditionsActions = withoutConditionsInterpreter.interpret(urlCString, flags);
-        
-        URL topURL = resourceLoadInfo.mainDocumentURL;
-        DFABytecodeInterpreter withConditionsInterpreter(compiledExtension.filtersWithConditionsBytecode());
-        DFABytecodeInterpreter::Actions withConditionsActions = withConditionsInterpreter.interpretWithConditions(urlCString, flags, contentExtension->topURLActions(topURL));
-        
-        auto serializedActions = compiledExtension.serializedActions();
-        
-        const Vector<uint32_t>& universalWithConditions = contentExtension->universalActionsWithConditions(topURL);
-        const Vector<uint32_t>& universalWithoutConditions = contentExtension->universalActionsWithoutConditions();
-        if (!withoutConditionsActions.isEmpty() || !withConditionsActions.isEmpty() || !universalWithConditions.isEmpty() || !universalWithoutConditions.isEmpty()) {
-            Vector<uint32_t> actionLocations;
-            actionLocations.reserveInitialCapacity(withoutConditionsActions.size() + withConditionsActions.size() + universalWithoutConditions.size() + universalWithConditions.size());
-            for (uint64_t actionLocation : withoutConditionsActions)
-                actionLocations.uncheckedAppend(static_cast<uint32_t>(actionLocation));
-            for (uint64_t actionLocation : withConditionsActions)
-                actionLocations.uncheckedAppend(static_cast<uint32_t>(actionLocation));
-            for (uint32_t actionLocation : universalWithoutConditions)
-                actionLocations.uncheckedAppend(actionLocation);
-            for (uint32_t actionLocation : universalWithConditions)
-                actionLocations.uncheckedAppend(actionLocation);
-            std::sort(actionLocations.begin(), actionLocations.end());
-
-            // Add actions in reverse order to properly deal with IgnorePreviousRules.
-            for (unsigned i = actionLocations.size(); i; i--) {
-                auto action = DeserializedAction::deserialize(serializedActions, actionLocations[i - 1]);
-                if (std::holds_alternative<IgnorePreviousRulesAction>(action.data())) {
-                    actionsStruct.sawIgnorePreviousRules = true;
-                    break;
-                }
-                actionsStruct.actions.append(WTFMove(action));
-            }
-        }
-        actionsVector.uncheckedAppend(WTFMove(actionsStruct));
-    }
</del><ins>+    ASSERT(!(resourceLoadInfo.getResourceFlags() & ActionConditionMask));
+    const ResourceFlags flags = resourceLoadInfo.getResourceFlags() | ActionConditionMask;
+    for (auto& contentExtension : m_contentExtensions.values())
+        actionsVector.uncheckedAppend(actionsFromContentRuleList(contentExtension.get(), urlCString, resourceLoadInfo, flags));
</ins><span class="cx"> #if CONTENT_EXTENSIONS_PERFORMANCE_REPORTING
</span><span class="cx">     MonotonicTime addedTimeEnd = MonotonicTime::now();
</span><span class="cx">     dataLogF("Time added: %f microseconds %s \n", (addedTimeEnd - addedTimeStart).microseconds(), resourceLoadInfo.resourceURL.string().utf8().data());
</span><span class="lines">@@ -180,6 +195,7 @@
</span><span class="cx"> {
</span><span class="cx">     Document* currentDocument = nullptr;
</span><span class="cx">     URL mainDocumentURL;
</span><ins>+    URL frameURL;
</ins><span class="cx">     bool mainFrameContext = false;
</span><span class="cx"> 
</span><span class="cx">     if (auto* frame = initiatingDocumentLoader.frame()) {
</span><span class="lines">@@ -193,8 +209,12 @@
</span><span class="cx">         else if (auto* mainDocument = frame->mainFrame().document())
</span><span class="cx">             mainDocumentURL = mainDocument->url();
</span><span class="cx">     }
</span><ins>+    if (currentDocument)
+        frameURL = currentDocument->url();
+    else
+        frameURL = url;
</ins><span class="cx"> 
</span><del>-    ResourceLoadInfo resourceLoadInfo = { url, mainDocumentURL, resourceType, mainFrameContext };
</del><ins>+    ResourceLoadInfo resourceLoadInfo { url, mainDocumentURL, frameURL, resourceType, mainFrameContext };
</ins><span class="cx">     auto actions = actionsForResourceLoad(resourceLoadInfo);
</span><span class="cx"> 
</span><span class="cx">     ContentRuleListResults results;
</span><span class="lines">@@ -271,9 +291,9 @@
</span><span class="cx">     return results;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-ContentRuleListResults ContentExtensionsBackend::processContentRuleListsForPingLoad(const URL& url, const URL& mainDocumentURL)
</del><ins>+ContentRuleListResults ContentExtensionsBackend::processContentRuleListsForPingLoad(const URL& url, const URL& mainDocumentURL, const URL& frameURL)
</ins><span class="cx"> {
</span><del>-    ResourceLoadInfo resourceLoadInfo = { url, mainDocumentURL, ResourceType::Ping };
</del><ins>+    ResourceLoadInfo resourceLoadInfo { url, mainDocumentURL, frameURL, ResourceType::Ping };
</ins><span class="cx">     auto actions = actionsForResourceLoad(resourceLoadInfo);
</span><span class="cx"> 
</span><span class="cx">     ContentRuleListResults results;
</span><span class="lines">@@ -340,8 +360,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx">     
</span><del>-} // namespace ContentExtensions
</del><ins>+} // namespace WebCore::ContentExtensions
</ins><span class="cx"> 
</span><del>-} // namespace WebCore
-
</del><span class="cx"> #endif // ENABLE(CONTENT_EXTENSIONS)
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsContentExtensionsBackendh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h        2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionsBackend.h   2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -71,7 +71,7 @@
</span><span class="cx">     WEBCORE_EXPORT StyleSheetContents* globalDisplayNoneStyleSheet(const String& identifier) const;
</span><span class="cx"> 
</span><span class="cx">     ContentRuleListResults processContentRuleListsForLoad(Page&, const URL&, OptionSet<ResourceType>, DocumentLoader& initiatingDocumentLoader, const URL& redirectFrom);
</span><del>-    WEBCORE_EXPORT ContentRuleListResults processContentRuleListsForPingLoad(const URL&, const URL& mainDocumentURL);
</del><ins>+    WEBCORE_EXPORT ContentRuleListResults processContentRuleListsForPingLoad(const URL&, const URL& mainDocumentURL, const URL& frameURL);
</ins><span class="cx"> 
</span><span class="cx">     static const String& displayNoneCSSRule();
</span><span class="cx"> 
</span><span class="lines">@@ -80,12 +80,14 @@
</span><span class="cx">     WEBCORE_EXPORT static bool shouldBeMadeSecure(const URL&);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    ActionsFromContentRuleList actionsFromContentRuleList(const ContentExtension&, const CString& urlString, const ResourceLoadInfo&, ResourceFlags) const;
+
</ins><span class="cx">     HashMap<String, Ref<ContentExtension>> m_contentExtensions;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WEBCORE_EXPORT void applyResultsToRequest(ContentRuleListResults&&, Page*, ResourceRequest&);
</span><span class="cx"> 
</span><del>-} // namespace ContentExtensions
</del><ins>+} // namespace WebCore::ContentExtensions
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(CONTENT_EXTENSIONS)
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsDFABytecodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/DFABytecode.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/DFABytecode.h     2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/DFABytecode.h        2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -60,13 +60,11 @@
</span><span class="cx">     // AppendAction has one argument:
</span><span class="cx">     // The action to append (1-4 bytes).
</span><span class="cx">     AppendAction = 0x6,
</span><del>-    AppendActionWithIfCondition = 0x7,
</del><span class="cx">     
</span><span class="cx">     // TestFlagsAndAppendAction has two arguments:
</span><span class="cx">     // The flags to check before appending (1-3 bytes).
</span><span class="cx">     // The action to append (1-4 bytes).
</span><span class="cx">     TestFlagsAndAppendAction = 0x8,
</span><del>-    TestFlagsAndAppendActionWithIfCondition = 0x9,
</del><span class="cx"> 
</span><span class="cx">     // Terminate has no arguments.
</span><span class="cx">     Terminate = 0xA,
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsDFABytecodeCompilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp   2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp      2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -74,13 +74,6 @@
</span><span class="cx">     *reinterpret_cast<IntType*>(&bytecode[index]) = value;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static unsigned appendActionBytecodeSize(uint64_t action)
-{
-    if (action & ActionFlagMask)
-        return sizeof(DFABytecodeInstruction) + sizeof(uint16_t) + sizeof(uint32_t);
-    return sizeof(DFABytecodeInstruction) + sizeof(uint32_t);
-}
-
</del><span class="cx"> static DFABytecodeFlagsSize bytecodeFlagsSize(ResourceFlags flags)
</span><span class="cx"> {
</span><span class="cx">     if (flags <= std::numeric_limits<uint8_t>::max())
</span><span class="lines">@@ -102,6 +95,40 @@
</span><span class="cx">     return DFABytecodeActionSize::UInt32;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static size_t toSizeT(DFABytecodeFlagsSize size)
+{
+    switch (size) {
+    case DFABytecodeFlagsSize::UInt8:
+        return sizeof(uint8_t);
+    case DFABytecodeFlagsSize::UInt16:
+        return sizeof(uint16_t);
+    case DFABytecodeFlagsSize::UInt24:
+        return UInt24Size;
+    }
+}
+
+static size_t toSizeT(DFABytecodeActionSize size)
+{
+    switch (size) {
+    case DFABytecodeActionSize::UInt8:
+        return sizeof(uint8_t);
+    case DFABytecodeActionSize::UInt16:
+        return sizeof(uint16_t);
+    case DFABytecodeActionSize::UInt24:
+        return UInt24Size;
+    case DFABytecodeActionSize::UInt32:
+        return sizeof(uint32_t);
+    }
+}
+
+static size_t appendActionBytecodeSize(uint64_t action)
+{
+    auto flags = static_cast<ResourceFlags>((action & ActionFlagMask) >> 32);
+    return sizeof(DFABytecodeInstruction)
+        + (flags ? toSizeT(bytecodeFlagsSize(flags)) : 0)
+        + toSizeT(bytecodeActionSize(action));
+}
+
</ins><span class="cx"> static void appendVariableLengthUnsignedInteger(Vector<DFABytecode>& bytecode, uint32_t integer)
</span><span class="cx"> {
</span><span class="cx">     if (integer <= std::numeric_limits<uint8_t>::max())
</span><span class="lines">@@ -121,7 +148,7 @@
</span><span class="cx">     // High bits are used to store flags. See compileRuleList.
</span><span class="cx">     if (ResourceFlags flags = (action & ActionFlagMask) >> 32) {
</span><span class="cx">         auto flagsSize = bytecodeFlagsSize(flags);
</span><del>-        auto instruction = (action & IfConditionFlag) ? DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition : DFABytecodeInstruction::TestFlagsAndAppendAction;
</del><ins>+        auto instruction = DFABytecodeInstruction::TestFlagsAndAppendAction;
</ins><span class="cx">         ASSERT(!(static_cast<uint8_t>(instruction) & static_cast<uint8_t>(flagsSize) & static_cast<uint8_t>(actionSize)));
</span><span class="cx">         append<uint8_t>(m_bytecode, static_cast<uint8_t>(instruction) | static_cast<uint8_t>(flagsSize) | static_cast<uint8_t>(actionSize));
</span><span class="cx">         appendVariableLengthUnsignedInteger(m_bytecode, flags);
</span><span class="lines">@@ -129,7 +156,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    auto instruction = (action & IfConditionFlag) ? DFABytecodeInstruction::AppendActionWithIfCondition : DFABytecodeInstruction::AppendAction;
</del><ins>+    auto instruction = DFABytecodeInstruction::AppendAction;
</ins><span class="cx">     ASSERT(!(static_cast<uint8_t>(instruction) & static_cast<uint8_t>(actionSize)));
</span><span class="cx">     append<uint8_t>(m_bytecode, static_cast<uint8_t>(instruction) | static_cast<uint8_t>(actionSize));
</span><span class="cx">     appendVariableLengthUnsignedInteger(m_bytecode, actionWithoutFlags);
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsDFABytecodeInterpretercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp        2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp   2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -83,7 +83,6 @@
</span><span class="cx"> {
</span><span class="cx">     switch (instruction) {
</span><span class="cx">     case DFABytecodeInstruction::TestFlagsAndAppendAction:
</span><del>-    case DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition:
</del><span class="cx">         return true;
</span><span class="cx">     case DFABytecodeInstruction::CheckValueCaseSensitive:
</span><span class="cx">     case DFABytecodeInstruction::CheckValueCaseInsensitive:
</span><span class="lines">@@ -93,7 +92,6 @@
</span><span class="cx">     case DFABytecodeInstruction::CheckValueRangeCaseInsensitive:
</span><span class="cx">     case DFABytecodeInstruction::Jump:
</span><span class="cx">     case DFABytecodeInstruction::AppendAction:
</span><del>-    case DFABytecodeInstruction::AppendActionWithIfCondition:
</del><span class="cx">     case DFABytecodeInstruction::Terminate:
</span><span class="cx">         break;
</span><span class="cx">     }
</span><span class="lines">@@ -104,9 +102,7 @@
</span><span class="cx"> {
</span><span class="cx">     switch (instruction) {
</span><span class="cx">     case DFABytecodeInstruction::TestFlagsAndAppendAction:
</span><del>-    case DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition:
</del><span class="cx">     case DFABytecodeInstruction::AppendAction:
</span><del>-    case DFABytecodeInstruction::AppendActionWithIfCondition:
</del><span class="cx">         return true;
</span><span class="cx">     case DFABytecodeInstruction::CheckValueCaseSensitive:
</span><span class="cx">     case DFABytecodeInstruction::CheckValueCaseInsensitive:
</span><span class="lines">@@ -179,25 +175,14 @@
</span><span class="cx">     RELEASE_ASSERT_NOT_REACHED();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool matchesCondition(uint64_t actionAndFlags, const DFABytecodeInterpreter::Actions& conditionActions)
</del><ins>+void DFABytecodeInterpreter::interpretAppendAction(uint32_t& programCounter, Actions& actions)
</ins><span class="cx"> {
</span><del>-    bool ifCondition = actionAndFlags & IfConditionFlag;
-    bool condition = conditionActions.contains(actionAndFlags);
-    return ifCondition == condition;
-}
-
-void DFABytecodeInterpreter::interpretAppendAction(uint32_t& programCounter, Actions& actions, bool ifCondition)
-{
-    ASSERT(getInstruction(m_bytecode, programCounter) == DFABytecodeInstruction::AppendAction
-        || getInstruction(m_bytecode, programCounter) == DFABytecodeInstruction::AppendActionWithIfCondition);
</del><ins>+    ASSERT(getInstruction(m_bytecode, programCounter) == DFABytecodeInstruction::AppendAction);
</ins><span class="cx">     auto instructionLocation = programCounter++;
</span><del>-    uint64_t actionWithoutFlags = consumeAction(m_bytecode, programCounter, instructionLocation);
-    uint64_t action = (ifCondition ? IfConditionFlag : 0) | actionWithoutFlags;
-    if (!m_topURLActions || matchesCondition(action, *m_topURLActions))
-        actions.add(action);
</del><ins>+    actions.add(consumeAction(m_bytecode, programCounter, instructionLocation));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void DFABytecodeInterpreter::interpretTestFlagsAndAppendAction(uint32_t& programCounter, ResourceFlags flags, Actions& actions, bool ifCondition)
</del><ins>+void DFABytecodeInterpreter::interpretTestFlagsAndAppendAction(uint32_t& programCounter, ResourceFlags flags, Actions& actions)
</ins><span class="cx"> {
</span><span class="cx">     auto instructionLocation = programCounter;
</span><span class="cx">     auto flagsToCheck = consumeResourceFlagsAndInstruction(m_bytecode, programCounter);
</span><span class="lines">@@ -212,9 +197,8 @@
</span><span class="cx">     
</span><span class="cx">     auto actionWithoutFlags = consumeAction(m_bytecode, programCounter, instructionLocation);
</span><span class="cx">     if (loadTypeMatches && loadContextMatches && resourceTypeMatches) {
</span><del>-        uint64_t actionAndFlags = (ifCondition ? IfConditionFlag : 0) | (static_cast<uint64_t>(flagsToCheck) << 32) | static_cast<uint64_t>(actionWithoutFlags);
-        if (!m_topURLActions || matchesCondition(actionAndFlags, *m_topURLActions))
-            actions.add(actionAndFlags);
</del><ins>+        uint64_t actionAndFlags = (static_cast<uint64_t>(flagsToCheck) << 32) | static_cast<uint64_t>(actionWithoutFlags);
+        actions.add(actionAndFlags);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -248,11 +232,8 @@
</span><span class="cx">     while (programCounter < dfaBytecodeLength) {
</span><span class="cx">         DFABytecodeInstruction instruction = getInstruction(m_bytecode, programCounter);
</span><span class="cx">         if (instruction == DFABytecodeInstruction::AppendAction)
</span><del>-            interpretAppendAction(programCounter, actions, false);
-        else if (instruction == DFABytecodeInstruction::AppendActionWithIfCondition)
-            interpretAppendAction(programCounter, actions, true);
-        else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction
-            || instruction == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition) {
</del><ins>+            interpretAppendAction(programCounter, actions);
+        else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction) {
</ins><span class="cx">             auto programCounterAtInstruction = programCounter;
</span><span class="cx">             consumeResourceFlagsAndInstruction(m_bytecode, programCounter);
</span><span class="cx">             consumeAction(m_bytecode, programCounter, programCounterAtInstruction);
</span><span class="lines">@@ -261,15 +242,6 @@
</span><span class="cx">     }
</span><span class="cx">     return actions;
</span><span class="cx"> }
</span><del>-    
-auto DFABytecodeInterpreter::interpretWithConditions(const CString& urlCString, ResourceFlags flags, const Actions& topURLActions) -> Actions
-{
-    ASSERT(!m_topURLActions);
-    m_topURLActions = &topURLActions;
-    auto actions = interpret(urlCString, flags);
-    m_topURLActions = nullptr;
-    return actions;
-}
</del><span class="cx"> 
</span><span class="cx"> auto DFABytecodeInterpreter::interpret(const CString& urlCString, ResourceFlags flags) -> Actions
</span><span class="cx"> {
</span><span class="lines">@@ -290,13 +262,11 @@
</span><span class="cx">         if (!dfaStart) {
</span><span class="cx">             while (programCounter < dfaBytecodeLength) {
</span><span class="cx">                 DFABytecodeInstruction instruction = getInstruction(m_bytecode, programCounter);
</span><del>-                if (instruction == DFABytecodeInstruction::AppendAction || instruction == DFABytecodeInstruction::AppendActionWithIfCondition) {
</del><ins>+                if (instruction == DFABytecodeInstruction::AppendAction) {
</ins><span class="cx">                     auto instructionLocation = programCounter++;
</span><span class="cx">                     consumeAction(m_bytecode, programCounter, instructionLocation);
</span><span class="cx">                 } else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendAction)
</span><del>-                    interpretTestFlagsAndAppendAction(programCounter, flags, actions, false);
-                else if (instruction == DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition)
-                    interpretTestFlagsAndAppendAction(programCounter, flags, actions, true);
</del><ins>+                    interpretTestFlagsAndAppendAction(programCounter, flags, actions);
</ins><span class="cx">                 else
</span><span class="cx">                     break;
</span><span class="cx">             }
</span><span class="lines">@@ -304,9 +274,7 @@
</span><span class="cx">                 return actions;
</span><span class="cx">         } else {
</span><span class="cx">             ASSERT_WITH_MESSAGE(getInstruction(m_bytecode, programCounter) != DFABytecodeInstruction::AppendAction
</span><del>-                && getInstruction(m_bytecode, programCounter) != DFABytecodeInstruction::AppendActionWithIfCondition
-                && getInstruction(m_bytecode, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendAction
-                && getInstruction(m_bytecode, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition,
</del><ins>+                && getInstruction(m_bytecode, programCounter) != DFABytecodeInstruction::TestFlagsAndAppendAction,
</ins><span class="cx">                 "Triggers that match everything should only be in the first DFA.");
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="lines">@@ -418,20 +386,12 @@
</span><span class="cx">             }
</span><span class="cx">                     
</span><span class="cx">             case DFABytecodeInstruction::AppendAction:
</span><del>-                interpretAppendAction(programCounter, actions, false);
</del><ins>+                interpretAppendAction(programCounter, actions);
</ins><span class="cx">                 break;
</span><span class="cx">                     
</span><del>-            case DFABytecodeInstruction::AppendActionWithIfCondition:
-                interpretAppendAction(programCounter, actions, true);
-                break;
-                    
</del><span class="cx">             case DFABytecodeInstruction::TestFlagsAndAppendAction:
</span><del>-                interpretTestFlagsAndAppendAction(programCounter, flags, actions, false);
</del><ins>+                interpretTestFlagsAndAppendAction(programCounter, flags, actions);
</ins><span class="cx">                 break;
</span><del>-            
-            case DFABytecodeInstruction::TestFlagsAndAppendActionWithIfCondition:
-                interpretTestFlagsAndAppendAction(programCounter, flags, actions, true);
-                break;
</del><span class="cx">                     
</span><span class="cx">             default:
</span><span class="cx">                 RELEASE_ASSERT_NOT_REACHED(); // Invalid bytecode.
</span></span></pre></div>
<a id="trunkSourceWebCorecontentextensionsDFABytecodeInterpreterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h  2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/contentextensions/DFABytecodeInterpreter.h     2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -43,18 +43,16 @@
</span><span class="cx">     using Actions = HashSet<uint64_t, DefaultHash<uint64_t>, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>>;
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT Actions interpret(const CString&, ResourceFlags);
</span><del>-    Actions interpretWithConditions(const CString&, ResourceFlags, const Actions& conditionActions);
</del><span class="cx">     Actions actionsMatchingEverything();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void interpretAppendAction(unsigned& programCounter, Actions&, bool ifCondition);
-    void interpretTestFlagsAndAppendAction(unsigned& programCounter, ResourceFlags, Actions&, bool ifCondition);
</del><ins>+    void interpretAppendAction(unsigned& programCounter, Actions&);
+    void interpretTestFlagsAndAppendAction(unsigned& programCounter, ResourceFlags, Actions&);
</ins><span class="cx"> 
</span><span class="cx">     template<bool caseSensitive>
</span><span class="cx">     void interpetJumpTable(const char* url, uint32_t& urlIndex, uint32_t& programCounter, bool& urlIndexIsAfterEndOfString);
</span><span class="cx"> 
</span><span class="cx">     const Span<const uint8_t> m_bytecode;
</span><del>-    const DFABytecodeInterpreter::Actions* m_topURLActions { nullptr };
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore::ContentExtensions
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadInfocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoadInfo.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoadInfo.cpp 2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.cpp    2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -34,6 +34,14 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore::ContentExtensions {
</span><span class="cx"> 
</span><ins>+static_assert(!(ResourceTypeMask & LoadTypeMask), "ResourceTypeMask and LoadTypeMask should be mutually exclusive because they are stored in the same uint32_t");
+static_assert(!(ResourceTypeMask & LoadContextMask), "ResourceTypeMask and LoadContextMask should be mutually exclusive because they are stored in the same uint32_t");
+static_assert(!(ResourceTypeMask & ActionConditionMask), "ResourceTypeMask and ActionConditionMask should be mutually exclusive because they are stored in the same uint32_t");
+static_assert(!(LoadContextMask & LoadTypeMask), "LoadContextMask and LoadTypeMask should be mutually exclusive because they are stored in the same uint32_t");
+static_assert(!(LoadContextMask & ActionConditionMask), "LoadContextMask and ActionConditionMask should be mutually exclusive because they are stored in the same uint32_t");
+static_assert(!(LoadTypeMask & ActionConditionMask), "LoadTypeMask and ActionConditionMask should be mutually exclusive because they are stored in the same uint32_t");
+static_assert(static_cast<uint64_t>(AllResourceFlags) << 32 == ActionFlagMask, "ActionFlagMask should cover all the action flags");
+
</ins><span class="cx"> OptionSet<ResourceType> toResourceType(CachedResource::Type type, ResourceRequestBase::Requester requester)
</span><span class="cx"> {
</span><span class="cx">     switch (type) {
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadInfoh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoadInfo.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoadInfo.h   2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebCore/loader/ResourceLoadInfo.h      2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -33,6 +33,14 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore::ContentExtensions {
</span><span class="cx"> 
</span><ins>+enum class ActionCondition : uint32_t {
+    None = 0x00000,
+    IfTopURL = 0x20000,
+    UnlessTopURL = 0x40000,
+    IfFrameURL = 0x60000,
+};
+static constexpr uint32_t ActionConditionMask = 0x60000;
+
</ins><span class="cx"> enum class ResourceType : uint32_t {
</span><span class="cx">     Document = 0x0001,
</span><span class="cx">     Image = 0x0002,
</span><span class="lines">@@ -62,21 +70,14 @@
</span><span class="cx"> };
</span><span class="cx"> static constexpr uint32_t LoadContextMask = 0xC000;
</span><span class="cx"> 
</span><del>-static_assert(!(ResourceTypeMask & LoadTypeMask), "ResourceTypeMask and LoadTypeMask should be mutually exclusive because they are stored in the same uint32_t");
-static_assert(!(ResourceTypeMask & LoadContextMask), "ResourceTypeMask and LoadContextMask should be mutually exclusive because they are stored in the same uint32_t");
-static_assert(!(LoadContextMask & LoadTypeMask), "LoadContextMask and LoadTypeMask should be mutually exclusive because they are stored in the same uint32_t");
-
</del><span class="cx"> using ResourceFlags = uint32_t;
</span><span class="cx"> 
</span><ins>+constexpr ResourceFlags AllResourceFlags = LoadTypeMask | ResourceTypeMask | LoadContextMask | ActionConditionMask;
+
</ins><span class="cx"> // The first 32 bits of a uint64_t action are used for the action location.
</span><del>-// The next 24 bits are used for the flags (ResourceType and LoadType).
-// The next bit is used to mark actions that are from a rule with an if-domain.
-//     Actions from rules with unless-domain conditions are distinguished from
-//     rules with if-domain conditions by not having this bit set.
-//     Actions from rules with no conditions are put in the DFA without conditions.
</del><ins>+// The next 19 bits are used for the flags (ResourceType, LoadType, LoadContext, ActionCondition).
</ins><span class="cx"> // The values -1 and -2 are used for removed and empty values in HashTables.
</span><del>-static constexpr uint64_t ActionFlagMask = 0x00FFFFFF00000000;
-static constexpr uint64_t IfConditionFlag = 0x0100000000000000;
</del><ins>+static constexpr uint64_t ActionFlagMask = 0x0007FFFF00000000;
</ins><span class="cx"> 
</span><span class="cx"> OptionSet<ResourceType> toResourceType(CachedResource::Type, ResourceRequestBase::Requester);
</span><span class="cx"> std::optional<OptionSet<ResourceType>> readResourceType(StringView);
</span><span class="lines">@@ -86,6 +87,7 @@
</span><span class="cx"> struct ResourceLoadInfo {
</span><span class="cx">     URL resourceURL;
</span><span class="cx">     URL mainDocumentURL;
</span><ins>+    URL frameURL;
</ins><span class="cx">     OptionSet<ResourceType> type;
</span><span class="cx">     bool mainFrameContext { false };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/ChangeLog       2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2021-12-13  Alex Christensen  <achristensen@webkit.org>
+
+        Allow WKContentRuleList to run regexes on current frame's URL, not just top frame's URL
+        https://bugs.webkit.org/show_bug.cgi?id=233889
+
+        Reviewed by Timothy Hatcher.
+
+        * NetworkProcess/NetworkLoadChecker.cpp:
+        (WebKit::NetworkLoadChecker::processContentRuleListsForLoad):
+        * NetworkProcess/NetworkLoadChecker.h:
+        (WebKit::NetworkLoadChecker::setContentExtensionController):
+        * NetworkProcess/NetworkResourceLoadParameters.h:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        * NetworkProcess/PingLoad.cpp:
+        (WebKit::PingLoad::initialize):
+        * Shared/WebCompiledContentRuleList.cpp:
+        (WebKit::WebCompiledContentRuleList::urlFiltersBytecode const):
+        (WebKit::WebCompiledContentRuleList::filtersWithoutConditionsBytecode const): Deleted.
+        (WebKit::WebCompiledContentRuleList::filtersWithConditionsBytecode const): Deleted.
+        * Shared/WebCompiledContentRuleList.h:
+        * Shared/WebCompiledContentRuleListData.cpp:
+        (WebKit::WebCompiledContentRuleListData::encode const):
+        (WebKit::WebCompiledContentRuleListData::decode):
+        * Shared/WebCompiledContentRuleListData.h:
+        (WebKit::WebCompiledContentRuleListData::WebCompiledContentRuleListData):
+        * UIProcess/API/APIContentRuleListStore.cpp:
+        (API::ContentRuleListMetaData::fileSize const):
+        (API::encodeContentRuleListMetaData):
+        (API::decodeContentRuleListMetaData):
+        (API::compiledToFile):
+        (API::createExtension):
+        (API::getContentRuleListSourceFromMappedFile):
+        * UIProcess/API/APIContentRuleListStore.h:
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::WebLoaderStrategy::scheduleLoadFromNetworkProcess):
+        (WebKit::WebLoaderStrategy::startPingLoad):
+
</ins><span class="cx"> 2021-12-13  Brady Eidson  <beidson@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Teach webpushtool to register and "host" the daemon.
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessNetworkLoadCheckercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp        2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp   2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -474,7 +474,7 @@
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        auto results = backend.processContentRuleListsForPingLoad(request.url(), m_mainDocumentURL);
</del><ins>+        auto results = backend.processContentRuleListsForPingLoad(request.url(), m_mainDocumentURL, m_frameURL);
</ins><span class="cx">         WebCore::ContentExtensions::applyResultsToRequest(ContentRuleListResults { results }, nullptr, request);
</span><span class="cx">         callback(ContentExtensionResult { WTFMove(request), results });
</span><span class="cx">     });
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessNetworkLoadCheckerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.h  2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.h     2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -85,9 +85,10 @@
</span><span class="cx">     void setParentCrossOriginEmbedderPolicy(const WebCore::CrossOriginEmbedderPolicy& parentCrossOriginEmbedderPolicy) { m_parentCrossOriginEmbedderPolicy = parentCrossOriginEmbedderPolicy; }
</span><span class="cx">     void setCrossOriginEmbedderPolicy(const WebCore::CrossOriginEmbedderPolicy& crossOriginEmbedderPolicy) { m_crossOriginEmbedderPolicy = crossOriginEmbedderPolicy; }
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><del>-    void setContentExtensionController(URL&& mainDocumentURL, std::optional<UserContentControllerIdentifier> identifier)
</del><ins>+    void setContentExtensionController(URL&& mainDocumentURL, URL&& frameURL, std::optional<UserContentControllerIdentifier> identifier)
</ins><span class="cx">     {
</span><span class="cx">         m_mainDocumentURL = WTFMove(mainDocumentURL);
</span><ins>+        m_frameURL = WTFMove(frameURL);
</ins><span class="cx">         m_userContentControllerIdentifier = identifier;
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="lines">@@ -148,6 +149,7 @@
</span><span class="cx">     WebCore::CrossOriginEmbedderPolicy m_crossOriginEmbedderPolicy;
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><span class="cx">     URL m_mainDocumentURL;
</span><ins>+    URL m_frameURL;
</ins><span class="cx">     std::optional<UserContentControllerIdentifier> m_userContentControllerIdentifier;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessNetworkResourceLoadParametersh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h       2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h  2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -87,6 +87,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><span class="cx">     URL mainDocumentURL;
</span><ins>+    URL frameURL;
</ins><span class="cx">     std::optional<UserContentControllerIdentifier> userContentControllerIdentifier;
</span><span class="cx"> #endif
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessNetworkResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp     2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp        2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -128,7 +128,7 @@
</span><span class="cx">         m_networkLoadChecker->setParentCrossOriginEmbedderPolicy(m_parameters.parentCrossOriginEmbedderPolicy);
</span><span class="cx">         m_networkLoadChecker->setCrossOriginEmbedderPolicy(m_parameters.crossOriginEmbedderPolicy);
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><del>-        m_networkLoadChecker->setContentExtensionController(URL { m_parameters.mainDocumentURL }, m_parameters.userContentControllerIdentifier);
</del><ins>+        m_networkLoadChecker->setContentExtensionController(URL { m_parameters.mainDocumentURL }, URL { m_parameters.frameURL }, m_parameters.userContentControllerIdentifier);
</ins><span class="cx"> #endif
</span><span class="cx">     }
</span><span class="cx">     if (synchronousReply)
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessPingLoadcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/PingLoad.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/PingLoad.cpp  2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/NetworkProcess/PingLoad.cpp     2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -74,7 +74,7 @@
</span><span class="cx">     m_networkLoadChecker->setParentCrossOriginEmbedderPolicy(m_parameters.parentCrossOriginEmbedderPolicy);
</span><span class="cx">     m_networkLoadChecker->setCrossOriginEmbedderPolicy(m_parameters.crossOriginEmbedderPolicy);
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><del>-    m_networkLoadChecker->setContentExtensionController(WTFMove(m_parameters.mainDocumentURL), m_parameters.userContentControllerIdentifier);
</del><ins>+    m_networkLoadChecker->setContentExtensionController(WTFMove(m_parameters.mainDocumentURL), WTFMove(m_parameters.frameURL), m_parameters.userContentControllerIdentifier);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // If the server never responds, this object will hang around forever.
</span></span></pre></div>
<a id="trunkSourceWebKitSharedWebCompiledContentRuleListcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/WebCompiledContentRuleList.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/WebCompiledContentRuleList.cpp        2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/Shared/WebCompiledContentRuleList.cpp   2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -44,16 +44,11 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Span<const uint8_t> WebCompiledContentRuleList::filtersWithoutConditionsBytecode() const
</del><ins>+Span<const uint8_t> WebCompiledContentRuleList::urlFiltersBytecode() const
</ins><span class="cx"> {
</span><del>-    return spanWithOffsetAndLength(m_data.filtersWithoutConditionsBytecodeOffset, m_data.filtersWithoutConditionsBytecodeSize);
</del><ins>+    return spanWithOffsetAndLength(m_data.urlFiltersBytecodeOffset, m_data.urlFiltersBytecodeSize);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-Span<const uint8_t> WebCompiledContentRuleList::filtersWithConditionsBytecode() const
-{
-    return spanWithOffsetAndLength(m_data.filtersWithConditionsBytecodeOffset, m_data.filtersWithConditionsBytecodeSize);
-}
-
</del><span class="cx"> Span<const uint8_t> WebCompiledContentRuleList::topURLFiltersBytecode() const
</span><span class="cx"> {
</span><span class="cx">     return spanWithOffsetAndLength(m_data.topURLFiltersBytecodeOffset, m_data.topURLFiltersBytecodeSize);
</span></span></pre></div>
<a id="trunkSourceWebKitSharedWebCompiledContentRuleListh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/WebCompiledContentRuleList.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/WebCompiledContentRuleList.h  2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/Shared/WebCompiledContentRuleList.h     2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -43,8 +43,7 @@
</span><span class="cx"> private:
</span><span class="cx">     WebCompiledContentRuleList(WebCompiledContentRuleListData&&);
</span><span class="cx"> 
</span><del>-    Span<const uint8_t> filtersWithoutConditionsBytecode() const final;
-    Span<const uint8_t> filtersWithConditionsBytecode() const final;
</del><ins>+    Span<const uint8_t> urlFiltersBytecode() const final;
</ins><span class="cx">     Span<const uint8_t> topURLFiltersBytecode() const final;
</span><span class="cx">     Span<const uint8_t> frameURLFiltersBytecode() const final;
</span><span class="cx">     Span<const uint8_t> serializedActions() const final;
</span></span></pre></div>
<a id="trunkSourceWebKitSharedWebCompiledContentRuleListDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp    2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp       2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -51,10 +51,8 @@
</span><span class="cx"> 
</span><span class="cx">     encoder << actionsOffset;
</span><span class="cx">     encoder << actionsSize;
</span><del>-    encoder << filtersWithoutConditionsBytecodeOffset;
-    encoder << filtersWithoutConditionsBytecodeSize;
-    encoder << filtersWithConditionsBytecodeOffset;
-    encoder << filtersWithConditionsBytecodeSize;
</del><ins>+    encoder << urlFiltersBytecodeOffset;
+    encoder << urlFiltersBytecodeSize;
</ins><span class="cx">     encoder << topURLFiltersBytecodeOffset;
</span><span class="cx">     encoder << topURLFiltersBytecodeSize;
</span><span class="cx">     encoder << frameURLFiltersBytecodeOffset;
</span><span class="lines">@@ -85,26 +83,16 @@
</span><span class="cx">     if (!actionsSize)
</span><span class="cx">         return std::nullopt;
</span><span class="cx"> 
</span><del>-    std::optional<size_t> filtersWithoutConditionsBytecodeOffset;
-    decoder >> filtersWithoutConditionsBytecodeOffset;
-    if (!filtersWithoutConditionsBytecodeOffset)
</del><ins>+    std::optional<size_t> urlFiltersBytecodeOffset;
+    decoder >> urlFiltersBytecodeOffset;
+    if (!urlFiltersBytecodeOffset)
</ins><span class="cx">         return std::nullopt;
</span><span class="cx"> 
</span><del>-    std::optional<size_t> filtersWithoutConditionsBytecodeSize;
-    decoder >> filtersWithoutConditionsBytecodeSize;
-    if (!filtersWithoutConditionsBytecodeSize)
</del><ins>+    std::optional<size_t> urlFiltersBytecodeSize;
+    decoder >> urlFiltersBytecodeSize;
+    if (!urlFiltersBytecodeSize)
</ins><span class="cx">         return std::nullopt;
</span><span class="cx"> 
</span><del>-    std::optional<size_t> filtersWithConditionsBytecodeOffset;
-    decoder >> filtersWithConditionsBytecodeOffset;
-    if (!filtersWithConditionsBytecodeOffset)
-        return std::nullopt;
-
-    std::optional<size_t> filtersWithConditionsBytecodeSize;
-    decoder >> filtersWithConditionsBytecodeSize;
-    if (!filtersWithConditionsBytecodeSize)
-        return std::nullopt;
-
</del><span class="cx">     std::optional<size_t> topURLFiltersBytecodeOffset;
</span><span class="cx">     decoder >> topURLFiltersBytecodeOffset;
</span><span class="cx">     if (!topURLFiltersBytecodeOffset)
</span><span class="lines">@@ -130,10 +118,8 @@
</span><span class="cx">         data.releaseNonNull(),
</span><span class="cx">         WTFMove(*actionsOffset),
</span><span class="cx">         WTFMove(*actionsSize),
</span><del>-        WTFMove(*filtersWithoutConditionsBytecodeOffset),
-        WTFMove(*filtersWithoutConditionsBytecodeSize),
-        WTFMove(*filtersWithConditionsBytecodeOffset),
-        WTFMove(*filtersWithConditionsBytecodeSize),
</del><ins>+        WTFMove(*urlFiltersBytecodeOffset),
+        WTFMove(*urlFiltersBytecodeSize),
</ins><span class="cx">         WTFMove(*topURLFiltersBytecodeOffset),
</span><span class="cx">         WTFMove(*topURLFiltersBytecodeSize),
</span><span class="cx">         WTFMove(*frameURLFiltersBytecodeOffset),
</span></span></pre></div>
<a id="trunkSourceWebKitSharedWebCompiledContentRuleListDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.h      2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.h 2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -41,15 +41,13 @@
</span><span class="cx"> 
</span><span class="cx"> class WebCompiledContentRuleListData {
</span><span class="cx"> public:
</span><del>-    WebCompiledContentRuleListData(String&& identifier, Ref<SharedMemory>&& data, size_t actionsOffset, size_t actionsSize, size_t filtersWithoutConditionsBytecodeOffset, size_t filtersWithoutConditionsBytecodeSize, size_t filtersWithConditionsBytecodeOffset, size_t filtersWithConditionsBytecodeSize, size_t topURLFiltersBytecodeOffset, size_t topURLFiltersBytecodeSize, size_t frameURLFiltersBytecodeOffset, size_t frameURLFiltersBytecodeSize)
</del><ins>+    WebCompiledContentRuleListData(String&& identifier, Ref<SharedMemory>&& data, size_t actionsOffset, size_t actionsSize, size_t urlFiltersBytecodeOffset, size_t urlFiltersBytecodeSize, size_t topURLFiltersBytecodeOffset, size_t topURLFiltersBytecodeSize, size_t frameURLFiltersBytecodeOffset, size_t frameURLFiltersBytecodeSize)
</ins><span class="cx">         : identifier(WTFMove(identifier))
</span><span class="cx">         , data(WTFMove(data))
</span><span class="cx">         , actionsOffset(actionsOffset)
</span><span class="cx">         , actionsSize(actionsSize)
</span><del>-        , filtersWithoutConditionsBytecodeOffset(filtersWithoutConditionsBytecodeOffset)
-        , filtersWithoutConditionsBytecodeSize(filtersWithoutConditionsBytecodeSize)
-        , filtersWithConditionsBytecodeOffset(filtersWithConditionsBytecodeOffset)
-        , filtersWithConditionsBytecodeSize(filtersWithConditionsBytecodeSize)
</del><ins>+        , urlFiltersBytecodeOffset(urlFiltersBytecodeOffset)
+        , urlFiltersBytecodeSize(urlFiltersBytecodeSize)
</ins><span class="cx">         , topURLFiltersBytecodeOffset(topURLFiltersBytecodeOffset)
</span><span class="cx">         , topURLFiltersBytecodeSize(topURLFiltersBytecodeSize)
</span><span class="cx">         , frameURLFiltersBytecodeOffset(frameURLFiltersBytecodeOffset)
</span><span class="lines">@@ -64,10 +62,8 @@
</span><span class="cx">     Ref<SharedMemory> data;
</span><span class="cx">     size_t actionsOffset { 0 };
</span><span class="cx">     size_t actionsSize { 0 };
</span><del>-    size_t filtersWithoutConditionsBytecodeOffset { 0 };
-    size_t filtersWithoutConditionsBytecodeSize { 0 };
-    size_t filtersWithConditionsBytecodeOffset { 0 };
-    size_t filtersWithConditionsBytecodeSize { 0 };
</del><ins>+    size_t urlFiltersBytecodeOffset { 0 };
+    size_t urlFiltersBytecodeSize { 0 };
</ins><span class="cx">     size_t topURLFiltersBytecodeOffset { 0 };
</span><span class="cx">     size_t topURLFiltersBytecodeSize { 0 };
</span><span class="cx">     size_t frameURLFiltersBytecodeOffset { 0 };
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIAPIContentRuleListStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp    2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp       2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -109,12 +109,12 @@
</span><span class="cx">     uint32_t version { ContentRuleListStore::CurrentContentRuleListFileVersion };
</span><span class="cx">     uint64_t sourceSize { 0 };
</span><span class="cx">     uint64_t actionsSize { 0 };
</span><del>-    uint64_t filtersWithoutConditionsBytecodeSize { 0 };
-    uint64_t filtersWithConditionsBytecodeSize { 0 };
-    uint64_t conditionedFiltersBytecodeSize { 0 };
</del><ins>+    uint64_t urlFiltersBytecodeSize { 0 };
+    uint64_t topURLFiltersBytecodeSize { 0 };
+    uint64_t frameURLFiltersBytecodeSize { 0 };
</ins><span class="cx">     uint32_t unused32bits { false };
</span><del>-    uint64_t frameURLFiltersBytecodeSize { 0 };
-    uint64_t unused64bits { 0 }; // Additional space on disk reserved so we can add something without incrementing the version number.
</del><ins>+    uint64_t unused64bits1 { 0 };
+    uint64_t unused64bits2 { 0 }; // Additional space on disk reserved so we can add something without incrementing the version number.
</ins><span class="cx">     
</span><span class="cx">     size_t fileSize() const
</span><span class="cx">     {
</span><span class="lines">@@ -121,9 +121,8 @@
</span><span class="cx">         return headerSize(version)
</span><span class="cx">             + sourceSize
</span><span class="cx">             + actionsSize
</span><del>-            + filtersWithoutConditionsBytecodeSize
-            + filtersWithConditionsBytecodeSize
-            + conditionedFiltersBytecodeSize
</del><ins>+            + urlFiltersBytecodeSize
+            + topURLFiltersBytecodeSize
</ins><span class="cx">             + frameURLFiltersBytecodeSize;
</span><span class="cx">     }
</span><span class="cx"> };
</span><span class="lines">@@ -135,12 +134,12 @@
</span><span class="cx">     encoder << metaData.version;
</span><span class="cx">     encoder << metaData.sourceSize;
</span><span class="cx">     encoder << metaData.actionsSize;
</span><del>-    encoder << metaData.filtersWithoutConditionsBytecodeSize;
-    encoder << metaData.filtersWithConditionsBytecodeSize;
-    encoder << metaData.conditionedFiltersBytecodeSize;
</del><ins>+    encoder << metaData.urlFiltersBytecodeSize;
+    encoder << metaData.topURLFiltersBytecodeSize;
+    encoder << metaData.frameURLFiltersBytecodeSize;
</ins><span class="cx">     encoder << metaData.unused32bits;
</span><del>-    encoder << metaData.frameURLFiltersBytecodeSize;
-    encoder << metaData.unused64bits;
</del><ins>+    encoder << metaData.unused64bits1;
+    encoder << metaData.unused64bits2;
</ins><span class="cx"> 
</span><span class="cx">     ASSERT(encoder.bufferSize() == CurrentVersionFileHeaderSize);
</span><span class="cx">     return WebKit::NetworkCache::Data(encoder.buffer(), encoder.bufferSize());
</span><span class="lines">@@ -181,23 +180,23 @@
</span><span class="cx">         return std::nullopt;
</span><span class="cx">     metaData.actionsSize = WTFMove(*actionsSize);
</span><span class="cx"> 
</span><del>-    std::optional<uint64_t> filtersWithoutConditionsBytecodeSize;
-    decoder >> filtersWithoutConditionsBytecodeSize;
-    if (!filtersWithoutConditionsBytecodeSize)
</del><ins>+    std::optional<uint64_t> urlFiltersBytecodeSize;
+    decoder >> urlFiltersBytecodeSize;
+    if (!urlFiltersBytecodeSize)
</ins><span class="cx">         return std::nullopt;
</span><del>-    metaData.filtersWithoutConditionsBytecodeSize = WTFMove(*filtersWithoutConditionsBytecodeSize);
</del><ins>+    metaData.urlFiltersBytecodeSize = WTFMove(*urlFiltersBytecodeSize);
</ins><span class="cx"> 
</span><del>-    std::optional<uint64_t> filtersWithConditionsBytecodeSize;
-    decoder >> filtersWithConditionsBytecodeSize;
-    if (!filtersWithConditionsBytecodeSize)
</del><ins>+    std::optional<uint64_t> topURLFiltersBytecodeSize;
+    decoder >> topURLFiltersBytecodeSize;
+    if (!topURLFiltersBytecodeSize)
</ins><span class="cx">         return std::nullopt;
</span><del>-    metaData.filtersWithConditionsBytecodeSize = WTFMove(*filtersWithConditionsBytecodeSize);
</del><ins>+    metaData.topURLFiltersBytecodeSize = WTFMove(*topURLFiltersBytecodeSize);
</ins><span class="cx"> 
</span><del>-    std::optional<uint64_t> conditionedFiltersBytecodeSize;
-    decoder >> conditionedFiltersBytecodeSize;
-    if (!conditionedFiltersBytecodeSize)
</del><ins>+    std::optional<uint64_t> frameURLFiltersBytecodeSize;
+    decoder >> frameURLFiltersBytecodeSize;
+    if (!frameURLFiltersBytecodeSize)
</ins><span class="cx">         return std::nullopt;
</span><del>-    metaData.conditionedFiltersBytecodeSize = WTFMove(*conditionedFiltersBytecodeSize);
</del><ins>+    metaData.frameURLFiltersBytecodeSize = WTFMove(*frameURLFiltersBytecodeSize);
</ins><span class="cx"> 
</span><span class="cx">     std::optional<uint32_t> unused32bits;
</span><span class="cx">     decoder >> unused32bits;
</span><span class="lines">@@ -208,17 +207,17 @@
</span><span class="cx">     if (metaData.version < 12)
</span><span class="cx">         return metaData;
</span><span class="cx"> 
</span><del>-    std::optional<uint64_t> frameURLFiltersBytecodeSize;
-    decoder >> frameURLFiltersBytecodeSize;
-    if (!frameURLFiltersBytecodeSize)
</del><ins>+    std::optional<uint64_t> unused1;
+    decoder >> unused1;
+    if (!unused1)
</ins><span class="cx">         return std::nullopt;
</span><del>-    metaData.frameURLFiltersBytecodeSize = WTFMove(*frameURLFiltersBytecodeSize);
-    
-    std::optional<uint64_t> unused;
-    decoder >> unused;
-    if (!unused)
</del><ins>+    metaData.unused64bits1 = 0;
+
+    std::optional<uint64_t> unused2;
+    decoder >> unused2;
+    if (!unused2)
</ins><span class="cx">         return std::nullopt;
</span><del>-    metaData.unused64bits = 0;
</del><ins>+    metaData.unused64bits2 = 0;
</ins><span class="cx"> 
</span><span class="cx">     return metaData;
</span><span class="cx"> }
</span><span class="lines">@@ -266,18 +265,19 @@
</span><span class="cx">         {
</span><span class="cx">             ASSERT(!metaData.sourceSize);
</span><span class="cx">             ASSERT(!metaData.actionsSize);
</span><del>-            ASSERT(!metaData.filtersWithoutConditionsBytecodeSize);
-            ASSERT(!metaData.filtersWithConditionsBytecodeSize);
-            ASSERT(!metaData.conditionedFiltersBytecodeSize);
</del><ins>+            ASSERT(!metaData.urlFiltersBytecodeSize);
+            ASSERT(!metaData.topURLFiltersBytecodeSize);
+            ASSERT(!metaData.frameURLFiltersBytecodeSize);
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         void writeSource(WTF::String&& sourceJSON) final
</span><span class="cx">         {
</span><del>-            ASSERT(!m_filtersWithoutConditionsBytecodeWritten);
-            ASSERT(!m_filtersWithConditionBytecodeWritten);
-            ASSERT(!m_conditionFiltersBytecodeWritten);
</del><ins>+            ASSERT(!m_sourceWritten);
</ins><span class="cx">             ASSERT(!m_actionsWritten);
</span><del>-            ASSERT(!m_sourceWritten);
</del><ins>+            ASSERT(!m_urlFiltersBytecodeWritten);
+            ASSERT(!m_topURLFiltersBytecodeWritten);
+            ASSERT(!m_frameURLFiltersBytecodeWritten);
+
</ins><span class="cx">             writeToFile(sourceJSON.is8Bit());
</span><span class="cx">             m_sourceWritten += sizeof(bool);
</span><span class="cx">             if (sourceJSON.is8Bit()) {
</span><span class="lines">@@ -290,36 +290,36 @@
</span><span class="cx">                 m_sourceWritten += serializedLength;
</span><span class="cx">             }
</span><span class="cx">         }
</span><del>-        
-        void writeFiltersWithoutConditionsBytecode(Vector<DFABytecode>&& bytecode) final
</del><ins>+
+        void writeActions(Vector<SerializedActionByte>&& actions) final
</ins><span class="cx">         {
</span><del>-            ASSERT(!m_filtersWithConditionBytecodeWritten);
-            ASSERT(!m_conditionFiltersBytecodeWritten);
-            m_filtersWithoutConditionsBytecodeWritten += bytecode.size();
-            writeToFile(WebKit::NetworkCache::Data(bytecode.data(), bytecode.size()));
</del><ins>+            ASSERT(!m_actionsWritten);
+            ASSERT(!m_urlFiltersBytecodeWritten);
+            ASSERT(!m_topURLFiltersBytecodeWritten);
+            ASSERT(!m_frameURLFiltersBytecodeWritten);
+            m_actionsWritten += actions.size();
+            writeToFile(WebKit::NetworkCache::Data(actions.data(), actions.size()));
</ins><span class="cx">         }
</span><del>-        
-        void writeFiltersWithConditionsBytecode(Vector<DFABytecode>&& bytecode) final
</del><ins>+
+        void writeURLFiltersBytecode(Vector<DFABytecode>&& bytecode) final
</ins><span class="cx">         {
</span><del>-            ASSERT(!m_conditionFiltersBytecodeWritten);
-            m_filtersWithConditionBytecodeWritten += bytecode.size();
</del><ins>+            ASSERT(!m_topURLFiltersBytecodeWritten);
+            ASSERT(!m_frameURLFiltersBytecodeWritten);
+            m_urlFiltersBytecodeWritten += bytecode.size();
</ins><span class="cx">             writeToFile(WebKit::NetworkCache::Data(bytecode.data(), bytecode.size()));
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         void writeTopURLFiltersBytecode(Vector<DFABytecode>&& bytecode) final
</span><span class="cx">         {
</span><del>-            m_conditionFiltersBytecodeWritten += bytecode.size();
</del><ins>+            ASSERT(!m_frameURLFiltersBytecodeWritten);
+            m_topURLFiltersBytecodeWritten += bytecode.size();
</ins><span class="cx">             writeToFile(WebKit::NetworkCache::Data(bytecode.data(), bytecode.size()));
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        void writeActions(Vector<SerializedActionByte>&& actions) final
</del><ins>+        void writeFrameURLFiltersBytecode(Vector<DFABytecode>&& bytecode) final
</ins><span class="cx">         {
</span><del>-            ASSERT(!m_filtersWithoutConditionsBytecodeWritten);
-            ASSERT(!m_filtersWithConditionBytecodeWritten);
-            ASSERT(!m_conditionFiltersBytecodeWritten);
-            ASSERT(!m_actionsWritten);
-            m_actionsWritten += actions.size();
-            writeToFile(WebKit::NetworkCache::Data(actions.data(), actions.size()));
</del><ins>+            m_frameURLFiltersBytecodeWritten += bytecode.size();
+            writeToFile(WebKit::NetworkCache::Data(bytecode.data(), bytecode.size()));
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         void finalize() final
</span><span class="lines">@@ -326,10 +326,10 @@
</span><span class="cx">         {
</span><span class="cx">             m_metaData.sourceSize = m_sourceWritten;
</span><span class="cx">             m_metaData.actionsSize = m_actionsWritten;
</span><del>-            m_metaData.filtersWithoutConditionsBytecodeSize = m_filtersWithoutConditionsBytecodeWritten;
-            m_metaData.filtersWithConditionsBytecodeSize = m_filtersWithConditionBytecodeWritten;
-            m_metaData.conditionedFiltersBytecodeSize = m_conditionFiltersBytecodeWritten;
-            
</del><ins>+            m_metaData.urlFiltersBytecodeSize = m_urlFiltersBytecodeWritten;
+            m_metaData.topURLFiltersBytecodeSize = m_topURLFiltersBytecodeWritten;
+            m_metaData.frameURLFiltersBytecodeSize = m_frameURLFiltersBytecodeWritten;
+
</ins><span class="cx">             WebKit::NetworkCache::Data header = encodeContentRuleListMetaData(m_metaData);
</span><span class="cx">             if (!m_fileError && seekFile(m_fileHandle, 0ll, FileSeekOrigin::Beginning) == -1) {
</span><span class="cx">                 closeFile(m_fileHandle);
</span><span class="lines">@@ -355,11 +355,11 @@
</span><span class="cx">         
</span><span class="cx">         PlatformFileHandle m_fileHandle;
</span><span class="cx">         ContentRuleListMetaData& m_metaData;
</span><del>-        size_t m_filtersWithoutConditionsBytecodeWritten { 0 };
-        size_t m_filtersWithConditionBytecodeWritten { 0 };
-        size_t m_conditionFiltersBytecodeWritten { 0 };
</del><ins>+        size_t m_sourceWritten { 0 };
</ins><span class="cx">         size_t m_actionsWritten { 0 };
</span><del>-        size_t m_sourceWritten { 0 };
</del><ins>+        size_t m_urlFiltersBytecodeWritten { 0 };
+        size_t m_topURLFiltersBytecodeWritten { 0 };
+        size_t m_frameURLFiltersBytecodeWritten { 0 };
</ins><span class="cx">         bool m_fileError { false };
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="lines">@@ -422,28 +422,21 @@
</span><span class="cx">     RELEASE_ASSERT(sharedMemory);
</span><span class="cx"> 
</span><span class="cx">     const size_t headerAndSourceSize = headerSize(data.metaData.version) + data.metaData.sourceSize;
</span><ins>+    const size_t actionsOffset = headerAndSourceSize;
+    const size_t urlFiltersOffset = actionsOffset + data.metaData.actionsSize;
+    const size_t topURLFiltersOffset = urlFiltersOffset + data.metaData.urlFiltersBytecodeSize;
+    const size_t frameURLFiltersOffset = topURLFiltersOffset + data.metaData.topURLFiltersBytecodeSize;
+
</ins><span class="cx">     auto compiledContentRuleListData = WebKit::WebCompiledContentRuleListData(
</span><span class="cx">         WTF::String(identifier),
</span><span class="cx">         sharedMemory.releaseNonNull(),
</span><del>-        headerAndSourceSize,
</del><ins>+        actionsOffset,
</ins><span class="cx">         data.metaData.actionsSize,
</span><del>-        headerAndSourceSize
-            + data.metaData.actionsSize,
-        data.metaData.filtersWithoutConditionsBytecodeSize,
-        headerAndSourceSize
-            + data.metaData.actionsSize
-            + data.metaData.filtersWithoutConditionsBytecodeSize,
-        data.metaData.filtersWithConditionsBytecodeSize,
-        headerAndSourceSize
-            + data.metaData.actionsSize
-            + data.metaData.filtersWithoutConditionsBytecodeSize
-            + data.metaData.filtersWithConditionsBytecodeSize,
-        data.metaData.conditionedFiltersBytecodeSize,
-        headerAndSourceSize
-            + data.metaData.actionsSize
-            + data.metaData.filtersWithoutConditionsBytecodeSize
-            + data.metaData.filtersWithConditionsBytecodeSize
-            + data.metaData.conditionedFiltersBytecodeSize,
</del><ins>+        urlFiltersOffset,
+        data.metaData.urlFiltersBytecodeSize,
+        topURLFiltersOffset,
+        data.metaData.topURLFiltersBytecodeSize,
+        frameURLFiltersOffset,
</ins><span class="cx">         data.metaData.frameURLFiltersBytecodeSize
</span><span class="cx">     );
</span><span class="cx">     auto compiledContentRuleList = WebKit::WebCompiledContentRuleList::create(WTFMove(compiledContentRuleListData));
</span><span class="lines">@@ -454,30 +447,25 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!RunLoop::isMain());
</span><span class="cx"> 
</span><del>-    switch (mappedData.metaData.version) {
-    case 9:
-    case 10:
-    case 11:
-    case 12:
-    case 13:
-        if (!mappedData.metaData.sourceSize)
-            return { };
-            
-        auto headerSizeBytes = headerSize(mappedData.metaData.version);
-        bool is8Bit = mappedData.data.data()[headerSizeBytes];
-        size_t start = headerSizeBytes + sizeof(bool);
-        size_t length = mappedData.metaData.sourceSize - sizeof(bool);
-        if (is8Bit)
-            return WTF::String(mappedData.data.data() + start, length);
-        if (length % sizeof(UChar)) {
-            ASSERT_NOT_REACHED();
-            return { };
-        }
-        return WTF::String(reinterpret_cast<const UChar*>(mappedData.data.data() + start), length / sizeof(UChar));
</del><ins>+    if (mappedData.metaData.version < 9) {
+        // Older versions cannot recover the original JSON source from disk.
+        return { };
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // Older versions cannot recover the original JSON source from disk.
-    return { };
</del><ins>+    if (!mappedData.metaData.sourceSize)
+        return { };
+
+    auto headerSizeBytes = headerSize(mappedData.metaData.version);
+    bool is8Bit = mappedData.data.data()[headerSizeBytes];
+    size_t start = headerSizeBytes + sizeof(bool);
+    size_t length = mappedData.metaData.sourceSize - sizeof(bool);
+    if (is8Bit)
+        return WTF::String(mappedData.data.data() + start, length);
+    if (length % sizeof(UChar)) {
+        ASSERT_NOT_REACHED();
+        return { };
+    }
+    return WTF::String(reinterpret_cast<const UChar*>(mappedData.data.data() + start), length / sizeof(UChar));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ContentRuleListStore::lookupContentRuleList(const WTF::String& identifier, CompletionHandler<void(RefPtr<API::ContentRuleList>, std::error_code)> completionHandler)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIAPIContentRuleListStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.h (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.h      2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.h 2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -54,9 +54,7 @@
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><span class="cx">     // This should be incremented every time a functional change is made to the bytecode, file format, etc.
</span><span class="cx">     // to prevent crashing while loading old data.
</span><del>-    // Also update getContentRuleListSourceFromMappedFile to be able to find the original JSON
-    // source from old versions.
-    static constexpr uint32_t CurrentContentRuleListFileVersion = 13;
</del><ins>+    static constexpr uint32_t CurrentContentRuleListFileVersion = 14;
</ins><span class="cx"> 
</span><span class="cx">     static ContentRuleListStore& defaultStore();
</span><span class="cx">     static Ref<ContentRuleListStore> storeWithPath(const WTF::String& storePath);
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessNetworkWebLoaderStrategycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp     2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp        2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -361,6 +361,7 @@
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><span class="cx">     if (document) {
</span><span class="cx">         loadParameters.mainDocumentURL = document->topDocument().url();
</span><ins>+        loadParameters.frameURL = document->url();
</ins><span class="cx">         // FIXME: Instead of passing userContentControllerIdentifier, the NetworkProcess should be able to get it using webPageId.
</span><span class="cx">         if (auto* webPage = webFrame ? webFrame->page() : nullptr)
</span><span class="cx">             loadParameters.userContentControllerIdentifier = webPage->userContentControllerIdentifier();
</span><span class="lines">@@ -752,6 +753,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTENT_EXTENSIONS)
</span><span class="cx">     loadParameters.mainDocumentURL = document->topDocument().url();
</span><ins>+    loadParameters.frameURL = document->url();
</ins><span class="cx">     // FIXME: Instead of passing userContentControllerIdentifier, we should just pass webPageId to NetworkProcess.
</span><span class="cx">     loadParameters.userContentControllerIdentifier = webPage->userContentControllerIdentifier();
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Tools/ChangeLog       2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2021-12-13  Alex Christensen  <achristensen@webkit.org>
+
+        Allow WKContentRuleList to run regexes on current frame's URL, not just top frame's URL
+        https://bugs.webkit.org/show_bug.cgi?id=233889
+
+        Reviewed by Timothy Hatcher.
+
+        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+        (TestWebKitAPI::mainDocumentRequest):
+        (TestWebKitAPI::subResourceRequest):
+        (TestWebKitAPI::TEST_F):
+
</ins><span class="cx"> 2021-12-13  Brady Eidson  <beidson@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Teach webpushtool to register and "host" the daemon.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebCoreContentExtensionscpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (287009 => 287010)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp    2021-12-14 04:23:27 UTC (rev 287009)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp       2021-12-14 04:26:34 UTC (rev 287010)
</span><span class="lines">@@ -63,8 +63,7 @@
</span><span class="cx"> 
</span><span class="cx"> struct CompiledContentExtensionData {
</span><span class="cx">     Vector<ContentExtensions::SerializedActionByte> actions;
</span><del>-    Vector<ContentExtensions::DFABytecode> filtersWithoutConditions;
-    Vector<ContentExtensions::DFABytecode> filtersWithConditions;
</del><ins>+    Vector<ContentExtensions::DFABytecode> urlFilters;
</ins><span class="cx">     Vector<ContentExtensions::DFABytecode> topURLFilters;
</span><span class="cx">     Vector<ContentExtensions::DFABytecode> frameURLFilters;
</span><span class="cx"> };
</span><span class="lines">@@ -75,52 +74,62 @@
</span><span class="cx">         : m_data(data)
</span><span class="cx">     {
</span><span class="cx">         EXPECT_EQ(data.actions.size(), 0ull);
</span><del>-        EXPECT_EQ(data.filtersWithoutConditions.size(), 0ull);
-        EXPECT_EQ(data.filtersWithConditions.size(), 0ull);
</del><ins>+        EXPECT_EQ(data.urlFilters.size(), 0ull);
</ins><span class="cx">         EXPECT_EQ(data.topURLFilters.size(), 0ull);
</span><ins>+        EXPECT_EQ(data.frameURLFilters.size(), 0ull);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void writeSource(String&&) final { }
</del><ins>+    void writeSource(String&&) final
+    {
+        EXPECT_FALSE(sourceWritten);
+        sourceWritten = true;
+    }
</ins><span class="cx"> 
</span><del>-    void writeActions(Vector<ContentExtensions::SerializedActionByte>&& actions) final
</del><ins>+    void writeActions(Vector<SerializedActionByte>&& actions) final
</ins><span class="cx">     {
</span><ins>+        EXPECT_TRUE(sourceWritten);
</ins><span class="cx">         EXPECT_FALSE(finalized);
</span><span class="cx">         EXPECT_EQ(m_data.actions.size(), 0ull);
</span><del>-        EXPECT_EQ(m_data.filtersWithoutConditions.size(), 0ull);
-        EXPECT_EQ(m_data.filtersWithConditions.size(), 0ull);
</del><ins>+        EXPECT_EQ(m_data.urlFilters.size(), 0ull);
</ins><span class="cx">         EXPECT_EQ(m_data.topURLFilters.size(), 0ull);
</span><del>-        EXPECT_EQ(m_data.actions.size(), 0ull);
</del><ins>+        EXPECT_EQ(m_data.frameURLFilters.size(), 0ull);
</ins><span class="cx">         m_data.actions.appendVector(actions);
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    void writeFiltersWithoutConditionsBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) final
</del><ins>+    void writeURLFiltersBytecode(Vector<DFABytecode>&& bytecode) final
</ins><span class="cx">     {
</span><ins>+        EXPECT_TRUE(sourceWritten);
</ins><span class="cx">         EXPECT_FALSE(finalized);
</span><del>-        EXPECT_EQ(m_data.filtersWithConditions.size(), 0ull);
</del><span class="cx">         EXPECT_EQ(m_data.topURLFilters.size(), 0ull);
</span><del>-        m_data.filtersWithoutConditions.appendVector(bytecode);
</del><ins>+        EXPECT_EQ(m_data.frameURLFilters.size(), 0ull);
+        m_data.urlFilters.appendVector(bytecode);
</ins><span class="cx">     }
</span><del>-    
-    void writeFiltersWithConditionsBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) final
</del><ins>+
+    void writeTopURLFiltersBytecode(Vector<DFABytecode>&& bytecode) final
</ins><span class="cx">     {
</span><ins>+        EXPECT_TRUE(sourceWritten);
</ins><span class="cx">         EXPECT_FALSE(finalized);
</span><del>-        EXPECT_EQ(m_data.topURLFilters.size(), 0ull);
-        m_data.filtersWithConditions.appendVector(bytecode);
</del><ins>+        EXPECT_EQ(m_data.frameURLFilters.size(), 0ull);
+        m_data.topURLFilters.appendVector(bytecode);
</ins><span class="cx">     }
</span><del>-    
-    void writeTopURLFiltersBytecode(Vector<ContentExtensions::DFABytecode>&& bytecode) final
</del><ins>+
+    void writeFrameURLFiltersBytecode(Vector<DFABytecode>&& bytecode) final
</ins><span class="cx">     {
</span><ins>+        EXPECT_TRUE(sourceWritten);
</ins><span class="cx">         EXPECT_FALSE(finalized);
</span><del>-        m_data.topURLFilters.appendVector(bytecode);
</del><ins>+        m_data.frameURLFilters.appendVector(bytecode);
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     void finalize() final
</span><span class="cx">     {
</span><ins>+        EXPECT_TRUE(sourceWritten);
+        EXPECT_FALSE(finalized);
</ins><span class="cx">         finalized = true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     CompiledContentExtensionData& m_data;
</span><ins>+    bool sourceWritten { false };
</ins><span class="cx">     bool finalized { false };
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -143,8 +152,7 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     Span<const uint8_t> serializedActions() const final { return { m_data.actions.data(), m_data.actions.size() }; }
</span><del>-    Span<const uint8_t> filtersWithoutConditionsBytecode() const final { return { m_data.filtersWithoutConditions.data(), m_data.filtersWithoutConditions.size() }; }
-    Span<const uint8_t> filtersWithConditionsBytecode() const final { return { m_data.filtersWithConditions.data(), m_data.filtersWithConditions.size() }; }
</del><ins>+    Span<const uint8_t> urlFiltersBytecode() const final { return { m_data.urlFilters.data(), m_data.urlFilters.size() }; }
</ins><span class="cx">     Span<const uint8_t> topURLFiltersBytecode() const final { return { m_data.topURLFilters.data(), m_data.topURLFilters.size() }; }
</span><span class="cx">     Span<const uint8_t> frameURLFiltersBytecode() const final { return { m_data.frameURLFilters.data(), m_data.frameURLFilters.size() }; }
</span><span class="cx"> 
</span><span class="lines">@@ -185,16 +193,23 @@
</span><span class="cx">     EXPECT_EQ(actions.second.size(), stylesheets);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static ResourceLoadInfo mainDocumentRequest(const char* url, ResourceType resourceType = ResourceType::Document)
</del><ins>+static ResourceLoadInfo mainDocumentRequest(const char* urlString, ResourceType resourceType = ResourceType::Document)
</ins><span class="cx"> {
</span><del>-    return { URL(URL(), url), URL(URL(), url), resourceType };
</del><ins>+    URL url(URL(), urlString);
+    return { url, url, url, resourceType };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static ResourceLoadInfo subResourceRequest(const char* url, const char* mainDocumentURL, ResourceType resourceType = ResourceType::Document)
</del><ins>+static ResourceLoadInfo subResourceRequest(const char* url, const char* mainDocumentURLString, ResourceType resourceType = ResourceType::Document)
</ins><span class="cx"> {
</span><del>-    return { URL(URL(), url), URL(URL(), mainDocumentURL), resourceType };
</del><ins>+    URL mainDocumentURL(URL(), mainDocumentURLString);
+    return { URL(URL(), url), mainDocumentURL, mainDocumentURL, resourceType };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static ResourceLoadInfo requestInTopAndFrameURLs(const char* url, const char* topURL, const char* frameURL, ResourceType resourceType = ResourceType::Document)
+{
+    return { URL(URL(), url), URL(URL(), topURL), URL(URL(), frameURL), resourceType };
+}
+
</ins><span class="cx"> ContentExtensions::ContentExtensionsBackend makeBackend(const char* json)
</span><span class="cx"> {
</span><span class="cx">     AtomString::init();
</span><span class="lines">@@ -970,9 +985,9 @@
</span><span class="cx">     ASSERT_EQ(sequenceInstances(data.actions, "GGG"), 1);
</span><span class="cx"> 
</span><span class="cx">     ASSERT_EQ(data.actions.size(), 72u);
</span><del>-    ASSERT_EQ(data.filtersWithoutConditions.size(), 288u);
-    ASSERT_EQ(data.filtersWithConditions.size(), 5u);
</del><ins>+    ASSERT_EQ(data.urlFilters.size(), 288u);
</ins><span class="cx">     ASSERT_EQ(data.topURLFilters.size(), 5u);
</span><ins>+    ASSERT_EQ(data.frameURLFilters.size(), 5u);
</ins><span class="cx"> 
</span><span class="cx">     auto extensionWithFlags = InMemoryCompiledContentExtension::create("["
</span><span class="cx">         "{\"action\":{\"type\":\"notify\",\"notification\":\"AAA\"},\"trigger\":{\"url-filter\":\"A\"}},"
</span><span class="lines">@@ -1123,13 +1138,13 @@
</span><span class="cx">         "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"alwaysblock.pdf\"}}]");
</span><span class="cx">     
</span><span class="cx">     testRequest(backend, mainDocumentRequest("http://webkit.org"), { });
</span><del>-    testRequest(backend, { URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Document }, { variantIndex<ContentExtensions::BlockLoadAction> });
</del><ins>+    testRequest(backend, { URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Document }, { variantIndex<ContentExtensions::BlockLoadAction> });
</ins><span class="cx">         
</span><span class="cx">     testRequest(backend, mainDocumentRequest("http://whatwg.org"), { variantIndex<ContentExtensions::BlockLoadAction> });
</span><del>-    testRequest(backend, { URL(URL(), "http://whatwg.org"), URL(URL(), "http://not_whatwg.org"), ResourceType::Document }, { });
</del><ins>+    testRequest(backend, { URL(URL(), "http://whatwg.org"), URL(URL(), "http://not_whatwg.org"), URL(URL(), "http://not_whatwg.org"), ResourceType::Document }, { });
</ins><span class="cx">     
</span><span class="cx">     testRequest(backend, mainDocumentRequest("http://foobar.org/alwaysblock.pdf"), { variantIndex<ContentExtensions::BlockLoadAction> });
</span><del>-    testRequest(backend, { URL(URL(), "http://foobar.org/alwaysblock.pdf"), URL(URL(), "http://not_foobar.org/alwaysblock.pdf"), ResourceType::Document }, { variantIndex<ContentExtensions::BlockLoadAction> });
</del><ins>+    testRequest(backend, { URL(URL(), "http://foobar.org/alwaysblock.pdf"), URL(URL(), "http://not_foobar.org/alwaysblock.pdf"), URL(URL(), "http://not_foobar.org/alwaysblock.pdf"), ResourceType::Document }, { variantIndex<ContentExtensions::BlockLoadAction> });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TEST_F(ContentExtensionTest, ResourceType)
</span><span class="lines">@@ -1166,8 +1181,8 @@
</span><span class="cx">         "{\"action\":{\"type\":\"ignore-previous-rules\"},\"trigger\":{\"url-filter\":\".*\",\"load-type\":[\"first-party\"]}}]");
</span><span class="cx">     
</span><span class="cx">     testRequest(backend, mainDocumentRequest("http://webkit.org"), { }, 0);
</span><del>-    testRequest(backend, { URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Document }, { variantIndex<ContentExtensions::BlockCookiesAction> });
-    testRequest(backend, { URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Image }, { variantIndex<ContentExtensions::BlockCookiesAction>, variantIndex<ContentExtensions::BlockLoadAction> });
</del><ins>+    testRequest(backend, { URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Document }, { variantIndex<ContentExtensions::BlockCookiesAction> });
+    testRequest(backend, { URL(URL(), "http://webkit.org"), URL(URL(), "http://not_webkit.org"), URL(URL(), "http://not_webkit.org"), ResourceType::Image }, { variantIndex<ContentExtensions::BlockCookiesAction>, variantIndex<ContentExtensions::BlockLoadAction> });
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> TEST_F(ContentExtensionTest, WideNFA)
</span><span class="lines">@@ -1540,6 +1555,7 @@
</span><span class="cx"> 
</span><span class="cx">     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"],\"unless-domain\":[\"a\"]}}]", ContentExtensionError::JSONMultipleConditions);
</span><span class="cx">     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-top-url\":[\"a\"],\"unless-top-url\":[]}}]", ContentExtensionError::JSONMultipleConditions);
</span><ins>+    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-top-url\":[\"a\"],\"if-frame-url\":[]}}]", ContentExtensionError::JSONMultipleConditions);
</ins><span class="cx">     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-top-url\":[\"a\"],\"unless-top-url\":[\"a\"]}}]", ContentExtensionError::JSONMultipleConditions);
</span><span class="cx">     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"],\"if-top-url\":[\"a\"]}}]", ContentExtensionError::JSONMultipleConditions);
</span><span class="cx">     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-top-url\":[],\"unless-domain\":[\"a\"]}}]", ContentExtensionError::JSONMultipleConditions);
</span><span class="lines">@@ -3053,6 +3069,34 @@
</span><span class="cx">     EXPECT_EQ(modifyHeaders, deserializedModifyHeaders);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST_F(ContentExtensionTest, IfFrameURL)
+{
+    auto basic = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"https\", \"if-frame-url\":[\"whatwg\"]}}]");
+    testRequest(basic, requestInTopAndFrameURLs("https://example.com/", "https://webkit.org/", "https://whatwg.org/"), { variantIndex<BlockLoadAction> });
+    testRequest(basic, requestInTopAndFrameURLs("https://example.com/", "https://webkit.org/", "https://webkit.org/"), { });
+
+    auto caseSensitivity = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"https\", \"if-frame-url\":[\"whatwg\"],\"frame-url-filter-is-case-sensitive\":true}}]");
+    auto caseSensitivityRequest = requestInTopAndFrameURLs("https://example.com/", "https://webkit.org/", "https://example.com/wHaTwG");
+    testRequest(basic, caseSensitivityRequest, { variantIndex<BlockLoadAction> });
+    testRequest(caseSensitivity, caseSensitivityRequest, { });
+
+    auto otherFlags = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"https\", \"if-frame-url\":[\"whatwg\"],\"resource-type\":[\"image\"]}}]");
+    testRequest(otherFlags, requestInTopAndFrameURLs("https://example.com/", "https://webkit.org/", "https://whatwg.org/", ResourceType::Document), { });
+    testRequest(otherFlags, requestInTopAndFrameURLs("https://example.com/", "https://webkit.org/", "https://whatwg.org/", ResourceType::Image), { variantIndex<BlockLoadAction> });
+
+    auto otherRulesWithConditions = makeBackend("["
+        "{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"https\", \"if-frame-url\":[\"whatwg\"]}},"
+        "{\"action\":{\"type\":\"block-cookies\"},\"trigger\":{\"url-filter\":\"https\", \"if-top-url\":[\"example\"]}}"
+    "]");
+    testRequest(otherRulesWithConditions, requestInTopAndFrameURLs("https://example.com/", "https://webkit.org/", "https://whatwg.org/"), { variantIndex<BlockLoadAction> });
+    testRequest(otherRulesWithConditions, requestInTopAndFrameURLs("https://example.com/", "https://example.com/", "https://webkit.org/"), { variantIndex<BlockCookiesAction> });
+    testRequest(otherRulesWithConditions, requestInTopAndFrameURLs("https://example.com/", "https://example.com/", "https://whatwg.org/"), { variantIndex<BlockCookiesAction>, variantIndex<BlockLoadAction> });
+    
+    auto matchingEverything = makeBackend("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"https\", \"if-frame-url\":[\".*\"]}}]");
+    testRequest(matchingEverything, requestInTopAndFrameURLs("https://example.com/", "https://webkit.org/", "https://whatwg.org/"), { variantIndex<BlockLoadAction> });
+    testRequest(matchingEverything, requestInTopAndFrameURLs("http://example.com/", "https://webkit.org/", "https://webkit.org/"), { });
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(CONTENT_EXTENSIONS)
</span></span></pre>
</div>
</div>

</body>
</html>