Diff
Modified: trunk/Source/WebKit2/ChangeLog (188516 => 188517)
--- trunk/Source/WebKit2/ChangeLog 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Source/WebKit2/ChangeLog 2015-08-16 03:29:01 UTC (rev 188517)
@@ -1,3 +1,21 @@
+2015-08-11 Andy Estes <[email protected]>
+
+ [Cocoa] Add redirect support to CustomProtocolManager
+ https://bugs.webkit.org/show_bug.cgi?id=147871
+
+ Reviewed by Dan Bernstein.
+
+ NSURLProtocols have the ability to generate redirect responses. This change teaches CustomProtocolManager how to handle them.
+
+ * Shared/Network/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm:
+ (WebKit::CustomProtocolManager::wasRedirectedToRequest): Called -URLProtocol:wasRedirectedToRequest:redirectResponse: on the NSURLProtocolClient.
+ * Shared/Network/CustomProtocols/CustomProtocolManager.h:
+ * Shared/Network/CustomProtocols/CustomProtocolManager.messages.in: Defined WasRedirectedToRequest.
+ * Shared/Network/CustomProtocols/soup/CustomProtocolManagerSoup.cpp:
+ (WebKit::CustomProtocolManager::wasRedirectedToRequest): Defined empty function.
+ * UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm:
+ (-[WKCustomProtocolLoader connection:willSendRequest:redirectResponse:]): If a redirect response is received, send WasRedirectedToRequest and return nil to ignore the redirect.
+
2015-08-13 Andy Estes <[email protected]>
[Cocoa] Downloads do not start if policy decision is made asynchronously
Modified: trunk/Source/WebKit2/Shared/Network/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm (188516 => 188517)
--- trunk/Source/WebKit2/Shared/Network/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Source/WebKit2/Shared/Network/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm 2015-08-16 03:29:01 UTC (rev 188517)
@@ -259,6 +259,20 @@
removeCustomProtocol(protocol.get());
}
+void CustomProtocolManager::wasRedirectedToRequest(uint64_t customProtocolID, const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& redirectResponse)
+{
+ RetainPtr<WKCustomProtocol> protocol = protocolForID(customProtocolID);
+ if (!protocol)
+ return;
+
+ RetainPtr<NSURLRequest> nsRequest = request.nsURLRequest(WebCore::DoNotUpdateHTTPBody);
+ RetainPtr<NSURLResponse> nsRedirectResponse = redirectResponse.nsURLResponse();
+
+ dispatchOnResourceLoaderRunLoop([protocol, nsRequest, nsRedirectResponse]() {
+ [[protocol client] URLProtocol:protocol.get() wasRedirectedToRequest:nsRequest.get() redirectResponse:nsRedirectResponse.get()];
+ });
+}
+
RetainPtr<WKCustomProtocol> CustomProtocolManager::protocolForID(uint64_t customProtocolID)
{
MutexLocker locker(m_customProtocolMapMutex);
Modified: trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h (188516 => 188517)
--- trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.h 2015-08-16 03:29:01 UTC (rev 188517)
@@ -49,6 +49,7 @@
namespace WebCore {
class ResourceError;
+class ResourceRequest;
class ResourceResponse;
} // namespace WebCore
@@ -94,6 +95,7 @@
void didLoadData(uint64_t customProtocolID, const IPC::DataReference&);
void didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse&, uint32_t cacheStoragePolicy);
void didFinishLoading(uint64_t customProtocolID);
+ void wasRedirectedToRequest(uint64_t customProtocolID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
ChildProcess* m_childProcess;
RefPtr<WorkQueue> m_messageQueue;
Modified: trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.messages.in (188516 => 188517)
--- trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.messages.in 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Source/WebKit2/Shared/Network/CustomProtocols/CustomProtocolManager.messages.in 2015-08-16 03:29:01 UTC (rev 188517)
@@ -25,6 +25,7 @@
DidLoadData(uint64_t customProtocolID, IPC::DataReference data)
DidReceiveResponse(uint64_t customProtocolID, WebCore::ResourceResponse response, uint32_t cacheStoragePolicy)
DidFinishLoading(uint64_t customProtocolID)
+ WasRedirectedToRequest(uint64_t customProtocolID, WebCore::ResourceRequest request, WebCore::ResourceResponse redirectResponse);
RegisterScheme(String name)
UnregisterScheme(String name)
Modified: trunk/Source/WebKit2/Shared/Network/CustomProtocols/soup/CustomProtocolManagerSoup.cpp (188516 => 188517)
--- trunk/Source/WebKit2/Shared/Network/CustomProtocols/soup/CustomProtocolManagerSoup.cpp 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Source/WebKit2/Shared/Network/CustomProtocols/soup/CustomProtocolManagerSoup.cpp 2015-08-16 03:29:01 UTC (rev 188517)
@@ -106,4 +106,9 @@
m_impl->didFinishLoading(customProtocolID);
}
+void CustomProtocolManager::wasRedirectedToRequest(uint64_t, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&)
+{
+ notImplemented();
+}
+
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm (188516 => 188517)
--- trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm 2015-08-16 03:29:01 UTC (rev 188517)
@@ -110,6 +110,10 @@
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
+ if (redirectResponse) {
+ _connection->send(Messages::CustomProtocolManager::WasRedirectedToRequest(_customProtocolID, request, redirectResponse), 0);
+ return nil;
+ }
return request;
}
Modified: trunk/Tools/ChangeLog (188516 => 188517)
--- trunk/Tools/ChangeLog 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Tools/ChangeLog 2015-08-16 03:29:01 UTC (rev 188517)
@@ -1,3 +1,27 @@
+2015-08-11 Andy Estes <[email protected]>
+
+ [Cocoa] Add redirect support to CustomProtocolManager
+ https://bugs.webkit.org/show_bug.cgi?id=147871
+
+ Reviewed by Dan Bernstein.
+
+ Updated WebKit2CustomProtocolsTest.MainResource to generate a redirect response.
+
+ * TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm:
+ (TestWebKitAPI::TEST): Unregesitered TestProtocol.
+ * TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html: Changed scheme to http.
+ * TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm:
+ (-[CustomProtocolsLoadDelegate browsingContextControllerDidStartProvisionalLoad:]): Expected a certain provisional URL.
+ (-[CustomProtocolsLoadDelegate browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:]): Ditto.
+ (-[CustomProtocolsLoadDelegate browsingContextControllerDidCommitLoad:]): Expected a certain committed URL.
+ (-[CustomProtocolsLoadDelegate browsingContextControllerDidFinishLoad:]): Expected isLoading to be false.
+ (TestWebKitAPI::TEST): Used the new load delegate and unregistered TestProtocol.
+ * TestWebKitAPI/Tests/WebKit2ObjC/PreventImageLoadWithAutoResizing.mm:
+ (TestWebKitAPI::TEST): Unregistered TestProtocol.
+ * TestWebKitAPI/mac/TestProtocol.mm: Changed scheme to http.
+ (+[TestProtocol canInitWithRequest:]): Changed to use property syntax.
+ (-[TestProtocol startLoading]): Taught to handle redirect responses.
+
2015-08-13 Andy Estes <[email protected]>
[Cocoa] Downloads do not start if policy decision is made asynchronously
Modified: trunk/Tools/TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm (188516 => 188517)
--- trunk/Tools/TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Tools/TestWebKitAPI/Tests/CustomProtocolsSyncXHRTest.mm 2015-08-16 03:29:01 UTC (rev 188517)
@@ -69,6 +69,8 @@
WKPageLoadURL(wkView.get().pageRef, Util::createURLForResource("custom-protocol-sync-xhr", "html"));
TestWebKitAPI::Util::run(&testFinished);
+ [NSURLProtocol unregisterClass:[TestProtocol class]];
+ [WKBrowsingContextController unregisterSchemeForCustomProtocol:[TestProtocol scheme]];
}
} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html (188516 => 188517)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/custom-protocol-sync-xhr.html 2015-08-16 03:29:01 UTC (rev 188517)
@@ -1,6 +1,6 @@
<script>
var request = new XMLHttpRequest();
- request.open('GET', 'test://test', false);
+ request.open('GET', 'http://test', false);
request.send(null);
window._testResult = request.responseText;
</script>
\ No newline at end of file
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm (188516 => 188517)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm 2015-08-16 03:29:01 UTC (rev 188517)
@@ -39,6 +39,34 @@
static bool testFinished = false;
+@interface CustomProtocolsLoadDelegate : NSObject <WKBrowsingContextLoadDelegate>
+@end
+
+@implementation CustomProtocolsLoadDelegate
+
+- (void)browsingContextControllerDidStartProvisionalLoad:(WKBrowsingContextController *)sender
+{
+ EXPECT_TRUE([sender.provisionalURL.absoluteString isEqualToString:@"http://redirect/?test"]);
+}
+
+- (void)browsingContextControllerDidReceiveServerRedirectForProvisionalLoad:(WKBrowsingContextController *)sender
+{
+ EXPECT_TRUE([sender.provisionalURL.absoluteString isEqualToString:@"http://test/"]);
+}
+
+- (void)browsingContextControllerDidCommitLoad:(WKBrowsingContextController *)sender
+{
+ EXPECT_TRUE([sender.committedURL.absoluteString isEqualToString:@"http://test/"]);
+}
+
+- (void)browsingContextControllerDidFinishLoad:(WKBrowsingContextController *)sender
+{
+ EXPECT_FALSE(sender.isLoading);
+ testFinished = true;
+}
+
+@end
+
namespace TestWebKitAPI {
TEST(WebKit2CustomProtocolsTest, MainResource)
@@ -49,12 +77,13 @@
RetainPtr<WKProcessGroup> processGroup = adoptNS([[WKProcessGroup alloc] init]);
RetainPtr<WKBrowsingContextGroup> browsingContextGroup = adoptNS([[WKBrowsingContextGroup alloc] initWithIdentifier:@"TestIdentifier"]);
RetainPtr<WKView> wkView = adoptNS([[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup.get() browsingContextGroup:browsingContextGroup.get()]);
- wkView.get().browsingContextController.loadDelegate = [[TestBrowsingContextLoadDelegate alloc] initWithBlockToRunOnLoad:^(WKBrowsingContextController *sender) {
- testFinished = true;
- }];
- [wkView.get().browsingContextController loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://test", [TestProtocol scheme]]]]];
+ RetainPtr<CustomProtocolsLoadDelegate> loadDelegate = adoptNS([[CustomProtocolsLoadDelegate alloc] init]);
+ [wkView browsingContextController].loadDelegate = loadDelegate.get();
+ [[wkView browsingContextController] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://redirect?test", [TestProtocol scheme]]]]];
Util::run(&testFinished);
+ [NSURLProtocol unregisterClass:[TestProtocol class]];
+ [WKBrowsingContextController unregisterSchemeForCustomProtocol:[TestProtocol scheme]];
}
} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/PreventImageLoadWithAutoResizing.mm (188516 => 188517)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/PreventImageLoadWithAutoResizing.mm 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/PreventImageLoadWithAutoResizing.mm 2015-08-16 03:29:01 UTC (rev 188517)
@@ -57,6 +57,8 @@
[webView.platformView().browsingContextController loadHTMLString:@"<html><body style='background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAFZJREFUeF59z4EJADEIQ1F36k7u5E7ZKXeUQPACJ3wK7UNokVxVk9kHnQH7bY9hbDyDhNXgjpRLqFlo4M2GgfyJHhjq8V4agfrgPQX3JtJQGbofmCHgA/nAKks+JAjFAAAAAElFTkSuQmCC);'></body></html>" baseURL:[NSURL URLWithString:@"about:blank"]];
Util::run(&testFinished);
+ [NSURLProtocol unregisterClass:[TestProtocol class]];
+ [WKBrowsingContextController unregisterSchemeForCustomProtocol:[TestProtocol scheme]];
}
} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/mac/TestProtocol.mm (188516 => 188517)
--- trunk/Tools/TestWebKitAPI/mac/TestProtocol.mm 2015-08-15 20:48:25 UTC (rev 188516)
+++ trunk/Tools/TestWebKitAPI/mac/TestProtocol.mm 2015-08-16 03:29:01 UTC (rev 188517)
@@ -26,13 +26,17 @@
#import "config.h"
#import "TestProtocol.h"
-static NSString *testScheme = @"test";
+#import <wtf/RetainPtr.h>
+// Even though NSURLProtocol is capable of generating redirect responses for any protocol, WebCore asserts if a redirect is not in the http family.
+// See http://webkit.org/b/147870 for details.
+static NSString *testScheme = @"http";
+
@implementation TestProtocol
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
- return [[[request URL] scheme] caseInsensitiveCompare:testScheme] == NSOrderedSame;
+ return [request.URL.scheme caseInsensitiveCompare:testScheme] == NSOrderedSame;
}
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
@@ -52,14 +56,21 @@
- (void)startLoading
{
- EXPECT_TRUE([[[[self request] URL] scheme] isEqualToString:testScheme]);
-
+ NSURL *requestURL = self.request.URL;
+ EXPECT_TRUE([requestURL.scheme isEqualToString:testScheme]);
+
NSData *data = "" dataUsingEncoding:NSASCIIStringEncoding];
- NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] MIMEType:@"text/html" expectedContentLength:[data length] textEncodingName:nil];
- [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
- [[self client] URLProtocol:self didLoadData:data];
- [[self client] URLProtocolDidFinishLoading:self];
- [response release];
+ RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:requestURL MIMEType:@"text/html" expectedContentLength:data.length textEncodingName:nil]);
+
+ if ([requestURL.host isEqualToString:@"redirect"]) {
+ NSURL *redirectURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", testScheme, requestURL.query]];
+ [self.client URLProtocol:self wasRedirectedToRequest:[NSURLRequest requestWithURL:redirectURL] redirectResponse:response.get()];
+ return;
+ }
+
+ [self.client URLProtocol:self didReceiveResponse:response.get() cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+ [self.client URLProtocol:self didLoadData:data];
+ [self.client URLProtocolDidFinishLoading:self];
}
- (void)stopLoading