Web Replay: add page-level setting to bypass the MemoryCache
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Mar 2014 22:46:27 +0000 (22:46 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Mar 2014 22:46:27 +0000 (22:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=130728

Reviewed by Timothy Hatcher.

Source/WebCore:

When replaying a specific Page we don't want to store its cached resources in the
MemoryCache. This patch adds a page setting to prevent the page's resources from
being saved in the MemoryCache.

If Settings::usesMemoryCache() is false, page resources are given the special
SessionID bypassCacheSessionID(). The cached resource loader and memory cache
act as if the memory cache is disabled if the resource has this special session id.

Hook up ReplayController to override the memory cache setting during capture/replay.

Test: http/tests/cache/bypass-memory-cache-after-reload.html

* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
(WebCore::CachedResourceLoader::revalidateResource):
* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::add):
* page/Page.cpp:
(WebCore::Page::sessionID):
* page/SessionID.h:
(WebCore::SessionID::bypassCacheSessionID):
* page/Settings.cpp:
(WebCore::Settings::Settings):
* page/Settings.h:
(WebCore::Settings::setUsesMemoryCache):
(WebCore::Settings::usesMemoryCache):
* replay/ReplayController.cpp:
(WebCore::ReplayController::setForceDeterministicSettings):
* replay/ReplayController.h:
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::Backup::Backup):
(WebCore::InternalSettings::Backup::restoreTo):
(WebCore::InternalSettings::setUsesMemoryCache):
* testing/InternalSettings.h:
* testing/InternalSettings.idl:

Source/WebKit2:

* UIProcess/APISession.cpp:
(API::generateID): update the base ID for generating unique sessions.

LayoutTests:

Mac WebKit2 needs different expectations because of resource load timing characteristics
introduced by the interaction of Settings::usesMemoryCache and NetworkProcess.

* http/tests/cache/bypass-memory-cache-after-reload-expected.txt: Added.
* http/tests/cache/bypass-memory-cache-after-reload.html: Added.
* platform/mac-wk2/http/tests/cache/bypass-memory-cache-after-reload-expected.txt: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166434 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/cache/bypass-memory-cache-after-reload-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/cache/bypass-memory-cache-after-reload.html [new file with mode: 0644]
LayoutTests/platform/mac-wk2/http/tests/cache/bypass-memory-cache-after-reload-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/MemoryCache.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/SessionID.h
Source/WebCore/page/Settings.cpp
Source/WebCore/page/Settings.h
Source/WebCore/replay/ReplayController.cpp
Source/WebCore/replay/ReplayController.h
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/APISession.cpp

index 41e2f9c..db57d46 100644 (file)
@@ -1,3 +1,17 @@
+2014-03-28  Brian Burg  <bburg@apple.com>
+
+        Web Replay: add page-level setting to bypass the MemoryCache
+        https://bugs.webkit.org/show_bug.cgi?id=130728
+
+        Reviewed by Timothy Hatcher.
+
+        Mac WebKit2 needs different expectations because of resource load timing characteristics
+        introduced by the interaction of Settings::usesMemoryCache and NetworkProcess.
+
+        * http/tests/cache/bypass-memory-cache-after-reload-expected.txt: Added.
+        * http/tests/cache/bypass-memory-cache-after-reload.html: Added.
+        * platform/mac-wk2/http/tests/cache/bypass-memory-cache-after-reload-expected.txt: Added.
+
 2014-03-28  Radu Stavila  <stavila@adobe.com>
 
         In some situations, partial layouts of floating elements produce incorrect results.
diff --git a/LayoutTests/http/tests/cache/bypass-memory-cache-after-reload-expected.txt b/LayoutTests/http/tests/cache/bypass-memory-cache-after-reload-expected.txt
new file mode 100644 (file)
index 0000000..329100b
--- /dev/null
@@ -0,0 +1,11 @@
+http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html - didFinishLoading
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/cache/resources/random-cached.cgi, main document URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/cache/resources/random-cached.cgi, http status code 200>
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - didFinishLoading
+http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, main document URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http status code 200>
+http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html - didFinishLoading
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/cache/resources/random-cached.cgi, main document URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/cache/resources/random-cached.cgi, http status code 200>
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - didFinishLoading
+FINISHED LOADING
diff --git a/LayoutTests/http/tests/cache/bypass-memory-cache-after-reload.html b/LayoutTests/http/tests/cache/bypass-memory-cache-after-reload.html
new file mode 100644 (file)
index 0000000..b9a42ce
--- /dev/null
@@ -0,0 +1,53 @@
+<body>
+<h1></h1>
+<script>
+// Test that a subresource fetched after onload, following a reload, is
+// not cached if we configure the page's settings to bypass the memory cache.
+if (!sessionStorage.lastRandom) {
+    if (window.testRunner && window.internals) {
+        internals.settings.setUsesMemoryCache(false);
+        testRunner.dumpResourceLoadCallbacks();
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+}
+
+function done(result)
+{
+    delete sessionStorage.lastRandom;
+
+    document.body.innerText = result;
+
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function scriptLoaded()
+{
+    setTimeout(function()
+    {
+        if (!window.randomNumber)
+            done('FAIL: window.randomNumber not defined!');
+        else if (sessionStorage.lastRandom) {
+            // We don't want to compare the actual random numbers because
+            // the request may or may not be cached by the network stack.
+            done('FINISHED LOADING');
+        } else {
+            sessionStorage.lastRandom = randomNumber;
+            location.reload();
+        }
+    }, 0);
+}
+
+onload = function()
+{
+    setTimeout(function()
+    {
+        var s = document.createElement("script");
+        s.src = "resources/random-cached.cgi";
+        s.onload = scriptLoaded;
+        document.body.appendChild(s);
+    }, 0);
+};
+</script>
+</body>
diff --git a/LayoutTests/platform/mac-wk2/http/tests/cache/bypass-memory-cache-after-reload-expected.txt b/LayoutTests/platform/mac-wk2/http/tests/cache/bypass-memory-cache-after-reload-expected.txt
new file mode 100644 (file)
index 0000000..ff9fa49
--- /dev/null
@@ -0,0 +1,14 @@
+http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html - didFinishLoading
+http://127.0.0.1:8000/favicon.ico - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/favicon.ico, main document URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/cache/resources/random-cached.cgi, main document URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/favicon.ico - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/favicon.ico, http status code 200>
+http://127.0.0.1:8000/favicon.ico - didFinishLoading
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/cache/resources/random-cached.cgi, http status code 200>
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - didFinishLoading
+http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, main document URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http status code 200>
+http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html - didFinishLoading
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/cache/resources/random-cached.cgi, main document URL http://127.0.0.1:8000/cache/bypass-memory-cache-after-reload.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/cache/resources/random-cached.cgi, http status code 200>
+http://127.0.0.1:8000/cache/resources/random-cached.cgi - didFinishLoading
+FINISHED LOADING
index b571744..89f90c4 100644 (file)
@@ -1,3 +1,46 @@
+2014-03-28  Brian Burg  <bburg@apple.com>
+
+        Web Replay: add page-level setting to bypass the MemoryCache
+        https://bugs.webkit.org/show_bug.cgi?id=130728
+
+        Reviewed by Timothy Hatcher.
+
+        When replaying a specific Page we don't want to store its cached resources in the
+        MemoryCache. This patch adds a page setting to prevent the page's resources from
+        being saved in the MemoryCache.
+
+        If Settings::usesMemoryCache() is false, page resources are given the special
+        SessionID bypassCacheSessionID(). The cached resource loader and memory cache
+        act as if the memory cache is disabled if the resource has this special session id.
+
+        Hook up ReplayController to override the memory cache setting during capture/replay.
+
+        Test: http/tests/cache/bypass-memory-cache-after-reload.html
+
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::requestResource):
+        (WebCore::CachedResourceLoader::revalidateResource):
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::MemoryCache::add):
+        * page/Page.cpp:
+        (WebCore::Page::sessionID):
+        * page/SessionID.h:
+        (WebCore::SessionID::bypassCacheSessionID):
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings):
+        * page/Settings.h:
+        (WebCore::Settings::setUsesMemoryCache):
+        (WebCore::Settings::usesMemoryCache):
+        * replay/ReplayController.cpp:
+        (WebCore::ReplayController::setForceDeterministicSettings):
+        * replay/ReplayController.h:
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::Backup::Backup):
+        (WebCore::InternalSettings::Backup::restoreTo):
+        (WebCore::InternalSettings::setUsesMemoryCache):
+        * testing/InternalSettings.h:
+        * testing/InternalSettings.idl:
+
 2014-03-28  Radu Stavila  <stavila@adobe.com>
 
         In some situations, partial layouts of floating elements produce incorrect results.
index 601f711..0d75dc3 100644 (file)
@@ -484,7 +484,10 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::requestResource(Cache
         m_validatedURLs.add(request.resourceRequest().url());
 
     ASSERT(resource->url() == url.string());
-    m_documentResources.set(resource->url(), resource);
+
+    if (sessionID() != SessionID::bypassCacheSessionID())
+        m_documentResources.set(resource->url(), resource);
+
     return resource;
 }
 
@@ -496,6 +499,7 @@ CachedResourceHandle<CachedResource> CachedResourceLoader::revalidateResource(co
     ASSERT(resource->canUseCacheValidator());
     ASSERT(!resource->resourceToRevalidate());
     ASSERT(resource->sessionID() == sessionID());
+    ASSERT(sessionID() != SessionID::bypassCacheSessionID());
 
     // Copy the URL out of the resource to be revalidated in case it gets deleted by the remove() call below.
     String url = resource->url();
index a9a0553..378038f 100644 (file)
@@ -110,6 +110,9 @@ bool MemoryCache::add(CachedResource* resource)
     if (disabled())
         return false;
 
+    if (resource->sessionID() == SessionID::bypassCacheSessionID())
+        return false;
+
     ASSERT(WTF::isMainThread());
 
     CachedResourceMap& resources = getSessionMap(resource->sessionID());
index f83cb14..98d96ef 100644 (file)
@@ -1520,6 +1520,9 @@ SessionID Page::sessionID() const
     if (settings().privateBrowsingEnabled())
         return SessionID::legacyPrivateSessionID();
 
+    if (!settings().usesMemoryCache())
+        return SessionID::bypassCacheSessionID();
+
     return SessionID::defaultSessionID();
 }
 
index 5efd74a..c4deb1b 100644 (file)
@@ -43,6 +43,7 @@ public:
     static SessionID emptySessionID() { return SessionID(0); }
     static SessionID defaultSessionID() { return SessionID(1); }
     static SessionID legacyPrivateSessionID() { return SessionID(2); }
+    static SessionID bypassCacheSessionID() { return SessionID(3); }
 private:
     uint64_t m_sessionID;
 };
index 32b5a7f..e7f60e4 100644 (file)
@@ -177,6 +177,7 @@ Settings::Settings(Page* page)
     , m_isScriptEnabled(false)
     , m_needsAdobeFrameReloadingQuirk(false)
     , m_usesPageCache(false)
+    , m_usesMemoryCache(true)
     , m_fontRenderingMode(0)
     , m_showTiledScrollingIndicator(false)
     , m_tiledBackingStoreEnabled(false)
index 516f0dc..458fa34 100644 (file)
@@ -181,7 +181,10 @@ public:
 
     void setUsesPageCache(bool);
     bool usesPageCache() const { return m_usesPageCache; }
-        
+
+    void setUsesMemoryCache(bool usesMemoryCache) { m_usesMemoryCache = usesMemoryCache; }
+    bool usesMemoryCache() const { return m_usesMemoryCache; }
+
     void setFontRenderingMode(FontRenderingMode mode);
     FontRenderingMode fontRenderingMode() const;
 
@@ -307,6 +310,7 @@ private:
     bool m_isScriptEnabled : 1;
     bool m_needsAdobeFrameReloadingQuirk : 1;
     bool m_usesPageCache : 1;
+    bool m_usesMemoryCache : 1;
     unsigned m_fontRenderingMode : 1;
     bool m_showTiledScrollingIndicator : 1;
     bool m_tiledBackingStoreEnabled : 1;
index edfc9eb..00c9c4d 100644 (file)
@@ -71,10 +71,13 @@ void ReplayController::setForceDeterministicSettings(bool shouldForce)
     ASSERT(shouldForce ^ (m_sessionState == SessionState::Inactive));
 
     if (shouldForce) {
+        m_savedSettings.usesMemoryCache = m_page.settings().usesMemoryCache();
         m_savedSettings.usesPageCache = m_page.settings().usesPageCache();
 
+        m_page.settings().setUsesMemoryCache(false);
         m_page.settings().setUsesPageCache(false);
     } else {
+        m_page.settings().setUsesMemoryCache(m_savedSettings.usesMemoryCache);
         m_page.settings().setUsesPageCache(m_savedSettings.usesPageCache);
     }
 }
index ef05771..aff0023 100644 (file)
@@ -154,10 +154,12 @@ private:
     void setForceDeterministicSettings(bool);
 
     struct SavedSettings {
+        bool usesMemoryCache;
         bool usesPageCache;
 
         SavedSettings()
-            : usesPageCache(false)
+            : usesMemoryCache(true)
+            , usesPageCache(false)
         { }
     };
 
index 31bd30c..50ef5a5 100644 (file)
@@ -91,6 +91,7 @@ InternalSettings::Backup::Backup(Settings& settings)
     , m_autoscrollForDragAndDropEnabled(settings.autoscrollForDragAndDropEnabled())
     , m_pluginReplacementEnabled(RuntimeEnabledFeatures::sharedFeatures().pluginReplacementEnabled())
     , m_shouldConvertPositionStyleOnCopy(settings.shouldConvertPositionStyleOnCopy())
+    , m_usesMemoryCache(settings.usesMemoryCache())
 {
 }
 
@@ -149,6 +150,7 @@ void InternalSettings::Backup::restoreTo(Settings& settings)
     settings.setUseLegacyBackgroundSizeShorthandBehavior(m_useLegacyBackgroundSizeShorthandBehavior);
     settings.setAutoscrollForDragAndDropEnabled(m_autoscrollForDragAndDropEnabled);
     settings.setShouldConvertPositionStyleOnCopy(m_shouldConvertPositionStyleOnCopy);
+    settings.setUsesMemoryCache(m_usesMemoryCache);
     RuntimeEnabledFeatures::sharedFeatures().setPluginReplacementEnabled(m_pluginReplacementEnabled);
 }
 
@@ -493,4 +495,10 @@ void InternalSettings::setShouldConvertPositionStyleOnCopy(bool convert, Excepti
     settings()->setShouldConvertPositionStyleOnCopy(convert);
 }
 
+void InternalSettings::setUsesMemoryCache(bool usesMemoryCache, ExceptionCode& ec)
+{
+    InternalSettingsGuardForSettings();
+    settings()->setUsesMemoryCache(usesMemoryCache);
+}
+
 }
index 7307383..ed89558 100644 (file)
@@ -88,6 +88,7 @@ public:
         bool m_autoscrollForDragAndDropEnabled;
         bool m_pluginReplacementEnabled;
         bool m_shouldConvertPositionStyleOnCopy;
+        bool m_usesMemoryCache;
     };
 
     static PassRefPtr<InternalSettings> create(Page* page)
@@ -132,7 +133,7 @@ public:
     void setPluginReplacementEnabled(bool);
     void setBackgroundShouldExtendBeyondPage(bool hasExtendedBackground, ExceptionCode&);
     void setShouldConvertPositionStyleOnCopy(bool convert, ExceptionCode&);
-
+    void setUsesMemoryCache(bool usesMemoryCache, ExceptionCode&);
 
 private:
     explicit InternalSettings(Page*);
index 1dd6fa7..0f6b5e2 100644 (file)
@@ -59,4 +59,5 @@
     void setPluginReplacementEnabled(boolean enabled);
     [RaisesException] void setBackgroundShouldExtendBeyondPage(boolean hasExtendedBackground);
     [RaisesException] void setShouldConvertPositionStyleOnCopy(boolean convert);
+    [RaisesException] void setUsesMemoryCache(boolean usesMemoryCache);
 };
index 887f60f..1ed3dc4 100644 (file)
@@ -1,3 +1,13 @@
+2014-03-28  Brian Burg  <bburg@apple.com>
+
+        Web Replay: add page-level setting to bypass the MemoryCache
+        https://bugs.webkit.org/show_bug.cgi?id=130728
+
+        Reviewed by Timothy Hatcher.
+
+        * UIProcess/APISession.cpp:
+        (API::generateID): update the base ID for generating unique sessions.
+
 2014-03-28  Cody Krieger  <cjk@apple.com>
 
         Add willSubmitForm callback support to WKWebProcessPlugInFormDelegatePrivate.
index 55861b4..d7a9251 100644 (file)
@@ -34,7 +34,7 @@ static uint64_t generateID(bool isEphemeral)
 {
     ASSERT(RunLoop::isMain());
 
-    static uint64_t uniqueSessionID = WebCore::SessionID::legacyPrivateSessionID().sessionID();
+    static uint64_t uniqueSessionID = WebCore::SessionID::bypassCacheSessionID().sessionID();
     ASSERT_UNUSED(isEphemeral, isEphemeral);
     return ++uniqueSessionID;
 }