Title: [221444] trunk
Revision
221444
Author
commit-qu...@webkit.org
Date
2017-08-31 14:26:24 -0700 (Thu, 31 Aug 2017)

Log 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_ques...@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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (221443 => 221444)


--- trunk/Source/WebCore/ChangeLog	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebCore/ChangeLog	2017-08-31 21:26:24 UTC (rev 221444)
@@ -1,3 +1,21 @@
+2017-08-31  David Quesada  <david_ques...@apple.com>
+
+        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
+
+        Reviewed by Brady Eidson.
+
+        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:
+
 2017-08-31  Chris Dumez  <cdu...@apple.com>
 
         getFileMetadata() does not work as expected for symbolic links

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (221443 => 221444)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2017-08-31 21:26:24 UTC (rev 221444)
@@ -2050,12 +2050,6 @@
     m_quickRedirectComing = (lockBackForwardList == LockBackForwardList::Yes || history().currentItemShouldBeReplaced()) && m_documentLoader && !m_isExecutingJavaScriptFormAction;
 }
 
-void FrameLoader::performClientRedirect(FrameLoadRequest&& frameLoadRequest)
-{
-    changeLocation(WTFMove(frameLoadRequest));
-    m_client.dispatchDidPerformClientRedirect();
-}
-
 bool FrameLoader::shouldReload(const URL& currentURL, const URL& destinationURL)
 {
     // This function implements the rule: "Don't reload if navigating by fragment within

Modified: trunk/Source/WebCore/loader/FrameLoader.h (221443 => 221444)


--- trunk/Source/WebCore/loader/FrameLoader.h	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebCore/loader/FrameLoader.h	2017-08-31 21:26:24 UTC (rev 221444)
@@ -265,7 +265,6 @@
     bool allAncestorsAreComplete() const; // including this
     void clientRedirected(const URL&, double delay, double fireDate, LockBackForwardList);
     void clientRedirectCancelledOrFinished(bool cancelWithLoadInProgress);
-    void performClientRedirect(FrameLoadRequest&&);
 
     // FIXME: This is public because this asynchronous callback from the FrameLoaderClient
     // uses the policy machinery (and therefore is called via the PolicyChecker).  Once we

Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (221443 => 221444)


--- trunk/Source/WebCore/loader/FrameLoaderClient.h	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebCore/loader/FrameLoaderClient.h	2017-08-31 21:26:24 UTC (rev 221444)
@@ -154,7 +154,6 @@
     virtual void dispatchDidChangeProvisionalURL() { }
     virtual void dispatchDidCancelClientRedirect() = 0;
     virtual void dispatchWillPerformClientRedirect(const URL&, double interval, double fireDate) = 0;
-    virtual void dispatchDidPerformClientRedirect() { }
     virtual void dispatchDidChangeMainDocument() { }
     virtual void dispatchDidNavigateWithinPage() { }
     virtual void dispatchDidChangeLocationWithinPage() = 0;

Modified: trunk/Source/WebCore/loader/NavigationScheduler.cpp (221443 => 221444)


--- trunk/Source/WebCore/loader/NavigationScheduler.cpp	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebCore/loader/NavigationScheduler.cpp	2017-08-31 21:26:24 UTC (rev 221444)
@@ -185,7 +185,7 @@
         ResourceRequest resourceRequest { url(), referrer(), refresh ? ReloadIgnoringCacheData : UseProtocolCachePolicy };
         FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
 
-        frame.loader().performClientRedirect(WTFMove(frameLoadRequest));
+        frame.loader().changeLocation(WTFMove(frameLoadRequest));
     }
 };
 
@@ -201,7 +201,7 @@
         ResourceRequest resourceRequest { url(), referrer(), UseProtocolCachePolicy };
         FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
 
-        frame.loader().performClientRedirect(WTFMove(frameLoadRequest));
+        frame.loader().changeLocation(WTFMove(frameLoadRequest));
     }
 };
 

Modified: trunk/Source/WebKit/ChangeLog (221443 => 221444)


--- trunk/Source/WebKit/ChangeLog	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/ChangeLog	2017-08-31 21:26:24 UTC (rev 221444)
@@ -1,3 +1,37 @@
+2017-08-31  David Quesada  <david_ques...@apple.com>
+
+        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
+
+        Reviewed by Brady Eidson.
+
+        _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:
+
 2017-08-30  Megan Gardner  <megan_gard...@apple.com>
 
         Remove IsBlockSelection flag

Modified: trunk/Source/WebKit/UIProcess/API/APINavigationClient.h (221443 => 221444)


--- trunk/Source/WebKit/UIProcess/API/APINavigationClient.h	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/UIProcess/API/APINavigationClient.h	2017-08-31 21:26:24 UTC (rev 221444)
@@ -69,7 +69,8 @@
 
     virtual void didStartProvisionalNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
     virtual void didReceiveServerRedirectForProvisionalNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
-    virtual void didPerformClientRedirectForNavigation(WebKit::WebPageProxy&, Navigation*) { }
+    virtual void willPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String&, double) { }
+    virtual void didCancelClientRedirect(WebKit::WebPageProxy&) { }
     virtual void didFailProvisionalNavigationWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, Navigation*, const WebCore::ResourceError&, Object*) { }
     virtual void didFailProvisionalLoadInSubframeWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::SecurityOriginData&, Navigation*, const WebCore::ResourceError&, Object*) { }
     virtual void didCommitNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h (221443 => 221444)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h	2017-08-31 21:26:24 UTC (rev 221444)
@@ -44,7 +44,8 @@
 
 - (void)_webView:(WKWebView *)webView navigation:(WKNavigation *)navigation didFailProvisionalLoadInSubframe:(WKFrameInfo *)subframe withError:(NSError *)error;
 
-- (void)_webView:(WKWebView *)webView didPerformClientRedirectForNavigation:(WKNavigation *)navigation;
+- (void)_webView:(WKWebView *)webView willPerformClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)delay;
+- (void)_webViewDidCancelClientRedirect:(WKWebView *)webView;
 
 - (void)_webView:(WKWebView *)webView navigationDidFinishDocumentLoad:(WKNavigation *)navigation;
 - (void)_webView:(WKWebView *)webView navigation:(WKNavigation *)navigation didSameDocumentNavigation:(_WKSameDocumentNavigationType)navigationType;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h (221443 => 221444)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2017-08-31 21:26:24 UTC (rev 221444)
@@ -91,7 +91,8 @@
     private:
         void didStartProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
         void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
-        void didPerformClientRedirectForNavigation(WebPageProxy&, API::Navigation*) override;
+        void willPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String&, double) override;
+        void didCancelClientRedirect(WebKit::WebPageProxy&) override;
         void didFailProvisionalNavigationWithError(WebPageProxy&, WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
         void didFailProvisionalLoadInSubframeWithError(WebPageProxy&, WebFrameProxy&, const WebCore::SecurityOriginData&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
         void didCommitNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
@@ -173,7 +174,8 @@
         bool webViewDidReceiveServerRedirectForProvisionalNavigation : 1;
         bool webViewDidFailProvisionalNavigationWithError : 1;
         bool webViewNavigationDidFailProvisionalLoadInSubframeWithError : 1;
-        bool webViewDidPerformClientRedirectForNavigation : 1;
+        bool webViewWillPerformClientRedirect : 1;
+        bool webViewDidCancelClientRedirect : 1;
         bool webViewDidCommitNavigation : 1;
         bool webViewNavigationDidFinishDocumentLoad : 1;
         bool webViewDidFinishNavigation : 1;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (221443 => 221444)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2017-08-31 21:26:24 UTC (rev 221444)
@@ -150,7 +150,8 @@
     m_navigationDelegateMethods.webViewDidFailNavigationWithError = [delegate respondsToSelector:@selector(webView:didFailNavigation:withError:)];
 
     m_navigationDelegateMethods.webViewNavigationDidFailProvisionalLoadInSubframeWithError = [delegate respondsToSelector:@selector(_webView:navigation:didFailProvisionalLoadInSubframe:withError:)];
-    m_navigationDelegateMethods.webViewDidPerformClientRedirectForNavigation = [delegate respondsToSelector:@selector(_webView:didPerformClientRedirectForNavigation:)];
+    m_navigationDelegateMethods.webViewWillPerformClientRedirect = [delegate respondsToSelector:@selector(_webView:willPerformClientRedirectToURL:delay:)];
+    m_navigationDelegateMethods.webViewDidCancelClientRedirect = [delegate respondsToSelector:@selector(_webViewDidCancelClientRedirect:)];
     m_navigationDelegateMethods.webViewNavigationDidFinishDocumentLoad = [delegate respondsToSelector:@selector(_webView:navigationDidFinishDocumentLoad:)];
     m_navigationDelegateMethods.webViewNavigationDidSameDocumentNavigation = [delegate respondsToSelector:@selector(_webView:navigation:didSameDocumentNavigation:)];
     m_navigationDelegateMethods.webViewRenderingProgressDidChange = [delegate respondsToSelector:@selector(_webView:renderingProgressDidChange:)];
@@ -489,9 +490,9 @@
     [navigationDelegate webView:m_navigationState.m_webView didReceiveServerRedirectForProvisionalNavigation:wkNavigation];
 }
 
-void NavigationState::NavigationClient::didPerformClientRedirectForNavigation(WebPageProxy& page, API::Navigation* navigation)
+void NavigationState::NavigationClient::willPerformClientRedirect(WebKit::WebPageProxy& page, const WTF::String& urlString, double delay)
 {
-    if (!m_navigationState.m_navigationDelegateMethods.webViewDidPerformClientRedirectForNavigation)
+    if (!m_navigationState.m_navigationDelegateMethods.webViewWillPerformClientRedirect)
         return;
 
     auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
@@ -498,14 +499,23 @@
     if (!navigationDelegate)
         return;
 
-    // FIXME: We should assert that navigation is not null here, but it's currently null for some navigations through the page cache.
-    WKNavigation *wkNavigation = nil;
-    if (navigation)
-        wkNavigation = wrapper(*navigation);
+    WebCore::URL url(WebCore::URL(), urlString);
 
-    [(id <WKNavigationDelegatePrivate>)navigationDelegate _webView:m_navigationState.m_webView didPerformClientRedirectForNavigation:wkNavigation];
+    [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate) _webView:m_navigationState.m_webView willPerformClientRedirectToURL:url delay:delay];
 }
 
+void NavigationState::NavigationClient::didCancelClientRedirect(WebKit::WebPageProxy& page)
+{
+    if (!m_navigationState.m_navigationDelegateMethods.webViewDidCancelClientRedirect)
+        return;
+
+    auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
+    if (!navigationDelegate)
+        return;
+
+    [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate) _webViewDidCancelClientRedirect:m_navigationState.m_webView];
+}
+
 static RetainPtr<NSError> createErrorWithRecoveryAttempter(WKWebView *webView, WebFrameProxy& webFrameProxy, NSError *originalError)
 {
     RefPtr<API::FrameHandle> frameHandle = API::FrameHandle::create(webFrameProxy.frameID());

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (221443 => 221444)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2017-08-31 21:26:24 UTC (rev 221444)
@@ -3208,7 +3208,7 @@
         m_loaderClient->didReceiveServerRedirectForProvisionalLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
 }
 
-void WebPageProxy::didPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID)
+void WebPageProxy::willPerformClientRedirectForFrame(uint64_t frameID, const String& url, double delay)
 {
     PageClientProtector protector(m_pageClient);
 
@@ -3215,14 +3215,22 @@
     WebFrameProxy* frame = m_process->webFrame(frameID);
     MESSAGE_CHECK(frame);
 
-    // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
-    RefPtr<API::Navigation> navigation;
-    if (frame->isMainFrame() && navigationID)
-        navigation = &navigationState().navigation(navigationID);
+    if (m_navigationClient) {
+        if (frame->isMainFrame())
+            m_navigationClient->willPerformClientRedirect(*this, url, delay);
+    }
+}
 
+void WebPageProxy::didCancelClientRedirectForFrame(uint64_t frameID)
+{
+    PageClientProtector protector(m_pageClient);
+
+    WebFrameProxy* frame = m_process->webFrame(frameID);
+    MESSAGE_CHECK(frame);
+
     if (m_navigationClient) {
         if (frame->isMainFrame())
-            m_navigationClient->didPerformClientRedirectForNavigation(*this, navigation.get());
+            m_navigationClient->didCancelClientRedirect(*this);
     }
 }
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (221443 => 221444)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2017-08-31 21:26:24 UTC (rev 221444)
@@ -1247,7 +1247,8 @@
 
     void didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const String& unreachableURL, const UserData&);
     void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String&, const UserData&);
-    void didPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID);
+    void willPerformClientRedirectForFrame(uint64_t frameID, const String& url, double delay);
+    void didCancelClientRedirectForFrame(uint64_t frameID);
     void didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, const String& url);
     void didFailProvisionalLoadForFrame(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, const UserData&);
     void didCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& mimeType, bool frameHasCustomContentProvider, uint32_t frameLoadType, const WebCore::CertificateInfo&, bool containsPluginDocument, std::optional<WebCore::HasInsecureContent> forcedHasInsecureContent, const UserData&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (221443 => 221444)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2017-08-31 21:26:24 UTC (rev 221444)
@@ -118,7 +118,8 @@
     # Frame load messages
     DidStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, String unreachableURL, WebKit::UserData userData)
     DidReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, WebKit::UserData userData)
-    DidPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID)
+    WillPerformClientRedirectForFrame(uint64_t frameID, String url, double delay)
+    DidCancelClientRedirectForFrame(uint64_t frameID)
     DidChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, String url)
     DidFailProvisionalLoadForFrame(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, uint64_t navigationID, String provisionalURL, WebCore::ResourceError error, WebKit::UserData userData)
     DidCommitLoadForFrame(uint64_t frameID, uint64_t navigationID, String mimeType, bool hasCustomContentProvider, uint32_t loadType, WebCore::CertificateInfo certificateInfo, bool containsPluginDocument, std::optional<WebCore::HasInsecureContent> forcedHasInsecureContent, WebKit::UserData userData)

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (221443 => 221444)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2017-08-31 21:26:24 UTC (rev 221444)
@@ -289,18 +289,6 @@
     webPage->send(Messages::WebPageProxy::DidReceiveServerRedirectForProvisionalLoadForFrame(m_frame->frameID(), documentLoader.navigationID(), url, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
 }
 
-void WebFrameLoaderClient::dispatchDidPerformClientRedirect()
-{
-    WebPage* webPage = m_frame->page();
-    if (!webPage)
-        return;
-
-    auto navigationID = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().documentLoader()).navigationID();
-
-    // Notify the UIProcess.
-    webPage->send(Messages::WebPageProxy::DidPerformClientRedirectForLoadForFrame(m_frame->frameID(), navigationID));
-}
-
 void WebFrameLoaderClient::dispatchDidChangeProvisionalURL()
 {
     WebPage* webPage = m_frame->page();
@@ -319,6 +307,9 @@
 
     // Notify the bundle client.
     webPage->injectedBundleLoaderClient().didCancelClientRedirectForFrame(*webPage, *m_frame);
+
+    // Notify the UIProcess.
+    webPage->send(Messages::WebPageProxy::DidCancelClientRedirectForFrame(m_frame->frameID()));
 }
 
 void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const URL& url, double interval, double fireDate)
@@ -329,6 +320,9 @@
 
     // Notify the bundle client.
     webPage->injectedBundleLoaderClient().willPerformClientRedirectForFrame(*webPage, *m_frame, url, interval, fireDate);
+
+    // Notify the UIProcess.
+    webPage->send(Messages::WebPageProxy::WillPerformClientRedirectForFrame(m_frame->frameID(), url.string(), interval));
 }
 
 void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h (221443 => 221444)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2017-08-31 21:26:24 UTC (rev 221444)
@@ -88,7 +88,6 @@
 
     void dispatchDidDispatchOnloadEvents() final;
     void dispatchDidReceiveServerRedirectForProvisionalLoad() final;
-    void dispatchDidPerformClientRedirect() final;
     void dispatchDidChangeProvisionalURL() final;
     void dispatchDidCancelClientRedirect() final;
     void dispatchWillPerformClientRedirect(const WebCore::URL&, double interval, double fireDate) final;

Modified: trunk/Tools/ChangeLog (221443 => 221444)


--- trunk/Tools/ChangeLog	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Tools/ChangeLog	2017-08-31 21:26:24 UTC (rev 221444)
@@ -1,3 +1,20 @@
+2017-08-31  David Quesada  <david_ques...@apple.com>
+
+        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
+
+        Reviewed by Brady Eidson.
+
+        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):
+
 2017-08-31  Filip Pizlo  <fpi...@apple.com>
 
         WSL should handle variable assignments and variable declarations

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm (221443 => 221444)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm	2017-08-31 21:13:38 UTC (rev 221443)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm	2017-08-31 21:26:24 UTC (rev 221444)
@@ -37,6 +37,8 @@
 static bool isDone;
 static RetainPtr<WKNavigation> currentNavigation;
 static RetainPtr<NSURL> redirectURL;
+static NSTimeInterval redirectDelay;
+static bool didCancelRedirect;
 
 @interface NavigationDelegate : NSObject <WKNavigationDelegate>
 @end
@@ -188,40 +190,106 @@
     ASSERT_TRUE([delegate decidedPolicyForBackForwardNavigation]);
 }
 
-@interface DidPerformClientRedirectNavigationDelegate : NSObject<WKNavigationDelegatePrivate>
+@interface ClientRedirectNavigationDelegate : NSObject<WKNavigationDelegatePrivate>
 @end
 
-@implementation DidPerformClientRedirectNavigationDelegate
-- (void)_webView:(WKWebView *)webView didPerformClientRedirectForNavigation:(WKNavigation *)navigation
+@implementation ClientRedirectNavigationDelegate
+- (void)_webView:(WKWebView *)webView willPerformClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)delay
 {
+    redirectURL = URL;
+    redirectDelay = delay;
+}
+- (void)_webViewDidCancelClientRedirect:(WKWebView *)webView
+{
+    didCancelRedirect = true;
+}
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
     isDone = true;
-    redirectURL = webView.URL;
 }
 @end
 
-TEST(WKNavigation, DidPerformClientRedirect)
+TEST(WKNavigation, WebViewWillPerformClientRedirect)
 {
-    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
 
-    RetainPtr<DidPerformClientRedirectNavigationDelegate> delegate = adoptNS([[DidPerformClientRedirectNavigationDelegate alloc] init]);
+    auto delegate = adoptNS([[ClientRedirectNavigationDelegate alloc] init]);
     [webView setNavigationDelegate:delegate.get()];
 
-    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%220;URL=""
+    auto request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%22123;URL=""
 
     isDone = false;
     redirectURL = nil;
+    redirectDelay = 0;
     [webView loadRequest:request];
     TestWebKitAPI::Util::run(&isDone);
 
+    ASSERT_DOUBLE_EQ(redirectDelay, 123);
     ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page1");
 
     request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cscript%3Ewindow.location=%22data:text/html,Page2%22;%3C/script%3E"]];
     isDone = false;
     redirectURL = nil;
+    redirectDelay = NSTimeIntervalSince1970; // Use any non-zero value, we will test that the delegate receives a delay of 0.
     [webView loadRequest:request];
     TestWebKitAPI::Util::run(&isDone);
 
+    ASSERT_DOUBLE_EQ(redirectDelay, 0);
     ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page2");
 }
 
+TEST(WKNavigation, WebViewDidCancelClientRedirect)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto delegate = adoptNS([[ClientRedirectNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+
+    // Test 1: During a navigation that is not a client redirect, -_webViewDidCancelClientRedirect: should not be called.
+
+    auto request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,Page1"]];
+
+    isDone = false;
+    didCancelRedirect = false;
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&isDone);
+
+    ASSERT_FALSE(didCancelRedirect);
+
+    // Test 2: When a client redirect does happen, -_webViewDidCancelClientRedirect: should still be called. It essentially
+    // is called whenever the web view transitions from "expecting a redirect" to "not expecting a redirect".
+
+    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cscript%3Ewindow.location=%22data:text/html,Page2%22;%3C/script%3E"]];
+    isDone = false;
+    didCancelRedirect = false;
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&isDone);
+
+    ASSERT_FALSE(didCancelRedirect);
+
+    isDone = false;
+    TestWebKitAPI::Util::run(&isDone);
+
+    ASSERT_TRUE(didCancelRedirect);
+
+    // Test 3: When another navigation begins while a client redirect is scheduled, -_webViewDidCancelClientRedirect:
+    // should be called.
+
+    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%2210000;URL=""
+
+    isDone = false;
+    didCancelRedirect = false;
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&isDone);
+
+    ASSERT_FALSE(didCancelRedirect);
+
+    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,Page4"]];
+    isDone = false;
+    [webView loadRequest:request];
+    TestWebKitAPI::Util::run(&isDone);
+
+    ASSERT_TRUE(didCancelRedirect);
+}
+
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to