#import "Base64.h"
#import "BlobRegistry.h"
#import "BlockExceptions.h"
+#import "CookieStorage.h"
#import "CredentialStorage.h"
#import "CachedResourceLoader.h"
#import "EmptyProtocolDefinitions.h"
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.
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)
static bool supportsSettingConnectionProperties = [NSURLConnection instancesRespondToSelector:@selector(_initWithRequest:delegate:usesCache:maxContentLength:startImmediately:connectionProperties:)];
#endif
+#if USE(CFURLSTORAGESESSIONS)
+ if (CFURLStorageSessionRef storageSession = privateBrowsingStorageSession())
+ nsRequest = [wkCopyRequestWithStorageSession(storageSession, nsRequest) autorelease];
+#endif
+
if (supportsSettingConnectionProperties) {
NSDictionary *sessionID = shouldUseCredentialStorage ? [NSDictionary dictionary] : [NSDictionary dictionaryWithObject:@"WebKitPrivateSession" forKey:@"_kCFURLConnectionSessionID"];
NSDictionary *propertyDictionary = [NSDictionary dictionaryWithObject:sessionID forKey:@"kCFURLConnectionSocketStreamProperties"];
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;
if (!protocolHostAndPortAreEqual(request.url(), redirectResponse.url()))
request.clearHTTPAuthorization();
+#if USE(CFURLSTORAGESESSIONS)
+ if (CFURLStorageSessionRef storageSession = privateBrowsingStorageSession())
+ request.setStorageSession(storageSession);
+#endif
+
client()->willSendRequest(this, request, redirectResponse);
}
client()->receivedCancellation(this, challenge);
}
+#if USE(CFURLSTORAGESESSIONS)
+
RetainPtr<CFURLStorageSessionRef> ResourceHandle::createPrivateBrowsingStorageSession(CFStringRef identifier)
{
return RetainPtr<CFURLStorageSessionRef>(AdoptCF, wkCreatePrivateStorageSession(identifier));
return String([[NSBundle mainBundle] bundleIdentifier]);
}
+#endif
+
} // namespace WebCore
@implementation WebCoreResourceHandleAsDelegate
// Avoid MIME type sniffing if the response comes back as 304 Not Modified.
int statusCode = [r respondsToSelector:@selector(statusCode)] ? [(id)r statusCode] : 0;
if (statusCode != 304)
- [r adjustMIMETypeIfNecessary];
+ adjustMIMETypeIfNecessary([r _CFURLResponse]);
if ([m_handle->firstRequest().nsURLRequest() _propertyForKey:@"ForceHTMLMIMEType"])
[r _setMIMEType:@"text/html"];