Ignore:
Timestamp:
Dec 1, 2021, 1:31:04 PM (3 years ago)
Author:
[email protected]
Message:

Add csp-report resource type to WKContentRuleList
https://bugs.webkit.org/show_bug.cgi?id=233675
<rdar://71869893>

Reviewed by Tim Hatcher.

Source/WebCore:

This feature is trivial to implement and test except for one small thing: we use a uint16_t to represent the
resource type and context and first party flags, and we already have 16 of them. So we needed to get another
bit from somewhere. What I did was make the flags have a variable length from 1-3 bytes instead of just 2 bytes.
I used the unused upper bits in the instruction to indicate the length of the flags, and if the upper bits were 0,
then I assume it was 2 bytes, which is binary compatible with existing compiled WKContentRuleLists, so no need
to increment the version number and force a recompile. It worked so well that I did the same thing with the actions,
which were 4 bytes but are now 1-4 bytes. This reduced the compiled binary size of one of the tests from 313 bytes
to 288 bytes, a reduction of about 8% of the binary size of the compiled WKContentRuleLists. Larger lists will see
slightly less binary size reduction, but still an improvement.

  • contentextensions/ContentExtension.cpp:

(WebCore::ContentExtensions::ContentExtension::ContentExtension):
(WebCore::ContentExtensions::ContentExtension::populateConditionCacheIfNeeded):

  • contentextensions/ContentExtensionsBackend.cpp:

(WebCore::ContentExtensions::ContentExtensionsBackend::actionsForResourceLoad const):

  • contentextensions/DFABytecode.h:

(WebCore::ContentExtensions::smallestPossibleJumpSize):
(): Deleted.
(WebCore::ContentExtensions::instructionSizeWithArguments): Deleted.

  • contentextensions/DFABytecodeCompiler.cpp:

(WebCore::ContentExtensions::append):
(WebCore::ContentExtensions::append24BitInteger):
(WebCore::ContentExtensions::appendZeroes):
(WebCore::ContentExtensions::setBits):
(WebCore::ContentExtensions::bytecodeFlagsSize):
(WebCore::ContentExtensions::bytecodeActionSize):
(WebCore::ContentExtensions::appendVariableLengthInteger):
(WebCore::ContentExtensions::DFABytecodeCompiler::emitAppendAction):
(WebCore::ContentExtensions::DFABytecodeCompiler::emitJump):
(WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValue):
(WebCore::ContentExtensions::DFABytecodeCompiler::emitCheckValueRange):
(WebCore::ContentExtensions::DFABytecodeCompiler::transitions):
(WebCore::ContentExtensions::DFABytecodeCompiler::compileJumpTable):
(WebCore::ContentExtensions::DFABytecodeCompiler::nodeTransitionsMaxBytecodeSize):
(WebCore::ContentExtensions::DFABytecodeCompiler::compile):

  • contentextensions/DFABytecodeInterpreter.cpp:

(WebCore::ContentExtensions::getBits):
(WebCore::ContentExtensions::get24Bits):
(WebCore::ContentExtensions::getInstruction):
(WebCore::ContentExtensions::jumpSizeInBytes):
(WebCore::ContentExtensions::consumeInteger):
(WebCore::ContentExtensions::consume24BitInteger):
(WebCore::ContentExtensions::hasFlags):
(WebCore::ContentExtensions::hasAction):
(WebCore::ContentExtensions::consumeResourceFlagsAndInstruction):
(WebCore::ContentExtensions::consumeAction):
(WebCore::ContentExtensions::getJumpSize):
(WebCore::ContentExtensions::getJumpDistance):
(WebCore::ContentExtensions::matchesCondition):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretTestFlagsAndAppendAction):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpetJumpTable):
(WebCore::ContentExtensions::DFABytecodeInterpreter::actionsMatchingEverything):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpretWithConditions):
(WebCore::ContentExtensions::DFABytecodeInterpreter::interpret):

  • contentextensions/DFABytecodeInterpreter.h:

(WebCore::ContentExtensions::DFABytecodeInterpreter::DFABytecodeInterpreter):

  • loader/PingLoader.cpp:

(WebCore::PingLoader::sendViolationReport):

  • loader/ResourceLoadInfo.cpp:

(WebCore::ContentExtensions::readResourceType):

  • loader/ResourceLoadInfo.h:

Tools:

  • TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:

(TestWebKitAPI::compareContents):
(TestWebKitAPI::TEST_F):

  • TestWebKitAPI/Tests/WebKitCocoa/ContentRuleListNotification.mm:

(TEST):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/loader/PingLoader.cpp

    r282860 r286383  
    160160    ResourceRequest request(reportURL);
    161161#if ENABLE(CONTENT_EXTENSIONS)
    162     if (processContentRuleListsForLoad(frame, request, ContentExtensions::ResourceType::Other))
     162    if (processContentRuleListsForLoad(frame, request, ContentExtensions::ResourceType::CSPReport))
    163163        return;
    164164#endif
Note: See TracChangeset for help on using the changeset viewer.