Title: [145161] trunk/Source
Revision
145161
Author
jp...@apple.com
Date
2013-03-07 17:10:54 -0800 (Thu, 07 Mar 2013)

Log Message

CFNetwork cache partitioning does not work properly on subdomains
https://bugs.webkit.org/show_bug.cgi?id=111772

Reviewed by David Kilzer.

Source/WebCore:

Ensure that the cache partitioning is done over the top privately-controlled domain for the NSURLRequest.

Not possible to test with current automated test tools, must be tested manually.

* loader/cache/MemoryCache.cpp: Remove extraneous calls to partitionName
(WebCore):
(WebCore::MemoryCache::add):
(WebCore::MemoryCache::revalidationSucceeded):
(WebCore::MemoryCache::resourceForRequest):
(WebCore::MemoryCache::evict):
(WebCore::MemoryCache::removeResourcesWithOrigin):
* platform/network/cf/ResourceRequest.h: Put top privately-controlled domain reduction code into ResourceRequest::partitionName
(ResourceRequest):
(WebCore::ResourceRequest::cachePartition):
(WebCore::ResourceRequest::setCachePartition): Pre-process the partition name
* platform/network/cf/ResourceRequestCFNet.cpp:
(WebCore):
(WebCore::ResourceRequest::partitionName):
* platform/network/mac/ResourceRequestMac.mm:
(WebCore::ResourceRequest::doUpdatePlatformRequest): Use a UTF-8 version of the cache partition name

Source/WebKit2:

Ensure that the CFString is UTF-8 so that WKCFURLCacheCopyAllHostNamesInPersistentStoreForPartition will always work.

* WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp:
(WebKit::partitionName): Create a UTF-8 CFString explicitly

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (145160 => 145161)


--- trunk/Source/WebCore/ChangeLog	2013-03-08 01:06:58 UTC (rev 145160)
+++ trunk/Source/WebCore/ChangeLog	2013-03-08 01:10:54 UTC (rev 145161)
@@ -1,3 +1,31 @@
+2013-03-07  Jeffrey Pfau  <jp...@apple.com>
+
+        CFNetwork cache partitioning does not work properly on subdomains
+        https://bugs.webkit.org/show_bug.cgi?id=111772
+
+        Reviewed by David Kilzer.
+
+        Ensure that the cache partitioning is done over the top privately-controlled domain for the NSURLRequest.
+
+        Not possible to test with current automated test tools, must be tested manually.
+
+        * loader/cache/MemoryCache.cpp: Remove extraneous calls to partitionName
+        (WebCore):
+        (WebCore::MemoryCache::add):
+        (WebCore::MemoryCache::revalidationSucceeded):
+        (WebCore::MemoryCache::resourceForRequest):
+        (WebCore::MemoryCache::evict):
+        (WebCore::MemoryCache::removeResourcesWithOrigin):
+        * platform/network/cf/ResourceRequest.h: Put top privately-controlled domain reduction code into ResourceRequest::partitionName
+        (ResourceRequest):
+        (WebCore::ResourceRequest::cachePartition):
+        (WebCore::ResourceRequest::setCachePartition): Pre-process the partition name
+        * platform/network/cf/ResourceRequestCFNet.cpp:
+        (WebCore):
+        (WebCore::ResourceRequest::partitionName):
+        * platform/network/mac/ResourceRequestMac.mm:
+        (WebCore::ResourceRequest::doUpdatePlatformRequest): Use a UTF-8 version of the cache partition name
+
 2013-03-07  Kenneth Russell  <k...@google.com>
 
         Compute WebGL context attributes from DrawingBuffer when it is used

Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (145160 => 145161)


--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2013-03-08 01:06:58 UTC (rev 145160)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2013-03-08 01:10:54 UTC (rev 145161)
@@ -57,22 +57,6 @@
 static const float cTargetPrunePercentage = .95f; // Percentage of capacity toward which we prune, to avoid immediately pruning again.
 static const double cDefaultDecodedDataDeletionInterval = 0;
 
-#if ENABLE(CACHE_PARTITIONING)
-static String partitionName(String domain)
-{
-    if (domain.isNull())
-        return emptyString();
-#if ENABLE(PUBLIC_SUFFIX_LIST)
-    String highLevel = topPrivatelyControlledDomain(domain);
-    if (highLevel.isNull())
-        return emptyString();
-    return highLevel;
-#else
-    return domain;
-#endif
-}
-#endif
-
 MemoryCache* memoryCache()
 {
     static MemoryCache* staticCache = new MemoryCache;
@@ -121,7 +105,7 @@
         originMap = new CachedResourceItem;
         m_resources.set(resource->url(), adoptPtr(originMap));
     }
-    originMap->set(partitionName(resource->cachePartition()), resource);
+    originMap->set(resource->cachePartition(), resource);
 #else
     m_resources.set(resource->url(), resource);
 #endif
@@ -149,13 +133,13 @@
     evict(revalidatingResource);
 
 #if ENABLE(CACHE_PARTITIONING)
-    ASSERT(!m_resources.get(resource->url()) || !m_resources.get(resource->url())->get(partitionName(resource->cachePartition())));
+    ASSERT(!m_resources.get(resource->url()) || !m_resources.get(resource->url())->get(resource->cachePartition()));
     CachedResourceItem* originMap = m_resources.get(resource->url());
     if (!originMap) {
         originMap = new CachedResourceItem;
         m_resources.set(resource->url(), adoptPtr(originMap));
     }
-    originMap->set(partitionName(resource->cachePartition()), resource);
+    originMap->set(resource->cachePartition(), resource);
 #else
     ASSERT(!m_resources.get(resource->url()));
     m_resources.set(resource->url(), resource);
@@ -196,7 +180,7 @@
     CachedResourceItem* item = m_resources.get(url);
     CachedResource* resource = 0;
     if (item)
-        resource = item->get(partitionName(request.cachePartition()));
+        resource = item->get(request.cachePartition());
 #else
     CachedResource* resource = m_resources.get(url);
 #endif
@@ -441,7 +425,7 @@
 #if ENABLE(CACHE_PARTITIONING)
         CachedResourceItem* item = m_resources.get(resource->url());
         if (item) {
-            item->remove(partitionName(resource->cachePartition()));
+            item->remove(resource->cachePartition());
             if (!item->size())
                 m_resources.remove(resource->url());
         }
@@ -461,7 +445,7 @@
             adjustSize(resource->hasClients(), -static_cast<int>(resource->size()));
     } else
 #if ENABLE(CACHE_PARTITIONING)
-        ASSERT(!m_resources.get(resource->url()) || m_resources.get(resource->url())->get(partitionName(resource->cachePartition())) != resource);
+        ASSERT(!m_resources.get(resource->url()) || m_resources.get(resource->url())->get(resource->cachePartition()) != resource);
 #else
         ASSERT(m_resources.get(resource->url()) != resource);
 #endif
@@ -585,7 +569,7 @@
 
     CachedResourceMap::iterator e = m_resources.end();
 #if ENABLE(CACHE_PARTITIONING)
-    String originPartition = partitionName(origin->host());
+    String originPartition = ResourceRequest::partitionName(origin->host());
 #endif
 
     for (CachedResourceMap::iterator it = m_resources.begin(); it != e; ++it) {

Modified: trunk/Source/WebCore/platform/network/cf/ResourceRequest.h (145160 => 145161)


--- trunk/Source/WebCore/platform/network/cf/ResourceRequest.h	2013-03-08 01:06:58 UTC (rev 145160)
+++ trunk/Source/WebCore/platform/network/cf/ResourceRequest.h	2013-03-08 01:10:54 UTC (rev 145161)
@@ -97,8 +97,9 @@
 #endif
 
 #if ENABLE(CACHE_PARTITIONING)
-        const String& cachePartition() const { return m_cachePartition; }
-        void setCachePartition(const String& cachePartition) { m_cachePartition = cachePartition; }
+        static String partitionName(const String& domain);
+        const String& cachePartition() const { return m_cachePartition.isNull() ? emptyString() : m_cachePartition; }
+        void setCachePartition(const String& cachePartition) { m_cachePartition = partitionName(cachePartition); }
 #endif
 
 #if PLATFORM(MAC) || USE(CFNETWORK)

Modified: trunk/Source/WebCore/platform/network/cf/ResourceRequestCFNet.cpp (145160 => 145161)


--- trunk/Source/WebCore/platform/network/cf/ResourceRequestCFNet.cpp	2013-03-08 01:06:58 UTC (rev 145160)
+++ trunk/Source/WebCore/platform/network/cf/ResourceRequestCFNet.cpp	2013-03-08 01:10:54 UTC (rev 145161)
@@ -29,6 +29,10 @@
 #include "ResourceHandle.h"
 #include "ResourceRequest.h"
 
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+#include "PublicSuffix.h"
+#endif
+
 #if USE(CFNETWORK)
 #include "FormDataStreamCFNet.h"
 #include <CFNetwork/CFURLRequestPriv.h>
@@ -305,6 +309,22 @@
     s_httpPipeliningEnabled = flag;
 }
 
+#if ENABLE(CACHE_PARTITIONING)
+String ResourceRequest::partitionName(const String& domain)
+{
+    if (domain.isNull())
+        return emptyString();
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+    String highLevel = topPrivatelyControlledDomain(domain);
+    if (highLevel.isNull())
+        return emptyString();
+    return highLevel;
+#else
+    return domain;
+#endif
+}
+#endif
+
 PassOwnPtr<CrossThreadResourceRequestData> ResourceRequest::doPlatformCopyData(PassOwnPtr<CrossThreadResourceRequestData> data) const
 {
 #if ENABLE(CACHE_PARTITIONING)

Modified: trunk/Source/WebCore/platform/network/mac/ResourceRequestMac.mm (145160 => 145161)


--- trunk/Source/WebCore/platform/network/mac/ResourceRequestMac.mm	2013-03-08 01:06:58 UTC (rev 145160)
+++ trunk/Source/WebCore/platform/network/mac/ResourceRequestMac.mm	2013-03-08 01:10:54 UTC (rev 145161)
@@ -30,6 +30,7 @@
 #import "ResourceRequestCFNet.h"
 #import "RuntimeApplicationChecks.h"
 #import "WebCoreSystemInterface.h"
+#import <wtf/text/CString.h>
 
 #import <Foundation/Foundation.h>
 
@@ -187,7 +188,11 @@
     }
 
 #if ENABLE(CACHE_PARTITIONING)
-    [NSURLProtocol setProperty:m_cachePartition forKey:(NSString *)wkCachePartitionKey() inRequest:nsRequest];
+    String partition = cachePartition();
+    if (!partition.isNull() && !partition.isEmpty()) {
+        NSString *partitionValue = [NSString stringWithUTF8String:partition.utf8().data()];
+        [NSURLProtocol setProperty:partitionValue forKey:(NSString *)wkCachePartitionKey() inRequest:nsRequest];
+    }
 #endif
 
     m_nsRequest.adoptNS(nsRequest);

Modified: trunk/Source/WebKit2/ChangeLog (145160 => 145161)


--- trunk/Source/WebKit2/ChangeLog	2013-03-08 01:06:58 UTC (rev 145160)
+++ trunk/Source/WebKit2/ChangeLog	2013-03-08 01:10:54 UTC (rev 145161)
@@ -1,3 +1,15 @@
+2013-03-07  Jeffrey Pfau  <jp...@apple.com>
+
+        CFNetwork cache partitioning does not work properly on subdomains
+        https://bugs.webkit.org/show_bug.cgi?id=111772
+
+        Reviewed by David Kilzer.
+
+        Ensure that the CFString is UTF-8 so that WKCFURLCacheCopyAllHostNamesInPersistentStoreForPartition will always work.
+
+        * WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp:
+        (WebKit::partitionName): Create a UTF-8 CFString explicitly
+
 2013-03-07  Beth Dakin  <bda...@apple.com>
 
         Need API to draw custom overhang area

Modified: trunk/Source/WebKit2/WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp (145160 => 145161)


--- trunk/Source/WebKit2/WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp	2013-03-08 01:06:58 UTC (rev 145160)
+++ trunk/Source/WebKit2/WebProcess/ResourceCache/cf/WebResourceCacheManagerCFNet.cpp	2013-03-08 01:10:54 UTC (rev 145161)
@@ -30,6 +30,7 @@
 
 #if ENABLE(CACHE_PARTITIONING)
 #include <WebCore/PublicSuffix.h>
+#include <wtf/text/CString.h>
 #endif
 
 #if PLATFORM(MAC)
@@ -46,7 +47,8 @@
     String highLevel = WebCore::topPrivatelyControlledDomain(domain);
     if (highLevel.isNull())
         return 0;
-    return highLevel.createCFString();
+    CString utf8String = highLevel.utf8();
+    return adoptCF(CFStringCreateWithBytes(0, reinterpret_cast<const UInt8*>(utf8String.data()), utf8String.length(), kCFStringEncodingUTF8, false));
 #else
     return domain;
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to