Title: [221633] trunk
Revision
221633
Author
commit-qu...@webkit.org
Date
2017-09-05 14:00:23 -0700 (Tue, 05 Sep 2017)

Log Message

Cache Storage Engine should not mix different origin caches
https://bugs.webkit.org/show_bug.cgi?id=176394

Patch by Youenn Fablet <you...@apple.com> on 2017-09-05
Reviewed by Alex Christensen.

Source/WebKit:

* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::readCachesFromDisk): Initializing the salt before creating the Caches object
so that its persistency path is correctly computed.
* NetworkProcess/cache/CacheStorageEngineCaches.cpp:
(WebKit::CacheStorage::cachesRootPath): Setting origin as partition string.

LayoutTests:

* http/tests/cache-storage/cache-origins.https-expected.txt: Added.
* http/tests/cache-storage/cache-origins.https.html: Added.
* http/tests/cache-storage/resources/cache-persistency-iframe.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (221632 => 221633)


--- trunk/LayoutTests/ChangeLog	2017-09-05 20:41:31 UTC (rev 221632)
+++ trunk/LayoutTests/ChangeLog	2017-09-05 21:00:23 UTC (rev 221633)
@@ -1,3 +1,14 @@
+2017-09-05  Youenn Fablet  <you...@apple.com>
+
+        Cache Storage Engine should not mix different origin caches
+        https://bugs.webkit.org/show_bug.cgi?id=176394
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/cache-storage/cache-origins.https-expected.txt: Added.
+        * http/tests/cache-storage/cache-origins.https.html: Added.
+        * http/tests/cache-storage/resources/cache-persistency-iframe.html:
+
 2017-09-05  Per Arne Vollan  <pvol...@apple.com>
 
         Unskip two tests which was skipped by mistake.

Added: trunk/LayoutTests/http/tests/cache-storage/cache-origins.https-expected.txt (0 => 221633)


--- trunk/LayoutTests/http/tests/cache-storage/cache-origins.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache-storage/cache-origins.https-expected.txt	2017-09-05 21:00:23 UTC (rev 221633)
@@ -0,0 +1,5 @@
+  
+
+PASS Create a cache storage and look at the representation 
+PASS Caches from different origins should not mix 
+

Added: trunk/LayoutTests/http/tests/cache-storage/cache-origins.https.html (0 => 221633)


--- trunk/LayoutTests/http/tests/cache-storage/cache-origins.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/cache-storage/cache-origins.https.html	2017-09-05 21:00:23 UTC (rev 221633)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Cache Storage: testing persistency of different origins</title>
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+    <script>
+
+    function checkCaches(name) {
+        promise_test(() => {
+            return self.caches.keys().then(keys => {
+                assert_true(keys.indexOf("cache1") !== -1, "Should have cache1");
+                assert_true(keys.indexOf("cache2") === -1, "Should not have cache1");
+            });
+        }, name);
+    }
+
+    promise_test(test => {
+        if (!window.internals)
+            return Promise.reject("Test requires internals");
+
+        return new Promise((resolve, reject) => {
+            var counter = 0;
+            window.addEventListener("message", test.step_func((event) => {
+                if (++counter <= 1)
+                    return;
+                internals.clearCacheStorageMemoryRepresentation();
+                checkCaches("Caches from different origins should not mix");
+                resolve();
+            }));
+        })
+    }, "Create a cache storage and look at the representation");
+    </script>
+    <div>
+        <iframe src=""
+        <iframe src=""
+    </div>
+</body>
+</html>
+

Modified: trunk/LayoutTests/http/tests/cache-storage/resources/cache-persistency-iframe.html (221632 => 221633)


--- trunk/LayoutTests/http/tests/cache-storage/resources/cache-persistency-iframe.html	2017-09-05 20:41:31 UTC (rev 221632)
+++ trunk/LayoutTests/http/tests/cache-storage/resources/cache-persistency-iframe.html	2017-09-05 21:00:23 UTC (rev 221633)
@@ -11,7 +11,10 @@
         return;
     }
 
-    self.caches.open("testCacheName").then(() => {
+    var cacheName = "testCacheName";
+    if (window.location.hash.indexOf("#name=") === 0)
+        cacheName = window.location.hash.substring(6);
+    self.caches.open(cacheName).then(() => {
         window.parent.postMessage("ready", "*");
     });
 }

Modified: trunk/Source/WebKit/ChangeLog (221632 => 221633)


--- trunk/Source/WebKit/ChangeLog	2017-09-05 20:41:31 UTC (rev 221632)
+++ trunk/Source/WebKit/ChangeLog	2017-09-05 21:00:23 UTC (rev 221633)
@@ -1,3 +1,16 @@
+2017-09-05  Youenn Fablet  <you...@apple.com>
+
+        Cache Storage Engine should not mix different origin caches
+        https://bugs.webkit.org/show_bug.cgi?id=176394
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::readCachesFromDisk): Initializing the salt before creating the Caches object
+        so that its persistency path is correctly computed.
+        * NetworkProcess/cache/CacheStorageEngineCaches.cpp:
+        (WebKit::CacheStorage::cachesRootPath): Setting origin as partition string.
+
 2017-09-05  Brent Fulgham  <bfulg...@apple.com>
 
         Use a single network storage session for stateless connections

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (221632 => 221633)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-09-05 20:41:31 UTC (rev 221632)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2017-09-05 21:00:23 UTC (rev 221633)
@@ -188,31 +188,28 @@
 
 void Engine::readCachesFromDisk(const String& origin, CachesCallback&& callback)
 {
-    auto& caches = m_caches.ensure(origin, [&origin, this] {
-        return Caches::create(*this, origin);
-    }).iterator->value;
+    initialize([this, origin, callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
+        auto& caches = m_caches.ensure(origin, [&origin, this] {
+            return Caches::create(*this, origin);
+        }).iterator->value;
 
-    if (caches->isInitialized()) {
-        callback(std::reference_wrapper<Caches> { caches.get() });
-        return;
-    }
+        if (caches->isInitialized()) {
+            callback(std::reference_wrapper<Caches> { caches.get() });
+            return;
+        }
 
-    initialize([this, origin, callback = WTFMove(callback)](std::optional<Error>&& error) mutable {
         if (error) {
             callback(makeUnexpected(error.value()));
             return;
         }
 
-        auto caches = m_caches.get(origin);
-        ASSERT(caches);
-
-        caches->initialize([callback = WTFMove(callback), caches](std::optional<Error>&& error) mutable {
+        caches->initialize([callback = WTFMove(callback), caches = caches.copyRef()](std::optional<Error>&& error) mutable {
             if (error) {
                 callback(makeUnexpected(error.value()));
                 return;
             }
 
-            callback(std::reference_wrapper<Caches> { *caches });
+            callback(std::reference_wrapper<Caches> { caches.get() });
         });
     });
 }

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp (221632 => 221633)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2017-09-05 20:41:31 UTC (rev 221632)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngineCaches.cpp	2017-09-05 21:00:23 UTC (rev 221633)
@@ -41,7 +41,7 @@
     if (!engine.shouldPersist())
         return { };
 
-    Key key(engine.rootPath(), { }, { }, origin, engine.salt());
+    Key key(origin, { }, { }, { }, engine.salt());
     return WebCore::pathByAppendingComponent(engine.rootPath(), key.partitionHashAsString());
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to