Changeset 224786 in webkit
- Timestamp:
- Nov 13, 2017, 3:00:38 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r224785 r224786 1 2017-11-13 Alex Christensen <achristensen@webkit.org> 2 3 Call willPerformHTTPRedirection on WebCoreNSURLSession's delegate 4 https://bugs.webkit.org/show_bug.cgi?id=179539 5 6 Reviewed by Jer Noble. 7 8 This is now possible! 9 This will allow AVFoundation to fix redirect-related bugs. 10 11 * platform/network/cocoa/WebCoreNSURLSession.mm: 12 (-[WebCoreNSURLSession addDelegateOperation:]): 13 (-[WebCoreNSURLSession resetWithCompletionHandler:]): 14 (-[WebCoreNSURLSession flushWithCompletionHandler:]): 15 (WebCore::WebCoreNSURLSessionDataTaskClient::redirectReceived): 16 (-[WebCoreNSURLSessionDataTask resource:shouldCacheResponse:]): 17 (-[WebCoreNSURLSessionDataTask resource:receivedData:length:]): 18 (-[WebCoreNSURLSessionDataTask resource:receivedRedirect:request:completionHandler:]): 19 (-[WebCoreNSURLSessionDataTask resource:receivedRedirect:request:]): Deleted. 20 1 21 2017-11-13 Chris Dumez <cdumez@apple.com> 2 22 -
trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm
r224699 r224786 30 30 #import "PlatformMediaResourceLoader.h" 31 31 #import "SubresourceLoader.h" 32 #import <wtf/BlockPtr.h> 32 33 #import <wtf/CompletionHandler.h> 33 34 … … 42 43 @property (readwrite, retain) id<NSURLSessionTaskDelegate> delegate; 43 44 - (void)taskCompleted:(WebCoreNSURLSessionDataTask *)task; 44 - (void)addDelegateOperation:( void (^)(void))operation;45 - (void)addDelegateOperation:(Function<void()>&&)operation; 45 46 - (void)task:(WebCoreNSURLSessionDataTask *)task didReceiveCORSAccessCheckResult:(BOOL)result; 46 47 @end … … 59 60 - (BOOL)resource:(PlatformMediaResource&)resource shouldCacheResponse:(const ResourceResponse&)response; 60 61 - (void)resource:(PlatformMediaResource&)resource receivedData:(const char*)data length:(int)length; 61 - (void)resource:(PlatformMediaResource&)resource receivedRedirect:(const ResourceResponse&)response request:(ResourceRequest& )request;62 - (void)resource:(PlatformMediaResource&)resource receivedRedirect:(const ResourceResponse&)response request:(ResourceRequest&&)request completionHandler:(CompletionHandler<void(ResourceRequest&&)>&&)completionHandler; 62 63 - (void)resource:(PlatformMediaResource&)resource accessControlCheckFailedWithError:(const ResourceError&)error; 63 64 - (void)resource:(PlatformMediaResource&)resource loadFailedWithError:(const ResourceError&)error; … … 128 129 } 129 130 130 - (void)addDelegateOperation:( void (^)(void))block131 - (void)addDelegateOperation:(Function<void()>&&)function 131 132 { 132 133 RetainPtr<WebCoreNSURLSession> strongSelf { self }; 133 RetainPtr<NSBlockOperation> operation = [NSBlockOperation blockOperationWithBlock: block];134 RetainPtr<NSBlockOperation> operation = [NSBlockOperation blockOperationWithBlock:BlockPtr<void()>::fromCallable(WTFMove(function)).get()]; 134 135 dispatch_async(_internalQueue.get(), [strongSelf, operation] { 135 136 [strongSelf.get().delegateQueue addOperation:operation.get()]; … … 217 218 { 218 219 // FIXME: This cannot currently be implemented. We cannot guarantee that the next connection will happen on a new socket. 219 [self addDelegateOperation:completionHandler]; 220 [self addDelegateOperation:[completionHandler = BlockPtr<void()>(completionHandler)] { 221 completionHandler(); 222 }]; 220 223 } 221 224 … … 223 226 { 224 227 // FIXME: This cannot currently be implemented. We cannot guarantee that the next connection will happen on a new socket. 225 [self addDelegateOperation:completionHandler]; 228 [self addDelegateOperation:[completionHandler = BlockPtr<void()>(completionHandler)] { 229 completionHandler(); 230 }]; 226 231 } 227 232 … … 385 390 void WebCoreNSURLSessionDataTaskClient::redirectReceived(PlatformMediaResource& resource, ResourceRequest&& request, const ResourceResponse& response, CompletionHandler<void(ResourceRequest&&)>&& completionHandler) 386 391 { 387 [m_task resource:resource receivedRedirect:response request:request]; 388 completionHandler(WTFMove(request)); 392 [m_task resource:resource receivedRedirect:response request:WTFMove(request) completionHandler:WTFMove(completionHandler)]; 389 393 } 390 394 … … 588 592 { 589 593 ASSERT_UNUSED(resource, &resource == _resource); 590 UNUSED_PARAM(response);591 594 592 595 ASSERT(isMainThread()); … … 599 602 { 600 603 ASSERT_UNUSED(resource, &resource == _resource); 601 UNUSED_PARAM(data);602 UNUSED_PARAM(length);603 604 RetainPtr<NSData> nsData = adoptNS([[NSData alloc] initWithBytes:data length:length]); 604 605 RetainPtr<WebCoreNSURLSessionDataTask> strongSelf { self }; … … 611 612 } 612 613 613 - (void)resource:(PlatformMediaResource&)resource receivedRedirect:(const ResourceResponse&)response request:(ResourceRequest& )request614 - (void)resource:(PlatformMediaResource&)resource receivedRedirect:(const ResourceResponse&)response request:(ResourceRequest&&)request completionHandler:(CompletionHandler<void(ResourceRequest&&)>&&)completionHandler 614 615 { 615 616 ASSERT_UNUSED(resource, &resource == _resource); 616 UNUSED_PARAM(response); 617 UNUSED_PARAM(request); 618 // FIXME: This cannot currently be implemented, as the callback is synchronous 619 // on the main thread, and the NSURLSession delegate must be called back on a 620 // background queue, and we do not want to block the main thread until the 621 // delegate handles the callback and responds via a completion handler. If, in 622 // the future, the ResourceLoader exposes a callback-based willSendResponse 623 // API, this can be implemented. 617 [self.session addDelegateOperation:[strongSelf = retainPtr(self), response = retainPtr(response.nsURLResponse()), request = WTFMove(request), completionHandler = WTFMove(completionHandler)] () mutable { 618 if (![response isKindOfClass:[NSHTTPURLResponse class]]) { 619 ASSERT_NOT_REACHED(); 620 return completionHandler(WTFMove(request)); 621 } 622 623 id<NSURLSessionDataDelegate> dataDelegate = (id<NSURLSessionDataDelegate>)strongSelf.get().session.delegate; 624 if ([dataDelegate respondsToSelector:@selector(URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:)]) { 625 auto completionHandlerBlock = BlockPtr<void(NSURLRequest *)>::fromCallable([completionHandler = WTFMove(completionHandler)](NSURLRequest *newRequest) mutable { 626 completionHandler(newRequest); 627 }); 628 [dataDelegate URLSession:(NSURLSession *)strongSelf.get().session task:(NSURLSessionTask *)strongSelf.get() willPerformHTTPRedirection:(NSHTTPURLResponse *)response.get() newRequest:request.nsURLRequest(DoNotUpdateHTTPBody) completionHandler:completionHandlerBlock.get()]; 629 } else 630 completionHandler(WTFMove(request)); 631 }]; 624 632 } 625 633
Note:
See TracChangeset
for help on using the changeset viewer.