Changeset 223299 in webkit
- Timestamp:
- Oct 13, 2017 1:31:34 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r223288 r223299 1 2017-10-13 Youenn Fablet <youenn@apple.com> 2 3 Implement listing origins for which CacheStorage is storing data 4 https://bugs.webkit.org/show_bug.cgi?id=178236 5 6 Reviewed by Chris Dumez. 7 8 * http/tests/cache-storage/cache-clearing-origin.https.html: 9 1 10 2017-10-13 Youenn Fablet <youenn@apple.com> 2 11 -
trunk/LayoutTests/http/tests/cache-storage/cache-clearing-origin.https.html
r223284 r223299 23 23 if (!window.testRunner) 24 24 return Promise.reject("test runner needed"); 25 26 assert_false(testRunner.hasDOMCache('https://localhost:80'), 'hasDOMCache with fake origin'); 27 assert_true(testRunner.hasDOMCache(window.location.origin), "hasDOMCache with actual origin"); 28 25 29 testRunner.clearDOMCache('https://localhost:80'); 26 30 … … 29 33 30 34 testRunner.clearDOMCache(window.location.origin); 35 assert_false(testRunner.hasDOMCache(window.location.origin), "Actual origin cache is cleared"); 36 31 37 keys = await self.caches.keys(); 32 38 assert_equals(keys.length, 0, "keys should be empty"); -
trunk/Source/WebKit/ChangeLog
r223286 r223299 1 2017-10-13 Youenn Fablet <youenn@apple.com> 2 3 Implement listing origins for which CacheStorage is storing data 4 https://bugs.webkit.org/show_bug.cgi?id=178236 5 6 Reviewed by Chris Dumez. 7 8 Cache storage is split on per-origin folders which name is obfuscated through salting. 9 To retrieve the origin for each folder, an origin file is now stored within each folder. 10 This file contains the actual origin. 11 12 Adding support to get the list of origin by iterating through each folder and 13 getting the actual origin by reading the content of the 'origin' file. 14 15 Adding C API for WebKitTestRunner. 16 17 * NetworkProcess/cache/CacheStorageEngine.cpp: 18 (WebKit::CacheStorage::Engine::fetchEntries): 19 (WebKit::CacheStorage::ReadOriginsTaskCounter::create): 20 (WebKit::CacheStorage::ReadOriginsTaskCounter::~ReadOriginsTaskCounter): 21 (WebKit::CacheStorage::ReadOriginsTaskCounter::addOrigin): 22 (WebKit::CacheStorage::ReadOriginsTaskCounter::ReadOriginsTaskCounter): 23 * NetworkProcess/cache/CacheStorageEngine.h: 24 * NetworkProcess/cache/CacheStorageEngineCaches.cpp: 25 (WebKit::CacheStorage::cachesOriginFilename): 26 (WebKit::CacheStorage::Caches::retrieveOriginFromDirectory): 27 (WebKit::CacheStorage::Caches::Caches): 28 (WebKit::CacheStorage::Caches::storeOrigin): 29 (WebKit::CacheStorage::Caches::readOrigin): 30 (WebKit::CacheStorage::Caches::initialize): 31 * NetworkProcess/cache/CacheStorageEngineCaches.h: 32 (WebKit::CacheStorage::Caches::origin const): 33 * UIProcess/API/C/WKWebsiteDataStoreRef.cpp: 34 (WKWebsiteDataStoreGetFetchCacheOrigins): 35 * UIProcess/API/C/WKWebsiteDataStoreRef.h: 36 1 37 2017-10-13 Alex Christensen <achristensen@webkit.org> 2 38 -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
r223265 r223299 30 30 #include "NetworkCacheIOChannel.h" 31 31 #include "NetworkProcess.h" 32 #include "WebsiteDataType.h" 32 33 #include <WebCore/CacheQueryOptions.h> 33 #include <WebCore/ NotImplemented.h>34 #include <WebCore/SecurityOrigin.h> 34 35 #include <pal/SessionID.h> 35 36 #include <wtf/CallbackAggregator.h> … … 81 82 } 82 83 83 void Engine::fetchEntries(PAL::SessionID sessionID, bool shouldComputeSize, WTF::Function<void(Vector<WebsiteData::Entry>)>&& completionHandler) 84 { 85 // FIXME: Support fetching entries 86 notImplemented(); 87 completionHandler({ }); 84 void Engine::fetchEntries(PAL::SessionID sessionID, bool shouldComputeSize, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler) 85 { 86 from(sessionID).fetchEntries(shouldComputeSize, WTFMove(completionHandler)); 88 87 } 89 88 … … 346 345 } 347 346 347 class ReadOriginsTaskCounter : public RefCounted<ReadOriginsTaskCounter> { 348 public: 349 static Ref<ReadOriginsTaskCounter> create(WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& callback) 350 { 351 return adoptRef(*new ReadOriginsTaskCounter(WTFMove(callback)));} 352 353 ~ReadOriginsTaskCounter() 354 { 355 m_callback(WTFMove(m_entries)); 356 } 357 358 void addOrigin(WebCore::SecurityOriginData&& origin) 359 { 360 m_entries.append(WebsiteData::Entry { WTFMove(origin), WebsiteDataType::DOMCache, 0 }); 361 } 362 363 private: 364 explicit ReadOriginsTaskCounter(WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& callback) 365 : m_callback(WTFMove(callback)) 366 { 367 } 368 369 WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)> m_callback; 370 Vector<WebsiteData::Entry> m_entries; 371 }; 372 373 void Engine::fetchEntries(bool /* shouldComputeSize */, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&& completionHandler) 374 { 375 if (!shouldPersist()) { 376 auto entries = WTF::map(m_caches, [] (auto& pair) { 377 return WebsiteData::Entry { pair.value->origin(), WebsiteDataType::DOMCache, 0 }; 378 }); 379 completionHandler(WTFMove(entries)); 380 return; 381 } 382 383 auto taskCounter = ReadOriginsTaskCounter::create(WTFMove(completionHandler)); 384 for (auto& folderPath : WebCore::listDirectory(m_rootPath, "*")) { 385 if (!WebCore::fileIsDirectory(folderPath, WebCore::ShouldFollowSymbolicLinks::No)) 386 continue; 387 Caches::retrieveOriginFromDirectory(folderPath, *m_ioQueue, [taskCounter = taskCounter.copyRef()] (std::optional<WebCore::SecurityOriginData>&& origin) mutable { 388 ASSERT(RunLoop::isMain()); 389 if (origin) 390 taskCounter->addOrigin(WTFMove(origin.value())); 391 }); 392 } 393 } 394 348 395 void Engine::clearAllCaches(CallbackAggregator& taskHandler) 349 396 { -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.h
r223213 r223299 60 60 static void clearAllEngines(WTF::Function<void()>&&); 61 61 static void clearEnginesForOrigins(const Vector<String>& origins, WTF::Function<void()>&&); 62 static void fetchEntries(PAL::SessionID, bool shouldComputeSize, WTF:: Function<void(Vector<WebsiteData::Entry>)>&&);62 static void fetchEntries(PAL::SessionID, bool shouldComputeSize, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&&); 63 63 64 64 static Ref<Engine> create(String&& rootPath) { return adoptRef(*new Engine(WTFMove(rootPath))); } … … 96 96 String cachesRootPath(const String& origin); 97 97 98 void fetchEntries(bool /* shouldComputeSize */, WTF::CompletionHandler<void(Vector<WebsiteData::Entry>)>&&); 99 98 100 void initialize(WTF::Function<void(std::optional<WebCore::DOMCacheEngine::Error>&&)>&&); 99 101 void clearAllCaches(WTF::CallbackAggregator&); -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp
r223213 r223299 28 28 29 29 #include "NetworkCacheCoders.h" 30 #include "NetworkCacheIOChannel.h" 31 #include <WebCore/SecurityOrigin.h> 30 32 #include <wtf/RunLoop.h> 31 33 #include <wtf/UUID.h> … … 44 46 } 45 47 48 static inline String cachesOriginFilename(const String& cachesRootPath) 49 { 50 return WebCore::pathByAppendingComponent(cachesRootPath, ASCIILiteral("origin")); 51 } 52 53 void Caches::retrieveOriginFromDirectory(const String& folderPath, WorkQueue& queue, WTF::CompletionHandler<void(std::optional<WebCore::SecurityOriginData>&&)>&& completionHandler) 54 { 55 queue.dispatch([completionHandler = WTFMove(completionHandler), folderPath = folderPath.isolatedCopy()]() mutable { 56 if (!WebCore::fileExists(cachesListFilename(folderPath))) { 57 RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)]() mutable { 58 completionHandler(std::nullopt); 59 }); 60 return; 61 } 62 63 auto channel = IOChannel::open(cachesOriginFilename(folderPath), IOChannel::Type::Read); 64 channel->read(0, std::numeric_limits<size_t>::max(), nullptr, [completionHandler = WTFMove(completionHandler)](const Data& data, int error) mutable { 65 ASSERT(RunLoop::isMain()); 66 if (error) { 67 completionHandler(std::nullopt); 68 return; 69 } 70 completionHandler(readOrigin(data)); 71 }); 72 }); 73 } 74 46 75 Caches::Caches(Engine& engine, String&& origin, String&& rootPath, uint64_t quota) 47 76 : m_engine(&engine) 48 , m_origin(W TFMove(origin))77 , m_origin(WebCore::SecurityOriginData::fromSecurityOrigin(WebCore::SecurityOrigin::createFromString(origin))) 49 78 , m_rootPath(WTFMove(rootPath)) 50 79 , m_quota(quota) 51 80 { 81 } 82 83 void Caches::storeOrigin(CompletionCallback&& completionHandler) 84 { 85 WTF::Persistence::Encoder encoder; 86 encoder << m_origin.protocol; 87 encoder << m_origin.host; 88 encoder << m_origin.port; 89 m_engine->writeFile(cachesOriginFilename(m_rootPath), Data { encoder.buffer(), encoder.bufferSize() }, [protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)] (std::optional<Error>&& error) mutable { 90 completionHandler(WTFMove(error)); 91 }); 92 } 93 94 std::optional<WebCore::SecurityOriginData> Caches::readOrigin(const Data& data) 95 { 96 // FIXME: We should be able to use modern decoders for persistent data. 97 WebCore::SecurityOriginData origin; 98 WTF::Persistence::Decoder decoder(data.data(), data.size()); 99 100 if (!decoder.decode(origin.protocol)) 101 return std::nullopt; 102 if (!decoder.decode(origin.host)) 103 return std::nullopt; 104 if (!decoder.decode(origin.port)) 105 return std::nullopt; 106 return WTFMove(origin); 52 107 } 53 108 … … 78 133 m_storage = storage.releaseNonNull(); 79 134 m_storage->writeWithoutWaiting(); 80 readCachesFromDisk([this, callback = WTFMove(callback)](Expected<Vector<Cache>, Error>&& result) mutable { 81 makeDirty(); 82 83 if (!result.hasValue()) { 84 callback(result.error()); 85 86 auto pendingCallbacks = WTFMove(m_pendingInitializationCallbacks); 87 for (auto& callback : pendingCallbacks) 135 136 storeOrigin([this, callback = WTFMove(callback)] (std::optional<Error>&& error) mutable { 137 if (error) { 138 callback(Error::WriteDisk); 139 return; 140 } 141 142 readCachesFromDisk([this, callback = WTFMove(callback)](Expected<Vector<Cache>, Error>&& result) mutable { 143 makeDirty(); 144 145 if (!result.hasValue()) { 88 146 callback(result.error()); 89 return; 90 } 91 m_caches = WTFMove(result.value()); 92 initializeSize(WTFMove(callback)); 147 148 auto pendingCallbacks = WTFMove(m_pendingInitializationCallbacks); 149 for (auto& callback : pendingCallbacks) 150 callback(result.error()); 151 return; 152 } 153 m_caches = WTFMove(result.value()); 154 155 initializeSize(WTFMove(callback)); 156 }); 93 157 }); 94 158 } -
trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.h
r223213 r223299 28 28 #include "CacheStorageEngineCache.h" 29 29 #include "NetworkCacheStorage.h" 30 #include <WebCore/SecurityOriginData.h> 30 31 #include <wtf/CompletionHandler.h> 31 32 … … 39 40 public: 40 41 static Ref<Caches> create(Engine& engine, String&& origin, String&& rootPath, uint64_t quota) { return adoptRef(*new Caches { engine, WTFMove(origin), WTFMove(rootPath), quota }); } 42 43 static void retrieveOriginFromDirectory(const String& folderPath, WorkQueue&, WTF::CompletionHandler<void(std::optional<WebCore::SecurityOriginData>&&)>&&); 41 44 42 45 void initialize(WebCore::DOMCacheEngine::CompletionCallback&&); … … 64 67 65 68 const NetworkCache::Salt& salt() const; 69 const WebCore::SecurityOriginData& origin() const { return m_origin; } 66 70 67 71 bool shouldPersist() const { return !m_rootPath.isNull(); } … … 77 81 void writeCachesToDisk(WebCore::DOMCacheEngine::CompletionCallback&&); 78 82 83 void storeOrigin(WebCore::DOMCacheEngine::CompletionCallback&&); 84 static std::optional<WebCore::SecurityOriginData> readOrigin(const NetworkCache::Data&); 85 79 86 Cache* find(const String& name); 80 87 … … 85 92 Engine* m_engine { nullptr }; 86 93 uint64_t m_updateCounter { 0 }; 87 Stringm_origin;94 WebCore::SecurityOriginData m_origin; 88 95 String m_rootPath; 89 96 uint64_t m_quota { 0 }; -
trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp
r223265 r223299 27 27 #include "WKWebsiteDataStoreRef.h" 28 28 29 #include "APIArray.h" 29 30 #include "APIWebsiteDataStore.h" 30 31 #include "WKAPICast.h" … … 356 357 #endif 357 358 } 359 360 void WKWebsiteDataStoreGetFetchCacheOrigins(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreGetFetchCacheOriginsFunction callback) 361 { 362 WebKit::toImpl(dataStoreRef)->websiteDataStore().fetchData(WebKit::WebsiteDataType::DOMCache, { }, [context, callback] (auto dataRecords) { 363 Vector<RefPtr<API::Object>> securityOrigins; 364 for (const auto& dataRecord : dataRecords) { 365 for (const auto& origin : dataRecord.origins) 366 securityOrigins.append(API::SecurityOrigin::create(origin.securityOrigin())); 367 } 368 callback(WebKit::toAPI(API::Array::create(WTFMove(securityOrigins)).ptr()), context); 369 }); 370 } -
trunk/Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h
r223265 r223299 79 79 WK_EXPORT void WKWebsiteDataStoreRemoveAllServiceWorkerRegistrations(WKWebsiteDataStoreRef dataStoreRef); 80 80 81 typedef void (*WKWebsiteDataStoreGetFetchCacheOriginsFunction)(WKArrayRef, void*); 82 WK_EXPORT void WKWebsiteDataStoreGetFetchCacheOrigins(WKWebsiteDataStoreRef dataStoreRef, void* context, WKWebsiteDataStoreGetFetchCacheOriginsFunction function); 83 81 84 #ifdef __cplusplus 82 85 } -
trunk/Tools/ChangeLog
r223291 r223299 1 2017-10-13 Youenn Fablet <youenn@apple.com> 2 3 Implement listing origins for which CacheStorage is storing data 4 https://bugs.webkit.org/show_bug.cgi?id=178236 5 6 Reviewed by Chris Dumez. 7 8 Adding hasDOMCache API for checking whether origin is storing data through Cache API. 9 10 * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: 11 * WebKitTestRunner/InjectedBundle/TestRunner.cpp: 12 (WTR::TestRunner::hasDOMCache): 13 * WebKitTestRunner/InjectedBundle/TestRunner.h: 14 * WebKitTestRunner/TestController.cpp: 15 (WTR::FetchCacheOriginsCallbackContext::FetchCacheOriginsCallbackContext): 16 (WTR::fetchCacheOriginsCallback): 17 (WTR::TestController::hasDOMCache): 18 * WebKitTestRunner/TestController.h: 19 * WebKitTestRunner/TestInvocation.cpp: 20 (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle): 21 1 22 2017-10-13 Alex Christensen <achristensen@webkit.org> 2 23 -
trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
r223253 r223299 59 59 60 60 void clearDOMCache(DOMString origin); 61 boolean hasDOMCache(DOMString origin); 61 62 62 63 // Special options. -
trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
r223265 r223299 1837 1837 } 1838 1838 1839 bool TestRunner::hasDOMCache(JSStringRef origin) 1840 { 1841 WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("HasDOMCache")); 1842 WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithJSString(origin)); 1843 WKTypeRef returnData = 0; 1844 WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData); 1845 return WKBooleanGetValue(static_cast<WKBooleanRef>(returnData)); 1846 } 1847 1839 1848 } // namespace WTR -
trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
r223253 r223299 166 166 167 167 void clearDOMCache(JSStringRef origin); 168 bool hasDOMCache(JSStringRef origin); 168 169 169 170 // Failed load condition testing -
trunk/Tools/WebKitTestRunner/TestController.cpp
r223265 r223299 2336 2336 } 2337 2337 2338 struct FetchCacheOriginsCallbackContext { 2339 FetchCacheOriginsCallbackContext(TestController& controller, WKStringRef origin) 2340 : testController(controller) 2341 , origin(origin) 2342 { 2343 } 2344 2345 TestController& testController; 2346 WKStringRef origin; 2347 2348 bool done { false }; 2349 bool result { false }; 2350 }; 2351 2352 static void fetchCacheOriginsCallback(WKArrayRef origins, void* userData) 2353 { 2354 auto* context = static_cast<FetchCacheOriginsCallbackContext*>(userData); 2355 context->done = true; 2356 2357 auto size = WKArrayGetSize(origins); 2358 for (size_t index = 0; index < size && !context->result; ++index) { 2359 WKSecurityOriginRef securityOrigin = reinterpret_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, index)); 2360 if (WKStringIsEqual(context->origin, adoptWK(WKSecurityOriginCopyToString(securityOrigin)).get())) 2361 context->result = true; 2362 } 2363 context->testController.notifyDone(); 2364 } 2365 2366 bool TestController::hasDOMCache(WKStringRef origin) 2367 { 2368 auto* dataStore = WKContextGetWebsiteDataStore(platformContext()); 2369 FetchCacheOriginsCallbackContext context(*this, origin); 2370 WKWebsiteDataStoreGetFetchCacheOrigins(dataStore, &context, fetchCacheOriginsCallback); 2371 if (!context.done) 2372 runUntil(context.done, m_currentInvocation->shortTimeout()); 2373 return context.result; 2374 } 2375 2338 2376 #if !PLATFORM(COCOA) || !WK_API_ENABLED 2339 2377 -
trunk/Tools/WebKitTestRunner/TestController.h
r223253 r223299 184 184 void statisticsResetToConsistentState(); 185 185 186 bool hasDOMCache(WKStringRef); 187 186 188 WKArrayRef openPanelFileURLs() const { return m_openPanelFileURLs.get(); } 187 189 void setOpenPanelFileURLs(WKArrayRef fileURLs) { m_openPanelFileURLs = fileURLs; } -
trunk/Tools/WebKitTestRunner/TestInvocation.cpp
r223265 r223299 1211 1211 } 1212 1212 1213 if (WKStringIsEqualToUTF8CString(messageName, "HasDOMCache")) { 1214 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 1215 WKStringRef origin = static_cast<WKStringRef>(messageBody); 1216 1217 bool hasDOMCache = TestController::singleton().hasDOMCache(origin); 1218 WKRetainPtr<WKTypeRef> result(AdoptWK, WKBooleanCreate(hasDOMCache)); 1219 return result; 1220 } 1221 1213 1222 ASSERT_NOT_REACHED(); 1214 1223 return nullptr;
Note: See TracChangeset
for help on using the changeset viewer.