Changeset 254345 in webkit
- Timestamp:
- Jan 10, 2020 10:06:08 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r254344 r254345 1 2020-01-10 Alex Christensen <achristensen@webkit.org> 2 3 Expand _WKResourceLoadDelegate callbacks 4 https://bugs.webkit.org/show_bug.cgi?id=206037 5 <rdar://problem/57132290> 6 7 Reviewed by Youenn Fablet. 8 9 Add 5 informative delegate callbacks at these times during the loading process: 10 1. When a request is sent. 11 2. When a redirect happens. 12 3. When a challenge happens. 13 4. When a response is received. 14 5. When loading completes or fails. 15 16 As mentioned in r254183 these callbacks are only called when a _WKResourceLoadDelegate is given to a WKWebView. 17 We add a new struct ResourceLoadInfo which will need to be expanded containing currently only the load identifier. 18 Covered by new API tests which verify the validity of the sent information. 19 20 * NetworkProcess/NetworkLoad.cpp: 21 (WebKit::NetworkLoad::didReceiveChallenge): 22 * NetworkProcess/NetworkLoadClient.h: 23 (WebKit::NetworkLoadClient::didReceiveChallenge): 24 * NetworkProcess/NetworkResourceLoader.cpp: 25 (WebKit::generateResourceLoadID): 26 (WebKit::NetworkResourceLoader::startNetworkLoad): 27 (WebKit::NetworkResourceLoader::resourceLoadInfo): 28 (WebKit::NetworkResourceLoader::didReceiveResponse): 29 (WebKit::NetworkResourceLoader::didFinishLoading): 30 (WebKit::NetworkResourceLoader::didFailLoading): 31 (WebKit::NetworkResourceLoader::didReceiveChallenge): 32 Add a way to send a message informing that a challenge happened with information gathered from the NetworkResourceLoader, 33 which previously was not informed of challenges because the challenges went directly from the NetworkLoad to the AuthenticationManager. 34 (WebKit::NetworkResourceLoader::willSendRedirectedRequest): 35 (WebKit::NetworkResourceLoader::continueWillSendRequest): 36 (WebKit::m_shouldCaptureExtraNetworkLoadMetrics): Deleted. 37 * NetworkProcess/NetworkResourceLoader.h: 38 * Shared/API/APIObject.h: 39 * Shared/Cocoa/APIObject.mm: 40 (API::Object::newObject): 41 * Shared/ResourceLoadInfo.h: Added. 42 (WebKit::ResourceLoadInfo::encode const): 43 (WebKit::ResourceLoadInfo::decode): 44 * SourcesCocoa.txt: 45 * UIProcess/API/APIResourceLoadClient.h: 46 * UIProcess/API/APIResourceLoadInfo.h: Added. 47 * UIProcess/API/Cocoa/_WKResourceLoadDelegate.h: 48 * UIProcess/API/Cocoa/_WKResourceLoadInfo.h: Added. 49 * UIProcess/API/Cocoa/_WKResourceLoadInfo.mm: Added. 50 (-[_WKResourceLoadInfo dealloc]): 51 (-[_WKResourceLoadInfo resourceLoadID]): 52 (-[_WKResourceLoadInfo _apiObject]): 53 * UIProcess/API/Cocoa/_WKResourceLoadInfoInternal.h: Added. 54 * UIProcess/Authentication/AuthenticationChallengeProxy.cpp: 55 (WebKit::AuthenticationChallengeProxy::AuthenticationChallengeProxy): 56 An AuthenticationChallengeProxy was only used for challenges that needed credentials, so they wrapped a CompletionHandler. 57 This new type of informative-only challenge will be given a null CompletionHandler, which means no action can be taken. 58 * UIProcess/Cocoa/ResourceLoadDelegate.h: 59 * UIProcess/Cocoa/ResourceLoadDelegate.mm: 60 (WebKit::ResourceLoadDelegate::setDelegate): 61 (WebKit::ResourceLoadDelegate::ResourceLoadClient::didSendRequest const): 62 (WebKit::ResourceLoadDelegate::ResourceLoadClient::didPerformHTTPRedirection const): 63 (WebKit::ResourceLoadDelegate::ResourceLoadClient::didReceiveChallenge const): 64 (WebKit::ResourceLoadDelegate::ResourceLoadClient::didReceiveResponse const): 65 (WebKit::ResourceLoadDelegate::ResourceLoadClient::didCompleteWithError const): 66 (WebKit::ResourceLoadDelegate::ResourceLoadClient::willSendRequest const): Deleted. 67 * UIProcess/Network/NetworkProcessProxy.cpp: 68 (WebKit::NetworkProcessProxy::resourceLoadDidSendRequest): 69 (WebKit::NetworkProcessProxy::resourceLoadDidPerformHTTPRedirection): 70 (WebKit::NetworkProcessProxy::resourceLoadDidReceiveChallenge): 71 (WebKit::NetworkProcessProxy::resourceLoadDidReceiveResponse): 72 (WebKit::NetworkProcessProxy::resourceLoadDidCompleteWithError): 73 (WebKit::NetworkProcessProxy::pageWillSendRequest): Deleted. 74 * UIProcess/Network/NetworkProcessProxy.h: 75 * UIProcess/Network/NetworkProcessProxy.messages.in: 76 * UIProcess/WebPageProxy.cpp: 77 * UIProcess/WebPageProxy.h: 78 * WebKit.xcodeproj/project.pbxproj: 79 * WebProcess/Network/WebLoaderStrategy.cpp: 80 (WebKit::WebLoaderStrategy::loadResourceSynchronously): 81 (WebKit::WebLoaderStrategy::startPingLoad): 82 * WebProcess/Network/WebResourceLoader.cpp: 83 (WebKit::WebResourceLoader::willSendRequest): 84 1 85 2020-01-10 Alex Christensen <achristensen@webkit.org> 2 86 -
trunk/Source/WebKit/NetworkProcess/NetworkLoad.cpp
r249501 r254345 190 190 void NetworkLoad::didReceiveChallenge(AuthenticationChallenge&& challenge, ChallengeCompletionHandler&& completionHandler) 191 191 { 192 m_client.get().didReceiveChallenge(challenge); 193 192 194 auto scheme = challenge.protectionSpace().authenticationScheme(); 193 195 bool isTLSHandshake = scheme == ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested -
trunk/Source/WebKit/NetworkProcess/NetworkLoadClient.h
r239007 r254345 31 31 32 32 namespace WebCore { 33 class AuthenticationChallenge; 33 34 class NetworkLoadMetrics; 34 35 class SharedBuffer; … … 55 56 virtual void didFailLoading(const WebCore::ResourceError&) = 0; 56 57 virtual void didBlockAuthenticationChallenge() { }; 58 virtual void didReceiveChallenge(const WebCore::AuthenticationChallenge&) { }; 57 59 virtual bool shouldCaptureExtraNetworkLoadMetrics() const { return false; } 58 60 }; -
trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
r254183 r254345 40 40 #include "NetworkProcessProxyMessages.h" 41 41 #include "NetworkSession.h" 42 #include "ResourceLoadInfo.h" 42 43 #include "ServiceWorkerFetchTask.h" 43 44 #include "SharedBufferDataReference.h" … … 105 106 , m_bufferingTimer { *this, &NetworkResourceLoader::bufferingTimerFired } 106 107 , m_shouldCaptureExtraNetworkLoadMetrics(m_connection->captureExtraNetworkLoadMetricsEnabled()) 108 , m_resourceLoadID { NetworkResourceLoadIdentifier::generate() } 107 109 { 108 110 ASSERT(RunLoop::isMain()); … … 324 326 325 327 if (m_parameters.pageHasResourceLoadClient) 326 m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy:: PageWillSendRequest(m_parameters.webPageProxyID, request), 0);328 m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ResourceLoadDidSendRequest(m_parameters.webPageProxyID, resourceLoadInfo(), request), 0); 327 329 328 330 parameters.request = WTFMove(request); … … 330 332 331 333 RELEASE_LOG_IF_ALLOWED("startNetworkLoad: Going to the network (description=%{public}s)", m_networkLoad->description().utf8().data()); 334 } 335 336 ResourceLoadInfo NetworkResourceLoader::resourceLoadInfo() 337 { 338 return { 339 m_resourceLoadID 340 }; 332 341 } 333 342 … … 548 557 send(Messages::WebResourceLoader::DidReceiveResponse { response, willWaitForContinueDidReceiveResponse }); 549 558 559 if (m_parameters.pageHasResourceLoadClient) 560 m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ResourceLoadDidReceiveResponse(m_parameters.webPageProxyID, resourceLoadInfo(), response), 0); 561 550 562 if (willWaitForContinueDidReceiveResponse) { 551 563 m_responseCompletionHandler = WTFMove(completionHandler); … … 623 635 624 636 tryStoreAsCacheEntry(); 637 638 if (m_parameters.pageHasResourceLoadClient) 639 m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ResourceLoadDidCompleteWithError(m_parameters.webPageProxyID, resourceLoadInfo(), { }), 0); 625 640 626 641 cleanup(LoadResult::Success); … … 656 671 } 657 672 673 if (m_parameters.pageHasResourceLoadClient) 674 m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ResourceLoadDidCompleteWithError(m_parameters.webPageProxyID, resourceLoadInfo(), error), 0); 675 658 676 cleanup(LoadResult::Failure); 659 677 } … … 663 681 RELEASE_LOG_IF_ALLOWED("didBlockAuthenticationChallenge:"); 664 682 send(Messages::WebResourceLoader::DidBlockAuthenticationChallenge()); 683 } 684 685 void NetworkResourceLoader::didReceiveChallenge(const AuthenticationChallenge& challenge) 686 { 687 if (m_parameters.pageHasResourceLoadClient) 688 m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ResourceLoadDidReceiveChallenge(m_parameters.webPageProxyID, resourceLoadInfo(), challenge), 0); 665 689 } 666 690 … … 691 715 RELEASE_LOG_IF_ALLOWED("willSendRedirectedRequest:"); 692 716 ++m_redirectCount; 717 m_redirectResponse = redirectResponse; 693 718 694 719 Optional<AdClickAttribution::Conversion> adClickConversion; … … 866 891 if (m_networkLoad) { 867 892 RELEASE_LOG_IF_ALLOWED("continueWillSendRequest: Telling NetworkLoad to proceed with the redirect"); 893 894 if (m_parameters.pageHasResourceLoadClient && !newRequest.isNull()) 895 m_connection->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::ResourceLoadDidPerformHTTPRedirection(m_parameters.webPageProxyID, resourceLoadInfo(), m_redirectResponse, newRequest), 0); 896 868 897 m_networkLoad->continueWillSendRequest(WTFMove(newRequest)); 869 898 } -
trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h
r253528 r254345 32 32 #include "NetworkConnectionToWebProcessMessagesReplies.h" 33 33 #include "NetworkLoadClient.h" 34 #include "NetworkResourceLoadIdentifier.h" 34 35 #include "NetworkResourceLoadParameters.h" 35 36 #include <WebCore/AdClickAttribution.h> … … 54 55 class ServiceWorkerFetchTask; 55 56 class WebSWServerConnection; 57 58 struct ResourceLoadInfo; 56 59 57 60 namespace NetworkCache { … … 98 101 99 102 // NetworkLoadClient. 100 void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override; 101 bool isSynchronous() const override; 102 bool isAllowedToAskUserForCredentials() const override { return m_isAllowedToAskUserForCredentials; } 103 void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&&) override; 104 void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) override; 105 void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override; 106 void didFinishLoading(const WebCore::NetworkLoadMetrics&) override; 107 void didFailLoading(const WebCore::ResourceError&) override; 108 void didBlockAuthenticationChallenge() override; 109 bool shouldCaptureExtraNetworkLoadMetrics() const override; 103 void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) final; 104 bool isSynchronous() const final; 105 bool isAllowedToAskUserForCredentials() const final { return m_isAllowedToAskUserForCredentials; } 106 void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&&) final; 107 void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final; 108 void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) final; 109 void didFinishLoading(const WebCore::NetworkLoadMetrics&) final; 110 void didFailLoading(const WebCore::ResourceError&) final; 111 void didBlockAuthenticationChallenge() final; 112 void didReceiveChallenge(const WebCore::AuthenticationChallenge&) final; 113 bool shouldCaptureExtraNetworkLoadMetrics() const final; 110 114 111 115 void convertToDownload(DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&); … … 195 199 196 200 Optional<Seconds> validateCacheEntryForMaxAgeCapValidation(const WebCore::ResourceRequest&, const WebCore::ResourceRequest& redirectRequest, const WebCore::ResourceResponse&); 201 202 ResourceLoadInfo resourceLoadInfo(); 197 203 198 204 const NetworkResourceLoadParameters m_parameters; … … 235 241 std::unique_ptr<ServiceWorkerFetchTask> m_serviceWorkerFetchTask; 236 242 #endif 243 NetworkResourceLoadIdentifier m_resourceLoadID; 244 WebCore::ResourceResponse m_redirectResponse; 237 245 }; 238 246 -
trunk/Source/WebKit/Shared/API/APIObject.h
r253868 r254345 72 72 RenderLayer, 73 73 RenderObject, 74 ResourceLoadInfo, 74 75 SecurityOrigin, 75 76 SessionState, -
trunk/Source/WebKit/Shared/Cocoa/APIObject.mm
r253868 r254345 82 82 #import "_WKInternalDebugFeatureInternal.h" 83 83 #import "_WKProcessPoolConfigurationInternal.h" 84 #import "_WKResourceLoadInfoInternal.h" 84 85 #import "_WKResourceLoadStatisticsFirstPartyInternal.h" 85 86 #import "_WKResourceLoadStatisticsThirdPartyInternal.h" … … 333 334 break; 334 335 336 case Type::ResourceLoadInfo: 337 wrapper = [_WKResourceLoadInfo alloc]; 338 break; 339 335 340 case Type::ResourceLoadStatisticsFirstParty: 336 341 wrapper = [_WKResourceLoadStatisticsFirstParty alloc]; -
trunk/Source/WebKit/SourcesCocoa.txt
r254194 r254345 265 265 UIProcess/API/Cocoa/_WKProcessPoolConfiguration.mm 266 266 UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm 267 UIProcess/API/Cocoa/_WKResourceLoadInfo.mm 267 268 UIProcess/API/Cocoa/_WKSessionState.mm 268 269 UIProcess/API/Cocoa/_WKTextInputContext.mm -
trunk/Source/WebKit/UIProcess/API/APIResourceLoadClient.h
r254183 r254345 26 26 #pragma once 27 27 28 namespace WebKit { 29 class AuthenticationChallengeProxy; 30 struct ResourceLoadInfo; 31 } 32 28 33 namespace API { 29 34 … … 32 37 virtual ~ResourceLoadClient() = default; 33 38 34 virtual void willSendRequest(const WebCore::ResourceRequest&) const = 0; 39 virtual void didSendRequest(WebKit::ResourceLoadInfo&&, WebCore::ResourceRequest&&) const = 0; 40 virtual void didPerformHTTPRedirection(WebKit::ResourceLoadInfo&&, WebCore::ResourceResponse&&, WebCore::ResourceRequest&&) const = 0; 41 virtual void didReceiveChallenge(WebKit::ResourceLoadInfo&&, WebKit::AuthenticationChallengeProxy&) const = 0; 42 virtual void didReceiveResponse(WebKit::ResourceLoadInfo&&, WebCore::ResourceResponse&&) const = 0; 43 virtual void didCompleteWithError(WebKit::ResourceLoadInfo&&, WebCore::ResourceError&&) const = 0; 35 44 }; 36 45 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKResourceLoadDelegate.h
r254183 r254345 26 26 #import <WebKit/WKFoundation.h> 27 27 28 @class _WKResourceLoadInfo; 29 28 30 NS_ASSUME_NONNULL_BEGIN 29 31 … … 32 34 @optional 33 35 34 - (void)webView:(WKWebView *)webView willSendRequest:(NSURLRequest *)request; 36 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didSendRequest:(NSURLRequest *)request; 37 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didPerformHTTPRedirection:(NSURLResponse *)response newRequest:(NSURLRequest *)request; 38 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge; 39 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didReceiveResponse:(NSURLResponse *)response; 40 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didCompleteWithError:(NSError * __nullable)error; 35 41 36 42 @end -
trunk/Source/WebKit/UIProcess/Authentication/AuthenticationChallengeProxy.cpp
r241658 r254345 46 46 AuthenticationChallengeProxy::AuthenticationChallengeProxy(WebCore::AuthenticationChallenge&& authenticationChallenge, uint64_t challengeID, Ref<IPC::Connection>&& connection, WeakPtr<SecKeyProxyStore>&& secKeyProxyStore) 47 47 : m_coreAuthenticationChallenge(WTFMove(authenticationChallenge)) 48 , m_listener(AuthenticationDecisionListener::create( [challengeID, connection = WTFMove(connection), secKeyProxyStore = WTFMove(secKeyProxyStore)](AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential) {48 , m_listener(AuthenticationDecisionListener::create(challengeID ? CompletionHandler<void(AuthenticationChallengeDisposition, const WebCore::Credential&)>([challengeID, connection = WTFMove(connection), secKeyProxyStore = WTFMove(secKeyProxyStore)](AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential) { 49 49 #if HAVE(SEC_KEY_PROXY) 50 50 if (secKeyProxyStore && secKeyProxyStore->initialize(credential)) { … … 54 54 #endif 55 55 connection->send(Messages::AuthenticationManager::CompleteAuthenticationChallenge(challengeID, disposition, credential), 0); 56 }) )56 }) : nullptr)) 57 57 { 58 58 } -
trunk/Source/WebKit/UIProcess/Cocoa/ResourceLoadDelegate.h
r254183 r254345 58 58 private: 59 59 // API::ResourceLoadClient 60 void willSendRequest(const WebCore::ResourceRequest&) const final; 60 void didSendRequest(ResourceLoadInfo&&, WebCore::ResourceRequest&&) const final; 61 void didPerformHTTPRedirection(ResourceLoadInfo&&, WebCore::ResourceResponse&&, WebCore::ResourceRequest&&) const final; 62 void didReceiveChallenge(ResourceLoadInfo&&, WebKit::AuthenticationChallengeProxy&) const final; 63 void didReceiveResponse(ResourceLoadInfo&&, WebCore::ResourceResponse&&) const final; 64 void didCompleteWithError(ResourceLoadInfo&&, WebCore::ResourceError&&) const final; 61 65 62 66 ResourceLoadDelegate& m_resourceLoadDelegate; … … 67 71 68 72 struct { 69 bool willSendRequest : 1; 73 bool didSendRequest : 1; 74 bool didPerformHTTPRedirection : 1; 75 bool didReceiveChallenge : 1; 76 bool didReceiveResponse : 1; 77 bool didCompleteWithError : 1; 70 78 } m_delegateMethods; 71 79 }; -
trunk/Source/WebKit/UIProcess/Cocoa/ResourceLoadDelegate.mm
r254183 r254345 28 28 29 29 #import "_WKResourceLoadDelegate.h" 30 #import "_WKResourceLoadInfoInternal.h" 30 31 31 32 namespace WebKit { … … 52 53 m_delegate = delegate; 53 54 54 m_delegateMethods.willSendRequest = [delegate respondsToSelector:@selector(webView:willSendRequest:)]; 55 // resourceWithID: 56 // type: 57 // _WKFrameHandle frame: 58 // _WKFrameHandle parentFrame: 59 60 m_delegateMethods.didSendRequest = [delegate respondsToSelector:@selector(webView:resourceLoad:didSendRequest:)]; 61 m_delegateMethods.didPerformHTTPRedirection = [delegate respondsToSelector:@selector(webView:resourceLoad:didPerformHTTPRedirection:newRequest:)]; 62 m_delegateMethods.didReceiveChallenge = [delegate respondsToSelector:@selector(webView:resourceLoad:didReceiveChallenge:)]; 63 m_delegateMethods.didReceiveResponse = [delegate respondsToSelector:@selector(webView:resourceLoad:didReceiveResponse:)]; 64 m_delegateMethods.didCompleteWithError = [delegate respondsToSelector:@selector(webView:resourceLoad:didCompleteWithError:)]; 55 65 } 56 66 … … 62 72 ResourceLoadDelegate::ResourceLoadClient::~ResourceLoadClient() = default; 63 73 64 void ResourceLoadDelegate::ResourceLoadClient:: willSendRequest(const WebCore::ResourceRequest& request) const74 void ResourceLoadDelegate::ResourceLoadClient::didSendRequest(WebKit::ResourceLoadInfo&& loadInfo, WebCore::ResourceRequest&& request) const 65 75 { 66 if (!m_resourceLoadDelegate.m_delegateMethods. willSendRequest)76 if (!m_resourceLoadDelegate.m_delegateMethods.didSendRequest) 67 77 return; 68 78 … … 71 81 return; 72 82 73 [delegate webView:m_resourceLoadDelegate.m_webView.get().get() willSendRequest:request.nsURLRequest(HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody)]; 83 [delegate webView:m_resourceLoadDelegate.m_webView.get().get() resourceLoad:wrapper(API::ResourceLoadInfo::create(WTFMove(loadInfo)).get()) didSendRequest:request.nsURLRequest(HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody)]; 84 } 85 86 void ResourceLoadDelegate::ResourceLoadClient::didPerformHTTPRedirection(WebKit::ResourceLoadInfo&& loadInfo, WebCore::ResourceResponse&& response, WebCore::ResourceRequest&& request) const 87 { 88 if (!m_resourceLoadDelegate.m_delegateMethods.didPerformHTTPRedirection) 89 return; 90 91 auto delegate = m_resourceLoadDelegate.m_delegate.get(); 92 if (!delegate) 93 return; 94 95 [delegate webView:m_resourceLoadDelegate.m_webView.get().get() resourceLoad:wrapper(API::ResourceLoadInfo::create(WTFMove(loadInfo)).get()) didPerformHTTPRedirection:response.nsURLResponse() newRequest:request.nsURLRequest(HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody)]; 96 } 97 98 void ResourceLoadDelegate::ResourceLoadClient::didReceiveChallenge(WebKit::ResourceLoadInfo&& loadInfo, WebKit::AuthenticationChallengeProxy& challenge) const 99 { 100 if (!m_resourceLoadDelegate.m_delegateMethods.didReceiveChallenge) 101 return; 102 103 auto delegate = m_resourceLoadDelegate.m_delegate.get(); 104 if (!delegate) 105 return; 106 107 [delegate webView:m_resourceLoadDelegate.m_webView.get().get() resourceLoad:wrapper(API::ResourceLoadInfo::create(WTFMove(loadInfo)).get()) didReceiveChallenge:wrapper(challenge)]; 108 } 109 110 void ResourceLoadDelegate::ResourceLoadClient::didReceiveResponse(WebKit::ResourceLoadInfo&& loadInfo, WebCore::ResourceResponse&& response) const 111 { 112 if (!m_resourceLoadDelegate.m_delegateMethods.didReceiveResponse) 113 return; 114 115 auto delegate = m_resourceLoadDelegate.m_delegate.get(); 116 if (!delegate) 117 return; 118 119 [delegate webView:m_resourceLoadDelegate.m_webView.get().get() resourceLoad:wrapper(API::ResourceLoadInfo::create(WTFMove(loadInfo)).get()) didReceiveResponse:response.nsURLResponse()]; 120 } 121 122 void ResourceLoadDelegate::ResourceLoadClient::didCompleteWithError(WebKit::ResourceLoadInfo&& loadInfo, WebCore::ResourceError&& error) const 123 { 124 if (!m_resourceLoadDelegate.m_delegateMethods.didCompleteWithError) 125 return; 126 127 auto delegate = m_resourceLoadDelegate.m_delegate.get(); 128 if (!delegate) 129 return; 130 131 [delegate webView:m_resourceLoadDelegate.m_webView.get().get() resourceLoad:wrapper(API::ResourceLoadInfo::create(WTFMove(loadInfo)).get()) didCompleteWithError:error.nsError()]; 74 132 } 75 133 -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
r254342 r254345 453 453 } 454 454 455 void NetworkProcessProxy:: pageWillSendRequest(WebPageProxyIdentifier pageID, const WebCore::ResourceRequest& request)455 void NetworkProcessProxy::resourceLoadDidSendRequest(WebPageProxyIdentifier pageID, ResourceLoadInfo&& loadInfo, WebCore::ResourceRequest&& request) 456 456 { 457 457 auto* page = WebProcessProxy::webPage(pageID); … … 459 459 return; 460 460 461 page->willSendRequest(request); 461 page->resourceLoadDidSendRequest(WTFMove(loadInfo), WTFMove(request)); 462 } 463 464 void NetworkProcessProxy::resourceLoadDidPerformHTTPRedirection(WebPageProxyIdentifier pageID, ResourceLoadInfo&& loadInfo, WebCore::ResourceResponse&& response, WebCore::ResourceRequest&& request) 465 { 466 auto* page = WebProcessProxy::webPage(pageID); 467 if (!page) 468 return; 469 470 page->resourceLoadDidPerformHTTPRedirection(WTFMove(loadInfo), WTFMove(response), WTFMove(request)); 471 } 472 473 void NetworkProcessProxy::resourceLoadDidReceiveChallenge(WebPageProxyIdentifier pageID, ResourceLoadInfo&& loadInfo, WebCore::AuthenticationChallenge&& challenge) 474 { 475 auto* page = WebProcessProxy::webPage(pageID); 476 if (!page) 477 return; 478 479 auto challengeProxy = AuthenticationChallengeProxy::create(WTFMove(challenge), 0, *connection(), nullptr); 480 page->resourceLoadDidReceiveChallenge(WTFMove(loadInfo), challengeProxy.get()); 481 } 482 483 void NetworkProcessProxy::resourceLoadDidReceiveResponse(WebPageProxyIdentifier pageID, ResourceLoadInfo&& loadInfo, WebCore::ResourceResponse&& response) 484 { 485 auto* page = WebProcessProxy::webPage(pageID); 486 if (!page) 487 return; 488 489 page->resourceLoadDidReceiveResponse(WTFMove(loadInfo), WTFMove(response)); 490 } 491 492 void NetworkProcessProxy::resourceLoadDidCompleteWithError(WebPageProxyIdentifier pageID, ResourceLoadInfo&& loadInfo, WebCore::ResourceError&& error) 493 { 494 auto* page = WebProcessProxy::webPage(pageID); 495 if (!page) 496 return; 497 498 page->resourceLoadDidCompleteWithError(WTFMove(loadInfo), WTFMove(error)); 462 499 } 463 500 -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
r254183 r254345 65 65 class DownloadProxyMap; 66 66 class WebProcessPool; 67 class WebUserContentControllerProxy; 68 67 69 enum class ShouldGrandfatherStatistics : bool; 68 70 enum class StorageAccessStatus : uint8_t; 69 71 enum class WebsiteDataFetchOption; 70 72 enum class WebsiteDataType; 73 71 74 struct NetworkProcessCreationParameters; 72 class WebUserContentControllerProxy;75 struct ResourceLoadInfo; 73 76 struct WebsiteData; 74 77 … … 202 205 void resetQuota(PAL::SessionID, CompletionHandler<void()>&&); 203 206 204 void pageWillSendRequest(WebPageProxyIdentifier, const WebCore::ResourceRequest&); 207 void resourceLoadDidSendRequest(WebPageProxyIdentifier, ResourceLoadInfo&&, WebCore::ResourceRequest&&); 208 void resourceLoadDidPerformHTTPRedirection(WebPageProxyIdentifier, ResourceLoadInfo&&, WebCore::ResourceResponse&&, WebCore::ResourceRequest&&); 209 void resourceLoadDidReceiveChallenge(WebPageProxyIdentifier, ResourceLoadInfo&&, WebCore::AuthenticationChallenge&&); 210 void resourceLoadDidReceiveResponse(WebPageProxyIdentifier, ResourceLoadInfo&&, WebCore::ResourceResponse&&); 211 void resourceLoadDidCompleteWithError(WebPageProxyIdentifier, ResourceLoadInfo&&, WebCore::ResourceError&&); 205 212 206 213 private: -
trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in
r254183 r254345 69 69 RequestStorageSpace(PAL::SessionID sessionID, struct WebCore::ClientOrigin origin, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired) -> (Optional<uint64_t> newQuota) Async 70 70 71 PageWillSendRequest(WebKit::WebPageProxyIdentifier pageIdentifier, WebCore::ResourceRequest request) 71 ResourceLoadDidSendRequest(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::ResourceRequest request) 72 ResourceLoadDidPerformHTTPRedirection(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::ResourceResponse resourceResponse, WebCore::ResourceRequest request) 73 ResourceLoadDidReceiveChallenge(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::AuthenticationChallenge challenge) 74 ResourceLoadDidReceiveResponse(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::ResourceResponse response) 75 ResourceLoadDidCompleteWithError(WebKit::WebPageProxyIdentifier pageIdentifier, struct WebKit::ResourceLoadInfo resourceLoadInfo, WebCore::ResourceError error) 72 76 } -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r254312 r254345 5922 5922 } 5923 5923 5924 void WebPageProxy:: willSendRequest(const WebCore::ResourceRequest& request)5924 void WebPageProxy::resourceLoadDidSendRequest(ResourceLoadInfo&& loadInfo, WebCore::ResourceRequest&& request) 5925 5925 { 5926 5926 if (m_resourceLoadClient) 5927 m_resourceLoadClient->willSendRequest(request); 5927 m_resourceLoadClient->didSendRequest(WTFMove(loadInfo), WTFMove(request)); 5928 } 5929 5930 void WebPageProxy::resourceLoadDidPerformHTTPRedirection(ResourceLoadInfo&& loadInfo, WebCore::ResourceResponse&& response, WebCore::ResourceRequest&& request) 5931 { 5932 if (m_resourceLoadClient) 5933 m_resourceLoadClient->didPerformHTTPRedirection(WTFMove(loadInfo), WTFMove(response), WTFMove(request)); 5934 } 5935 5936 void WebPageProxy::resourceLoadDidReceiveChallenge(ResourceLoadInfo&& loadInfo, WebKit::AuthenticationChallengeProxy& challenge) 5937 { 5938 if (m_resourceLoadClient) 5939 m_resourceLoadClient->didReceiveChallenge(WTFMove(loadInfo), challenge); 5940 } 5941 5942 void WebPageProxy::resourceLoadDidReceiveResponse(ResourceLoadInfo&& loadInfo, WebCore::ResourceResponse&& response) 5943 { 5944 if (m_resourceLoadClient) 5945 m_resourceLoadClient->didReceiveResponse(WTFMove(loadInfo), WTFMove(response)); 5946 } 5947 5948 void WebPageProxy::resourceLoadDidCompleteWithError(ResourceLoadInfo&& loadInfo, WebCore::ResourceError&& error) 5949 { 5950 if (m_resourceLoadClient) 5951 m_resourceLoadClient->didCompleteWithError(WTFMove(loadInfo), WTFMove(error)); 5928 5952 } 5929 5953 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r254312 r254345 326 326 struct PrintInfo; 327 327 struct PDFContextMenu; 328 struct ResourceLoadInfo; 328 329 struct WebAutocorrectionData; 329 330 struct WebHitTestResultData; … … 471 472 WebInspectorProxy* inspector() const; 472 473 473 void willSendRequest(const WebCore::ResourceRequest&); 474 void resourceLoadDidSendRequest(ResourceLoadInfo&&, WebCore::ResourceRequest&&); 475 void resourceLoadDidPerformHTTPRedirection(ResourceLoadInfo&&, WebCore::ResourceResponse&&, WebCore::ResourceRequest&&); 476 void resourceLoadDidReceiveChallenge(ResourceLoadInfo&&, WebKit::AuthenticationChallengeProxy&); 477 void resourceLoadDidReceiveResponse(ResourceLoadInfo&&, WebCore::ResourceResponse&&); 478 void resourceLoadDidCompleteWithError(ResourceLoadInfo&&, WebCore::ResourceError&&); 474 479 475 480 void didChangeInspectorFrontendCount(unsigned count) { m_inspectorFrontendCount = count; } -
trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
r254081 r254345 49 49 #import "RemoteScrollingCoordinatorProxy.h" 50 50 #import "ShareableResource.h" 51 #import "UIKitSPI.h" 51 52 #import "UserData.h" 52 53 #import "UserInterfaceIdiom.h" -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r254307 r254345 1171 1171 5CB2378E1DF0E0D300117AA3 /* _WKWebsitePoliciesInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB2378D1DF0E0C200117AA3 /* _WKWebsitePoliciesInternal.h */; }; 1172 1172 5CB7AFE023C52CE500E49CF3 /* _WKResourceLoadDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB7AFDF23C52CBC00E49CF3 /* _WKResourceLoadDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1173 5CB7AFE723C6820700E49CF3 /* ResourceLoadInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB7AFE623C681B000E49CF3 /* ResourceLoadInfo.h */; }; 1174 5CB7AFE823C69B6100E49CF3 /* _WKResourceLoadInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB7AFE323C67D3700E49CF3 /* _WKResourceLoadInfo.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1173 1175 5CBC9B8E1C652CA000A8FDCF /* NetworkDataTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CBC9B891C6524A500A8FDCF /* NetworkDataTask.h */; }; 1174 1176 5CBD595C2280EDF4002B22AA /* _WKCustomHeaderFields.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C5D2388227A1892000B9BDA /* _WKCustomHeaderFields.mm */; }; … … 3908 3910 5CB7AFDE23C5273D00E49CF3 /* ResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceLoadDelegate.mm; sourceTree = "<group>"; }; 3909 3911 5CB7AFDF23C52CBC00E49CF3 /* _WKResourceLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKResourceLoadDelegate.h; sourceTree = "<group>"; }; 3912 5CB7AFE223C67D3700E49CF3 /* _WKResourceLoadInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKResourceLoadInfo.mm; sourceTree = "<group>"; }; 3913 5CB7AFE323C67D3700E49CF3 /* _WKResourceLoadInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKResourceLoadInfo.h; sourceTree = "<group>"; }; 3914 5CB7AFE423C67D6400E49CF3 /* APIResourceLoadInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIResourceLoadInfo.h; sourceTree = "<group>"; }; 3915 5CB7AFE523C67DF900E49CF3 /* _WKResourceLoadInfoInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKResourceLoadInfoInternal.h; sourceTree = "<group>"; }; 3916 5CB7AFE623C681B000E49CF3 /* ResourceLoadInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadInfo.h; sourceTree = "<group>"; }; 3910 3917 5CBC9B891C6524A500A8FDCF /* NetworkDataTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkDataTask.h; sourceTree = "<group>"; }; 3911 3918 5CBC9B8B1C65257300A8FDCF /* NetworkDataTaskCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkDataTaskCocoa.mm; sourceTree = "<group>"; }; … … 3920 3927 5CD2864F1E722F440094FDC8 /* WKContentRuleListStoreInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContentRuleListStoreInternal.h; sourceTree = "<group>"; }; 3921 3928 5CD286501E722F440094FDC8 /* WKContentRuleListStorePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContentRuleListStorePrivate.h; sourceTree = "<group>"; }; 3929 5CD748B523C8EB190092A9B5 /* NetworkResourceLoadIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkResourceLoadIdentifier.h; sourceTree = "<group>"; }; 3922 3930 5CE0C366229F2D3D003695F0 /* APIContextMenuElementInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = APIContextMenuElementInfo.cpp; sourceTree = "<group>"; }; 3923 3931 5CE0C367229F2D3E003695F0 /* APIContextMenuElementInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIContextMenuElementInfo.h; sourceTree = "<group>"; }; … … 5618 5626 1ADCB868189831B30022EE5A /* NavigationActionData.cpp */, 5619 5627 1ADCB869189831B30022EE5A /* NavigationActionData.h */, 5628 5CD748B523C8EB190092A9B5 /* NetworkResourceLoadIdentifier.h */, 5620 5629 9BC59D6D1EFCDC6D001E8D09 /* OptionalCallbackID.h */, 5621 5630 7AFBD36E21E546E3005DBACB /* PersistencyUtils.cpp */, … … 5627 5636 463FD4811EB94EAD00A2982C /* ProcessTerminationReason.h */, 5628 5637 F6A0C13F13281E6E0070430F /* ResourceCachesToClear.h */, 5638 5CB7AFE623C681B000E49CF3 /* ResourceLoadInfo.h */, 5629 5639 410482CB1DDD2FB500F006D0 /* RTCNetwork.cpp */, 5630 5640 410482CC1DDD2FB500F006D0 /* RTCNetwork.h */, … … 6783 6793 990E1E082384A88B004602DF /* _WKRemoteWebInspectorViewControllerPrivate.h */, 6784 6794 5CB7AFDF23C52CBC00E49CF3 /* _WKResourceLoadDelegate.h */, 6795 5CB7AFE323C67D3700E49CF3 /* _WKResourceLoadInfo.h */, 6796 5CB7AFE223C67D3700E49CF3 /* _WKResourceLoadInfo.mm */, 6797 5CB7AFE523C67DF900E49CF3 /* _WKResourceLoadInfoInternal.h */, 6785 6798 49FBEFFB239ADB1800BD032F /* _WKResourceLoadStatisticsFirstParty.h */, 6786 6799 49FBEFFC239B011D00BD032F /* _WKResourceLoadStatisticsFirstParty.mm */, … … 8493 8506 7CE4D21E1A4914CA00C7F152 /* APIProcessPoolConfiguration.h */, 8494 8507 5CB7AFDA23C43E6400E49CF3 /* APIResourceLoadClient.h */, 8508 5CB7AFE423C67D6400E49CF3 /* APIResourceLoadInfo.h */, 8495 8509 49BCA19123A177660028A836 /* APIResourceLoadStatisticsFirstParty.h */, 8496 8510 49BCA19623A18F620028A836 /* APIResourceLoadStatisticsThirdParty.h */, … … 9840 9854 1F604BAA1889FBB800EE0395 /* _WKRenderingProgressEventsInternal.h in Headers */, 9841 9855 5CB7AFE023C52CE500E49CF3 /* _WKResourceLoadDelegate.h in Headers */, 9856 5CB7AFE823C69B6100E49CF3 /* _WKResourceLoadInfo.h in Headers */, 9842 9857 49FBF001239B1F8D00BD032F /* _WKResourceLoadStatisticsFirstParty.h in Headers */, 9843 9858 49BCA19523A18CFD0028A836 /* _WKResourceLoadStatisticsFirstPartyInternal.h in Headers */, … … 10300 10315 A55BA8251BA25CFB007CD33D /* RemoteWebInspectorProxyMessages.h in Headers */, 10301 10316 A55BA8171BA23E12007CD33D /* RemoteWebInspectorUI.h in Headers */, 10317 5CB7AFE723C6820700E49CF3 /* ResourceLoadInfo.h in Headers */, 10302 10318 6BE969CD1E54E054008B7483 /* ResourceLoadStatisticsClassifier.h in Headers */, 10303 10319 6BE969CB1E54D4CF008B7483 /* ResourceLoadStatisticsClassifierCocoa.h in Headers */, -
trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp
r254183 r254345 527 527 void WebLoaderStrategy::loadResourceSynchronously(FrameLoader& frameLoader, unsigned long resourceLoadIdentifier, const ResourceRequest& request, ClientCredentialPolicy clientCredentialPolicy, const FetchOptions& options, const HTTPHeaderMap& originalRequestHeaders, ResourceError& error, ResourceResponse& response, Vector<char>& data) 528 528 { 529 WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(frameLoader.client()); 530 WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr; 531 WebPage* webPage = webFrame ? webFrame->page() : nullptr; 529 auto* webFrameLoaderClient = toWebFrameLoaderClient(frameLoader.client()); 530 auto* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : nullptr; 531 auto* webPage = webFrame ? webFrame->page() : nullptr; 532 auto* page = webPage ? webPage->corePage() : nullptr; 532 533 533 534 auto webPageProxyID = webPage ? webPage->webPageProxyIdentifier() : WebPageProxyIdentifier { }; … … 580 581 } 581 582 loadParameters.originalRequestHeaders = originalRequestHeaders; 583 if (page) 584 loadParameters.pageHasResourceLoadClient = page->hasResourceLoadClient(); 582 585 583 586 data.shrink(0); … … 592 595 if (!WebProcess::singleton().ensureNetworkProcessConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad(loadParameters), Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::Reply(error, response, data), 0)) { 593 596 WEBLOADERSTRATEGY_WITH_FRAMELOADER_RELEASE_LOG_ERROR_IF_ALLOWED("loadResourceSynchronously: failed sending synchronous network process message"); 594 if ( auto* page = webPage ? webPage->corePage() : nullptr)597 if (page) 595 598 page->diagnosticLoggingClient().logDiagnosticMessage(WebCore::DiagnosticLoggingKeys::internalErrorKey(), WebCore::DiagnosticLoggingKeys::synchronousMessageFailedKey(), WebCore::ShouldSample::No); 596 599 response = ResourceResponse(); … … 645 648 loadParameters.cspResponseHeaders = contentSecurityPolicy->responseHeaders(); 646 649 } 650 if (auto* page = document->page()) 651 loadParameters.pageHasResourceLoadClient = page->hasResourceLoadClient(); 647 652 648 653 #if ENABLE(CONTENT_EXTENSIONS) -
trunk/Tools/ChangeLog
r254344 r254345 1 2020-01-10 Alex Christensen <achristensen@webkit.org> 2 3 Expand _WKResourceLoadDelegate callbacks 4 https://bugs.webkit.org/show_bug.cgi?id=206037 5 6 Reviewed by Youenn Fablet. 7 8 * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm: 9 (-[TestResourceLoadDelegate webView:resourceLoad:didSendRequest:]): 10 (-[TestResourceLoadDelegate webView:resourceLoad:didPerformHTTPRedirection:newRequest:]): 11 (-[TestResourceLoadDelegate webView:resourceLoad:didReceiveChallenge:]): 12 (-[TestResourceLoadDelegate webView:resourceLoad:didReceiveResponse:]): 13 (-[TestResourceLoadDelegate webView:resourceLoad:didCompleteWithError:]): 14 (TEST): 15 (-[TestResourceLoadDelegate webView:willSendRequest:]): Deleted. 16 * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: 17 * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm: 18 (TEST): 19 * TestWebKitAPI/cocoa/HTTPServer.h: 20 (TestWebKitAPI::HTTPServer::HTTPResponse::HTTPResponse): 21 Add the ability to have non-200 status codes in responses. 22 Also switch the order of parameters to reflect the fact that header fields are sent before the body. 23 * TestWebKitAPI/cocoa/HTTPServer.mm: 24 (TestWebKitAPI::statusText): 25 (TestWebKitAPI::HTTPServer::respondToRequests): 26 1 27 2020-01-10 Alex Christensen <achristensen@webkit.org> 2 28 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm
r254183 r254345 26 26 #import "config.h" 27 27 28 #import "HTTPServer.h" 28 29 #import "PlatformUtilities.h" 30 #import "TCPServer.h" 29 31 #import "TestNavigationDelegate.h" 32 #import "TestWKWebView.h" 30 33 #import <WebKit/WKWebViewPrivate.h> 31 34 #import <WebKit/WebKit.h> 32 35 #import <WebKit/_WKResourceLoadDelegate.h> 36 #import <WebKit/_WKResourceLoadInfo.h> 33 37 #import <wtf/RetainPtr.h> 34 38 35 39 @interface TestResourceLoadDelegate : NSObject <_WKResourceLoadDelegate> 36 40 37 @property (nonatomic, copy) void (^willSendRequest)(WKWebView *, NSURLRequest *); 41 @property (nonatomic, copy) void (^didSendRequest)(WKWebView *, _WKResourceLoadInfo *, NSURLRequest *); 42 @property (nonatomic, copy) void (^didPerformHTTPRedirection)(WKWebView *, _WKResourceLoadInfo *, NSURLResponse *, NSURLRequest *); 43 @property (nonatomic, copy) void (^didReceiveChallenge)(WKWebView *, _WKResourceLoadInfo *, NSURLAuthenticationChallenge *); 44 @property (nonatomic, copy) void (^didReceiveResponse)(WKWebView *, _WKResourceLoadInfo *, NSURLResponse *); 45 @property (nonatomic, copy) void (^didCompleteWithError)(WKWebView *, _WKResourceLoadInfo *, NSError *); 38 46 39 47 @end … … 41 49 @implementation TestResourceLoadDelegate 42 50 43 - (void)webView:(WKWebView *)webView willSendRequest:(NSURLRequest *)request 44 { 45 if (_willSendRequest) 46 _willSendRequest(webView, request); 51 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didSendRequest:(NSURLRequest *)request 52 { 53 if (_didSendRequest) 54 _didSendRequest(webView, resourceLoad, request); 55 } 56 57 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didPerformHTTPRedirection:(NSURLResponse *)response newRequest:(NSURLRequest *)request 58 { 59 if (_didPerformHTTPRedirection) 60 _didPerformHTTPRedirection(webView, resourceLoad, response, request); 61 } 62 63 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge 64 { 65 if (_didReceiveChallenge) 66 _didReceiveChallenge(webView, resourceLoad, challenge); 67 } 68 69 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didReceiveResponse:(NSURLResponse *)response 70 { 71 if (_didReceiveResponse) 72 _didReceiveResponse(webView, resourceLoad, response); 73 } 74 75 - (void)webView:(WKWebView *)webView resourceLoad:(_WKResourceLoadInfo *)resourceLoad didCompleteWithError:(NSError *)error 76 { 77 if (_didCompleteWithError) 78 _didCompleteWithError(webView, resourceLoad, error); 47 79 } 48 80 … … 63 95 auto resourceLoadDelegate = adoptNS([TestResourceLoadDelegate new]); 64 96 [webView _setResourceLoadDelegate:resourceLoadDelegate.get()]; 65 [resourceLoadDelegate set WillSendRequest:^(WKWebView*, NSURLRequest *request) {97 [resourceLoadDelegate setDidSendRequest:^(WKWebView *, _WKResourceLoadInfo *, NSURLRequest *request) { 66 98 requestFromDelegate = request; 67 99 }]; … … 73 105 EXPECT_WK_STREQ(requestLoaded.get().URL.absoluteString, requestFromDelegate.get().URL.absoluteString); 74 106 } 107 108 #if HAVE(NETWORK_FRAMEWORK) 109 110 TEST(ResourceLoadDelegate, BeaconAndSyncXHR) 111 { 112 TestWebKitAPI::HTTPServer server({ 113 { "/", { "hello" } }, 114 { "/xhrTarget", { "hi" } }, 115 { "/beaconTarget", { "hi" } }, 116 }); 117 118 auto webView = adoptNS([TestWKWebView new]); 119 [webView synchronouslyLoadRequest:server.request()]; 120 121 __block RetainPtr<NSURLRequest> requestFromDelegate; 122 __block bool receivedCallback = false; 123 auto resourceLoadDelegate = adoptNS([TestResourceLoadDelegate new]); 124 [webView _setResourceLoadDelegate:resourceLoadDelegate.get()]; 125 [resourceLoadDelegate setDidSendRequest:^(WKWebView *, _WKResourceLoadInfo *, NSURLRequest *request) { 126 requestFromDelegate = request; 127 receivedCallback = true; 128 }]; 129 130 [webView evaluateJavaScript:@"navigator.sendBeacon('/beaconTarget')" completionHandler:nil]; 131 TestWebKitAPI::Util::run(&receivedCallback); 132 EXPECT_WK_STREQ("/beaconTarget", requestFromDelegate.get().URL.path); 133 134 receivedCallback = false; 135 [webView evaluateJavaScript: 136 @"var request = new XMLHttpRequest();" 137 "var asynchronous = false;" 138 "request.open('GET', 'xhrTarget', asynchronous);" 139 "request.send();" completionHandler:nil]; 140 TestWebKitAPI::Util::run(&receivedCallback); 141 EXPECT_WK_STREQ("/xhrTarget", requestFromDelegate.get().URL.path); 142 } 143 144 TEST(ResourceLoadDelegate, Redirect) 145 { 146 TestWebKitAPI::HTTPServer server({ 147 { "/", { 301, {{ "Location", "/redirectTarget" }} } }, 148 { "/redirectTarget", { "hi" } }, 149 }); 150 151 __block bool done = false; 152 auto resourceLoadDelegate = adoptNS([TestResourceLoadDelegate new]); 153 [resourceLoadDelegate setDidPerformHTTPRedirection:^(WKWebView *, _WKResourceLoadInfo *, NSURLResponse *response, NSURLRequest *request) { 154 EXPECT_WK_STREQ(response.URL.path, "/"); 155 EXPECT_WK_STREQ(request.URL.path, "/redirectTarget"); 156 done = true; 157 }]; 158 159 auto webView = adoptNS([WKWebView new]); 160 [webView _setResourceLoadDelegate:resourceLoadDelegate.get()]; 161 [webView loadRequest:server.request()]; 162 TestWebKitAPI::Util::run(&done); 163 } 164 165 TEST(ResourceLoadDelegate, LoadInfo) 166 { 167 TestWebKitAPI::HTTPServer server({ 168 { "/", { "<iframe src='iframeSrc'></iframe>" } }, 169 { "/iframeSrc", { "<script>fetch('fetchTarget')</script>" } }, 170 { "/fetchTarget", { "hi" } }, 171 }); 172 173 enum class Callback { 174 DidSendRequest, 175 DidReceiveResponse, 176 DidCompleteWithError, 177 }; 178 179 __block Vector<Callback> callbacks; 180 __block Vector<RetainPtr<WKWebView>> webViews; 181 __block Vector<RetainPtr<_WKResourceLoadInfo>> loadInfos; 182 __block Vector<RetainPtr<id>> otherParameters; 183 184 __block size_t resourceCompletionCount = 0; 185 auto delegate = adoptNS([TestResourceLoadDelegate new]); 186 [delegate setDidSendRequest:^(WKWebView *webView, _WKResourceLoadInfo *loadInfo, NSURLRequest *request) { 187 callbacks.append(Callback::DidSendRequest); 188 webViews.append(webView); 189 loadInfos.append(loadInfo); 190 otherParameters.append(request); 191 }]; 192 [delegate setDidReceiveResponse:^(WKWebView *webView, _WKResourceLoadInfo *loadInfo, NSURLResponse *response) { 193 callbacks.append(Callback::DidReceiveResponse); 194 webViews.append(webView); 195 loadInfos.append(loadInfo); 196 otherParameters.append(response); 197 }]; 198 [delegate setDidCompleteWithError:^(WKWebView *webView, _WKResourceLoadInfo *loadInfo, NSError *error) { 199 callbacks.append(Callback::DidCompleteWithError); 200 webViews.append(webView); 201 loadInfos.append(loadInfo); 202 otherParameters.append(error); 203 resourceCompletionCount++; 204 }]; 205 206 auto webView = adoptNS([WKWebView new]); 207 [webView _setResourceLoadDelegate:delegate.get()]; 208 [webView loadRequest:server.request()]; 209 while (resourceCompletionCount < 3) 210 TestWebKitAPI::Util::spinRunLoop(); 211 212 Vector<Callback> expectedCallbacks { 213 Callback::DidSendRequest, 214 Callback::DidReceiveResponse, 215 Callback::DidCompleteWithError, 216 Callback::DidSendRequest, 217 Callback::DidReceiveResponse, 218 Callback::DidCompleteWithError, 219 Callback::DidSendRequest, 220 Callback::DidReceiveResponse, 221 Callback::DidCompleteWithError 222 }; 223 EXPECT_EQ(callbacks, expectedCallbacks); 224 225 EXPECT_EQ(webViews.size(), 9ull); 226 for (auto& view : webViews) 227 EXPECT_EQ(webView.get(), view.get()); 228 229 EXPECT_EQ(loadInfos.size(), 9ull); 230 EXPECT_EQ(loadInfos[0].get().resourceLoadID, loadInfos[1].get().resourceLoadID); 231 EXPECT_EQ(loadInfos[0].get().resourceLoadID, loadInfos[2].get().resourceLoadID); 232 EXPECT_NE(loadInfos[0].get().resourceLoadID, loadInfos[3].get().resourceLoadID); 233 EXPECT_EQ(loadInfos[3].get().resourceLoadID, loadInfos[4].get().resourceLoadID); 234 EXPECT_EQ(loadInfos[3].get().resourceLoadID, loadInfos[5].get().resourceLoadID); 235 EXPECT_NE(loadInfos[3].get().resourceLoadID, loadInfos[6].get().resourceLoadID); 236 EXPECT_EQ(loadInfos[6].get().resourceLoadID, loadInfos[7].get().resourceLoadID); 237 EXPECT_EQ(loadInfos[6].get().resourceLoadID, loadInfos[8].get().resourceLoadID); 238 EXPECT_NE(loadInfos[6].get().resourceLoadID, loadInfos[0].get().resourceLoadID); 239 240 EXPECT_EQ(otherParameters.size(), 9ull); 241 EXPECT_WK_STREQ(NSStringFromClass([otherParameters[0] class]), "NSMutableURLRequest"); 242 EXPECT_WK_STREQ([otherParameters[0] URL].path, "/"); 243 EXPECT_WK_STREQ(NSStringFromClass([otherParameters[1] class]), "NSHTTPURLResponse"); 244 EXPECT_WK_STREQ([otherParameters[1] URL].path, "/"); 245 EXPECT_EQ(otherParameters[2], nil); 246 EXPECT_WK_STREQ(NSStringFromClass([otherParameters[3] class]), "NSMutableURLRequest"); 247 EXPECT_WK_STREQ([otherParameters[3] URL].path, "/iframeSrc"); 248 EXPECT_WK_STREQ(NSStringFromClass([otherParameters[4] class]), "NSHTTPURLResponse"); 249 EXPECT_WK_STREQ([otherParameters[4] URL].path, "/iframeSrc"); 250 EXPECT_EQ(otherParameters[5], nil); 251 EXPECT_WK_STREQ(NSStringFromClass([otherParameters[6] class]), "NSMutableURLRequest"); 252 EXPECT_WK_STREQ([otherParameters[6] URL].path, "/fetchTarget"); 253 EXPECT_WK_STREQ(NSStringFromClass([otherParameters[7] class]), "NSHTTPURLResponse"); 254 EXPECT_WK_STREQ([otherParameters[7] URL].path, "/fetchTarget"); 255 EXPECT_EQ(otherParameters[8], nil); 256 } 257 258 #endif // HAVE(NETWORK_FRAMEWORK) 259 260 TEST(ResourceLoadDelegate, Challenge) 261 { 262 using namespace TestWebKitAPI; 263 TCPServer server(TCPServer::Protocol::HTTPS, [] (SSL* ssl) { 264 EXPECT_TRUE(!!ssl); // Connection should succeed after a server trust challenge. 265 // Send nothing to make the resource load fail. 266 }); 267 268 auto navigationDelegate = adoptNS([TestNavigationDelegate new]); 269 [navigationDelegate setDidReceiveAuthenticationChallenge:^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^completionHandler)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) { 270 EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust); 271 completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]); 272 }]; 273 274 __block bool receivedErrorNotification = false; 275 __block bool receivedChallengeNotificiation = false; 276 auto resourceLoadDelegate = adoptNS([TestResourceLoadDelegate new]); 277 [resourceLoadDelegate setDidReceiveChallenge:^(WKWebView *, _WKResourceLoadInfo *, NSURLAuthenticationChallenge *challenge) { 278 EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust); 279 receivedChallengeNotificiation = true; 280 }]; 281 [resourceLoadDelegate setDidCompleteWithError:^(WKWebView *, _WKResourceLoadInfo *, NSError *error) { 282 EXPECT_EQ(error.code, kCFURLErrorCannotConnectToHost); 283 EXPECT_WK_STREQ(error.domain, NSURLErrorDomain); 284 receivedErrorNotification = true; 285 }]; 286 287 auto webView = adoptNS([WKWebView new]); 288 [webView setNavigationDelegate:navigationDelegate.get()]; 289 [webView _setResourceLoadDelegate:resourceLoadDelegate.get()]; 290 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]]]; 291 TestWebKitAPI::Util::run(&receivedErrorNotification); 292 EXPECT_TRUE(receivedChallengeNotificiation); 293 } -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm
r254342 r254345 1706 1706 TestWebKitAPI::HTTPServer server({ 1707 1707 { "/", { mainBytes } }, 1708 { "/sw.js", { scriptBytes, {{ "Content-Type", "application/javascript" }}} },1708 { "/sw.js", { {{ "Content-Type", "application/javascript" }}, scriptBytes } }, 1709 1709 }); 1710 1710 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm
r253952 r254345 579 579 { "/index.html", { "<html manifest='test.appcache'>" } }, 580 580 { "/test.appcache", { "CACHE MANIFEST\nindex.html\ntest.mp4\n" } }, 581 { "/test.mp4", { "test!", {{ "Content-Type", "video/test" }}}},581 { "/test.mp4", { {{ "Content-Type", "video/test" }}, "test!" }}, 582 582 }); 583 583 -
trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h
r252476 r254345 53 53 HTTPResponse(String&& body) 54 54 : body(WTFMove(body)) { } 55 HTTPResponse(String&& body, HashMap<String, String>&& headerFields) 56 : body(WTFMove(body)) 57 , headerFields(WTFMove(headerFields)) { } 55 HTTPResponse(HashMap<String, String>&& headerFields, String&& body) 56 : headerFields(WTFMove(headerFields)) 57 , body(WTFMove(body)) { } 58 HTTPResponse(unsigned statusCode, HashMap<String, String>&& headerFields, String&& body = { }) 59 : statusCode(statusCode) 60 , headerFields(WTFMove(headerFields)) 61 , body(WTFMove(body)) { } 58 62 59 63 HTTPResponse(const HTTPResponse&) = default; … … 63 67 HTTPResponse& operator=(HTTPResponse&&) = default; 64 68 69 unsigned statusCode { 200 }; 70 HashMap<String, String> headerFields; 65 71 String body; 66 HashMap<String, String> headerFields;67 72 }; 68 73 -
trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm
r253444 r254345 53 53 } 54 54 55 static String statusText(unsigned statusCode) 56 { 57 switch (statusCode) { 58 case 200: 59 return "OK"_s; 60 case 301: 61 return "Moved Permanently"_s; 62 } 63 ASSERT_NOT_REACHED(); 64 return { }; 65 } 66 55 67 void HTTPServer::respondToRequests(nw_connection_t connection) 56 68 { … … 77 89 auto response = m_requestResponseMap.get(path); 78 90 StringBuilder responseBuilder; 79 responseBuilder.append("HTTP/1.1 200 OK\r\nContent-Length: "); 91 responseBuilder.append("HTTP/1.1 "); 92 responseBuilder.appendNumber(response.statusCode); 93 responseBuilder.append(' '); 94 responseBuilder.append(statusText(response.statusCode)); 95 responseBuilder.append("\r\nContent-Length: "); 80 96 responseBuilder.appendNumber(response.body.length()); 81 97 responseBuilder.append("\r\n");
Note: See TracChangeset
for help on using the changeset viewer.