Changeset 242710 in webkit


Ignore:
Timestamp:
Mar 11, 2019 9:50:32 AM (5 years ago)
Author:
achristensen@apple.com
Message:

Unreviewed, rolling out r242698.

API test crashes on bots.

Reverted changeset:

"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
https://trac.webkit.org/changeset/242698

Location:
trunk
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r242709 r242710  
     12019-03-11  Alex Christensen  <achristensen@webkit.org>
     2
     3        Unreviewed, rolling out r242698.
     4
     5        API test crashes on bots.
     6
     7        Reverted changeset:
     8
     9        "Add a WKContentRuleList variant that uses copied memory
     10        instead of mmap'd shared memory for class A containerized
     11        apps"
     12        https://bugs.webkit.org/show_bug.cgi?id=195511
     13        https://trac.webkit.org/changeset/242698
     14
    1152019-03-11  Michael Catanzaro  <mcatanzaro@igalia.com>
    216
  • trunk/Source/WebKit/NetworkProcess/NetworkContentRuleListManager.cpp

    r242698 r242710  
    6767}
    6868
    69 void NetworkContentRuleListManager::addContentRuleLists(UserContentControllerIdentifier identifier, Vector<std::pair<String, WebCompiledContentRuleListData>>&& contentRuleLists)
     69void NetworkContentRuleListManager::addContentRuleLists(UserContentControllerIdentifier identifier, const Vector<std::pair<String, WebCompiledContentRuleListData>>& contentRuleLists)
    7070{
    7171    auto& backend = *m_contentExtensionBackends.ensure(identifier, [] {
     
    7373    }).iterator->value;
    7474
    75     for (auto&& contentRuleList : contentRuleLists) {
    76         auto compiledContentRuleList = WebCompiledContentRuleList::create(WTFMove(contentRuleList.second));
     75    for (const auto& contentRuleList : contentRuleLists) {
     76        WebCompiledContentRuleListData contentRuleListData = contentRuleList.second;
     77        auto compiledContentRuleList = WebCompiledContentRuleList::create(WTFMove(contentRuleListData));
    7778        backend.addContentExtension(contentRuleList.first, WTFMove(compiledContentRuleList), ContentExtensions::ContentExtension::ShouldCompileCSS::No);
    7879    }
  • trunk/Source/WebKit/NetworkProcess/NetworkContentRuleListManager.h

    r242698 r242710  
    5252
    5353private:
    54     void addContentRuleLists(UserContentControllerIdentifier, Vector<std::pair<String, WebCompiledContentRuleListData>>&&);
     54    void addContentRuleLists(UserContentControllerIdentifier, const Vector<std::pair<String, WebCompiledContentRuleListData>>&);
    5555    void removeContentRuleList(UserContentControllerIdentifier, const String& name);
    5656    void removeAllContentRuleLists(UserContentControllerIdentifier);
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp

    r242698 r242710  
    146146}
    147147
    148 static String& pathRegisteredAsUnsafeToMemoryMapForTesting()
    149 {
    150     static NeverDestroyed<String> path;
    151     return path.get();
    152 }
    153 
    154 void registerPathAsUnsafeToMemoryMapForTesting(const String& path)
    155 {
    156     pathRegisteredAsUnsafeToMemoryMapForTesting() = path;
    157 }
    158 
    159    
    160148bool isSafeToUseMemoryMapForPath(const String& path)
    161149{
    162     if (path == pathRegisteredAsUnsafeToMemoryMapForTesting())
    163         return false;
    164 
    165150#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
    166151    struct {
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.h

    r242698 r242710  
    4444
    4545bool isSafeToUseMemoryMapForPath(const String& path);
    46 void registerPathAsUnsafeToMemoryMapForTesting(const String&);
    4746
    4847}
  • trunk/Source/WebKit/Shared/WebCompiledContentRuleList.cpp

    r242698 r242710  
    4545}
    4646
    47 bool WebCompiledContentRuleList::usesCopiedMemory() const
    48 {
    49     return WTF::holds_alternative<RefPtr<WebCore::SharedBuffer>>(m_data.data);
    50 }
    51 
    5247bool WebCompiledContentRuleList::conditionsApplyOnlyToDomain() const
    5348{
    54     return *reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(m_data.dataPointer()) + m_data.conditionsApplyOnlyToDomainOffset);
     49    return *reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(m_data.data->data()) + m_data.conditionsApplyOnlyToDomainOffset);
    5550}
    5651
    5752const WebCore::ContentExtensions::DFABytecode* WebCompiledContentRuleList::filtersWithoutConditionsBytecode() const
    5853{
    59     return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.dataPointer()) + m_data.filtersWithoutConditionsBytecodeOffset;
     54    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.filtersWithoutConditionsBytecodeOffset;
    6055}
    6156
     
    6762const WebCore::ContentExtensions::DFABytecode* WebCompiledContentRuleList::filtersWithConditionsBytecode() const
    6863{
    69     return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.dataPointer()) + m_data.filtersWithConditionsBytecodeOffset;
     64    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.filtersWithConditionsBytecodeOffset;
    7065}
    7166
     
    7772const WebCore::ContentExtensions::DFABytecode* WebCompiledContentRuleList::topURLFiltersBytecode() const
    7873{
    79     return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.dataPointer()) + m_data.topURLFiltersBytecodeOffset;
     74    return static_cast<const WebCore::ContentExtensions::DFABytecode*>(m_data.data->data()) + m_data.topURLFiltersBytecodeOffset;
    8075}
    8176
     
    8782const WebCore::ContentExtensions::SerializedActionByte* WebCompiledContentRuleList::actions() const
    8883{
    89     return static_cast<const WebCore::ContentExtensions::SerializedActionByte*>(m_data.dataPointer()) + m_data.actionsOffset;
     84    return static_cast<const WebCore::ContentExtensions::SerializedActionByte*>(m_data.data->data()) + m_data.actionsOffset;
    9085}
    9186
  • trunk/Source/WebKit/Shared/WebCompiledContentRuleList.h

    r242698 r242710  
    3939    virtual ~WebCompiledContentRuleList();
    4040
    41     const WebCompiledContentRuleListData& data() const { return m_data; }
     41    WebCompiledContentRuleListData data() const { return m_data; }
    4242
    43     bool usesCopiedMemory() const;
    44    
    4543private:
    4644    WebCompiledContentRuleList(WebCompiledContentRuleListData&&);
  • trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp

    r242698 r242710  
    3030
    3131#include "ArgumentCoders.h"
    32 #include "SharedBufferDataReference.h"
    3332
    3433namespace WebKit {
    3534
    36 size_t WebCompiledContentRuleListData::size() const
    37 {
    38     return WTF::switchOn(data, [] (const auto& sharedMemoryOrBuffer) {
    39         return sharedMemoryOrBuffer->size();
    40     });
    41 }
    42 
    43 const void* WebCompiledContentRuleListData::dataPointer() const
    44 {
    45     return WTF::switchOn(data, [] (const auto& sharedMemoryOrBuffer) -> const void* {
    46         return sharedMemoryOrBuffer->data();
    47     });
    48 }
    49 
    5035void WebCompiledContentRuleListData::encode(IPC::Encoder& encoder) const
    5136{
    52     if (auto sharedMemory = WTF::get_if<RefPtr<SharedMemory>>(data)) {
    53         encoder << true;
    54         SharedMemory::Handle handle;
    55         sharedMemory->get()->createHandle(handle, SharedMemory::Protection::ReadOnly);
    56         encoder << handle;
    57     } else {
    58         encoder << false;
    59         encoder << IPC::SharedBufferDataReference { *WTF::get<RefPtr<WebCore::SharedBuffer>>(data) };
    60     }
    61 
    62     // fileData needs to be kept in the UIProcess, but it does not need to be serialized.
    63     // FIXME: Move it to API::ContentRuleList
     37    SharedMemory::Handle handle;
     38    data->createHandle(handle, SharedMemory::Protection::ReadOnly);
     39    encoder << handle;
    6440
    6541    encoder << conditionsApplyOnlyToDomainOffset;
     
    7753{
    7854    WebCompiledContentRuleListData compiledContentRuleListData;
    79 
    80     Optional<bool> hasSharedMemory;
    81     decoder >> hasSharedMemory;
    82     if (!hasSharedMemory)
     55    SharedMemory::Handle handle;
     56    if (!decoder.decode(handle))
    8357        return WTF::nullopt;
    84     if (*hasSharedMemory) {
    85         SharedMemory::Handle handle;
    86         if (!decoder.decode(handle))
    87             return WTF::nullopt;
    88         compiledContentRuleListData.data = { SharedMemory::map(handle, SharedMemory::Protection::ReadOnly) };
    89     } else {
    90         IPC::DataReference dataReference;
    91         if (!decoder.decode(dataReference))
    92             return WTF::nullopt;
    93         compiledContentRuleListData.data = { RefPtr<WebCore::SharedBuffer>(WebCore::SharedBuffer::create(dataReference.data(), dataReference.size())) };
    94     }
     58    compiledContentRuleListData.data = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
    9559
    9660    if (!decoder.decode(compiledContentRuleListData.conditionsApplyOnlyToDomainOffset))
  • trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.h

    r242698 r242710  
    3030#include "NetworkCacheData.h"
    3131#include "SharedMemory.h"
    32 #include <WebCore/SharedBuffer.h>
    3332#include <wtf/RefPtr.h>
    34 #include <wtf/Variant.h>
    3533
    3634namespace IPC {
     
    4543    WebCompiledContentRuleListData() = default;
    4644
    47     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)
     45    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)
    4846        : data(WTFMove(data))
    4947        , fileData(fileData)
     
    6361    static Optional<WebCompiledContentRuleListData> decode(IPC::Decoder&);
    6462
    65     size_t size() const;
    66     const void* dataPointer() const;
    67    
    68     Variant<RefPtr<SharedMemory>, RefPtr<WebCore::SharedBuffer>> data;
     63    RefPtr<SharedMemory> data;
    6964    NetworkCache::Data fileData;
    7065    unsigned conditionsApplyOnlyToDomainOffset { 0 };
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleList.cpp

    r242698 r242710  
    4343}
    4444
    45 bool ContentRuleList::usesCopiedMemory() const
    46 {
    47     return m_compiledRuleList->usesCopiedMemory();
    48 }
    49 
    5045} // namespace API
    5146
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleList.h

    r242698 r242710  
    4949    const WebKit::WebCompiledContentRuleList& compiledRuleList() const { return m_compiledRuleList.get(); }
    5050
    51     bool usesCopiedMemory() const;
    52 
    5351private:
    5452    WTF::String m_name;
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp

    r242698 r242710  
    3838#include <WebCore/ContentExtensionParser.h>
    3939#include <WebCore/QualifiedName.h>
    40 #include <WebCore/SharedBuffer.h>
    4140#include <string>
    4241#include <wtf/CompletionHandler.h>
     
    158157}
    159158
    160 template<typename T> void getData(const T&, const Function<bool(const uint8_t*, size_t)>&);
    161 template<> void getData(const WebKit::NetworkCache::Data& data, const Function<bool(const uint8_t*, size_t)>& function)
    162 {
    163     data.apply(function);
    164 }
    165 template<> void getData(const WebCore::SharedBuffer& data, const Function<bool(const uint8_t*, size_t)>& function)
    166 {
    167     function(reinterpret_cast<const uint8_t*>(data.data()), data.size());
    168 }
    169 
    170 template<typename T>
    171 static Optional<ContentRuleListMetaData> decodeContentRuleListMetaData(const T& fileData)
     159static bool decodeContentRuleListMetaData(ContentRuleListMetaData& metaData, const WebKit::NetworkCache::Data& fileData)
    172160{
    173161    bool success = false;
    174     ContentRuleListMetaData metaData;
    175     getData(fileData, [&metaData, &success, &fileData](const uint8_t* data, size_t size) {
     162    fileData.apply([&metaData, &success, &fileData](const uint8_t* data, size_t size) {
    176163        // The file data should be mapped into one continuous memory segment so the size
    177164        // passed to the applier should always equal the data size.
     
    197184        return false;
    198185    });
    199     if (!success)
    200         return WTF::nullopt;
    201     return WTFMove(metaData);
    202 }
    203 
    204 #if !PLATFORM(COCOA)
    205 RefPtr<WebCore::SharedBuffer> ContentRuleListStore::readContentsOfFile(const WTF::String& filePath)
    206 {
    207     ASSERT_NOT_REACHED();
    208     return nullptr;
    209 }
    210 #endif
    211 
    212 struct MappedOrCopiedData {
    213     ContentRuleListMetaData metaData;
    214     Variant<WebKit::NetworkCache::Data, RefPtr<WebCore::SharedBuffer>> data;
    215    
    216     const uint8_t* dataPointer() const
    217     {
    218         return WTF::switchOn(data, [] (const WebKit::NetworkCache::Data& data) {
    219             return data.data();
    220         }, [] (const RefPtr<WebCore::SharedBuffer>& sharedBuffer) {
    221             return reinterpret_cast<const uint8_t*>(sharedBuffer->data());
    222         });
    223     }
    224 };
    225 
    226 static Optional<MappedOrCopiedData> openAndMapOrCopyContentRuleList(const WTF::String& path)
    227 {
    228     if (!WebKit::NetworkCache::isSafeToUseMemoryMapForPath(path)) {
    229         RefPtr<WebCore::SharedBuffer> buffer = ContentRuleListStore::readContentsOfFile(path);
    230         if (!buffer)
    231             return WTF::nullopt;
    232         auto metaData = decodeContentRuleListMetaData(*buffer);
    233         if (!metaData)
    234             return WTF::nullopt;
    235         return {{ WTFMove(*metaData), { buffer.releaseNonNull() }}};
    236     }
    237 
    238     WebKit::NetworkCache::Data fileData = mapFile(fileSystemRepresentation(path).data());
     186    return success;
     187}
     188
     189static bool openAndMapContentRuleList(const WTF::String& path, ContentRuleListMetaData& metaData, WebKit::NetworkCache::Data& fileData)
     190{
     191    fileData = mapFile(fileSystemRepresentation(path).data());
    239192    if (fileData.isNull())
    240         return WTF::nullopt;
    241     auto metaData = decodeContentRuleListMetaData(fileData);
    242     if (!metaData)
    243         return WTF::nullopt;
    244     return {{ WTFMove(*metaData), { WTFMove(fileData) }}};
     193        return false;
     194
     195    if (!decodeContentRuleListMetaData(metaData, fileData))
     196        return false;
     197
     198    return true;
    245199}
    246200
     
    259213}
    260214
    261 static Expected<MappedOrCopiedData, std::error_code> compiledToFile(WTF::String&& json, Vector<WebCore::ContentExtensions::ContentExtensionRule>&& parsedRules, const WTF::String& finalFilePath)
     215static std::error_code compiledToFile(WTF::String&& json, Vector<WebCore::ContentExtensions::ContentExtensionRule>&& parsedRules, const WTF::String& finalFilePath, ContentRuleListMetaData& metaData, WebKit::NetworkCache::Data& mappedData)
    262216{
    263217    using namespace WebCore::ContentExtensions;
     
    376330    if (temporaryFileHandle == invalidPlatformFileHandle) {
    377331        WTFLogAlways("Content Rule List compiling failed: Opening temporary file failed.");
    378         return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
     332        return ContentRuleListStore::Error::CompileFailed;
    379333    }
    380334   
     
    385339        WTFLogAlways("Content Rule List compiling failed: Writing header to file failed.");
    386340        closeFile(temporaryFileHandle);
    387         return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
    388     }
    389 
    390     ContentRuleListMetaData metaData;
     341        return ContentRuleListStore::Error::CompileFailed;
     342    }
     343
    391344    CompilationClient compilationClient(temporaryFileHandle, metaData);
    392345   
     
    394347        WTFLogAlways("Content Rule List compiling failed: Compiling failed.");
    395348        closeFile(temporaryFileHandle);
    396         return makeUnexpected(compilerError);
     349        return compilerError;
    397350    }
    398351    if (compilationClient.hadErrorWhileWritingToFile()) {
    399352        WTFLogAlways("Content Rule List compiling failed: Writing to file failed.");
    400353        closeFile(temporaryFileHandle);
    401         return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
    402     }
    403 
    404     auto mappedData = adoptAndMapFile(temporaryFileHandle, 0, metaData.fileSize());
     354        return ContentRuleListStore::Error::CompileFailed;
     355    }
     356
     357    mappedData = adoptAndMapFile(temporaryFileHandle, 0, metaData.fileSize());
    405358    if (mappedData.isNull()) {
    406359        WTFLogAlways("Content Rule List compiling failed: Mapping file failed.");
    407         return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
     360        return ContentRuleListStore::Error::CompileFailed;
    408361    }
    409362
    410363    if (!moveFile(temporaryFilePath, finalFilePath)) {
    411364        WTFLogAlways("Content Rule List compiling failed: Moving file failed.");
    412         return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
    413     }
    414 
    415     if (!isSafeToUseMemoryMapForPath(finalFilePath)) {
    416         auto contents = ContentRuleListStore::readContentsOfFile(finalFilePath);
    417         if (!contents)
    418             return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
    419         return {{ WTFMove(metaData), WTFMove(contents) }};
    420     }
    421    
    422     return {{ WTFMove(metaData), WTFMove(mappedData) }};
    423 }
    424 
    425 static Ref<API::ContentRuleList> createExtension(const WTF::String& identifier, MappedOrCopiedData&& data)
    426 {
    427     RefPtr<WebKit::SharedMemory> sharedMemory;
    428     if (auto mappedFileData = WTF::get_if<WebKit::NetworkCache::Data>(data.data)) {
    429         sharedMemory = mappedFileData->tryCreateSharedMemory();
    430 
    431         // Content extensions are always compiled to files, and at this point the file
    432         // has been already mapped, therefore tryCreateSharedMemory() cannot fail.
    433         ASSERT(sharedMemory);
    434     }
    435     auto mappedOrCopiedFileData = sharedMemory ?
    436         Variant<RefPtr<WebKit::SharedMemory>, RefPtr<WebCore::SharedBuffer>> { sharedMemory }
    437         : Variant<RefPtr<WebKit::SharedMemory>, RefPtr<WebCore::SharedBuffer>> { WTFMove(WTF::get<RefPtr<WebCore::SharedBuffer>>(data.data)) };
    438 
    439     const size_t headerAndSourceSize = ContentRuleListFileHeaderSize + data.metaData.sourceSize;
     365        return ContentRuleListStore::Error::CompileFailed;
     366    }
     367
     368    return { };
     369}
     370
     371static Ref<API::ContentRuleList> createExtension(const WTF::String& identifier, const ContentRuleListMetaData& metaData, const WebKit::NetworkCache::Data& fileData)
     372{
     373    // Content extensions are always compiled to files, and at this point the file
     374    // has been already mapped, therefore tryCreateSharedMemory() cannot fail.
     375    auto sharedMemory = fileData.tryCreateSharedMemory();
     376    ASSERT(sharedMemory);
     377
     378    const size_t headerAndSourceSize = ContentRuleListFileHeaderSize + metaData.sourceSize;
    440379    auto compiledContentRuleListData = WebKit::WebCompiledContentRuleListData(
    441         WTFMove(mappedOrCopiedFileData),
    442         WTF::holds_alternative<WebKit::NetworkCache::Data>(data.data) ? WTF::get<WebKit::NetworkCache::Data>(data.data) : WebKit::NetworkCache::Data { },
     380        WTFMove(sharedMemory),
     381        fileData,
    443382        ConditionsApplyOnlyToDomainOffset,
    444383        headerAndSourceSize,
    445         data.metaData.actionsSize,
     384        metaData.actionsSize,
    446385        headerAndSourceSize
    447             + data.metaData.actionsSize,
    448         data.metaData.filtersWithoutConditionsBytecodeSize,
     386            + metaData.actionsSize,
     387        metaData.filtersWithoutConditionsBytecodeSize,
    449388        headerAndSourceSize
    450             + data.metaData.actionsSize
    451             + data.metaData.filtersWithoutConditionsBytecodeSize,
    452         data.metaData.filtersWithConditionsBytecodeSize,
     389            + metaData.actionsSize
     390            + metaData.filtersWithoutConditionsBytecodeSize,
     391        metaData.filtersWithConditionsBytecodeSize,
    453392        headerAndSourceSize
    454             + data.metaData.actionsSize
    455             + data.metaData.filtersWithoutConditionsBytecodeSize
    456             + data.metaData.filtersWithConditionsBytecodeSize,
    457         data.metaData.conditionedFiltersBytecodeSize
     393            + metaData.actionsSize
     394            + metaData.filtersWithoutConditionsBytecodeSize
     395            + metaData.filtersWithConditionsBytecodeSize,
     396        metaData.conditionedFiltersBytecodeSize
    458397    );
    459398    auto compiledContentRuleList = WebKit::WebCompiledContentRuleList::create(WTFMove(compiledContentRuleListData));
     
    466405        auto path = constructedPath(storePath, identifier, legacyFilename);
    467406       
    468         auto contentRuleList = openAndMapOrCopyContentRuleList(path);
    469         if (!contentRuleList) {
     407        ContentRuleListMetaData metaData;
     408        WebKit::NetworkCache::Data fileData;
     409        if (!openAndMapContentRuleList(path, metaData, fileData)) {
    470410            RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] () mutable {
    471411                completionHandler(nullptr, Error::LookupFailed);
     
    474414        }
    475415       
    476         if (contentRuleList->metaData.version != ContentRuleListStore::CurrentContentRuleListFileVersion) {
     416        if (metaData.version != ContentRuleListStore::CurrentContentRuleListFileVersion) {
    477417            RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)] () mutable {
    478418                completionHandler(nullptr, Error::VersionMismatch);
     
    481421        }
    482422       
    483         RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), identifier = identifier.isolatedCopy(), contentRuleList = WTFMove(*contentRuleList), completionHandler = WTFMove(completionHandler)] () mutable {
    484             completionHandler(createExtension(identifier, WTFMove(contentRuleList)), { });
     423        RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), identifier = identifier.isolatedCopy(), fileData = WTFMove(fileData), metaData = WTFMove(metaData), completionHandler = WTFMove(completionHandler)] () mutable {
     424            completionHandler(createExtension(identifier, metaData, fileData), { });
    485425        });
    486426    });
     
    516456        auto path = constructedPath(storePath, identifier, legacyFilename);
    517457
    518         auto result = compiledToFile(WTFMove(json), WTFMove(parsedRules), path);
    519         if (!result.has_value()) {
    520             RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), error = WTFMove(result.error()), completionHandler = WTFMove(completionHandler)] () mutable {
     458        ContentRuleListMetaData metaData;
     459        WebKit::NetworkCache::Data fileData;
     460        auto error = compiledToFile(WTFMove(json), WTFMove(parsedRules), path, metaData, fileData);
     461        if (error) {
     462            RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), error = WTFMove(error), completionHandler = WTFMove(completionHandler)] () mutable {
    521463                completionHandler(nullptr, error);
    522464            });
     
    524466        }
    525467
    526         RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), identifier = WTFMove(identifier), data = WTFMove(result.value()), completionHandler = WTFMove(completionHandler)] () mutable {
    527             auto contentRuleList = createExtension(identifier, WTFMove(data));
    528             completionHandler(contentRuleList.ptr(), { });
     468        RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), identifier = WTFMove(identifier), fileData = WTFMove(fileData), metaData = WTFMove(metaData), completionHandler = WTFMove(completionHandler)] () mutable {
     469            RefPtr<API::ContentRuleList> contentRuleList = createExtension(identifier, metaData, fileData);
     470            completionHandler(contentRuleList, { });
    529471        });
    530472    });
     
    576518            });
    577519        };
    578 
    579         auto contentRuleList = openAndMapOrCopyContentRuleList(path);
    580         if (!contentRuleList) {
     520       
     521        ContentRuleListMetaData metaData;
     522        WebKit::NetworkCache::Data fileData;
     523        if (!openAndMapContentRuleList(path, metaData, fileData)) {
    581524            complete({ });
    582525            return;
    583526        }
    584527       
    585         switch (contentRuleList->metaData.version) {
     528        switch (metaData.version) {
    586529        case 9:
    587530        case 10:
    588             if (!contentRuleList->metaData.sourceSize) {
     531            if (!metaData.sourceSize) {
    589532                complete({ });
    590533                return;
    591534            }
    592             bool is8Bit = contentRuleList->dataPointer()[ContentRuleListFileHeaderSize];
     535            bool is8Bit = fileData.data()[ContentRuleListFileHeaderSize];
    593536            size_t start = ContentRuleListFileHeaderSize + sizeof(bool);
    594             size_t length = contentRuleList->metaData.sourceSize - sizeof(bool);
     537            size_t length = metaData.sourceSize - sizeof(bool);
    595538            if (is8Bit)
    596                 complete(WTF::String(contentRuleList->dataPointer() + start, length));
     539                complete(WTF::String(fileData.data() + start, length));
    597540            else {
    598541                ASSERT(!(length % sizeof(UChar)));
    599                 complete(WTF::String(reinterpret_cast<const UChar*>(contentRuleList->dataPointer() + start), length / sizeof(UChar)));
     542                complete(WTF::String(reinterpret_cast<const UChar*>(fileData.data() + start), length / sizeof(UChar)));
    600543            }
    601544            return;
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.h

    r242698 r242710  
    3131#include <system_error>
    3232#include <wtf/text/WTFString.h>
    33 
    34 namespace WebCore {
    35 class SharedBuffer;
    36 }
    3733
    3834namespace WTF {
     
    7773    void getContentRuleListSource(const WTF::String& identifier, CompletionHandler<void(WTF::String)>);
    7874
    79     static RefPtr<WebCore::SharedBuffer> readContentsOfFile(const WTF::String& path);
    80 
    8175private:
    8276    WTF::String defaultStorePath(bool legacyFilename);
  • trunk/Source/WebKit/UIProcess/API/Cocoa/APIContentRuleListStoreCocoa.mm

    r242698 r242710  
    3030
    3131#include "SandboxUtilities.h"
    32 #include <WebCore/SharedBuffer.h>
    3332
    3433namespace API {
     
    6564}
    6665
    67 RefPtr<WebCore::SharedBuffer> ContentRuleListStore::readContentsOfFile(const String& filePath)
    68 {
    69     ASSERT(!isMainThread());
    70     NSData *data = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:filePath isDirectory:NO]];
    71     if (!data)
    72         return nullptr;
    73     return WebCore::SharedBuffer::create(data);
    74 }
    75 
    7666} // namespace API
    7767
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStore.mm

    r242698 r242710  
    2929
    3030#import "APIContentRuleListStore.h"
    31 #import "NetworkCacheFilesystem.h"
    3231#import "WKErrorInternal.h"
    3332#import <wtf/BlockPtr.h>
     
    127126// For testing only.
    128127
    129 + (void)_registerPathAsUnsafeToMemoryMapForTesting:(NSString *)filename
    130 {
    131     WebKit::NetworkCache::registerPathAsUnsafeToMemoryMapForTesting(filename);
    132 }
    133 
    134128- (void)_removeAllContentRuleLists
    135129{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKContentRuleListStorePrivate.h

    r242698 r242710  
    3232- (void)_invalidateContentRuleListVersionForIdentifier:(NSString *)identifier;
    3333- (void)_getContentRuleListSourceForIdentifier:(NSString *)identifier completionHandler:(void (^)(NSString*))completionHandler;
    34 + (void)_registerPathAsUnsafeToMemoryMapForTesting:(NSString *)filename;
    3534
    3635// NS_RELEASES_ARGUMENT to keep peak memory usage low.
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilter.mm

    r242698 r242710  
    5757}
    5858
    59 - (BOOL)usesCopiedMemory
    60 {
    61     return _contentRuleList->_contentRuleList->usesCopiedMemory();
    62 }
    63 
    6459@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKUserContentFilterPrivate.h

    r242698 r242710  
    3131
    3232- (id)_initWithWKContentRuleList:(WKContentRuleList*)contentRuleList WK_API_AVAILABLE(macosx(10.13), ios(11.0));
    33 @property (nonatomic, readonly) BOOL usesCopiedMemory;
    3433
    3534@end
  • trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.cpp

    r242698 r242710  
    349349
    350350#if ENABLE(CONTENT_EXTENSIONS)
    351 void WebUserContentController::addContentRuleLists(Vector<std::pair<String, WebCompiledContentRuleListData>>&& contentRuleLists)
    352 {
    353     for (auto&& contentRuleList : contentRuleLists) {
    354         auto compiledContentRuleList = WebCompiledContentRuleList::create(WTFMove(contentRuleList.second));
     351void WebUserContentController::addContentRuleLists(const Vector<std::pair<String, WebCompiledContentRuleListData>>& contentRuleLists)
     352{
     353    for (const auto& contentRuleList : contentRuleLists) {
     354        WebCompiledContentRuleListData contentRuleListData = contentRuleList.second;
     355        auto compiledContentRuleList = WebCompiledContentRuleList::create(WTFMove(contentRuleListData));
    355356
    356357        m_contentExtensionBackend.addContentExtension(contentRuleList.first, WTFMove(compiledContentRuleList));
  • trunk/Source/WebKit/WebProcess/UserContent/WebUserContentController.h

    r242698 r242710  
    7070    void addUserScriptMessageHandlers(const Vector<WebScriptMessageHandlerData>&);
    7171#if ENABLE(CONTENT_EXTENSIONS)
    72     void addContentRuleLists(Vector<std::pair<String, WebCompiledContentRuleListData>>&&);
     72    void addContentRuleLists(const Vector<std::pair<String, WebCompiledContentRuleListData>>&);
    7373#endif
    7474
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r242698 r242710  
    638638    m_userContentController->addUserScriptMessageHandlers(parameters.messageHandlers);
    639639#if ENABLE(CONTENT_EXTENSIONS)
    640     m_userContentController->addContentRuleLists(WTFMove(parameters.contentRuleLists));
     640    m_userContentController->addContentRuleLists(parameters.contentRuleLists);
    641641#endif
    642642
  • trunk/Tools/ChangeLog

    r242709 r242710  
     12019-03-11  Alex Christensen  <achristensen@webkit.org>
     2
     3        Unreviewed, rolling out r242698.
     4
     5        API test crashes on bots.
     6
     7        Reverted changeset:
     8
     9        "Add a WKContentRuleList variant that uses copied memory
     10        instead of mmap'd shared memory for class A containerized
     11        apps"
     12        https://bugs.webkit.org/show_bug.cgi?id=195511
     13        https://trac.webkit.org/changeset/242698
     14
    1152019-03-11  Michael Catanzaro  <mcatanzaro@igalia.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm

    r242698 r242710  
    2929#import "PlatformUtilities.h"
    3030#import "Test.h"
    31 #import "TestWKWebView.h"
    3231#import <WebKit/WKContentRuleList.h>
    3332#import <WebKit/WKContentRuleListStorePrivate.h>
    34 #import <WebKit/_WKUserContentFilterPrivate.h>
    3533#import <wtf/RetainPtr.h>
    36 #import <wtf/text/StringBuilder.h>
    37 #import <wtf/text/StringConcatenate.h>
    38 #import <wtf/text/StringConcatenateNumbers.h>
    3934
    4035class WKContentRuleListStoreTest : public testing::Test {
     
    383378    TestWebKitAPI::Util::run(&receivedAlert);
    384379}
    385 
    386 @interface TestSchemeHandlerSubresourceShouldBeBlocked : NSObject <WKURLSchemeHandler>
    387 @end
    388 @implementation TestSchemeHandlerSubresourceShouldBeBlocked
    389 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task
    390 {
    391     EXPECT_TRUE([task.request.URL.path isEqualToString:@"/shouldload"]);
    392     [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:0 textEncodingName:nil] autorelease]];
    393     [task didFinish];
    394 }
    395 - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task
    396 {
    397     EXPECT_TRUE(false);
    398 }
    399 @end
    400 
    401 TEST_F(WKContentRuleListStoreTest, UnsafeMMap)
    402 {
    403     NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:@"UnsafeMMapTest"];
    404     WKContentRuleListStore *store = [WKContentRuleListStore storeWithURL:[NSURL fileURLWithPath:tempDir isDirectory:YES]];
    405     NSString *identifier = @"TestRuleList";
    406     NSString *fileName = @"ContentRuleList-TestRuleList";
    407     NSString *filePath = [tempDir stringByAppendingPathComponent:fileName];
    408     NSString *ruleListSourceString = @"[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"blockedsubresource\"}}]";
    409 
    410     auto runTest = [&] (bool shouldUseCopiedMemory) {
    411         EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
    412        
    413         __block bool doneCompiling = false;
    414         __block RetainPtr<WKContentRuleList> ruleList;
    415         [store compileContentRuleListForIdentifier:identifier encodedContentRuleList:ruleListSourceString completionHandler:^(WKContentRuleList *filter, NSError *error) {
    416             EXPECT_NOT_NULL(filter);
    417             EXPECT_NULL(error);
    418             doneCompiling = true;
    419             ruleList = filter;
    420             EXPECT_TRUE([[[[_WKUserContentFilter alloc] _initWithWKContentRuleList:filter] autorelease] usesCopiedMemory] == shouldUseCopiedMemory);
    421         }];
    422         TestWebKitAPI::Util::run(&doneCompiling);
    423        
    424         EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
    425 
    426         auto handler = adoptNS([TestSchemeHandlerSubresourceShouldBeBlocked new]);
    427         auto configuration = adoptNS([WKWebViewConfiguration new]);
    428         [configuration setURLSchemeHandler:handler.get() forURLScheme:@"testmmap"];
    429         [[configuration userContentController] addContentRuleList:ruleList.get()];
    430         auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    431         [webView synchronouslyLoadHTMLString:@"<html>main resource content</html>" baseURL:[NSURL URLWithString:@"testmmap://webkit.org/mainresource"]];
    432 
    433         auto loadingShouldSucceed = [&] (NSString *resourcePath, NSString *shouldSucceed) {
    434             __block bool doneEvaluating = false;
    435             [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) {
    436                 EXPECT_NULL(error);
    437                 EXPECT_TRUE([@"success" isEqualToString:result]);
    438                 doneEvaluating = true;
    439             }];
    440             TestWebKitAPI::Util::run(&doneEvaluating);
    441         };
    442         loadingShouldSucceed(@"/shouldload", @"true");
    443         loadingShouldSucceed(@"/blockedsubresource", @"false");
    444 
    445         [[configuration userContentController] removeContentRuleList:ruleList.get()];
    446        
    447         __block bool doneLookingUp = false;
    448         [store lookUpContentRuleListForIdentifier:identifier completionHandler:^(WKContentRuleList *filter, NSError *error) {
    449             EXPECT_NOT_NULL(filter);
    450             EXPECT_NULL(error);
    451            
    452             doneLookingUp = true;
    453            
    454             EXPECT_TRUE([[[[_WKUserContentFilter alloc] _initWithWKContentRuleList:filter] autorelease] usesCopiedMemory] == shouldUseCopiedMemory);
    455             ruleList = filter;
    456         }];
    457         TestWebKitAPI::Util::run(&doneLookingUp);
    458 
    459         [[configuration userContentController] addContentRuleList:ruleList.get()];
    460         loadingShouldSucceed(@"/shouldload", @"true");
    461         loadingShouldSucceed(@"/blockedsubresource", @"false");
    462 
    463         __block bool doneCheckingSource = false;
    464         [store _getContentRuleListSourceForIdentifier:identifier completionHandler:^(NSString *source) {
    465             EXPECT_TRUE([source isEqualToString:ruleListSourceString]);
    466             doneCheckingSource = true;
    467         }];
    468         TestWebKitAPI::Util::run(&doneCheckingSource);
    469        
    470         __block bool doneRemoving = false;
    471         [store removeContentRuleListForIdentifier:identifier completionHandler:^(NSError *error) {
    472             EXPECT_NULL(error);
    473             doneRemoving = true;
    474         }];
    475         TestWebKitAPI::Util::run(&doneRemoving);
    476 
    477         EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
    478     };
    479    
    480     runTest(false);
    481     [WKContentRuleListStore _registerPathAsUnsafeToMemoryMapForTesting:filePath];
    482     runTest(true);
    483 }
Note: See TracChangeset for help on using the changeset viewer.