Diff
Modified: branches/safari-607-branch/Source/WebKit/ChangeLog (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/ChangeLog 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/ChangeLog 2019-03-13 08:24:51 UTC (rev 242860)
@@ -1,5 +1,141 @@
2019-03-13 Babak Shafiei <[email protected]>
+ Cherry-pick r242735. rdar://problem/48780112
+
+ Add a WKContentRuleList variant that uses copied memory instead of mmap'd shared memory for class A containerized apps
+ https://bugs.webkit.org/show_bug.cgi?id=195511
+ <rdar://problem/44873269>
+
+ Patch by Alex Christensen <[email protected]> on 2019-03-11
+ Reviewed by Darin Adler.
+
+ Source/WebKit:
+
+ * NetworkProcess/NetworkContentRuleListManager.cpp:
+ (WebKit::NetworkContentRuleListManager::addContentRuleLists):
+ * NetworkProcess/NetworkContentRuleListManager.h:
+ * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
+ (WebKit::NetworkCache::pathRegisteredAsUnsafeToMemoryMapForTesting):
+ (WebKit::NetworkCache::registerPathAsUnsafeToMemoryMapForTesting):
+ (WebKit::NetworkCache::isSafeToUseMemoryMapForPath):
+ * NetworkProcess/cache/NetworkCacheFileSystem.h:
+ * Shared/WebCompiledContentRuleList.cpp:
+ (WebKit::WebCompiledContentRuleList::usesCopiedMemory const):
+ (WebKit::WebCompiledContentRuleList::conditionsApplyOnlyToDomain const):
+ (WebKit::WebCompiledContentRuleList::filtersWithoutConditionsBytecode const):
+ (WebKit::WebCompiledContentRuleList::filtersWithConditionsBytecode const):
+ (WebKit::WebCompiledContentRuleList::topURLFiltersBytecode const):
+ (WebKit::WebCompiledContentRuleList::actions const):
+ * Shared/WebCompiledContentRuleList.h:
+ * Shared/WebCompiledContentRuleListData.cpp:
+ (WebKit::WebCompiledContentRuleListData::size const):
+ (WebKit::WebCompiledContentRuleListData::dataPointer const):
+ (WebKit::WebCompiledContentRuleListData::encode const):
+ (WebKit::WebCompiledContentRuleListData::decode):
+ * Shared/WebCompiledContentRuleListData.h:
+ (WebKit::WebCompiledContentRuleListData::WebCompiledContentRuleListData):
+ * UIProcess/API/APIContentRuleList.cpp:
+ (API::ContentRuleList::usesCopiedMemory const):
+ * UIProcess/API/APIContentRuleList.h:
+ * UIProcess/API/APIContentRuleListStore.cpp:
+ (API::getData):
+ (API::decodeContentRuleListMetaData):
+ (API::ContentRuleListStore::readContentsOfFile):
+ (API::MappedOrCopiedData::dataPointer const):
+ (API::openAndMapOrCopyContentRuleList):
+ (API::compiledToFile):
+ (API::createExtension):
+ (API::ContentRuleListStore::lookupContentRuleList):
+ (API::ContentRuleListStore::compileContentRuleList):
+ (API::ContentRuleListStore::getContentRuleListSource):
+ (API::openAndMapContentRuleList): Deleted.
+ * UIProcess/API/APIContentRuleListStore.h:
+ * UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm:
+ (API::ContentRuleListStore::readContentsOfFile):
+ * UIProcess/API/Cocoa/WKContentRuleListStore.mm:
+ (+[WKContentRuleListStore _registerPathAsUnsafeToMemoryMapForTesting:]):
+ * UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h:
+ * UIProcess/API/Cocoa/_WKUserContentFilter.mm:
+ (-[_WKUserContentFilter usesCopiedMemory]):
+ * UIProcess/API/Cocoa/_WKUserContentFilterPrivate.h:
+ * WebProcess/UserContent/WebUserContentController.cpp:
+ (WebKit::WebUserContentController::addContentRuleLists):
+ * WebProcess/UserContent/WebUserContentController.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::m_hostFileDescriptor):
+
+ Tools:
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm:
+ (-[TestSchemeHandlerSubresourceShouldBeBlocked webView:startURLSchemeTask:]):
+ (-[TestSchemeHandlerSubresourceShouldBeBlocked webView:stopURLSchemeTask:]):
+ (TEST_F):
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242735 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-03-11 Alex Christensen <[email protected]>
+
+ Add a WKContentRuleList variant that uses copied memory instead of mmap'd shared memory for class A containerized apps
+ https://bugs.webkit.org/show_bug.cgi?id=195511
+ <rdar://problem/44873269>
+
+ Reviewed by Darin Adler.
+
+ * NetworkProcess/NetworkContentRuleListManager.cpp:
+ (WebKit::NetworkContentRuleListManager::addContentRuleLists):
+ * NetworkProcess/NetworkContentRuleListManager.h:
+ * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
+ (WebKit::NetworkCache::pathRegisteredAsUnsafeToMemoryMapForTesting):
+ (WebKit::NetworkCache::registerPathAsUnsafeToMemoryMapForTesting):
+ (WebKit::NetworkCache::isSafeToUseMemoryMapForPath):
+ * NetworkProcess/cache/NetworkCacheFileSystem.h:
+ * Shared/WebCompiledContentRuleList.cpp:
+ (WebKit::WebCompiledContentRuleList::usesCopiedMemory const):
+ (WebKit::WebCompiledContentRuleList::conditionsApplyOnlyToDomain const):
+ (WebKit::WebCompiledContentRuleList::filtersWithoutConditionsBytecode const):
+ (WebKit::WebCompiledContentRuleList::filtersWithConditionsBytecode const):
+ (WebKit::WebCompiledContentRuleList::topURLFiltersBytecode const):
+ (WebKit::WebCompiledContentRuleList::actions const):
+ * Shared/WebCompiledContentRuleList.h:
+ * Shared/WebCompiledContentRuleListData.cpp:
+ (WebKit::WebCompiledContentRuleListData::size const):
+ (WebKit::WebCompiledContentRuleListData::dataPointer const):
+ (WebKit::WebCompiledContentRuleListData::encode const):
+ (WebKit::WebCompiledContentRuleListData::decode):
+ * Shared/WebCompiledContentRuleListData.h:
+ (WebKit::WebCompiledContentRuleListData::WebCompiledContentRuleListData):
+ * UIProcess/API/APIContentRuleList.cpp:
+ (API::ContentRuleList::usesCopiedMemory const):
+ * UIProcess/API/APIContentRuleList.h:
+ * UIProcess/API/APIContentRuleListStore.cpp:
+ (API::getData):
+ (API::decodeContentRuleListMetaData):
+ (API::ContentRuleListStore::readContentsOfFile):
+ (API::MappedOrCopiedData::dataPointer const):
+ (API::openAndMapOrCopyContentRuleList):
+ (API::compiledToFile):
+ (API::createExtension):
+ (API::ContentRuleListStore::lookupContentRuleList):
+ (API::ContentRuleListStore::compileContentRuleList):
+ (API::ContentRuleListStore::getContentRuleListSource):
+ (API::openAndMapContentRuleList): Deleted.
+ * UIProcess/API/APIContentRuleListStore.h:
+ * UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm:
+ (API::ContentRuleListStore::readContentsOfFile):
+ * UIProcess/API/Cocoa/WKContentRuleListStore.mm:
+ (+[WKContentRuleListStore _registerPathAsUnsafeToMemoryMapForTesting:]):
+ * UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h:
+ * UIProcess/API/Cocoa/_WKUserContentFilter.mm:
+ (-[_WKUserContentFilter usesCopiedMemory]):
+ * UIProcess/API/Cocoa/_WKUserContentFilterPrivate.h:
+ * WebProcess/UserContent/WebUserContentController.cpp:
+ (WebKit::WebUserContentController::addContentRuleLists):
+ * WebProcess/UserContent/WebUserContentController.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::m_hostFileDescriptor):
+
+2019-03-13 Babak Shafiei <[email protected]>
+
Cherry-pick r242587. rdar://problem/48839354
Crash when attempting to change input type while dismissing datalist suggestions
Modified: branches/safari-607-branch/Source/WebKit/NetworkProcess/NetworkContentRuleListManager.cpp (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/NetworkProcess/NetworkContentRuleListManager.cpp 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/NetworkProcess/NetworkContentRuleListManager.cpp 2019-03-13 08:24:51 UTC (rev 242860)
@@ -62,15 +62,14 @@
NetworkProcess::singleton().parentProcessConnection()->send(Messages::NetworkProcessProxy::ContentExtensionRules { identifier }, 0);
}
-void NetworkContentRuleListManager::addContentRuleLists(UserContentControllerIdentifier identifier, const Vector<std::pair<String, WebCompiledContentRuleListData>>& contentRuleLists)
+void NetworkContentRuleListManager::addContentRuleLists(UserContentControllerIdentifier identifier, Vector<std::pair<String, WebCompiledContentRuleListData>>&& contentRuleLists)
{
auto& backend = *m_contentExtensionBackends.ensure(identifier, [] {
return std::make_unique<WebCore::ContentExtensions::ContentExtensionsBackend>();
}).iterator->value;
- for (const auto& contentRuleList : contentRuleLists) {
- WebCompiledContentRuleListData contentRuleListData = contentRuleList.second;
- auto compiledContentRuleList = WebCompiledContentRuleList::create(WTFMove(contentRuleListData));
+ for (auto&& contentRuleList : contentRuleLists) {
+ auto compiledContentRuleList = WebCompiledContentRuleList::create(WTFMove(contentRuleList.second));
backend.addContentExtension(contentRuleList.first, WTFMove(compiledContentRuleList), ContentExtensions::ContentExtension::ShouldCompileCSS::No);
}
Modified: branches/safari-607-branch/Source/WebKit/NetworkProcess/NetworkContentRuleListManager.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/NetworkProcess/NetworkContentRuleListManager.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/NetworkProcess/NetworkContentRuleListManager.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -49,7 +49,7 @@
void contentExtensionsBackend(UserContentControllerIdentifier, BackendCallback&&);
private:
- void addContentRuleLists(UserContentControllerIdentifier, const Vector<std::pair<String, WebCompiledContentRuleListData>>&);
+ void addContentRuleLists(UserContentControllerIdentifier, Vector<std::pair<String, WebCompiledContentRuleListData>>&&);
void removeContentRuleList(UserContentControllerIdentifier, const String& name);
void removeAllContentRuleLists(UserContentControllerIdentifier);
void remove(UserContentControllerIdentifier);
Modified: branches/safari-607-branch/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp 2019-03-13 08:24:51 UTC (rev 242860)
@@ -145,8 +145,23 @@
#endif
}
+static String& pathRegisteredAsUnsafeToMemoryMapForTesting()
+{
+ static NeverDestroyed<String> path;
+ return path.get();
+}
+
+void registerPathAsUnsafeToMemoryMapForTesting(const String& path)
+{
+ pathRegisteredAsUnsafeToMemoryMapForTesting() = path;
+}
+
+
bool isSafeToUseMemoryMapForPath(const String& path)
{
+ if (path == pathRegisteredAsUnsafeToMemoryMapForTesting())
+ return false;
+
#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
struct {
uint32_t length;
Modified: branches/safari-607-branch/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -43,6 +43,7 @@
void updateFileModificationTimeIfNeeded(const String& path);
bool isSafeToUseMemoryMapForPath(const String& path);
+void registerPathAsUnsafeToMemoryMapForTesting(const String&);
}
}
Modified: branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleList.cpp (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleList.cpp 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleList.cpp 2019-03-13 08:24:51 UTC (rev 242860)
@@ -44,14 +44,19 @@
{
}
+bool WebCompiledContentRuleList::usesCopiedMemory() const
+{
+ return WTF::holds_alternative<RefPtr<WebCore::SharedBuffer>>(m_data.data);
+}
+
bool WebCompiledContentRuleList::conditionsApplyOnlyToDomain() const
{
- return *reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(m_data.data->data()) + m_data.conditionsApplyOnlyToDomainOffset);
+ return *reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(m_data.dataPointer()) + m_data.conditionsApplyOnlyToDomainOffset);
}
const WebCore::ContentExtensions::DFABytecode* WebCompiledContentRuleList::filtersWithoutConditionsBytecode() const
{
- return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.filtersWithoutConditionsBytecodeOffset;
+ return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.dataPointer()) + m_data.filtersWithoutConditionsBytecodeOffset;
}
unsigned WebCompiledContentRuleList::filtersWithoutConditionsBytecodeLength() const
@@ -61,7 +66,7 @@
const WebCore::ContentExtensions::DFABytecode* WebCompiledContentRuleList::filtersWithConditionsBytecode() const
{
- return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.filtersWithConditionsBytecodeOffset;
+ return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.dataPointer()) + m_data.filtersWithConditionsBytecodeOffset;
}
unsigned WebCompiledContentRuleList::filtersWithConditionsBytecodeLength() const
@@ -71,7 +76,7 @@
const WebCore::ContentExtensions::DFABytecode* WebCompiledContentRuleList::topURLFiltersBytecode() const
{
- return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.topURLFiltersBytecodeOffset;
+ return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.dataPointer()) + m_data.topURLFiltersBytecodeOffset;
}
unsigned WebCompiledContentRuleList::topURLFiltersBytecodeLength() const
@@ -81,7 +86,7 @@
const WebCore::ContentExtensions::SerializedActionByte* WebCompiledContentRuleList::actions() const
{
- return static_cast<const WebCore::ContentExtensions::SerializedActionByte*>(m_data.data->data()) + m_data.actionsOffset;
+ return static_cast<const WebCore::ContentExtensions::SerializedActionByte*>(m_data.dataPointer()) + m_data.actionsOffset;
}
unsigned WebCompiledContentRuleList::actionsLength() const
Modified: branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleList.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleList.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleList.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -38,8 +38,10 @@
static Ref<WebCompiledContentRuleList> create(WebCompiledContentRuleListData&&);
virtual ~WebCompiledContentRuleList();
- WebCompiledContentRuleListData data() const { return m_data; }
+ const WebCompiledContentRuleListData& data() const { return m_data; }
+ bool usesCopiedMemory() const;
+
private:
WebCompiledContentRuleList(WebCompiledContentRuleListData&&);
Modified: branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp 2019-03-13 08:24:51 UTC (rev 242860)
@@ -29,15 +29,39 @@
#if ENABLE(CONTENT_EXTENSIONS)
#include "ArgumentCoders.h"
+#include "SharedBufferDataReference.h"
namespace WebKit {
+size_t WebCompiledContentRuleListData::size() const
+{
+ return WTF::switchOn(data, [] (const auto& sharedMemoryOrBuffer) {
+ return sharedMemoryOrBuffer->size();
+ });
+}
+
+const void* WebCompiledContentRuleListData::dataPointer() const
+{
+ return WTF::switchOn(data, [] (const auto& sharedMemoryOrBuffer) -> const void* {
+ return sharedMemoryOrBuffer->data();
+ });
+}
+
void WebCompiledContentRuleListData::encode(IPC::Encoder& encoder) const
{
- SharedMemory::Handle handle;
- data->createHandle(handle, SharedMemory::Protection::ReadOnly);
- encoder << handle;
+ if (auto sharedMemory = WTF::get_if<RefPtr<SharedMemory>>(data)) {
+ encoder << true;
+ SharedMemory::Handle handle;
+ sharedMemory->get()->createHandle(handle, SharedMemory::Protection::ReadOnly);
+ encoder << handle;
+ } else {
+ encoder << false;
+ 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;
@@ -52,10 +76,22 @@
Optional<WebCompiledContentRuleListData> WebCompiledContentRuleListData::decode(IPC::Decoder& decoder)
{
WebCompiledContentRuleListData compiledContentRuleListData;
- SharedMemory::Handle handle;
- if (!decoder.decode(handle))
+
+ Optional<bool> hasSharedMemory;
+ decoder >> hasSharedMemory;
+ if (!hasSharedMemory)
return WTF::nullopt;
- compiledContentRuleListData.data = "" SharedMemory::Protection::ReadOnly);
+ if (*hasSharedMemory) {
+ SharedMemory::Handle handle;
+ if (!decoder.decode(handle))
+ return WTF::nullopt;
+ compiledContentRuleListData.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())) };
+ }
if (!decoder.decode(compiledContentRuleListData.conditionsApplyOnlyToDomainOffset))
return WTF::nullopt;
Modified: branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleListData.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleListData.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/Shared/WebCompiledContentRuleListData.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -29,7 +29,9 @@
#include "NetworkCacheData.h"
#include "SharedMemory.h"
+#include <WebCore/SharedBuffer.h>
#include <wtf/RefPtr.h>
+#include <wtf/Variant.h>
namespace IPC {
class Decoder;
@@ -42,7 +44,7 @@
public:
WebCompiledContentRuleListData() = default;
- WebCompiledContentRuleListData(RefPtr<SharedMemory>&& 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, NetworkCache::Data fileData, 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)
@@ -60,7 +62,10 @@
void encode(IPC::Encoder&) const;
static Optional<WebCompiledContentRuleListData> decode(IPC::Decoder&);
- RefPtr<SharedMemory> data;
+ size_t size() const;
+ const void* dataPointer() const;
+
+ Variant<RefPtr<SharedMemory>, RefPtr<WebCore::SharedBuffer>> data;
NetworkCache::Data fileData;
unsigned conditionsApplyOnlyToDomainOffset { 0 };
unsigned actionsOffset { 0 };
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleList.cpp (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleList.cpp 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleList.cpp 2019-03-13 08:24:51 UTC (rev 242860)
@@ -42,6 +42,11 @@
{
}
+bool ContentRuleList::usesCopiedMemory() const
+{
+ return m_compiledRuleList->usesCopiedMemory();
+}
+
} // namespace API
#endif // ENABLE(CONTENT_EXTENSIONS)
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleList.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleList.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleList.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -48,6 +48,8 @@
const WTF::String& name() const { return m_name; }
const WebKit::WebCompiledContentRuleList& compiledRuleList() const { return m_compiledRuleList.get(); }
+ bool usesCopiedMemory() const;
+
private:
WTF::String m_name;
Ref<WebKit::WebCompiledContentRuleList> m_compiledRuleList;
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp 2019-03-13 08:24:51 UTC (rev 242860)
@@ -37,6 +37,7 @@
#include <WebCore/ContentExtensionError.h>
#include <WebCore/ContentExtensionParser.h>
#include <WebCore/QualifiedName.h>
+#include <WebCore/SharedBuffer.h>
#include <string>
#include <wtf/CompletionHandler.h>
#include <wtf/NeverDestroyed.h>
@@ -155,10 +156,22 @@
return WebKit::NetworkCache::Data(encoder.buffer(), encoder.bufferSize());
}
-static bool decodeContentRuleListMetaData(ContentRuleListMetaData& metaData, const WebKit::NetworkCache::Data& fileData)
+template<typename T> void getData(const T&, const Function<bool(const uint8_t*, size_t)>&);
+template<> void getData(const WebKit::NetworkCache::Data& data, const Function<bool(const uint8_t*, size_t)>& function)
{
+ data.apply(function);
+}
+template<> void getData(const WebCore::SharedBuffer& data, const Function<bool(const uint8_t*, size_t)>& function)
+{
+ function(reinterpret_cast<const uint8_t*>(data.data()), data.size());
+}
+
+template<typename T>
+static Optional<ContentRuleListMetaData> decodeContentRuleListMetaData(const T& fileData)
+{
bool success = false;
- fileData.apply([&metaData, &success, &fileData](const uint8_t* data, size_t size) {
+ ContentRuleListMetaData metaData;
+ getData(fileData, [&metaData, &success, &fileData](const uint8_t* data, size_t size) {
// The file data should be mapped into one continuous memory segment so the size
// passed to the applier should always equal the data size.
if (size != fileData.size())
@@ -182,19 +195,52 @@
success = true;
return false;
});
- return success;
+ if (!success)
+ return WTF::nullopt;
+ return WTFMove(metaData);
}
-static bool openAndMapContentRuleList(const WTF::String& path, ContentRuleListMetaData& metaData, WebKit::NetworkCache::Data& fileData)
+#if !PLATFORM(COCOA)
+RefPtr<WebCore::SharedBuffer> ContentRuleListStore::readContentsOfFile(const WTF::String& filePath)
{
- fileData = mapFile(fileSystemRepresentation(path).data());
- if (fileData.isNull())
- return false;
+ ASSERT_NOT_REACHED();
+ return nullptr;
+}
+#endif
- if (!decodeContentRuleListMetaData(metaData, fileData))
- return false;
+struct MappedOrCopiedData {
+ ContentRuleListMetaData metaData;
+ Variant<WebKit::NetworkCache::Data, RefPtr<WebCore::SharedBuffer>> data;
+
+ const uint8_t* dataPointer() const
+ {
+ return WTF::switchOn(data, [] (const WebKit::NetworkCache::Data& data) {
+ return data.data();
+ }, [] (const RefPtr<WebCore::SharedBuffer>& sharedBuffer) {
+ return reinterpret_cast<const uint8_t*>(sharedBuffer->data());
+ });
+ }
+};
- return true;
+static Optional<MappedOrCopiedData> openAndMapOrCopyContentRuleList(const WTF::String& path)
+{
+ if (!WebKit::NetworkCache::isSafeToUseMemoryMapForPath(path)) {
+ RefPtr<WebCore::SharedBuffer> buffer = ContentRuleListStore::readContentsOfFile(path);
+ if (!buffer)
+ return WTF::nullopt;
+ auto metaData = decodeContentRuleListMetaData(*buffer);
+ if (!metaData)
+ return WTF::nullopt;
+ return {{ WTFMove(*metaData), { buffer.releaseNonNull() }}};
+ }
+
+ WebKit::NetworkCache::Data fileData = mapFile(fileSystemRepresentation(path).data());
+ if (fileData.isNull())
+ return WTF::nullopt;
+ auto metaData = decodeContentRuleListMetaData(fileData);
+ if (!metaData)
+ return WTF::nullopt;
+ return {{ WTFMove(*metaData), { WTFMove(fileData) }}};
}
static bool writeDataToFile(const WebKit::NetworkCache::Data& fileData, PlatformFileHandle fd)
@@ -211,7 +257,7 @@
return success;
}
-static std::error_code compiledToFile(WTF::String&& json, Vector<WebCore::ContentExtensions::ContentExtensionRule>&& parsedRules, const WTF::String& finalFilePath, ContentRuleListMetaData& metaData, WebKit::NetworkCache::Data& mappedData)
+static Expected<MappedOrCopiedData, std::error_code> compiledToFile(WTF::String&& json, Vector<WebCore::ContentExtensions::ContentExtensionRule>&& parsedRules, const WTF::String& finalFilePath)
{
using namespace WebCore::ContentExtensions;
@@ -328,7 +374,7 @@
WTF::String temporaryFilePath = openTemporaryFile("ContentRuleList", temporaryFileHandle);
if (temporaryFileHandle == invalidPlatformFileHandle) {
WTFLogAlways("Content Rule List compiling failed: Opening temporary file failed.");
- return ContentRuleListStore::Error::CompileFailed;
+ return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
}
char invalidHeader[ContentRuleListFileHeaderSize];
@@ -337,62 +383,77 @@
if (writeToFile(temporaryFileHandle, invalidHeader, sizeof(invalidHeader)) == -1) {
WTFLogAlways("Content Rule List compiling failed: Writing header to file failed.");
closeFile(temporaryFileHandle);
- return ContentRuleListStore::Error::CompileFailed;
+ return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
}
+ ContentRuleListMetaData metaData;
CompilationClient compilationClient(temporaryFileHandle, metaData);
if (auto compilerError = compileRuleList(compilationClient, WTFMove(json), WTFMove(parsedRules))) {
WTFLogAlways("Content Rule List compiling failed: Compiling failed.");
closeFile(temporaryFileHandle);
- return compilerError;
+ return makeUnexpected(compilerError);
}
if (compilationClient.hadErrorWhileWritingToFile()) {
WTFLogAlways("Content Rule List compiling failed: Writing to file failed.");
closeFile(temporaryFileHandle);
- return ContentRuleListStore::Error::CompileFailed;
+ return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
}
- mappedData = adoptAndMapFile(temporaryFileHandle, 0, metaData.fileSize());
+ auto mappedData = adoptAndMapFile(temporaryFileHandle, 0, metaData.fileSize());
if (mappedData.isNull()) {
WTFLogAlways("Content Rule List compiling failed: Mapping file failed.");
- return ContentRuleListStore::Error::CompileFailed;
+ return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
}
if (!moveFile(temporaryFilePath, finalFilePath)) {
WTFLogAlways("Content Rule List compiling failed: Moving file failed.");
- return ContentRuleListStore::Error::CompileFailed;
+ return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
}
- return { };
+ if (!isSafeToUseMemoryMapForPath(finalFilePath)) {
+ auto contents = ContentRuleListStore::readContentsOfFile(finalFilePath);
+ if (!contents)
+ return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
+ return {{ WTFMove(metaData), WTFMove(contents) }};
+ }
+
+ return {{ WTFMove(metaData), WTFMove(mappedData) }};
}
-static Ref<API::ContentRuleList> createExtension(const WTF::String& identifier, const ContentRuleListMetaData& metaData, const WebKit::NetworkCache::Data& fileData)
+static Ref<API::ContentRuleList> createExtension(const WTF::String& identifier, MappedOrCopiedData&& data)
{
- // Content extensions are always compiled to files, and at this point the file
- // has been already mapped, therefore tryCreateSharedMemory() cannot fail.
- auto sharedMemory = fileData.tryCreateSharedMemory();
- ASSERT(sharedMemory);
+ RefPtr<WebKit::SharedMemory> sharedMemory;
+ if (auto mappedFileData = WTF::get_if<WebKit::NetworkCache::Data>(data.data)) {
+ sharedMemory = mappedFileData->tryCreateSharedMemory();
- const size_t headerAndSourceSize = ContentRuleListFileHeaderSize + metaData.sourceSize;
+ // Content extensions are always compiled to files, and at this point the file
+ // has been already mapped, therefore tryCreateSharedMemory() cannot fail.
+ ASSERT(sharedMemory);
+ }
+ auto mappedOrCopiedFileData = sharedMemory ?
+ Variant<RefPtr<WebKit::SharedMemory>, RefPtr<WebCore::SharedBuffer>> { sharedMemory }
+ : Variant<RefPtr<WebKit::SharedMemory>, RefPtr<WebCore::SharedBuffer>> { WTFMove(WTF::get<RefPtr<WebCore::SharedBuffer>>(data.data)) };
+
+ const size_t headerAndSourceSize = ContentRuleListFileHeaderSize + data.metaData.sourceSize;
auto compiledContentRuleListData = WebKit::WebCompiledContentRuleListData(
- WTFMove(sharedMemory),
- fileData,
+ WTFMove(mappedOrCopiedFileData),
+ WTF::holds_alternative<WebKit::NetworkCache::Data>(data.data) ? WTF::get<WebKit::NetworkCache::Data>(data.data) : WebKit::NetworkCache::Data { },
ConditionsApplyOnlyToDomainOffset,
headerAndSourceSize,
- metaData.actionsSize,
+ data.metaData.actionsSize,
headerAndSourceSize
- + metaData.actionsSize,
- metaData.filtersWithoutConditionsBytecodeSize,
+ + data.metaData.actionsSize,
+ data.metaData.filtersWithoutConditionsBytecodeSize,
headerAndSourceSize
- + metaData.actionsSize
- + metaData.filtersWithoutConditionsBytecodeSize,
- metaData.filtersWithConditionsBytecodeSize,
+ + data.metaData.actionsSize
+ + data.metaData.filtersWithoutConditionsBytecodeSize,
+ data.metaData.filtersWithConditionsBytecodeSize,
headerAndSourceSize
- + metaData.actionsSize
- + metaData.filtersWithoutConditionsBytecodeSize
- + metaData.filtersWithConditionsBytecodeSize,
- metaData.conditionedFiltersBytecodeSize
+ + data.metaData.actionsSize
+ + data.metaData.filtersWithoutConditionsBytecodeSize
+ + data.metaData.filtersWithConditionsBytecodeSize,
+ data.metaData.conditionedFiltersBytecodeSize
);
auto compiledContentRuleList = WebKit::WebCompiledContentRuleList::create(WTFMove(compiledContentRuleListData));
return API::ContentRuleList::create(identifier, WTFMove(compiledContentRuleList));
@@ -403,9 +464,8 @@
m_readQueue->dispatch([protectedThis = makeRef(*this), identifier = identifier.isolatedCopy(), storePath = m_storePath.isolatedCopy(), legacyFilename = m_legacyFilename, completionHandler = WTFMove(completionHandler)]() mutable {
auto path = constructedPath(storePath, identifier, legacyFilename);
- ContentRuleListMetaData metaData;
- WebKit::NetworkCache::Data fileData;
- if (!openAndMapContentRuleList(path, metaData, fileData)) {
+ auto contentRuleList = openAndMapOrCopyContentRuleList(path);
+ if (!contentRuleList) {
RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] () mutable {
completionHandler(nullptr, Error::LookupFailed);
});
@@ -412,7 +472,7 @@
return;
}
- if (metaData.version != ContentRuleListStore::CurrentContentRuleListFileVersion) {
+ if (contentRuleList->metaData.version != ContentRuleListStore::CurrentContentRuleListFileVersion) {
RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] () mutable {
completionHandler(nullptr, Error::VersionMismatch);
});
@@ -419,8 +479,8 @@
return;
}
- RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), identifier = identifier.isolatedCopy(), fileData = WTFMove(fileData), metaData = WTFMove(metaData), completionHandler = WTFMove(completionHandler)] () mutable {
- completionHandler(createExtension(identifier, metaData, fileData), { });
+ RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), identifier = identifier.isolatedCopy(), contentRuleList = WTFMove(*contentRuleList), completionHandler = WTFMove(completionHandler)] () mutable {
+ completionHandler(createExtension(identifier, WTFMove(contentRuleList)), { });
});
});
}
@@ -454,19 +514,17 @@
m_compileQueue->dispatch([protectedThis = makeRef(*this), identifier = identifier.isolatedCopy(), legacyFilename = m_legacyFilename, json = json.isolatedCopy(), parsedRules = parsedRules.value().isolatedCopy(), storePath = m_storePath.isolatedCopy(), completionHandler = WTFMove(completionHandler)] () mutable {
auto path = constructedPath(storePath, identifier, legacyFilename);
- ContentRuleListMetaData metaData;
- WebKit::NetworkCache::Data fileData;
- auto error = compiledToFile(WTFMove(json), WTFMove(parsedRules), path, metaData, fileData);
- if (error) {
- RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), error = WTFMove(error), completionHandler = WTFMove(completionHandler)] () mutable {
+ auto result = compiledToFile(WTFMove(json), WTFMove(parsedRules), path);
+ if (!result.has_value()) {
+ RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), error = WTFMove(result.error()), completionHandler = WTFMove(completionHandler)] () mutable {
completionHandler(nullptr, error);
});
return;
}
- RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), identifier = WTFMove(identifier), fileData = WTFMove(fileData), metaData = WTFMove(metaData), completionHandler = WTFMove(completionHandler)] () mutable {
- RefPtr<API::ContentRuleList> contentRuleList = createExtension(identifier, metaData, fileData);
- completionHandler(contentRuleList, { });
+ RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), identifier = WTFMove(identifier), data = "" completionHandler = WTFMove(completionHandler)] () mutable {
+ auto contentRuleList = createExtension(identifier, WTFMove(data));
+ completionHandler(contentRuleList.ptr(), { });
});
});
}
@@ -516,29 +574,28 @@
completionHandler(source);
});
};
-
- ContentRuleListMetaData metaData;
- WebKit::NetworkCache::Data fileData;
- if (!openAndMapContentRuleList(path, metaData, fileData)) {
+
+ auto contentRuleList = openAndMapOrCopyContentRuleList(path);
+ if (!contentRuleList) {
complete({ });
return;
}
- switch (metaData.version) {
+ switch (contentRuleList->metaData.version) {
case 9:
case 10:
- if (!metaData.sourceSize) {
+ if (!contentRuleList->metaData.sourceSize) {
complete({ });
return;
}
- bool is8Bit = fileData.data()[ContentRuleListFileHeaderSize];
+ bool is8Bit = contentRuleList->dataPointer()[ContentRuleListFileHeaderSize];
size_t start = ContentRuleListFileHeaderSize + sizeof(bool);
- size_t length = metaData.sourceSize - sizeof(bool);
+ size_t length = contentRuleList->metaData.sourceSize - sizeof(bool);
if (is8Bit)
- complete(WTF::String(fileData.data() + start, length));
+ complete(WTF::String(contentRuleList->dataPointer() + start, length));
else {
ASSERT(!(length % sizeof(UChar)));
- complete(WTF::String(reinterpret_cast<const UChar*>(fileData.data() + start), length / sizeof(UChar)));
+ complete(WTF::String(reinterpret_cast<const UChar*>(contentRuleList->dataPointer() + start), length / sizeof(UChar)));
}
return;
}
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleListStore.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleListStore.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/APIContentRuleListStore.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -31,6 +31,10 @@
#include <system_error>
#include <wtf/text/WTFString.h>
+namespace WebCore {
+class SharedBuffer;
+}
+
namespace WTF {
class WorkQueue;
}
@@ -72,6 +76,8 @@
void invalidateContentRuleListVersion(const WTF::String& identifier);
void getContentRuleListSource(const WTF::String& identifier, CompletionHandler<void(WTF::String)>);
+ static RefPtr<WebCore::SharedBuffer> readContentsOfFile(const WTF::String& path);
+
private:
WTF::String defaultStorePath(bool legacyFilename);
static ContentRuleListStore& legacyDefaultStore();
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm 2019-03-13 08:24:51 UTC (rev 242860)
@@ -29,6 +29,7 @@
#if ENABLE(CONTENT_EXTENSIONS)
#include "SandboxUtilities.h"
+#include <WebCore/SharedBuffer.h>
namespace API {
@@ -63,6 +64,15 @@
return contentRuleListStoreURL.absoluteURL.path.fileSystemRepresentation;
}
+RefPtr<WebCore::SharedBuffer> ContentRuleListStore::readContentsOfFile(const String& filePath)
+{
+ ASSERT(!isMainThread());
+ NSData *data = "" dataWithContentsOfURL:[NSURL fileURLWithPath:filePath isDirectory:NO]];
+ if (!data)
+ return nullptr;
+ return WebCore::SharedBuffer::create(data);
+}
+
} // namespace API
#endif // ENABLE(CONTENT_EXTENSIONS)
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStore.mm (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStore.mm 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStore.mm 2019-03-13 08:24:51 UTC (rev 242860)
@@ -30,6 +30,7 @@
#if WK_API_ENABLED
#import "APIContentRuleListStore.h"
+#import "NetworkCacheFilesystem.h"
#import "WKErrorInternal.h"
#import <wtf/BlockPtr.h>
#import <wtf/CompletionHandler.h>
@@ -127,6 +128,11 @@
// For testing only.
++ (void)_registerPathAsUnsafeToMemoryMapForTesting:(NSString *)filename
+{
+ WebKit::NetworkCache::registerPathAsUnsafeToMemoryMapForTesting(filename);
+}
+
- (void)_removeAllContentRuleLists
{
_contentRuleListStore->synchronousRemoveAllContentRuleLists();
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -33,6 +33,7 @@
- (void)_removeAllContentRuleLists;
- (void)_invalidateContentRuleListVersionForIdentifier:(NSString *)identifier;
- (void)_getContentRuleListSourceForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSString*))completionHandler;
++ (void)_registerPathAsUnsafeToMemoryMapForTesting:(NSString *)filename;
// NS_RELEASES_ARGUMENT to keep peak memory usage low.
- (void)_compileContentRuleListForIdentifier:(NSString *)identifier encodedContentRuleList:(NSString *) NS_RELEASES_ARGUMENT encodedContentRuleList completionHandler:(void (^)(WKContentRuleList *, NSError *))completionHandler;
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilter.mm (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilter.mm 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilter.mm 2019-03-13 08:24:51 UTC (rev 242860)
@@ -58,6 +58,11 @@
return self;
}
+- (BOOL)usesCopiedMemory
+{
+ return _contentRuleList->_contentRuleList->usesCopiedMemory();
+}
+
@end
#endif // WK_API_ENABLED
Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilterPrivate.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilterPrivate.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilterPrivate.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -32,6 +32,7 @@
@interface _WKUserContentFilter (WKPrivate)
- (id)_initWithWKContentRuleList:(WKContentRuleList*)contentRuleList WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+@property (nonatomic, readonly) BOOL usesCopiedMemory;
@end
Modified: branches/safari-607-branch/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp 2019-03-13 08:24:51 UTC (rev 242860)
@@ -348,11 +348,10 @@
#endif
#if ENABLE(CONTENT_EXTENSIONS)
-void WebUserContentController::addContentRuleLists(const Vector<std::pair<String, WebCompiledContentRuleListData>>& contentRuleLists)
+void WebUserContentController::addContentRuleLists(Vector<std::pair<String, WebCompiledContentRuleListData>>&& contentRuleLists)
{
- for (const auto& contentRuleList : contentRuleLists) {
- WebCompiledContentRuleListData contentRuleListData = contentRuleList.second;
- auto compiledContentRuleList = WebCompiledContentRuleList::create(WTFMove(contentRuleListData));
+ for (auto&& contentRuleList : contentRuleLists) {
+ auto compiledContentRuleList = WebCompiledContentRuleList::create(WTFMove(contentRuleList.second));
m_contentExtensionBackend.addContentExtension(contentRuleList.first, WTFMove(compiledContentRuleList));
}
Modified: branches/safari-607-branch/Source/WebKit/WebProcess/UserContent/WebUserContentController.h (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/WebProcess/UserContent/WebUserContentController.h 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/WebProcess/UserContent/WebUserContentController.h 2019-03-13 08:24:51 UTC (rev 242860)
@@ -69,7 +69,7 @@
void addUserStyleSheets(const Vector<WebUserStyleSheetData>&);
void addUserScriptMessageHandlers(const Vector<WebScriptMessageHandlerData>&);
#if ENABLE(CONTENT_EXTENSIONS)
- void addContentRuleLists(const Vector<std::pair<String, WebCompiledContentRuleListData>>&);
+ void addContentRuleLists(Vector<std::pair<String, WebCompiledContentRuleListData>>&&);
#endif
private:
Modified: branches/safari-607-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (242859 => 242860)
--- branches/safari-607-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-03-13 08:24:51 UTC (rev 242860)
@@ -624,7 +624,7 @@
m_userContentController->addUserStyleSheets(parameters.userStyleSheets);
m_userContentController->addUserScriptMessageHandlers(parameters.messageHandlers);
#if ENABLE(CONTENT_EXTENSIONS)
- m_userContentController->addContentRuleLists(parameters.contentRuleLists);
+ m_userContentController->addContentRuleLists(WTFMove(parameters.contentRuleLists));
#endif
#if PLATFORM(IOS_FAMILY)
Modified: branches/safari-607-branch/Tools/ChangeLog (242859 => 242860)
--- branches/safari-607-branch/Tools/ChangeLog 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Tools/ChangeLog 2019-03-13 08:24:51 UTC (rev 242860)
@@ -1,3 +1,91 @@
+2019-03-13 Babak Shafiei <[email protected]>
+
+ Cherry-pick r242735. rdar://problem/48780112
+
+ Add a WKContentRuleList variant that uses copied memory instead of mmap'd shared memory for class A containerized apps
+ https://bugs.webkit.org/show_bug.cgi?id=195511
+ <rdar://problem/44873269>
+
+ Patch by Alex Christensen <[email protected]> on 2019-03-11
+ Reviewed by Darin Adler.
+
+ Source/WebKit:
+
+ * NetworkProcess/NetworkContentRuleListManager.cpp:
+ (WebKit::NetworkContentRuleListManager::addContentRuleLists):
+ * NetworkProcess/NetworkContentRuleListManager.h:
+ * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
+ (WebKit::NetworkCache::pathRegisteredAsUnsafeToMemoryMapForTesting):
+ (WebKit::NetworkCache::registerPathAsUnsafeToMemoryMapForTesting):
+ (WebKit::NetworkCache::isSafeToUseMemoryMapForPath):
+ * NetworkProcess/cache/NetworkCacheFileSystem.h:
+ * Shared/WebCompiledContentRuleList.cpp:
+ (WebKit::WebCompiledContentRuleList::usesCopiedMemory const):
+ (WebKit::WebCompiledContentRuleList::conditionsApplyOnlyToDomain const):
+ (WebKit::WebCompiledContentRuleList::filtersWithoutConditionsBytecode const):
+ (WebKit::WebCompiledContentRuleList::filtersWithConditionsBytecode const):
+ (WebKit::WebCompiledContentRuleList::topURLFiltersBytecode const):
+ (WebKit::WebCompiledContentRuleList::actions const):
+ * Shared/WebCompiledContentRuleList.h:
+ * Shared/WebCompiledContentRuleListData.cpp:
+ (WebKit::WebCompiledContentRuleListData::size const):
+ (WebKit::WebCompiledContentRuleListData::dataPointer const):
+ (WebKit::WebCompiledContentRuleListData::encode const):
+ (WebKit::WebCompiledContentRuleListData::decode):
+ * Shared/WebCompiledContentRuleListData.h:
+ (WebKit::WebCompiledContentRuleListData::WebCompiledContentRuleListData):
+ * UIProcess/API/APIContentRuleList.cpp:
+ (API::ContentRuleList::usesCopiedMemory const):
+ * UIProcess/API/APIContentRuleList.h:
+ * UIProcess/API/APIContentRuleListStore.cpp:
+ (API::getData):
+ (API::decodeContentRuleListMetaData):
+ (API::ContentRuleListStore::readContentsOfFile):
+ (API::MappedOrCopiedData::dataPointer const):
+ (API::openAndMapOrCopyContentRuleList):
+ (API::compiledToFile):
+ (API::createExtension):
+ (API::ContentRuleListStore::lookupContentRuleList):
+ (API::ContentRuleListStore::compileContentRuleList):
+ (API::ContentRuleListStore::getContentRuleListSource):
+ (API::openAndMapContentRuleList): Deleted.
+ * UIProcess/API/APIContentRuleListStore.h:
+ * UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm:
+ (API::ContentRuleListStore::readContentsOfFile):
+ * UIProcess/API/Cocoa/WKContentRuleListStore.mm:
+ (+[WKContentRuleListStore _registerPathAsUnsafeToMemoryMapForTesting:]):
+ * UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h:
+ * UIProcess/API/Cocoa/_WKUserContentFilter.mm:
+ (-[_WKUserContentFilter usesCopiedMemory]):
+ * UIProcess/API/Cocoa/_WKUserContentFilterPrivate.h:
+ * WebProcess/UserContent/WebUserContentController.cpp:
+ (WebKit::WebUserContentController::addContentRuleLists):
+ * WebProcess/UserContent/WebUserContentController.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::m_hostFileDescriptor):
+
+ Tools:
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm:
+ (-[TestSchemeHandlerSubresourceShouldBeBlocked webView:startURLSchemeTask:]):
+ (-[TestSchemeHandlerSubresourceShouldBeBlocked webView:stopURLSchemeTask:]):
+ (TEST_F):
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242735 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-03-11 Alex Christensen <[email protected]>
+
+ Add a WKContentRuleList variant that uses copied memory instead of mmap'd shared memory for class A containerized apps
+ https://bugs.webkit.org/show_bug.cgi?id=195511
+ <rdar://problem/44873269>
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm:
+ (-[TestSchemeHandlerSubresourceShouldBeBlocked webView:startURLSchemeTask:]):
+ (-[TestSchemeHandlerSubresourceShouldBeBlocked webView:stopURLSchemeTask:]):
+ (TEST_F):
+
2019-03-04 Kocsen Chung <[email protected]>
Cherry-pick r242302. rdar://problem/48572673
Modified: branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm (242859 => 242860)
--- branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm 2019-03-13 08:24:45 UTC (rev 242859)
+++ branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm 2019-03-13 08:24:51 UTC (rev 242860)
@@ -30,9 +30,14 @@
#import "PlatformUtilities.h"
#import "Test.h"
+#import "TestWKWebView.h"
#import <WebKit/WKContentRuleList.h>
#import <WebKit/WKContentRuleListStorePrivate.h>
+#import <WebKit/_WKUserContentFilterPrivate.h>
#import <wtf/RetainPtr.h>
+#import <wtf/text/StringBuilder.h>
+#import <wtf/text/StringConcatenate.h>
+#import <wtf/text/StringConcatenateNumbers.h>
class WKContentRuleListStoreTest : public testing::Test {
public:
@@ -380,5 +385,103 @@
TestWebKitAPI::Util::run(&receivedAlert);
}
+@interface TestSchemeHandlerSubresourceShouldBeBlocked : NSObject <WKURLSchemeHandler>
+@end
+@implementation TestSchemeHandlerSubresourceShouldBeBlocked
+- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task
+{
+ EXPECT_TRUE([task.request.URL.path isEqualToString:@"/shouldload"]);
+ [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:0 textEncodingName:nil] autorelease]];
+ [task didFinish];
+}
+- (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task
+{
+ EXPECT_TRUE(false);
+}
+@end
+TEST_F(WKContentRuleListStoreTest, UnsafeMMap)
+{
+ RetainPtr<NSString> tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:@"UnsafeMMapTest"];
+ RetainPtr<WKContentRuleListStore> store = [WKContentRuleListStore storeWithURL:[NSURL fileURLWithPath:tempDir.get() isDirectory:YES]];
+ static NSString *identifier = @"TestRuleList";
+ static NSString *fileName = @"ContentRuleList-TestRuleList";
+ static NSString *ruleListSourceString = @"[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"blockedsubresource\"}}]";
+ RetainPtr<NSString> filePath = [tempDir stringByAppendingPathComponent:fileName];
+
+ auto runTest = [&] (bool shouldUseCopiedMemory) {
+ EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:filePath.get()]);
+
+ __block bool doneCompiling = false;
+ __block RetainPtr<WKContentRuleList> ruleList;
+ [store compileContentRuleListForIdentifier:identifier encodedContentRuleList:ruleListSourceString completionHandler:^(WKContentRuleList *filter, NSError *error) {
+ EXPECT_NOT_NULL(filter);
+ EXPECT_NULL(error);
+ doneCompiling = true;
+ ruleList = filter;
+ EXPECT_TRUE([[[[_WKUserContentFilter alloc] _initWithWKContentRuleList:filter] autorelease] usesCopiedMemory] == shouldUseCopiedMemory);
+ }];
+ TestWebKitAPI::Util::run(&doneCompiling);
+
+ EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:filePath.get()]);
+
+ auto handler = adoptNS([TestSchemeHandlerSubresourceShouldBeBlocked new]);
+ auto configuration = adoptNS([WKWebViewConfiguration new]);
+ [configuration setURLSchemeHandler:handler.get() forURLScheme:@"testmmap"];
+ [[configuration userContentController] addContentRuleList:ruleList.get()];
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+ [webView synchronouslyLoadHTMLString:@"<html>main resource content</html>" baseURL:[NSURL URLWithString:@"testmmap://webkit.org/mainresource"]];
+
+ auto loadingShouldSucceed = [&] (NSString *resourcePath, NSString *shouldSucceed) {
+ __block bool doneEvaluating = false;
+ [webView evaluateJavaScript:[NSString stringWithFormat:@"var caught = false; var xhr = new XMLHttpRequest(); xhr.open('GET', '%@', false); try{ xhr.send() } catch(e) { caught = true; }; caught != %@ ? 'success' : 'failure'", resourcePath, shouldSucceed] completionHandler:^(id result, NSError *error) {
+ EXPECT_NULL(error);
+ EXPECT_TRUE([@"success" isEqualToString:result]);
+ doneEvaluating = true;
+ }];
+ TestWebKitAPI::Util::run(&doneEvaluating);
+ };
+ loadingShouldSucceed(@"/shouldload", @"true");
+ loadingShouldSucceed(@"/blockedsubresource", @"false");
+
+ [[configuration userContentController] removeContentRuleList:ruleList.get()];
+
+ __block bool doneLookingUp = false;
+ [store lookUpContentRuleListForIdentifier:identifier completionHandler:^(WKContentRuleList *filter, NSError *error) {
+ EXPECT_NOT_NULL(filter);
+ EXPECT_NULL(error);
+
+ doneLookingUp = true;
+
+ EXPECT_TRUE([[[[_WKUserContentFilter alloc] _initWithWKContentRuleList:filter] autorelease] usesCopiedMemory] == shouldUseCopiedMemory);
+ ruleList = filter;
+ }];
+ TestWebKitAPI::Util::run(&doneLookingUp);
+
+ [[configuration userContentController] addContentRuleList:ruleList.get()];
+ loadingShouldSucceed(@"/shouldload", @"true");
+ loadingShouldSucceed(@"/blockedsubresource", @"false");
+
+ __block bool doneCheckingSource = false;
+ [store _getContentRuleListSourceForIdentifier:identifier completionHandler:^(NSString *source) {
+ EXPECT_TRUE([source isEqualToString:ruleListSourceString]);
+ doneCheckingSource = true;
+ }];
+ TestWebKitAPI::Util::run(&doneCheckingSource);
+
+ __block bool doneRemoving = false;
+ [store removeContentRuleListForIdentifier:identifier completionHandler:^(NSError *error) {
+ EXPECT_NULL(error);
+ doneRemoving = true;
+ }];
+ TestWebKitAPI::Util::run(&doneRemoving);
+
+ EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:filePath.get()]);
+ };
+
+ runTest(false);
+ [WKContentRuleListStore _registerPathAsUnsafeToMemoryMapForTesting:filePath.get()];
+ runTest(true);
+}
+
#endif