[Content Extensions] Introduce if-top-url and unless-top-url
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Mar 2017 22:17:13 +0000 (22:17 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Mar 2017 22:17:13 +0000 (22:17 +0000)
commitad0834e2aaefa8131c2906e836732dfd53cecfae
treee63c4ff10559a49b42030ede7d86a90d4aadc518
parent35bae7c4e563f39c10759e44275c1d66161ff8a1
[Content Extensions] Introduce if-top-url and unless-top-url
https://bugs.webkit.org/show_bug.cgi?id=169433

Reviewed by Brady Eidson.

Source/WebCore:

In r184116 I added if-domain and unless-domain to control whether a rule applies
based on the domain of the main document URL.  I'm expanding this by adding if-top-url
and unless-top-url that run regular expressions on the entire main document URL so that
example.com/user1content can be distinguished from example.com/user2content.
To not add to the number of passes we make on the URLs for each load and to maintain JSON
backwards compatibility, I've made it so that if-top-url and unless-top-url can be used
instead of if-domain and unless-domain (which continue to work) but the two condition types
cannot be used together since running regular expressions on the entire main document URL
is strictly more powerful than checking the domain and subdomains.
As a minor detail, content extension regexes are by default ASCII-case-insensitive, so I've
done the same with top URL regexes, adding top-url-filter-is-case-sensitive to mirror the existing
url-filter-is-case-sensitive if the JSON author decides to make regexes case sensitive.

Covered by new API tests.

* contentextensions/CompiledContentExtension.h:
* contentextensions/ContentExtension.cpp:
(WebCore::ContentExtensions::ContentExtension::populateConditionCacheIfNeeded):
(WebCore::ContentExtensions::ContentExtension::topURLActions):
(WebCore::ContentExtensions::ContentExtension::cachedConditionedActions): Deleted.
* contentextensions/ContentExtension.h:
* contentextensions/ContentExtensionCompiler.cpp:
(WebCore::ContentExtensions::addUniversalActionsToDFA):
(WebCore::ContentExtensions::compileToBytecode):
We had three copies of compiling to bytecode that were almost the same and would've been made into three copies of the same code.
I moved them to one helper function that is called three times.
(WebCore::ContentExtensions::compileRuleList):
* contentextensions/ContentExtensionCompiler.h:
* contentextensions/ContentExtensionError.cpp:
(WebCore::ContentExtensions::contentExtensionErrorCategory):
Add the new error type for JSON that tries to use if-top-url and unless-top-url with if-domain and unless-domain.
* contentextensions/ContentExtensionError.h:
* contentextensions/ContentExtensionParser.cpp:
(WebCore::ContentExtensions::loadTrigger):
Parse the new values if-top-url, unless-top-url, and top-url-filter-is-case-sensitive.
* contentextensions/ContentExtensionRule.h:
(WebCore::ContentExtensions::Trigger::~Trigger):
* contentextensions/ContentExtensionsBackend.cpp:
(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad):
* contentextensions/DFABytecodeInterpreter.cpp:
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretWithConditions):
* contentextensions/DFABytecodeInterpreter.h:

Source/WebKit2:

Rename conditionedFilters to topURLFilters to reflect the fact that they are the filters
that are run on the top URL, and possibly just the domain of the top url.
I was a bit too aggressive when renaming domain* to condition* in r213533.

* Shared/WebCompiledContentExtension.cpp:
(WebKit::WebCompiledContentExtension::conditionsApplyOnlyToDomain):
(WebKit::WebCompiledContentExtension::topURLFiltersBytecode):
(WebKit::WebCompiledContentExtension::topURLFiltersBytecodeLength):
(WebKit::WebCompiledContentExtension::conditionedFiltersBytecode): Deleted.
(WebKit::WebCompiledContentExtension::conditionedFiltersBytecodeLength): Deleted.
* Shared/WebCompiledContentExtension.h:
* Shared/WebCompiledContentExtensionData.cpp:
(WebKit::WebCompiledContentExtensionData::encode):
(WebKit::WebCompiledContentExtensionData::decode):
* Shared/WebCompiledContentExtensionData.h:
(WebKit::WebCompiledContentExtensionData::WebCompiledContentExtensionData):
* UIProcess/API/APIUserContentExtensionStore.cpp:
(API::encodeContentExtensionMetaData):
(API::decodeContentExtensionMetaData):
(API::compiledToFile):
(API::createExtension):
(API::UserContentExtensionStore::invalidateContentExtensionVersion):
(API::userContentExtensionStoreErrorCategory):
* UIProcess/API/APIUserContentExtensionStore.h:
Increment CurrentContentExtensionFileVersion because we have changed the format of the binary on disk.
We only added 4 bytes, but that's binary incompatible and requires re-compiling any existing content extensions.

Tools:

* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::TEST_F):
Add tests for new functionality and new failure types.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213669 268f45cc-cd09-0410-ab3c-d52691b4dbfc
22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/contentextensions/CompiledContentExtension.h
Source/WebCore/contentextensions/ContentExtension.cpp
Source/WebCore/contentextensions/ContentExtension.h
Source/WebCore/contentextensions/ContentExtensionCompiler.cpp
Source/WebCore/contentextensions/ContentExtensionCompiler.h
Source/WebCore/contentextensions/ContentExtensionError.cpp
Source/WebCore/contentextensions/ContentExtensionError.h
Source/WebCore/contentextensions/ContentExtensionParser.cpp
Source/WebCore/contentextensions/ContentExtensionRule.h
Source/WebCore/contentextensions/ContentExtensionsBackend.cpp
Source/WebCore/contentextensions/DFABytecodeInterpreter.cpp
Source/WebCore/contentextensions/DFABytecodeInterpreter.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCompiledContentExtension.cpp
Source/WebKit2/Shared/WebCompiledContentExtension.h
Source/WebKit2/Shared/WebCompiledContentExtensionData.cpp
Source/WebKit2/Shared/WebCompiledContentExtensionData.h
Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp
Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp