Changeset 222944 in webkit


Ignore:
Timestamp:
Oct 5, 2017 4:18:36 PM (7 years ago)
Author:
achristensen@apple.com
Message:

Add ObjC equivalent of WKPageNavigationClient.didChangeBackForwardList
https://bugs.webkit.org/show_bug.cgi?id=177966
<rdar://problem/22387135>

Reviewed by Tim Horton.

Source/WebKit:

  • 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):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm:

(-[ListItemDelegate _webView:backForwardListItemAdded:removed:]):
(-[ListItemDelegate webView:didFinishNavigation:]):
(TEST):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r222942 r222944  
     12017-10-05  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add ObjC equivalent of WKPageNavigationClient.didChangeBackForwardList
     4        https://bugs.webkit.org/show_bug.cgi?id=177966
     5        <rdar://problem/22387135>
     6
     7        Reviewed by Tim Horton.
     8
     9        * UIProcess/API/APINavigationClient.h:
     10        (API::NavigationClient::didChangeBackForwardList):
     11        * UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h:
     12        * UIProcess/Cocoa/NavigationState.h:
     13        * UIProcess/Cocoa/NavigationState.mm:
     14        (WebKit::NavigationState::setNavigationDelegate):
     15        (WebKit::NavigationState::NavigationClient::didFailToInitializePlugIn):
     16        (WebKit::NavigationState::NavigationClient::didChangeBackForwardList):
     17        (WebKit::NavigationState::NavigationClient::willPerformClientRedirect):
     18        (WebKit::NavigationState::NavigationClient::didCancelClientRedirect):
     19        (WebKit::NavigationState::NavigationClient::renderingProgressDidChange):
     20        (WebKit::NavigationState::NavigationClient::canAuthenticateAgainstProtectionSpace):
     21        (WebKit::NavigationState::NavigationClient::processDidTerminate):
     22        (WebKit::NavigationState::NavigationClient::processDidBecomeResponsive):
     23        (WebKit::NavigationState::NavigationClient::processDidBecomeUnresponsive):
     24        (WebKit::NavigationState::NavigationClient::webCryptoMasterKey):
     25        (WebKit::NavigationState::NavigationClient::didFinishLoadForQuickLookDocumentInMainFrame):
     26        (WebKit::NavigationState::HistoryClient::didNavigateWithNavigationData):
     27        (WebKit::NavigationState::HistoryClient::didPerformClientRedirect):
     28        (WebKit::NavigationState::HistoryClient::didPerformServerRedirect):
     29        (WebKit::NavigationState::HistoryClient::didUpdateHistoryTitle):
     30        * UIProcess/WebPageProxy.cpp:
     31        (WebKit::WebPageProxy::didChangeBackForwardList):
     32
    1332017-10-05  Alex Christensen  <achristensen@webkit.org>
    234
  • trunk/Source/WebKit/UIProcess/API/APINavigationClient.h

    r222802 r222944  
    128128    virtual void didEndNavigationGesture(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { }
    129129    virtual void didRemoveNavigationGestureSnapshot(WebKit::WebPageProxy&) { }
     130    virtual bool didChangeBackForwardList(WebKit::WebPageProxy&, WebKit::WebBackForwardListItem*, const Vector<Ref<WebKit::WebBackForwardListItem>>&) { return false; }
    130131};
    131132
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h

    r222942 r222944  
    9393- (void)_webView:(WKWebView *)webView willGoToBackForwardListItem:(WKBackForwardListItem *)item inPageCache:(BOOL)inPageCache WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    9494- (void)_webView:(WKWebView *)webView didFailToInitializePlugInWithInfo:(NSDictionary *)info WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     95- (void)_webView:(WKWebView *)webView backForwardListItemAdded:(WKBackForwardListItem *)itemAdded removed:(NSArray<WKBackForwardListItem *> *)itemsRemoved WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    9596#endif
    9697
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h

    r222942 r222944  
    121121        void resolveWebGLLoadPolicy(WebPageProxy&, const WebCore::URL&, WTF::Function<void(WebCore::WebGLLoadPolicy)>&& completionHandler) const final;
    122122        bool willGoToBackForwardListItem(WebPageProxy&, WebBackForwardListItem&, bool inPageCache, API::Object*) final;
    123         bool didFailToInitializePlugIn(WebKit::WebPageProxy&, API::Dictionary&) final;
     123        bool didFailToInitializePlugIn(WebPageProxy&, API::Dictionary&) final;
     124        bool didChangeBackForwardList(WebPageProxy&, WebBackForwardListItem*, const Vector<Ref<WebBackForwardListItem>>&) final;
    124125#endif
    125126
     
    218219        bool webViewWebGLLoadPolicyForURL : 1;
    219220        bool webViewResolveWebGLLoadPolicyForURL : 1;
     221        bool webViewBackForwardListItemAddedRemoved : 1;
    220222        bool webViewDidFailToInitializePlugInWithInfo : 1;
    221223        bool webViewWillGoToBackForwardListItemInPageCache : 1;
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r222942 r222944  
    184184    m_navigationDelegateMethods.webViewWillGoToBackForwardListItemInPageCache = [delegate respondsToSelector:@selector(_webView:willGoToBackForwardListItem:inPageCache:)];
    185185    m_navigationDelegateMethods.webViewDidFailToInitializePlugInWithInfo = [delegate respondsToSelector:@selector(_webView:didFailToInitializePlugInWithInfo:)];
     186    m_navigationDelegateMethods.webViewBackForwardListItemAddedRemoved = [delegate respondsToSelector:@selector(_webView:backForwardListItemAdded:removed:)];
    186187#endif
    187188}
     
    298299
    299300#if PLATFORM(MAC)
    300 bool NavigationState::NavigationClient::didFailToInitializePlugIn(WebKit::WebPageProxy&, API::Dictionary& info)
     301bool NavigationState::NavigationClient::didFailToInitializePlugIn(WebPageProxy&, API::Dictionary& info)
    301302{
    302303    if (!m_navigationState.m_navigationDelegateMethods.webViewDidFailToInitializePlugInWithInfo)
     
    358359        completionHandler(toWebCoreWebGLLoadPolicy(policy));
    359360    }).get()];
     361}
     362
     363bool NavigationState::NavigationClient::didChangeBackForwardList(WebPageProxy&, WebBackForwardListItem* added, const Vector<Ref<WebBackForwardListItem>>& removed)
     364{
     365    if (!m_navigationState.m_navigationDelegateMethods.webViewBackForwardListItemAddedRemoved)
     366        return false;
     367
     368    auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
     369    if (!navigationDelegate)
     370        return false;
     371
     372    NSMutableArray<WKBackForwardListItem *> *removedItems = nil;
     373    if (removed.size()) {
     374        removedItems = [[[NSMutableArray alloc] initWithCapacity:removed.size()] autorelease];
     375        for (auto& removedItem : removed)
     376            [removedItems addObject:wrapper(removedItem.get())];
     377    }
     378    [(id <WKNavigationDelegatePrivate>)navigationDelegate _webView:m_navigationState.m_webView backForwardListItemAdded:added ? wrapper(*added) : nil removed:removedItems];
     379    return true;
    360380}
    361381
     
    607627}
    608628
    609 void NavigationState::NavigationClient::willPerformClientRedirect(WebKit::WebPageProxy& page, const WTF::String& urlString, double delay)
     629void NavigationState::NavigationClient::willPerformClientRedirect(WebPageProxy& page, const WTF::String& urlString, double delay)
    610630{
    611631    if (!m_navigationState.m_navigationDelegateMethods.webViewWillPerformClientRedirect)
     
    621641}
    622642
    623 void NavigationState::NavigationClient::didCancelClientRedirect(WebKit::WebPageProxy& page)
     643void NavigationState::NavigationClient::didCancelClientRedirect(WebPageProxy& page)
    624644{
    625645    if (!m_navigationState.m_navigationDelegateMethods.webViewDidCancelClientRedirect)
     
    776796}
    777797
    778 void NavigationState::NavigationClient::renderingProgressDidChange(WebKit::WebPageProxy&, WebCore::LayoutMilestones layoutMilestones)
     798void NavigationState::NavigationClient::renderingProgressDidChange(WebPageProxy&, WebCore::LayoutMilestones layoutMilestones)
    779799{
    780800    if (!m_navigationState.m_navigationDelegateMethods.webViewRenderingProgressDidChange)
     
    788808}
    789809
    790 bool NavigationState::NavigationClient::canAuthenticateAgainstProtectionSpace(WebKit::WebPageProxy&, WebKit::WebProtectionSpace* protectionSpace)
     810bool NavigationState::NavigationClient::canAuthenticateAgainstProtectionSpace(WebPageProxy&, WebProtectionSpace* protectionSpace)
    791811{
    792812    if (m_navigationState.m_navigationDelegateMethods.webViewDidReceiveAuthenticationChallengeCompletionHandler)
     
    860880}
    861881
    862 void NavigationState::NavigationClient::processDidTerminate(WebKit::WebPageProxy& page, WebKit::ProcessTerminationReason)
     882void NavigationState::NavigationClient::processDidTerminate(WebPageProxy& page, ProcessTerminationReason)
    863883{
    864884    if (!m_navigationState.m_navigationDelegateMethods.webViewWebContentProcessDidTerminate && !m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidCrash)
     
    879899}
    880900
    881 void NavigationState::NavigationClient::processDidBecomeResponsive(WebKit::WebPageProxy& page)
     901void NavigationState::NavigationClient::processDidBecomeResponsive(WebPageProxy& page)
    882902{
    883903    if (!m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidBecomeResponsive)
     
    891911}
    892912
    893 void NavigationState::NavigationClient::processDidBecomeUnresponsive(WebKit::WebPageProxy& page)
     913void NavigationState::NavigationClient::processDidBecomeUnresponsive(WebPageProxy& page)
    894914{
    895915    if (!m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidBecomeUnresponsive)
     
    903923}
    904924
    905 RefPtr<API::Data> NavigationState::NavigationClient::webCryptoMasterKey(WebKit::WebPageProxy&)
     925RefPtr<API::Data> NavigationState::NavigationClient::webCryptoMasterKey(WebPageProxy&)
    906926{
    907927    if (!m_navigationState.m_navigationDelegateMethods.webCryptoMasterKeyForWebView) {
     
    937957}
    938958
    939 void NavigationState::NavigationClient::didFinishLoadForQuickLookDocumentInMainFrame(const WebKit::QuickLookDocumentData& data)
     959void NavigationState::NavigationClient::didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData& data)
    940960{
    941961    if (!m_navigationState.m_navigationDelegateMethods.webViewDidFinishLoadForQuickLookDocumentInMainFrame)
     
    961981}
    962982
    963 void NavigationState::HistoryClient::didNavigateWithNavigationData(WebKit::WebPageProxy&, const WebKit::WebNavigationDataStore& navigationDataStore)
     983void NavigationState::HistoryClient::didNavigateWithNavigationData(WebPageProxy&, const WebNavigationDataStore& navigationDataStore)
    964984{
    965985    if (!m_navigationState.m_historyDelegateMethods.webViewDidNavigateWithNavigationData)
     
    973993}
    974994
    975 void NavigationState::HistoryClient::didPerformClientRedirect(WebKit::WebPageProxy&, const WTF::String& sourceURL, const WTF::String& destinationURL)
     995void NavigationState::HistoryClient::didPerformClientRedirect(WebPageProxy&, const WTF::String& sourceURL, const WTF::String& destinationURL)
    976996{
    977997    if (!m_navigationState.m_historyDelegateMethods.webViewDidPerformClientRedirectFromURLToURL)
     
    9851005}
    9861006
    987 void NavigationState::HistoryClient::didPerformServerRedirect(WebKit::WebPageProxy&, const WTF::String& sourceURL, const WTF::String& destinationURL)
     1007void NavigationState::HistoryClient::didPerformServerRedirect(WebPageProxy&, const WTF::String& sourceURL, const WTF::String& destinationURL)
    9881008{
    9891009    if (!m_navigationState.m_historyDelegateMethods.webViewDidPerformServerRedirectFromURLToURL)
     
    9971017}
    9981018
    999 void NavigationState::HistoryClient::didUpdateHistoryTitle(WebKit::WebPageProxy&, const WTF::String& title, const WTF::String& url)
     1019void NavigationState::HistoryClient::didUpdateHistoryTitle(WebPageProxy&, const WTF::String& title, const WTF::String& url)
    10001020{
    10011021    if (!m_navigationState.m_historyDelegateMethods.webViewDidUpdateHistoryTitleForURL)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r222941 r222944  
    11971197    PageClientProtector protector(m_pageClient);
    11981198
    1199     m_loaderClient->didChangeBackForwardList(*this, added, WTFMove(removed));
     1199    if (!m_navigationClient || !m_navigationClient->didChangeBackForwardList(*this, added, removed))
     1200        m_loaderClient->didChangeBackForwardList(*this, added, WTFMove(removed));
    12001201
    12011202    auto transaction = m_pageLoadState.transaction();
  • trunk/Tools/ChangeLog

    r222937 r222944  
     12017-10-05  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add ObjC equivalent of WKPageNavigationClient.didChangeBackForwardList
     4        https://bugs.webkit.org/show_bug.cgi?id=177966
     5        <rdar://problem/22387135>
     6
     7        Reviewed by Tim Horton.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm:
     10        (-[ListItemDelegate _webView:backForwardListItemAdded:removed:]):
     11        (-[ListItemDelegate webView:didFinishNavigation:]):
     12        (TEST):
     13
    1142017-10-04  Megan Gardner  <megan_gardner@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm

    r222794 r222944  
    2626#include "config.h"
    2727
     28#import <WebKit/WKBackForwardListPrivate.h>
    2829#import <WebKit/WKNavigationDelegatePrivate.h>
    2930#import <WebKit/WKNavigationPrivate.h>
     
    329330}
    330331
     332RetainPtr<WKBackForwardListItem> firstItem;
     333RetainPtr<WKBackForwardListItem> secondItem;
     334
     335@interface ListItemDelegate : NSObject<WKNavigationDelegatePrivate>
     336@end
     337@implementation ListItemDelegate
     338- (void)_webView:(WKWebView *)webView backForwardListItemAdded:(WKBackForwardListItem *)itemAdded removed:(NSArray<WKBackForwardListItem *> *)itemsRemoved
     339{
     340    NSString *firstURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"].absoluteString;
     341    NSString *secondURL = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"].absoluteString;
     342
     343    if (!firstItem) {
     344        EXPECT_NULL(firstItem);
     345        EXPECT_NULL(secondItem);
     346        EXPECT_NULL(itemsRemoved);
     347        EXPECT_NOT_NULL(itemAdded);
     348        EXPECT_STREQ(firstURL.UTF8String, itemAdded.URL.absoluteString.UTF8String);
     349        firstItem = itemAdded;
     350    } else if (!secondItem) {
     351        EXPECT_NOT_NULL(firstItem);
     352        EXPECT_NULL(secondItem);
     353        EXPECT_NULL(itemsRemoved);
     354        EXPECT_NOT_NULL(itemAdded);
     355        EXPECT_STREQ(secondURL.UTF8String, itemAdded.URL.absoluteString.UTF8String);
     356        secondItem = itemAdded;
     357    } else {
     358        EXPECT_NOT_NULL(firstItem);
     359        EXPECT_NOT_NULL(secondItem);
     360        EXPECT_NOT_NULL(itemsRemoved);
     361        EXPECT_NULL(itemAdded);
     362        EXPECT_EQ([itemsRemoved count], 2u);
     363        EXPECT_STREQ(firstURL.UTF8String, [itemsRemoved objectAtIndex:0].URL.absoluteString.UTF8String);
     364        EXPECT_STREQ(secondURL.UTF8String, [itemsRemoved objectAtIndex:1].URL.absoluteString.UTF8String);
     365        isDone = true;
     366    }
     367}
     368- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
     369{
     370    navigationComplete = true;
     371}
     372@end
     373
     374TEST(WKNavigation, ListItemAddedRemoved)
     375{
     376    auto webView = adoptNS([[WKWebView alloc] init]);
     377    auto delegate = adoptNS([[ListItemDelegate alloc] init]);
     378    [webView setNavigationDelegate:delegate.get()];
     379    [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
     380    TestWebKitAPI::Util::run(&navigationComplete);
     381    navigationComplete = false;
     382    [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
     383    TestWebKitAPI::Util::run(&navigationComplete);
     384    [[webView backForwardList] _removeAllItems];
     385    TestWebKitAPI::Util::run(&isDone);
     386}
    331387#endif // PLATFORM(MAC)
    332388
Note: See TracChangeset for help on using the changeset viewer.