Title: [200655] trunk/Source
Revision
200655
Author
achristen...@apple.com
Date
2016-05-10 16:49:01 -0700 (Tue, 10 May 2016)

Log Message

Handle _schemeUpgraded delegate callbacks in NSURLSessionDataDelegate
https://bugs.webkit.org/show_bug.cgi?id=157354
rdar://problem/25842107

Reviewed by Darin Adler.

Source/WebCore:

No new tests.  This cannot be tested with a self-signed certificate.
This needs to be tested once we use real ssl certificates for testing.

* platform/network/mac/WebCoreResourceHandleAsDelegate.mm:
(-[WebCoreResourceHandleAsDelegate connection:willSendRequest:redirectResponse:]):
* platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:willSendRequest:redirectResponse:]):
* platform/network/mac/WebCoreURLResponse.h:
* platform/network/mac/WebCoreURLResponse.mm:
(WebCore::synthesizeRedirectResponseIfNecessary):
Take the NSURLRequest instead of the NSURLConnection as a parameter so we can share this code with the NSURLSession loader,
which has an NSURLSessionDataTask.  Both have the currentRequest, which is all we need in this function anyway.

Source/WebKit2:

* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:task:_schemeUpgraded:completionHandler:]):
When we make a request to a http url and CFNetwork determines that that url would have redirected to an HSTS site
and it is going to change the request to an https request, this delegate callback is called.  We need to call the
redirection code to have the same behavior as the NSURLConnection-based loader.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (200654 => 200655)


--- trunk/Source/WebCore/ChangeLog	2016-05-10 23:47:10 UTC (rev 200654)
+++ trunk/Source/WebCore/ChangeLog	2016-05-10 23:49:01 UTC (rev 200655)
@@ -1,3 +1,24 @@
+2016-05-10  Alex Christensen  <achristen...@webkit.org>
+
+        Handle _schemeUpgraded delegate callbacks in NSURLSessionDataDelegate
+        https://bugs.webkit.org/show_bug.cgi?id=157354
+        rdar://problem/25842107
+
+        Reviewed by Darin Adler.
+
+        No new tests.  This cannot be tested with a self-signed certificate.
+        This needs to be tested once we use real ssl certificates for testing.
+
+        * platform/network/mac/WebCoreResourceHandleAsDelegate.mm:
+        (-[WebCoreResourceHandleAsDelegate connection:willSendRequest:redirectResponse:]):
+        * platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
+        (-[WebCoreResourceHandleAsOperationQueueDelegate connection:willSendRequest:redirectResponse:]):
+        * platform/network/mac/WebCoreURLResponse.h:
+        * platform/network/mac/WebCoreURLResponse.mm:
+        (WebCore::synthesizeRedirectResponseIfNecessary):
+        Take the NSURLRequest instead of the NSURLConnection as a parameter so we can share this code with the NSURLSession loader,
+        which has an NSURLSessionDataTask.  Both have the currentRequest, which is all we need in this function anyway.
+
 2016-05-10  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Backend should initiate timeline recordings on page navigations to ensure nothing is missed

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsDelegate.mm (200654 => 200655)


--- trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsDelegate.mm	2016-05-10 23:47:10 UTC (rev 200654)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsDelegate.mm	2016-05-10 23:49:01 UTC (rev 200655)
@@ -64,7 +64,7 @@
     if (!m_handle)
         return nil;
 
-    redirectResponse = synthesizeRedirectResponseIfNecessary(connection, newRequest, redirectResponse);
+    redirectResponse = synthesizeRedirectResponseIfNecessary([connection currentRequest], newRequest, redirectResponse);
     
     // See <rdar://problem/5380697>. This is a workaround for a behavior change in CFNetwork where willSendRequest gets called more often.
     if (!redirectResponse)

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm (200654 => 200655)


--- trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm	2016-05-10 23:47:10 UTC (rev 200654)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm	2016-05-10 23:49:01 UTC (rev 200655)
@@ -100,7 +100,7 @@
     ASSERT(!isMainThread());
     UNUSED_PARAM(connection);
 
-    redirectResponse = synthesizeRedirectResponseIfNecessary(connection, newRequest, redirectResponse);
+    redirectResponse = synthesizeRedirectResponseIfNecessary([connection currentRequest], newRequest, redirectResponse);
 
     // See <rdar://problem/5380697>. This is a workaround for a behavior change in CFNetwork where willSendRequest gets called more often.
     if (!redirectResponse)

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.h (200654 => 200655)


--- trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.h	2016-05-10 23:47:10 UTC (rev 200654)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.h	2016-05-10 23:49:01 UTC (rev 200655)
@@ -38,7 +38,7 @@
 @class NSURLResponse;
 
 namespace WebCore {
-WEBCORE_EXPORT NSURLResponse *synthesizeRedirectResponseIfNecessary(NSURLConnection *, NSURLRequest *newRequest, NSURLResponse *redirectResponse);
+WEBCORE_EXPORT NSURLResponse *synthesizeRedirectResponseIfNecessary(NSURLRequest *currentRequest, NSURLRequest *newRequest, NSURLResponse *redirectResponse);
 }
 #endif // __OBJC__
 

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm (200654 => 200655)


--- trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm	2016-05-10 23:47:10 UTC (rev 200654)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm	2016-05-10 23:49:01 UTC (rev 200655)
@@ -326,18 +326,18 @@
 #endif
 
 #if !USE(CFNETWORK)
-NSURLResponse *synthesizeRedirectResponseIfNecessary(NSURLConnection *connection, NSURLRequest *newRequest, NSURLResponse *redirectResponse)
+NSURLResponse *synthesizeRedirectResponseIfNecessary(NSURLRequest *currentRequest, NSURLRequest *newRequest, NSURLResponse *redirectResponse)
 {
     if (redirectResponse)
         return redirectResponse;
 
-    if ([[[newRequest URL] scheme] isEqualToString:[[[connection currentRequest] URL] scheme]])
+    if ([[[newRequest URL] scheme] isEqualToString:[[currentRequest URL] scheme]])
         return nil;
 
     // If the new request is a different protocol than the current request, synthesize a redirect response.
     // This is critical for HSTS (<rdar://problem/14241270>).
     NSDictionary *synthesizedResponseHeaderFields = @{ @"Location": [[newRequest URL] absoluteString], @"Cache-Control": @"no-store" };
-    return [[[NSHTTPURLResponse alloc] initWithURL:[[connection currentRequest] URL] statusCode:302 HTTPVersion:(NSString *)kCFHTTPVersion1_1 headerFields:synthesizedResponseHeaderFields] autorelease];
+    return [[[NSHTTPURLResponse alloc] initWithURL:[currentRequest URL] statusCode:302 HTTPVersion:(NSString *)kCFHTTPVersion1_1 headerFields:synthesizedResponseHeaderFields] autorelease];
 }
 #endif
 

Modified: trunk/Source/WebKit2/ChangeLog (200654 => 200655)


--- trunk/Source/WebKit2/ChangeLog	2016-05-10 23:47:10 UTC (rev 200654)
+++ trunk/Source/WebKit2/ChangeLog	2016-05-10 23:49:01 UTC (rev 200655)
@@ -1,3 +1,17 @@
+2016-05-10  Alex Christensen  <achristen...@webkit.org>
+
+        Handle _schemeUpgraded delegate callbacks in NSURLSessionDataDelegate
+        https://bugs.webkit.org/show_bug.cgi?id=157354
+        rdar://problem/25842107
+
+        Reviewed by Darin Adler.
+
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (-[WKNetworkSessionDelegate URLSession:task:_schemeUpgraded:completionHandler:]):
+        When we make a request to a http url and CFNetwork determines that that url would have redirected to an HSTS site
+        and it is going to change the request to an https request, this delegate callback is called.  We need to call the
+        redirection code to have the same behavior as the NSURLConnection-based loader.
+
 2016-05-10  Csaba Osztrogonác  <o...@webkit.org>
 
         Fix the !ENABLE(VIDEO) build

Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (200654 => 200655)


--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2016-05-10 23:47:10 UTC (rev 200654)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2016-05-10 23:49:01 UTC (rev 200655)
@@ -125,6 +125,19 @@
         completionHandler(nil);
 }
 
+- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask*)task _schemeUpgraded:(NSURLRequest*)request completionHandler:(void (^)(NSURLRequest*))completionHandler
+{
+    auto storedCredentials = _withCredentials ? WebCore::StoredCredentials::AllowStoredCredentials : WebCore::StoredCredentials::DoNotAllowStoredCredentials;
+    if (auto* networkDataTask = _session->dataTaskForIdentifier(task.taskIdentifier, storedCredentials)) {
+        auto completionHandlerCopy = Block_copy(completionHandler);
+        networkDataTask->willPerformHTTPRedirection(WebCore::synthesizeRedirectResponseIfNecessary([task currentRequest], request, nil), request, [completionHandlerCopy](const WebCore::ResourceRequest& request) {
+            completionHandlerCopy(request.nsURLRequest(WebCore::UpdateHTTPBody));
+            Block_release(completionHandlerCopy);
+        });
+    } else
+        completionHandler(nil);
+}
+
 - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask willCacheResponse:(NSCachedURLResponse *)proposedResponse completionHandler:(void (^)(NSCachedURLResponse * _Nullable cachedResponse))completionHandler
 {
     // FIXME: remove if <rdar://problem/20001985> is ever resolved.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to