Title: [223299] trunk
Revision
223299
Author
[email protected]
Date
2017-10-13 13:31:34 -0700 (Fri, 13 Oct 2017)

Log Message

Implement listing origins for which CacheStorage is storing data
https://bugs.webkit.org/show_bug.cgi?id=178236

Patch by Youenn Fablet <[email protected]> on 2017-10-13
Reviewed by Chris Dumez.

Source/WebKit:

Cache storage is split on per-origin folders which name is obfuscated through salting.
To retrieve the origin for each folder, an origin file is now stored within each folder.
This file contains the actual origin.

Adding support to get the list of origin by iterating through each folder and
getting the actual origin by reading the content of the 'origin' file.

Adding C API for WebKitTestRunner.

* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::fetchEntries):
(WebKit::CacheStorage::ReadOriginsTaskCounter::create):
(WebKit::CacheStorage::ReadOriginsTaskCounter::~ReadOriginsTaskCounter):
(WebKit::CacheStorage::ReadOriginsTaskCounter::addOrigin):
(WebKit::CacheStorage::ReadOriginsTaskCounter::ReadOriginsTaskCounter):
* NetworkProcess/cache/CacheStorageEngine.h:
* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::cachesOriginFilename):
(WebKit::CacheStorage::Caches::retrieveOriginFromDirectory):
(WebKit::CacheStorage::Caches::Caches):
(WebKit::CacheStorage::Caches::storeOrigin):
(WebKit::CacheStorage::Caches::readOrigin):
(WebKit::CacheStorage::Caches::initialize):
* NetworkProcess/cache/CacheStorageEngineCaches.h:
(WebKit::CacheStorage::Caches::origin const):
* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreGetFetchCacheOrigins):
* UIProcess/API/C/WKWebsiteDataStoreRef.h:

Tools:

Adding hasDOMCache API for checking whether origin is storing data through Cache API.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::hasDOMCache):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::FetchCacheOriginsCallbackContext::FetchCacheOriginsCallbackContext):
(WTR::fetchCacheOriginsCallback):
(WTR::TestController::hasDOMCache):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:

* http/tests/cache-storage/cache-clearing-origin.https.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (223298 => 223299)


--- trunk/LayoutTests/ChangeLog	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/LayoutTests/ChangeLog	2017-10-13 20:31:34 UTC (rev 223299)
@@ -1,5 +1,14 @@
 2017-10-13  Youenn Fablet  <[email protected]>
 
+        Implement listing origins for which CacheStorage is storing data
+        https://bugs.webkit.org/show_bug.cgi?id=178236
+
+        Reviewed by Chris Dumez.
+
+        * http/tests/cache-storage/cache-clearing-origin.https.html:
+
+2017-10-13  Youenn Fablet  <[email protected]>
+
         http/tests/cache-storage/cache-origins.https.html is flaky
         https://bugs.webkit.org/show_bug.cgi?id=178266
 

Modified: trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html (223298 => 223299)


--- trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html	2017-10-13 20:31:34 UTC (rev 223299)
@@ -22,6 +22,10 @@
 
     if (!window.testRunner)
         return Promise.reject("test runner needed");
+
+    assert_false(testRunner.hasDOMCache('https://localhost:80'), 'hasDOMCache with fake origin');
+    assert_true(testRunner.hasDOMCache(window.location.origin), "hasDOMCache with actual origin");
+
     testRunner.clearDOMCache('https://localhost:80');
 
     var keys = await self.caches.keys();
@@ -28,6 +32,8 @@
     assert_not_equals(keys.length, 0, "keys should not be empty");
 
     testRunner.clearDOMCache(window.location.origin);
+    assert_false(testRunner.hasDOMCache(window.location.origin), "Actual origin cache is cleared");
+
     keys = await self.caches.keys();
     assert_equals(keys.length, 0, "keys should be empty");
 

Modified: trunk/Source/WebKit/ChangeLog (223298 => 223299)


--- trunk/Source/WebKit/ChangeLog	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Source/WebKit/ChangeLog	2017-10-13 20:31:34 UTC (rev 223299)
@@ -1,3 +1,39 @@
+2017-10-13  Youenn Fablet  <[email protected]>
+
+        Implement listing origins for which CacheStorage is storing data
+        https://bugs.webkit.org/show_bug.cgi?id=178236
+
+        Reviewed by Chris Dumez.
+
+        Cache storage is split on per-origin folders which name is obfuscated through salting.
+        To retrieve the origin for each folder, an origin file is now stored within each folder.
+        This file contains the actual origin.
+
+        Adding support to get the list of origin by iterating through each folder and
+        getting the actual origin by reading the content of the 'origin' file.
+
+        Adding C API for WebKitTestRunner.
+
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::fetchEntries):
+        (WebKit::CacheStorage::ReadOriginsTaskCounter::create):
+        (WebKit::CacheStorage::ReadOriginsTaskCounter::~ReadOriginsTaskCounter):
+        (WebKit::CacheStorage::ReadOriginsTaskCounter::addOrigin):
+        (WebKit::CacheStorage::ReadOriginsTaskCounter::ReadOriginsTaskCounter):
+        * NetworkProcess/cache/CacheStorageEngine.h:
+        * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+        (WebKit::CacheStorage::cachesOriginFilename):
+        (WebKit::CacheStorage::Caches::retrieveOriginFromDirectory):
+        (WebKit::CacheStorage::Caches::Caches):
+        (WebKit::CacheStorage::Caches::storeOrigin):
+        (WebKit::CacheStorage::Caches::readOrigin):
+        (WebKit::CacheStorage::Caches::initialize):
+        * NetworkProcess/cache/CacheStorageEngineCaches.h:
+        (WebKit::CacheStorage::Caches::origin const):
+        * UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
+        (WKWebsiteDataStoreGetFetchCacheOrigins):
+        * UIProcess/API/C/WKWebsiteDataStoreRef.h:
+
 2017-10-13  Alex Christensen  <[email protected]>
 
         Fix API tests after r223269.

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (223298 => 223299)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-10-13 20:31:34 UTC (rev 223299)
@@ -29,8 +29,9 @@
 #include "NetworkCacheFileSystem.h"
 #include "NetworkCacheIOChannel.h"
 #include "NetworkProcess.h"
+#include "WebsiteDataType.h"
 #include <WebCore/CacheQueryOptions.h>
-#include <WebCore/NotImplemented.h>
+#include <WebCore/SecurityOrigin.h>
 #include <pal/SessionID.h>
 #include <wtf/CallbackAggregator.h>
 #include <wtf/NeverDestroyed.h>
@@ -80,11 +81,9 @@
     globalEngineMap().remove(sessionID);
 }
 
-void Engine::fetchEntries(PAL::SessionID sessionID, bool shouldComputeSize, WTF::Function<void(Vector<WebsiteData::Entry>)>&& completionHandler)
+void Engine::fetchEntries(PAL::SessionID sessionID, bool shouldComputeSize, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
 {
-    // FIXME: Support fetching entries
-    notImplemented();
-    completionHandler({ });
+    from(sessionID).fetchEntries(shouldComputeSize, WTFMove(completionHandler));
 }
 
 void Engine::clearAllEngines(WTF::Function<void()>&& completionHandler)
@@ -345,6 +344,54 @@
     m_caches.remove(origin);
 }
 
+class ReadOriginsTaskCounter : public RefCounted<ReadOriginsTaskCounter> {
+public:
+    static Ref<ReadOriginsTaskCounter> create(WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& callback)
+    {
+        return adoptRef(*new ReadOriginsTaskCounter(WTFMove(callback)));}
+
+    ~ReadOriginsTaskCounter()
+    {
+        m_callback(WTFMove(m_entries));
+    }
+
+    void addOrigin(WebCore::SecurityOriginData&& origin)
+    {
+        m_entries.append(WebsiteData::Entry { WTFMove(origin), WebsiteDataType::DOMCache, 0 });
+    }
+
+private:
+    explicit ReadOriginsTaskCounter(WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& callback)
+        : m_callback(WTFMove(callback))
+    {
+    }
+
+    WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)> m_callback;
+    Vector<WebsiteData::Entry> m_entries;
+};
+
+void Engine::fetchEntries(bool /* shouldComputeSize */, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler)
+{
+    if (!shouldPersist()) {
+        auto entries = WTF::map(m_caches, [] (auto& pair) {
+            return WebsiteData::Entry { pair.value->origin(), WebsiteDataType::DOMCache, 0 };
+        });
+        completionHandler(WTFMove(entries));
+        return;
+    }
+
+    auto taskCounter = ReadOriginsTaskCounter::create(WTFMove(completionHandler));
+    for (auto& folderPath : WebCore::listDirectory(m_rootPath, "*")) {
+        if (!WebCore::fileIsDirectory(folderPath, WebCore::ShouldFollowSymbolicLinks::No))
+            continue;
+        Caches::retrieveOriginFromDirectory(folderPath, *m_ioQueue, [taskCounter = taskCounter.copyRef()] (std::optional<WebCore::SecurityOriginData>&& origin) mutable {
+            ASSERT(RunLoop::isMain());
+            if (origin)
+                taskCounter->addOrigin(WTFMove(origin.value()));
+        });
+    }
+}
+
 void Engine::clearAllCaches(CallbackAggregator& taskHandler)
 {
     for (auto& caches : m_caches.values())

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h (223298 => 223299)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h	2017-10-13 20:31:34 UTC (rev 223299)
@@ -59,7 +59,7 @@
     static void destroyEngine(PAL::SessionID);
     static void clearAllEngines(WTF::Function<void()>&&);
     static void clearEnginesForOrigins(const Vector<String>& origins, WTF::Function<void()>&&);
-    static void fetchEntries(PAL::SessionID, bool shouldComputeSize, WTF::Function<void(Vector<WebsiteData::Entry>)>&&);
+    static void fetchEntries(PAL::SessionID, bool shouldComputeSize, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&&);
 
     static Ref<Engine> create(String&& rootPath) { return adoptRef(*new Engine(WTFMove(rootPath))); }
 
@@ -95,6 +95,8 @@
 
     String cachesRootPath(const String& origin);
 
+    void fetchEntries(bool /* shouldComputeSize */, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&&);
+
     void initialize(WTF::Function<void(std::optional<WebCore::DOMCacheEngine::Error>&&)>&&);
     void clearAllCaches(WTF::CallbackAggregator&);
     void clearCachesForOrigin(const String& origin, WTF::CallbackAggregator&);

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp (223298 => 223299)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2017-10-13 20:31:34 UTC (rev 223299)
@@ -27,6 +27,8 @@
 #include "CacheStorageEngine.h"
 
 #include "NetworkCacheCoders.h"
+#include "NetworkCacheIOChannel.h"
+#include <WebCore/SecurityOrigin.h>
 #include <wtf/RunLoop.h>
 #include <wtf/UUID.h>
 #include <wtf/text/StringBuilder.h>
@@ -43,14 +45,67 @@
     return WebCore::pathByAppendingComponent(cachesRootPath, ASCIILiteral("cacheslist"));
 }
 
+static inline String cachesOriginFilename(const String& cachesRootPath)
+{
+    return WebCore::pathByAppendingComponent(cachesRootPath, ASCIILiteral("origin"));
+}
+
+void Caches::retrieveOriginFromDirectory(const String& folderPath, WorkQueue& queue, WTF::CompletionHandler<void(std::optional<WebCore::SecurityOriginData>&&)>&& completionHandler)
+{
+    queue.dispatch([completionHandler = WTFMove(completionHandler), folderPath = folderPath.isolatedCopy()]() mutable {
+        if (!WebCore::fileExists(cachesListFilename(folderPath))) {
+            RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)]() mutable {
+                completionHandler(std::nullopt);
+            });
+            return;
+        }
+
+        auto channel = IOChannel::open(cachesOriginFilename(folderPath), IOChannel::Type::Read);
+        channel->read(0, std::numeric_limits<size_t>::max(), nullptr, [completionHandler = WTFMove(completionHandler)](const Data& data, int error) mutable {
+            ASSERT(RunLoop::isMain());
+            if (error) {
+                completionHandler(std::nullopt);
+                return;
+            }
+            completionHandler(readOrigin(data));
+        });
+    });
+}
+
 Caches::Caches(Engine& engine, String&& origin, String&& rootPath, uint64_t quota)
     : m_engine(&engine)
-    , m_origin(WTFMove(origin))
+    , m_origin(WebCore::SecurityOriginData::fromSecurityOrigin(WebCore::SecurityOrigin::createFromString(origin)))
     , m_rootPath(WTFMove(rootPath))
     , m_quota(quota)
 {
 }
 
+void Caches::storeOrigin(CompletionCallback&& completionHandler)
+{
+    WTF::Persistence::Encoder encoder;
+    encoder << m_origin.protocol;
+    encoder << m_origin.host;
+    encoder << m_origin.port;
+    m_engine->writeFile(cachesOriginFilename(m_rootPath), Data { encoder.buffer(), encoder.bufferSize() }, [protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)] (std::optional<Error>&& error) mutable {
+        completionHandler(WTFMove(error));
+    });
+}
+
+std::optional<WebCore::SecurityOriginData> Caches::readOrigin(const Data& data)
+{
+    // FIXME: We should be able to use modern decoders for persistent data.
+    WebCore::SecurityOriginData origin;
+    WTF::Persistence::Decoder decoder(data.data(), data.size());
+
+    if (!decoder.decode(origin.protocol))
+        return std::nullopt;
+    if (!decoder.decode(origin.host))
+        return std::nullopt;
+    if (!decoder.decode(origin.port))
+        return std::nullopt;
+    return WTFMove(origin);
+}
+
 void Caches::initialize(WebCore::DOMCacheEngine::CompletionCallback&& callback)
 {
     if (m_isInitialized) {
@@ -77,19 +132,28 @@
     }
     m_storage = storage.releaseNonNull();
     m_storage->writeWithoutWaiting();
-    readCachesFromDisk([this, callback = WTFMove(callback)](Expected<Vector<Cache>, Error>&& result) mutable {
-        makeDirty();
 
-        if (!result.hasValue()) {
-            callback(result.error());
+    storeOrigin([this, callback = WTFMove(callback)] (std::optional<Error>&& error) mutable {
+        if (error) {
+            callback(Error::WriteDisk);
+            return;
+        }
 
-            auto pendingCallbacks = WTFMove(m_pendingInitializationCallbacks);
-            for (auto& callback : pendingCallbacks)
+        readCachesFromDisk([this, callback = WTFMove(callback)](Expected<Vector<Cache>, Error>&& result) mutable {
+            makeDirty();
+
+            if (!result.hasValue()) {
                 callback(result.error());
-            return;
-        }
-        m_caches = WTFMove(result.value());
-        initializeSize(WTFMove(callback));
+
+                auto pendingCallbacks = WTFMove(m_pendingInitializationCallbacks);
+                for (auto& callback : pendingCallbacks)
+                    callback(result.error());
+                return;
+            }
+            m_caches = WTFMove(result.value());
+
+            initializeSize(WTFMove(callback));
+        });
     });
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h (223298 => 223299)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h	2017-10-13 20:31:34 UTC (rev 223299)
@@ -27,6 +27,7 @@
 
 #include "CacheStorageEngineCache.h"
 #include "NetworkCacheStorage.h"
+#include <WebCore/SecurityOriginData.h>
 #include <wtf/CompletionHandler.h>
 
 namespace WebKit {
@@ -39,6 +40,8 @@
 public:
     static Ref<Caches> create(Engine& engine, String&& origin, String&& rootPath, uint64_t quota) { return adoptRef(*new Caches { engine, WTFMove(origin), WTFMove(rootPath), quota }); }
 
+    static void retrieveOriginFromDirectory(const String& folderPath, WorkQueue&, WTF::CompletionHandler<void(std::optional<WebCore::SecurityOriginData>&&)>&&);
+
     void initialize(WebCore::DOMCacheEngine::CompletionCallback&&);
     void open(const String& name, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
     void remove(uint64_t identifier, WebCore::DOMCacheEngine::CacheIdentifierCallback&&);
@@ -63,6 +66,7 @@
     void removeRecord(const RecordInformation&);
 
     const NetworkCache::Salt& salt() const;
+    const WebCore::SecurityOriginData& origin() const { return m_origin; }
 
     bool shouldPersist() const { return !m_rootPath.isNull(); }
 
@@ -76,6 +80,9 @@
     void readCachesFromDisk(WTF::Function<void(Expected<Vector<Cache>, WebCore::DOMCacheEngine::Error>&&)>&&);
     void writeCachesToDisk(WebCore::DOMCacheEngine::CompletionCallback&&);
 
+    void storeOrigin(WebCore::DOMCacheEngine::CompletionCallback&&);
+    static std::optional<WebCore::SecurityOriginData> readOrigin(const NetworkCache::Data&);
+
     Cache* find(const String& name);
 
     void makeDirty() { ++m_updateCounter; }
@@ -84,7 +91,7 @@
     bool m_isInitialized { false };
     Engine* m_engine { nullptr };
     uint64_t m_updateCounter { 0 };
-    String m_origin;
+    WebCore::SecurityOriginData m_origin;
     String m_rootPath;
     uint64_t m_quota { 0 };
     uint64_t m_size { 0 };

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp (223298 => 223299)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp	2017-10-13 20:31:34 UTC (rev 223299)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "WKWebsiteDataStoreRef.h"
 
+#include "APIArray.h"
 #include "APIWebsiteDataStore.h"
 #include "WKAPICast.h"
 #include "WebResourceLoadStatisticsStore.h"
@@ -355,3 +356,15 @@
     UNUSED_PARAM(dataStoreRef);
 #endif
 }
+
+void WKWebsiteDataStoreGetFetchCacheOrigins(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreGetFetchCacheOriginsFunction callback)
+{
+    WebKit::toImpl(dataStoreRef)->websiteDataStore().fetchData(WebKit::WebsiteDataType::DOMCache, { }, [context, callback] (auto dataRecords) {
+        Vector<RefPtr<API::Object>> securityOrigins;
+        for (const auto& dataRecord : dataRecords) {
+            for (const auto& origin : dataRecord.origins)
+                securityOrigins.append(API::SecurityOrigin::create(origin.securityOrigin()));
+        }
+        callback(WebKit::toAPI(API::Array::create(WTFMove(securityOrigins)).ptr()), context);
+    });
+}

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h (223298 => 223299)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h	2017-10-13 20:31:34 UTC (rev 223299)
@@ -78,6 +78,9 @@
 WK_EXPORT void WKWebsiteDataStoreRemoveAllIndexedDatabases(WKWebsiteDataStoreRef dataStoreRef);
 WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef);
 
+typedef void (*WKWebsiteDataStoreGetFetchCacheOriginsFunction)(WKArrayRef, void*);
+WK_EXPORT void WKWebsiteDataStoreGetFetchCacheOrigins(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreGetFetchCacheOriginsFunction function);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/Tools/ChangeLog (223298 => 223299)


--- trunk/Tools/ChangeLog	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Tools/ChangeLog	2017-10-13 20:31:34 UTC (rev 223299)
@@ -1,3 +1,24 @@
+2017-10-13  Youenn Fablet  <[email protected]>
+
+        Implement listing origins for which CacheStorage is storing data
+        https://bugs.webkit.org/show_bug.cgi?id=178236
+
+        Reviewed by Chris Dumez.
+
+        Adding hasDOMCache API for checking whether origin is storing data through Cache API.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::hasDOMCache):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::FetchCacheOriginsCallbackContext::FetchCacheOriginsCallbackContext):
+        (WTR::fetchCacheOriginsCallback):
+        (WTR::TestController::hasDOMCache):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
+
 2017-10-13  Alex Christensen  <[email protected]>
 
         Remove Editor::simplifyMarkup

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (223298 => 223299)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2017-10-13 20:31:34 UTC (rev 223299)
@@ -58,6 +58,7 @@
     void dumpPolicyDelegateCallbacks();
 
     void clearDOMCache(DOMString origin);
+    boolean hasDOMCache(DOMString origin);
 
     // Special options.
     void keepWebHistory();

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (223298 => 223299)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2017-10-13 20:31:34 UTC (rev 223299)
@@ -1836,4 +1836,13 @@
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), messageBody.get(), nullptr);
 }
 
+bool TestRunner::hasDOMCache(JSStringRef origin)
+{
+    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("HasDOMCache"));
+    WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithJSString(origin));
+    WKTypeRef returnData = 0;
+    WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData);
+    return WKBooleanGetValue(static_cast<WKBooleanRef>(returnData));
+}
+
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (223298 => 223299)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2017-10-13 20:31:34 UTC (rev 223299)
@@ -165,6 +165,7 @@
     JSValueRef originsWithApplicationCache();
 
     void clearDOMCache(JSStringRef origin);
+    bool hasDOMCache(JSStringRef origin);
 
     // Failed load condition testing
     void forceImmediateCompletion();

Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (223298 => 223299)


--- trunk/Tools/WebKitTestRunner/TestController.cpp	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp	2017-10-13 20:31:34 UTC (rev 223299)
@@ -2335,6 +2335,44 @@
 #endif
 }
 
+struct FetchCacheOriginsCallbackContext {
+    FetchCacheOriginsCallbackContext(TestController& controller, WKStringRef origin)
+        : testController(controller)
+        , origin(origin)
+    {
+    }
+
+    TestController& testController;
+    WKStringRef origin;
+
+    bool done { false };
+    bool result { false };
+};
+
+static void fetchCacheOriginsCallback(WKArrayRef origins, void* userData)
+{
+    auto* context = static_cast<FetchCacheOriginsCallbackContext*>(userData);
+    context->done = true;
+
+    auto size = WKArrayGetSize(origins);
+    for (size_t index = 0; index < size && !context->result; ++index) {
+        WKSecurityOriginRef securityOrigin = reinterpret_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, index));
+        if (WKStringIsEqual(context->origin, adoptWK(WKSecurityOriginCopyToString(securityOrigin)).get()))
+            context->result = true;
+    }
+    context->testController.notifyDone();
+}
+
+bool TestController::hasDOMCache(WKStringRef origin)
+{
+    auto* dataStore = WKContextGetWebsiteDataStore(platformContext());
+    FetchCacheOriginsCallbackContext context(*this, origin);
+    WKWebsiteDataStoreGetFetchCacheOrigins(dataStore, &context, fetchCacheOriginsCallback);
+    if (!context.done)
+        runUntil(context.done, m_currentInvocation->shortTimeout());
+    return context.result;
+}
+
 #if !PLATFORM(COCOA) || !WK_API_ENABLED
 
 void TestController::setStatisticsLastSeen(WKStringRef host, double seconds)

Modified: trunk/Tools/WebKitTestRunner/TestController.h (223298 => 223299)


--- trunk/Tools/WebKitTestRunner/TestController.h	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Tools/WebKitTestRunner/TestController.h	2017-10-13 20:31:34 UTC (rev 223299)
@@ -183,6 +183,8 @@
     void statisticsClearThroughWebsiteDataRemoval();
     void statisticsResetToConsistentState();
 
+    bool hasDOMCache(WKStringRef);
+
     WKArrayRef openPanelFileURLs() const { return m_openPanelFileURLs.get(); }
     void setOpenPanelFileURLs(WKArrayRef fileURLs) { m_openPanelFileURLs = fileURLs; }
 

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (223298 => 223299)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2017-10-13 20:24:28 UTC (rev 223298)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2017-10-13 20:31:34 UTC (rev 223299)
@@ -1210,6 +1210,15 @@
         return nullptr;
     }
 
+    if (WKStringIsEqualToUTF8CString(messageName, "HasDOMCache")) {
+        ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
+        WKStringRef origin = static_cast<WKStringRef>(messageBody);
+
+        bool hasDOMCache = TestController::singleton().hasDOMCache(origin);
+        WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(hasDOMCache));
+        return result;
+    }
+
     ASSERT_NOT_REACHED();
     return nullptr;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to