Commit 31cf0095 authored by akling@apple.com's avatar akling@apple.com

Page::backForward() should return a reference.

<https://webkit.org/b/121151>

Reviewed by Anders Carlsson.

There is always a BackForwardController, so make backForward() return a reference.
Also made it store a Page& internally since it's tied to the lifetime of Page.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155529 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 11f610c1
2013-09-11 Andreas Kling <akling@apple.com>
Page::backForward() should return a reference.
<https://webkit.org/b/121151>
Reviewed by Anders Carlsson.
There is always a BackForwardController, so make backForward() return a reference.
Also made it store a Page& internally since it's tied to the lifetime of Page.
2013-09-11 Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com>
WTF::OwnPtr should behave similarly with the rest of WTF smart pointers
......@@ -32,41 +32,36 @@
namespace WebCore {
BackForwardController::BackForwardController(Page* page, PassRefPtr<BackForwardClient> client)
BackForwardController::BackForwardController(Page& page, PassRefPtr<BackForwardClient> client)
: m_page(page)
, m_client(client)
{
if (!m_client)
m_client = BackForwardList::create(page);
m_client = BackForwardList::create(&page);
}
BackForwardController::~BackForwardController()
{
}
PassOwnPtr<BackForwardController> BackForwardController::create(Page* page, PassRefPtr<BackForwardClient> client)
{
return adoptPtr(new BackForwardController(page, client));
}
bool BackForwardController::canGoBackOrForward(int distance) const
{
return m_page->canGoBackOrForward(distance);
return m_page.canGoBackOrForward(distance);
}
void BackForwardController::goBackOrForward(int distance)
{
m_page->goBackOrForward(distance);
m_page.goBackOrForward(distance);
}
bool BackForwardController::goBack()
{
return m_page->goBack();
return m_page.goBack();
}
bool BackForwardController::goForward()
{
return m_page->goForward();
return m_page.goForward();
}
void BackForwardController::addItem(PassRefPtr<HistoryItem> item)
......@@ -81,7 +76,7 @@ void BackForwardController::setCurrentItem(HistoryItem* item)
int BackForwardController::count() const
{
return m_page->getHistoryLength();
return m_page.getHistoryLength();
}
int BackForwardController::backCount() const
......
......@@ -39,10 +39,9 @@ class Page;
class BackForwardController {
WTF_MAKE_NONCOPYABLE(BackForwardController); WTF_MAKE_FAST_ALLOCATED;
public:
BackForwardController(Page&, PassRefPtr<BackForwardClient>);
~BackForwardController();
static PassOwnPtr<BackForwardController> create(Page*, PassRefPtr<BackForwardClient>);
BackForwardClient* client() const { return m_client.get(); }
bool canGoBackOrForward(int distance) const;
......@@ -69,9 +68,7 @@ public:
HistoryItem* forwardItem() { return itemAtIndex(1); }
private:
BackForwardController(Page*, PassRefPtr<BackForwardClient>);
Page* m_page;
Page& m_page;
RefPtr<BackForwardClient> m_client;
};
......
......@@ -217,7 +217,7 @@ static void logCanCachePageDecision(Page* page)
if (frameRejectReasons)
rejectReasons |= 1 << FrameCannotBeInPageCache;
if (!page->backForward()->isActive()) {
if (!page->backForward().isActive()) {
PCLOG(" -The back/forward list is disabled or has 0 capacity");
rejectReasons |= 1 << DisabledBackForwardList;
}
......@@ -355,7 +355,7 @@ bool PageCache::canCache(Page* page) const
return m_capacity > 0
&& canCachePageContainingThisFrame(&page->mainFrame())
&& page->backForward()->isActive()
&& page->backForward().isActive()
&& page->settings().usesPageCache()
#if ENABLE(DEVICE_ORIENTATION)
&& !DeviceMotionController::isActiveAt(page)
......
......@@ -1123,7 +1123,7 @@ void FrameLoader::prepareForHistoryNavigation()
currentItem = HistoryItem::create();
currentItem->setLastVisitWasFailure(true);
history().setCurrentItem(currentItem.get());
m_frame.page()->backForward()->setCurrentItem(currentItem.get());
m_frame.page()->backForward().setCurrentItem(currentItem.get());
ASSERT(stateMachine()->isDisplayingInitialEmptyDocument());
stateMachine()->advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit);
......@@ -2149,7 +2149,7 @@ void FrameLoader::checkLoadCompleteForThisFrame()
}
if (shouldReset && item)
if (Page* page = m_frame.page()) {
page->backForward()->setCurrentItem(item.get());
page->backForward().setCurrentItem(item.get());
m_frame.loader().client().updateGlobalHistoryItemForPage();
}
return;
......@@ -2236,11 +2236,11 @@ static KURL originatingURLFromBackForwardList(Page* page)
// It has the same meaning of "page a user thinks is the current one".
KURL originalURL;
int backCount = page->backForward()->backCount();
int backCount = page->backForward().backCount();
for (int backIndex = 0; backIndex <= backCount; backIndex++) {
// FIXME: At one point we had code here to check a "was user gesture" flag.
// Do we need to restore that logic?
HistoryItem* historyItem = page->backForward()->itemAtIndex(-backIndex);
HistoryItem* historyItem = page->backForward().itemAtIndex(-backIndex);
if (!historyItem)
continue;
......@@ -2843,7 +2843,7 @@ void FrameLoader::continueLoadAfterNavigationPolicy(const ResourceRequest&, Pass
if ((isTargetItem || isLoadingMainFrame()) && isBackForwardLoadType(policyChecker().loadType())) {
if (Page* page = m_frame.page()) {
if (HistoryItem* resetItem = page->mainFrame().loader().history().currentItem()) {
page->backForward()->setCurrentItem(resetItem);
page->backForward().setCurrentItem(resetItem);
m_frame.loader().client().updateGlobalHistoryItemForPage();
}
}
......@@ -3060,7 +3060,7 @@ void FrameLoader::checkDidPerformFirstNavigation()
if (!page)
return;
if (!m_didPerformFirstNavigation && page->backForward()->currentItem() && !page->backForward()->backItem() && !page->backForward()->forwardItem()) {
if (!m_didPerformFirstNavigation && page->backForward().currentItem() && !page->backForward().backItem() && !page->backForward().forwardItem()) {
m_didPerformFirstNavigation = true;
m_client.didPerformFirstNavigation();
}
......
......@@ -277,8 +277,8 @@ void HistoryController::goToItem(HistoryItem* targetItem, FrameLoadType type)
// Set the BF cursor before commit, which lets the user quickly click back/forward again.
// - plus, it only makes sense for the top level of the operation through the frametree,
// as opposed to happening for some/one of the page commits that might happen soon
RefPtr<HistoryItem> currentItem = page->backForward()->currentItem();
page->backForward()->setCurrentItem(targetItem);
RefPtr<HistoryItem> currentItem = page->backForward().currentItem();
page->backForward().setCurrentItem(targetItem);
m_frame.loader().client().updateGlobalHistoryItemForPage();
// First set the provisional item of any frames that are not actually navigating.
......@@ -802,7 +802,7 @@ void HistoryController::updateBackForwardListClippedAtTarget(bool doClip)
RefPtr<HistoryItem> topItem = frameLoader.history().createItemTree(m_frame, doClip);
LOG(BackForward, "WebCoreBackForward - Adding backforward item %p for frame %s", topItem.get(), m_frame.loader().documentLoader()->url().string().ascii().data());
page->backForward()->addItem(topItem.release());
page->backForward().addItem(topItem.release());
}
void HistoryController::updateCurrentItem()
......@@ -847,7 +847,7 @@ void HistoryController::pushState(PassRefPtr<SerializedScriptValue> stateObject,
m_currentItem->setStateObject(stateObject);
m_currentItem->setURLString(urlString);
page->backForward()->addItem(topItem.release());
page->backForward().addItem(topItem.release());
if (m_frame.settings().privateBrowsingEnabled())
return;
......
......@@ -205,7 +205,7 @@ public:
}
// go(i!=0) from a frame navigates into the history of the frame only,
// in both IE and NS (but not in Mozilla). We can't easily do that.
frame->page()->backForward()->goBackOrForward(m_historySteps);
frame->page()->backForward().goBackOrForward(m_historySteps);
}
private:
......@@ -402,8 +402,8 @@ void NavigationScheduler::scheduleHistoryNavigation(int steps)
// Invalid history navigations (such as history.forward() during a new load) have the side effect of cancelling any scheduled
// redirects. We also avoid the possibility of cancelling the current load by avoiding the scheduled redirection altogether.
BackForwardController* backForward = m_frame->page()->backForward();
if (steps > backForward->forwardCount() || -steps > backForward->backCount()) {
BackForwardController& backForward = m_frame->page()->backForward();
if (steps > backForward.forwardCount() || -steps > backForward.backCount()) {
cancel();
return;
}
......
......@@ -292,11 +292,11 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
break;
case ContextMenuItemTagGoBack:
if (Page* page = frame->page())
page->backForward()->goBackOrForward(-1);
page->backForward().goBackOrForward(-1);
break;
case ContextMenuItemTagGoForward:
if (Page* page = frame->page())
page->backForward()->goBackOrForward(1);
page->backForward().goBackOrForward(1);
break;
case ContextMenuItemTagStop:
frame->loader().stop();
......@@ -912,10 +912,10 @@ void ContextMenuController::populate()
appendItem(StopItem, m_contextMenu.get());
appendItem(ReloadItem, m_contextMenu.get());
#else
if (frame->page() && frame->page()->backForward()->canGoBackOrForward(-1))
if (frame->page() && frame->page()->backForward().canGoBackOrForward(-1))
appendItem(BackItem, m_contextMenu.get());
if (frame->page() && frame->page()->backForward()->canGoBackOrForward(1))
if (frame->page() && frame->page()->backForward().canGoBackOrForward(1))
appendItem(ForwardItem, m_contextMenu.get());
// use isLoadingInAPISense rather than isLoading because Stop/Reload are
......@@ -1293,10 +1293,10 @@ void ContextMenuController::checkOrEnableIfNeeded(ContextMenuItem& item) const
#endif
#if PLATFORM(GTK)
case ContextMenuItemTagGoBack:
shouldEnable = frame->page() && frame->page()->backForward()->canGoBackOrForward(-1);
shouldEnable = frame->page() && frame->page()->backForward().canGoBackOrForward(-1);
break;
case ContextMenuItemTagGoForward:
shouldEnable = frame->page() && frame->page()->backForward()->canGoBackOrForward(1);
shouldEnable = frame->page() && frame->page()->backForward().canGoBackOrForward(1);
break;
case ContextMenuItemTagStop:
shouldEnable = frame->loader().documentLoader()->isLoadingInAPISense();
......
......@@ -972,7 +972,7 @@ void DOMWindow::close(ScriptExecutionContext* context)
bool allowScriptsToCloseWindows = m_frame->settings().allowScriptsToCloseWindows();
if (!(page->openedByDOM() || page->backForward()->count() <= 1 || allowScriptsToCloseWindows)) {
if (!(page->openedByDOM() || page->backForward().count() <= 1 || allowScriptsToCloseWindows)) {
pageConsole()->addMessage(JSMessageSource, WarningMessageLevel, ASCIILiteral("Can't close the window since it was not opened by JavaScript"));
return;
}
......
......@@ -53,7 +53,7 @@ unsigned History::length() const
return 0;
if (!m_frame->page())
return 0;
return m_frame->page()->backForward()->count();
return m_frame->page()->backForward().count();
}
PassRefPtr<SerializedScriptValue> History::state()
......
......@@ -141,7 +141,7 @@ Page::Page(PageClients& pageClients)
#endif
, m_settings(Settings::create(this))
, m_progress(ProgressTracker::create())
, m_backForwardController(BackForwardController::create(this, pageClients.backForwardClient))
, m_backForwardController(createOwned<BackForwardController>(*this, pageClients.backForwardClient))
, m_mainFrame(Frame::create(this, 0, pageClients.loaderClientForMainFrame))
, m_theme(RenderTheme::themeForPage(this))
, m_editorClient(pageClients.editorClient)
......@@ -230,7 +230,7 @@ Page::~Page()
if (m_scrollingCoordinator)
m_scrollingCoordinator->pageDestroyed();
backForward()->close();
backForward().close();
#ifndef NDEBUG
pageCounter.decrement();
......@@ -356,12 +356,12 @@ void Page::setOpenedByDOM()
BackForwardClient* Page::backForwardClient() const
{
return m_backForwardController->client();
return backForward().client();
}
bool Page::goBack()
{
HistoryItem* item = backForward()->backItem();
HistoryItem* item = backForward().backItem();
if (item) {
goToItem(item, FrameLoadTypeBack);
......@@ -372,7 +372,7 @@ bool Page::goBack()
bool Page::goForward()
{
HistoryItem* item = backForward()->forwardItem();
HistoryItem* item = backForward().forwardItem();
if (item) {
goToItem(item, FrameLoadTypeForward);
......@@ -385,9 +385,9 @@ bool Page::canGoBackOrForward(int distance) const
{
if (distance == 0)
return true;
if (distance > 0 && distance <= backForward()->forwardCount())
if (distance > 0 && distance <= backForward().forwardCount())
return true;
if (distance < 0 && -distance <= backForward()->backCount())
if (distance < 0 && -distance <= backForward().backCount())
return true;
return false;
}
......@@ -397,14 +397,14 @@ void Page::goBackOrForward(int distance)
if (distance == 0)
return;
HistoryItem* item = backForward()->itemAtIndex(distance);
HistoryItem* item = backForward().itemAtIndex(distance);
if (!item) {
if (distance > 0) {
if (int forwardCount = backForward()->forwardCount())
item = backForward()->itemAtIndex(forwardCount);
if (int forwardCount = backForward().forwardCount())
item = backForward().itemAtIndex(forwardCount);
} else {
if (int backCount = backForward()->backCount())
item = backForward()->itemAtIndex(-backCount);
if (int backCount = backForward().backCount())
item = backForward().itemAtIndex(-backCount);
}
}
......@@ -428,7 +428,7 @@ void Page::goToItem(HistoryItem* item, FrameLoadType type)
int Page::getHistoryLength()
{
return backForward()->backCount() + 1 + backForward()->forwardCount();
return backForward().backCount() + 1 + backForward().forwardCount();
}
void Page::setGroupName(const String& name)
......
......@@ -212,7 +212,7 @@ public:
Settings& settings() const { return *m_settings; }
ProgressTracker& progress() const { return *m_progress; }
BackForwardController* backForward() const { return m_backForwardController.get(); }
BackForwardController& backForward() const { return *m_backForwardController; }
FeatureObserver* featureObserver() { return &m_featureObserver; }
......@@ -463,7 +463,7 @@ private:
const RefPtr<Settings> m_settings;
const OwnPtr<ProgressTracker> m_progress;
OwnPtr<BackForwardController> m_backForwardController;
const OwnPtr<BackForwardController> m_backForwardController;
const RefPtr<Frame> m_mainFrame;
mutable RefPtr<PluginData> m_pluginData;
......
......@@ -468,10 +468,10 @@ void Settings::setUsesPageCache(bool usesPageCache)
m_usesPageCache = usesPageCache;
if (!m_usesPageCache) {
int first = -m_page->backForward()->backCount();
int last = m_page->backForward()->forwardCount();
int first = -m_page->backForward().backCount();
int last = m_page->backForward().forwardCount();
for (int i = first; i <= last; i++)
pageCache()->remove(m_page->backForward()->itemAtIndex(i));
pageCache()->remove(m_page->backForward().itemAtIndex(i));
}
}
......
......@@ -977,7 +977,7 @@ void WebFrameLoaderClient::updateGlobalHistoryItemForPage()
if (Page* page = core(m_webFrame.get())->page()) {
if (!page->settings().privateBrowsingEnabled())
historyItem = page->backForward()->currentItem();
historyItem = page->backForward().currentItem();
}
WebView *webView = getWebView(m_webFrame.get());
......
......@@ -825,7 +825,7 @@ void WebFrameLoaderClient::updateGlobalHistoryItemForPage()
if (Page* page = webView->page()) {
if (!page->settings().privateBrowsingEnabled())
historyItem = page->backForward()->currentItem();
historyItem = page->backForward().currentItem();
}
webView->setGlobalHistoryItem(historyItem);
......
......@@ -43,7 +43,7 @@ PassRefPtr<InjectedBundleBackForwardListItem> InjectedBundleBackForwardList::ite
Page* page = m_page->corePage();
if (!page)
return 0;
return InjectedBundleBackForwardListItem::create(page->backForward()->itemAtIndex(index));
return InjectedBundleBackForwardListItem::create(page->backForward().itemAtIndex(index));
}
int InjectedBundleBackForwardList::backListCount() const
......@@ -53,7 +53,7 @@ int InjectedBundleBackForwardList::backListCount() const
Page* page = m_page->corePage();
if (!page)
return 0;
return page->backForward()->backCount();
return page->backForward().backCount();
}
int InjectedBundleBackForwardList::forwardListCount() const
......@@ -63,7 +63,7 @@ int InjectedBundleBackForwardList::forwardListCount() const
Page* page = m_page->corePage();
if (!page)
return 0;
return page->backForward()->forwardCount();
return page->backForward().forwardCount();
}
void InjectedBundleBackForwardList::clear()
......@@ -73,7 +73,7 @@ void InjectedBundleBackForwardList::clear()
Page* page = m_page->corePage();
if (!page)
return;
static_cast<WebBackForwardListProxy*>(page->backForward()->client())->clear();
static_cast<WebBackForwardListProxy*>(page->backForward().client())->clear();
}
} // namespace WebKit
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment