[CTTE] The WebPageProxy's WebBackForwardList is never null so it should be stored...
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Dec 2013 02:25:39 +0000 (02:25 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Dec 2013 02:25:39 +0000 (02:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=125035

Reviewed by Dan Bernstein.

* UIProcess/API/C/WKPage.cpp:
(WKPageGetBackForwardList):
* UIProcess/API/Cocoa/WKBrowsingContextController.mm:
(-[WKBrowsingContextController backForwardList]): Remove null check.
* UIProcess/WebBackForwardList.cpp:
(WebKit::WebBackForwardList::WebBackForwardList):
(WebKit::WebBackForwardList::currentItem): Constify.
(WebKit::WebBackForwardList::backItem): Constify.
(WebKit::WebBackForwardList::forwardItem): Constify.
(WebKit::WebBackForwardList::itemAtIndex): Constify.
* UIProcess/WebBackForwardList.h:
(WebKit::WebBackForwardList::create):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::backForwardList):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159891 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/Cocoa/WKBrowsingContextController.mm
Source/WebKit2/UIProcess/WebBackForwardList.cpp
Source/WebKit2/UIProcess/WebBackForwardList.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h

index 1ddbc2b..2ccbefc 100644 (file)
@@ -1,3 +1,27 @@
+2013-11-30  Sam Weinig  <sam@webkit.org>
+
+        [CTTE] The WebPageProxy's WebBackForwardList is never null so it should be stored in a Ref
+        https://bugs.webkit.org/show_bug.cgi?id=125035
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageGetBackForwardList):
+        * UIProcess/API/Cocoa/WKBrowsingContextController.mm:
+        (-[WKBrowsingContextController backForwardList]): Remove null check.
+        * UIProcess/WebBackForwardList.cpp:
+        (WebKit::WebBackForwardList::WebBackForwardList):
+        (WebKit::WebBackForwardList::currentItem): Constify.
+        (WebKit::WebBackForwardList::backItem): Constify.
+        (WebKit::WebBackForwardList::forwardItem): Constify.
+        (WebKit::WebBackForwardList::itemAtIndex): Constify.
+        * UIProcess/WebBackForwardList.h:
+        (WebKit::WebBackForwardList::create):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::backForwardList):
+
 2013-11-30  Zan Dobersek  <zdobersek@igalia.com>
 
         Unreviewed GTK build fix after r159889.
index 04ec412..4596280 100644 (file)
@@ -205,7 +205,7 @@ void WKPageTryRestoreScrollPosition(WKPageRef pageRef)
 
 WKBackForwardListRef WKPageGetBackForwardList(WKPageRef pageRef)
 {
-    return toAPI(toImpl(pageRef)->backForwardList());
+    return toAPI(&toImpl(pageRef)->backForwardList());
 }
 
 bool WKPageWillHandleHorizontalScrollEvents(WKPageRef pageRef)
index e95f7d1..5e1bedf 100644 (file)
@@ -323,11 +323,7 @@ static void releaseNSData(unsigned char*, const void* data)
 
 - (WKBackForwardList *)backForwardList
 {
-    WebBackForwardList* list = _page->backForwardList();
-    if (!list)
-        return nil;
-
-    return wrapper(*list);
+    return wrapper(_page->backForwardList());
 }
 
 #pragma mark Active Load Introspection
index 64cfb81..411ea56 100644 (file)
@@ -33,13 +33,12 @@ namespace WebKit {
 
 static const unsigned DefaultCapacity = 100;
 
-WebBackForwardList::WebBackForwardList(WebPageProxy* page)
-    : m_page(page)
+WebBackForwardList::WebBackForwardList(WebPageProxy& page)
+    : m_page(&page)
     , m_hasCurrentIndex(false)
     , m_currentIndex(0)
     , m_capacity(DefaultCapacity)
 {
-    ASSERT(m_page);
 }
 
 WebBackForwardList::~WebBackForwardList()
@@ -149,40 +148,40 @@ void WebBackForwardList::goToItem(WebBackForwardListItem* item)
     }
 }
 
-WebBackForwardListItem* WebBackForwardList::currentItem()
+WebBackForwardListItem* WebBackForwardList::currentItem() const
 {
     ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size());
 
-    return m_page && m_hasCurrentIndex ? m_entries[m_currentIndex].get() : 0;
+    return m_page && m_hasCurrentIndex ? m_entries[m_currentIndex].get() : nullptr;
 }
 
-WebBackForwardListItem* WebBackForwardList::backItem()
+WebBackForwardListItem* WebBackForwardList::backItem() const
 {
     ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size());
 
-    return m_page && m_hasCurrentIndex && m_currentIndex ? m_entries[m_currentIndex - 1].get() : 0;
+    return m_page && m_hasCurrentIndex && m_currentIndex ? m_entries[m_currentIndex - 1].get() : nullptr;
 }
 
-WebBackForwardListItem* WebBackForwardList::forwardItem()
+WebBackForwardListItem* WebBackForwardList::forwardItem() const
 {
     ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size());
 
-    return m_page && m_hasCurrentIndex && m_entries.size() && m_currentIndex < m_entries.size() - 1 ? m_entries[m_currentIndex + 1].get() : 0;
+    return m_page && m_hasCurrentIndex && m_entries.size() && m_currentIndex < m_entries.size() - 1 ? m_entries[m_currentIndex + 1].get() : nullptr;
 }
 
-WebBackForwardListItem* WebBackForwardList::itemAtIndex(int index)
+WebBackForwardListItem* WebBackForwardList::itemAtIndex(int index) const
 {
     ASSERT(!m_hasCurrentIndex || m_currentIndex < m_entries.size());
 
     if (!m_hasCurrentIndex || !m_page)
-        return 0;
+        return nullptr;
     
     // Do range checks without doing math on index to avoid overflow.
     if (index < -backListCount())
-        return 0;
+        return nullptr;
     
     if (index > forwardListCount())
-        return 0;
+        return nullptr;
         
     return m_entries[index + m_currentIndex].get();
 }
index 1c453e8..0f24ccf 100644 (file)
@@ -29,7 +29,7 @@
 #include "APIObject.h"
 #include "WebBackForwardListItem.h"
 #include "WebPageProxy.h"
-#include <wtf/PassRefPtr.h>
+#include <wtf/PassRef.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 #if USE(CF)
@@ -46,9 +46,9 @@ namespace WebKit {
 
 class WebBackForwardList : public API::TypedObject<API::Object::Type::BackForwardList> {
 public:
-    static PassRefPtr<WebBackForwardList> create(WebPageProxy* page)
+    static PassRef<WebBackForwardList> create(WebPageProxy& page)
     {
-        return adoptRef(new WebBackForwardList(page));
+        return adoptRef(*new WebBackForwardList(page));
     }
     void pageClosed();
 
@@ -58,10 +58,10 @@ public:
     void goToItem(WebBackForwardListItem*);
     void clear();
 
-    WebBackForwardListItem* currentItem();
-    WebBackForwardListItem* backItem();
-    WebBackForwardListItem* forwardItem();
-    WebBackForwardListItem* itemAtIndex(int);
+    WebBackForwardListItem* currentItem() const;
+    WebBackForwardListItem* backItem() const;
+    WebBackForwardListItem* forwardItem() const;
+    WebBackForwardListItem* itemAtIndex(int) const;
     
     const BackForwardListItemVector& entries() const { return m_entries; }
 
@@ -80,7 +80,7 @@ public:
 #endif
 
 private:
-    explicit WebBackForwardList(WebPageProxy*);
+    explicit WebBackForwardList(WebPageProxy&);
 
     WebPageProxy* m_page;
     BackForwardListItemVector m_entries;
index 79ff196..b996998 100644 (file)
@@ -237,7 +237,7 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, PassRefPtr<WebProcessProxy> p
     , m_notificationPermissionRequestManager(*this)
     , m_estimatedProgress(0)
     , m_viewState(ViewState::NoFlags)
-    , m_backForwardList(WebBackForwardList::create(this))
+    , m_backForwardList(WebBackForwardList::create(*this))
     , m_loadStateAtProcessExit(FrameLoadState::State::Finished)
     , m_temporarilyClosedComposition(false)
     , m_textZoomFactor(1)
index 523ad2d..cefa089 100644 (file)
@@ -333,7 +333,7 @@ public:
 
     DrawingAreaProxy* drawingArea() const { return m_drawingArea.get(); }
 
-    WebBackForwardList* backForwardList() const { return m_backForwardList.get(); }
+    WebBackForwardList& backForwardList() { return m_backForwardList.get(); }
 
 #if ENABLE(INSPECTOR)
     WebInspectorProxy* inspector();
@@ -1212,7 +1212,7 @@ private:
 
     bool m_canGoBack;
     bool m_canGoForward;
-    RefPtr<WebBackForwardList> m_backForwardList;
+    Ref<WebBackForwardList> m_backForwardList;
     
     bool m_maintainsInactiveSelection;