Bug 147871 - [Cocoa] Add redirect support to CustomProtocolManager
Summary: [Cocoa] Add redirect support to CustomProtocolManager
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andy Estes
URL:
Keywords:
Depends on:
Blocks: 147872
  Show dependency treegraph
 
Reported: 2015-08-11 00:00 PDT by Andy Estes
Modified: 2015-08-15 20:29 PDT (History)
5 users (show)

See Also:


Attachments
Patch (15.32 KB, patch)
2015-08-11 00:23 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (16.32 KB, patch)
2015-08-11 13:52 PDT, Andy Estes
no flags Details | Formatted Diff | Diff
Patch (16.19 KB, patch)
2015-08-11 13:55 PDT, Andy Estes
mitz: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Estes 2015-08-11 00:00:52 PDT
[Cocoa] Add redirect support to CustomProtocolManager
Comment 1 Andy Estes 2015-08-11 00:19:47 PDT
This is needed to write a test for https://bugs.webkit.org/show_bug.cgi?id=147872
Comment 2 Andy Estes 2015-08-11 00:23:07 PDT
Created attachment 258709 [details]
Patch
Comment 3 Andy Estes 2015-08-11 13:52:06 PDT
Created attachment 258750 [details]
Patch
Comment 4 Andy Estes 2015-08-11 13:55:57 PDT
Created attachment 258751 [details]
Patch
Comment 5 mitz 2015-08-15 10:19:14 PDT
Comment on attachment 258751 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=258751&action=review

> Source/WebKit2/Shared/Network/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm:54
> +using namespace WebCore;

I think recently in WebKit2 we have taken to avoiding using namespace WebCore. It sure looks like existing functions in this file already use WebCore::-qualified types.

> Source/WebKit2/Shared/Network/CustomProtocols/soup/CustomProtocolManagerSoup.cpp:110
> +{

Do we need a notImplemented() here?
Comment 6 Alexey Proskuryakov 2015-08-15 12:56:49 PDT
Comment on attachment 258751 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=258751&action=review

> Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm:116
> +    if (redirectResponse) {
> +        _connection->send(Messages::CustomProtocolManager::WasRedirectedToRequest(_customProtocolID, request, redirectResponse), 0);
> +        return nil;
> +    }

For normal loading, -connection:willSendRequest:redirectResponse: needs to return "request" if the delegate agrees to take the redirect, nil if the request is canceled, and some other request if the delegate decides to modify it.

Is it a bug to return nil here, or do custom protocols work differently? If it's a bug, please add a test case that would have caught it.
Comment 7 Andy Estes 2015-08-15 19:32:59 PDT
(In reply to comment #5)
> Comment on attachment 258751 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=258751&action=review
> 
> > Source/WebKit2/Shared/Network/CustomProtocols/Cocoa/CustomProtocolManagerCocoa.mm:54
> > +using namespace WebCore;
> 
> I think recently in WebKit2 we have taken to avoiding using namespace
> WebCore. It sure looks like existing functions in this file already use
> WebCore::-qualified types.

Oh, ok. I was actually going to remove all the WebCore::s in another patch, so that's good to know!

> 
> > Source/WebKit2/Shared/Network/CustomProtocols/soup/CustomProtocolManagerSoup.cpp:110
> > +{
> 
> Do we need a notImplemented() here?

I can add it.

Thanks for the review!
Comment 8 Andy Estes 2015-08-15 19:49:09 PDT
(In reply to comment #6)
> Comment on attachment 258751 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=258751&action=review
> 
> > Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm:116
> > +    if (redirectResponse) {
> > +        _connection->send(Messages::CustomProtocolManager::WasRedirectedToRequest(_customProtocolID, request, redirectResponse), 0);
> > +        return nil;
> > +    }
> 
> For normal loading, -connection:willSendRequest:redirectResponse: needs to
> return "request" if the delegate agrees to take the redirect, nil if the
> request is canceled, and some other request if the delegate decides to
> modify it.
> 
> Is it a bug to return nil here, or do custom protocols work differently? If
> it's a bug, please add a test case that would have caught it.

Custom protocols do work differently in this case. If I were to return the request here, then the connection would tell the embedder's NSURLProtocol to start loading the redirect request.

Then, when the Networking process receives WasRedirectedToRequest, it starts a redirect for the underlying connection, which triggers our normal willSendRequest() logic. If this results in a new request, then the Networking process's NSURLProtocol receives -startLoading, which starts a new connection in the UI process.

So returning nil here prevents duplicate loads from starting in the embedder's NSURLProtocol, and ensures that the request that is started is the one that WebKit has had a chance to modify.
Comment 9 Andy Estes 2015-08-15 20:29:25 PDT
Committed r188517: <http://trac.webkit.org/changeset/188517>