WebKit2: Use CFNetwork Sessions API.
authorjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Mar 2011 18:39:18 +0000 (18:39 +0000)
committerjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Mar 2011 18:39:18 +0000 (18:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=55435.

Reviewed by Sam Weinig.

Source/WebCore:

When Private Browsing is enabled, use cookies from a in-memory cookie storage based on the
Private Browsing Storage Session.

* WebCore.exp.in:
Add the new WKSI functions.
* platform/mac/WebCoreSystemInterface.h:
Ditto.
* platform/mac/WebCoreSystemInterface.mm:
Ditto.

* platform/mac/CookieJar.mm:
(WebCore::cookies):
If USE(CFURLSTORAGESESSIONS) and there is a Private Browsing Cookie Storage, call into WKSI.
Otherwise, behave the same as before.
(WebCore::cookieRequestHeaderFieldValue):
Ditto.
(WebCore::setCookies):
Ditto.
(WebCore::cookiesEnabled):
Ditto
(WebCore::getRawCookies):
Ditto.
(WebCore::deleteCookie):
Ditto.

* platform/network/CookieStorage.h:
* platform/network/cf/CookieStorageCFNet.cpp:
(WebCore::privateBrowsingCookieStorage):
Keep track of the Private Browsing Cookie Storage in a locally defined static inside a
function instead of at the global scope.
(WebCore::currentCookieStorage):
Use privateBrowsingCookieStorage.
(WebCore::setCurrentCookieStorage):
Ditto.
(WebCore::setCookieStoragePrivateBrowsingEnabled):
If USE(CFURLSTORAGESESSIONS), send the Private Browsing Storage Session to
wkCreatePrivateInMemoryHTTPCookieStorage.
* platform/network/mac/CookieStorageMac.mm:
(WebCore::privateBrowsingCookieStorage):
Keep track of the Private Browsing Cookie Storage.
(WebCore::setCookieStoragePrivateBrowsingEnabled):
If USE(CFURLSTORAGESESSIONS), then set or clear privateBrowsingCookieStorage().
Added a FIXME to observe changes to the Private Browsing Cookie Storage when it is defined.

* platform/network/mac/ResourceHandleMac.mm:
(WebCore::shouldRelaxThirdPartyCookiePolicy):
Refactor the logic to determine whether or not to relax the third party cookie policy here.
If USE(CFURLSTORAGESESSIONS), then get the information from the privateBrowsingCookieStorage.
(WebCore::ResourceHandle::createNSURLConnection):
Use shouldRelaxThirdPartyCookiePolicy.
(WebCore::ResourceHandle::loadResourceSynchronously):
Ditto.

Source/WebKit/mac:

When Private Browsing is enabled, use cookies from a in-memory cookie storage based on the
Private Browsing Storage Session.

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
Add support for using the new WKSI functions in WebCore.

Source/WebKit2:

When Private Browsing is enabled, use cookies from a in-memory cookie storage based on the
Private Browsing Storage Session.

* WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
(InitWebCoreSystemInterface):
Add support for using the new WKSI functions in WebCore.

WebKitLibraries:

When Private Browsing is enabled, use cookies from a in-memory Cookie Storage based on the
Private Browsing Storage Session.

Update WebKitSystemInterface headers and libraries with the new functions.

* WebKitSystemInterface.h:
* libWebKitSystemInterfaceLeopard.a:
* libWebKitSystemInterfaceSnowLeopard.a:
* win/include/WebKitSystemInterface/WebKitSystemInterface.h:
* win/lib/WebKitSystemInterface.lib:

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

19 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/mac/CookieJar.mm
Source/WebCore/platform/mac/WebCoreSystemInterface.h
Source/WebCore/platform/mac/WebCoreSystemInterface.mm
Source/WebCore/platform/network/CookieStorage.h
Source/WebCore/platform/network/cf/CookieStorageCFNet.cpp
Source/WebCore/platform/network/mac/CookieStorageMac.mm
Source/WebCore/platform/network/mac/ResourceHandleMac.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm
WebKitLibraries/ChangeLog
WebKitLibraries/WebKitSystemInterface.h
WebKitLibraries/libWebKitSystemInterfaceLeopard.a
WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a
WebKitLibraries/win/include/WebKitSystemInterface/WebKitSystemInterface.h
WebKitLibraries/win/lib/WebKitSystemInterface.lib

index d2348fa..ac92b36 100644 (file)
@@ -1,3 +1,63 @@
+2011-03-06  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        WebKit2: Use CFNetwork Sessions API.
+        https://bugs.webkit.org/show_bug.cgi?id=55435.
+
+        When Private Browsing is enabled, use cookies from a in-memory cookie storage based on the
+        Private Browsing Storage Session.
+
+        * WebCore.exp.in:
+        Add the new WKSI functions.
+        * platform/mac/WebCoreSystemInterface.h:
+        Ditto.
+        * platform/mac/WebCoreSystemInterface.mm:
+        Ditto.
+
+        * platform/mac/CookieJar.mm:
+        (WebCore::cookies):
+        If USE(CFURLSTORAGESESSIONS) and there is a Private Browsing Cookie Storage, call into WKSI.
+        Otherwise, behave the same as before.
+        (WebCore::cookieRequestHeaderFieldValue):
+        Ditto.
+        (WebCore::setCookies):
+        Ditto.
+        (WebCore::cookiesEnabled):
+        Ditto
+        (WebCore::getRawCookies):
+        Ditto.
+        (WebCore::deleteCookie):
+        Ditto.
+
+        * platform/network/CookieStorage.h:
+        * platform/network/cf/CookieStorageCFNet.cpp:
+        (WebCore::privateBrowsingCookieStorage):
+        Keep track of the Private Browsing Cookie Storage in a locally defined static inside a
+        function instead of at the global scope.
+        (WebCore::currentCookieStorage):
+        Use privateBrowsingCookieStorage.
+        (WebCore::setCurrentCookieStorage):
+        Ditto.
+        (WebCore::setCookieStoragePrivateBrowsingEnabled):
+        If USE(CFURLSTORAGESESSIONS), send the Private Browsing Storage Session to
+        wkCreatePrivateInMemoryHTTPCookieStorage.
+        * platform/network/mac/CookieStorageMac.mm:
+        (WebCore::privateBrowsingCookieStorage):
+        Keep track of the Private Browsing Cookie Storage.
+        (WebCore::setCookieStoragePrivateBrowsingEnabled):
+        If USE(CFURLSTORAGESESSIONS), then set or clear privateBrowsingCookieStorage().
+        Added a FIXME to observe changes to the Private Browsing Cookie Storage when it is defined.
+
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::shouldRelaxThirdPartyCookiePolicy):
+        Refactor the logic to determine whether or not to relax the third party cookie policy here.
+        If USE(CFURLSTORAGESESSIONS), then get the information from the privateBrowsingCookieStorage.
+        (WebCore::ResourceHandle::createNSURLConnection):
+        Use shouldRelaxThirdPartyCookiePolicy.
+        (WebCore::ResourceHandle::loadResourceSynchronously):
+        Ditto.
+
 2011-03-05  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r80428.
index 3465f20..596756c 100644 (file)
@@ -1340,6 +1340,11 @@ _wkSignalCFReadStreamError
 _wkSignalCFReadStreamHasBytes
 _wkCreatePrivateStorageSession
 _wkCopyRequestWithStorageSession
+_wkCreatePrivateInMemoryHTTPCookieStorage
+_wkGetHTTPCookieAcceptPolicy
+_wkHTTPCookiesForURL
+_wkSetHTTPCookiesForURL
+_wkDeleteHTTPCookie
 
 #if !defined(NDEBUG)
 __ZN7WebCore20LogNotYetImplementedE
index 2864228..e788949 100644 (file)
 
 #import "BlockExceptions.h"
 #import "Cookie.h"
+#import "CookieStorage.h"
 #import "Document.h"
 #import "KURL.h"
+#import "WebCoreSystemInterface.h"
 #import <wtf/RetainPtr.h>
 
 #ifdef BUILDING_ON_TIGER
@@ -79,7 +81,14 @@ String cookies(const Document*, const KURL& url)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSURL *cookieURL = url;
-    NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
+    NSArray *cookies;
+#if USE(CFURLSTORAGESESSIONS)
+    if (CFHTTPCookieStorageRef cookieStorage = privateBrowsingCookieStorage().get())
+        cookies = wkHTTPCookiesForURL(cookieStorage, cookieURL);
+    else
+#endif
+        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
+
     return [[NSHTTPCookie requestHeaderFieldsWithCookies:filterCookies(cookies).get()] objectForKey:@"Cookie"];
 
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -91,7 +100,14 @@ String cookieRequestHeaderFieldValue(const Document*, const KURL& url)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSURL *cookieURL = url;
-    NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
+    NSArray *cookies;
+#if USE(CFURLSTORAGESESSIONS)
+    if (CFHTTPCookieStorageRef cookieStorage = privateBrowsingCookieStorage().get())
+        cookies = wkHTTPCookiesForURL(cookieStorage, cookieURL);
+    else
+#endif
+        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
+
     return [[NSHTTPCookie requestHeaderFieldsWithCookies:cookies] objectForKey:@"Cookie"];
 
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -112,8 +128,14 @@ void setCookies(Document* document, const KURL& url, const String& cookieStr)
     String cookieString = cookieStr.contains('=') ? cookieStr : cookieStr + "=";
 
     NSURL *cookieURL = url;    
-    NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:[NSDictionary dictionaryWithObject:cookieString forKey:@"Set-Cookie"] forURL:cookieURL];
-    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:filterCookies(cookies).get() forURL:cookieURL mainDocumentURL:document->firstPartyForCookies()];
+    RetainPtr<NSArray> filteredCookies = filterCookies([NSHTTPCookie cookiesWithResponseHeaderFields:[NSDictionary dictionaryWithObject:cookieString forKey:@"Set-Cookie"] forURL:cookieURL]);
+
+#if USE(CFURLSTORAGESESSIONS)
+    if (CFHTTPCookieStorageRef cookieStorage = privateBrowsingCookieStorage().get())
+        wkSetHTTPCookiesForURL(cookieStorage, filteredCookies.get(), cookieURL, document->firstPartyForCookies());
+    else
+#endif
+        [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:filteredCookies.get() forURL:cookieURL mainDocumentURL:document->firstPartyForCookies()];
 
     END_BLOCK_OBJC_EXCEPTIONS;
 }
@@ -122,7 +144,14 @@ bool cookiesEnabled(const Document*)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    NSHTTPCookieAcceptPolicy cookieAcceptPolicy = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookieAcceptPolicy];
+    NSHTTPCookieAcceptPolicy cookieAcceptPolicy;
+#if USE(CFURLSTORAGESESSIONS)
+    if (CFHTTPCookieStorageRef cookieStorage = privateBrowsingCookieStorage().get())
+        cookieAcceptPolicy = wkGetHTTPCookieAcceptPolicy(cookieStorage);
+    else
+#endif
+        cookieAcceptPolicy = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookieAcceptPolicy];
+
     return cookieAcceptPolicy == NSHTTPCookieAcceptPolicyAlways || cookieAcceptPolicy == NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
 
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -135,7 +164,13 @@ bool getRawCookies(const Document*, const KURL& url, Vector<Cookie>& rawCookies)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSURL *cookieURL = url;
-    NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
+    NSArray *cookies;
+#if USE(CFURLSTORAGESESSIONS)
+    if (CFHTTPCookieStorageRef cookieStorage = privateBrowsingCookieStorage().get())
+        cookies = wkHTTPCookiesForURL(cookieStorage, cookieURL);
+    else
+#endif
+        cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:cookieURL];
 
     NSUInteger count = [cookies count];
     rawCookies.reserveCapacity(count);
@@ -162,14 +197,27 @@ void deleteCookie(const Document*, const KURL& url, const String& cookieName)
 
     NSURL *cookieURL = url;
     NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
-    NSArray *cookies = [cookieStorage cookiesForURL:cookieURL];
+    NSArray *cookies;
+#if USE(CFURLSTORAGESESSIONS)
+    CFHTTPCookieStorageRef cfCookieStorage = privateBrowsingCookieStorage().get();
+    if (cfCookieStorage)
+        cookies = wkHTTPCookiesForURL(cfCookieStorage, cookieURL);
+    else
+#endif
+        cookies = [cookieStorage cookiesForURL:cookieURL];
+
     NSString *cookieNameString = (NSString *) cookieName;
 
     NSUInteger count = [cookies count];
     for (NSUInteger i = 0; i < count; ++i) {
         NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i];
         if ([[cookie name] isEqualToString:cookieNameString]) {
-            [cookieStorage deleteCookie:cookie];
+#if USE(CFURLSTORAGESESSIONS)
+            if (cfCookieStorage)
+                wkDeleteHTTPCookie(cfCookieStorage, cookie);
+            else
+#endif
+                [cookieStorage deleteCookie:cookie];
             break;
         }
     }
index a175f5e..df65ff2 100644 (file)
@@ -50,11 +50,13 @@ typedef struct _NSRect NSRect;
 @class NSDate;
 @class NSEvent;
 @class NSFont;
+@class NSHTTPCookie;
 @class NSImage;
 @class NSMenu;
 @class NSMutableURLRequest;
 @class NSString;
 @class NSTextFieldCell;
+@class NSURL;
 @class NSURLConnection;
 @class NSURLRequest;
 @class NSURLResponse;
@@ -68,10 +70,12 @@ class NSData;
 class NSDate;
 class NSEvent;
 class NSFont;
+class NSHTTPCookie;
 class NSImage;
 class NSMenu;
 class NSMutableArray;
 class NSMutableURLRequest;
+class NSURL;
 class NSURLRequest;
 class NSString;
 class NSTextFieldCell;
@@ -239,6 +243,13 @@ typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
 extern CFURLStorageSessionRef (*wkCreatePrivateStorageSession)(CFStringRef);
 extern NSURLRequest* (*wkCopyRequestWithStorageSession)(CFURLStorageSessionRef, NSURLRequest*);
 
+typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
+extern CFHTTPCookieStorageRef (*wkCreatePrivateInMemoryHTTPCookieStorage)(CFURLStorageSessionRef);
+extern unsigned (*wkGetHTTPCookieAcceptPolicy)(CFHTTPCookieStorageRef);
+extern NSArray *(*wkHTTPCookiesForURL)(CFHTTPCookieStorageRef, NSURL *);
+extern void (*wkSetHTTPCookiesForURL)(CFHTTPCookieStorageRef, NSArray *, NSURL *, NSURL *);
+extern void (*wkDeleteHTTPCookie)(CFHTTPCookieStorageRef, NSHTTPCookie *);
+
 }
 
 #endif
index beba334..50ac236 100644 (file)
@@ -174,3 +174,8 @@ AXUIElementRef (*wkCreateAXUIElementRef)(id element);
 
 CFURLStorageSessionRef (*wkCreatePrivateStorageSession)(CFStringRef);
 NSURLRequest* (*wkCopyRequestWithStorageSession)(CFURLStorageSessionRef, NSURLRequest*);
+CFHTTPCookieStorageRef (*wkCreatePrivateInMemoryHTTPCookieStorage)(CFURLStorageSessionRef);
+unsigned (*wkGetHTTPCookieAcceptPolicy)(CFHTTPCookieStorageRef);
+NSArray *(*wkHTTPCookiesForURL)(CFHTTPCookieStorageRef, NSURL *);
+void (*wkSetHTTPCookiesForURL)(CFHTTPCookieStorageRef, NSArray *, NSURL *, NSURL *);
+void (*wkDeleteHTTPCookie)(CFHTTPCookieStorageRef, NSHTTPCookie *);
index 8876af8..67bb4d5 100644 (file)
 #ifndef CookieStorage_h
 #define CookieStorage_h
 
+#include <wtf/RetainPtr.h>
+
+typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
+
 namespace WebCore {
 
+
+#if USE(CFURLSTORAGESESSIONS) && PLATFORM(MAC)
+RetainPtr<CFHTTPCookieStorageRef>& privateBrowsingCookieStorage();
+#endif
+
 void setCookieStoragePrivateBrowsingEnabled(bool);
 void startObservingCookieChanges();
 void stopObservingCookieChanges();
index b50d58a..c2a5691 100644 (file)
@@ -29,6 +29,7 @@
 #if USE(CFNETWORK)
 
 #include "LoaderRunLoopCF.h"
+#include "ResourceHandle.h"
 #include <CFNetwork/CFHTTPCookiesPriv.h>
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #include <wtf/MainThread.h>
 
 namespace WebCore {
 
-static CFHTTPCookieStorageRef s_cookieStorage;
+static RetainPtr<CFHTTPCookieStorageRef>& privateBrowsingCookieStorage()
+{
+    DEFINE_STATIC_LOCAL(RetainPtr<CFHTTPCookieStorageRef>, cookieStorage, ());
+    return cookieStorage;
+}
 
 CFHTTPCookieStorageRef currentCookieStorage()
 {
     ASSERT(isMainThread());
 
-    if (s_cookieStorage)
-        return s_cookieStorage;
+    if (CFHTTPCookieStorageRef privateCookieStorage = privateBrowsingCookieStorage().get())
+        return privateCookieStorage;
     return wkGetDefaultHTTPCookieStorage();
 }
 
@@ -56,24 +61,23 @@ void setCurrentCookieStorage(CFHTTPCookieStorageRef cookieStorage)
 {
     ASSERT(isMainThread());
 
-    CFRetain(cookieStorage);
-    if (s_cookieStorage)
-        CFRelease(s_cookieStorage);
-
-    s_cookieStorage = cookieStorage;
+    privateBrowsingCookieStorage().adoptCF(cookieStorage);
 }
 
 void setCookieStoragePrivateBrowsingEnabled(bool enabled)
 {
     ASSERT(isMainThread());
 
-    if (s_cookieStorage)
-        CFRelease(s_cookieStorage);
+    if (!enabled) {
+        privateBrowsingCookieStorage() = nullptr;
+        return;
+    }
 
-    if (enabled)
-        s_cookieStorage = wkCreatePrivateHTTPCookieStorage();
-    else
-        s_cookieStorage = 0;
+#if USE(CFURLSTORAGESESSIONS)
+    privateBrowsingCookieStorage().adoptCF(wkCreatePrivateInMemoryHTTPCookieStorage(ResourceHandle::privateBrowsingStorageSession()));
+#else
+    privateBrowsingCookieStorage().adoptCF(wkCreatePrivateInMemoryHTTPCookieStorage(0));
+#endif
 }
 
 static void notifyCookiesChangedOnMainThread(void* context)
index 8b77ffe..db64aae 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "CookieStorage.h"
 
+#import "ResourceHandle.h"
 #import "WebCoreSystemInterface.h"
 #import <wtf/RetainPtr.h>
 #import <wtf/UnusedParam.h>
@@ -74,8 +75,33 @@ using namespace WebCore;
 
 namespace WebCore {
 
+#if USE(CFURLSTORAGESESSIONS)
+
+RetainPtr<CFHTTPCookieStorageRef>& privateBrowsingCookieStorage()
+{
+    DEFINE_STATIC_LOCAL(RetainPtr<CFHTTPCookieStorageRef>, cookieStorage, ());
+    return cookieStorage;
+}
+
+#endif
+
 void setCookieStoragePrivateBrowsingEnabled(bool enabled)
 {
+#if USE(CFURLSTORAGESESSIONS)
+    if (enabled && privateBrowsingCookieStorage())
+        return;
+
+    if (enabled && ResourceHandle::privateBrowsingStorageSession()) {
+        privateBrowsingCookieStorage().adoptCF(wkCreatePrivateInMemoryHTTPCookieStorage(ResourceHandle::privateBrowsingStorageSession()));
+
+        // FIXME: When Private Browsing is enabled, the Private Browsing Cookie Storage should be
+        // observed for changes, not the default Cookie Storage.
+
+        return;
+    }
+
+    privateBrowsingCookieStorage() = nullptr;
+#endif
     wkSetCookieStoragePrivateBrowsingEnabled(enabled);
 }
 
index ae90e06..96d561d 100644 (file)
@@ -33,6 +33,7 @@
 #import "Base64.h"
 #import "BlobRegistry.h"
 #import "BlockExceptions.h"
+#import "CookieStorage.h"
 #import "CredentialStorage.h"
 #import "CachedResourceLoader.h"
 #import "EmptyProtocolDefinitions.h"
@@ -186,6 +187,35 @@ bool ResourceHandle::didSendBodyDataDelegateExists()
     return NSFoundationVersionNumber > MaxFoundationVersionWithoutdidSendBodyDataDelegate;
 }
 
+static bool shouldRelaxThirdPartyCookiePolicy(const KURL& url)
+{
+    // If a URL already has cookies, then we'll relax the 3rd party cookie policy and accept new cookies.
+
+    NSHTTPCookieStorage *sharedStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
+
+    NSHTTPCookieAcceptPolicy cookieAcceptPolicy;
+#if USE(CFURLSTORAGESESSIONS)
+    CFHTTPCookieStorageRef cfPrivateBrowsingStorage = privateBrowsingCookieStorage().get();
+    if (cfPrivateBrowsingStorage)
+        cookieAcceptPolicy =  wkGetHTTPCookieAcceptPolicy(cfPrivateBrowsingStorage);
+    else
+#endif
+        cookieAcceptPolicy = [sharedStorage cookieAcceptPolicy];
+
+    if (cookieAcceptPolicy != NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain)
+        return false;
+
+    NSArray *cookies;
+#if USE(CFURLSTORAGESESSIONS)
+    if (cfPrivateBrowsingStorage)
+        cookies = wkHTTPCookiesForURL(cfPrivateBrowsingStorage, url);
+    else
+#endif
+        cookies = [sharedStorage cookiesForURL:url];
+
+    return [cookies count];
+}
+
 void ResourceHandle::createNSURLConnection(id delegate, bool shouldUseCredentialStorage, bool shouldContentSniff)
 {
     // Credentials for ftp can only be passed in URL, the connection:didReceiveAuthenticationChallenge: delegate call won't be made.
@@ -200,9 +230,7 @@ void ResourceHandle::createNSURLConnection(id delegate, bool shouldUseCredential
         firstRequest().setURL(urlWithCredentials);
     }
 
-    // If a URL already has cookies, then we'll relax the 3rd party cookie policy and accept new cookies.
-    NSHTTPCookieStorage *sharedStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
-    if ([sharedStorage cookieAcceptPolicy] == NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain && [[sharedStorage cookiesForURL:firstRequest().url()] count])
+    if (shouldRelaxThirdPartyCookiePolicy(firstRequest().url()))
         firstRequest().setFirstPartyForCookies(firstRequest().url());
 
 #if !defined(BUILDING_ON_TIGER)
@@ -511,9 +539,7 @@ void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const
     UNUSED_PARAM(context);
     NSURLRequest *firstRequest = request.nsURLRequest();
 
-    // If a URL already has cookies, then we'll relax the 3rd party cookie policy and accept new cookies.
-    NSHTTPCookieStorage *sharedStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
-    if ([sharedStorage cookieAcceptPolicy] == NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain && [[sharedStorage cookiesForURL:[firstRequest URL]] count]) {
+    if (shouldRelaxThirdPartyCookiePolicy([firstRequest URL])) {
         NSMutableURLRequest *mutableRequest = [[firstRequest mutableCopy] autorelease];
         [mutableRequest setMainDocumentURL:[mutableRequest URL]];
         firstRequest = mutableRequest;
index 9df8bcf..a8acb67 100644 (file)
@@ -1,3 +1,17 @@
+2011-03-06  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        WebKit2: Use CFNetwork Sessions API.
+        https://bugs.webkit.org/show_bug.cgi?id=55435.
+
+        When Private Browsing is enabled, use cookies from a in-memory cookie storage based on the
+        Private Browsing Storage Session.
+
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+        Add support for using the new WKSI functions in WebCore.
+
 2011-03-05  Ilya Sherman  <isherman@chromium.org>
 
         Reviewed by Darin Adler.
index ff1073d..6504f17 100644 (file)
@@ -168,6 +168,11 @@ void InitWebCoreSystemInterface(void)
     INIT(UnregisterUniqueIdForElement);
     INIT(CreatePrivateStorageSession);
     INIT(CopyRequestWithStorageSession);
+    INIT(CreatePrivateInMemoryHTTPCookieStorage);
+    INIT(GetHTTPCookieAcceptPolicy);
+    INIT(HTTPCookiesForURL);
+    INIT(SetHTTPCookiesForURL);
+    INIT(DeleteHTTPCookie);
 
     didInit = true;
 }
index 751782e..0e19ed0 100644 (file)
@@ -1,3 +1,17 @@
+2011-03-06  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        WebKit2: Use CFNetwork Sessions API.
+        https://bugs.webkit.org/show_bug.cgi?id=55435.
+
+        When Private Browsing is enabled, use cookies from a in-memory cookie storage based on the
+        Private Browsing Storage Session.
+
+        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+        Add support for using the new WKSI functions in WebCore.
+
 2011-03-06  Oleg Romashin  <romaxa@gmail.com>
 
         Reviewed by Kenneth Rohde Christiansen.
index 36f72ba..2c8649e 100644 (file)
@@ -95,6 +95,11 @@ void InitWebCoreSystemInterface(void)
         INIT(SignalCFReadStreamHasBytes);
         INIT(CreatePrivateStorageSession);
         INIT(CopyRequestWithStorageSession);
+        INIT(CreatePrivateInMemoryHTTPCookieStorage);
+        INIT(GetHTTPCookieAcceptPolicy);
+        INIT(HTTPCookiesForURL);
+        INIT(SetHTTPCookiesForURL);
+        INIT(DeleteHTTPCookie);
 
 #if !defined(BUILDING_ON_SNOW_LEOPARD)
         INIT(IOSurfaceContextCreate);
index d89e9da..114cb70 100644 (file)
@@ -1,3 +1,21 @@
+2011-03-06  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        WebKit2: Use CFNetwork Sessions API.
+        https://bugs.webkit.org/show_bug.cgi?id=55435.
+
+        When Private Browsing is enabled, use cookies from a in-memory Cookie Storage based on the
+        Private Browsing Storage Session.
+
+        Update WebKitSystemInterface headers and libraries with the new functions.
+
+        * WebKitSystemInterface.h:
+        * libWebKitSystemInterfaceLeopard.a:
+        * libWebKitSystemInterfaceSnowLeopard.a:
+        * win/include/WebKitSystemInterface/WebKitSystemInterface.h:
+        * win/lib/WebKitSystemInterface.lib:
+
 2011-03-04  Jessie Berlin  <jberlin@apple.com>
 
         Reviewed by Maciej Stachowiak.
index cd5281f..4d6703c 100644 (file)
@@ -238,6 +238,13 @@ CFURLStorageSessionRef WKCreatePrivateStorageSession(CFStringRef);
 NSURLRequest *WKCopyRequestWithStorageSession(CFURLStorageSessionRef, NSURLRequest*);
 NSCachedURLResponse *WKCachedResponseForRequest(CFURLStorageSessionRef, NSURLRequest*);
 
+typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
+CFHTTPCookieStorageRef WKCreatePrivateInMemoryHTTPCookieStorage(CFURLStorageSessionRef);
+unsigned WKGetHTTPCookieAcceptPolicy(CFHTTPCookieStorageRef);
+NSArray *WKHTTPCookiesForURL(CFHTTPCookieStorageRef, NSURL *);
+void WKSetHTTPCookiesForURL(CFHTTPCookieStorageRef, NSArray *, NSURL *, NSURL *);
+void WKDeleteHTTPCookie(CFHTTPCookieStorageRef, NSHTTPCookie *);
+
 void WKSetVisibleApplicationName(CFStringRef);
 
 typedef enum {
index c621579..d52ce7f 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceLeopard.a and b/WebKitLibraries/libWebKitSystemInterfaceLeopard.a differ
index dbda67e..e54b844 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a and b/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a differ
index 28b2704..5d17561 100644 (file)
@@ -89,7 +89,7 @@ CFDictionaryRef wkGetSSLCertificateInfo(CFURLResponseRef);
 void* wkGetSSLPeerCertificateData(CFDictionaryRef);
 void* wkGetSSLCertificateChainContext(CFDictionaryRef);
 CFHTTPCookieStorageRef wkGetDefaultHTTPCookieStorage();
-CFHTTPCookieStorageRef wkCreatePrivateHTTPCookieStorage();
+CFHTTPCookieStorageRef wkCreatePrivateInMemoryHTTPCookieStorage(CFURLStorageSessionRef);
 void wkSetCFURLRequestShouldContentSniff(CFMutableURLRequestRef, bool);
 CFStringRef wkCopyFoundationCacheDirectory();
 void wkSetClientCertificateInSSLProperties(CFMutableDictionaryRef, CFDataRef);
index 50e5443..c6fe998 100644 (file)
Binary files a/WebKitLibraries/win/lib/WebKitSystemInterface.lib and b/WebKitLibraries/win/lib/WebKitSystemInterface.lib differ