summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tabs
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-18 16:17:49 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-18 16:17:49 +0000
commit3c9e187bd8ec34ebf2a91a37c868584c465647e8 (patch)
tree84c9540d220fa155cf2af8c944638c0719dee670 /chrome/browser/tabs
parent3e35b224fd0c36f17f432f23e2eb3729667210b1 (diff)
downloadchromium_src-3c9e187bd8ec34ebf2a91a37c868584c465647e8.zip
chromium_src-3c9e187bd8ec34ebf2a91a37c868584c465647e8.tar.gz
chromium_src-3c9e187bd8ec34ebf2a91a37c868584c465647e8.tar.bz2
Make pink's TabContentsWrapper change compile on Windows.
Code by pinkerton@, with modifications by evanm and myself to get it to build on windows/linux/chromeos. BUG=none TEST=none Review URL: http://codereview.chromium.org/4694008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66626 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tabs')
-rw-r--r--chrome/browser/tabs/default_tab_handler.cc37
-rw-r--r--chrome/browser/tabs/default_tab_handler.h52
-rw-r--r--chrome/browser/tabs/pinned_tab_codec.cc3
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc104
-rw-r--r--chrome/browser/tabs/tab_strip_model.h56
-rw-r--r--chrome/browser/tabs/tab_strip_model_delegate.h15
-rw-r--r--chrome/browser/tabs/tab_strip_model_observer.cc29
-rw-r--r--chrome/browser/tabs/tab_strip_model_observer.h28
-rw-r--r--chrome/browser/tabs/tab_strip_model_order_controller.cc13
-rw-r--r--chrome/browser/tabs/tab_strip_model_order_controller.h8
-rw-r--r--chrome/browser/tabs/tab_strip_model_unittest.cc329
11 files changed, 368 insertions, 306 deletions
diff --git a/chrome/browser/tabs/default_tab_handler.cc b/chrome/browser/tabs/default_tab_handler.cc
index a68466a..b98bdef 100644
--- a/chrome/browser/tabs/default_tab_handler.cc
+++ b/chrome/browser/tabs/default_tab_handler.cc
@@ -34,17 +34,18 @@ TabStripModel* DefaultTabHandler::GetTabStripModel() const {
////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, TabStripModelDelegate implementation:
-TabContents* DefaultTabHandler::AddBlankTab(bool foreground) {
+TabContentsWrapper* DefaultTabHandler::AddBlankTab(bool foreground) {
UmaNaclHistogramEnumeration(NEW_TAB_NACL_BASELINE);
return delegate_->AsBrowser()->AddBlankTab(foreground);
}
-TabContents* DefaultTabHandler::AddBlankTabAt(int index, bool foreground) {
+TabContentsWrapper* DefaultTabHandler::AddBlankTabAt(int index,
+ bool foreground) {
return delegate_->AsBrowser()->AddBlankTabAt(index, foreground);
}
Browser* DefaultTabHandler::CreateNewStripWithContents(
- TabContents* detached_contents,
+ TabContentsWrapper* detached_contents,
const gfx::Rect& window_bounds,
const DockInfo& dock_info,
bool maximize) {
@@ -55,7 +56,7 @@ Browser* DefaultTabHandler::CreateNewStripWithContents(
}
void DefaultTabHandler::ContinueDraggingDetachedTab(
- TabContents* contents,
+ TabContentsWrapper* contents,
const gfx::Rect& window_bounds,
const gfx::Rect& tab_bounds) {
delegate_->AsBrowser()->ContinueDraggingDetachedTab(contents,
@@ -67,7 +68,7 @@ int DefaultTabHandler::GetDragActions() const {
return delegate_->AsBrowser()->GetDragActions();
}
-TabContents* DefaultTabHandler::CreateTabContentsForURL(
+TabContentsWrapper* DefaultTabHandler::CreateTabContentsForURL(
const GURL& url,
const GURL& referrer,
Profile* profile,
@@ -94,11 +95,12 @@ void DefaultTabHandler::CloseFrameAfterDragSession() {
delegate_->AsBrowser()->CloseFrameAfterDragSession();
}
-void DefaultTabHandler::CreateHistoricalTab(TabContents* contents) {
+void DefaultTabHandler::CreateHistoricalTab(TabContentsWrapper* contents) {
delegate_->AsBrowser()->CreateHistoricalTab(contents);
}
-bool DefaultTabHandler::RunUnloadListenerBeforeClosing(TabContents* contents) {
+bool DefaultTabHandler::RunUnloadListenerBeforeClosing(
+ TabContentsWrapper* contents) {
return delegate_->AsBrowser()->RunUnloadListenerBeforeClosing(contents);
}
@@ -141,28 +143,29 @@ bool DefaultTabHandler::UseVerticalTabs() const {
////////////////////////////////////////////////////////////////////////////////
// DefaultTabHandler, TabStripModelObserver implementation:
-void DefaultTabHandler::TabInsertedAt(TabContents* contents,
+void DefaultTabHandler::TabInsertedAt(TabContentsWrapper* contents,
int index,
bool foreground) {
delegate_->AsBrowser()->TabInsertedAt(contents, index, foreground);
}
void DefaultTabHandler::TabClosingAt(TabStripModel* tab_strip_model,
- TabContents* contents,
+ TabContentsWrapper* contents,
int index) {
delegate_->AsBrowser()->TabClosingAt(tab_strip_model, contents, index);
}
-void DefaultTabHandler::TabDetachedAt(TabContents* contents, int index) {
+void DefaultTabHandler::TabDetachedAt(TabContentsWrapper* contents, int index) {
delegate_->AsBrowser()->TabDetachedAt(contents, index);
}
-void DefaultTabHandler::TabDeselectedAt(TabContents* contents, int index) {
+void DefaultTabHandler::TabDeselectedAt(TabContentsWrapper* contents,
+ int index) {
delegate_->AsBrowser()->TabDeselectedAt(contents, index);
}
-void DefaultTabHandler::TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
+void DefaultTabHandler::TabSelectedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index,
bool user_gesture) {
delegate_->AsBrowser()->TabSelectedAt(old_contents,
@@ -171,19 +174,19 @@ void DefaultTabHandler::TabSelectedAt(TabContents* old_contents,
user_gesture);
}
-void DefaultTabHandler::TabMoved(TabContents* contents,
+void DefaultTabHandler::TabMoved(TabContentsWrapper* contents,
int from_index,
int to_index) {
delegate_->AsBrowser()->TabMoved(contents, from_index, to_index);
}
-void DefaultTabHandler::TabReplacedAt(TabContents* old_contents,
- TabContents* new_contents,
+void DefaultTabHandler::TabReplacedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index) {
delegate_->AsBrowser()->TabReplacedAt(old_contents, new_contents, index);
}
-void DefaultTabHandler::TabPinnedStateChanged(TabContents* contents,
+void DefaultTabHandler::TabPinnedStateChanged(TabContentsWrapper* contents,
int index) {
delegate_->AsBrowser()->TabPinnedStateChanged(contents, index);
}
diff --git a/chrome/browser/tabs/default_tab_handler.h b/chrome/browser/tabs/default_tab_handler.h
index f8e2fde..79f1af6 100644
--- a/chrome/browser/tabs/default_tab_handler.h
+++ b/chrome/browser/tabs/default_tab_handler.h
@@ -25,27 +25,29 @@ class DefaultTabHandler : public TabHandler,
virtual TabStripModel* GetTabStripModel() const;
// Overridden from TabStripModelDelegate:
- virtual TabContents* AddBlankTab(bool foreground);
- virtual TabContents* AddBlankTabAt(int index, bool foreground);
- virtual Browser* CreateNewStripWithContents(TabContents* detached_contents,
- const gfx::Rect& window_bounds,
- const DockInfo& dock_info,
- bool maximize);
- virtual void ContinueDraggingDetachedTab(TabContents* contents,
+ virtual TabContentsWrapper* AddBlankTab(bool foreground);
+ virtual TabContentsWrapper* AddBlankTabAt(int index, bool foreground);
+ virtual Browser* CreateNewStripWithContents(
+ TabContentsWrapper* detached_contents,
+ const gfx::Rect& window_bounds,
+ const DockInfo& dock_info,
+ bool maximize);
+ virtual void ContinueDraggingDetachedTab(TabContentsWrapper* contents,
const gfx::Rect& window_bounds,
const gfx::Rect& tab_bounds);
virtual int GetDragActions() const;
- virtual TabContents* CreateTabContentsForURL(const GURL& url,
- const GURL& referrer,
- Profile* profile,
- PageTransition::Type transition,
- bool defer_load,
- SiteInstance* instance) const;
+ virtual TabContentsWrapper* CreateTabContentsForURL(
+ const GURL& url,
+ const GURL& referrer,
+ Profile* profile,
+ PageTransition::Type transition,
+ bool defer_load,
+ SiteInstance* instance) const;
virtual bool CanDuplicateContentsAt(int index);
virtual void DuplicateContentsAt(int index);
virtual void CloseFrameAfterDragSession();
- virtual void CreateHistoricalTab(TabContents* contents);
- virtual bool RunUnloadListenerBeforeClosing(TabContents* contents);
+ virtual void CreateHistoricalTab(TabContentsWrapper* contents);
+ virtual bool RunUnloadListenerBeforeClosing(TabContentsWrapper* contents);
virtual bool CanCloseContentsAt(int index);
virtual bool CanBookmarkAllTabs() const;
virtual void BookmarkAllTabs();
@@ -57,25 +59,25 @@ class DefaultTabHandler : public TabHandler,
virtual bool UseVerticalTabs() const;
// Overridden from TabStripModelObserver:
- virtual void TabInsertedAt(TabContents* contents,
+ virtual void TabInsertedAt(TabContentsWrapper* contents,
int index,
bool foreground);
virtual void TabClosingAt(TabStripModel* tab_strip_model,
- TabContents* contents,
+ TabContentsWrapper* contents,
int index);
- virtual void TabDetachedAt(TabContents* contents, int index);
- virtual void TabDeselectedAt(TabContents* contents, int index);
- virtual void TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
+ virtual void TabDetachedAt(TabContentsWrapper* contents, int index);
+ virtual void TabDeselectedAt(TabContentsWrapper* contents, int index);
+ virtual void TabSelectedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index,
bool user_gesture);
- virtual void TabMoved(TabContents* contents,
+ virtual void TabMoved(TabContentsWrapper* contents,
int from_index,
int to_index);
- virtual void TabReplacedAt(TabContents* old_contents,
- TabContents* new_contents,
+ virtual void TabReplacedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index);
- virtual void TabPinnedStateChanged(TabContents* contents, int index);
+ virtual void TabPinnedStateChanged(TabContentsWrapper* contents, int index);
virtual void TabStripEmpty();
private:
diff --git a/chrome/browser/tabs/pinned_tab_codec.cc b/chrome/browser/tabs/pinned_tab_codec.cc
index 9afaf51..08264b2 100644
--- a/chrome/browser/tabs/pinned_tab_codec.cc
+++ b/chrome/browser/tabs/pinned_tab_codec.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents_wrapper.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/extensions/extension.h"
@@ -41,7 +42,7 @@ static void EncodePinnedTab(TabStripModel* model,
ListValue* values) {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
- TabContents* tab_contents = model->GetTabContentsAt(index);
+ TabContentsWrapper* tab_contents = model->GetTabContentsAt(index);
if (model->IsAppTab(index)) {
const Extension* extension = tab_contents->extension_app();
DCHECK(extension);
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 711fe49..1341578 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/tabs/tab_strip_model_order_controller.h"
+#include "chrome/browser/tab_contents_wrapper.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
@@ -103,7 +104,8 @@ bool TabStripModel::ContainsIndex(int index) const {
return index >= 0 && index < count();
}
-void TabStripModel::AppendTabContents(TabContents* contents, bool foreground) {
+void TabStripModel::AppendTabContents(TabContentsWrapper* contents,
+ bool foreground) {
int index = order_controller_->DetermineInsertionIndexForAppending();
InsertTabContentsAt(index, contents,
foreground ? (ADD_INHERIT_GROUP | ADD_SELECTED) :
@@ -111,7 +113,7 @@ void TabStripModel::AppendTabContents(TabContents* contents, bool foreground) {
}
void TabStripModel::InsertTabContentsAt(int index,
- TabContents* contents,
+ TabContentsWrapper* contents,
int add_types) {
bool foreground = add_types & ADD_SELECTED;
// Force app tabs to be pinned.
@@ -127,7 +129,7 @@ void TabStripModel::InsertTabContentsAt(int index,
// Have to get the selected contents before we monkey with |contents_|
// otherwise we run into problems when we try to change the selected contents
// since the old contents and the new contents will be the same...
- TabContents* selected_contents = GetSelectedTabContents();
+ TabContentsWrapper* selected_contents = GetSelectedTabContents();
TabContentsData* data = new TabContentsData(contents);
data->pinned = pin;
if ((add_types & ADD_INHERIT_GROUP) && selected_contents) {
@@ -162,11 +164,12 @@ void TabStripModel::InsertTabContentsAt(int index,
ChangeSelectedContentsFrom(selected_contents, index, false);
}
-void TabStripModel::ReplaceTabContentsAt(int index, TabContents* new_contents) {
+void TabStripModel::ReplaceTabContentsAt(int index,
+ TabContentsWrapper* new_contents) {
// TODO: this should reset group/opener of any tabs that point at
// old_contents.
DCHECK(ContainsIndex(index));
- scoped_ptr<TabContents> old_contents(GetContentsAt(index));
+ scoped_ptr<TabContentsWrapper> old_contents(GetContentsAt(index));
contents_data_[index]->contents = new_contents;
@@ -184,25 +187,25 @@ void TabStripModel::ReplaceTabContentsAt(int index, TabContents* new_contents) {
}
void TabStripModel::ReplaceNavigationControllerAt(
- int index, NavigationController* controller) {
+ int index, TabContentsWrapper* contents) {
// This appears to be OK with no flicker since no redraw event
// occurs between the call to add an aditional tab and one to close
// the previous tab.
InsertTabContentsAt(
- index + 1, controller->tab_contents(),
+ index + 1, contents,
ADD_SELECTED | ADD_INHERIT_GROUP);
std::vector<int> closing_tabs;
closing_tabs.push_back(index);
InternalCloseTabs(closing_tabs, CLOSE_NONE);
}
-TabContents* TabStripModel::DetachTabContentsAt(int index) {
+TabContentsWrapper* TabStripModel::DetachTabContentsAt(int index) {
if (contents_data_.empty())
return NULL;
DCHECK(ContainsIndex(index));
- TabContents* removed_contents = GetContentsAt(index);
+ TabContentsWrapper* removed_contents = GetContentsAt(index);
int next_selected_index = order_controller_->DetermineNewSelectedIndex(index);
delete contents_data_.at(index);
contents_data_.erase(contents_data_.begin() + index);
@@ -248,17 +251,18 @@ void TabStripModel::MoveTabContentsAt(int index, int to_position,
MoveTabContentsAtImpl(index, to_position, select_after_move);
}
-TabContents* TabStripModel::GetSelectedTabContents() const {
+TabContentsWrapper* TabStripModel::GetSelectedTabContents() const {
return GetTabContentsAt(selected_index_);
}
-TabContents* TabStripModel::GetTabContentsAt(int index) const {
+TabContentsWrapper* TabStripModel::GetTabContentsAt(int index) const {
if (ContainsIndex(index))
return GetContentsAt(index);
return NULL;
}
-int TabStripModel::GetIndexOfTabContents(const TabContents* contents) const {
+int TabStripModel::GetIndexOfTabContents(
+ const TabContentsWrapper* contents) const {
int index = 0;
TabContentsDataVector::const_iterator iter = contents_data_.begin();
for (; iter != contents_data_.end(); ++iter, ++index) {
@@ -268,6 +272,16 @@ int TabStripModel::GetIndexOfTabContents(const TabContents* contents) const {
return kNoTab;
}
+int TabStripModel::GetWrapperIndex(const TabContents* contents) const {
+ int index = 0;
+ TabContentsDataVector::const_iterator iter = contents_data_.begin();
+ for (; iter != contents_data_.end(); ++iter, ++index) {
+ if ((*iter)->contents->tab_contents() == contents)
+ return index;
+ }
+ return kNoTab;
+}
+
int TabStripModel::GetIndexOfController(
const NavigationController* controller) const {
int index = 0;
@@ -307,7 +321,7 @@ bool TabStripModel::CloseTabContentsAt(int index, uint32 close_types) {
bool TabStripModel::TabsAreLoading() const {
TabContentsDataVector::const_iterator iter = contents_data_.begin();
for (; iter != contents_data_.end(); ++iter) {
- if ((*iter)->contents->is_loading())
+ if ((*iter)->contents->tab_contents()->is_loading())
return true;
}
return false;
@@ -368,7 +382,7 @@ int TabStripModel::GetIndexOfLastTabContentsOpenedBy(
return kNoTab;
}
-void TabStripModel::TabNavigating(TabContents* contents,
+void TabStripModel::TabNavigating(TabContentsWrapper* contents,
PageTransition::Type transition) {
if (ShouldForgetOpenersForTransition(transition)) {
// Don't forget the openers if this tab is a New Tab page opened at the
@@ -398,14 +412,15 @@ void TabStripModel::ForgetAllOpeners() {
(*iter)->ForgetOpener();
}
-void TabStripModel::ForgetGroup(TabContents* contents) {
+void TabStripModel::ForgetGroup(TabContentsWrapper* contents) {
int index = GetIndexOfTabContents(contents);
DCHECK(ContainsIndex(index));
contents_data_.at(index)->SetGroup(NULL);
contents_data_.at(index)->ForgetOpener();
}
-bool TabStripModel::ShouldResetGroupOnSelect(TabContents* contents) const {
+bool TabStripModel::ShouldResetGroupOnSelect(
+ TabContentsWrapper* contents) const {
int index = GetIndexOfTabContents(contents);
DCHECK(ContainsIndex(index));
return contents_data_.at(index)->reset_group_on_select;
@@ -469,7 +484,7 @@ bool TabStripModel::IsMiniTab(int index) const {
}
bool TabStripModel::IsAppTab(int index) const {
- TabContents* contents = GetTabContentsAt(index);
+ TabContentsWrapper* contents = GetTabContentsAt(index);
return contents && contents->is_app();
}
@@ -491,7 +506,7 @@ int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) {
std::min(count(), std::max(index, IndexOfFirstNonMiniTab()));
}
-void TabStripModel::AddTabContents(TabContents* contents,
+void TabStripModel::AddTabContents(TabContentsWrapper* contents,
int index,
PageTransition::Type transition,
int add_types) {
@@ -545,13 +560,15 @@ void TabStripModel::AddTabContents(TabContents* contents,
// initial layout and not recalculated later, we need to ensure the first
// layout is performed with sane view dimensions even when we're opening a
// new background tab.
- if (TabContents* old_contents = GetSelectedTabContents()) {
+ if (TabContentsWrapper* old_contents = GetSelectedTabContents()) {
if ((add_types & ADD_SELECTED) == 0) {
- contents->view()->SizeContents(old_contents->view()->GetContainerSize());
+ contents->tab_contents()->view()->
+ SizeContents(old_contents->tab_contents()->
+ view()->GetContainerSize());
// We need to hide the contents or else we get and execute paints for
// background tabs. With enough background tabs they will steal the
// backing store of the visible tab causing flashing. See bug 20831.
- contents->HideContents();
+ contents->tab_contents()->HideContents();
}
}
}
@@ -591,8 +608,9 @@ bool TabStripModel::IsContextMenuCommandEnabled(
case CommandCloseTab:
return delegate_->CanCloseTab();
case CommandReload:
- if (TabContents* contents = GetTabContentsAt(context_index)) {
- return contents->delegate()->CanReloadContents(contents);
+ if (TabContentsWrapper* contents = GetTabContentsAt(context_index)) {
+ return contents->tab_contents()->
+ delegate()->CanReloadContents(contents->tab_contents());
} else {
return false;
}
@@ -746,7 +764,7 @@ void TabStripModel::Observe(NotificationType type,
// Sometimes, on qemu, it seems like a TabContents object can be destroyed
// while we still have a reference to it. We need to break this reference
// here so we don't crash later.
- int index = GetIndexOfTabContents(Source<TabContents>(source).ptr());
+ int index = GetWrapperIndex(Source<TabContents>(source).ptr());
if (index != TabStripModel::kNoTab) {
// Note that we only detach the contents here, not close it - it's
// already been closed. We just want to undo our bookkeeping.
@@ -759,7 +777,7 @@ void TabStripModel::Observe(NotificationType type,
const Extension* extension = Details<const Extension>(details).ptr();
// Iterate backwards as we may remove items while iterating.
for (int i = count() - 1; i >= 0; i--) {
- TabContents* contents = GetTabContentsAt(i);
+ TabContentsWrapper* contents = GetTabContentsAt(i);
if (contents->extension_app() == extension) {
// The extension an app tab was created from has been nuked. Delete
// the TabContents. Deleting a TabContents results in a notification
@@ -780,8 +798,9 @@ void TabStripModel::Observe(NotificationType type,
///////////////////////////////////////////////////////////////////////////////
// TabStripModel, private:
-bool TabStripModel::IsNewTabAtEndOfTabStrip(TabContents* contents) const {
- return LowerCaseEqualsASCII(contents->GetURL().spec(),
+bool TabStripModel::IsNewTabAtEndOfTabStrip(
+ TabContentsWrapper* contents) const {
+ return LowerCaseEqualsASCII(contents->tab_contents()->GetURL().spec(),
chrome::kChromeUINewTabURL) &&
contents == GetContentsAt(count() - 1) &&
contents->controller().entry_count() == 1;
@@ -797,7 +816,7 @@ bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices,
// Map the indices to TabContents, that way if deleting a tab deletes other
// tabs we're ok. Crashes seem to indicate during tab deletion other tabs are
// getting removed.
- std::vector<TabContents*> tabs;
+ std::vector<TabContentsWrapper*> tabs;
for (size_t i = 0; i < indices.size(); ++i)
tabs.push_back(GetContentsAt(indices[i]));
@@ -814,8 +833,9 @@ bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices,
continue;
}
- TabContents* detached_contents = GetContentsAt(indices[i]);
- RenderProcessHost* process = detached_contents->GetRenderProcessHost();
+ TabContentsWrapper* detached_contents = GetContentsAt(indices[i]);
+ RenderProcessHost* process =
+ detached_contents->tab_contents()->GetRenderProcessHost();
std::map<RenderProcessHost*, size_t>::iterator iter =
processes.find(process);
if (iter == processes.end()) {
@@ -835,13 +855,13 @@ bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices,
// We now return to our regularly scheduled shutdown procedure.
for (size_t i = 0; i < tabs.size(); ++i) {
- TabContents* detached_contents = tabs[i];
+ TabContentsWrapper* detached_contents = tabs[i];
int index = GetIndexOfTabContents(detached_contents);
// Make sure we still contain the tab.
if (index == kNoTab)
continue;
- detached_contents->OnCloseStarted();
+ detached_contents->tab_contents()->OnCloseStarted();
if (!delegate_->CanCloseContentsAt(index)) {
retval = false;
@@ -852,8 +872,8 @@ bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices,
// close the state is reset in Browser. We don't update the explicitly
// closed state if already marked as explicitly closed as unload handlers
// call back to this if the close is allowed.
- if (!detached_contents->closed_by_user_gesture()) {
- detached_contents->set_closed_by_user_gesture(
+ if (!detached_contents->tab_contents()->closed_by_user_gesture()) {
+ detached_contents->tab_contents()->set_closed_by_user_gesture(
close_types & CLOSE_USER_GESTURE);
}
@@ -869,7 +889,7 @@ bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices,
return retval;
}
-void TabStripModel::InternalCloseTab(TabContents* contents,
+void TabStripModel::InternalCloseTab(TabContentsWrapper* contents,
int index,
bool create_historical_tabs) {
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
@@ -885,28 +905,34 @@ void TabStripModel::InternalCloseTab(TabContents* contents,
delete contents;
}
-TabContents* TabStripModel::GetContentsAt(int index) const {
+TabContentsWrapper* TabStripModel::GetContentsAt(int index) const {
CHECK(ContainsIndex(index)) <<
"Failed to find: " << index << " in: " << count() << " entries.";
return contents_data_.at(index)->contents;
}
void TabStripModel::ChangeSelectedContentsFrom(
- TabContents* old_contents, int to_index, bool user_gesture) {
- TabContents* new_contents = GetContentsAt(to_index);
+ TabContentsWrapper* old_contents, int to_index, bool user_gesture) {
+ TabContentsWrapper* new_contents = GetContentsAt(to_index);
if (old_contents == new_contents)
return;
- TabContents* last_selected_contents = old_contents;
+ TabContentsWrapper* last_selected_contents = old_contents;
if (last_selected_contents) {
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
TabDeselectedAt(last_selected_contents, selected_index_));
}
selected_index_ = to_index;
+ ObserverListBase<TabStripModelObserver>::Iterator it(observers_);
+ TabStripModelObserver* obs;
+ while ((obs = it.GetNext()) != NULL)
+ obs->TabSelectedAt(last_selected_contents, new_contents, selected_index_, user_gesture);
+ /*
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
TabSelectedAt(last_selected_contents, new_contents, selected_index_,
user_gesture));
+ */
}
void TabStripModel::SelectRelativeTab(bool next) {
diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h
index 3e7a98d..8d385cb 100644
--- a/chrome/browser/tabs/tab_strip_model.h
+++ b/chrome/browser/tabs/tab_strip_model.h
@@ -17,6 +17,7 @@
class NavigationController;
class Profile;
class TabContents;
+class TabContentsWrapper;
class TabStripModelDelegate;
class TabStripModelOrderController;
@@ -159,7 +160,7 @@ class TabStripModel : public NotificationObserver {
// Adds the specified TabContents in the default location. Tabs opened in the
// foreground inherit the group of the previously selected tab.
- void AppendTabContents(TabContents* contents, bool foreground);
+ void AppendTabContents(TabContentsWrapper* contents, bool foreground);
// Adds the specified TabContents at the specified location. |add_types| is a
// bitmask of AddTypes; see it for details.
@@ -172,7 +173,7 @@ class TabStripModel : public NotificationObserver {
// constraint that all mini-tabs occur before non-mini-tabs.
// See also AddTabContents.
void InsertTabContentsAt(int index,
- TabContents* contents,
+ TabContentsWrapper* contents,
int add_types);
// Closes the TabContents at the specified index. This causes the TabContents
@@ -190,18 +191,19 @@ class TabStripModel : public NotificationObserver {
//
// The old NavigationController is deallocated and this object takes
// ownership of the passed in controller.
+ // XXXPINK This API is weird and wrong. Remove it or change it or rename it?
void ReplaceNavigationControllerAt(int index,
- NavigationController* controller);
+ TabContentsWrapper* contents);
// Replaces the tab contents at |index| with |new_contents|. This deletes the
// TabContents currently at |index|.
- void ReplaceTabContentsAt(int index, TabContents* new_contents);
+ void ReplaceTabContentsAt(int index, TabContentsWrapper* new_contents);
// Detaches the TabContents at the specified index from this strip. The
// TabContents is not destroyed, just removed from display. The caller is
// responsible for doing something with it (e.g. stuffing it into another
// strip).
- TabContents* DetachTabContentsAt(int index);
+ TabContentsWrapper* DetachTabContentsAt(int index);
// Select the TabContents at the specified index. |user_gesture| is true if
// the user actually clicked on the tab or navigated to it using a keyboard
@@ -220,16 +222,25 @@ class TabStripModel : public NotificationObserver {
void MoveTabContentsAt(int index, int to_position, bool select_after_move);
// Returns the currently selected TabContents, or NULL if there is none.
- TabContents* GetSelectedTabContents() const;
+ TabContentsWrapper* GetSelectedTabContents() const;
- // Returns the TabContents at the specified index, or NULL if there is none.
- TabContents* GetTabContentsAt(int index) const;
+ // Returns the TabContentsWrapper at the specified index, or NULL if there is
+ // none.
+ TabContentsWrapper* GetTabContentsAt(int index) const;
- // Returns the index of the specified TabContents, or TabContents::kNoTab if
- // the TabContents is not in this TabStripModel.
- int GetIndexOfTabContents(const TabContents* contents) const;
+ // Returns the index of the specified TabContents wrapper, or
+ // TabStripModel::kNoTab if the TabContents is not in this TabStripModel.
+ int GetIndexOfTabContents(const TabContentsWrapper* contents) const;
- // Returns the index of the specified NavigationController, or -1 if it is
+ // Returns the index of the specified TabContents wrapper given its raw
+ // TabContents, or TabStripModel::kNoTab if the TabContents is not in this
+ // TabStripModel. Note: This is only needed in rare cases where the wrapper
+ // is not already present (such as implementing TabContentsDelegate methods,
+ // which don't know about the wrapper. Returns NULL if |contents| is not
+ // associated with any wrapper in the model.
+ int GetWrapperIndex(const TabContents* contents) const;
+
+ // Returns the index of the specified NavigationController, or kNoTab if it is
// not in this TabStripModel.
int GetIndexOfController(const NavigationController* controller) const;
@@ -278,7 +289,8 @@ class TabStripModel : public NotificationObserver {
// TabContents. Depending on the tab, and the transition type of the
// navigation, the TabStripModel may adjust its selection and grouping
// behavior.
- void TabNavigating(TabContents* contents, PageTransition::Type transition);
+ void TabNavigating(TabContentsWrapper* contents,
+ PageTransition::Type transition);
// Forget all Opener relationships that are stored (but _not_ group
// relationships!) This is to reduce unpredictable tab switching behavior
@@ -292,11 +304,11 @@ class TabStripModel : public NotificationObserver {
// moved to a new logical context by the user (e.g. by typing a new URL or
// selecting a bookmark). This also forgets the opener, which is considered
// a weaker relationship than group.
- void ForgetGroup(TabContents* contents);
+ void ForgetGroup(TabContentsWrapper* contents);
// Returns true if the group/opener relationships present for |contents|
// should be reset when _any_ selection change occurs in the model.
- bool ShouldResetGroupOnSelect(TabContents* contents) const;
+ bool ShouldResetGroupOnSelect(TabContentsWrapper* contents) const;
// Changes the blocked state of the tab at |index|.
void SetTabBlocked(int index, bool blocked);
@@ -338,7 +350,7 @@ class TabStripModel : public NotificationObserver {
// specified insertion index, transition, etc. |add_types| is a bitmask of
// AddTypes; see it for details. This method ends up calling into
// InsertTabContentsAt to do the actual inertion.
- void AddTabContents(TabContents* contents,
+ void AddTabContents(TabContentsWrapper* contents,
int index,
PageTransition::Type transition,
int add_types);
@@ -408,7 +420,7 @@ class TabStripModel : public NotificationObserver {
// forgotten for the New Tab page opened as a result of a New Tab gesture
// (e.g. Ctrl+T, etc) since the user may open a tab transiently to look up
// something related to their current activity.
- bool IsNewTabAtEndOfTabStrip(TabContents* contents) const;
+ bool IsNewTabAtEndOfTabStrip(TabContentsWrapper* contents) const;
// Closes the TabContents at the specified indices. This causes the
// TabContents to be destroyed, but it may not happen immediately. If the
@@ -428,18 +440,18 @@ class TabStripModel : public NotificationObserver {
// The boolean parameter create_historical_tab controls whether to
// record these tabs and their history for reopening recently closed
// tabs.
- void InternalCloseTab(TabContents* contents,
+ void InternalCloseTab(TabContentsWrapper* contents,
int index,
bool create_historical_tabs);
- TabContents* GetContentsAt(int index) const;
+ TabContentsWrapper* GetContentsAt(int index) const;
// The actual implementation of SelectTabContentsAt. Takes the previously
// selected contents in |old_contents|, which may actually not be in
// |contents_| anymore because it may have been removed by a call to say
// DetachTabContentsAt...
void ChangeSelectedContentsFrom(
- TabContents* old_contents, int to_index, bool user_gesture);
+ TabContentsWrapper* old_contents, int to_index, bool user_gesture);
// Returns the number of New Tab tabs in the TabStripModel.
int GetNewTabCount() const;
@@ -470,7 +482,7 @@ class TabStripModel : public NotificationObserver {
// the TabContents is in the current TabStripModel, unless otherwise
// specified in code.
struct TabContentsData {
- explicit TabContentsData(TabContents* a_contents)
+ explicit TabContentsData(TabContentsWrapper* a_contents)
: contents(a_contents),
reset_group_on_select(false),
pinned(false),
@@ -491,7 +503,7 @@ class TabStripModel : public NotificationObserver {
opener = NULL;
}
- TabContents* contents;
+ TabContentsWrapper* contents;
// We use NavigationControllers here since they more closely model the
// "identity" of a Tab, TabContents can change depending on the URL loaded
// in the Tab.
diff --git a/chrome/browser/tabs/tab_strip_model_delegate.h b/chrome/browser/tabs/tab_strip_model_delegate.h
index 4901bbe..c6cb6ae 100644
--- a/chrome/browser/tabs/tab_strip_model_delegate.h
+++ b/chrome/browser/tabs/tab_strip_model_delegate.h
@@ -14,6 +14,7 @@ class GURL;
class Profile;
class SiteInstance;
class TabContents;
+class TabContentsWrapper;
namespace gfx {
class Rect;
}
@@ -38,8 +39,8 @@ class TabStripModelDelegate {
};
// Adds what the delegate considers to be a blank tab to the model.
- virtual TabContents* AddBlankTab(bool foreground) = 0;
- virtual TabContents* AddBlankTabAt(int index, bool foreground) = 0;
+ virtual TabContentsWrapper* AddBlankTab(bool foreground) = 0;
+ virtual TabContentsWrapper* AddBlankTabAt(int index, bool foreground) = 0;
// Asks for a new TabStripModel to be created and the given tab contents to
// be added to it. Its size and position are reflected in |window_bounds|.
@@ -47,7 +48,7 @@ class TabStripModelDelegate {
// be docked as identified by |dock_info|. Returns the Browser object
// representing the newly created window and tab strip. This does not
// show the window, it's up to the caller to do so.
- virtual Browser* CreateNewStripWithContents(TabContents* contents,
+ virtual Browser* CreateNewStripWithContents(TabContentsWrapper* contents,
const gfx::Rect& window_bounds,
const DockInfo& dock_info,
bool maximize) = 0;
@@ -58,7 +59,7 @@ class TabStripModelDelegate {
// screen coordinates, used to place the new window, and |tab_bounds| are the
// bounds of the dragged Tab view in the source window, in screen coordinates,
// used to place the new Tab in the new window.
- virtual void ContinueDraggingDetachedTab(TabContents* contents,
+ virtual void ContinueDraggingDetachedTab(TabContentsWrapper* contents,
const gfx::Rect& window_bounds,
const gfx::Rect& tab_bounds) = 0;
@@ -70,7 +71,7 @@ class TabStripModelDelegate {
// exist for it to be constructed (e.g. a parent HWND).
// If |defer_load| is true, the navigation controller doesn't load the url.
// If |instance| is not null, its process is used to render the tab.
- virtual TabContents* CreateTabContentsForURL(
+ virtual TabContentsWrapper* CreateTabContentsForURL(
const GURL& url,
const GURL& referrer,
Profile* profile,
@@ -91,14 +92,14 @@ class TabStripModelDelegate {
// Creates an entry in the historical tab database for the specified
// TabContents.
- virtual void CreateHistoricalTab(TabContents* contents) = 0;
+ virtual void CreateHistoricalTab(TabContentsWrapper* contents) = 0;
// Runs any unload listeners associated with the specified TabContents before
// it is closed. If there are unload listeners that need to be run, this
// function returns true and the TabStripModel will wait before closing the
// TabContents. If it returns false, there are no unload listeners and the
// TabStripModel can close the TabContents immediately.
- virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) = 0;
+ virtual bool RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) = 0;
// Returns true if a tab can be restored.
virtual bool CanRestoreTab() = 0;
diff --git a/chrome/browser/tabs/tab_strip_model_observer.cc b/chrome/browser/tabs/tab_strip_model_observer.cc
index af5f899..8ba8814 100644
--- a/chrome/browser/tabs/tab_strip_model_observer.cc
+++ b/chrome/browser/tabs/tab_strip_model_observer.cc
@@ -4,51 +4,54 @@
#include "chrome/browser/tabs/tab_strip_model_observer.h"
-void TabStripModelObserver::TabInsertedAt(TabContents* contents,
+void TabStripModelObserver::TabInsertedAt(TabContentsWrapper* contents,
int index,
bool foreground) {
}
void TabStripModelObserver::TabClosingAt(TabStripModel* tab_strip_model,
- TabContents* contents,
+ TabContentsWrapper* contents,
int index) {
}
-void TabStripModelObserver::TabDetachedAt(TabContents* contents, int index) {
+void TabStripModelObserver::TabDetachedAt(TabContentsWrapper* contents,
+ int index) {
}
-void TabStripModelObserver::TabDeselectedAt(TabContents* contents, int index) {
+void TabStripModelObserver::TabDeselectedAt(TabContentsWrapper* contents,
+ int index) {
}
-void TabStripModelObserver::TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
+void TabStripModelObserver::TabSelectedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index,
bool user_gesture) {
}
-void TabStripModelObserver::TabMoved(TabContents* contents,
+void TabStripModelObserver::TabMoved(TabContentsWrapper* contents,
int from_index,
int to_index) {
}
-void TabStripModelObserver::TabChangedAt(TabContents* contents, int index,
+void TabStripModelObserver::TabChangedAt(TabContentsWrapper* contents,
+ int index,
TabChangeType change_type) {
}
-void TabStripModelObserver::TabReplacedAt(TabContents* old_contents,
- TabContents* new_contents,
+void TabStripModelObserver::TabReplacedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index) {
}
-void TabStripModelObserver::TabPinnedStateChanged(TabContents* contents,
+void TabStripModelObserver::TabPinnedStateChanged(TabContentsWrapper* contents,
int index) {
}
-void TabStripModelObserver::TabMiniStateChanged(TabContents* contents,
+void TabStripModelObserver::TabMiniStateChanged(TabContentsWrapper* contents,
int index) {
}
-void TabStripModelObserver::TabBlockedStateChanged(TabContents* contents,
+void TabStripModelObserver::TabBlockedStateChanged(TabContentsWrapper* contents,
int index) {
}
diff --git a/chrome/browser/tabs/tab_strip_model_observer.h b/chrome/browser/tabs/tab_strip_model_observer.h
index d39e436..0477247 100644
--- a/chrome/browser/tabs/tab_strip_model_observer.h
+++ b/chrome/browser/tabs/tab_strip_model_observer.h
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_TABS_TAB_STRIP_MODEL_OBSERVER_H_
#pragma once
-class TabContents;
+class TabContentsWrapper;
class TabStripModel;
////////////////////////////////////////////////////////////////////////////////
@@ -41,37 +41,37 @@ class TabStripModelObserver {
// A new TabContents was inserted into the TabStripModel at the specified
// index. |foreground| is whether or not it was opened in the foreground
// (selected).
- virtual void TabInsertedAt(TabContents* contents,
+ virtual void TabInsertedAt(TabContentsWrapper* contents,
int index,
bool foreground);
// The specified TabContents at |index| is being closed (and eventually
// destroyed). |tab_strip_model| is the TabStripModel the tab was part of.
virtual void TabClosingAt(TabStripModel* tab_strip_model,
- TabContents* contents,
+ TabContentsWrapper* contents,
int index);
// The specified TabContents at |index| is being detached, perhaps to be
// inserted in another TabStripModel. The implementer should take whatever
// action is necessary to deal with the TabContents no longer being present.
- virtual void TabDetachedAt(TabContents* contents, int index);
+ virtual void TabDetachedAt(TabContentsWrapper* contents, int index);
// The selected TabContents is about to change from |old_contents| at |index|.
// This gives observers a chance to prepare for an impending switch before it
// happens.
- virtual void TabDeselectedAt(TabContents* contents, int index);
+ virtual void TabDeselectedAt(TabContentsWrapper* contents, int index);
// The selected TabContents changed from |old_contents| to |new_contents| at
// |index|. |user_gesture| specifies whether or not this was done by a user
// input event (e.g. clicking on a tab, keystroke) or as a side-effect of
// some other function.
- virtual void TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
+ virtual void TabSelectedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index,
bool user_gesture);
// The specified TabContents at |from_index| was moved to |to_index|.
- virtual void TabMoved(TabContents* contents,
+ virtual void TabMoved(TabContentsWrapper* contents,
int from_index,
int to_index);
@@ -80,31 +80,31 @@ class TabStripModelObserver {
// by the time this message is delivered.
//
// See TabChangeType for a description of |change_type|.
- virtual void TabChangedAt(TabContents* contents,
+ virtual void TabChangedAt(TabContentsWrapper* contents,
int index,
TabChangeType change_type);
// The tab contents was replaced at the specified index. This is invoked when
// a tab becomes phantom. See description of phantom tabs in class description
// of TabStripModel for details.
- virtual void TabReplacedAt(TabContents* old_contents,
- TabContents* new_contents,
+ virtual void TabReplacedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index);
// Invoked when the pinned state of a tab changes. See note in
// TabMiniStateChanged as to how this relates to TabMiniStateChanged.
- virtual void TabPinnedStateChanged(TabContents* contents, int index);
+ virtual void TabPinnedStateChanged(TabContentsWrapper* contents, int index);
// Invoked if the mini state of a tab changes.
// NOTE: this is sent when the pinned state of a non-app tab changes and is
// sent in addition to TabPinnedStateChanged. UI code typically need not care
// about TabPinnedStateChanged, but instead this.
- virtual void TabMiniStateChanged(TabContents* contents, int index);
+ virtual void TabMiniStateChanged(TabContentsWrapper* contents, int index);
// Invoked when the blocked state of a tab changes.
// NOTE: This is invoked when a tab becomes blocked/unblocked by a tab modal
// window.
- virtual void TabBlockedStateChanged(TabContents* contents, int index);
+ virtual void TabBlockedStateChanged(TabContentsWrapper* contents, int index);
// The TabStripModel now no longer has any phantom tabs. The implementer may
// use this as a trigger to try and close the window containing the
diff --git a/chrome/browser/tabs/tab_strip_model_order_controller.cc b/chrome/browser/tabs/tab_strip_model_order_controller.cc
index aa66920..7cadbf7 100644
--- a/chrome/browser/tabs/tab_strip_model_order_controller.cc
+++ b/chrome/browser/tabs/tab_strip_model_order_controller.cc
@@ -4,7 +4,7 @@
#include "chrome/browser/tabs/tab_strip_model_order_controller.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents_wrapper.h"
///////////////////////////////////////////////////////////////////////////////
// TabStripModelOrderController, public:
@@ -21,7 +21,7 @@ TabStripModelOrderController::~TabStripModelOrderController() {
}
int TabStripModelOrderController::DetermineInsertionIndex(
- TabContents* new_contents,
+ TabContentsWrapper* new_contents,
PageTransition::Type transition,
bool foreground) {
int tab_count = tabstrip_->count();
@@ -104,10 +104,11 @@ int TabStripModelOrderController::DetermineNewSelectedIndex(
return selected_index;
}
-void TabStripModelOrderController::TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
- int index,
- bool user_gesture) {
+void TabStripModelOrderController::TabSelectedAt(
+ TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
+ int index,
+ bool user_gesture) {
NavigationController* old_opener = NULL;
if (old_contents) {
int index = tabstrip_->GetIndexOfTabContents(old_contents);
diff --git a/chrome/browser/tabs/tab_strip_model_order_controller.h b/chrome/browser/tabs/tab_strip_model_order_controller.h
index f2c466f..5ecaa2c 100644
--- a/chrome/browser/tabs/tab_strip_model_order_controller.h
+++ b/chrome/browser/tabs/tab_strip_model_order_controller.h
@@ -9,7 +9,7 @@
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/common/page_transition_types.h"
-class TabContents;
+class TabContentsWrapper;
///////////////////////////////////////////////////////////////////////////////
// TabStripModelOrderController
@@ -32,7 +32,7 @@ class TabStripModelOrderController : public TabStripModelObserver {
// Determine where to place a newly opened tab by using the supplied
// transition and foreground flag to figure out how it was opened.
- int DetermineInsertionIndex(TabContents* new_contents,
+ int DetermineInsertionIndex(TabContentsWrapper* new_contents,
PageTransition::Type transition,
bool foreground);
@@ -43,8 +43,8 @@ class TabStripModelOrderController : public TabStripModelObserver {
int DetermineNewSelectedIndex(int removed_index) const;
// Overridden from TabStripModelObserver:
- virtual void TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
+ virtual void TabSelectedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index,
bool user_gesture);
diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc
index 26ac70d..9bff9ed 100644
--- a/chrome/browser/tabs/tab_strip_model_unittest.cc
+++ b/chrome/browser/tabs/tab_strip_model_unittest.cc
@@ -13,6 +13,7 @@
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/profile.h"
@@ -21,6 +22,7 @@
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents_wrapper.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/tabs/tab_strip_model_order_controller.h"
@@ -41,26 +43,26 @@ namespace {
// Class used to delete a TabContents when another TabContents is destroyed.
class DeleteTabContentsOnDestroyedObserver : public NotificationObserver {
public:
- DeleteTabContentsOnDestroyedObserver(TabContents* source,
- TabContents* tab_to_delete)
+ DeleteTabContentsOnDestroyedObserver(TabContentsWrapper* source,
+ TabContentsWrapper* tab_to_delete)
: source_(source),
tab_to_delete_(tab_to_delete) {
registrar_.Add(this,
NotificationType::TAB_CONTENTS_DESTROYED,
- Source<TabContents>(source));
+ Source<TabContents>(source->tab_contents()));
}
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- TabContents* tab_to_delete = tab_to_delete_;
+ TabContentsWrapper* tab_to_delete = tab_to_delete_;
tab_to_delete_ = NULL;
delete tab_to_delete;
}
private:
- TabContents* source_;
- TabContents* tab_to_delete_;
+ TabContentsWrapper* source_;
+ TabContentsWrapper* tab_to_delete_;
NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(DeleteTabContentsOnDestroyedObserver);
@@ -70,7 +72,7 @@ class DeleteTabContentsOnDestroyedObserver : public NotificationObserver {
class TabStripDummyDelegate : public TabStripModelDelegate {
public:
- explicit TabStripDummyDelegate(TabContents* dummy)
+ explicit TabStripDummyDelegate(TabContentsWrapper* dummy)
: dummy_contents_(dummy), can_close_(true), run_unload_(false) {}
virtual ~TabStripDummyDelegate() {}
@@ -78,22 +80,24 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
void set_run_unload_listener(bool value) { run_unload_ = value; }
// Overridden from TabStripModelDelegate:
- virtual TabContents* AddBlankTab(bool foreground) { return NULL; }
- virtual TabContents* AddBlankTabAt(int index, bool foreground) {
+ virtual TabContentsWrapper* AddBlankTab(bool foreground) {
return NULL;
}
- virtual Browser* CreateNewStripWithContents(TabContents* contents,
+ virtual TabContentsWrapper* AddBlankTabAt(int index, bool foreground) {
+ return NULL;
+ }
+ virtual Browser* CreateNewStripWithContents(TabContentsWrapper* contents,
const gfx::Rect& window_bounds,
const DockInfo& dock_info,
bool maximize) {
return NULL;
}
- virtual void ContinueDraggingDetachedTab(TabContents* contents,
+ virtual void ContinueDraggingDetachedTab(TabContentsWrapper* contents,
const gfx::Rect& window_bounds,
const gfx::Rect& tab_bounds) {
}
virtual int GetDragActions() const { return 0; }
- virtual TabContents* CreateTabContentsForURL(
+ virtual TabContentsWrapper* CreateTabContentsForURL(
const GURL& url,
const GURL& referrer,
Profile* profile,
@@ -107,8 +111,8 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
virtual bool CanDuplicateContentsAt(int index) { return false; }
virtual void DuplicateContentsAt(int index) {}
virtual void CloseFrameAfterDragSession() {}
- virtual void CreateHistoricalTab(TabContents* contents) {}
- virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) {
+ virtual void CreateHistoricalTab(TabContentsWrapper* contents) {}
+ virtual bool RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) {
return run_unload_;
}
virtual bool CanRestoreTab() { return false; }
@@ -124,7 +128,7 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
private:
// A dummy TabContents we give to callers that expect us to actually build a
// Destinations tab for them.
- TabContents* dummy_contents_;
+ TabContentsWrapper* dummy_contents_;
// Whether tabs can be closed.
bool can_close_;
@@ -137,15 +141,16 @@ class TabStripDummyDelegate : public TabStripModelDelegate {
class TabStripModelTest : public RenderViewHostTestHarness {
public:
- TabContents* CreateTabContents() {
- return new TabContents(profile(), NULL, 0, NULL, NULL);
+ TabContentsWrapper* CreateTabContents() {
+ return Browser::TabContentsFactory(profile(), NULL, 0, NULL, NULL);
}
- TabContents* CreateTabContentsWithSharedRPH(TabContents* tab_contents) {
- TabContents* retval = new TabContents(profile(),
+ TabContentsWrapper* CreateTabContentsWithSharedRPH(
+ TabContents* tab_contents) {
+ TabContentsWrapper* retval = Browser::TabContentsFactory(profile(),
tab_contents->render_view_host()->site_instance(), MSG_ROUTING_NONE,
NULL, NULL);
- EXPECT_EQ(retval->GetRenderProcessHost(),
+ EXPECT_EQ(retval->tab_contents()->GetRenderProcessHost(),
tab_contents->GetRenderProcessHost());
return retval;
}
@@ -188,7 +193,8 @@ class TabStripModelTest : public RenderViewHostTestHarness {
if (i > 0)
actual += " ";
- actual += base::IntToString(GetID(model.GetTabContentsAt(i)));
+ actual +=
+ base::IntToString(GetID(model.GetTabContentsAt(i)->tab_contents()));
if (model.IsAppTab(i))
actual += "a";
@@ -248,7 +254,7 @@ class MockTabStripModelObserver : public TabStripModelObserver {
};
struct State {
- State(TabContents* a_dst_contents,
+ State(TabContentsWrapper* a_dst_contents,
int a_dst_index,
TabStripModelObserverAction a_action)
: src_contents(NULL),
@@ -260,8 +266,8 @@ class MockTabStripModelObserver : public TabStripModelObserver {
action(a_action) {
}
- TabContents* src_contents;
- TabContents* dst_contents;
+ TabContentsWrapper* src_contents;
+ TabContentsWrapper* dst_contents;
int src_index;
int dst_index;
bool user_gesture;
@@ -297,7 +303,7 @@ class MockTabStripModelObserver : public TabStripModelObserver {
}
// TabStripModelObserver implementation:
- virtual void TabInsertedAt(TabContents* contents,
+ virtual void TabInsertedAt(TabContentsWrapper* contents,
int index,
bool foreground) {
empty_ = false;
@@ -305,8 +311,8 @@ class MockTabStripModelObserver : public TabStripModelObserver {
s->foreground = foreground;
states_.push_back(s);
}
- virtual void TabSelectedAt(TabContents* old_contents,
- TabContents* new_contents,
+ virtual void TabSelectedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
int index,
bool user_gesture) {
State* s = new State(new_contents, index, SELECT);
@@ -315,31 +321,31 @@ class MockTabStripModelObserver : public TabStripModelObserver {
states_.push_back(s);
}
virtual void TabMoved(
- TabContents* contents, int from_index, int to_index) {
+ TabContentsWrapper* contents, int from_index, int to_index) {
State* s = new State(contents, to_index, MOVE);
s->src_index = from_index;
states_.push_back(s);
}
virtual void TabClosingAt(TabStripModel* tab_strip_model,
- TabContents* contents,
+ TabContentsWrapper* contents,
int index) {
states_.push_back(new State(contents, index, CLOSE));
}
- virtual void TabDetachedAt(TabContents* contents, int index) {
+ virtual void TabDetachedAt(TabContentsWrapper* contents, int index) {
states_.push_back(new State(contents, index, DETACH));
}
- virtual void TabChangedAt(TabContents* contents, int index,
+ virtual void TabChangedAt(TabContentsWrapper* contents, int index,
TabChangeType change_type) {
states_.push_back(new State(contents, index, CHANGE));
}
- virtual void TabReplacedAt(TabContents* old_contents,
- TabContents* new_contents, int index) {
+ virtual void TabReplacedAt(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents, int index) {
State* s = new State(new_contents, index, REPLACED);
s ->src_contents = old_contents;
states_.push_back(s);
}
- virtual void TabPinnedStateChanged(TabContents* contents, int index) {
+ virtual void TabPinnedStateChanged(TabContentsWrapper* contents, int index) {
states_.push_back(new State(contents, index, PINNED));
}
virtual void TabStripEmpty() {
@@ -371,7 +377,7 @@ TEST_F(TabStripModelTest, TestBasicAPI) {
typedef MockTabStripModelObserver::State State;
- TabContents* contents1 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
// Note! The ordering of these tests is important, each subsequent test
// builds on the state established in the previous. This is important if you
@@ -394,7 +400,7 @@ TEST_F(TabStripModelTest, TestBasicAPI) {
}
// Test InsertTabContentsAt, foreground tab.
- TabContents* contents2 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
{
tabstrip.InsertTabContentsAt(1, contents2, TabStripModel::ADD_SELECTED);
@@ -410,7 +416,7 @@ TEST_F(TabStripModelTest, TestBasicAPI) {
}
// Test InsertTabContentsAt, background tab.
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
{
tabstrip.InsertTabContentsAt(2, contents3, TabStripModel::ADD_NONE);
@@ -436,7 +442,7 @@ TEST_F(TabStripModelTest, TestBasicAPI) {
// Test DetachTabContentsAt
{
// Detach
- TabContents* detached = tabstrip.DetachTabContentsAt(2);
+ TabContentsWrapper* detached = tabstrip.DetachTabContentsAt(2);
// ... and append again because we want this for later.
tabstrip.AppendTabContents(detached, true);
EXPECT_EQ(4, observer.GetStateCount());
@@ -566,14 +572,14 @@ TEST_F(TabStripModelTest, TestBasicOpenerAPI) {
// as the first tab in the strip and then we create 5 other tabs in the
// background with opener_contents set as their opener.
- TabContents* opener_contents = CreateTabContents();
+ TabContentsWrapper* opener_contents = CreateTabContents();
NavigationController* opener = &opener_contents->controller();
tabstrip.AppendTabContents(opener_contents, true);
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
- TabContents* contents4 = CreateTabContents();
- TabContents* contents5 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
+ TabContentsWrapper* contents4 = CreateTabContents();
+ TabContentsWrapper* contents5 = CreateTabContents();
// We use |InsertTabContentsAt| here instead of AppendTabContents so that
// openership relationships are preserved.
@@ -619,15 +625,16 @@ TEST_F(TabStripModelTest, TestBasicOpenerAPI) {
EXPECT_TRUE(tabstrip.empty());
}
-static int GetInsertionIndex(TabStripModel* tabstrip, TabContents* contents) {
+static int GetInsertionIndex(TabStripModel* tabstrip,
+ TabContentsWrapper* contents) {
return tabstrip->order_controller()->DetermineInsertionIndex(
contents, PageTransition::LINK, false);
}
static void InsertTabContentses(TabStripModel* tabstrip,
- TabContents* contents1,
- TabContents* contents2,
- TabContents* contents3) {
+ TabContentsWrapper* contents1,
+ TabContentsWrapper* contents2,
+ TabContentsWrapper* contents3) {
tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents1),
contents1, TabStripModel::ADD_INHERIT_GROUP);
tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents2),
@@ -642,12 +649,12 @@ TEST_F(TabStripModelTest, TestLTRInsertionOptions) {
TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
- TabContents* opener_contents = CreateTabContents();
+ TabContentsWrapper* opener_contents = CreateTabContents();
tabstrip.AppendTabContents(opener_contents, true);
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
// Test LTR
InsertTabContentses(&tabstrip, contents1, contents2, contents3);
@@ -666,9 +673,9 @@ TEST_F(TabStripModelTest, InsertBefore) {
tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE);
EXPECT_TRUE(tabstrip.empty());
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
InsertTabContentses(&tabstrip, contents1, contents2, contents3);
@@ -687,12 +694,12 @@ TEST_F(TabStripModelTest, InsertBeforeOpeners) {
TabStripModel tabstrip(&delegate, profile());
tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE);
EXPECT_TRUE(tabstrip.empty());
- TabContents* opener_contents = CreateTabContents();
+ TabContentsWrapper* opener_contents = CreateTabContents();
tabstrip.AppendTabContents(opener_contents, true);
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
InsertTabContentses(&tabstrip, contents1, contents2, contents3);
@@ -716,18 +723,18 @@ TEST_F(TabStripModelTest, TestInsertionIndexDetermination) {
TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
- TabContents* opener_contents = CreateTabContents();
+ TabContentsWrapper* opener_contents = CreateTabContents();
NavigationController* opener = &opener_contents->controller();
tabstrip.AppendTabContents(opener_contents, true);
// Open some other random unrelated tab in the background to monkey with our
// insertion index.
- TabContents* other_contents = CreateTabContents();
+ TabContentsWrapper* other_contents = CreateTabContents();
tabstrip.AppendTabContents(other_contents, false);
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
// Start by testing LTR
InsertTabContentses(&tabstrip, contents1, contents2, contents3);
@@ -744,7 +751,7 @@ TEST_F(TabStripModelTest, TestInsertionIndexDetermination) {
// Now open a foreground tab from a link. It should be opened adjacent to the
// opener tab.
- TabContents* fg_link_contents = CreateTabContents();
+ TabContentsWrapper* fg_link_contents = CreateTabContents();
int insert_index = tabstrip.order_controller()->DetermineInsertionIndex(
fg_link_contents, PageTransition::LINK, true);
EXPECT_EQ(1, insert_index);
@@ -759,7 +766,7 @@ TEST_F(TabStripModelTest, TestInsertionIndexDetermination) {
EXPECT_EQ(0, tabstrip.selected_index());
// Now open a new empty tab. It should open at the end of the strip.
- TabContents* fg_nonlink_contents = CreateTabContents();
+ TabContentsWrapper* fg_nonlink_contents = CreateTabContents();
insert_index = tabstrip.order_controller()->DetermineInsertionIndex(
fg_nonlink_contents, PageTransition::AUTO_BOOKMARK, true);
EXPECT_EQ(tabstrip.count(), insert_index);
@@ -798,12 +805,12 @@ TEST_F(TabStripModelTest, TestSelectOnClose) {
TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
- TabContents* opener_contents = CreateTabContents();
+ TabContentsWrapper* opener_contents = CreateTabContents();
tabstrip.AppendTabContents(opener_contents, true);
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
// Note that we use Detach instead of Close throughout this test to avoid
// having to keep reconstructing these TabContentses.
@@ -851,10 +858,10 @@ TEST_F(TabStripModelTest, TestSelectOnClose) {
EXPECT_EQ(0, tabstrip.selected_index());
// Finally test that when a tab has no "siblings" that the opener is
// selected.
- TabContents* other_contents = CreateTabContents();
+ TabContentsWrapper* other_contents = CreateTabContents();
tabstrip.InsertTabContentsAt(1, other_contents, TabStripModel::ADD_NONE);
EXPECT_EQ(2, tabstrip.count());
- TabContents* opened_contents = CreateTabContents();
+ TabContentsWrapper* opened_contents = CreateTabContents();
tabstrip.InsertTabContentsAt(2, opened_contents,
TabStripModel::ADD_SELECTED |
TabStripModel::ADD_INHERIT_GROUP);
@@ -875,12 +882,12 @@ TEST_F(TabStripModelTest, TestContextMenuCloseCommands) {
TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
- TabContents* opener_contents = CreateTabContents();
+ TabContentsWrapper* opener_contents = CreateTabContents();
tabstrip.AppendTabContents(opener_contents, true);
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
InsertTabContentses(&tabstrip, contents1, contents2, contents3);
EXPECT_EQ(0, tabstrip.selected_index());
@@ -892,7 +899,7 @@ TEST_F(TabStripModelTest, TestContextMenuCloseCommands) {
EXPECT_EQ(1, tabstrip.count());
EXPECT_EQ(opener_contents, tabstrip.GetSelectedTabContents());
- TabContents* dummy_contents = CreateTabContents();
+ TabContentsWrapper* dummy_contents = CreateTabContents();
tabstrip.AppendTabContents(dummy_contents, false);
contents1 = CreateTabContents();
@@ -920,11 +927,11 @@ TEST_F(TabStripModelTest, GetIndicesClosedByCommand) {
TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
- TabContents* contents4 = CreateTabContents();
- TabContents* contents5 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
+ TabContentsWrapper* contents4 = CreateTabContents();
+ TabContentsWrapper* contents5 = CreateTabContents();
tabstrip.AppendTabContents(contents1, true);
tabstrip.AppendTabContents(contents2, true);
@@ -970,13 +977,13 @@ TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) {
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
- TabContents* homepage_contents = CreateTabContents();
+ TabContentsWrapper* homepage_contents = CreateTabContents();
tabstrip.AddTabContents(
homepage_contents, -1, PageTransition::AUTO_BOOKMARK,
TabStripModel::ADD_SELECTED);
// Open some other tab, by user typing.
- TabContents* typed_page_contents = CreateTabContents();
+ TabContentsWrapper* typed_page_contents = CreateTabContents();
tabstrip.AddTabContents(
typed_page_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -988,15 +995,15 @@ TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) {
// Open a bunch of tabs by simulating middle clicking on links on the home
// page.
- TabContents* middle_click_contents1 = CreateTabContents();
+ TabContentsWrapper* middle_click_contents1 = CreateTabContents();
tabstrip.AddTabContents(
middle_click_contents1, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
- TabContents* middle_click_contents2 = CreateTabContents();
+ TabContentsWrapper* middle_click_contents2 = CreateTabContents();
tabstrip.AddTabContents(
middle_click_contents2, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
- TabContents* middle_click_contents3 = CreateTabContents();
+ TabContentsWrapper* middle_click_contents3 = CreateTabContents();
tabstrip.AddTabContents(
middle_click_contents3, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
@@ -1039,13 +1046,13 @@ TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) {
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
- TabContents* homepage_contents = CreateTabContents();
+ TabContentsWrapper* homepage_contents = CreateTabContents();
tabstrip.AddTabContents(
homepage_contents, -1, PageTransition::AUTO_BOOKMARK,
TabStripModel::ADD_SELECTED);
// Open some other tab, by user typing.
- TabContents* typed_page_contents = CreateTabContents();
+ TabContentsWrapper* typed_page_contents = CreateTabContents();
tabstrip.AddTabContents(
typed_page_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -1056,7 +1063,7 @@ TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) {
tabstrip.SelectTabContentsAt(0, true);
// Open a tab by simulating a left click on a link that opens in a new tab.
- TabContents* left_click_contents = CreateTabContents();
+ TabContentsWrapper* left_click_contents = CreateTabContents();
tabstrip.AddTabContents(left_click_contents, -1, PageTransition::LINK,
TabStripModel::ADD_SELECTED);
@@ -1089,13 +1096,13 @@ TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) {
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
- TabContents* homepage_contents = CreateTabContents();
+ TabContentsWrapper* homepage_contents = CreateTabContents();
tabstrip.AddTabContents(
homepage_contents, -1, PageTransition::AUTO_BOOKMARK,
TabStripModel::ADD_SELECTED);
// Open some other tab, by user typing.
- TabContents* typed_page_contents = CreateTabContents();
+ TabContentsWrapper* typed_page_contents = CreateTabContents();
tabstrip.AddTabContents(
typed_page_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -1106,7 +1113,7 @@ TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) {
tabstrip.SelectTabContentsAt(0, true);
// Open a new blank tab in the foreground.
- TabContents* new_blank_contents = CreateTabContents();
+ TabContentsWrapper* new_blank_contents = CreateTabContents();
tabstrip.AddTabContents(new_blank_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -1117,11 +1124,11 @@ TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) {
EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2));
// Now open a couple more blank tabs in the background.
- TabContents* background_blank_contents1 = CreateTabContents();
+ TabContentsWrapper* background_blank_contents1 = CreateTabContents();
tabstrip.AddTabContents(
background_blank_contents1, -1, PageTransition::TYPED,
TabStripModel::ADD_NONE);
- TabContents* background_blank_contents2 = CreateTabContents();
+ TabContentsWrapper* background_blank_contents2 = CreateTabContents();
tabstrip.AddTabContents(
background_blank_contents2, -1, PageTransition::GENERATED,
TabStripModel::ADD_NONE);
@@ -1144,13 +1151,13 @@ TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) {
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
- TabContents* homepage_contents = CreateTabContents();
+ TabContentsWrapper* homepage_contents = CreateTabContents();
tabstrip.AddTabContents(
homepage_contents, -1, PageTransition::AUTO_BOOKMARK,
TabStripModel::ADD_SELECTED);
// Open some other tab, by user typing.
- TabContents* typed_page_contents = CreateTabContents();
+ TabContentsWrapper* typed_page_contents = CreateTabContents();
tabstrip.AddTabContents(
typed_page_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -1162,15 +1169,15 @@ TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) {
// Open a bunch of tabs by simulating middle clicking on links on the home
// page.
- TabContents* middle_click_contents1 = CreateTabContents();
+ TabContentsWrapper* middle_click_contents1 = CreateTabContents();
tabstrip.AddTabContents(
middle_click_contents1, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
- TabContents* middle_click_contents2 = CreateTabContents();
+ TabContentsWrapper* middle_click_contents2 = CreateTabContents();
tabstrip.AddTabContents(
middle_click_contents2, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
- TabContents* middle_click_contents3 = CreateTabContents();
+ TabContentsWrapper* middle_click_contents3 = CreateTabContents();
tabstrip.AddTabContents(
middle_click_contents3, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
@@ -1204,19 +1211,21 @@ TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) {
// Added for http://b/issue?id=958960
TEST_F(TabStripModelTest, AppendContentsReselectionTest) {
- TabContents fake_destinations_tab(profile(), NULL, 0, NULL, NULL);
- TabStripDummyDelegate delegate(&fake_destinations_tab);
+ TabContents* fake_destinations_tab =
+ new TabContents(profile(), NULL, 0, NULL, NULL);
+ TabContentsWrapper wrapper(fake_destinations_tab);
+ TabStripDummyDelegate delegate(&wrapper);
TabStripModel tabstrip(&delegate, profile());
EXPECT_TRUE(tabstrip.empty());
// Open the Home Page
- TabContents* homepage_contents = CreateTabContents();
+ TabContentsWrapper* homepage_contents = CreateTabContents();
tabstrip.AddTabContents(
homepage_contents, -1, PageTransition::AUTO_BOOKMARK,
TabStripModel::ADD_SELECTED);
// Open some other tab, by user typing.
- TabContents* typed_page_contents = CreateTabContents();
+ TabContentsWrapper* typed_page_contents = CreateTabContents();
tabstrip.AddTabContents(
typed_page_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_NONE);
@@ -1226,7 +1235,7 @@ TEST_F(TabStripModelTest, AppendContentsReselectionTest) {
// Now simulate a link click that opens a new tab (by virtue of target=_blank)
// and make sure the right tab gets selected when the new tab is closed.
- TabContents* target_blank_contents = CreateTabContents();
+ TabContentsWrapper* target_blank_contents = CreateTabContents();
tabstrip.AppendTabContents(target_blank_contents, true);
EXPECT_EQ(2, tabstrip.selected_index());
tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE);
@@ -1242,16 +1251,16 @@ TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) {
TabStripModel strip(&delegate, profile());
// Open page A
- TabContents* page_a_contents = CreateTabContents();
+ TabContentsWrapper* page_a_contents = CreateTabContents();
strip.AddTabContents(
page_a_contents, -1, PageTransition::AUTO_BOOKMARK,
TabStripModel::ADD_SELECTED);
// Simulate middle click to open page A.A and A.B
- TabContents* page_a_a_contents = CreateTabContents();
+ TabContentsWrapper* page_a_a_contents = CreateTabContents();
strip.AddTabContents(page_a_a_contents, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
- TabContents* page_a_b_contents = CreateTabContents();
+ TabContentsWrapper* page_a_b_contents = CreateTabContents();
strip.AddTabContents(page_a_b_contents, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
@@ -1260,7 +1269,7 @@ TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) {
EXPECT_EQ(page_a_a_contents, strip.GetSelectedTabContents());
// Simulate a middle click to open page A.A.A
- TabContents* page_a_a_a_contents = CreateTabContents();
+ TabContentsWrapper* page_a_a_a_contents = CreateTabContents();
strip.AddTabContents(page_a_a_a_contents, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
@@ -1293,14 +1302,14 @@ TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) {
TabStripModel strip(&delegate, profile());
// Open page A
- TabContents* page_a_contents = CreateTabContents();
+ TabContentsWrapper* page_a_contents = CreateTabContents();
strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE,
TabStripModel::ADD_SELECTED);
// Open pages B, C and D in the background from links on page A...
- TabContents* page_b_contents = CreateTabContents();
- TabContents* page_c_contents = CreateTabContents();
- TabContents* page_d_contents = CreateTabContents();
+ TabContentsWrapper* page_b_contents = CreateTabContents();
+ TabContentsWrapper* page_c_contents = CreateTabContents();
+ TabContentsWrapper* page_d_contents = CreateTabContents();
strip.AddTabContents(page_b_contents, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
strip.AddTabContents(page_c_contents, -1, PageTransition::LINK,
@@ -1312,7 +1321,7 @@ TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) {
strip.SelectTabContentsAt(1, true);
// Open a New Tab at the end of the strip (simulate Ctrl+T)
- TabContents* new_tab_contents = CreateTabContents();
+ TabContentsWrapper* new_tab_contents = CreateTabContents();
strip.AddTabContents(new_tab_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -1328,7 +1337,7 @@ TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) {
// Open a non-New Tab tab at the end of the strip, with a TYPED transition.
// This is like typing a URL in the address bar and pressing Alt+Enter. The
// behavior should be the same as above.
- TabContents* page_e_contents = CreateTabContents();
+ TabContentsWrapper* page_e_contents = CreateTabContents();
strip.AddTabContents(page_e_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -1344,7 +1353,7 @@ TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) {
// transition. This is like right clicking on a bookmark and choosing "Open
// in New Tab". No opener relationship should be preserved between this Tab
// and the one that was active when the gesture was performed.
- TabContents* page_f_contents = CreateTabContents();
+ TabContentsWrapper* page_f_contents = CreateTabContents();
strip.AddTabContents(page_f_contents, -1, PageTransition::AUTO_BOOKMARK,
TabStripModel::ADD_SELECTED);
@@ -1369,14 +1378,14 @@ TEST_F(TabStripModelTest, NavigationForgetsOpeners) {
TabStripModel strip(&delegate, profile());
// Open page A
- TabContents* page_a_contents = CreateTabContents();
+ TabContentsWrapper* page_a_contents = CreateTabContents();
strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE,
TabStripModel::ADD_SELECTED);
// Open pages B, C and D in the background from links on page A...
- TabContents* page_b_contents = CreateTabContents();
- TabContents* page_c_contents = CreateTabContents();
- TabContents* page_d_contents = CreateTabContents();
+ TabContentsWrapper* page_b_contents = CreateTabContents();
+ TabContentsWrapper* page_c_contents = CreateTabContents();
+ TabContentsWrapper* page_d_contents = CreateTabContents();
strip.AddTabContents(page_b_contents, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
strip.AddTabContents(page_c_contents, -1, PageTransition::LINK,
@@ -1385,7 +1394,7 @@ TEST_F(TabStripModelTest, NavigationForgetsOpeners) {
TabStripModel::ADD_NONE);
// Open page E in a different opener group from page A.
- TabContents* page_e_contents = CreateTabContents();
+ TabContentsWrapper* page_e_contents = CreateTabContents();
strip.AddTabContents(page_e_contents, -1, PageTransition::START_PAGE,
TabStripModel::ADD_NONE);
@@ -1418,13 +1427,13 @@ TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) {
// Open a tab and several tabs from it, then select one of the tabs that was
// opened.
- TabContents* page_a_contents = CreateTabContents();
+ TabContentsWrapper* page_a_contents = CreateTabContents();
strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE,
TabStripModel::ADD_SELECTED);
- TabContents* page_b_contents = CreateTabContents();
- TabContents* page_c_contents = CreateTabContents();
- TabContents* page_d_contents = CreateTabContents();
+ TabContentsWrapper* page_b_contents = CreateTabContents();
+ TabContentsWrapper* page_c_contents = CreateTabContents();
+ TabContentsWrapper* page_d_contents = CreateTabContents();
strip.AddTabContents(page_b_contents, -1, PageTransition::LINK,
TabStripModel::ADD_NONE);
strip.AddTabContents(page_c_contents, -1, PageTransition::LINK,
@@ -1439,7 +1448,7 @@ TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) {
// last on.
// Now simulate opening a new tab at the end of the TabStrip.
- TabContents* new_tab_contents1 = CreateTabContents();
+ TabContentsWrapper* new_tab_contents1 = CreateTabContents();
strip.AddTabContents(new_tab_contents1, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -1453,7 +1462,7 @@ TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) {
// tab's opener relationship to be forgotten.
// Open a new tab again.
- TabContents* new_tab_contents2 = CreateTabContents();
+ TabContentsWrapper* new_tab_contents2 = CreateTabContents();
strip.AddTabContents(new_tab_contents2, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
@@ -1482,11 +1491,12 @@ TEST_F(TabStripModelTest, FastShutdown) {
// Make sure fast shutdown is attempted when tabs that share a RPH are shut
// down.
{
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContentsWithSharedRPH(contents1);
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 =
+ CreateTabContentsWithSharedRPH(contents1->tab_contents());
- SetID(contents1, 1);
- SetID(contents2, 2);
+ SetID(contents1->tab_contents(), 1);
+ SetID(contents2->tab_contents(), 2);
tabstrip.AppendTabContents(contents1, true);
tabstrip.AppendTabContents(contents2, true);
@@ -1498,7 +1508,8 @@ TEST_F(TabStripModelTest, FastShutdown) {
tabstrip.CloseAllTabs();
// On a mock RPH this checks whether we *attempted* fast shutdown.
// A real RPH would reject our attempt since there is an unload handler.
- EXPECT_TRUE(contents1->GetRenderProcessHost()->fast_shutdown_started());
+ EXPECT_TRUE(contents1->tab_contents()->
+ GetRenderProcessHost()->fast_shutdown_started());
EXPECT_EQ(2, tabstrip.count());
delegate.set_run_unload_listener(false);
@@ -1509,17 +1520,19 @@ TEST_F(TabStripModelTest, FastShutdown) {
// Make sure fast shutdown is not attempted when only some tabs that share a
// RPH are shut down.
{
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContentsWithSharedRPH(contents1);
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 =
+ CreateTabContentsWithSharedRPH(contents1->tab_contents());
- SetID(contents1, 1);
- SetID(contents2, 2);
+ SetID(contents1->tab_contents(), 1);
+ SetID(contents2->tab_contents(), 2);
tabstrip.AppendTabContents(contents1, true);
tabstrip.AppendTabContents(contents2, true);
tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE);
- EXPECT_FALSE(contents1->GetRenderProcessHost()->fast_shutdown_started());
+ EXPECT_FALSE(contents1->tab_contents()->
+ GetRenderProcessHost()->fast_shutdown_started());
EXPECT_EQ(1, tabstrip.count());
tabstrip.CloseAllTabs();
@@ -1546,15 +1559,15 @@ TEST_F(TabStripModelTest, Apps) {
scoped_refptr<Extension> extension_app(new Extension(path,
Extension::INVALID));
extension_app->launch_web_url_ = "http://www.google.com";
- TabContents* contents1 = CreateTabContents();
- contents1->SetExtensionApp(extension_app);
- TabContents* contents2 = CreateTabContents();
- contents2->SetExtensionApp(extension_app);
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ contents1->tab_contents()->SetExtensionApp(extension_app);
+ TabContentsWrapper* contents2 = CreateTabContents();
+ contents2->tab_contents()->SetExtensionApp(extension_app);
+ TabContentsWrapper* contents3 = CreateTabContents();
- SetID(contents1, 1);
- SetID(contents2, 2);
- SetID(contents3, 3);
+ SetID(contents1->tab_contents(), 1);
+ SetID(contents2->tab_contents(), 2);
+ SetID(contents3->tab_contents(), 3);
// Note! The ordering of these tests is important, each subsequent test
// builds on the state established in the previous. This is important if you
@@ -1664,13 +1677,13 @@ TEST_F(TabStripModelTest, Pinning) {
typedef MockTabStripModelObserver::State State;
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
- TabContents* contents3 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
+ TabContentsWrapper* contents3 = CreateTabContents();
- SetID(contents1, 1);
- SetID(contents2, 2);
- SetID(contents3, 3);
+ SetID(contents1->tab_contents(), 1);
+ SetID(contents2->tab_contents(), 2);
+ SetID(contents3->tab_contents(), 3);
// Note! The ordering of these tests is important, each subsequent test
// builds on the state established in the previous. This is important if you
@@ -1799,8 +1812,8 @@ TEST_F(TabStripModelTest, Pinning) {
observer.ClearStates();
}
- TabContents* contents4 = CreateTabContents();
- SetID(contents4, 4);
+ TabContentsWrapper* contents4 = CreateTabContents();
+ SetID(contents4->tab_contents(), 4);
// Insert "4" between "1" and "3". As "1" and "4" are pinned, "4" should end
// up after them.
@@ -1825,14 +1838,14 @@ TEST_F(TabStripModelTest, ReplaceSendsSelected) {
TabStripDummyDelegate delegate(NULL);
TabStripModel strip(&delegate, profile());
- TabContents* first_contents = CreateTabContents();
+ TabContentsWrapper* first_contents = CreateTabContents();
strip.AddTabContents(first_contents, -1, PageTransition::TYPED,
TabStripModel::ADD_SELECTED);
MockTabStripModelObserver tabstrip_observer;
strip.AddObserver(&tabstrip_observer);
- TabContents* new_contents = CreateTabContents();
+ TabContentsWrapper* new_contents = CreateTabContents();
strip.ReplaceTabContentsAt(0, new_contents);
ASSERT_EQ(2, tabstrip_observer.GetStateCount());
@@ -1849,7 +1862,7 @@ TEST_F(TabStripModelTest, ReplaceSendsSelected) {
// Now add another tab and replace it, making sure we don't get a selected
// event this time.
- TabContents* third_contents = CreateTabContents();
+ TabContentsWrapper* third_contents = CreateTabContents();
strip.AddTabContents(third_contents, 1, PageTransition::TYPED,
TabStripModel::ADD_NONE);
@@ -1873,8 +1886,8 @@ TEST_F(TabStripModelTest, ReplaceSendsSelected) {
TEST_F(TabStripModelTest, DeleteFromDestroy) {
TabStripDummyDelegate delegate(NULL);
TabStripModel strip(&delegate, profile());
- TabContents* contents1 = CreateTabContents();
- TabContents* contents2 = CreateTabContents();
+ TabContentsWrapper* contents1 = CreateTabContents();
+ TabContentsWrapper* contents2 = CreateTabContents();
strip.AppendTabContents(contents1, true);
strip.AppendTabContents(contents2, true);
// DeleteTabContentsOnDestroyedObserver deletes contents1 when contents2 sends