Changeset 221444 in webkit


Ignore:
Timestamp:
Aug 31, 2017 2:26:24 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

WKNavigationDelegatePrivate client redirect SPI needs to be able to detect redirects scheduled before the document finishes loading
https://bugs.webkit.org/show_bug.cgi?id=176128
rdar://problem/34068476

Patch by David Quesada <david_quesada@apple.com> on 2017-08-31
Reviewed by Brady Eidson.

Source/WebCore:

Removed FrameLoaderClient::dispatchDidPerformClientRedirect() since no client cares about this event anymore.
Also removed FrameLoader::performClientRedirect() since it wouldn't do anything but call changeLocation().

No new tests - no change in functionality.

  • loader/FrameLoader.cpp:
  • loader/FrameLoader.h:
  • loader/FrameLoaderClient.h:
  • loader/NavigationScheduler.cpp:

Source/WebKit:

_webView:didPerformClientRedirect: isn't useful for delegates that want to know about client redirects
started before the document is finished loading. This is because the method would be called after the
navigation scheduler's timer fires and the navigation for the redirect has begun. Since this happens in
a later iteration of the run loop, the document has already finished loading. Address this by replacing
the method with two that give the navigation delegate more information about when client redirects are
scheduled and canceled.

  • UIProcess/API/APINavigationClient.h:

(API::NavigationClient::willPerformClientRedirect):
(API::NavigationClient::didCancelClientRedirect):

  • UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h:
  • UIProcess/Cocoa/NavigationState.h:
  • UIProcess/Cocoa/NavigationState.mm:

(WebKit::NavigationState::setNavigationDelegate):
(WebKit::NavigationState::NavigationClient::willPerformClientRedirect):
(WebKit::NavigationState::NavigationClient::didCancelClientRedirect):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::willPerformClientRedirectForFrame):
(WebKit::WebPageProxy::didCancelClientRedirectForFrame):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:

(WebKit::WebFrameLoaderClient::dispatchDidCancelClientRedirect):
(WebKit::WebFrameLoaderClient::dispatchWillPerformClientRedirect):

  • WebProcess/WebCoreSupport/WebFrameLoaderClient.h:

Tools:

Removed API test for the deleted WKNavigationDelegatePrivate method,
and added two new tests for the two new methods.

  • TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm:

(-[ClientRedirectNavigationDelegate _webView:willPerformClientRedirectToURL:delay:]):
(-[ClientRedirectNavigationDelegate _webViewDidCancelClientRedirect:]):
(-[ClientRedirectNavigationDelegate webView:didFinishNavigation:]):
(TEST):

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r221441 r221444  
     12017-08-31  David Quesada  <david_quesada@apple.com>
     2
     3        WKNavigationDelegatePrivate client redirect SPI needs to be able to detect redirects scheduled before the document finishes loading
     4        https://bugs.webkit.org/show_bug.cgi?id=176128
     5        rdar://problem/34068476
     6
     7        Reviewed by Brady Eidson.
     8
     9        Removed FrameLoaderClient::dispatchDidPerformClientRedirect() since no client cares about this event anymore.
     10        Also removed FrameLoader::performClientRedirect() since it wouldn't do anything but call changeLocation().
     11
     12        No new tests - no change in functionality.
     13
     14        * loader/FrameLoader.cpp:
     15        * loader/FrameLoader.h:
     16        * loader/FrameLoaderClient.h:
     17        * loader/NavigationScheduler.cpp:
     18
    1192017-08-31  Chris Dumez  <cdumez@apple.com>
    220
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r221193 r221444  
    20512051}
    20522052
    2053 void FrameLoader::performClientRedirect(FrameLoadRequest&& frameLoadRequest)
    2054 {
    2055     changeLocation(WTFMove(frameLoadRequest));
    2056     m_client.dispatchDidPerformClientRedirect();
    2057 }
    2058 
    20592053bool FrameLoader::shouldReload(const URL& currentURL, const URL& destinationURL)
    20602054{
  • trunk/Source/WebCore/loader/FrameLoader.h

    r221103 r221444  
    266266    void clientRedirected(const URL&, double delay, double fireDate, LockBackForwardList);
    267267    void clientRedirectCancelledOrFinished(bool cancelWithLoadInProgress);
    268     void performClientRedirect(FrameLoadRequest&&);
    269268
    270269    // FIXME: This is public because this asynchronous callback from the FrameLoaderClient
  • trunk/Source/WebCore/loader/FrameLoaderClient.h

    r220857 r221444  
    155155    virtual void dispatchDidCancelClientRedirect() = 0;
    156156    virtual void dispatchWillPerformClientRedirect(const URL&, double interval, double fireDate) = 0;
    157     virtual void dispatchDidPerformClientRedirect() { }
    158157    virtual void dispatchDidChangeMainDocument() { }
    159158    virtual void dispatchDidNavigateWithinPage() { }
  • trunk/Source/WebCore/loader/NavigationScheduler.cpp

    r219709 r221444  
    186186        FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
    187187
    188         frame.loader().performClientRedirect(WTFMove(frameLoadRequest));
     188        frame.loader().changeLocation(WTFMove(frameLoadRequest));
    189189    }
    190190};
     
    202202        FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
    203203
    204         frame.loader().performClientRedirect(WTFMove(frameLoadRequest));
     204        frame.loader().changeLocation(WTFMove(frameLoadRequest));
    205205    }
    206206};
  • trunk/Source/WebKit/ChangeLog

    r221443 r221444  
     12017-08-31  David Quesada  <david_quesada@apple.com>
     2
     3        WKNavigationDelegatePrivate client redirect SPI needs to be able to detect redirects scheduled before the document finishes loading
     4        https://bugs.webkit.org/show_bug.cgi?id=176128
     5        rdar://problem/34068476
     6
     7        Reviewed by Brady Eidson.
     8
     9        _webView:didPerformClientRedirect: isn't useful for delegates that want to know about client redirects
     10        started before the document is finished loading. This is because the method would be called after the
     11        navigation scheduler's timer fires and the navigation for the redirect has begun. Since this happens in
     12        a later iteration of the run loop, the document has already finished loading. Address this by replacing
     13        the method with two that give the navigation delegate more information about when client redirects are
     14        scheduled and canceled.
     15
     16        * UIProcess/API/APINavigationClient.h:
     17        (API::NavigationClient::willPerformClientRedirect):
     18        (API::NavigationClient::didCancelClientRedirect):
     19        * UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h:
     20        * UIProcess/Cocoa/NavigationState.h:
     21        * UIProcess/Cocoa/NavigationState.mm:
     22        (WebKit::NavigationState::setNavigationDelegate):
     23        (WebKit::NavigationState::NavigationClient::willPerformClientRedirect):
     24        (WebKit::NavigationState::NavigationClient::didCancelClientRedirect):
     25        * UIProcess/WebPageProxy.cpp:
     26        (WebKit::WebPageProxy::willPerformClientRedirectForFrame):
     27        (WebKit::WebPageProxy::didCancelClientRedirectForFrame):
     28        * UIProcess/WebPageProxy.h:
     29        * UIProcess/WebPageProxy.messages.in:
     30        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
     31        (WebKit::WebFrameLoaderClient::dispatchDidCancelClientRedirect):
     32        (WebKit::WebFrameLoaderClient::dispatchWillPerformClientRedirect):
     33        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
     34
    1352017-08-30  Megan Gardner  <megan_gardner@apple.com>
    236
  • trunk/Source/WebKit/UIProcess/API/APINavigationClient.h

    r219871 r221444  
    7070    virtual void didStartProvisionalNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
    7171    virtual void didReceiveServerRedirectForProvisionalNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
    72     virtual void didPerformClientRedirectForNavigation(WebKit::WebPageProxy&, Navigation*) { }
     72    virtual void willPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String&, double) { }
     73    virtual void didCancelClientRedirect(WebKit::WebPageProxy&) { }
    7374    virtual void didFailProvisionalNavigationWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, Navigation*, const WebCore::ResourceError&, Object*) { }
    7475    virtual void didFailProvisionalLoadInSubframeWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::SecurityOriginData&, Navigation*, const WebCore::ResourceError&, Object*) { }
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h

    r219709 r221444  
    4545- (void)_webView:(WKWebView *)webView navigation:(WKNavigation *)navigation didFailProvisionalLoadInSubframe:(WKFrameInfo *)subframe withError:(NSError *)error;
    4646
    47 - (void)_webView:(WKWebView *)webView didPerformClientRedirectForNavigation:(WKNavigation *)navigation;
     47- (void)_webView:(WKWebView *)webView willPerformClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)delay;
     48- (void)_webViewDidCancelClientRedirect:(WKWebView *)webView;
    4849
    4950- (void)_webView:(WKWebView *)webView navigationDidFinishDocumentLoad:(WKNavigation *)navigation;
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h

    r219871 r221444  
    9292        void didStartProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
    9393        void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
    94         void didPerformClientRedirectForNavigation(WebPageProxy&, API::Navigation*) override;
     94        void willPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String&, double) override;
     95        void didCancelClientRedirect(WebKit::WebPageProxy&) override;
    9596        void didFailProvisionalNavigationWithError(WebPageProxy&, WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
    9697        void didFailProvisionalLoadInSubframeWithError(WebPageProxy&, WebFrameProxy&, const WebCore::SecurityOriginData&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
     
    174175        bool webViewDidFailProvisionalNavigationWithError : 1;
    175176        bool webViewNavigationDidFailProvisionalLoadInSubframeWithError : 1;
    176         bool webViewDidPerformClientRedirectForNavigation : 1;
     177        bool webViewWillPerformClientRedirect : 1;
     178        bool webViewDidCancelClientRedirect : 1;
    177179        bool webViewDidCommitNavigation : 1;
    178180        bool webViewNavigationDidFinishDocumentLoad : 1;
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r220809 r221444  
    151151
    152152    m_navigationDelegateMethods.webViewNavigationDidFailProvisionalLoadInSubframeWithError = [delegate respondsToSelector:@selector(_webView:navigation:didFailProvisionalLoadInSubframe:withError:)];
    153     m_navigationDelegateMethods.webViewDidPerformClientRedirectForNavigation = [delegate respondsToSelector:@selector(_webView:didPerformClientRedirectForNavigation:)];
     153    m_navigationDelegateMethods.webViewWillPerformClientRedirect = [delegate respondsToSelector:@selector(_webView:willPerformClientRedirectToURL:delay:)];
     154    m_navigationDelegateMethods.webViewDidCancelClientRedirect = [delegate respondsToSelector:@selector(_webViewDidCancelClientRedirect:)];
    154155    m_navigationDelegateMethods.webViewNavigationDidFinishDocumentLoad = [delegate respondsToSelector:@selector(_webView:navigationDidFinishDocumentLoad:)];
    155156    m_navigationDelegateMethods.webViewNavigationDidSameDocumentNavigation = [delegate respondsToSelector:@selector(_webView:navigation:didSameDocumentNavigation:)];
     
    490491}
    491492
    492 void NavigationState::NavigationClient::didPerformClientRedirectForNavigation(WebPageProxy& page, API::Navigation* navigation)
    493 {
    494     if (!m_navigationState.m_navigationDelegateMethods.webViewDidPerformClientRedirectForNavigation)
    495         return;
    496 
    497     auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
    498     if (!navigationDelegate)
    499         return;
    500 
    501     // FIXME: We should assert that navigation is not null here, but it's currently null for some navigations through the page cache.
    502     WKNavigation *wkNavigation = nil;
    503     if (navigation)
    504         wkNavigation = wrapper(*navigation);
    505 
    506     [(id <WKNavigationDelegatePrivate>)navigationDelegate _webView:m_navigationState.m_webView didPerformClientRedirectForNavigation:wkNavigation];
     493void NavigationState::NavigationClient::willPerformClientRedirect(WebKit::WebPageProxy& page, const WTF::String& urlString, double delay)
     494{
     495    if (!m_navigationState.m_navigationDelegateMethods.webViewWillPerformClientRedirect)
     496        return;
     497
     498    auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
     499    if (!navigationDelegate)
     500        return;
     501
     502    WebCore::URL url(WebCore::URL(), urlString);
     503
     504    [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate) _webView:m_navigationState.m_webView willPerformClientRedirectToURL:url delay:delay];
     505}
     506
     507void NavigationState::NavigationClient::didCancelClientRedirect(WebKit::WebPageProxy& page)
     508{
     509    if (!m_navigationState.m_navigationDelegateMethods.webViewDidCancelClientRedirect)
     510        return;
     511
     512    auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
     513    if (!navigationDelegate)
     514        return;
     515
     516    [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate) _webViewDidCancelClientRedirect:m_navigationState.m_webView];
    507517}
    508518
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r221216 r221444  
    32093209}
    32103210
    3211 void WebPageProxy::didPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID)
     3211void WebPageProxy::willPerformClientRedirectForFrame(uint64_t frameID, const String& url, double delay)
    32123212{
    32133213    PageClientProtector protector(m_pageClient);
     
    32163216    MESSAGE_CHECK(frame);
    32173217
    3218     // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
    3219     RefPtr<API::Navigation> navigation;
    3220     if (frame->isMainFrame() && navigationID)
    3221         navigation = &navigationState().navigation(navigationID);
    3222 
    32233218    if (m_navigationClient) {
    32243219        if (frame->isMainFrame())
    3225             m_navigationClient->didPerformClientRedirectForNavigation(*this, navigation.get());
     3220            m_navigationClient->willPerformClientRedirect(*this, url, delay);
     3221    }
     3222}
     3223
     3224void WebPageProxy::didCancelClientRedirectForFrame(uint64_t frameID)
     3225{
     3226    PageClientProtector protector(m_pageClient);
     3227
     3228    WebFrameProxy* frame = m_process->webFrame(frameID);
     3229    MESSAGE_CHECK(frame);
     3230
     3231    if (m_navigationClient) {
     3232        if (frame->isMainFrame())
     3233            m_navigationClient->didCancelClientRedirect(*this);
    32263234    }
    32273235}
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r221216 r221444  
    12481248    void didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const String& unreachableURL, const UserData&);
    12491249    void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String&, const UserData&);
    1250     void didPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID);
     1250    void willPerformClientRedirectForFrame(uint64_t frameID, const String& url, double delay);
     1251    void didCancelClientRedirectForFrame(uint64_t frameID);
    12511252    void didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, const String& url);
    12521253    void didFailProvisionalLoadForFrame(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, const UserData&);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r221216 r221444  
    119119    DidStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, String unreachableURL, WebKit::UserData userData)
    120120    DidReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, WebKit::UserData userData)
    121     DidPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID)
     121    WillPerformClientRedirectForFrame(uint64_t frameID, String url, double delay)
     122    DidCancelClientRedirectForFrame(uint64_t frameID)
    122123    DidChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, String url)
    123124    DidFailProvisionalLoadForFrame(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, uint64_t navigationID, String provisionalURL, WebCore::ResourceError error, WebKit::UserData userData)
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r220857 r221444  
    290290}
    291291
    292 void WebFrameLoaderClient::dispatchDidPerformClientRedirect()
    293 {
    294     WebPage* webPage = m_frame->page();
    295     if (!webPage)
    296         return;
    297 
    298     auto navigationID = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader()).navigationID();
    299 
    300     // Notify the UIProcess.
    301     webPage->send(Messages::WebPageProxy::DidPerformClientRedirectForLoadForFrame(m_frame->frameID(), navigationID));
    302 }
    303 
    304292void WebFrameLoaderClient::dispatchDidChangeProvisionalURL()
    305293{
     
    320308    // Notify the bundle client.
    321309    webPage->injectedBundleLoaderClient().didCancelClientRedirectForFrame(*webPage, *m_frame);
     310
     311    // Notify the UIProcess.
     312    webPage->send(Messages::WebPageProxy::DidCancelClientRedirectForFrame(m_frame->frameID()));
    322313}
    323314
     
    330321    // Notify the bundle client.
    331322    webPage->injectedBundleLoaderClient().willPerformClientRedirectForFrame(*webPage, *m_frame, url, interval, fireDate);
     323
     324    // Notify the UIProcess.
     325    webPage->send(Messages::WebPageProxy::WillPerformClientRedirectForFrame(m_frame->frameID(), url.string(), interval));
    332326}
    333327
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h

    r220857 r221444  
    8989    void dispatchDidDispatchOnloadEvents() final;
    9090    void dispatchDidReceiveServerRedirectForProvisionalLoad() final;
    91     void dispatchDidPerformClientRedirect() final;
    9291    void dispatchDidChangeProvisionalURL() final;
    9392    void dispatchDidCancelClientRedirect() final;
  • trunk/Tools/ChangeLog

    r221442 r221444  
     12017-08-31  David Quesada  <david_quesada@apple.com>
     2
     3        WKNavigationDelegatePrivate client redirect SPI needs to be able to detect redirects scheduled before the document finishes loading
     4        https://bugs.webkit.org/show_bug.cgi?id=176128
     5        rdar://problem/34068476
     6
     7        Reviewed by Brady Eidson.
     8
     9        Removed API test for the deleted WKNavigationDelegatePrivate method,
     10        and added two new tests for the two new methods.
     11
     12        * TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm:
     13        (-[ClientRedirectNavigationDelegate _webView:willPerformClientRedirectToURL:delay:]):
     14        (-[ClientRedirectNavigationDelegate _webViewDidCancelClientRedirect:]):
     15        (-[ClientRedirectNavigationDelegate webView:didFinishNavigation:]):
     16        (TEST):
     17
    1182017-08-31  Filip Pizlo  <fpizlo@apple.com>
    219
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm

    r219709 r221444  
    3838static RetainPtr<WKNavigation> currentNavigation;
    3939static RetainPtr<NSURL> redirectURL;
     40static NSTimeInterval redirectDelay;
     41static bool didCancelRedirect;
    4042
    4143@interface NavigationDelegate : NSObject <WKNavigationDelegate>
     
    189191}
    190192
    191 @interface DidPerformClientRedirectNavigationDelegate : NSObject<WKNavigationDelegatePrivate>
    192 @end
    193 
    194 @implementation DidPerformClientRedirectNavigationDelegate
    195 - (void)_webView:(WKWebView *)webView didPerformClientRedirectForNavigation:(WKNavigation *)navigation
    196 {
    197     isDone = true;
    198     redirectURL = webView.URL;
    199 }
    200 @end
    201 
    202 TEST(WKNavigation, DidPerformClientRedirect)
    203 {
    204     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
    205 
    206     RetainPtr<DidPerformClientRedirectNavigationDelegate> delegate = adoptNS([[DidPerformClientRedirectNavigationDelegate alloc] init]);
    207     [webView setNavigationDelegate:delegate.get()];
    208 
    209     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%220;URL=data:text/html,Page1%22%3E"]];
     193@interface ClientRedirectNavigationDelegate : NSObject<WKNavigationDelegatePrivate>
     194@end
     195
     196@implementation ClientRedirectNavigationDelegate
     197- (void)_webView:(WKWebView *)webView willPerformClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)delay
     198{
     199    redirectURL = URL;
     200    redirectDelay = delay;
     201}
     202- (void)_webViewDidCancelClientRedirect:(WKWebView *)webView
     203{
     204    didCancelRedirect = true;
     205}
     206- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
     207{
     208    isDone = true;
     209}
     210@end
     211
     212TEST(WKNavigation, WebViewWillPerformClientRedirect)
     213{
     214    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     215
     216    auto delegate = adoptNS([[ClientRedirectNavigationDelegate alloc] init]);
     217    [webView setNavigationDelegate:delegate.get()];
     218
     219    auto request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%22123;URL=data:text/html,Page1%22%3E"]];
    210220
    211221    isDone = false;
    212222    redirectURL = nil;
    213     [webView loadRequest:request];
    214     TestWebKitAPI::Util::run(&isDone);
    215 
     223    redirectDelay = 0;
     224    [webView loadRequest:request];
     225    TestWebKitAPI::Util::run(&isDone);
     226
     227    ASSERT_DOUBLE_EQ(redirectDelay, 123);
    216228    ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page1");
    217229
     
    219231    isDone = false;
    220232    redirectURL = nil;
    221     [webView loadRequest:request];
    222     TestWebKitAPI::Util::run(&isDone);
    223 
     233    redirectDelay = NSTimeIntervalSince1970; // Use any non-zero value, we will test that the delegate receives a delay of 0.
     234    [webView loadRequest:request];
     235    TestWebKitAPI::Util::run(&isDone);
     236
     237    ASSERT_DOUBLE_EQ(redirectDelay, 0);
    224238    ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page2");
    225239}
    226240
     241TEST(WKNavigation, WebViewDidCancelClientRedirect)
     242{
     243    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     244
     245    auto delegate = adoptNS([[ClientRedirectNavigationDelegate alloc] init]);
     246    [webView setNavigationDelegate:delegate.get()];
     247
     248    // Test 1: During a navigation that is not a client redirect, -_webViewDidCancelClientRedirect: should not be called.
     249
     250    auto request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,Page1"]];
     251
     252    isDone = false;
     253    didCancelRedirect = false;
     254    [webView loadRequest:request];
     255    TestWebKitAPI::Util::run(&isDone);
     256
     257    ASSERT_FALSE(didCancelRedirect);
     258
     259    // Test 2: When a client redirect does happen, -_webViewDidCancelClientRedirect: should still be called. It essentially
     260    // is called whenever the web view transitions from "expecting a redirect" to "not expecting a redirect".
     261
     262    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cscript%3Ewindow.location=%22data:text/html,Page2%22;%3C/script%3E"]];
     263    isDone = false;
     264    didCancelRedirect = false;
     265    [webView loadRequest:request];
     266    TestWebKitAPI::Util::run(&isDone);
     267
     268    ASSERT_FALSE(didCancelRedirect);
     269
     270    isDone = false;
     271    TestWebKitAPI::Util::run(&isDone);
     272
     273    ASSERT_TRUE(didCancelRedirect);
     274
     275    // Test 3: When another navigation begins while a client redirect is scheduled, -_webViewDidCancelClientRedirect:
     276    // should be called.
     277
     278    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%2210000;URL=data:text/html,Page3%22%3E"]];
     279
     280    isDone = false;
     281    didCancelRedirect = false;
     282    [webView loadRequest:request];
     283    TestWebKitAPI::Util::run(&isDone);
     284
     285    ASSERT_FALSE(didCancelRedirect);
     286
     287    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,Page4"]];
     288    isDone = false;
     289    [webView loadRequest:request];
     290    TestWebKitAPI::Util::run(&isDone);
     291
     292    ASSERT_TRUE(didCancelRedirect);
     293}
     294
    227295#endif
Note: See TracChangeset for help on using the changeset viewer.