Changeset 225645 in webkit


Ignore:
Timestamp:
Dec 7, 2017 1:59:48 PM (6 years ago)
Author:
achristensen@apple.com
Message:

Always synchronously continue with fragment navigations
https://bugs.webkit.org/show_bug.cgi?id=180544
<rdar://problem/34815986> and <rdar://problem/35126690>

Reviewed by Geoffrey Garen.

Source/WebCore:

Test: http/tests/dom/document-fragment.html

When a decidePolicyForNavigationAction completionHandler is called asynchronously,
the document's URL has not changed yet when JavaScript execution continues. This causes
significant web incompatibility because all browsers change the document's URL immediately
during fragment navigations. In order to make WebKit applications more web compatible,
we now immediately continue to have the state consistent. To keep compatibility with any
WebView, UIWebView, or WKWebView applications that use these delegate callbacks to update
state, we still call decidePolicyForNavigationAction. This would break a theoretical app
that would cancel fragment navigations, but it fixes apps that continue fragment navigations
asynchronously.

  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::loadURL):
(WebCore::FrameLoader::loadWithDocumentLoader):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/DecidePolicyForNavigationAction.mm:

(-[DecidePolicyForNavigationActionFragmentDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
(TEST):
Add a test that verifies that decidePolicyForNavigationAction is called for fragment navigations.

LayoutTests:

  • http/tests/dom/document-fragment-expected.txt: Added.
  • http/tests/dom/document-fragment.html: Added.

Add a test that verifies that the fragment of the document is set immediately during a fragment navigation,
even if decidePolicyForNavigationAction is called asynchronously. Also verify the order of various events
associated with the navigation.

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r225644 r225645  
     12017-12-07  Alex Christensen  <achristensen@webkit.org>
     2
     3        Always synchronously continue with fragment navigations
     4        https://bugs.webkit.org/show_bug.cgi?id=180544
     5        <rdar://problem/34815986> and <rdar://problem/35126690>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        * http/tests/dom/document-fragment-expected.txt: Added.
     10        * http/tests/dom/document-fragment.html: Added.
     11        Add a test that verifies that the fragment of the document is set immediately during a fragment navigation,
     12        even if decidePolicyForNavigationAction is called asynchronously.  Also verify the order of various events
     13        associated with the navigation.
     14
    1152017-12-07  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r225644 r225645  
     12017-12-07  Alex Christensen  <achristensen@webkit.org>
     2
     3        Always synchronously continue with fragment navigations
     4        https://bugs.webkit.org/show_bug.cgi?id=180544
     5        <rdar://problem/34815986> and <rdar://problem/35126690>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Test: http/tests/dom/document-fragment.html
     10
     11        When a decidePolicyForNavigationAction completionHandler is called asynchronously,
     12        the document's URL has not changed yet when JavaScript execution continues.  This causes
     13        significant web incompatibility because all browsers change the document's URL immediately
     14        during fragment navigations.  In order to make WebKit applications more web compatible,
     15        we now immediately continue to have the state consistent.  To keep compatibility with any
     16        WebView, UIWebView, or WKWebView applications that use these delegate callbacks to update
     17        state, we still call decidePolicyForNavigationAction.  This would break a theoretical app
     18        that would cancel fragment navigations, but it fixes apps that continue fragment navigations
     19        asynchronously.
     20
     21        * loader/FrameLoader.cpp:
     22        (WebCore::FrameLoader::loadURL):
     23        (WebCore::FrameLoader::loadWithDocumentLoader):
     24
    1252017-12-07  Youenn Fablet  <youenn@apple.com>
    226
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r225449 r225645  
    13161316        policyChecker().stopCheck();
    13171317        policyChecker().setLoadType(newLoadType);
    1318         policyChecker().checkNavigationPolicy(WTFMove(request), false /* didReceiveRedirectResponse */, oldDocumentLoader.get(), formState, [this] (const ResourceRequest& request, FormState*, bool shouldContinue) {
    1319             continueFragmentScrollAfterNavigationPolicy(request, shouldContinue);
    1320         });
     1318        continueFragmentScrollAfterNavigationPolicy(request, true);
     1319        policyChecker().checkNavigationPolicy(WTFMove(request), false /* didReceiveRedirectResponse */, oldDocumentLoader.get(), formState, [] (const ResourceRequest&, FormState*, bool) { });
    13211320        return;
    13221321    }
     
    14761475        oldDocumentLoader->setLastCheckedRequest(ResourceRequest());
    14771476        policyChecker().stopCheck();
    1478         policyChecker().checkNavigationPolicy(ResourceRequest(loader->request()), false /* didReceiveRedirectResponse */, oldDocumentLoader.get(), formState, [this] (const ResourceRequest& request, FormState*, bool shouldContinue) {
    1479             continueFragmentScrollAfterNavigationPolicy(request, shouldContinue);
    1480         });
     1477        continueFragmentScrollAfterNavigationPolicy(loader->request(), true);
     1478        policyChecker().checkNavigationPolicy(ResourceRequest(loader->request()), false /* didReceiveRedirectResponse */, oldDocumentLoader.get(), formState, [] (const ResourceRequest&, FormState*, bool) { });
    14811479        return;
    14821480    }
  • trunk/Tools/ChangeLog

    r225641 r225645  
     12017-12-07  Alex Christensen  <achristensen@webkit.org>
     2
     3        Always synchronously continue with fragment navigations
     4        https://bugs.webkit.org/show_bug.cgi?id=180544
     5        <rdar://problem/34815986> and <rdar://problem/35126690>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/DecidePolicyForNavigationAction.mm:
     10        (-[DecidePolicyForNavigationActionFragmentDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
     11        (TEST):
     12        Add a test that verifies that decidePolicyForNavigationAction is called for fragment navigations.
     13
    1142017-12-07  Myles C. Maxfield  <mmaxfield@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DecidePolicyForNavigationAction.mm

    r221505 r225645  
    527527}
    528528
     529static size_t calls;
     530static bool done;
     531
     532@interface DecidePolicyForNavigationActionFragmentDelegate : NSObject <WKNavigationDelegate>
     533@end
     534
     535@implementation DecidePolicyForNavigationActionFragmentDelegate
     536
     537- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
     538{
     539    decisionHandler(WKNavigationActionPolicyAllow);
     540    const char* url = navigationAction.request.URL.absoluteString.UTF8String;
     541    switch (calls++) {
     542    case 0:
     543        EXPECT_STREQ(url, "http://webkit.org/");
     544        return;
     545    case 1:
     546        EXPECT_STREQ(url, "http://webkit.org/#fragment");
     547        done = true;
     548        return;
     549    }
     550    ASSERT_NOT_REACHED();
     551}
     552
     553@end
     554
     555TEST(WebKit, DecidePolicyForNavigationActionFragment)
     556{
     557    auto webView = adoptNS([[WKWebView alloc] init]);
     558    auto delegate = adoptNS([[DecidePolicyForNavigationActionFragmentDelegate alloc] init]);
     559    [webView setNavigationDelegate:delegate.get()];
     560    [webView loadHTMLString:@"<script>window.location.href='#fragment';</script>" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
     561    TestWebKitAPI::Util::run(&done);
     562}
     563
    529564#endif
    530565
Note: See TracChangeset for help on using the changeset viewer.