Changeset 169805 in webkit


Ignore:
Timestamp:
Jun 11, 2014 7:30:34 AM (10 years ago)
Author:
mitz@apple.com
Message:

<rdar://problem/17218629> [Cocoa] WKWebView’s canGoBack and canGoForward properties are not KVO-compliant
https://bugs.webkit.org/show_bug.cgi?id=133722

Reviewed by Anders Carlsson.

  • UIProcess/API/Cocoa/WKBrowsingContextController.mm: Added no-op overrides of new

PageLoadStateObserver member functions.

  • UIProcess/API/Cocoa/WKWebView.h: Documented the canGoBack and canGoForward properties as

being KVO-compliant.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView canGoBack]): Changed to get the return value from the page load state.
(-[WKWebView canGoForward]): Ditto.

  • UIProcess/Cocoa/NavigationState.h:
  • UIProcess/Cocoa/NavigationState.mm:

(WebKit::NavigationState::willChangeCanGoBack): Override this new PageLoadStateObserver
member function by sending the appropriate KVO change message to the WKWebView.
(WebKit::NavigationState::didChangeCanGoBack): Ditto.
(WebKit::NavigationState::willChangeCanGoForward): Ditto.
(WebKit::NavigationState::didChangeCanGoForward): Ditto.

  • UIProcess/PageLoadState.cpp:

(WebKit::PageLoadState::commitChanges): Check for changes to canGoBack and canGoForward
and call the observers if needed.
(WebKit::PageLoadState::canGoBack): Added. Returns the value from the committed state.
(WebKit::PageLoadState::setCanGoBack): Added. Sets the value in the uncommitted state.
(WebKit::PageLoadState::canGoForward): Added. Returns the value from the committed state.
(WebKit::PageLoadState::setCanGoForward): Added. Sets the value in the uncommitted state.

  • UIProcess/PageLoadState.h:

(WebKit::PageLoadState::Data::Data): Added canGoBack and canGoForward boolean members.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::didChangeBackForwardList): Update the page load state with the new
state of canGoBack and canGoForward.

  • UIProcess/WebPageProxy.h: Removed unused member variables m_canGoBack and m_canGoForward.
Location:
trunk/Source/WebKit2
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r169803 r169805  
     12014-06-11  Dan Bernstein  <mitz@apple.com>
     2
     3        <rdar://problem/17218629> [Cocoa] WKWebView’s canGoBack and canGoForward properties are not KVO-compliant
     4        https://bugs.webkit.org/show_bug.cgi?id=133722
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * UIProcess/API/Cocoa/WKBrowsingContextController.mm: Added no-op overrides of new
     9        PageLoadStateObserver member functions.
     10
     11        * UIProcess/API/Cocoa/WKWebView.h: Documented the canGoBack and canGoForward properties as
     12        being KVO-compliant.
     13        * UIProcess/API/Cocoa/WKWebView.mm:
     14        (-[WKWebView canGoBack]): Changed to get the return value from the page load state.
     15        (-[WKWebView canGoForward]): Ditto.
     16
     17        * UIProcess/Cocoa/NavigationState.h:
     18        * UIProcess/Cocoa/NavigationState.mm:
     19        (WebKit::NavigationState::willChangeCanGoBack): Override this new PageLoadStateObserver
     20        member function by sending the appropriate KVO change message to the WKWebView.
     21        (WebKit::NavigationState::didChangeCanGoBack): Ditto.
     22        (WebKit::NavigationState::willChangeCanGoForward): Ditto.
     23        (WebKit::NavigationState::didChangeCanGoForward): Ditto.
     24
     25        * UIProcess/PageLoadState.cpp:
     26        (WebKit::PageLoadState::commitChanges): Check for changes to canGoBack and canGoForward
     27        and call the observers if needed.
     28        (WebKit::PageLoadState::canGoBack): Added. Returns the value from the committed state.
     29        (WebKit::PageLoadState::setCanGoBack): Added. Sets the value in the uncommitted state.
     30        (WebKit::PageLoadState::canGoForward): Added. Returns the value from the committed state.
     31        (WebKit::PageLoadState::setCanGoForward): Added. Sets the value in the uncommitted state.
     32        * UIProcess/PageLoadState.h:
     33        (WebKit::PageLoadState::Data::Data): Added canGoBack and canGoForward boolean members.
     34
     35        * UIProcess/WebPageProxy.cpp:
     36        (WebKit::WebPageProxy::didChangeBackForwardList): Update the page load state with the new
     37        state of canGoBack and canGoForward.
     38        * UIProcess/WebPageProxy.h: Removed unused member variables m_canGoBack and m_canGoForward.
     39
    1402014-06-11  Zan Dobersek  <zdobersek@igalia.com>
    241
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm

    r168213 r169805  
    121121    }
    122122
     123    virtual void willChangeCanGoBack() override { }
     124    virtual void didChangeCanGoBack() override { }
     125    virtual void willChangeCanGoForward() override { }
     126    virtual void didChangeCanGoForward() override { }
     127
    123128    WKBrowsingContextController *m_controller;
    124129};
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h

    r169765 r169805  
    147147/*! @abstract A Boolean value indicating whether there is a back item in
    148148 the back-forward list that can be navigated to.
     149 @discussion @link WKWebView @/link is key-value observing (KVO) compliant
     150 for this property.
    149151 @seealso backForwardList.
    150152 */
     
    153155/*! @abstract A Boolean value indicating whether there is a forward item in
    154156 the back-forward list that can be navigated to.
     157 @discussion @link WKWebView @/link is key-value observing (KVO) compliant
     158 for this property.
    155159 @seealso backForwardList.
    156160 */
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r169791 r169805  
    405405}
    406406
    407 // FIXME: This should be KVO compliant.
    408407- (BOOL)canGoBack
    409408{
    410     return !!_page->backForwardList().backItem();
    411 }
    412 
    413 // FIXME: This should be KVO compliant.
     409    return _page->pageLoadState().canGoBack();
     410}
     411
    414412- (BOOL)canGoForward
    415413{
    416     return !!_page->backForwardList().forwardItem();
     414    return _page->pageLoadState().canGoForward();
    417415}
    418416
  • trunk/Source/WebKit2/UIProcess/Cocoa/NavigationState.h

    r169782 r169805  
    128128    virtual void willChangeEstimatedProgress() override;
    129129    virtual void didChangeEstimatedProgress() override;
     130    virtual void willChangeCanGoBack() override;
     131    virtual void didChangeCanGoBack() override;
     132    virtual void willChangeCanGoForward() override;
     133    virtual void didChangeCanGoForward() override;
    130134
    131135    WKWebView *m_webView;
  • trunk/Source/WebKit2/UIProcess/Cocoa/NavigationState.mm

    r169782 r169805  
    733733}
    734734
     735void NavigationState::willChangeCanGoBack()
     736{
     737    [m_webView willChangeValueForKey:@"canGoBack"];
     738}
     739
     740void NavigationState::didChangeCanGoBack()
     741{
     742    [m_webView didChangeValueForKey:@"canGoBack"];
     743}
     744
     745void NavigationState::willChangeCanGoForward()
     746{
     747    [m_webView willChangeValueForKey:@"canGoForward"];
     748}
     749
     750void NavigationState::didChangeCanGoForward()
     751{
     752    [m_webView didChangeValueForKey:@"canGoForward"];
     753}
     754
    735755} // namespace WebKit
    736756
  • trunk/Source/WebKit2/UIProcess/PageLoadState.cpp

    r168405 r169805  
    9696    m_mayHaveUncommittedChanges = false;
    9797
     98    bool canGoBackChanged = m_committedState.canGoBack != m_uncommittedState.canGoBack;
     99    bool canGoForwardChanged = m_committedState.canGoForward != m_uncommittedState.canGoForward;
    98100    bool titleChanged = m_committedState.title != m_uncommittedState.title;
    99101    bool isLoadingChanged = isLoading(m_committedState) != isLoading(m_uncommittedState);
     
    102104    bool estimatedProgressChanged = estimatedProgress(m_committedState) != estimatedProgress(m_uncommittedState);
    103105
     106    if (canGoBackChanged)
     107        callObserverCallback(&Observer::willChangeCanGoBack);
     108    if (canGoForwardChanged)
     109        callObserverCallback(&Observer::willChangeCanGoForward);
    104110    if (titleChanged)
    105111        callObserverCallback(&Observer::willChangeTitle);
     
    126132    if (titleChanged)
    127133        callObserverCallback(&Observer::didChangeTitle);
     134    if (canGoForwardChanged)
     135        callObserverCallback(&Observer::didChangeCanGoForward);
     136    if (canGoBackChanged)
     137        callObserverCallback(&Observer::didChangeCanGoBack);
    128138}
    129139
     
    319329}
    320330
     331bool PageLoadState::canGoBack() const
     332{
     333    return m_committedState.canGoBack;
     334}
     335
     336void PageLoadState::setCanGoBack(const Transaction::Token& token, bool canGoBack)
     337{
     338    ASSERT_UNUSED(token, &token.m_pageLoadState == this);
     339    m_uncommittedState.canGoBack = canGoBack;
     340}
     341
     342bool PageLoadState::canGoForward() const
     343{
     344    return m_committedState.canGoForward;
     345}
     346
     347void PageLoadState::setCanGoForward(const Transaction::Token& token, bool canGoForward)
     348{
     349    ASSERT_UNUSED(token, &token.m_pageLoadState == this);
     350    m_uncommittedState.canGoForward = canGoForward;
     351}
     352
    321353void PageLoadState::didStartProgress(const Transaction::Token& token)
    322354{
  • trunk/Source/WebKit2/UIProcess/PageLoadState.h

    r168405 r169805  
    6262        virtual void willChangeEstimatedProgress() = 0;
    6363        virtual void didChangeEstimatedProgress() = 0;
     64
     65        virtual void willChangeCanGoBack() = 0;
     66        virtual void didChangeCanGoBack() = 0;
     67
     68        virtual void willChangeCanGoForward() = 0;
     69        virtual void didChangeCanGoForward() = 0;
    6470    };
    6571
     
    135141    void setTitle(const Transaction::Token&, const String&);
    136142
     143    bool canGoBack() const;
     144    void setCanGoBack(const Transaction::Token&, bool);
     145
     146    bool canGoForward() const;
     147    void setCanGoForward(const Transaction::Token&, bool);
     148
    137149    void didStartProgress(const Transaction::Token&);
    138150    void didChangeProgress(const Transaction::Token&, double);
     
    151163            : state(State::Finished)
    152164            , hasInsecureContent(false)
     165            , canGoBack(false)
     166            , canGoForward(false)
    153167            , estimatedProgress(0)
    154168        {
     
    166180
    167181        String title;
     182
     183        bool canGoBack;
     184        bool canGoForward;
    168185
    169186        double estimatedProgress;
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r169737 r169805  
    926926    m_loaderClient->didChangeBackForwardList(this, added, std::move(removed));
    927927
     928    auto transaction = m_pageLoadState.transaction();
     929
     930    m_pageLoadState.setCanGoBack(transaction, m_backForwardList->backItem());
     931    m_pageLoadState.setCanGoForward(transaction, m_backForwardList->forwardItem());
     932
    928933#if PLATFORM(MAC)
    929934    m_pageClient.clearCustomSwipeViews();
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r169791 r169805  
    15531553#endif
    15541554       
    1555     bool m_canGoBack;
    1556     bool m_canGoForward;
    15571555    Ref<WebBackForwardList> m_backForwardList;
    15581556       
Note: See TracChangeset for help on using the changeset viewer.