Title: [221619] branches/safari-604-branch

Diff

Modified: branches/safari-604-branch/Source/WebCore/ChangeLog (221618 => 221619)


--- branches/safari-604-branch/Source/WebCore/ChangeLog	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebCore/ChangeLog	2017-09-05 17:19:10 UTC (rev 221619)
@@ -1,3 +1,25 @@
+2017-09-05  Matthew Hanson  <matthew_han...@apple.com>
+
+        Cherry-pick r221444. rdar://problem/34215746
+
+    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-21  Jason Marcell  <jmarc...@apple.com>
 
         Cherry-pick r220940. rdar://problem/33994308

Modified: branches/safari-604-branch/Source/WebCore/loader/FrameLoader.cpp (221618 => 221619)


--- branches/safari-604-branch/Source/WebCore/loader/FrameLoader.cpp	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebCore/loader/FrameLoader.cpp	2017-09-05 17:19:10 UTC (rev 221619)
@@ -2049,12 +2049,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: branches/safari-604-branch/Source/WebCore/loader/FrameLoader.h (221618 => 221619)


--- branches/safari-604-branch/Source/WebCore/loader/FrameLoader.h	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebCore/loader/FrameLoader.h	2017-09-05 17:19:10 UTC (rev 221619)
@@ -263,7 +263,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: branches/safari-604-branch/Source/WebCore/loader/FrameLoaderClient.h (221618 => 221619)


--- branches/safari-604-branch/Source/WebCore/loader/FrameLoaderClient.h	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebCore/loader/FrameLoaderClient.h	2017-09-05 17:19:10 UTC (rev 221619)
@@ -151,7 +151,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: branches/safari-604-branch/Source/WebCore/loader/NavigationScheduler.cpp (221618 => 221619)


--- branches/safari-604-branch/Source/WebCore/loader/NavigationScheduler.cpp	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebCore/loader/NavigationScheduler.cpp	2017-09-05 17:19:10 UTC (rev 221619)
@@ -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: branches/safari-604-branch/Source/WebKit/ChangeLog (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/ChangeLog	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/ChangeLog	2017-09-05 17:19:10 UTC (rev 221619)
@@ -1,3 +1,41 @@
+2017-09-05  Matthew Hanson  <matthew_han...@apple.com>
+
+        Cherry-pick r221444. rdar://problem/34215746
+
+    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-28  Jason Marcell  <jmarc...@apple.com>
 
         Cherry-pick r221161. rdar://problem/34113784

Modified: branches/safari-604-branch/Source/WebKit/UIProcess/API/APINavigationClient.h (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/UIProcess/API/APINavigationClient.h	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/API/APINavigationClient.h	2017-09-05 17:19:10 UTC (rev 221619)
@@ -69,7 +69,8 @@
 
     virtual void didStartProvisionalNavigation(WebKit::WebPageProxy&, API::Navigation*, API::Object*) { }
     virtual void didReceiveServerRedirectForProvisionalNavigation(WebKit::WebPageProxy&, API::Navigation*, API::Object*) { }
-    virtual void didPerformClientRedirectForNavigation(WebKit::WebPageProxy&, API::Navigation*) { }
+    virtual void willPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String&, double) { }
+    virtual void didCancelClientRedirect(WebKit::WebPageProxy&) { }
     virtual void didFailProvisionalNavigationWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) { }
     virtual void didFailProvisionalLoadInSubframeWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::SecurityOriginData&, API::Navigation*, const WebCore::ResourceError&, API::Object*) { }
     virtual void didCommitNavigation(WebKit::WebPageProxy&, API::Navigation*, API::Object*) { }

Modified: branches/safari-604-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h	2017-09-05 17:19:10 UTC (rev 221619)
@@ -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: branches/safari-604-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2017-09-05 17:19:10 UTC (rev 221619)
@@ -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: branches/safari-604-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2017-09-05 17:19:10 UTC (rev 221619)
@@ -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: branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.cpp (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.cpp	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.cpp	2017-09-05 17:19:10 UTC (rev 221619)
@@ -3191,7 +3191,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);
 
@@ -3198,14 +3198,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: branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.h (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.h	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.h	2017-09-05 17:19:10 UTC (rev 221619)
@@ -1245,7 +1245,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: branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.messages.in (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.messages.in	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/WebPageProxy.messages.in	2017-09-05 17:19:10 UTC (rev 221619)
@@ -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: branches/safari-604-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2017-09-05 17:19:10 UTC (rev 221619)
@@ -290,18 +290,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();
@@ -320,6 +308,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)
@@ -330,6 +321,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: branches/safari-604-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h (221618 => 221619)


--- branches/safari-604-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2017-09-05 17:19:10 UTC (rev 221619)
@@ -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: branches/safari-604-branch/Tools/ChangeLog (221618 => 221619)


--- branches/safari-604-branch/Tools/ChangeLog	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Tools/ChangeLog	2017-09-05 17:19:10 UTC (rev 221619)
@@ -1,3 +1,24 @@
+2017-09-05  Matthew Hanson  <matthew_han...@apple.com>
+
+        Cherry-pick r221444. rdar://problem/34215746
+
+    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-30  Jason Marcell  <jmarc...@apple.com>
 
         Cherry-pick r220296. rdar://problem/34177414

Modified: branches/safari-604-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Navigation.mm (221618 => 221619)


--- branches/safari-604-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Navigation.mm	2017-09-05 16:44:53 UTC (rev 221618)
+++ branches/safari-604-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Navigation.mm	2017-09-05 17:19:10 UTC (rev 221619)
@@ -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