Make WebCompiledContentRuleListData non-default-constructible, move its nonserialized...
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 22:10:03 +0000 (22:10 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 22:10:03 +0000 (22:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197033

Reviewed by Tim Horton.

This is just cleanup that makes the code nicer without changing behavior.

* Shared/WebCompiledContentRuleListData.cpp:
(WebKit::WebCompiledContentRuleListData::encode const):
(WebKit::WebCompiledContentRuleListData::decode):
* Shared/WebCompiledContentRuleListData.h:
(WebKit::WebCompiledContentRuleListData::WebCompiledContentRuleListData):
* UIProcess/API/APIContentRuleList.h:
* UIProcess/API/APIContentRuleListStore.cpp:
(API::createExtension):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244403 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCompiledContentRuleListData.cpp
Source/WebKit/Shared/WebCompiledContentRuleListData.h
Source/WebKit/UIProcess/API/APIContentRuleList.cpp
Source/WebKit/UIProcess/API/APIContentRuleList.h
Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp

index 6866547..2532a72 100644 (file)
@@ -1,3 +1,21 @@
+2019-04-17  Alex Christensen  <achristensen@webkit.org>
+
+        Make WebCompiledContentRuleListData non-default-constructible, move its nonserialized member to API::ContentRuleList
+        https://bugs.webkit.org/show_bug.cgi?id=197033
+
+        Reviewed by Tim Horton.
+
+        This is just cleanup that makes the code nicer without changing behavior.
+
+        * Shared/WebCompiledContentRuleListData.cpp:
+        (WebKit::WebCompiledContentRuleListData::encode const):
+        (WebKit::WebCompiledContentRuleListData::decode):
+        * Shared/WebCompiledContentRuleListData.h:
+        (WebKit::WebCompiledContentRuleListData::WebCompiledContentRuleListData):
+        * UIProcess/API/APIContentRuleList.h:
+        * UIProcess/API/APIContentRuleListStore.cpp:
+        (API::createExtension):
+
 2019-04-17  John Wilander  <wilander@apple.com>
 
         Add prioritization of ad click conversions and cleaning of sent ad click conversions
index 650b924..bb67f14 100644 (file)
@@ -60,9 +60,6 @@ void WebCompiledContentRuleListData::encode(IPC::Encoder& encoder) const
         encoder << IPC::SharedBufferDataReference { *WTF::get<RefPtr<WebCore::SharedBuffer>>(data) };
     }
 
-    // fileData needs to be kept in the UIProcess, but it does not need to be serialized.
-    // FIXME: Move it to API::ContentRuleList
-
     encoder << conditionsApplyOnlyToDomainOffset;
     encoder << actionsOffset;
     encoder << actionsSize;
@@ -76,44 +73,82 @@ void WebCompiledContentRuleListData::encode(IPC::Encoder& encoder) const
 
 Optional<WebCompiledContentRuleListData> WebCompiledContentRuleListData::decode(IPC::Decoder& decoder)
 {
-    WebCompiledContentRuleListData compiledContentRuleListData;
+    Variant<RefPtr<SharedMemory>, RefPtr<WebCore::SharedBuffer>> data;
 
     Optional<bool> hasSharedMemory;
     decoder >> hasSharedMemory;
     if (!hasSharedMemory)
         return WTF::nullopt;
+
     if (*hasSharedMemory) {
         SharedMemory::Handle handle;
         if (!decoder.decode(handle))
             return WTF::nullopt;
-        compiledContentRuleListData.data = { SharedMemory::map(handle, SharedMemory::Protection::ReadOnly) };
+        data = { SharedMemory::map(handle, SharedMemory::Protection::ReadOnly) };
     } else {
         IPC::DataReference dataReference;
         if (!decoder.decode(dataReference))
             return WTF::nullopt;
-        compiledContentRuleListData.data = { RefPtr<WebCore::SharedBuffer>(WebCore::SharedBuffer::create(dataReference.data(), dataReference.size())) };
+        data = { RefPtr<WebCore::SharedBuffer>(WebCore::SharedBuffer::create(dataReference.data(), dataReference.size())) };
     }
 
-    if (!decoder.decode(compiledContentRuleListData.conditionsApplyOnlyToDomainOffset))
+    Optional<unsigned> conditionsApplyOnlyToDomainOffset;
+    decoder >> conditionsApplyOnlyToDomainOffset;
+    if (!conditionsApplyOnlyToDomainOffset)
         return WTF::nullopt;
-    if (!decoder.decode(compiledContentRuleListData.actionsOffset))
+
+    Optional<unsigned> actionsOffset;
+    decoder >> actionsOffset;
+    if (!actionsOffset)
         return WTF::nullopt;
-    if (!decoder.decode(compiledContentRuleListData.actionsSize))
+
+    Optional<unsigned> actionsSize;
+    decoder >> actionsSize;
+    if (!actionsSize)
         return WTF::nullopt;
-    if (!decoder.decode(compiledContentRuleListData.filtersWithoutConditionsBytecodeOffset))
+
+    Optional<unsigned> filtersWithoutConditionsBytecodeOffset;
+    decoder >> filtersWithoutConditionsBytecodeOffset;
+    if (!filtersWithoutConditionsBytecodeOffset)
         return WTF::nullopt;
-    if (!decoder.decode(compiledContentRuleListData.filtersWithoutConditionsBytecodeSize))
+
+    Optional<unsigned> filtersWithoutConditionsBytecodeSize;
+    decoder >> filtersWithoutConditionsBytecodeSize;
+    if (!filtersWithoutConditionsBytecodeSize)
         return WTF::nullopt;
-    if (!decoder.decode(compiledContentRuleListData.filtersWithConditionsBytecodeOffset))
+
+    Optional<unsigned> filtersWithConditionsBytecodeOffset;
+    decoder >> filtersWithConditionsBytecodeOffset;
+    if (!filtersWithConditionsBytecodeOffset)
         return WTF::nullopt;
-    if (!decoder.decode(compiledContentRuleListData.filtersWithConditionsBytecodeSize))
+
+    Optional<unsigned> filtersWithConditionsBytecodeSize;
+    decoder >> filtersWithConditionsBytecodeSize;
+    if (!filtersWithConditionsBytecodeSize)
         return WTF::nullopt;
-    if (!decoder.decode(compiledContentRuleListData.topURLFiltersBytecodeOffset))
+
+    Optional<unsigned> topURLFiltersBytecodeOffset;
+    decoder >> topURLFiltersBytecodeOffset;
+    if (!topURLFiltersBytecodeOffset)
         return WTF::nullopt;
-    if (!decoder.decode(compiledContentRuleListData.topURLFiltersBytecodeSize))
+
+    Optional<unsigned> topURLFiltersBytecodeSize;
+    decoder >> topURLFiltersBytecodeSize;
+    if (!topURLFiltersBytecodeSize)
         return WTF::nullopt;
 
-    return compiledContentRuleListData;
+    return {{
+        WTFMove(data),
+        WTFMove(*conditionsApplyOnlyToDomainOffset),
+        WTFMove(*actionsOffset),
+        WTFMove(*actionsSize),
+        WTFMove(*filtersWithoutConditionsBytecodeOffset),
+        WTFMove(*filtersWithoutConditionsBytecodeSize),
+        WTFMove(*filtersWithConditionsBytecodeOffset),
+        WTFMove(*filtersWithConditionsBytecodeSize),
+        WTFMove(*topURLFiltersBytecodeOffset),
+        WTFMove(*topURLFiltersBytecodeSize)
+    }};
 }
 
 } // namespace WebKit
index 10b435b..fe5c974 100644 (file)
@@ -27,7 +27,6 @@
 
 #if ENABLE(CONTENT_EXTENSIONS)
 
-#include "NetworkCacheData.h"
 #include "SharedMemory.h"
 #include <WebCore/SharedBuffer.h>
 #include <wtf/RefPtr.h>
@@ -42,11 +41,8 @@ namespace WebKit {
 
 class WebCompiledContentRuleListData {
 public:
-    WebCompiledContentRuleListData() = default;
-
-    WebCompiledContentRuleListData(Variant<RefPtr<SharedMemory>, RefPtr<WebCore::SharedBuffer>>&& data, NetworkCache::Data fileData, unsigned conditionsApplyOnlyToDomainOffset, unsigned actionsOffset, unsigned actionsSize, unsigned filtersWithoutConditionsBytecodeOffset, unsigned filtersWithoutConditionsBytecodeSize, unsigned filtersWithConditionsBytecodeOffset, unsigned filtersWithConditionsBytecodeSize, unsigned topURLFiltersBytecodeOffset, unsigned topURLFiltersBytecodeSize)
+    WebCompiledContentRuleListData(Variant<RefPtr<SharedMemory>, RefPtr<WebCore::SharedBuffer>>&& data, unsigned conditionsApplyOnlyToDomainOffset, unsigned actionsOffset, unsigned actionsSize, unsigned filtersWithoutConditionsBytecodeOffset, unsigned filtersWithoutConditionsBytecodeSize, unsigned filtersWithConditionsBytecodeOffset, unsigned filtersWithConditionsBytecodeSize, unsigned topURLFiltersBytecodeOffset, unsigned topURLFiltersBytecodeSize)
         : data(WTFMove(data))
-        , fileData(fileData)
         , conditionsApplyOnlyToDomainOffset(conditionsApplyOnlyToDomainOffset)
         , actionsOffset(actionsOffset)
         , actionsSize(actionsSize)
@@ -66,7 +62,6 @@ public:
     const void* dataPointer() const;
     
     Variant<RefPtr<SharedMemory>, RefPtr<WebCore::SharedBuffer>> data;
-    NetworkCache::Data fileData;
     unsigned conditionsApplyOnlyToDomainOffset { 0 };
     unsigned actionsOffset { 0 };
     unsigned actionsSize { 0 };
index 17ade0f..df77ffa 100644 (file)
 
 namespace API {
 
-ContentRuleList::ContentRuleList(const WTF::String& name, Ref<WebKit::WebCompiledContentRuleList>&& contentRuleList)
+ContentRuleList::ContentRuleList(const WTF::String& name, Ref<WebKit::WebCompiledContentRuleList>&& contentRuleList, WebKit::NetworkCache::Data&& mappedFile)
     : m_name(name)
     , m_compiledRuleList(WTFMove(contentRuleList))
+    , m_mappedFile(WTFMove(mappedFile))
 {
 }
 
index 32bc493..2e285d5 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "APIObject.h"
+#include "NetworkCacheData.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebKit {
@@ -37,12 +38,12 @@ namespace API {
 class ContentRuleList final : public ObjectImpl<Object::Type::ContentRuleList> {
 public:
 #if ENABLE(CONTENT_EXTENSIONS)
-    static Ref<ContentRuleList> create(const WTF::String& name, Ref<WebKit::WebCompiledContentRuleList>&& contentRuleList)
+    static Ref<ContentRuleList> create(const WTF::String& name, Ref<WebKit::WebCompiledContentRuleList>&& contentRuleList, WebKit::NetworkCache::Data&& mappedFile)
     {
-        return adoptRef(*new ContentRuleList(name, WTFMove(contentRuleList)));
+        return adoptRef(*new ContentRuleList(name, WTFMove(contentRuleList), WTFMove(mappedFile)));
     }
 
-    ContentRuleList(const WTF::String& name, Ref<WebKit::WebCompiledContentRuleList>&&);
+    ContentRuleList(const WTF::String& name, Ref<WebKit::WebCompiledContentRuleList>&&, WebKit::NetworkCache::Data&&);
     virtual ~ContentRuleList();
 
     const WTF::String& name() const { return m_name; }
@@ -53,6 +54,7 @@ public:
 private:
     WTF::String m_name;
     Ref<WebKit::WebCompiledContentRuleList> m_compiledRuleList;
+    WebKit::NetworkCache::Data m_mappedFile;
 #endif // ENABLE(CONTENT_EXTENSIONS)
 };
 
index 6e8c641..a4e1598 100644 (file)
@@ -439,7 +439,6 @@ static Ref<API::ContentRuleList> createExtension(const WTF::String& identifier,
     const size_t headerAndSourceSize = ContentRuleListFileHeaderSize + data.metaData.sourceSize;
     auto compiledContentRuleListData = WebKit::WebCompiledContentRuleListData(
         WTFMove(mappedOrCopiedFileData),
-        WTF::holds_alternative<WebKit::NetworkCache::Data>(data.data) ? WTF::get<WebKit::NetworkCache::Data>(data.data) : WebKit::NetworkCache::Data { },
         ConditionsApplyOnlyToDomainOffset,
         headerAndSourceSize,
         data.metaData.actionsSize,
@@ -457,7 +456,7 @@ static Ref<API::ContentRuleList> createExtension(const WTF::String& identifier,
         data.metaData.conditionedFiltersBytecodeSize
     );
     auto compiledContentRuleList = WebKit::WebCompiledContentRuleList::create(WTFMove(compiledContentRuleListData));
-    return API::ContentRuleList::create(identifier, WTFMove(compiledContentRuleList));
+    return API::ContentRuleList::create(identifier, WTFMove(compiledContentRuleList), WTF::holds_alternative<WebKit::NetworkCache::Data>(data.data) ? WTF::get<WebKit::NetworkCache::Data>(data.data) : WebKit::NetworkCache::Data { });
 }
 
 void ContentRuleListStore::lookupContentRuleList(const WTF::String& identifier, CompletionHandler<void(RefPtr<API::ContentRuleList>, std::error_code)> completionHandler)