Title: [196822] trunk/Source/WebCore
Revision
196822
Author
[email protected]
Date
2016-02-19 10:05:55 -0800 (Fri, 19 Feb 2016)

Log Message

Allow CachedRawResource clients to opt out of caching on a per-response basis
https://bugs.webkit.org/show_bug.cgi?id=154453

Reviewed by Brady Eidson.

For CF or NS networking clients, the system loader will ask whether the client (the
SubResourceLoader in this case) wants the response to be cached. This breaks for byte
range requests due to <rdar://problem/20001985>. Allow the SubresourceLoader to query
its clients, and return null, if they opt out.

* loader/cache/CachedRawResource.cpp:
(WebCore::CachedRawResource::shouldCacheResponse):
* loader/cache/CachedRawResource.h:
* loader/cache/CachedRawResourceClient.h:
(WebCore::CachedRawResourceClient::shouldCacheResponse):
* loader/cache/CachedResource.h:
(WebCore::CachedResource::shouldCacheResponse):
* loader/cocoa/SubresourceLoaderCocoa.mm:
(WebCore::SubresourceLoader::willCacheResponse):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (196821 => 196822)


--- trunk/Source/WebCore/ChangeLog	2016-02-19 17:35:52 UTC (rev 196821)
+++ trunk/Source/WebCore/ChangeLog	2016-02-19 18:05:55 UTC (rev 196822)
@@ -1,3 +1,25 @@
+2016-02-19  Jer Noble  <[email protected]>
+
+        Allow CachedRawResource clients to opt out of caching on a per-response basis
+        https://bugs.webkit.org/show_bug.cgi?id=154453
+
+        Reviewed by Brady Eidson.
+
+        For CF or NS networking clients, the system loader will ask whether the client (the
+        SubResourceLoader in this case) wants the response to be cached. This breaks for byte
+        range requests due to <rdar://problem/20001985>. Allow the SubresourceLoader to query
+        its clients, and return null, if they opt out.
+
+        * loader/cache/CachedRawResource.cpp:
+        (WebCore::CachedRawResource::shouldCacheResponse):
+        * loader/cache/CachedRawResource.h:
+        * loader/cache/CachedRawResourceClient.h:
+        (WebCore::CachedRawResourceClient::shouldCacheResponse):
+        * loader/cache/CachedResource.h:
+        (WebCore::CachedResource::shouldCacheResponse):
+        * loader/cocoa/SubresourceLoaderCocoa.mm:
+        (WebCore::SubresourceLoader::willCacheResponse):
+
 2016-02-19  Zalan Bujtas  <[email protected]>
 
         Blocked plug-in placeholder is sometimes not shown.

Modified: trunk/Source/WebCore/loader/cache/CachedRawResource.cpp (196821 => 196822)


--- trunk/Source/WebCore/loader/cache/CachedRawResource.cpp	2016-02-19 17:35:52 UTC (rev 196821)
+++ trunk/Source/WebCore/loader/cache/CachedRawResource.cpp	2016-02-19 18:05:55 UTC (rev 196822)
@@ -186,6 +186,16 @@
         c->responseReceived(this, m_response);
 }
 
+bool CachedRawResource::shouldCacheResponse(const ResourceResponse& response)
+{
+    CachedResourceClientWalker<CachedRawResourceClient> w(m_clients);
+    while (CachedRawResourceClient* c = w.next()) {
+        if (!c->shouldCacheResponse(this, response))
+            return false;
+    }
+    return true;
+}
+
 void CachedRawResource::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
 {
     CachedResourceClientWalker<CachedRawResourceClient> w(m_clients);

Modified: trunk/Source/WebCore/loader/cache/CachedRawResource.h (196821 => 196822)


--- trunk/Source/WebCore/loader/cache/CachedRawResource.h	2016-02-19 17:35:52 UTC (rev 196821)
+++ trunk/Source/WebCore/loader/cache/CachedRawResource.h	2016-02-19 18:05:55 UTC (rev 196822)
@@ -61,6 +61,7 @@
 
     virtual void redirectReceived(ResourceRequest&, const ResourceResponse&) override;
     virtual void responseReceived(const ResourceResponse&) override;
+    virtual bool shouldCacheResponse(const ResourceResponse&) override;
     virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override;
 
     virtual void switchClientsToRevalidatedResource() override;

Modified: trunk/Source/WebCore/loader/cache/CachedRawResourceClient.h (196821 => 196822)


--- trunk/Source/WebCore/loader/cache/CachedRawResourceClient.h	2016-02-19 17:35:52 UTC (rev 196821)
+++ trunk/Source/WebCore/loader/cache/CachedRawResourceClient.h	2016-02-19 18:05:55 UTC (rev 196822)
@@ -39,6 +39,7 @@
 
     virtual void dataSent(CachedResource*, unsigned long long /* bytesSent */, unsigned long long /* totalBytesToBeSent */) { }
     virtual void responseReceived(CachedResource*, const ResourceResponse&) { }
+    virtual bool shouldCacheResponse(CachedResource*, const ResourceResponse&) { return true; }
     virtual void dataReceived(CachedResource*, const char* /* data */, int /* length */) { }
     virtual void redirectReceived(CachedResource*, ResourceRequest&, const ResourceResponse&) { }
 #if USE(SOUP)

Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (196821 => 196822)


--- trunk/Source/WebCore/loader/cache/CachedResource.h	2016-02-19 17:35:52 UTC (rev 196821)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h	2016-02-19 18:05:55 UTC (rev 196822)
@@ -194,6 +194,7 @@
 
     virtual void redirectReceived(ResourceRequest&, const ResourceResponse&);
     virtual void responseReceived(const ResourceResponse&);
+    virtual bool shouldCacheResponse(const ResourceResponse&) { return true; }
     void setResponse(const ResourceResponse& response) { m_response = response; }
     const ResourceResponse& response() const { return m_response; }
     // This is the same as response() except after HTTP redirect to data: URL.

Modified: trunk/Source/WebCore/loader/cocoa/SubresourceLoaderCocoa.mm (196821 => 196822)


--- trunk/Source/WebCore/loader/cocoa/SubresourceLoaderCocoa.mm	2016-02-19 17:35:52 UTC (rev 196821)
+++ trunk/Source/WebCore/loader/cocoa/SubresourceLoaderCocoa.mm	2016-02-19 18:05:55 UTC (rev 196822)
@@ -40,6 +40,8 @@
 CFCachedURLResponseRef SubresourceLoader::willCacheResponse(ResourceHandle* handle, CFCachedURLResponseRef cachedResponse)
 {
     DiskCacheMonitor::monitorFileBackingStoreCreation(request(), m_resource->sessionID(), cachedResponse);
+    if (!m_resource->shouldCacheResponse(CFCachedURLResponseGetWrappedResponse(cachedResponse))
+        return nullptr;
     return ResourceLoader::willCacheResponse(handle, cachedResponse);
 }
 
@@ -48,6 +50,8 @@
 NSCachedURLResponse* SubresourceLoader::willCacheResponse(ResourceHandle* handle, NSCachedURLResponse* response)
 {
     DiskCacheMonitor::monitorFileBackingStoreCreation(request(), m_resource->sessionID(), [response _CFCachedURLResponse]);
+    if (!m_resource->shouldCacheResponse(response.response))
+        return nullptr;
     return ResourceLoader::willCacheResponse(handle, response);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to