Bug 184142

Summary: Process swapping on navigation needs to handle server redirects
Product: WebKit Reporter: Brady Eidson <beidson>
Component: WebKit Misc.Assignee: Brady Eidson <beidson>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, aestes, cdumez, commit-queue, rniwa, ryanhaddad, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=186441
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Brady Eidson 2018-03-29 11:56:32 PDT
Process swapping on navigation needs to handle server redirects

<rdar://problem/38690465>
Comment 1 Brady Eidson 2018-03-30 22:18:08 PDT Comment hidden (obsolete)
Comment 2 Brady Eidson 2018-03-31 11:40:18 PDT
Created attachment 336927 [details]
Patch
Comment 3 Alex Christensen 2018-04-02 10:16:23 PDT
Comment on attachment 336927 [details]
Patch

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

> Source/WebKit/ChangeLog:14
> +        3 - A WKWebView is showing content from a.com, we start a load to a.com, that that redirects to b.com.

Will future work will make it so a redirect from a to b then back to a will reuse the same process?

> Source/WebKit/UIProcess/WebPageProxy.cpp:2397
> +        m_mainFrameSetHandler = [this, protectedThis = makeRef(*this), navigation = makeRef(navigation), request = ResourceRequest { navigation.currentRequest() }]() mutable {

I think the explicit call to the constructor might be unnecessary.

> Source/WebKit/UIProcess/WebPageProxy.cpp:3212
> +    if (m_mainFrameSetHandler) {

m_mainFrameCreationHandler?

> Source/WebKit/UIProcess/WebPageProxy.cpp:3855
> +    Ref<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID, PolicyListenerType::NavigationAction);

auto?

> Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:162
> +        [(id<WKURLSchemeTaskPrivate>)task _didPerformRedirection:redirectResponse.get() newRequest:request.get()];

Wow, this SPI seems really useful!  I'm glad we have it.

> Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:568
> +    RetainPtr<PSONScheme> handler1 = adoptNS([[PSONScheme alloc] init]);

You have inconsistent use of auto in your tests.
Comment 4 youenn fablet 2018-04-02 10:30:12 PDT
> > Source/WebKit/ChangeLog:14
> > +        3 - A WKWebView is showing content from a.com, we start a load to a.com, that that redirects to b.com.
> 
> Will future work will make it so a redirect from a to b then back to a will
> reuse the same process?

Ideally, future work will enable us to do full loading in NetworkProcess without going through WebProcess, including navigations. That would handle this point automatically, although we might want to get to it before having the full loading stuff.
Comment 5 Brady Eidson 2018-04-02 10:32:32 PDT
(In reply to Alex Christensen from comment #3)
> Comment on attachment 336927 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=336927&action=review
> 
> > Source/WebKit/ChangeLog:14
> > +        3 - A WKWebView is showing content from a.com, we start a load to a.com, that that redirects to b.com.
> 
> Will future work will make it so a redirect from a to b then back to a will
> reuse the same process?

Maybe. 
Not necessarily worth it though - At the a.com to b.com redirect we have to fire up a second process, but then reverting back to the a.com process is more work...
CPU/Battery tradeoff...
I'll file a bug tracking the idea, definitely not convinced it's a slam dunk.

> > Source/WebKit/UIProcess/WebPageProxy.cpp:2397
> > +        m_mainFrameSetHandler = [this, protectedThis = makeRef(*this), navigation = makeRef(navigation), request = ResourceRequest { navigation.currentRequest() }]() mutable {
> 
> I think the explicit call to the constructor might be unnecessary.

Yah it was in some places, maybe not here, will 2x check.

> 
> > Source/WebKit/UIProcess/WebPageProxy.cpp:3212
> > +    if (m_mainFrameSetHandler) {
> 
> m_mainFrameCreationHandler?
> 

Sure.


> > Source/WebKit/UIProcess/WebPageProxy.cpp:3855
> > +    Ref<WebFramePolicyListenerProxy> listener = frame->setUpPolicyListenerProxy(listenerID, PolicyListenerType::NavigationAction);
> 
> auto?

Sure.

> 
> > Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:162
> > +        [(id<WKURLSchemeTaskPrivate>)task _didPerformRedirection:redirectResponse.get() newRequest:request.get()];
> 
> Wow, this SPI seems really useful!  I'm glad we have it.

Nice! I'll CC you on the bugs I file for how it does weird things... :)

> > Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:568
> > +    RetainPtr<PSONScheme> handler1 = adoptNS([[PSONScheme alloc] init]);
> 
> You have inconsistent use of auto in your tests.

Tests tests shmests
Comment 6 Brady Eidson 2018-04-02 10:32:46 PDT
(In reply to youenn fablet from comment #4)
> > > Source/WebKit/ChangeLog:14
> > > +        3 - A WKWebView is showing content from a.com, we start a load to a.com, that that redirects to b.com.
> > 
> > Will future work will make it so a redirect from a to b then back to a will
> > reuse the same process?
> 
> Ideally, future work will enable us to do full loading in NetworkProcess
> without going through WebProcess, including navigations. That would handle
> this point automatically, although we might want to get to it before having
> the full loading stuff.

^^^^ 👍
Comment 7 Brady Eidson 2018-04-02 10:35:41 PDT
Created attachment 336997 [details]
Patch
Comment 8 Brady Eidson 2018-04-02 11:05:10 PDT
Created attachment 337002 [details]
Patch
Comment 9 WebKit Commit Bot 2018-04-02 13:05:53 PDT
Comment on attachment 337002 [details]
Patch

Clearing flags on attachment: 337002

Committed r230174: <https://trac.webkit.org/changeset/230174>
Comment 10 WebKit Commit Bot 2018-04-02 13:05:54 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Ryan Haddad 2018-04-02 15:14:45 PDT
iOS and macOS Debug WK2 tests are exiting early due to crashes after this change.

ASSERTION FAILED: navigation->originalRequest().url() == originalRequest.url()
/Volumes/Data/slave/highsierra-debug/build/Source/WebKit/UIProcess/WebPageProxy.cpp(3845) : void WebKit::WebPageProxy::decidePolicyForNavigationAction(uint64_t, const WebCore::SecurityOriginData &, uint64_t, WebKit::NavigationActionData &&, const WebKit::FrameInfoData &, uint64_t, const WebCore::ResourceRequest &, WebCore::ResourceRequest &&, uint64_t, const WebKit::UserData &)

See:https://build.webkit.org/results/Apple%20High%20Sierra%20Debug%20WK2%20(Tests)/r230176%20(2692)/results.html
Comment 12 Ryan Haddad 2018-04-02 16:09:23 PDT
Reverted r230174 for reason:

Caused LayoutTests to exit early with assertion failures.

Committed r230191: <https://trac.webkit.org/changeset/230191>
Comment 13 Brady Eidson 2018-04-02 16:38:30 PDT
(In reply to Ryan Haddad from comment #11)
> iOS and macOS Debug WK2 tests are exiting early due to crashes after this
> change.

Annnnnnnnnnnd we don't have EWS for either of them.

Still.

To this day.
Comment 14 Brady Eidson 2018-04-02 17:24:45 PDT
Created attachment 337046 [details]
Patch
Comment 15 WebKit Commit Bot 2018-04-02 18:03:51 PDT
Comment on attachment 337046 [details]
Patch

Clearing flags on attachment: 337046

Committed r230195: <https://trac.webkit.org/changeset/230195>
Comment 16 WebKit Commit Bot 2018-04-02 18:03:53 PDT
All reviewed patches have been landed.  Closing bug.