Title: [203174] trunk/Source/WebKit2
Revision
203174
Author
[email protected]
Date
2016-07-13 13:01:11 -0700 (Wed, 13 Jul 2016)

Log Message

WebKit2 shouldn't signal custom protocol clients from the NSURLConnection loader thread.
https://bugs.webkit.org/show_bug.cgi?id=159725
<rdar://problem/27323131>

Reviewed by Andy Estes.

WebKit2 shouldn't signal custom protocol clients from the NSURLConnection
loader thread. Instead, use the RunLoop the WKCustomProtocol was initialized
on.

* NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm:
(-[WKCustomProtocol initWithRequest:cachedResponse:client:]):
(WebKit::dispatchOnInitializationRunLoop):
(WebKit::CustomProtocolManager::didFailWithError):
(WebKit::CustomProtocolManager::didLoadData):
(WebKit::CustomProtocolManager::didReceiveResponse):
(WebKit::CustomProtocolManager::didFinishLoading):
(WebKit::CustomProtocolManager::wasRedirectedToRequest):
(WebKit::dispatchOnResourceLoaderRunLoop): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (203173 => 203174)


--- trunk/Source/WebKit2/ChangeLog	2016-07-13 20:00:26 UTC (rev 203173)
+++ trunk/Source/WebKit2/ChangeLog	2016-07-13 20:01:11 UTC (rev 203174)
@@ -1,3 +1,25 @@
+2016-07-13  Chris Dumez  <[email protected]>
+
+        WebKit2 shouldn't signal custom protocol clients from the NSURLConnection loader thread.
+        https://bugs.webkit.org/show_bug.cgi?id=159725
+        <rdar://problem/27323131>
+
+        Reviewed by Andy Estes.
+
+        WebKit2 shouldn't signal custom protocol clients from the NSURLConnection
+        loader thread. Instead, use the RunLoop the WKCustomProtocol was initialized
+        on.
+
+        * NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm:
+        (-[WKCustomProtocol initWithRequest:cachedResponse:client:]):
+        (WebKit::dispatchOnInitializationRunLoop):
+        (WebKit::CustomProtocolManager::didFailWithError):
+        (WebKit::CustomProtocolManager::didLoadData):
+        (WebKit::CustomProtocolManager::didReceiveResponse):
+        (WebKit::CustomProtocolManager::didFinishLoading):
+        (WebKit::CustomProtocolManager::wasRedirectedToRequest):
+        (WebKit::dispatchOnResourceLoaderRunLoop): Deleted.
+
 2016-07-13  Enrica Casucci  <[email protected]>
 
         Update supported platforms in xcconfig files to match the sdk names.

Modified: trunk/Source/WebKit2/NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm (203173 => 203174)


--- trunk/Source/WebKit2/NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm	2016-07-13 20:00:26 UTC (rev 203173)
+++ trunk/Source/WebKit2/NetworkProcess/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm	2016-07-13 20:01:11 UTC (rev 203174)
@@ -57,8 +57,10 @@
 @interface WKCustomProtocol : NSURLProtocol {
 @private
     uint64_t _customProtocolID;
+    RetainPtr<CFRunLoopRef> _initializationRunLoop;
 }
 @property (nonatomic, readonly) uint64_t customProtocolID;
+@property (nonatomic, readonly) CFRunLoopRef initializationRunLoop;
 @end
 
 @implementation WKCustomProtocol
@@ -89,11 +91,17 @@
         return nil;
     
     _customProtocolID = generateCustomProtocolID();
+    _initializationRunLoop = CFRunLoopGetCurrent();
     if (auto* customProtocolManager = NetworkProcess::singleton().supplement<CustomProtocolManager>())
         customProtocolManager->addCustomProtocol(self);
     return self;
 }
 
+- (CFRunLoopRef)initializationRunLoop
+{
+    return _initializationRunLoop.get();
+}
+
 - (void)startLoading
 {
     if (auto* customProtocolManager = NetworkProcess::singleton().supplement<CustomProtocolManager>())
@@ -183,10 +191,11 @@
     return m_registeredSchemes.contains(scheme);
 }
 
-static inline void dispatchOnResourceLoaderRunLoop(void (^block)())
+static inline void dispatchOnInitializationRunLoop(WKCustomProtocol* protocol, void (^block)())
 {
-    CFRunLoopPerformBlock([NSURLConnection resourceLoaderRunLoop], kCFRunLoopDefaultMode, block);
-    CFRunLoopWakeUp([NSURLConnection resourceLoaderRunLoop]);
+    CFRunLoopRef runloop = protocol.initializationRunLoop;
+    CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, block);
+    CFRunLoopWakeUp(runloop);
 }
 
 void CustomProtocolManager::didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError& error)
@@ -197,7 +206,7 @@
 
     RetainPtr<NSError> nsError = error.nsError();
 
-    dispatchOnResourceLoaderRunLoop(^ {
+    dispatchOnInitializationRunLoop(protocol.get(), ^ {
         [[protocol client] URLProtocol:protocol.get() didFailWithError:nsError.get()];
     });
 
@@ -212,7 +221,7 @@
 
     RetainPtr<NSData> nsData = adoptNS([[NSData alloc] initWithBytes:data.data() length:data.size()]);
 
-    dispatchOnResourceLoaderRunLoop(^ {
+    dispatchOnInitializationRunLoop(protocol.get(), ^ {
         [[protocol client] URLProtocol:protocol.get() didLoadData:nsData.get()];
     });
 }
@@ -225,7 +234,7 @@
 
     RetainPtr<NSURLResponse> nsResponse = response.nsURLResponse();
 
-    dispatchOnResourceLoaderRunLoop(^ {
+    dispatchOnInitializationRunLoop(protocol.get(), ^ {
         [[protocol client] URLProtocol:protocol.get() didReceiveResponse:nsResponse.get() cacheStoragePolicy:static_cast<NSURLCacheStoragePolicy>(cacheStoragePolicy)];
     });
 }
@@ -236,7 +245,7 @@
     if (!protocol)
         return;
 
-    dispatchOnResourceLoaderRunLoop(^ {
+    dispatchOnInitializationRunLoop(protocol.get(), ^ {
         [[protocol client] URLProtocolDidFinishLoading:protocol.get()];
     });
 
@@ -252,7 +261,7 @@
     RetainPtr<NSURLRequest> nsRequest = request.nsURLRequest(WebCore::DoNotUpdateHTTPBody);
     RetainPtr<NSURLResponse> nsRedirectResponse = redirectResponse.nsURLResponse();
 
-    dispatchOnResourceLoaderRunLoop([protocol, nsRequest, nsRedirectResponse]() {
+    dispatchOnInitializationRunLoop(protocol.get(), [protocol, nsRequest, nsRedirectResponse]() {
         [[protocol client] URLProtocol:protocol.get() wasRedirectedToRequest:nsRequest.get() redirectResponse:nsRedirectResponse.get()];
     });
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to