| Differences between
and this patch
- a/Source/WebCore/ChangeLog +18 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2017-08-30  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 NOBODY (OOPS!).
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
1
2017-08-30  Youenn Fablet  <youenn@apple.com>
19
2017-08-30  Youenn Fablet  <youenn@apple.com>
2
20
3
        [Cache API] Support cache names persistency
21
        [Cache API] Support cache names persistency
- a/Source/WebCore/loader/FrameLoader.cpp -6 lines
Lines 2050-2061 void FrameLoader::clientRedirected(const URL& url, double seconds, double fireDa a/Source/WebCore/loader/FrameLoader.cpp_sec1
2050
    m_quickRedirectComing = (lockBackForwardList == LockBackForwardList::Yes || history().currentItemShouldBeReplaced()) && m_documentLoader && !m_isExecutingJavaScriptFormAction;
2050
    m_quickRedirectComing = (lockBackForwardList == LockBackForwardList::Yes || history().currentItemShouldBeReplaced()) && m_documentLoader && !m_isExecutingJavaScriptFormAction;
2051
}
2051
}
2052
2052
2053
void FrameLoader::performClientRedirect(FrameLoadRequest&& frameLoadRequest)
2054
{
2055
    changeLocation(WTFMove(frameLoadRequest));
2056
    m_client.dispatchDidPerformClientRedirect();
2057
}
2058
2059
bool FrameLoader::shouldReload(const URL& currentURL, const URL& destinationURL)
2053
bool FrameLoader::shouldReload(const URL& currentURL, const URL& destinationURL)
2060
{
2054
{
2061
    // This function implements the rule: "Don't reload if navigating by fragment within
2055
    // This function implements the rule: "Don't reload if navigating by fragment within
- a/Source/WebCore/loader/FrameLoader.h -1 lines
Lines 265-271 public: a/Source/WebCore/loader/FrameLoader.h_sec1
265
    bool allAncestorsAreComplete() const; // including this
265
    bool allAncestorsAreComplete() const; // including this
266
    void clientRedirected(const URL&, double delay, double fireDate, LockBackForwardList);
266
    void clientRedirected(const URL&, double delay, double fireDate, LockBackForwardList);
267
    void clientRedirectCancelledOrFinished(bool cancelWithLoadInProgress);
267
    void clientRedirectCancelledOrFinished(bool cancelWithLoadInProgress);
268
    void performClientRedirect(FrameLoadRequest&&);
269
268
270
    // FIXME: This is public because this asynchronous callback from the FrameLoaderClient
269
    // FIXME: This is public because this asynchronous callback from the FrameLoaderClient
271
    // uses the policy machinery (and therefore is called via the PolicyChecker).  Once we
270
    // uses the policy machinery (and therefore is called via the PolicyChecker).  Once we
- a/Source/WebCore/loader/FrameLoaderClient.h -1 lines
Lines 154-160 public: a/Source/WebCore/loader/FrameLoaderClient.h_sec1
154
    virtual void dispatchDidChangeProvisionalURL() { }
154
    virtual void dispatchDidChangeProvisionalURL() { }
155
    virtual void dispatchDidCancelClientRedirect() = 0;
155
    virtual void dispatchDidCancelClientRedirect() = 0;
156
    virtual void dispatchWillPerformClientRedirect(const URL&, double interval, double fireDate) = 0;
156
    virtual void dispatchWillPerformClientRedirect(const URL&, double interval, double fireDate) = 0;
157
    virtual void dispatchDidPerformClientRedirect() { }
158
    virtual void dispatchDidChangeMainDocument() { }
157
    virtual void dispatchDidChangeMainDocument() { }
159
    virtual void dispatchDidNavigateWithinPage() { }
158
    virtual void dispatchDidNavigateWithinPage() { }
160
    virtual void dispatchDidChangeLocationWithinPage() = 0;
159
    virtual void dispatchDidChangeLocationWithinPage() = 0;
- a/Source/WebCore/loader/NavigationScheduler.cpp -2 / +2 lines
Lines 185-191 public: a/Source/WebCore/loader/NavigationScheduler.cpp_sec1
185
        ResourceRequest resourceRequest { url(), referrer(), refresh ? ReloadIgnoringCacheData : UseProtocolCachePolicy };
185
        ResourceRequest resourceRequest { url(), referrer(), refresh ? ReloadIgnoringCacheData : UseProtocolCachePolicy };
186
        FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
186
        FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
187
187
188
        frame.loader().performClientRedirect(WTFMove(frameLoadRequest));
188
        frame.loader().changeLocation(WTFMove(frameLoadRequest));
189
    }
189
    }
190
};
190
};
191
191
Lines 201-207 public: a/Source/WebCore/loader/NavigationScheduler.cpp_sec2
201
        ResourceRequest resourceRequest { url(), referrer(), UseProtocolCachePolicy };
201
        ResourceRequest resourceRequest { url(), referrer(), UseProtocolCachePolicy };
202
        FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
202
        FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
203
203
204
        frame.loader().performClientRedirect(WTFMove(frameLoadRequest));
204
        frame.loader().changeLocation(WTFMove(frameLoadRequest));
205
    }
205
    }
206
};
206
};
207
207
- a/Source/WebKit/ChangeLog +34 lines
Lines 1-3 a/Source/WebKit/ChangeLog_sec1
1
2017-08-30  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 NOBODY (OOPS!).
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::didScheduleClientRedirect):
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::didScheduleClientRedirect):
24
        (WebKit::NavigationState::NavigationClient::didCancelClientRedirect):
25
        * UIProcess/WebPageProxy.cpp:
26
        (WebKit::WebPageProxy::didScheduleClientRedirectForFrame):
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
1
2017-08-30  Youenn Fablet  <youenn@apple.com>
35
2017-08-30  Youenn Fablet  <youenn@apple.com>
2
36
3
        [Cache API] Support cache names persistency
37
        [Cache API] Support cache names persistency
- a/Source/WebKit/UIProcess/API/APINavigationClient.h -1 / +2 lines
Lines 69-75 public: a/Source/WebKit/UIProcess/API/APINavigationClient.h_sec1
69
69
70
    virtual void didStartProvisionalNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
70
    virtual void didStartProvisionalNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
71
    virtual void didReceiveServerRedirectForProvisionalNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
71
    virtual void didReceiveServerRedirectForProvisionalNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
72
    virtual void didPerformClientRedirectForNavigation(WebKit::WebPageProxy&, Navigation*) { }
72
    virtual void didScheduleClientRedirect(WebKit::WebPageProxy&, const WTF::String&, double) { }
73
    virtual void didCancelClientRedirect(WebKit::WebPageProxy&) { }
73
    virtual void didFailProvisionalNavigationWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, Navigation*, const WebCore::ResourceError&, Object*) { }
74
    virtual void didFailProvisionalNavigationWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, Navigation*, const WebCore::ResourceError&, Object*) { }
74
    virtual void didFailProvisionalLoadInSubframeWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::SecurityOriginData&, Navigation*, const WebCore::ResourceError&, Object*) { }
75
    virtual void didFailProvisionalLoadInSubframeWithError(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::SecurityOriginData&, Navigation*, const WebCore::ResourceError&, Object*) { }
75
    virtual void didCommitNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
76
    virtual void didCommitNavigation(WebKit::WebPageProxy&, Navigation*, Object*) { }
- a/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h -1 / +2 lines
Lines 44-50 static const WKNavigationResponsePolicy _WKNavigationResponsePolicyBecomeDownloa a/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h_sec1
44
44
45
- (void)_webView:(WKWebView *)webView navigation:(WKNavigation *)navigation didFailProvisionalLoadInSubframe:(WKFrameInfo *)subframe withError:(NSError *)error;
45
- (void)_webView:(WKWebView *)webView navigation:(WKNavigation *)navigation didFailProvisionalLoadInSubframe:(WKFrameInfo *)subframe withError:(NSError *)error;
46
46
47
- (void)_webView:(WKWebView *)webView didPerformClientRedirectForNavigation:(WKNavigation *)navigation;
47
- (void)_webView:(WKWebView *)webView didScheduleClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)delay;
48
- (void)_webViewDidCancelClientRedirect:(WKWebView *)webView;
48
49
49
- (void)_webView:(WKWebView *)webView navigationDidFinishDocumentLoad:(WKNavigation *)navigation;
50
- (void)_webView:(WKWebView *)webView navigationDidFinishDocumentLoad:(WKNavigation *)navigation;
50
- (void)_webView:(WKWebView *)webView navigation:(WKNavigation *)navigation didSameDocumentNavigation:(_WKSameDocumentNavigationType)navigationType;
51
- (void)_webView:(WKWebView *)webView navigation:(WKNavigation *)navigation didSameDocumentNavigation:(_WKSameDocumentNavigationType)navigationType;
- a/Source/WebKit/UIProcess/Cocoa/NavigationState.h -2 / +4 lines
Lines 91-97 private: a/Source/WebKit/UIProcess/Cocoa/NavigationState.h_sec1
91
    private:
91
    private:
92
        void didStartProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
92
        void didStartProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
93
        void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
93
        void didReceiveServerRedirectForProvisionalNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
94
        void didPerformClientRedirectForNavigation(WebPageProxy&, API::Navigation*) override;
94
        void didScheduleClientRedirect(WebKit::WebPageProxy&, const WTF::String&, double) override;
95
        void didCancelClientRedirect(WebKit::WebPageProxy&) override;
95
        void didFailProvisionalNavigationWithError(WebPageProxy&, WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
96
        void didFailProvisionalNavigationWithError(WebPageProxy&, WebFrameProxy&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
96
        void didFailProvisionalLoadInSubframeWithError(WebPageProxy&, WebFrameProxy&, const WebCore::SecurityOriginData&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
97
        void didFailProvisionalLoadInSubframeWithError(WebPageProxy&, WebFrameProxy&, const WebCore::SecurityOriginData&, API::Navigation*, const WebCore::ResourceError&, API::Object*) override;
97
        void didCommitNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
98
        void didCommitNavigation(WebPageProxy&, API::Navigation*, API::Object*) override;
Lines 173-179 private: a/Source/WebKit/UIProcess/Cocoa/NavigationState.h_sec2
173
        bool webViewDidReceiveServerRedirectForProvisionalNavigation : 1;
174
        bool webViewDidReceiveServerRedirectForProvisionalNavigation : 1;
174
        bool webViewDidFailProvisionalNavigationWithError : 1;
175
        bool webViewDidFailProvisionalNavigationWithError : 1;
175
        bool webViewNavigationDidFailProvisionalLoadInSubframeWithError : 1;
176
        bool webViewNavigationDidFailProvisionalLoadInSubframeWithError : 1;
176
        bool webViewDidPerformClientRedirectForNavigation : 1;
177
        bool webViewDidScheduleClientRedirect : 1;
178
        bool webViewDidCancelClientRedirect : 1;
177
        bool webViewDidCommitNavigation : 1;
179
        bool webViewDidCommitNavigation : 1;
178
        bool webViewNavigationDidFinishDocumentLoad : 1;
180
        bool webViewNavigationDidFinishDocumentLoad : 1;
179
        bool webViewDidFinishNavigation : 1;
181
        bool webViewDidFinishNavigation : 1;
- a/Source/WebKit/UIProcess/Cocoa/NavigationState.mm -8 / +18 lines
Lines 150-156 void NavigationState::setNavigationDelegate(id <WKNavigationDelegate> delegate) a/Source/WebKit/UIProcess/Cocoa/NavigationState.mm_sec1
150
    m_navigationDelegateMethods.webViewDidFailNavigationWithError = [delegate respondsToSelector:@selector(webView:didFailNavigation:withError:)];
150
    m_navigationDelegateMethods.webViewDidFailNavigationWithError = [delegate respondsToSelector:@selector(webView:didFailNavigation:withError:)];
151
151
152
    m_navigationDelegateMethods.webViewNavigationDidFailProvisionalLoadInSubframeWithError = [delegate respondsToSelector:@selector(_webView:navigation:didFailProvisionalLoadInSubframe:withError:)];
152
    m_navigationDelegateMethods.webViewNavigationDidFailProvisionalLoadInSubframeWithError = [delegate respondsToSelector:@selector(_webView:navigation:didFailProvisionalLoadInSubframe:withError:)];
153
    m_navigationDelegateMethods.webViewDidPerformClientRedirectForNavigation = [delegate respondsToSelector:@selector(_webView:didPerformClientRedirectForNavigation:)];
153
    m_navigationDelegateMethods.webViewDidScheduleClientRedirect = [delegate respondsToSelector:@selector(_webView:didScheduleClientRedirectToURL:delay:)];
154
    m_navigationDelegateMethods.webViewDidCancelClientRedirect = [delegate respondsToSelector:@selector(_webViewDidCancelClientRedirect:)];
154
    m_navigationDelegateMethods.webViewNavigationDidFinishDocumentLoad = [delegate respondsToSelector:@selector(_webView:navigationDidFinishDocumentLoad:)];
155
    m_navigationDelegateMethods.webViewNavigationDidFinishDocumentLoad = [delegate respondsToSelector:@selector(_webView:navigationDidFinishDocumentLoad:)];
155
    m_navigationDelegateMethods.webViewNavigationDidSameDocumentNavigation = [delegate respondsToSelector:@selector(_webView:navigation:didSameDocumentNavigation:)];
156
    m_navigationDelegateMethods.webViewNavigationDidSameDocumentNavigation = [delegate respondsToSelector:@selector(_webView:navigation:didSameDocumentNavigation:)];
156
    m_navigationDelegateMethods.webViewRenderingProgressDidChange = [delegate respondsToSelector:@selector(_webView:renderingProgressDidChange:)];
157
    m_navigationDelegateMethods.webViewRenderingProgressDidChange = [delegate respondsToSelector:@selector(_webView:renderingProgressDidChange:)];
Lines 489-509 void NavigationState::NavigationClient::didReceiveServerRedirectForProvisionalNa a/Source/WebKit/UIProcess/Cocoa/NavigationState.mm_sec2
489
    [navigationDelegate webView:m_navigationState.m_webView didReceiveServerRedirectForProvisionalNavigation:wkNavigation];
490
    [navigationDelegate webView:m_navigationState.m_webView didReceiveServerRedirectForProvisionalNavigation:wkNavigation];
490
}
491
}
491
492
492
void NavigationState::NavigationClient::didPerformClientRedirectForNavigation(WebPageProxy& page, API::Navigation* navigation)
493
void NavigationState::NavigationClient::didScheduleClientRedirect(WebKit::WebPageProxy& page, const WTF::String& urlString, double delay)
493
{
494
{
494
    if (!m_navigationState.m_navigationDelegateMethods.webViewDidPerformClientRedirectForNavigation)
495
    if (!m_navigationState.m_navigationDelegateMethods.webViewDidScheduleClientRedirect)
495
        return;
496
        return;
496
497
497
    auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
498
    auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
498
    if (!navigationDelegate)
499
    if (!navigationDelegate)
499
        return;
500
        return;
500
501
501
    // FIXME: We should assert that navigation is not null here, but it's currently null for some navigations through the page cache.
502
    WebCore::URL url(WebCore::URL(), urlString);
502
    WKNavigation *wkNavigation = nil;
503
503
    if (navigation)
504
    [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate) _webView:m_navigationState.m_webView didScheduleClientRedirectToURL:url delay:delay];
504
        wkNavigation = wrapper(*navigation);
505
}
506
507
void 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;
505
515
506
    [(id <WKNavigationDelegatePrivate>)navigationDelegate _webView:m_navigationState.m_webView didPerformClientRedirectForNavigation:wkNavigation];
516
    [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate) _webViewDidCancelClientRedirect:m_navigationState.m_webView];
507
}
517
}
508
518
509
static RetainPtr<NSError> createErrorWithRecoveryAttempter(WKWebView *webView, WebFrameProxy& webFrameProxy, NSError *originalError)
519
static RetainPtr<NSError> createErrorWithRecoveryAttempter(WKWebView *webView, WebFrameProxy& webFrameProxy, NSError *originalError)
- a/Source/WebKit/UIProcess/WebPageProxy.cpp -6 / +14 lines
Lines 3208-3228 void WebPageProxy::didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t f a/Source/WebKit/UIProcess/WebPageProxy.cpp_sec1
3208
        m_loaderClient->didReceiveServerRedirectForProvisionalLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
3208
        m_loaderClient->didReceiveServerRedirectForProvisionalLoadForFrame(*this, *frame, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
3209
}
3209
}
3210
3210
3211
void WebPageProxy::didPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID)
3211
void WebPageProxy::didScheduleClientRedirectForFrame(uint64_t frameID, const String& url, double delay)
3212
{
3212
{
3213
    PageClientProtector protector(m_pageClient);
3213
    PageClientProtector protector(m_pageClient);
3214
3214
3215
    WebFrameProxy* frame = m_process->webFrame(frameID);
3215
    WebFrameProxy* frame = m_process->webFrame(frameID);
3216
    MESSAGE_CHECK(frame);
3216
    MESSAGE_CHECK(frame);
3217
3217
3218
    // FIXME: We should message check that navigationID is not zero here, but it's currently zero for some navigations through the page cache.
3218
    if (m_navigationClient) {
3219
    RefPtr<API::Navigation> navigation;
3219
        if (frame->isMainFrame())
3220
    if (frame->isMainFrame() && navigationID)
3220
            m_navigationClient->didScheduleClientRedirect(*this, url, delay);
3221
        navigation = &navigationState().navigation(navigationID);
3221
    }
3222
}
3223
3224
void WebPageProxy::didCancelClientRedirectForFrame(uint64_t frameID)
3225
{
3226
    PageClientProtector protector(m_pageClient);
3227
3228
    WebFrameProxy* frame = m_process->webFrame(frameID);
3229
    MESSAGE_CHECK(frame);
3222
3230
3223
    if (m_navigationClient) {
3231
    if (m_navigationClient) {
3224
        if (frame->isMainFrame())
3232
        if (frame->isMainFrame())
3225
            m_navigationClient->didPerformClientRedirectForNavigation(*this, navigation.get());
3233
            m_navigationClient->didCancelClientRedirect(*this);
3226
    }
3234
    }
3227
}
3235
}
3228
3236
- a/Source/WebKit/UIProcess/WebPageProxy.h -1 / +2 lines
Lines 1247-1253 private: a/Source/WebKit/UIProcess/WebPageProxy.h_sec1
1247
1247
1248
    void didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const String& unreachableURL, const UserData&);
1248
    void didStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String& url, const String& unreachableURL, const UserData&);
1249
    void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String&, const UserData&);
1249
    void didReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, const String&, const UserData&);
1250
    void didPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID);
1250
    void didScheduleClientRedirectForFrame(uint64_t frameID, const String& url, double delay);
1251
    void didCancelClientRedirectForFrame(uint64_t frameID);
1251
    void didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, const String& url);
1252
    void didChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, const String& url);
1252
    void didFailProvisionalLoadForFrame(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, const UserData&);
1253
    void didFailProvisionalLoadForFrame(uint64_t frameID, const WebCore::SecurityOriginData& frameSecurityOrigin, uint64_t navigationID, const String& provisionalURL, const WebCore::ResourceError&, const UserData&);
1253
    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&);
1254
    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&);
- a/Source/WebKit/UIProcess/WebPageProxy.messages.in -1 / +2 lines
Lines 118-124 messages -> WebPageProxy { a/Source/WebKit/UIProcess/WebPageProxy.messages.in_sec1
118
    # Frame load messages
118
    # Frame load messages
119
    DidStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, String unreachableURL, WebKit::UserData userData)
119
    DidStartProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, String unreachableURL, WebKit::UserData userData)
120
    DidReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, WebKit::UserData userData)
120
    DidReceiveServerRedirectForProvisionalLoadForFrame(uint64_t frameID, uint64_t navigationID, String url, WebKit::UserData userData)
121
    DidPerformClientRedirectForLoadForFrame(uint64_t frameID, uint64_t navigationID)
121
    DidScheduleClientRedirectForFrame(uint64_t frameID, String url, double delay)
122
    DidCancelClientRedirectForFrame(uint64_t frameID)
122
    DidChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, String url)
123
    DidChangeProvisionalURLForFrame(uint64_t frameID, uint64_t navigationID, String url)
123
    DidFailProvisionalLoadForFrame(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, uint64_t navigationID, String provisionalURL, WebCore::ResourceError error, WebKit::UserData userData)
124
    DidFailProvisionalLoadForFrame(uint64_t frameID, struct WebCore::SecurityOriginData frameSecurityOrigin, uint64_t navigationID, String provisionalURL, WebCore::ResourceError error, WebKit::UserData userData)
124
    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)
125
    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)
- a/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp -12 / +6 lines
Lines 289-306 void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad() a/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp_sec1
289
    webPage->send(Messages::WebPageProxy::DidReceiveServerRedirectForProvisionalLoadForFrame(m_frame->frameID(), documentLoader.navigationID(), url, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
289
    webPage->send(Messages::WebPageProxy::DidReceiveServerRedirectForProvisionalLoadForFrame(m_frame->frameID(), documentLoader.navigationID(), url, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
290
}
290
}
291
291
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
304
void WebFrameLoaderClient::dispatchDidChangeProvisionalURL()
292
void WebFrameLoaderClient::dispatchDidChangeProvisionalURL()
305
{
293
{
306
    WebPage* webPage = m_frame->page();
294
    WebPage* webPage = m_frame->page();
Lines 319-324 void WebFrameLoaderClient::dispatchDidCancelClientRedirect() a/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp_sec2
319
307
320
    // Notify the bundle client.
308
    // Notify the bundle client.
321
    webPage->injectedBundleLoaderClient().didCancelClientRedirectForFrame(*webPage, *m_frame);
309
    webPage->injectedBundleLoaderClient().didCancelClientRedirectForFrame(*webPage, *m_frame);
310
311
    // Notify the UIProcess.
312
    webPage->send(Messages::WebPageProxy::DidCancelClientRedirectForFrame(m_frame->frameID()));
322
}
313
}
323
314
324
void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const URL& url, double interval, double fireDate)
315
void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const URL& url, double interval, double fireDate)
Lines 329-334 void WebFrameLoaderClient::dispatchWillPerformClientRedirect(const URL& url, dou a/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp_sec3
329
320
330
    // Notify the bundle client.
321
    // Notify the bundle client.
331
    webPage->injectedBundleLoaderClient().willPerformClientRedirectForFrame(*webPage, *m_frame, url, interval, fireDate);
322
    webPage->injectedBundleLoaderClient().willPerformClientRedirectForFrame(*webPage, *m_frame, url, interval, fireDate);
323
324
    // Notify the UIProcess.
325
    webPage->send(Messages::WebPageProxy::DidScheduleClientRedirectForFrame(m_frame->frameID(), url.string(), interval));
332
}
326
}
333
327
334
void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
328
void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
- a/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h -1 lines
Lines 88-94 private: a/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h_sec1
88
88
89
    void dispatchDidDispatchOnloadEvents() final;
89
    void dispatchDidDispatchOnloadEvents() final;
90
    void dispatchDidReceiveServerRedirectForProvisionalLoad() final;
90
    void dispatchDidReceiveServerRedirectForProvisionalLoad() final;
91
    void dispatchDidPerformClientRedirect() final;
92
    void dispatchDidChangeProvisionalURL() final;
91
    void dispatchDidChangeProvisionalURL() final;
93
    void dispatchDidCancelClientRedirect() final;
92
    void dispatchDidCancelClientRedirect() final;
94
    void dispatchWillPerformClientRedirect(const WebCore::URL&, double interval, double fireDate) final;
93
    void dispatchWillPerformClientRedirect(const WebCore::URL&, double interval, double fireDate) final;
- a/Tools/ChangeLog +17 lines
Lines 1-3 a/Tools/ChangeLog_sec1
1
2017-08-30  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 NOBODY (OOPS!).
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:didScheduleClientRedirectToURL:delay:]):
14
        (-[ClientRedirectNavigationDelegate _webViewDidCancelClientRedirect:]):
15
        (-[ClientRedirectNavigationDelegate webView:didFinishNavigation:]):
16
        (TEST):
17
1
2017-08-30  Filip Pizlo  <fpizlo@apple.com>
18
2017-08-30  Filip Pizlo  <fpizlo@apple.com>
2
19
3
        Rename ArrayLang to WebGPU Shading Language, or WSL for short, pronounced "whistle"
20
        Rename ArrayLang to WebGPU Shading Language, or WSL for short, pronounced "whistle"
- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm -8 / +76 lines
Lines 37-42 a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm_sec1
37
static bool isDone;
37
static bool isDone;
38
static RetainPtr<WKNavigation> currentNavigation;
38
static RetainPtr<WKNavigation> currentNavigation;
39
static RetainPtr<NSURL> redirectURL;
39
static RetainPtr<NSURL> redirectURL;
40
static NSTimeInterval redirectDelay;
41
static bool didCancelRedirect;
40
42
41
@interface NavigationDelegate : NSObject <WKNavigationDelegate>
43
@interface NavigationDelegate : NSObject <WKNavigationDelegate>
42
@end
44
@end
Lines 188-227 TEST(WKNavigation, DecidePolicyForPageCacheNavigation) a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm_sec2
188
    ASSERT_TRUE([delegate decidedPolicyForBackForwardNavigation]);
190
    ASSERT_TRUE([delegate decidedPolicyForBackForwardNavigation]);
189
}
191
}
190
192
191
@interface DidPerformClientRedirectNavigationDelegate : NSObject<WKNavigationDelegatePrivate>
193
@interface ClientRedirectNavigationDelegate : NSObject<WKNavigationDelegatePrivate>
192
@end
194
@end
193
195
194
@implementation DidPerformClientRedirectNavigationDelegate
196
@implementation ClientRedirectNavigationDelegate
195
- (void)_webView:(WKWebView *)webView didPerformClientRedirectForNavigation:(WKNavigation *)navigation
197
- (void)_webView:(WKWebView *)webView didScheduleClientRedirectToURL:(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
196
{
207
{
197
    isDone = true;
208
    isDone = true;
198
    redirectURL = webView.URL;
199
}
209
}
200
@end
210
@end
201
211
202
TEST(WKNavigation, DidPerformClientRedirect)
212
TEST(WKNavigation, WebViewDidScheduleClientRedirect)
203
{
213
{
204
    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
214
    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
205
215
206
    RetainPtr<DidPerformClientRedirectNavigationDelegate> delegate = adoptNS([[DidPerformClientRedirectNavigationDelegate alloc] init]);
216
    auto delegate = adoptNS([[ClientRedirectNavigationDelegate alloc] init]);
207
    [webView setNavigationDelegate:delegate.get()];
217
    [webView setNavigationDelegate:delegate.get()];
208
218
209
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%220;URL=data:text/html,Page1%22%3E"]];
219
    auto request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cmeta%20http-equiv=%22refresh%22%20content=%22123;URL=data:text/html,Page1%22%3E"]];
210
220
211
    isDone = false;
221
    isDone = false;
212
    redirectURL = nil;
222
    redirectURL = nil;
223
    redirectDelay = 0;
213
    [webView loadRequest:request];
224
    [webView loadRequest:request];
214
    TestWebKitAPI::Util::run(&isDone);
225
    TestWebKitAPI::Util::run(&isDone);
215
226
227
    ASSERT_DOUBLE_EQ(redirectDelay, 123);
216
    ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page1");
228
    ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page1");
217
229
218
    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cscript%3Ewindow.location=%22data:text/html,Page2%22;%3C/script%3E"]];
230
    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,%3Cscript%3Ewindow.location=%22data:text/html,Page2%22;%3C/script%3E"]];
219
    isDone = false;
231
    isDone = false;
220
    redirectURL = nil;
232
    redirectURL = nil;
233
    redirectDelay = NSTimeIntervalSince1970; // Use any non-zero value, we will test that the delegate receives a delay of 0.
221
    [webView loadRequest:request];
234
    [webView loadRequest:request];
222
    TestWebKitAPI::Util::run(&isDone);
235
    TestWebKitAPI::Util::run(&isDone);
223
236
237
    ASSERT_DOUBLE_EQ(redirectDelay, 0);
224
    ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page2");
238
    ASSERT_STREQ(redirectURL.get().absoluteString.UTF8String, "data:text/html,Page2");
225
}
239
}
226
240
241
TEST(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
227
#endif
295
#endif

Return to Bug 176128