Changeset 188517 in webkit
- Timestamp:
- Aug 15, 2015 8:29:01 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r188486 r188517 1 2015-08-11 Andy Estes <aestes@apple.com> 2 3 [Cocoa] Add redirect support to CustomProtocolManager 4 https://bugs.webkit.org/show_bug.cgi?id=147871 5 6 Reviewed by Dan Bernstein. 7 8 NSURLProtocols have the ability to generate redirect responses. This change teaches CustomProtocolManager how to handle them. 9 10 * Shared/Network/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm: 11 (WebKit::CustomProtocolManager::wasRedirectedToRequest): Called -URLProtocol:wasRedirectedToRequest:redirectResponse: on the NSURLProtocolClient. 12 * Shared/Network/CustomProtocols/CustomProtocolManager.h: 13 * Shared/Network/CustomProtocols/CustomProtocolManager.messages.in: Defined WasRedirectedToRequest. 14 * Shared/Network/CustomProtocols/soup/CustomProtocolManagerSoup.cpp: 15 (WebKit::CustomProtocolManager::wasRedirectedToRequest): Defined empty function. 16 * UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm: 17 (-[WKCustomProtocolLoader connection:willSendRequest:redirectResponse:]): If a redirect response is received, send WasRedirectedToRequest and return nil to ignore the redirect. 18 1 19 2015-08-13 Andy Estes <aestes@apple.com> 2 20 -
trunk/Source/WebKit2/Shared/Network/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm
r188002 r188517 260 260 } 261 261 262 void CustomProtocolManager::wasRedirectedToRequest(uint64_t customProtocolID, const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& redirectResponse) 263 { 264 RetainPtr<WKCustomProtocol> protocol = protocolForID(customProtocolID); 265 if (!protocol) 266 return; 267 268 RetainPtr<NSURLRequest> nsRequest = request.nsURLRequest(WebCore::DoNotUpdateHTTPBody); 269 RetainPtr<NSURLResponse> nsRedirectResponse = redirectResponse.nsURLResponse(); 270 271 dispatchOnResourceLoaderRunLoop([protocol, nsRequest, nsRedirectResponse]() { 272 [[protocol client] URLProtocol:protocol.get() wasRedirectedToRequest:nsRequest.get() redirectResponse:nsRedirectResponse.get()]; 273 }); 274 } 275 262 276 RetainPtr<WKCustomProtocol> CustomProtocolManager::protocolForID(uint64_t customProtocolID) 263 277 { -
trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h
r188002 r188517 50 50 namespace WebCore { 51 51 class ResourceError; 52 class ResourceRequest; 52 53 class ResourceResponse; 53 54 } // namespace WebCore … … 95 96 void didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse&, uint32_t cacheStoragePolicy); 96 97 void didFinishLoading(uint64_t customProtocolID); 98 void wasRedirectedToRequest(uint64_t customProtocolID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse); 97 99 98 100 ChildProcess* m_childProcess; -
trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.messages.in
r174803 r188517 26 26 DidReceiveResponse(uint64_t customProtocolID, WebCore::ResourceResponse response, uint32_t cacheStoragePolicy) 27 27 DidFinishLoading(uint64_t customProtocolID) 28 WasRedirectedToRequest(uint64_t customProtocolID, WebCore::ResourceRequest request, WebCore::ResourceResponse redirectResponse); 28 29 29 30 RegisterScheme(String name) -
trunk/Source/WebKit2/Shared/Network/CustomProtocols/soup/CustomProtocolManagerSoup.cpp
r174803 r188517 107 107 } 108 108 109 void CustomProtocolManager::wasRedirectedToRequest(uint64_t, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&) 110 { 111 notImplemented(); 112 } 113 109 114 } // namespace WebKit -
trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm
r186464 r188517 111 111 - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse 112 112 { 113 if (redirectResponse) { 114 _connection->send(Messages::CustomProtocolManager::WasRedirectedToRequest(_customProtocolID, request, redirectResponse), 0); 115 return nil; 116 } 113 117 return request; 114 118 } -
trunk/Tools/ChangeLog
r188486 r188517 1 2015-08-11 Andy Estes <aestes@apple.com> 2 3 [Cocoa] Add redirect support to CustomProtocolManager 4 https://bugs.webkit.org/show_bug.cgi?id=147871 5 6 Reviewed by Dan Bernstein. 7 8 Updated WebKit2CustomProtocolsTest.MainResource to generate a redirect response. 9 10 * TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm: 11 (TestWebKitAPI::TEST): Unregesitered TestProtocol. 12 * TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html: Changed scheme to http. 13 * TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm: 14 (-[CustomProtocolsLoadDelegate browsingContextControllerDidStartProvisionalLoad:]): Expected a certain provisional URL. 15 (-[CustomProtocolsLoadDelegate browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:]): Ditto. 16 (-[CustomProtocolsLoadDelegate browsingContextControllerDidCommitLoad:]): Expected a certain committed URL. 17 (-[CustomProtocolsLoadDelegate browsingContextControllerDidFinishLoad:]): Expected isLoading to be false. 18 (TestWebKitAPI::TEST): Used the new load delegate and unregistered TestProtocol. 19 * TestWebKitAPI/Tests/WebKit2ObjC/PreventImageLoadWithAutoResizing.mm: 20 (TestWebKitAPI::TEST): Unregistered TestProtocol. 21 * TestWebKitAPI/mac/TestProtocol.mm: Changed scheme to http. 22 (+[TestProtocol canInitWithRequest:]): Changed to use property syntax. 23 (-[TestProtocol startLoading]): Taught to handle redirect responses. 24 1 25 2015-08-13 Andy Estes <aestes@apple.com> 2 26 -
trunk/Tools/TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm
r177506 r188517 70 70 71 71 TestWebKitAPI::Util::run(&testFinished); 72 [NSURLProtocol unregisterClass:[TestProtocol class]]; 73 [WKBrowsingContextController unregisterSchemeForCustomProtocol:[TestProtocol scheme]]; 72 74 } 73 75 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html
r149194 r188517 1 1 <script> 2 2 var request = new XMLHttpRequest(); 3 request.open('GET', ' test://test', false);3 request.open('GET', 'http://test', false); 4 4 request.send(null); 5 5 window._testResult = request.responseText; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm
r177506 r188517 40 40 static bool testFinished = false; 41 41 42 @interface CustomProtocolsLoadDelegate : NSObject <WKBrowsingContextLoadDelegate> 43 @end 44 45 @implementation CustomProtocolsLoadDelegate 46 47 - (void)browsingContextControllerDidStartProvisionalLoad:(WKBrowsingContextController *)sender 48 { 49 EXPECT_TRUE([sender.provisionalURL.absoluteString isEqualToString:@"http://redirect/?test"]); 50 } 51 52 - (void)browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:(WKBrowsingContextController *)sender 53 { 54 EXPECT_TRUE([sender.provisionalURL.absoluteString isEqualToString:@"http://test/"]); 55 } 56 57 - (void)browsingContextControllerDidCommitLoad:(WKBrowsingContextController *)sender 58 { 59 EXPECT_TRUE([sender.committedURL.absoluteString isEqualToString:@"http://test/"]); 60 } 61 62 - (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)sender 63 { 64 EXPECT_FALSE(sender.isLoading); 65 testFinished = true; 66 } 67 68 @end 69 42 70 namespace TestWebKitAPI { 43 71 … … 50 78 RetainPtr<WKBrowsingContextGroup> browsingContextGroup = adoptNS([[WKBrowsingContextGroup alloc] initWithIdentifier:@"TestIdentifier"]); 51 79 RetainPtr<WKView> wkView = adoptNS([[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup.get() browsingContextGroup:browsingContextGroup.get()]); 52 wkView.get().browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) { 53 testFinished = true; 54 }]; 55 [wkView.get().browsingContextController loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://test", [TestProtocol scheme]]]]]; 80 RetainPtr<CustomProtocolsLoadDelegate> loadDelegate = adoptNS([[CustomProtocolsLoadDelegate alloc] init]); 81 [wkView browsingContextController].loadDelegate = loadDelegate.get(); 82 [[wkView browsingContextController] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://redirect?test", [TestProtocol scheme]]]]]; 56 83 57 84 Util::run(&testFinished); 85 [NSURLProtocol unregisterClass:[TestProtocol class]]; 86 [WKBrowsingContextController unregisterSchemeForCustomProtocol:[TestProtocol scheme]]; 58 87 } 59 88 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/PreventImageLoadWithAutoResizing.mm
r177506 r188517 58 58 59 59 Util::run(&testFinished); 60 [NSURLProtocol unregisterClass:[TestProtocol class]]; 61 [WKBrowsingContextController unregisterSchemeForCustomProtocol:[TestProtocol scheme]]; 60 62 } 61 63 -
trunk/Tools/TestWebKitAPI/mac/TestProtocol.mm
r149194 r188517 27 27 #import "TestProtocol.h" 28 28 29 static NSString *testScheme = @"test"; 29 #import <wtf/RetainPtr.h> 30 31 // Even though NSURLProtocol is capable of generating redirect responses for any protocol, WebCore asserts if a redirect is not in the http family. 32 // See http://webkit.org/b/147870 for details. 33 static NSString *testScheme = @"http"; 30 34 31 35 @implementation TestProtocol … … 33 37 + (BOOL)canInitWithRequest:(NSURLRequest *)request 34 38 { 35 return [ [[request URL] scheme]caseInsensitiveCompare:testScheme] == NSOrderedSame;39 return [request.URL.scheme caseInsensitiveCompare:testScheme] == NSOrderedSame; 36 40 } 37 41 … … 53 57 - (void)startLoading 54 58 { 55 EXPECT_TRUE([[[[self request] URL] scheme] isEqualToString:testScheme]); 56 59 NSURL *requestURL = self.request.URL; 60 EXPECT_TRUE([requestURL.scheme isEqualToString:testScheme]); 61 57 62 NSData *data = [@"PASS" dataUsingEncoding:NSASCIIStringEncoding]; 58 NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"text/html" expectedContentLength:[data length] textEncodingName:nil]; 59 [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed]; 60 [[self client] URLProtocol:self didLoadData:data]; 61 [[self client] URLProtocolDidFinishLoading:self]; 62 [response release]; 63 RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:requestURL MIMEType:@"text/html" expectedContentLength:data.length textEncodingName:nil]); 64 65 if ([requestURL.host isEqualToString:@"redirect"]) { 66 NSURL *redirectURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, requestURL.query]]; 67 [self.client URLProtocol:self wasRedirectedToRequest:[NSURLRequest requestWithURL:redirectURL] redirectResponse:response.get()]; 68 return; 69 } 70 71 [self.client URLProtocol:self didReceiveResponse:response.get() cacheStoragePolicy:NSURLCacheStorageNotAllowed]; 72 [self.client URLProtocol:self didLoadData:data]; 73 [self.client URLProtocolDidFinishLoading:self]; 63 74 } 64 75
Note: See TracChangeset
for help on using the changeset viewer.