diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog index c6e4ddf593b3..6e3ee47d04c4 100644 --- a/Source/WebKit/ChangeLog +++ b/Source/WebKit/ChangeLog @@ -1,3 +1,35 @@ +2017-10-05 Alex Christensen + + Add ObjC equivalent of WKPageNavigationClient.didChangeBackForwardList + https://bugs.webkit.org/show_bug.cgi?id=177966 + + + Reviewed by Tim Horton. + + * UIProcess/API/APINavigationClient.h: + (API::NavigationClient::didChangeBackForwardList): + * UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h: + * UIProcess/Cocoa/NavigationState.h: + * UIProcess/Cocoa/NavigationState.mm: + (WebKit::NavigationState::setNavigationDelegate): + (WebKit::NavigationState::NavigationClient::didFailToInitializePlugIn): + (WebKit::NavigationState::NavigationClient::didChangeBackForwardList): + (WebKit::NavigationState::NavigationClient::willPerformClientRedirect): + (WebKit::NavigationState::NavigationClient::didCancelClientRedirect): + (WebKit::NavigationState::NavigationClient::renderingProgressDidChange): + (WebKit::NavigationState::NavigationClient::canAuthenticateAgainstProtectionSpace): + (WebKit::NavigationState::NavigationClient::processDidTerminate): + (WebKit::NavigationState::NavigationClient::processDidBecomeResponsive): + (WebKit::NavigationState::NavigationClient::processDidBecomeUnresponsive): + (WebKit::NavigationState::NavigationClient::webCryptoMasterKey): + (WebKit::NavigationState::NavigationClient::didFinishLoadForQuickLookDocumentInMainFrame): + (WebKit::NavigationState::HistoryClient::didNavigateWithNavigationData): + (WebKit::NavigationState::HistoryClient::didPerformClientRedirect): + (WebKit::NavigationState::HistoryClient::didPerformServerRedirect): + (WebKit::NavigationState::HistoryClient::didUpdateHistoryTitle): + * UIProcess/WebPageProxy.cpp: + (WebKit::WebPageProxy::didChangeBackForwardList): + 2017-10-05 Alex Christensen Add ObjC SPI with userInfo corresponding to WKPageNavigationClient's decidePolicyForNavigationAction, didStartProvisionalNavigation, and didFailNavigation diff --git a/Source/WebKit/UIProcess/API/APINavigationClient.h b/Source/WebKit/UIProcess/API/APINavigationClient.h index 98ba68d36036..906d26a1dff2 100644 --- a/Source/WebKit/UIProcess/API/APINavigationClient.h +++ b/Source/WebKit/UIProcess/API/APINavigationClient.h @@ -127,6 +127,7 @@ class NavigationClient { virtual void willEndNavigationGesture(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { } virtual void didEndNavigationGesture(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { } virtual void didRemoveNavigationGestureSnapshot(WebKit::WebPageProxy&) { } + virtual bool didChangeBackForwardList(WebKit::WebPageProxy&, WebKit::WebBackForwardListItem*, const Vector>&) { return false; } }; } // namespace API diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h b/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h index 2040eac8c431..4066d46d93cd 100644 --- a/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h +++ b/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h @@ -92,6 +92,7 @@ static const WKNavigationResponsePolicy _WKNavigationResponsePolicyBecomeDownloa - (void)_webView:(WKWebView *)webView resolveWebGLLoadPolicyForURL:(NSURL *)url decisionHandler:(void (^)(_WKWebGLLoadPolicy))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA)); - (void)_webView:(WKWebView *)webView willGoToBackForwardListItem:(WKBackForwardListItem *)item inPageCache:(BOOL)inPageCache WK_API_AVAILABLE(macosx(WK_MAC_TBA)); - (void)_webView:(WKWebView *)webView didFailToInitializePlugInWithInfo:(NSDictionary *)info WK_API_AVAILABLE(macosx(WK_MAC_TBA)); +- (void)_webView:(WKWebView *)webView backForwardListItemAdded:(WKBackForwardListItem *)itemAdded removed:(NSArray *)itemsRemoved WK_API_AVAILABLE(macosx(WK_MAC_TBA)); #endif @end diff --git a/Source/WebKit/UIProcess/Cocoa/NavigationState.h b/Source/WebKit/UIProcess/Cocoa/NavigationState.h index 34db5b4129e8..6dd29caef0bc 100644 --- a/Source/WebKit/UIProcess/Cocoa/NavigationState.h +++ b/Source/WebKit/UIProcess/Cocoa/NavigationState.h @@ -120,7 +120,8 @@ class NavigationState final : private PageLoadState::Observer { void webGLLoadPolicy(WebPageProxy&, const WebCore::URL&, WTF::Function&& completionHandler) const final; void resolveWebGLLoadPolicy(WebPageProxy&, const WebCore::URL&, WTF::Function&& completionHandler) const final; bool willGoToBackForwardListItem(WebPageProxy&, WebBackForwardListItem&, bool inPageCache, API::Object*) final; - bool didFailToInitializePlugIn(WebKit::WebPageProxy&, API::Dictionary&) final; + bool didFailToInitializePlugIn(WebPageProxy&, API::Dictionary&) final; + bool didChangeBackForwardList(WebPageProxy&, WebBackForwardListItem*, const Vector>&) final; #endif void contentRuleListNotification(WebPageProxy&, WebCore::URL&&, Vector&&, Vector&&) final; @@ -217,6 +218,7 @@ class NavigationState final : private PageLoadState::Observer { #if PLATFORM(MAC) bool webViewWebGLLoadPolicyForURL : 1; bool webViewResolveWebGLLoadPolicyForURL : 1; + bool webViewBackForwardListItemAddedRemoved : 1; bool webViewDidFailToInitializePlugInWithInfo : 1; bool webViewWillGoToBackForwardListItemInPageCache : 1; #endif diff --git a/Source/WebKit/UIProcess/Cocoa/NavigationState.mm b/Source/WebKit/UIProcess/Cocoa/NavigationState.mm index b5543d65a77b..572e0ec9a63a 100644 --- a/Source/WebKit/UIProcess/Cocoa/NavigationState.mm +++ b/Source/WebKit/UIProcess/Cocoa/NavigationState.mm @@ -183,6 +183,7 @@ m_navigationDelegateMethods.webViewResolveWebGLLoadPolicyForURL = [delegate respondsToSelector:@selector(_webView:resolveWebGLLoadPolicyForURL:decisionHandler:)]; m_navigationDelegateMethods.webViewWillGoToBackForwardListItemInPageCache = [delegate respondsToSelector:@selector(_webView:willGoToBackForwardListItem:inPageCache:)]; m_navigationDelegateMethods.webViewDidFailToInitializePlugInWithInfo = [delegate respondsToSelector:@selector(_webView:didFailToInitializePlugInWithInfo:)]; + m_navigationDelegateMethods.webViewBackForwardListItemAddedRemoved = [delegate respondsToSelector:@selector(_webView:backForwardListItemAdded:removed:)]; #endif } @@ -297,7 +298,7 @@ } #if PLATFORM(MAC) -bool NavigationState::NavigationClient::didFailToInitializePlugIn(WebKit::WebPageProxy&, API::Dictionary& info) +bool NavigationState::NavigationClient::didFailToInitializePlugIn(WebPageProxy&, API::Dictionary& info) { if (!m_navigationState.m_navigationDelegateMethods.webViewDidFailToInitializePlugInWithInfo) return false; @@ -359,6 +360,25 @@ }).get()]; } +bool NavigationState::NavigationClient::didChangeBackForwardList(WebPageProxy&, WebBackForwardListItem* added, const Vector>& removed) +{ + if (!m_navigationState.m_navigationDelegateMethods.webViewBackForwardListItemAddedRemoved) + return false; + + auto navigationDelegate = m_navigationState.m_navigationDelegate.get(); + if (!navigationDelegate) + return false; + + NSMutableArray *removedItems = nil; + if (removed.size()) { + removedItems = [[[NSMutableArray alloc] initWithCapacity:removed.size()] autorelease]; + for (auto& removedItem : removed) + [removedItems addObject:wrapper(removedItem.get())]; + } + [(id )navigationDelegate _webView:m_navigationState.m_webView backForwardListItemAdded:added ? wrapper(*added) : nil removed:removedItems]; + return true; +} + bool NavigationState::NavigationClient::willGoToBackForwardListItem(WebPageProxy&, WebBackForwardListItem& item, bool inPageCache, API::Object*) { if (!m_navigationState.m_navigationDelegateMethods.webViewWillGoToBackForwardListItemInPageCache) @@ -606,7 +626,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [navigationDelegate webView:m_navigationState.m_webView didReceiveServerRedirectForProvisionalNavigation:wkNavigation]; } -void NavigationState::NavigationClient::willPerformClientRedirect(WebKit::WebPageProxy& page, const WTF::String& urlString, double delay) +void NavigationState::NavigationClient::willPerformClientRedirect(WebPageProxy& page, const WTF::String& urlString, double delay) { if (!m_navigationState.m_navigationDelegateMethods.webViewWillPerformClientRedirect) return; @@ -620,7 +640,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [static_cast>(navigationDelegate) _webView:m_navigationState.m_webView willPerformClientRedirectToURL:url delay:delay]; } -void NavigationState::NavigationClient::didCancelClientRedirect(WebKit::WebPageProxy& page) +void NavigationState::NavigationClient::didCancelClientRedirect(WebPageProxy& page) { if (!m_navigationState.m_navigationDelegateMethods.webViewDidCancelClientRedirect) return; @@ -775,7 +795,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [static_cast>(navigationDelegate.get()) _webView:m_navigationState.m_webView navigation:wkNavigation didSameDocumentNavigation:toWKSameDocumentNavigationType(navigationType)]; } -void NavigationState::NavigationClient::renderingProgressDidChange(WebKit::WebPageProxy&, WebCore::LayoutMilestones layoutMilestones) +void NavigationState::NavigationClient::renderingProgressDidChange(WebPageProxy&, WebCore::LayoutMilestones layoutMilestones) { if (!m_navigationState.m_navigationDelegateMethods.webViewRenderingProgressDidChange) return; @@ -787,7 +807,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [static_cast>(navigationDelegate.get()) _webView:m_navigationState.m_webView renderingProgressDidChange:renderingProgressEvents(layoutMilestones)]; } -bool NavigationState::NavigationClient::canAuthenticateAgainstProtectionSpace(WebKit::WebPageProxy&, WebKit::WebProtectionSpace* protectionSpace) +bool NavigationState::NavigationClient::canAuthenticateAgainstProtectionSpace(WebPageProxy&, WebProtectionSpace* protectionSpace) { if (m_navigationState.m_navigationDelegateMethods.webViewDidReceiveAuthenticationChallengeCompletionHandler) return true; @@ -859,7 +879,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [static_cast>(navigationDelegate.get()) _webView:m_navigationState.m_webView didReceiveAuthenticationChallenge:wrapper(*authenticationChallenge)]; } -void NavigationState::NavigationClient::processDidTerminate(WebKit::WebPageProxy& page, WebKit::ProcessTerminationReason) +void NavigationState::NavigationClient::processDidTerminate(WebPageProxy& page, ProcessTerminationReason) { if (!m_navigationState.m_navigationDelegateMethods.webViewWebContentProcessDidTerminate && !m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidCrash) return; @@ -878,7 +898,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [static_cast>(navigationDelegate.get()) _webViewWebProcessDidCrash:m_navigationState.m_webView]; } -void NavigationState::NavigationClient::processDidBecomeResponsive(WebKit::WebPageProxy& page) +void NavigationState::NavigationClient::processDidBecomeResponsive(WebPageProxy& page) { if (!m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidBecomeResponsive) return; @@ -890,7 +910,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [static_cast>(navigationDelegate.get()) _webViewWebProcessDidBecomeResponsive:m_navigationState.m_webView]; } -void NavigationState::NavigationClient::processDidBecomeUnresponsive(WebKit::WebPageProxy& page) +void NavigationState::NavigationClient::processDidBecomeUnresponsive(WebPageProxy& page) { if (!m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidBecomeUnresponsive) return; @@ -902,7 +922,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [static_cast>(navigationDelegate.get()) _webViewWebProcessDidBecomeUnresponsive:m_navigationState.m_webView]; } -RefPtr NavigationState::NavigationClient::webCryptoMasterKey(WebKit::WebPageProxy&) +RefPtr NavigationState::NavigationClient::webCryptoMasterKey(WebPageProxy&) { if (!m_navigationState.m_navigationDelegateMethods.webCryptoMasterKeyForWebView) { Vector masterKey; @@ -936,7 +956,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [static_cast>(navigationDelegate.get()) _webView:m_navigationState.m_webView didStartLoadForQuickLookDocumentInMainFrameWithFileName:fileName uti:uti]; } -void NavigationState::NavigationClient::didFinishLoadForQuickLookDocumentInMainFrame(const WebKit::QuickLookDocumentData& data) +void NavigationState::NavigationClient::didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData& data) { if (!m_navigationState.m_navigationDelegateMethods.webViewDidFinishLoadForQuickLookDocumentInMainFrame) return; @@ -960,7 +980,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S { } -void NavigationState::HistoryClient::didNavigateWithNavigationData(WebKit::WebPageProxy&, const WebKit::WebNavigationDataStore& navigationDataStore) +void NavigationState::HistoryClient::didNavigateWithNavigationData(WebPageProxy&, const WebNavigationDataStore& navigationDataStore) { if (!m_navigationState.m_historyDelegateMethods.webViewDidNavigateWithNavigationData) return; @@ -972,7 +992,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [historyDelegate _webView:m_navigationState.m_webView didNavigateWithNavigationData:wrapper(API::NavigationData::create(navigationDataStore))]; } -void NavigationState::HistoryClient::didPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String& sourceURL, const WTF::String& destinationURL) +void NavigationState::HistoryClient::didPerformClientRedirect(WebPageProxy&, const WTF::String& sourceURL, const WTF::String& destinationURL) { if (!m_navigationState.m_historyDelegateMethods.webViewDidPerformClientRedirectFromURLToURL) return; @@ -984,7 +1004,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [historyDelegate _webView:m_navigationState.m_webView didPerformClientRedirectFromURL:[NSURL _web_URLWithWTFString:sourceURL] toURL:[NSURL _web_URLWithWTFString:destinationURL]]; } -void NavigationState::HistoryClient::didPerformServerRedirect(WebKit::WebPageProxy&, const WTF::String& sourceURL, const WTF::String& destinationURL) +void NavigationState::HistoryClient::didPerformServerRedirect(WebPageProxy&, const WTF::String& sourceURL, const WTF::String& destinationURL) { if (!m_navigationState.m_historyDelegateMethods.webViewDidPerformServerRedirectFromURLToURL) return; @@ -996,7 +1016,7 @@ static void tryAppLink(RefPtr&& navigationAction, const S [historyDelegate _webView:m_navigationState.m_webView didPerformServerRedirectFromURL:[NSURL _web_URLWithWTFString:sourceURL] toURL:[NSURL _web_URLWithWTFString:destinationURL]]; } -void NavigationState::HistoryClient::didUpdateHistoryTitle(WebKit::WebPageProxy&, const WTF::String& title, const WTF::String& url) +void NavigationState::HistoryClient::didUpdateHistoryTitle(WebPageProxy&, const WTF::String& title, const WTF::String& url) { if (!m_navigationState.m_historyDelegateMethods.webViewDidUpdateHistoryTitleForURL) return; diff --git a/Source/WebKit/UIProcess/WebPageProxy.cpp b/Source/WebKit/UIProcess/WebPageProxy.cpp index b8461b8d3c4c..bc1f36da8e63 100644 --- a/Source/WebKit/UIProcess/WebPageProxy.cpp +++ b/Source/WebKit/UIProcess/WebPageProxy.cpp @@ -1196,7 +1196,8 @@ void WebPageProxy::didChangeBackForwardList(WebBackForwardListItem* added, Vecto { PageClientProtector protector(m_pageClient); - m_loaderClient->didChangeBackForwardList(*this, added, WTFMove(removed)); + if (!m_navigationClient || !m_navigationClient->didChangeBackForwardList(*this, added, removed)) + m_loaderClient->didChangeBackForwardList(*this, added, WTFMove(removed)); auto transaction = m_pageLoadState.transaction(); diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 3539e7847298..5d9cf20d6df9 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,16 @@ +2017-10-05 Alex Christensen + + Add ObjC equivalent of WKPageNavigationClient.didChangeBackForwardList + https://bugs.webkit.org/show_bug.cgi?id=177966 + + + Reviewed by Tim Horton. + + * TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm: + (-[ListItemDelegate _webView:backForwardListItemAdded:removed:]): + (-[ListItemDelegate webView:didFinishNavigation:]): + (TEST): + 2017-10-04 Megan Gardner check-webkit-style erroneously requires a space between the carrot and brace in obj-c blocks. diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm index 798674218943..ae19a9c1e2cd 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm @@ -25,6 +25,7 @@ #include "config.h" +#import #import #import #import @@ -328,6 +329,61 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat TestWebKitAPI::Util::run(&isDone); } +RetainPtr firstItem; +RetainPtr secondItem; + +@interface ListItemDelegate : NSObject +@end +@implementation ListItemDelegate +- (void)_webView:(WKWebView *)webView backForwardListItemAdded:(WKBackForwardListItem *)itemAdded removed:(NSArray *)itemsRemoved +{ + NSString *firstURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"].absoluteString; + NSString *secondURL = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"].absoluteString; + + if (!firstItem) { + EXPECT_NULL(firstItem); + EXPECT_NULL(secondItem); + EXPECT_NULL(itemsRemoved); + EXPECT_NOT_NULL(itemAdded); + EXPECT_STREQ(firstURL.UTF8String, itemAdded.URL.absoluteString.UTF8String); + firstItem = itemAdded; + } else if (!secondItem) { + EXPECT_NOT_NULL(firstItem); + EXPECT_NULL(secondItem); + EXPECT_NULL(itemsRemoved); + EXPECT_NOT_NULL(itemAdded); + EXPECT_STREQ(secondURL.UTF8String, itemAdded.URL.absoluteString.UTF8String); + secondItem = itemAdded; + } else { + EXPECT_NOT_NULL(firstItem); + EXPECT_NOT_NULL(secondItem); + EXPECT_NOT_NULL(itemsRemoved); + EXPECT_NULL(itemAdded); + EXPECT_EQ([itemsRemoved count], 2u); + EXPECT_STREQ(firstURL.UTF8String, [itemsRemoved objectAtIndex:0].URL.absoluteString.UTF8String); + EXPECT_STREQ(secondURL.UTF8String, [itemsRemoved objectAtIndex:1].URL.absoluteString.UTF8String); + isDone = true; + } +} +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation +{ + navigationComplete = true; +} +@end + +TEST(WKNavigation, ListItemAddedRemoved) +{ + auto webView = adoptNS([[WKWebView alloc] init]); + auto delegate = adoptNS([[ListItemDelegate alloc] init]); + [webView setNavigationDelegate:delegate.get()]; + [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]]; + TestWebKitAPI::Util::run(&navigationComplete); + navigationComplete = false; + [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]]; + TestWebKitAPI::Util::run(&navigationComplete); + [[webView backForwardList] _removeAllItems]; + TestWebKitAPI::Util::run(&isDone); +} #endif // PLATFORM(MAC) #endif // WK_API_ENABLED