⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278318 in webkit


Ignore:
Timestamp:
Jun 1, 2021, 12:02:38 PM (5 years ago)
Author:
Chris Dumez
Message:

REGRESSION (iOS 14.5): Can't go back and render previous page properly after "location.href"
https://bugs.webkit.org/show_bug.cgi?id=226323
<rdar://problem/78623536>

Reviewed by Alex Christensen.

Source/WebKit:

A while back, we did an optimization to allow several WebPage objects associated with the
same WebPageProxy to live in the same WebProcess. This allowed us to reuse a process from
a SuspendedPageProxy for a forward navigation, without destroying the SuspendedPageProxy.
However, this added quite a bit of complexity and this broke some same-process back/forward
navigations like in this bug. In particular, it is really hard to get do our history
management right (with the current model) if there is more than more WebPage in a process
for the same WebPageProxy.

To address issues, we go back to the older model with one WebPage per WebProcess for a
given WebPageProxy. To achieve this, we make sure to destroy of SuspendedPageProxy objects
for the current page and destination process before we process-swap (like we used to do).

  • UIProcess/WebBackForwardCache.cpp:

(WebKit::WebBackForwardCache::removeEntriesForPageAndProcess):

  • UIProcess/WebBackForwardCache.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::receivedNavigationPolicyDecision):

Tools:

New API test written by Alex Christensen to cover this case.

  • TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r278317 r278318  
     12021-06-01  Chris Dumez  <cdumez@apple.com>
     2
     3        REGRESSION (iOS 14.5): Can't go back and render previous page properly after "location.href"
     4        https://bugs.webkit.org/show_bug.cgi?id=226323
     5        <rdar://problem/78623536>
     6
     7        Reviewed by Alex Christensen.
     8
     9        A while back, we did an optimization to allow several WebPage objects associated with the
     10        same WebPageProxy to live in the same WebProcess. This allowed us to reuse a process from
     11        a SuspendedPageProxy for a forward navigation, without destroying the SuspendedPageProxy.
     12        However, this added quite a bit of complexity and this broke some same-process back/forward
     13        navigations like in this bug. In particular, it is really hard to get do our history
     14        management right (with the current model) if there is more than more WebPage in a process
     15        for the same WebPageProxy.
     16
     17        To address issues, we go back to the older model with one WebPage per WebProcess for a
     18        given WebPageProxy. To achieve this, we make sure to destroy of SuspendedPageProxy objects
     19        for the current page and destination process before we process-swap (like we used to do).
     20
     21        * UIProcess/WebBackForwardCache.cpp:
     22        (WebKit::WebBackForwardCache::removeEntriesForPageAndProcess):
     23        * UIProcess/WebBackForwardCache.h:
     24        * UIProcess/WebPageProxy.cpp:
     25        (WebKit::WebPageProxy::receivedNavigationPolicyDecision):
     26
    1272021-06-01  Sihui Liu  <sihui_liu@apple.com>
    228
  • trunk/Source/WebKit/UIProcess/WebBackForwardCache.cpp

    r273183 r278318  
    146146}
    147147
     148void WebBackForwardCache::removeEntriesForPageAndProcess(WebPageProxy& page, WebProcessProxy& process)
     149{
     150    removeEntriesMatching([pageID = page.identifier(), processIdentifier = process.coreProcessIdentifier()](auto& item) {
     151        ASSERT(item.backForwardCacheEntry());
     152        return item.pageID() == pageID && item.backForwardCacheEntry()->processIdentifier() == processIdentifier;
     153    });
     154}
     155
    148156void WebBackForwardCache::removeEntriesMatching(const Function<bool(WebBackForwardListItem&)>& matches)
    149157{
  • trunk/Source/WebKit/UIProcess/WebBackForwardCache.h

    r251174 r278318  
    5454    void removeEntriesForProcess(WebProcessProxy&);
    5555    void removeEntriesForPage(WebPageProxy&);
     56    void removeEntriesForPageAndProcess(WebPageProxy&, WebProcessProxy&);
    5657    void removeEntriesForSession(PAL::SessionID);
    5758
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r278315 r278318  
    34253425            ASSERT(!destinationSuspendedPage || navigation->targetItem());
    34263426            auto suspendedPage = destinationSuspendedPage ? backForwardCache().takeSuspendedPage(*navigation->targetItem()) : nullptr;
     3427
     3428            // It is difficult to get history right if we have several WebPage objects inside a single WebProcess for the same WebPageProxy. As a result, if we make sure to
     3429            // clear any SuspendedPageProxy for the current page that are backed by the destination process before we proceed with the navigation. This makes sure the WebPage
     3430            // we are about to create in the destination process will be the only one associated with this WebPageProxy.
     3431            if (!destinationSuspendedPage)
     3432                backForwardCache().removeEntriesForPageAndProcess(*this, processForNavigation);
     3433
    34273434            ASSERT(suspendedPage.get() == destinationSuspendedPage);
    34283435            if (suspendedPage && suspendedPage->pageIsClosedOrClosing())
  • trunk/Tools/ChangeLog

    r278310 r278318  
     12021-06-01  Chris Dumez  <cdumez@apple.com>
     2
     3        REGRESSION (iOS 14.5): Can't go back and render previous page properly after "location.href"
     4        https://bugs.webkit.org/show_bug.cgi?id=226323
     5        <rdar://problem/78623536>
     6
     7        Reviewed by Alex Christensen.
     8
     9        New API test written by Alex Christensen to cover this case.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
     12
    1132021-06-01  Aakash Jain  <aakash_jain@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

    r273891 r278318  
    33523352}
    33533353
     3354TEST(ProcessSwap, NavigateBackAfterCrossOriginClientRedirect)
     3355{
     3356    auto processPoolConfiguration = psonProcessPoolConfiguration();
     3357    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
     3358
     3359    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
     3360    [webViewConfiguration setProcessPool:processPool.get()];
     3361    auto handler = adoptNS([[PSONScheme alloc] init]);
     3362    [handler addMappingFromURLString:@"pson://webkit.org/navigated_from" toData:"<a href='pson://apple.com/'>hello</a>"];
     3363    [handler addMappingFromURLString:@"pson://apple.com/" toData:"<script>window.location.href='pson://webkit.org/redirected_to'</script>redirecting..."];
     3364    [handler addMappingFromURLString:@"pson://webkit.org/redirected_to" toData:"<p>hello again</p>"];
     3365    [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
     3366
     3367    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
     3368
     3369    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://webkit.org/navigated_from"]]];
     3370    [webView _test_waitForDidFinishNavigation];
     3371
     3372    [webView evaluateJavaScript:@"document.querySelector('a').click()" completionHandler:nil];
     3373    [webView _test_waitForDidFinishNavigation];
     3374    [webView _test_waitForDidFinishNavigation];
     3375    EXPECT_WK_STREQ([webView objectByEvaluatingJavaScript:@"window.location.href"], "pson://webkit.org/redirected_to");
     3376    [webView goBack];
     3377    [webView _test_waitForDidFinishNavigation];
     3378    EXPECT_WK_STREQ([webView objectByEvaluatingJavaScript:@"window.location.href"], "pson://webkit.org/navigated_from");
     3379}
     3380
    33543381TEST(ProcessSwap, BackForwardCacheSkipBackForwardListItem)
    33553382{
Note: See TracChangeset for help on using the changeset viewer.