diff options
109 files changed, 1736 insertions, 1248 deletions
diff --git a/chrome/browser/aeropeek_manager.cc b/chrome/browser/aeropeek_manager.cc index 34cb3da..c79b538 100644 --- a/chrome/browser/aeropeek_manager.cc +++ b/chrome/browser/aeropeek_manager.cc @@ -24,6 +24,7 @@ #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -1058,20 +1059,21 @@ int AeroPeekManager::GetTabID(TabContents* contents) const { /////////////////////////////////////////////////////////////////////////////// // AeroPeekManager, TabStripModelObserver implementation: -void AeroPeekManager::TabInsertedAt(TabContents* contents, +void AeroPeekManager::TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground) { // If there are not any AeroPeekWindow objects associated with the given // tab, Create a new AeroPeekWindow object and add it to the list. - if (GetAeroPeekWindow(GetTabID(contents))) + if (GetAeroPeekWindow(GetTabID(contents->tab_contents()))) return; - AeroPeekWindow* window = new AeroPeekWindow(application_window_, - this, - GetTabID(contents), - foreground, - contents->GetTitle(), - contents->GetFavIcon()); + AeroPeekWindow* window = + new AeroPeekWindow(application_window_, + this, + GetTabID(contents->tab_contents()), + foreground, + contents->tab_contents()->GetTitle(), + contents->tab_contents()->GetFavIcon()); if (!window) return; @@ -1079,22 +1081,23 @@ void AeroPeekManager::TabInsertedAt(TabContents* contents, } void AeroPeekManager::TabClosingAt(TabStripModel* tab_strip_model, - TabContents* contents, + TabContentsWrapper* contents, int index) { // |tab_strip_model| is NULL when this is being called from TabDetachedAt // below. // Delete the AeroPeekWindow object associated with this tab and all its // resources. (AeroPeekWindow::Destory() also removes this tab from the tab // list of Windows.) - AeroPeekWindow* window = GetAeroPeekWindow(GetTabID(contents)); + AeroPeekWindow* window = + GetAeroPeekWindow(GetTabID(contents->tab_contents())); if (!window) return; window->Destroy(); - DeleteAeroPeekWindow(GetTabID(contents)); + DeleteAeroPeekWindow(GetTabID(contents->tab_contents())); } -void AeroPeekManager::TabDetachedAt(TabContents* contents, int index) { +void AeroPeekManager::TabDetachedAt(TabContentsWrapper* contents, int index) { // Same as TabClosingAt(), we remove this tab from the tab list and delete // its AeroPeekWindow. // Chrome will call TabInsertedAt() when this tab is inserted to another @@ -1103,22 +1106,24 @@ void AeroPeekManager::TabDetachedAt(TabContents* contents, int index) { TabClosingAt(NULL, contents, index); } -void AeroPeekManager::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, +void AeroPeekManager::TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture) { // Deactivate the old window in the thumbnail list and activate the new one // to synchronize the thumbnail list with TabStrip. - AeroPeekWindow* old_window = GetAeroPeekWindow(GetTabID(old_contents)); + AeroPeekWindow* old_window = + GetAeroPeekWindow(GetTabID(old_contents->tab_contents())); if (old_window) old_window->Deactivate(); - AeroPeekWindow* new_window = GetAeroPeekWindow(GetTabID(new_contents)); + AeroPeekWindow* new_window = + GetAeroPeekWindow(GetTabID(new_contents->tab_contents())); if (new_window) new_window->Activate(); } -void AeroPeekManager::TabMoved(TabContents* contents, +void AeroPeekManager::TabMoved(TabContentsWrapper* contents, int from_index, int to_index, bool pinned_state_changed) { @@ -1127,12 +1132,13 @@ void AeroPeekManager::TabMoved(TabContents* contents, // we detach/attach tabs.) } -void AeroPeekManager::TabChangedAt(TabContents* contents, +void AeroPeekManager::TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type) { // Retrieve the AeroPeekWindow object associated with this tab, update its // title, and post a task that update its thumbnail image if necessary. - AeroPeekWindow* window = GetAeroPeekWindow(GetTabID(contents)); + AeroPeekWindow* window = + GetAeroPeekWindow(GetTabID(contents->tab_contents())); if (!window) return; @@ -1141,9 +1147,9 @@ void AeroPeekManager::TabChangedAt(TabContents* contents, // Windows needs them (e.g. when a user hovers a taskbar icon) to avoid // hurting the rendering performance. (These functions just save the // information needed for handling update requests from Windows.) - window->SetTitle(contents->GetTitle()); - window->SetFavIcon(contents->GetFavIcon()); - window->Update(contents->is_loading()); + window->SetTitle(contents->tab_contents()->GetTitle()); + window->SetFavIcon(contents->tab_contents()->GetFavIcon()); + window->Update(contents->tab_contents()->is_loading()); } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/aeropeek_manager.h b/chrome/browser/aeropeek_manager.h index 104e57e..1e26af6 100644 --- a/chrome/browser/aeropeek_manager.h +++ b/chrome/browser/aeropeek_manager.h @@ -107,22 +107,22 @@ class AeroPeekManager : public TabStripModelObserver, static bool Enabled(); // 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 TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabDetachedAt(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, bool pinned_state_changed); - virtual void TabChangedAt(TabContents* contents, + virtual void TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type); diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 46b44706..2cefa30 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -38,6 +38,7 @@ #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/translate/page_translated_details.h" #include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/ui/browser.h" @@ -374,13 +375,14 @@ TabCountChangeObserver::~TabCountChangeObserver() { tab_strip_model_->RemoveObserver(this); } -void TabCountChangeObserver::TabInsertedAt(TabContents* contents, +void TabCountChangeObserver::TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground) { CheckTabCount(); } -void TabCountChangeObserver::TabDetachedAt(TabContents* contents, int index) { +void TabCountChangeObserver::TabDetachedAt(TabContentsWrapper* contents, + int index) { CheckTabCount(); } diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index cfa6e14..9783a6a 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -204,10 +204,10 @@ class TabCountChangeObserver : public TabStripModelObserver { IPC::Message* reply_message, int target_tab_count); // Implementation of TabStripModelObserver. - virtual void TabInsertedAt(TabContents* contents, + virtual void TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground); - virtual void TabDetachedAt(TabContents* contents, int index); + virtual void TabDetachedAt(TabContentsWrapper* contents, int index); virtual void TabStripModelDeleted(); private: diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index a0f7269b..9b03127 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -60,7 +60,7 @@ #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/interstitial_page.h" -#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" @@ -485,7 +485,7 @@ void TestingAutomationProvider::AppendTab(int handle, const GURL& url, if (browser_tracker_->ContainsHandle(handle)) { Browser* browser = browser_tracker_->GetResource(handle); observer = AddTabStripObserver(browser, reply_message); - TabContents* contents = + TabContentsWrapper* contents = browser->AddSelectedTabWithURL(url, PageTransition::TYPED); if (contents) { append_tab_response = @@ -963,8 +963,7 @@ void TestingAutomationProvider::GetTab(int win_handle, if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) { Browser* browser = browser_tracker_->GetResource(win_handle); if (tab_index < browser->tab_count()) { - TabContents* tab_contents = - browser->GetTabContentsAt(tab_index); + TabContents* tab_contents = browser->GetTabContentsAt(tab_index); *tab_handle = tab_tracker_->Add(&tab_contents->controller()); } } diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index 3386195..2cfc68e 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -21,6 +21,7 @@ #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/pinned_tab_codec.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser.h" @@ -88,7 +89,7 @@ class MockTabStripModelObserver : public TabStripModelObserver { MockTabStripModelObserver() : closing_count_(0) {} virtual void TabClosingAt(TabStripModel* tab_strip_model, - TabContents* contents, + TabContentsWrapper* contents, int index) { closing_count_++; } @@ -424,9 +425,10 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, TabClosingWhenRemovingExtension) { ui_test_utils::NavigateToURL(browser(), url); - TabContents* app_contents = new TabContents(browser()->profile(), NULL, - MSG_ROUTING_NONE, NULL, NULL); - app_contents->SetExtensionApp(extension_app); + TabContentsWrapper* app_contents = + Browser::TabContentsFactory(browser()->profile(), NULL, + MSG_ROUTING_NONE, NULL, NULL); + app_contents->tab_contents()->SetExtensionApp(extension_app); model->AddTabContents(app_contents, 0, 0, TabStripModel::ADD_NONE); model->SetTabPinned(0, true); @@ -505,9 +507,10 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); const Extension* extension_app = GetExtension(); ui_test_utils::NavigateToURL(browser(), url); - TabContents* app_contents = new TabContents(browser()->profile(), NULL, - MSG_ROUTING_NONE, NULL, NULL); - app_contents->SetExtensionApp(extension_app); + TabContentsWrapper* app_contents = + Browser::TabContentsFactory(browser()->profile(), NULL, + MSG_ROUTING_NONE, NULL, NULL); + app_contents->tab_contents()->SetExtensionApp(extension_app); model->AddTabContents(app_contents, 0, 0, TabStripModel::ADD_NONE); model->SetTabPinned(0, true); ui_test_utils::NavigateToURL(browser(), url); @@ -553,8 +556,9 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { EXPECT_TRUE(new_model->IsTabPinned(0)); EXPECT_TRUE(new_model->IsTabPinned(1)); - EXPECT_TRUE(new_model->GetTabContentsAt(0)->extension_app() == - extension_app); + EXPECT_TRUE( + new_model->GetTabContentsAt(0)->tab_contents()->extension_app() == + extension_app); } #endif // !defined(OS_CHROMEOS) diff --git a/chrome/browser/chromeos/tab_closeable_state_watcher.cc b/chrome/browser/chromeos/tab_closeable_state_watcher.cc index e54f374..4972079 100644 --- a/chrome/browser/chromeos/tab_closeable_state_watcher.cc +++ b/chrome/browser/chromeos/tab_closeable_state_watcher.cc @@ -10,6 +10,7 @@ #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" @@ -36,24 +37,26 @@ TabCloseableStateWatcher::TabStripWatcher::~TabStripWatcher() { // TabStripModelObserver implementation: void TabCloseableStateWatcher::TabStripWatcher::TabInsertedAt( - TabContents* tab_contents, int index, bool foreground) { + TabContentsWrapper* tab_contents, int index, bool foreground) { main_watcher_->OnTabStripChanged(browser_, false); } void TabCloseableStateWatcher::TabStripWatcher::TabClosingAt( - TabStripModel* tab_strip_model, TabContents* tab_contents, int index) { + TabStripModel* tab_strip_model, + TabContentsWrapper* tab_contents, + int index) { // Check if the last tab is closing. if (tab_strip_model->count() == 1) main_watcher_->OnTabStripChanged(browser_, true); } void TabCloseableStateWatcher::TabStripWatcher::TabDetachedAt( - TabContents* tab_contents, int index) { + TabContentsWrapper* tab_contents, int index) { main_watcher_->OnTabStripChanged(browser_, false); } void TabCloseableStateWatcher::TabStripWatcher::TabChangedAt( - TabContents* tab_contents, int index, TabChangeType change_type) { + TabContentsWrapper* tab_contents, int index, TabChangeType change_type) { main_watcher_->OnTabStripChanged(browser_, false); } @@ -191,8 +194,9 @@ void TabCloseableStateWatcher::CheckAndUpdateState( } else { TabStripModel* tabstrip_model = browser_to_check->tabstrip_model(); if (tabstrip_model->count() == 1) { - new_can_close = tabstrip_model->GetTabContentsAt(0)->GetURL() != - GURL(chrome::kChromeUINewTabURL); // Tab is not NewTabPage. + new_can_close = + tabstrip_model->GetTabContentsAt(0)->tab_contents()->GetURL() != + GURL(chrome::kChromeUINewTabURL); // Tab is not NewTabPage. } else { new_can_close = true; } diff --git a/chrome/browser/chromeos/tab_closeable_state_watcher.h b/chrome/browser/chromeos/tab_closeable_state_watcher.h index 4e028af..fde2669 100644 --- a/chrome/browser/chromeos/tab_closeable_state_watcher.h +++ b/chrome/browser/chromeos/tab_closeable_state_watcher.h @@ -114,13 +114,13 @@ class TabCloseableStateWatcher : public ::TabCloseableStateWatcher, virtual ~TabStripWatcher(); // TabStripModelObserver implementation: - virtual void TabInsertedAt(TabContents* contents, int index, + 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 TabChangedAt(TabContents* contents, int index, + virtual void TabDetachedAt(TabContentsWrapper* contents, int index); + virtual void TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type); const Browser* browser() const { diff --git a/chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc b/chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc index f94cfd0..6e23c0f 100644 --- a/chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc +++ b/chrome/browser/chromeos/tab_closeable_state_watcher_browsertest.cc @@ -102,7 +102,8 @@ class NewTabObserver : public TabStripModelObserver { } private: - virtual void TabInsertedAt(TabContents* contents, int index, + virtual void TabInsertedAt(TabContentsWrapper* contents, + int index, bool foreground) { MessageLoopForUI::current()->Quit(); } diff --git a/chrome/browser/chromeos/wm_overview_controller.cc b/chrome/browser/chromeos/wm_overview_controller.cc index 2d56e7b..8d373d8 100644 --- a/chrome/browser/chromeos/wm_overview_controller.cc +++ b/chrome/browser/chromeos/wm_overview_controller.cc @@ -19,6 +19,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/views/frame/browser_view.h" @@ -71,22 +72,22 @@ class BrowserListener : public TabStripModelObserver { ~BrowserListener(); // Begin TabStripModelObserver methods - 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 TabMoved(TabContents* contents, + virtual void TabDetachedAt(TabContentsWrapper* contents, int index); + virtual void TabMoved(TabContentsWrapper* contents, int from_index, int to_index); - virtual void TabChangedAt(TabContents* contents, int index, + virtual void TabChangedAt(TabContentsWrapper* contents, int index, TabStripModelObserver::TabChangeType change_type); virtual void TabStripEmpty(); - virtual void TabDeselectedAt(TabContents* contents, int index) {} - virtual void TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabDeselectedAt(TabContentsWrapper* contents, int index) {} + virtual void TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture); // End TabStripModelObserver methods @@ -127,7 +128,7 @@ class BrowserListener : public TabStripModelObserver { // Returns the tab contents from the tab model for this child at index. TabContents* GetTabContentsAt(int index) const { - return browser_->tabstrip_model()->GetTabContentsAt(index); + return browser_->tabstrip_model()->GetTabContentsAt(index)->tab_contents(); } private: // Calculate the size of a cell based on the browser window's size. @@ -203,7 +204,7 @@ BrowserListener::~BrowserListener() { browser_->tabstrip_model()->RemoveObserver(this); } -void BrowserListener::TabInsertedAt(TabContents* contents, +void BrowserListener::TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground) { InsertSnapshot(index); @@ -211,13 +212,13 @@ void BrowserListener::TabInsertedAt(TabContents* contents, UpdateSelectedIndex(browser_->selected_index()); } -void BrowserListener::TabDetachedAt(TabContents* contents, int index) { +void BrowserListener::TabDetachedAt(TabContentsWrapper* contents, int index) { ClearSnapshot(index); UpdateSelectedIndex(browser_->selected_index()); RenumberSnapshots(index); } -void BrowserListener::TabMoved(TabContents* contents, +void BrowserListener::TabMoved(TabContentsWrapper* contents, int from_index, int to_index) { // Need to reorder tab in the snapshots list, and reset the window @@ -232,13 +233,14 @@ void BrowserListener::TabMoved(TabContents* contents, } void BrowserListener::TabChangedAt( - TabContents* contents, + TabContentsWrapper* contents, int index, TabStripModelObserver::TabChangeType change_type) { if (change_type != TabStripModelObserver::LOADING_ONLY) { - snapshots_[index].title->SetTitle(contents->GetTitle()); - snapshots_[index].title->SetUrl(contents->GetURL()); - snapshots_[index].fav_icon->SetFavIcon(contents->GetFavIcon()); + snapshots_[index].title->SetTitle(contents->tab_contents()->GetTitle()); + snapshots_[index].title->SetUrl(contents->tab_contents()->GetURL()); + snapshots_[index].fav_icon->SetFavIcon( + contents->tab_contents()->GetFavIcon()); if (change_type != TabStripModelObserver::TITLE_NOT_LOADING) ReloadSnapshot(index); } @@ -248,8 +250,8 @@ void BrowserListener::TabStripEmpty() { snapshots_.clear(); } -void BrowserListener::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, +void BrowserListener::TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture) { UpdateSelectedIndex(index); diff --git a/chrome/browser/cocoa/applescript/window_applescript.mm b/chrome/browser/cocoa/applescript/window_applescript.mm index 7f5e6a5..631d52c 100644 --- a/chrome/browser/cocoa/applescript/window_applescript.mm +++ b/chrome/browser/cocoa/applescript/window_applescript.mm @@ -18,6 +18,7 @@ #import "chrome/browser/cocoa/applescript/tab_applescript.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_navigator.h" #include "chrome/common/url_constants.h" @@ -170,16 +171,16 @@ // Set how long it takes a tab to be created. base::TimeTicks newTabStartTime = base::TimeTicks::Now(); - TabContents* contents = + TabContentsWrapper* contents = browser_->AddSelectedTabWithURL(GURL(chrome::kChromeUINewTabURL), PageTransition::TYPED); - contents->set_new_tab_start_time(newTabStartTime); - - [aTab setTabContent:contents]; + contents->tab_contents()->set_new_tab_start_time(newTabStartTime); + [aTab setTabContent:contents->tab_contents()]; } - (void)insertInTabs:(TabAppleScript*)aTab atIndex:(int)index { // This method gets called when a new tab is created so + // This method gets called when a new tab is created so // the container and property are set here. [aTab setContainer:self property:AppleScript::kTabsProperty]; @@ -192,9 +193,10 @@ params.disposition = NEW_FOREGROUND_TAB; params.tabstrip_index = index; browser::Navigate(¶ms); - params.target_contents->set_new_tab_start_time(newTabStartTime); + params.target_contents->tab_contents()->set_new_tab_start_time( + newTabStartTime); - [aTab setTabContent:params.target_contents]; + [aTab setTabContent:params.target_contents->tab_contents()]; } - (void)removeFromTabsAtIndex:(int)index { diff --git a/chrome/browser/cocoa/bookmarks/bookmark_all_tabs_controller.mm b/chrome/browser/cocoa/bookmarks/bookmark_all_tabs_controller.mm index 0c4be7c..125d8e1 100644 --- a/chrome/browser/cocoa/bookmarks/bookmark_all_tabs_controller.mm +++ b/chrome/browser/cocoa/bookmarks/bookmark_all_tabs_controller.mm @@ -11,6 +11,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.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 "grit/generated_resources.h" @@ -44,7 +45,7 @@ TabStripModel* tabstrip_model = browser->tabstrip_model(); const int tabCount = tabstrip_model->count(); for (int i = 0; i < tabCount; ++i) { - TabContents* tc = tabstrip_model->GetTabContentsAt(i); + TabContents* tc = tabstrip_model->GetTabContentsAt(i)->tab_contents(); const string16 tabTitle = tc->GetTitle(); const GURL& tabURL(tc->GetURL()); ActiveTabNameURLPair tabPair(tabTitle, tabURL); diff --git a/chrome/browser/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmarks/bookmark_bar_controller.mm index 03e867e..79d8c23 100644 --- a/chrome/browser/cocoa/bookmarks/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmarks/bookmark_bar_controller.mm @@ -1970,9 +1970,8 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { #pragma mark BookmarkBarToolbarViewController Protocol - (int)currentTabContentsHeight { - return browser_->GetSelectedTabContents() ? - browser_->GetSelectedTabContents()->view()->GetContainerSize().height() : - 0; + TabContents* tc = browser_->GetSelectedTabContents(); + return tc ? tc->view()->GetContainerSize().height() : 0; } - (ThemeProvider*)themeProvider { diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h index 486ec11..1e9cf22 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -56,7 +56,7 @@ class BrowserWindowCocoa : public BrowserWindow, virtual LocationBar* GetLocationBar() const; virtual void SetFocusToLocationBar(bool select_all); virtual void UpdateReloadStopState(bool is_loading, bool force); - virtual void UpdateToolbar(TabContents* contents, + virtual void UpdateToolbar(TabContentsWrapper* contents, bool should_restore_state); virtual void FocusToolbar(); virtual void FocusAppMenu(); diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 5ce7156..8cac684 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -40,6 +40,7 @@ #include "chrome/browser/sidebar/sidebar_container.h" #include "chrome/browser/sidebar/sidebar_manager.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/native_web_keyboard_event.h" #include "chrome/common/notification_service.h" @@ -180,7 +181,7 @@ void BrowserWindowCocoa::ShelfVisibilityChanged() { void BrowserWindowCocoa::UpdateDevTools() { [controller_ updateDevToolsForContents: - browser_->tabstrip_model()->GetSelectedTabContents()]; + browser_->GetSelectedTabContents()]; } void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) { @@ -243,9 +244,9 @@ void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) { [controller_ setIsLoading:is_loading force:force]; } -void BrowserWindowCocoa::UpdateToolbar(TabContents* contents, +void BrowserWindowCocoa::UpdateToolbar(TabContentsWrapper* contents, bool should_restore_state) { - [controller_ updateToolbarWithContents:contents + [controller_ updateToolbarWithContents:contents->tab_contents() shouldRestoreState:should_restore_state ? YES : NO]; } @@ -625,7 +626,7 @@ NSWindow* BrowserWindowCocoa::window() const { } void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { - if (tab_contents == browser_->tabstrip_model()->GetSelectedTabContents()) { + if (tab_contents == browser_->GetSelectedTabContents()) { [controller_ updateSidebarForContents:tab_contents]; } } diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index b074603..b2a83d7 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -54,6 +54,7 @@ #include "chrome/browser/sync/sync_ui_util_mac.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view_mac.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/themes/browser_theme_provider.h" #include "chrome/browser/window_sizer.h" @@ -616,7 +617,7 @@ std::max(kProportion * frame.size.width, std::min(kProportion * frame.size.height, frame.size.width)); - TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents(); + TabContents* contents = browser_->GetSelectedTabContents(); if (contents) { // If the intrinsic width is bigger, then make it the zoomed width. const int kScrollbarWidth = 16; // TODO(viettrungluu): ugh. @@ -1086,8 +1087,8 @@ if (!isBrowser) return; BrowserWindowController* dragBWC = (BrowserWindowController*)dragController; int index = [dragBWC->tabStripController_ modelIndexForTabView:view]; - TabContents* contents = - dragBWC->browser_->tabstrip_model()->GetTabContentsAt(index); + TabContentsWrapper* contents = + dragBWC->browser_->GetTabContentsWrapperAt(index); // The tab contents may have gone away if given a window.close() while it // is being dragged. If so, bail, we've got nothing to drop. if (!contents) @@ -1165,7 +1166,7 @@ // Fetch the tab contents for the tab being dragged. int index = [tabStripController_ modelIndexForTabView:tabView]; - TabContents* contents = browser_->tabstrip_model()->GetTabContentsAt(index); + TabContentsWrapper* contents = browser_->GetTabContentsWrapperAt(index); // Set the window size. Need to do this before we detach the tab so it's // still in the window. We have to flip the coordinates as that's what @@ -1323,7 +1324,7 @@ } - (NSString*)selectedTabTitle { - TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents(); + TabContents* contents = browser_->GetSelectedTabContents(); return base::SysUTF16ToNSString(contents->GetTitle()); } diff --git a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm index 9ff22eee..6396115 100644 --- a/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar/location_bar_view_mac.mm @@ -314,7 +314,7 @@ void LocationBarViewMac::OnChanged() { if (update_instant_ && instant && GetTabContents()) { if (edit_view_->model()->user_input_in_progress() && edit_view_->model()->popup_model()->IsOpen()) { - instant->Update(GetTabContents(), + instant->Update(browser_->GetSelectedTabContentsWrapper(), edit_view_->model()->CurrentMatch(), WideToUTF16(edit_view_->GetText()), &suggested_text); diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h index b063d9a..bc3210c 100644 --- a/chrome/browser/cocoa/tab_strip_controller.h +++ b/chrome/browser/cocoa/tab_strip_controller.h @@ -177,7 +177,7 @@ class ToolbarModel; // previous window, setting |pinned| to YES will propagate that state to the // new window. Mini-tabs are either app or pinned tabs; the app state is stored // by the |contents|, but the |pinned| state is the caller's responsibility. -- (void)dropTabContents:(TabContents*)contents +- (void)dropTabContents:(TabContentsWrapper*)contents withFrame:(NSRect)frame asPinnedTab:(BOOL)pinned; diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 3ccdf3f..15b4e9c 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -37,6 +37,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_navigator.h" #include "grit/app_resources.h" @@ -376,9 +377,10 @@ private: // means the tab model is already fully formed with tabs. Need to walk the // list and create the UI for each. const int existingTabCount = tabStripModel_->count(); - const TabContents* selection = tabStripModel_->GetSelectedTabContents(); + const TabContentsWrapper* selection = + tabStripModel_->GetSelectedTabContents(); for (int i = 0; i < existingTabCount; ++i) { - TabContents* currentContents = tabStripModel_->GetTabContentsAt(i); + TabContentsWrapper* currentContents = tabStripModel_->GetTabContentsAt(i); [self insertTabWithContents:currentContents atIndex:i inForeground:NO]; @@ -474,15 +476,17 @@ private: // Make sure the new tabs's sheets are visible (necessary when a background // tab opened a sheet while it was in the background and now becomes active). - TabContents* newTab = tabStripModel_->GetTabContentsAt(modelIndex); + TabContentsWrapper* newTab = tabStripModel_->GetTabContentsAt(modelIndex); DCHECK(newTab); if (newTab) { TabContents::ConstrainedWindowList::iterator it, end; - end = newTab->constrained_window_end(); + end = newTab->tab_contents()->constrained_window_end(); NSWindowController* controller = [[newView window] windowController]; DCHECK([controller isKindOfClass:[BrowserWindowController class]]); - for (it = newTab->constrained_window_begin(); it != end; ++it) { + for (it = newTab->tab_contents()->constrained_window_begin(); + it != end; + ++it) { ConstrainedWindow* constrainedWindow = *it; static_cast<ConstrainedWindowMac*>(constrainedWindow)->Realize( static_cast<BrowserWindowController*>(controller)); @@ -627,10 +631,10 @@ private: if (!tabStripModel_->ContainsIndex(index)) return; - TabContents* contents = tabStripModel_->GetTabContentsAt(index); + TabContentsWrapper* contents = tabStripModel_->GetTabContentsAt(index); if (contents) UserMetrics::RecordAction(UserMetricsAction("CloseTab_Mouse"), - contents->profile()); + contents->tab_contents()->profile()); const NSInteger numberOfOpenTabs = [self numberOfOpenTabs]; if (numberOfOpenTabs > 1) { bool isClosingLastTab = index == numberOfOpenTabs - 1; @@ -960,7 +964,7 @@ private: // Called when a notification is received from the model to insert a new tab // at |modelIndex|. -- (void)insertTabWithContents:(TabContents*)contents +- (void)insertTabWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)modelIndex inForeground:(bool)inForeground { DCHECK(contents); @@ -973,7 +977,8 @@ private: // Make a new tab. Load the contents of this tab from the nib and associate // the new controller with |contents| so it can be looked up later. scoped_nsobject<TabContentsController> contentsController( - [[TabContentsController alloc] initWithContents:contents delegate:self]); + [[TabContentsController alloc] initWithContents:contents->tab_contents() + delegate:self]); [tabContentsArray_ insertObject:contentsController atIndex:index]; // Make a new tab and add it to the strip. Keep track of its controller. @@ -990,7 +995,7 @@ private: [newView setFrame:NSOffsetRect([newView frame], 0, -[[self class] defaultTabHeight])]; - [self setTabTitle:newController withContents:contents]; + [self setTabTitle:newController withContents:contents->tab_contents()]; // If a tab is being inserted, we can again use the entire tab strip width // for layout. @@ -1008,7 +1013,7 @@ private: // dragging a tab out into a new window, we have to put the tab's favicon // into the right state up front as we won't be told to do it from anywhere // else. - [self updateFavIconForContents:contents atIndex:modelIndex]; + [self updateFavIconForContents:contents->tab_contents() atIndex:modelIndex]; // Send a broadcast that the number of tabs have changed. [[NSNotificationCenter defaultCenter] @@ -1018,8 +1023,8 @@ private: // Called when a notification is received from the model to select a particular // tab. Swaps in the toolbar and content area associated with |newContents|. -- (void)selectTabWithContents:(TabContents*)newContents - previousContents:(TabContents*)oldContents +- (void)selectTabWithContents:(TabContentsWrapper*)newContents + previousContents:(TabContentsWrapper*)oldContents atIndex:(NSInteger)modelIndex userGesture:(bool)wasUserGesture { // Take closing tabs into account. @@ -1034,7 +1039,7 @@ private: [tabContentsArray_ objectAtIndex:oldIndex]; [oldController willBecomeUnselectedTab]; oldContents->view()->StoreFocus(); - oldContents->WasHidden(); + oldContents->tab_contents()->WasHidden(); } } @@ -1060,33 +1065,34 @@ private: [self swapInTabAtIndex:modelIndex]; if (newContents) { - newContents->DidBecomeSelected(); + newContents->tab_contents()->DidBecomeSelected(); newContents->view()->RestoreFocus(); - if (newContents->find_ui_active()) + if (newContents->tab_contents()->find_ui_active()) browser_->GetFindBarController()->find_bar()->SetFocusAndSelection(); } } -- (void)tabReplacedWithContents:(TabContents*)newContents - previousContents:(TabContents*)oldContents +- (void)tabReplacedWithContents:(TabContentsWrapper*)newContents + previousContents:(TabContentsWrapper*)oldContents atIndex:(NSInteger)modelIndex { NSInteger index = [self indexFromModelIndex:modelIndex]; TabContentsController* oldController = [tabContentsArray_ objectAtIndex:index]; - DCHECK_EQ(oldContents, [oldController tabContents]); + DCHECK_EQ(oldContents->tab_contents(), [oldController tabContents]); // Simply create a new TabContentsController for |newContents| and place it // into the array, replacing |oldContents|. A TabSelectedAt notification will // follow, at which point we will install the new view. scoped_nsobject<TabContentsController> newController( - [[TabContentsController alloc] initWithContents:newContents - delegate:self]); + [[TabContentsController alloc] + initWithContents:newContents->tab_contents() + delegate:self]); // Bye bye, |oldController|. [tabContentsArray_ replaceObjectAtIndex:index withObject:newController]; - [delegate_ onReplaceTabWithContents:newContents]; + [delegate_ onReplaceTabWithContents:newContents->tab_contents()]; } // Remove all knowledge about this tab and its associated controller, and remove @@ -1171,7 +1177,7 @@ private: // Called when a notification is received from the model that the given tab // has gone away. Start an animation then force a layout to put everything // in motion. -- (void)tabDetachedWithContents:(TabContents*)contents +- (void)tabDetachedWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)modelIndex { // Take closing tabs into account. NSInteger index = [self indexFromModelIndex:modelIndex]; @@ -1189,7 +1195,7 @@ private: postNotificationName:kTabStripNumberOfTabsChanged object:self]; - [delegate_ onTabDetachedWithContents:contents]; + [delegate_ onTabDetachedWithContents:contents->tab_contents()]; } // A helper routine for creating an NSImageView to hold the fav icon or app icon @@ -1289,7 +1295,7 @@ private: // Called when a notification is received from the model that the given tab // has been updated. |loading| will be YES when we only want to update the // throbber state, not anything else about the (partially) loading tab. -- (void)tabChangedWithContents:(TabContents*)contents +- (void)tabChangedWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)modelIndex changeType:(TabStripModelObserver::TabChangeType)change { // Take closing tabs into account. @@ -1307,19 +1313,19 @@ private: TabController* tabController = [tabArray_ objectAtIndex:index]; if (change != TabStripModelObserver::LOADING_ONLY) - [self setTabTitle:tabController withContents:contents]; + [self setTabTitle:tabController withContents:contents->tab_contents()]; - [self updateFavIconForContents:contents atIndex:modelIndex]; + [self updateFavIconForContents:contents->tab_contents() atIndex:modelIndex]; TabContentsController* updatedController = [tabContentsArray_ objectAtIndex:index]; - [updatedController tabDidChange:contents]; + [updatedController tabDidChange:contents->tab_contents()]; } // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays // in sync with the tab strip model. It can also be pinned/unpinned // simultaneously, so we need to take care of that. -- (void)tabMovedWithContents:(TabContents*)contents +- (void)tabMovedWithContents:(TabContentsWrapper*)contents fromIndex:(NSInteger)modelFrom toIndex:(NSInteger)modelTo { // Take closing tabs into account. @@ -1345,7 +1351,7 @@ private: } // Called when a tab is pinned or unpinned without moving. -- (void)tabMiniStateChangedWithContents:(TabContents*)contents +- (void)tabMiniStateChangedWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)modelIndex { // Take closing tabs into account. NSInteger index = [self indexFromModelIndex:modelIndex]; @@ -1360,7 +1366,7 @@ private: [tabController setMini:tabStripModel_->IsMiniTab(modelIndex)]; [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; - [self updateFavIconForContents:contents atIndex:modelIndex]; + [self updateFavIconForContents:contents->tab_contents() atIndex:modelIndex]; // If the tab is being restored and it's pinned, the mini state is set after // the tab has already been rendered, so re-layout the tabstrip. In all other // cases, the state is set before the tab is rendered so this isn't needed. @@ -1434,7 +1440,7 @@ private: // previous window, setting |pinned| to YES will propagate that state to the // new window. Mini-tabs are either app or pinned tabs; the app state is stored // by the |contents|, but the |pinned| state is the caller's responsibility. -- (void)dropTabContents:(TabContents*)contents +- (void)dropTabContents:(TabContentsWrapper*)contents withFrame:(NSRect)frame asPinnedTab:(BOOL)pinned { int modelIndex = [self indexOfPlaceholder]; @@ -1715,8 +1721,9 @@ private: case CURRENT_TAB: UserMetrics::RecordAction(UserMetricsAction("Tab_DropURLOnTab"), browser_->profile()); - tabStripModel_->GetTabContentsAt(index)->OpenURL(url, GURL(), CURRENT_TAB, - PageTransition::TYPED); + tabStripModel_->GetTabContentsAt(index) + ->tab_contents()->OpenURL(url, GURL(), CURRENT_TAB, + PageTransition::TYPED); tabStripModel_->SelectTabContentsAt(index, true); break; default: diff --git a/chrome/browser/cocoa/tab_strip_controller_unittest.mm b/chrome/browser/cocoa/tab_strip_controller_unittest.mm index 04cf539..7cfde56 100644 --- a/chrome/browser/cocoa/tab_strip_controller_unittest.mm +++ b/chrome/browser/cocoa/tab_strip_controller_unittest.mm @@ -11,6 +11,7 @@ #import "chrome/browser/cocoa/tab_strip_controller.h" #import "chrome/browser/cocoa/tab_strip_view.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/renderer_host/site_instance.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -36,26 +37,26 @@ namespace { // Stub model delegate class TestTabStripDelegate : public TabStripModelDelegate { public: - virtual TabContents* AddBlankTab(bool foreground) { + virtual TabContentsWrapper* AddBlankTab(bool foreground) { return NULL; } - virtual TabContents* AddBlankTabAt(int index, bool foreground) { + virtual TabContentsWrapper* AddBlankTabAt(int index, bool foreground) { return NULL; } - virtual Browser* CreateNewStripWithContents(TabContents* contents, + virtual Browser* CreateNewStripWithContents(TabContentsWrapper* contents, const gfx::Rect& window_bounds, const DockInfo& dock_info, bool maximize) { return NULL; } - virtual void ContinueDraggingDetachedTab(TabContents* contents, - const gfx::Rect& window_bounds, - const gfx::Rect& tab_bounds) { + 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, @@ -67,8 +68,8 @@ class TestTabStripDelegate : public TabStripModelDelegate { virtual bool CanDuplicateContentsAt(int index) { return true; } 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 true; } virtual bool CanRestoreTab() { @@ -152,9 +153,9 @@ TEST_F(TabStripControllerTest, AddRemoveTabs) { EXPECT_TRUE(model_->empty()); SiteInstance* instance = SiteInstance::CreateSiteInstance(browser_helper_.profile()); - TabContents* tab_contents = - new TabContents(browser_helper_.profile(), instance, MSG_ROUTING_NONE, - NULL, NULL); + TabContentsWrapper* tab_contents = + Browser::TabContentsFactory(browser_helper_.profile(), instance, + MSG_ROUTING_NONE, NULL, NULL); model_->AppendTabContents(tab_contents, true); EXPECT_EQ(model_->count(), 1); } diff --git a/chrome/browser/cocoa/tab_strip_model_observer_bridge.h b/chrome/browser/cocoa/tab_strip_model_observer_bridge.h index f5b0619..fa9d1d7 100644 --- a/chrome/browser/cocoa/tab_strip_model_observer_bridge.h +++ b/chrome/browser/cocoa/tab_strip_model_observer_bridge.h @@ -10,7 +10,7 @@ #include "chrome/browser/tabs/tab_strip_model_observer.h" -class TabContents; +class TabContentsWrapper; class TabStripModel; // A C++ bridge class to handle receiving notifications from the C++ tab strip @@ -24,26 +24,26 @@ class TabStripModelObserverBridge : public TabStripModelObserver { virtual ~TabStripModelObserverBridge(); // 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 TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabDetachedAt(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 TabChangedAt(TabContents* contents, int index, + virtual void TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type); - virtual void TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index); - virtual void TabMiniStateChanged(TabContents* contents, int index); + virtual void TabMiniStateChanged(TabContentsWrapper* contents, int index); virtual void TabStripEmpty(); virtual void TabStripModelDeleted(); @@ -56,27 +56,27 @@ class TabStripModelObserverBridge : public TabStripModelObserver { // Cocoa object to receive updates about changes to a tab strip model. It is // ok to not implement them, the calling code checks before calling. @interface NSObject(TabStripModelBridge) -- (void)insertTabWithContents:(TabContents*)contents +- (void)insertTabWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index inForeground:(bool)inForeground; -- (void)tabClosingWithContents:(TabContents*)contents +- (void)tabClosingWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index; -- (void)tabDetachedWithContents:(TabContents*)contents +- (void)tabDetachedWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index; -- (void)selectTabWithContents:(TabContents*)newContents - previousContents:(TabContents*)oldContents +- (void)selectTabWithContents:(TabContentsWrapper*)newContents + previousContents:(TabContentsWrapper*)oldContents atIndex:(NSInteger)index userGesture:(bool)wasUserGesture; -- (void)tabMovedWithContents:(TabContents*)contents +- (void)tabMovedWithContents:(TabContentsWrapper*)contents fromIndex:(NSInteger)from toIndex:(NSInteger)to; -- (void)tabChangedWithContents:(TabContents*)contents +- (void)tabChangedWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index changeType:(TabStripModelObserver::TabChangeType)change; -- (void)tabReplacedWithContents:(TabContents*)newContents - previousContents:(TabContents*)oldContents +- (void)tabReplacedWithContents:(TabContentsWrapper*)newContents + previousContents:(TabContentsWrapper*)oldContents atIndex:(NSInteger)index; -- (void)tabMiniStateChangedWithContents:(TabContents*)contents +- (void)tabMiniStateChangedWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index; - (void)tabStripEmpty; - (void)tabStripModelDeleted; diff --git a/chrome/browser/cocoa/tab_strip_model_observer_bridge.mm b/chrome/browser/cocoa/tab_strip_model_observer_bridge.mm index fbe5616..7aad635 100644 --- a/chrome/browser/cocoa/tab_strip_model_observer_bridge.mm +++ b/chrome/browser/cocoa/tab_strip_model_observer_bridge.mm @@ -20,7 +20,7 @@ TabStripModelObserverBridge::~TabStripModelObserverBridge() { model_->RemoveObserver(this); } -void TabStripModelObserverBridge::TabInsertedAt(TabContents* contents, +void TabStripModelObserverBridge::TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground) { if ([controller_ respondsToSelector: @@ -32,7 +32,7 @@ void TabStripModelObserverBridge::TabInsertedAt(TabContents* contents, } void TabStripModelObserverBridge::TabClosingAt(TabStripModel* tab_strip_model, - TabContents* contents, + TabContentsWrapper* contents, int index) { if ([controller_ respondsToSelector: @selector(tabClosingWithContents:atIndex:)]) { @@ -40,7 +40,7 @@ void TabStripModelObserverBridge::TabClosingAt(TabStripModel* tab_strip_model, } } -void TabStripModelObserverBridge::TabDetachedAt(TabContents* contents, +void TabStripModelObserverBridge::TabDetachedAt(TabContentsWrapper* contents, int index) { if ([controller_ respondsToSelector: @selector(tabDetachedWithContents:atIndex:)]) { @@ -48,10 +48,11 @@ void TabStripModelObserverBridge::TabDetachedAt(TabContents* contents, } } -void TabStripModelObserverBridge::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, - int index, - bool user_gesture) { +void TabStripModelObserverBridge::TabSelectedAt( + TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, + int index, + bool user_gesture) { if ([controller_ respondsToSelector: @selector(selectTabWithContents:previousContents:atIndex: userGesture:)]) { @@ -62,7 +63,7 @@ void TabStripModelObserverBridge::TabSelectedAt(TabContents* old_contents, } } -void TabStripModelObserverBridge::TabMoved(TabContents* contents, +void TabStripModelObserverBridge::TabMoved(TabContentsWrapper* contents, int from_index, int to_index) { if ([controller_ respondsToSelector: @@ -73,7 +74,7 @@ void TabStripModelObserverBridge::TabMoved(TabContents* contents, } } -void TabStripModelObserverBridge::TabChangedAt(TabContents* contents, +void TabStripModelObserverBridge::TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type) { if ([controller_ respondsToSelector: @@ -84,9 +85,10 @@ void TabStripModelObserverBridge::TabChangedAt(TabContents* contents, } } -void TabStripModelObserverBridge::TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, - int index) { +void TabStripModelObserverBridge::TabReplacedAt( + TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, + int index) { if ([controller_ respondsToSelector: @selector(tabReplacedWithContents:previousContents:atIndex:)]) { [controller_ tabReplacedWithContents:new_contents @@ -97,8 +99,8 @@ void TabStripModelObserverBridge::TabReplacedAt(TabContents* old_contents, } } -void TabStripModelObserverBridge::TabMiniStateChanged(TabContents* contents, - int index) { +void TabStripModelObserverBridge::TabMiniStateChanged( + TabContentsWrapper* contents, int index) { if ([controller_ respondsToSelector: @selector(tabMiniStateChangedWithContents:atIndex:)]) { [controller_ tabMiniStateChangedWithContents:contents atIndex:index]; diff --git a/chrome/browser/cocoa/tabpose_window.mm b/chrome/browser/cocoa/tabpose_window.mm index dde7caf..eecbd65 100644 --- a/chrome/browser/cocoa/tabpose_window.mm +++ b/chrome/browser/cocoa/tabpose_window.mm @@ -23,7 +23,9 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/pref_names.h" #include "grit/app_resources.h" #include "skia/ext/skia_utils_mac.h" @@ -522,7 +524,7 @@ void TileSet::Build(TabStripModel* source_model) { tiles_.resize(source_model->count()); for (size_t i = 0; i < tiles_.size(); ++i) { tiles_[i] = new Tile; - tiles_[i]->contents_ = source_model->GetTabContentsAt(i); + tiles_[i]->contents_ = source_model->GetTabContentsAt(i)->tab_contents(); } } @@ -1281,7 +1283,7 @@ void AnimateCALayerFrameFromTo( thumbLayer.frame = NSRectToCGRect(tile.thumb_rect()); } -- (void)insertTabWithContents:(TabContents*)contents +- (void)insertTabWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index inForeground:(bool)inForeground { // This happens if you cmd-click a link and then immediately open tabpose @@ -1289,7 +1291,7 @@ void AnimateCALayerFrameFromTo( ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); // Insert new layer and relayout. - tileSet_->InsertTileAt(index, contents); + tileSet_->InsertTileAt(index, contents->tab_contents()); tileSet_->Layout(containingRect_); [self addLayersForTile:tileSet_->tile_at(index) showZoom:NO @@ -1317,13 +1319,13 @@ void AnimateCALayerFrameFromTo( [self selectTileAtIndex:selectedIndex]; } -- (void)tabClosingWithContents:(TabContents*)contents +- (void)tabClosingWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index { // We will also get a -tabDetachedWithContents:atIndex: notification for // closing tabs, so do nothing here. } -- (void)tabDetachedWithContents:(TabContents*)contents +- (void)tabDetachedWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index { ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); @@ -1360,7 +1362,7 @@ void AnimateCALayerFrameFromTo( [self selectTileAtIndex:selectedIndex]; } -- (void)tabMovedWithContents:(TabContents*)contents +- (void)tabMovedWithContents:(TabContentsWrapper*)contents fromIndex:(NSInteger)from toIndex:(NSInteger)to { ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); @@ -1397,7 +1399,7 @@ void AnimateCALayerFrameFromTo( [self selectTileAtIndex:selectedIndex]; } -- (void)tabChangedWithContents:(TabContents*)contents +- (void)tabChangedWithContents:(TabContentsWrapper*)contents atIndex:(NSInteger)index changeType:(TabStripModelObserver::TabChangeType)change { // Tell the window to update text, title, and thumb layers at |index| to get @@ -1409,16 +1411,16 @@ void AnimateCALayerFrameFromTo( // For now, just make sure that we don't hold on to an invalid TabContents // object. tabpose::Tile& tile = tileSet_->tile_at(index); - if (contents == tile.tab_contents()) { + if (contents->tab_contents() == tile.tab_contents()) { // TODO(thakis): Install a timer to send a thumb request/update title/update // favicon after 20ms or so, and reset the timer every time this is called // to make sure we get an updated thumb, without requesting them all over. return; } - tile.set_tab_contents(contents); + tile.set_tab_contents(contents->tab_contents()); ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; - [thumbLayer setTabContents:contents]; + [thumbLayer setTabContents:contents->tab_contents()]; } - (void)tabStripModelDeleted { diff --git a/chrome/browser/cocoa/tabpose_window_unittest.mm b/chrome/browser/cocoa/tabpose_window_unittest.mm index c1c56d2..4874b30 100644 --- a/chrome/browser/cocoa/tabpose_window_unittest.mm +++ b/chrome/browser/cocoa/tabpose_window_unittest.mm @@ -9,6 +9,7 @@ #import "chrome/browser/cocoa/cocoa_test_helper.h" #include "chrome/browser/renderer_host/site_instance.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 "testing/gtest/include/gtest/gtest.h" @@ -20,7 +21,7 @@ class TabposeWindowTest : public CocoaTest { } void AppendTabToStrip() { - TabContents* tab_contents = new TabContents( + TabContentsWrapper* tab_contents = Browser::TabContentsFactory( browser_helper_.profile(), site_instance_, MSG_ROUTING_NONE, NULL, NULL); browser_helper_.browser()->tabstrip_model()->AppendTabContents( diff --git a/chrome/browser/debugger/devtools_http_protocol_handler.cc b/chrome/browser/debugger/devtools_http_protocol_handler.cc index 24be8b6..5327008 100644 --- a/chrome/browser/debugger/devtools_http_protocol_handler.cc +++ b/chrome/browser/debugger/devtools_http_protocol_handler.cc @@ -15,6 +15,7 @@ #include "chrome/browser/debugger/devtools_client_host.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser.h" @@ -173,7 +174,7 @@ void DevToolsHttpProtocolHandler::OnHttpRequestUI( end = BrowserList::end(); it != end; ++it) { TabStripModel* model = (*it)->tabstrip_model(); for (int i = 0, size = model->count(); i < size; ++i) { - TabContents* tab_contents = model->GetTabContentsAt(i); + TabContentsWrapper* tab_contents = model->GetTabContentsAt(i); NavigationController& controller = tab_contents->controller(); NavigationEntry* entry = controller.GetActiveEntry(); if (entry == NULL) @@ -183,7 +184,8 @@ void DevToolsHttpProtocolHandler::OnHttpRequestUI( continue; DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> - GetDevToolsClientHostFor(tab_contents->render_view_host()); + GetDevToolsClientHostFor(tab_contents->tab_contents()-> + render_view_host()); if (!client_host) { response += StringPrintf( "<a href='/devtools/devtools.html?page=%d'>%s (%s)</a><br>", diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc index 5b2d265..b18703c 100644 --- a/chrome/browser/debugger/devtools_window.cc +++ b/chrome/browser/debugger/devtools_window.cc @@ -22,6 +22,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/themes/browser_theme_provider.h" #include "chrome/browser/ui/browser.h" @@ -53,7 +54,7 @@ TabContents* DevToolsWindow::GetDevToolsContents(TabContents* inspected_tab) { if (!window || !window->is_docked()) { return NULL; } - return window->tab_contents(); + return window->tab_contents()->tab_contents(); } DevToolsWindow::DevToolsWindow(Profile* profile, @@ -65,8 +66,10 @@ DevToolsWindow::DevToolsWindow(Profile* profile, is_loaded_(false), action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) { // Create TabContents with devtools. - tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); - tab_contents_->render_view_host()->AllowBindings(BindingsPolicy::DOM_UI); + tab_contents_ = + Browser::TabContentsFactory(profile, NULL, MSG_ROUTING_NONE, NULL, NULL); + tab_contents_->tab_contents()-> + render_view_host()->AllowBindings(BindingsPolicy::DOM_UI); tab_contents_->controller().LoadURL( GetDevToolsUrl(), GURL(), PageTransition::START_PAGE); @@ -95,7 +98,8 @@ DevToolsWindow* DevToolsWindow::AsDevToolsWindow() { } void DevToolsWindow::SendMessageToClient(const IPC::Message& message) { - RenderViewHost* target_host = tab_contents_->render_view_host(); + RenderViewHost* target_host = + tab_contents_->tab_contents()->render_view_host(); IPC::Message* m = new IPC::Message(message); m->set_routing_id(target_host->routing_id()); target_host->Send(m); @@ -130,7 +134,7 @@ void DevToolsWindow::Show(DevToolsToggleAction action) { if (FindInspectedBrowserAndTabIndex(&inspected_browser, &inspected_tab_index)) { BrowserWindow* inspected_window = inspected_browser->window(); - tab_contents_->set_delegate(this); + tab_contents_->tab_contents()->set_delegate(this); inspected_window->UpdateDevTools(); SetAttachedWindow(); tab_contents_->view()->SetInitialFocus(); @@ -270,8 +274,9 @@ void DevToolsWindow::AddDevToolsExtensionsToClient() { CallClientFunction(L"WebInspector.setInspectedTabId", tabId); } ListValue results; - const ExtensionsService* extension_service = tab_contents_->profile()-> - GetOriginalProfile()->GetExtensionsService(); + const ExtensionsService* extension_service = + tab_contents_->tab_contents()->profile()-> + GetOriginalProfile()->GetExtensionsService(); const ExtensionList* extensions = extension_service->extensions(); for (ExtensionList::const_iterator extension = extensions->begin(); diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h index 85d7e84..a9ba40d 100644 --- a/chrome/browser/debugger/devtools_window.h +++ b/chrome/browser/debugger/devtools_window.h @@ -24,7 +24,7 @@ class Browser; class BrowserWindow; class Profile; class RenderViewHost; -class TabContents; +class TabContentsWrapper; class Value; class DevToolsWindow @@ -48,7 +48,7 @@ class DevToolsWindow void SetDocked(bool docked); RenderViewHost* GetRenderViewHost(); - TabContents* tab_contents() { return tab_contents_; } + TabContentsWrapper* tab_contents() { return tab_contents_; } Browser* browser() { return browser_; } // For tests. bool is_docked() { return docked_; } @@ -98,7 +98,7 @@ class DevToolsWindow Profile* profile_; TabContents* inspected_tab_; - TabContents* tab_contents_; + TabContentsWrapper* tab_contents_; Browser* browser_; bool docked_; bool is_loaded_; diff --git a/chrome/browser/debugger/inspectable_tab_proxy.cc b/chrome/browser/debugger/inspectable_tab_proxy.cc index eb9e4bc..5dd734f 100644 --- a/chrome/browser/debugger/inspectable_tab_proxy.cc +++ b/chrome/browser/debugger/inspectable_tab_proxy.cc @@ -11,6 +11,7 @@ #include "chrome/browser/debugger/devtools_client_host.h" #include "chrome/browser/sessions/session_id.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/devtools_messages.h" diff --git a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc index 20da920..1ba3c5c 100644 --- a/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc +++ b/chrome/browser/dom_ui/html_dialog_tab_contents_delegate.cc @@ -6,6 +6,7 @@ #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/browser/ui/browser_navigator.h" @@ -57,9 +58,12 @@ void HtmlDialogTabContentsDelegate::AddNewContents( // Specify a NULL browser for navigation. This will cause Navigate() // to find a browser matching params.profile or create a new one. Browser* browser = NULL; - browser::NavigateParams params(browser, new_contents); + + TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); + browser::NavigateParams params(browser, wrapper); params.profile = profile_; - params.source_contents = source; + // TODO(pinkerton): no way to get a wrapper for this. + // params.source_contents = source; params.disposition = disposition; params.window_bounds = initial_pos; params.show_window = true; diff --git a/chrome/browser/extensions/execute_code_in_tab_function.cc b/chrome/browser/extensions/execute_code_in_tab_function.cc index 52bf74f..1659af3 100644 --- a/chrome/browser/extensions/execute_code_in_tab_function.cc +++ b/chrome/browser/extensions/execute_code_in_tab_function.cc @@ -13,6 +13,7 @@ #include "chrome/browser/extensions/file_reader.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" @@ -50,7 +51,7 @@ bool ExecuteCodeInTabFunction::RunImpl() { execute_tab_id_ = -1; Browser* browser = NULL; - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; // If |tab_id| is specified, look for it. Otherwise default to selected tab // in the current window. @@ -82,7 +83,7 @@ bool ExecuteCodeInTabFunction::RunImpl() { const std::vector<URLPattern> host_permissions = extension->host_permissions(); if (!Extension::CanExecuteScriptOnPage( - contents->GetURL(), + contents->tab_contents()->GetURL(), extension->CanExecuteScriptEverywhere(), &host_permissions, NULL, @@ -146,7 +147,7 @@ void ExecuteCodeInTabFunction::DidLoadFile(bool success, } bool ExecuteCodeInTabFunction::Execute(const std::string& code_string) { - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; Browser* browser = NULL; bool success = ExtensionTabUtil::GetTabById( @@ -171,8 +172,8 @@ bool ExecuteCodeInTabFunction::Execute(const std::string& code_string) { } else if (function_name != TabsExecuteScriptFunction::function_name()) { DCHECK(false); } - if (!contents->ExecuteCode(request_id(), extension->id(), - is_js_code, code_string, all_frames_)) { + if (!contents->tab_contents()->ExecuteCode(request_id(), extension->id(), + is_js_code, code_string, all_frames_)) { SendResponse(false); return false; } diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index ce0d673..b49c1a9 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -13,6 +13,8 @@ #include "chrome/browser/profile.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/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/extensions/extension_constants.h" @@ -137,7 +139,7 @@ void ExtensionBrowserEventRouter::Init(Profile* profile) { Browser* browser = *iter; if (browser->tabstrip_model()) { for (int i = 0; i < browser->tabstrip_model()->count(); ++i) { - TabContents* contents = browser->tabstrip_model()->GetTabContentsAt(i); + TabContents* contents = browser->GetTabContentsAt(i); int tab_id = ExtensionTabUtil::GetTabId(contents); tab_entries_[tab_id] = TabEntry(); } @@ -171,8 +173,7 @@ void ExtensionBrowserEventRouter::RegisterForBrowserNotifications( if (browser->tabstrip_model()) { for (int i = 0; i < browser->tabstrip_model()->count(); ++i) - RegisterForTabNotifications( - browser->tabstrip_model()->GetTabContentsAt(i)); + RegisterForTabNotifications(browser->GetTabContentsAt(i)); } } @@ -265,15 +266,15 @@ void ExtensionBrowserEventRouter::TabCreatedAt(TabContents* contents, RegisterForTabNotifications(contents); } -void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents, +void ExtensionBrowserEventRouter::TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground) { // If tab is new, send created event. - int tab_id = ExtensionTabUtil::GetTabId(contents); - if (!GetTabEntry(contents)) { + int tab_id = ExtensionTabUtil::GetTabId(contents->tab_contents()); + if (!GetTabEntry(contents->tab_contents())) { tab_entries_[tab_id] = TabEntry(); - TabCreatedAt(contents, index, foreground); + TabCreatedAt(contents->tab_contents(), index, foreground); return; } @@ -282,7 +283,7 @@ void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents, DictionaryValue* object_args = new DictionaryValue(); object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( - ExtensionTabUtil::GetWindowIdOfTab(contents))); + ExtensionTabUtil::GetWindowIdOfTab(contents->tab_contents()))); object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( index)); args.Append(object_args); @@ -293,19 +294,20 @@ void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents, DispatchEvent(contents->profile(), events::kOnTabAttached, json_args); } -void ExtensionBrowserEventRouter::TabDetachedAt(TabContents* contents, +void ExtensionBrowserEventRouter::TabDetachedAt(TabContentsWrapper* contents, int index) { - if (!GetTabEntry(contents)) { + if (!GetTabEntry(contents->tab_contents())) { // The tab was removed. Don't send detach event. return; } ListValue args; - args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); + args.Append(Value::CreateIntegerValue( + ExtensionTabUtil::GetTabId(contents->tab_contents()))); DictionaryValue* object_args = new DictionaryValue(); object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( - ExtensionTabUtil::GetWindowIdOfTab(contents))); + ExtensionTabUtil::GetWindowIdOfTab(contents->tab_contents()))); object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( index)); args.Append(object_args); @@ -317,9 +319,9 @@ void ExtensionBrowserEventRouter::TabDetachedAt(TabContents* contents, } void ExtensionBrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, - TabContents* contents, + TabContentsWrapper* contents, int index) { - int tab_id = ExtensionTabUtil::GetTabId(contents); + int tab_id = ExtensionTabUtil::GetTabId(contents->tab_contents()); ListValue args; args.Append(Value::CreateIntegerValue(tab_id)); @@ -337,20 +339,21 @@ void ExtensionBrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, int removed_count = tab_entries_.erase(tab_id); DCHECK_GT(removed_count, 0); - UnregisterForTabNotifications(contents); + UnregisterForTabNotifications(contents->tab_contents()); } -void ExtensionBrowserEventRouter::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, - int index, - bool user_gesture) { +void ExtensionBrowserEventRouter::TabSelectedAt( + TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, + int index, + bool user_gesture) { ListValue args; args.Append(Value::CreateIntegerValue( - ExtensionTabUtil::GetTabId(new_contents))); + ExtensionTabUtil::GetTabId(new_contents->tab_contents()))); DictionaryValue* object_args = new DictionaryValue(); object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( - ExtensionTabUtil::GetWindowIdOfTab(new_contents))); + ExtensionTabUtil::GetWindowIdOfTab(new_contents->tab_contents()))); args.Append(object_args); std::string json_args; @@ -360,15 +363,16 @@ void ExtensionBrowserEventRouter::TabSelectedAt(TabContents* old_contents, json_args); } -void ExtensionBrowserEventRouter::TabMoved(TabContents* contents, +void ExtensionBrowserEventRouter::TabMoved(TabContentsWrapper* contents, int from_index, int to_index) { ListValue args; - args.Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); + args.Append(Value::CreateIntegerValue( + ExtensionTabUtil::GetTabId(contents->tab_contents()))); DictionaryValue* object_args = new DictionaryValue(); object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( - ExtensionTabUtil::GetWindowIdOfTab(contents))); + ExtensionTabUtil::GetWindowIdOfTab(contents->tab_contents()))); object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( from_index)); object_args->Set(tab_keys::kToIndexKey, Value::CreateIntegerValue( @@ -456,29 +460,32 @@ void ExtensionBrowserEventRouter::Observe(NotificationType type, } } -void ExtensionBrowserEventRouter::TabChangedAt(TabContents* contents, +void ExtensionBrowserEventRouter::TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type) { - TabUpdated(contents, false); + TabUpdated(contents->tab_contents(), false); } -void ExtensionBrowserEventRouter::TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, - int index) { - UnregisterForTabNotifications(old_contents); - RegisterForTabNotifications(new_contents); +void ExtensionBrowserEventRouter::TabReplacedAt( + TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, + int index) { + UnregisterForTabNotifications(old_contents->tab_contents()); + RegisterForTabNotifications(new_contents->tab_contents()); } -void ExtensionBrowserEventRouter::TabPinnedStateChanged(TabContents* contents, - int index) { +void ExtensionBrowserEventRouter::TabPinnedStateChanged( + TabContentsWrapper* contents, + int index) { TabStripModel* tab_strip = NULL; int tab_index; - if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { + if (ExtensionTabUtil::GetTabStripModel( + contents->tab_contents(), &tab_strip, &tab_index)) { DictionaryValue* changed_properties = new DictionaryValue(); changed_properties->SetBoolean(tab_keys::kPinnedKey, tab_strip->IsTabPinned(tab_index)); - DispatchTabUpdatedEvent(contents, changed_properties); + DispatchTabUpdatedEvent(contents->tab_contents(), changed_properties); } } @@ -515,21 +522,21 @@ void ExtensionBrowserEventRouter::PageActionExecuted( int button) { DispatchOldPageActionEvent(profile, extension_id, page_action_id, tab_id, url, button); - TabContents* tab_contents = NULL; + TabContentsWrapper* tab_contents = NULL; if (!ExtensionTabUtil::GetTabById(tab_id, profile, profile->IsOffTheRecord(), NULL, NULL, &tab_contents, NULL)) { return; } DispatchEventWithTab(profile, extension_id, "pageAction.onClicked", - tab_contents); + tab_contents->tab_contents()); } void ExtensionBrowserEventRouter::BrowserActionExecuted( Profile* profile, const std::string& extension_id, Browser* browser) { - TabContents* tab_contents = NULL; + TabContentsWrapper* tab_contents = NULL; int tab_id = 0; if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) return; DispatchEventWithTab(profile, extension_id, "browserAction.onClicked", - tab_contents); + tab_contents->tab_contents()); } diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h index a84749d..e951290 100644 --- a/chrome/browser/extensions/extension_browser_event_router.h +++ b/chrome/browser/extensions/extension_browser_event_router.h @@ -59,22 +59,24 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver, void OnBrowserWindowReady(const Browser* browser); // TabStripModelObserver - virtual void TabInsertedAt(TabContents* contents, int index, bool foreground); + 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 TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabDetachedAt(TabContentsWrapper* contents, int index); + virtual void TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture); - virtual void TabMoved(TabContents* contents, int from_index, int to_index); - virtual void TabChangedAt(TabContents* contents, int index, + virtual void TabMoved(TabContentsWrapper* contents, int from_index, + int to_index); + virtual void TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type); - 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(); // Page Action execute event. diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 224c1f8..fa034fc 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -19,6 +19,7 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/site_instance.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/chrome_paths.h" @@ -794,7 +795,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_OptionsPage) { ASSERT_EQ(2, tab_strip->count()); EXPECT_EQ(extension->GetResourceURL("options.html"), - tab_strip->GetTabContentsAt(1)->GetURL()); + tab_strip->GetTabContentsAt(1)->tab_contents()->GetURL()); } // Test window.chrome.app.isInstalled . diff --git a/chrome/browser/extensions/extension_clipboard_api.cc b/chrome/browser/extensions/extension_clipboard_api.cc index af1deae..f80be6b 100644 --- a/chrome/browser/extensions/extension_clipboard_api.cc +++ b/chrome/browser/extensions/extension_clipboard_api.cc @@ -9,6 +9,7 @@ #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/extensions/extension_error_utils.h" namespace { @@ -20,7 +21,7 @@ bool ClipboardFunction::RunImpl() { int tab_id; EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL)) { error_ = ExtensionErrorUtils::FormatErrorMessage( diff --git a/chrome/browser/extensions/extension_cookies_helpers.cc b/chrome/browser/extensions/extension_cookies_helpers.cc index cef1d1e..a140c8e 100644 --- a/chrome/browser/extensions/extension_cookies_helpers.cc +++ b/chrome/browser/extensions/extension_cookies_helpers.cc @@ -12,6 +12,7 @@ #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/profile.h" #include "chrome/browser/tabs/tab_strip_model.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/url_constants.h" @@ -121,7 +122,8 @@ void AppendToTabIdList(Browser* browser, ListValue* tab_ids) { TabStripModel* tab_strip = browser->tabstrip_model(); for (int i = 0; i < tab_strip->count(); ++i) { tab_ids->Append(Value::CreateIntegerValue( - ExtensionTabUtil::GetTabId(tab_strip->GetTabContentsAt(i)))); + ExtensionTabUtil::GetTabId( + tab_strip->GetTabContentsAt(i)->tab_contents()))); } } diff --git a/chrome/browser/extensions/extension_devtools_bridge.cc b/chrome/browser/extensions/extension_devtools_bridge.cc index d1731ce..3a8f525 100644 --- a/chrome/browser/extensions/extension_devtools_bridge.cc +++ b/chrome/browser/extensions/extension_devtools_bridge.cc @@ -14,6 +14,7 @@ #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/devtools_messages.h" ExtensionDevToolsBridge::ExtensionDevToolsBridge(int tab_id, @@ -36,7 +37,7 @@ bool ExtensionDevToolsBridge::RegisterAsDevToolsClientHost() { Browser* browser; TabStripModel* tab_strip; - TabContents* contents; + TabContentsWrapper* contents; int tab_index; if (ExtensionTabUtil::GetTabById(tab_id_, profile_, true, &browser, &tab_strip, diff --git a/chrome/browser/extensions/extension_devtools_browsertests.cc b/chrome/browser/extensions/extension_devtools_browsertests.cc index 3bfd134e..cc61b3d 100644 --- a/chrome/browser/extensions/extension_devtools_browsertests.cc +++ b/chrome/browser/extensions/extension_devtools_browsertests.cc @@ -61,7 +61,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, FLAKY_TimelineApi) { DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); // Grab the tab_id of whatever tab happens to be first. - TabContents* tab_contents = browser()->tabstrip_model()->GetTabContentsAt(0); + TabContents* tab_contents = browser()->GetTabContentsAt(0); ASSERT_TRUE(tab_contents); int tab_id = ExtensionTabUtil::GetTabId(tab_contents); @@ -117,7 +117,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionDevToolsBrowserTest, ProcessRefCounting) { DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); // Grab the tab_id of whatever tab happens to be first. - TabContents* tab_contents = browser()->tabstrip_model()->GetTabContentsAt(0); + TabContents* tab_contents = browser()->GetTabContentsAt(0); ASSERT_TRUE(tab_contents); int tab_id = ExtensionTabUtil::GetTabId(tab_contents); diff --git a/chrome/browser/extensions/extension_infobar_module.cc b/chrome/browser/extensions/extension_infobar_module.cc index f86abd2..21d94ae 100644 --- a/chrome/browser/extensions/extension_infobar_module.cc +++ b/chrome/browser/extensions/extension_infobar_module.cc @@ -14,6 +14,7 @@ #include "chrome/browser/extensions/extension_tabs_module_constants.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_error_utils.h" @@ -36,7 +37,7 @@ bool ShowInfoBarFunction::RunImpl() { GURL url = extension->GetResourceURL(extension->url(), html_path); Browser* browser = NULL; - TabContents* tab_contents = NULL; + TabContentsWrapper* tab_contents = NULL; if (!ExtensionTabUtil::GetTabById( tab_id, profile(), @@ -51,8 +52,9 @@ bool ShowInfoBarFunction::RunImpl() { return false; } - tab_contents->AddInfoBar( - new ExtensionInfoBarDelegate(browser, tab_contents, GetExtension(), url)); + tab_contents->tab_contents()->AddInfoBar( + new ExtensionInfoBarDelegate(browser, tab_contents->tab_contents(), + GetExtension(), url)); // TODO(finnur): Return the actual DOMWindow object. Bug 26463. result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc index 01faa1d..67c6e71 100644 --- a/chrome/browser/extensions/extension_message_service.cc +++ b/chrome/browser/extensions/extension_message_service.cc @@ -16,6 +16,7 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" #include "chrome/common/render_messages.h" @@ -173,7 +174,7 @@ void ExtensionMessageService::OpenChannelToTab( if (!source) return; - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; MessagePort receiver; if (ExtensionTabUtil::GetTabById(tab_id, source->profile(), true, NULL, NULL, &contents, NULL)) { diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc index 84b20de..c9dc2a3 100644 --- a/chrome/browser/extensions/extension_page_actions_module.cc +++ b/chrome/browser/extensions/extension_page_actions_module.cc @@ -12,6 +12,7 @@ #include "chrome/browser/profile.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/ui/browser.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_action.h" @@ -67,7 +68,7 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) { } // Find the TabContents that contains this tab id. - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; bool result = ExtensionTabUtil::GetTabById( tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); if (!result || !contents) { @@ -87,7 +88,7 @@ bool PageActionFunction::SetPageActionEnabled(bool enable) { page_action->SetIsVisible(tab_id, enable); page_action->SetTitle(tab_id, title); page_action->SetIconIndex(tab_id, icon_id); - contents->PageActionStateChanged(); + contents->tab_contents()->PageActionStateChanged(); return true; } @@ -101,13 +102,15 @@ bool PageActionFunction::InitCommon(int tab_id) { // Find the TabContents that contains this tab id. contents_ = NULL; + TabContentsWrapper* wrapper = NULL; bool result = ExtensionTabUtil::GetTabById( - tab_id, profile(), include_incognito(), NULL, NULL, &contents_, NULL); - if (!result || !contents_) { + tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL); + if (!result || !wrapper) { error_ = ExtensionErrorUtils::FormatErrorMessage( kNoTabError, base::IntToString(tab_id)); return false; } + contents_ = wrapper->tab_contents(); return true; } diff --git a/chrome/browser/extensions/extension_processes_api.cc b/chrome/browser/extensions/extension_processes_api.cc index 2246965..99b72e8 100644 --- a/chrome/browser/extensions/extension_processes_api.cc +++ b/chrome/browser/extensions/extension_processes_api.cc @@ -19,6 +19,7 @@ #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/task_manager/task_manager.h" #include "chrome/common/extensions/extension_error_utils.h" #include "chrome/common/notification_service.h" @@ -160,7 +161,7 @@ bool GetProcessIdForTabFunction::RunImpl() { int tab_id; EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; int tab_index = -1; if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(), NULL, NULL, &contents, &tab_index)) { @@ -171,7 +172,8 @@ bool GetProcessIdForTabFunction::RunImpl() { } // Return the process ID of the tab as an integer. - int id = base::GetProcId(contents->GetRenderProcessHost()->GetHandle()); + int id = base::GetProcId(contents->tab_contents()-> + GetRenderProcessHost()->GetHandle()); result_.reset(Value::CreateIntegerValue(id)); return true; } diff --git a/chrome/browser/extensions/extension_sidebar_api.cc b/chrome/browser/extensions/extension_sidebar_api.cc index 7dbb6fd..5495a8e 100644 --- a/chrome/browser/extensions/extension_sidebar_api.cc +++ b/chrome/browser/extensions/extension_sidebar_api.cc @@ -16,6 +16,7 @@ #include "chrome/browser/sidebar/sidebar_container.h" #include "chrome/browser/sidebar/sidebar_manager.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_error_utils.h" @@ -122,7 +123,7 @@ bool SidebarFunction::RunImpl() { } int tab_id; - TabContents* tab_contents = NULL; + TabContentsWrapper* tab_contents = NULL; if (details->HasKey(kTabIdKey)) { EXTENSION_FUNCTION_VALIDATE(details->GetInteger(kTabIdKey, &tab_id)); if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(), @@ -146,7 +147,7 @@ bool SidebarFunction::RunImpl() { return false; std::string content_id(GetExtension()->id()); - return RunImpl(tab_contents, content_id, *details); + return RunImpl(tab_contents->tab_contents(), content_id, *details); } @@ -193,7 +194,7 @@ bool GetStateSidebarFunction::RunImpl(TabContents* tab, // Check if this tab is selected. Browser* browser = GetCurrentBrowser(); - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; int default_tab_id = -1; if (browser && ExtensionTabUtil::GetDefaultTab(browser, &contents, diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index 8deafb2..169cfff 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -23,6 +23,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents_view.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/browser/ui/browser_navigator.h" @@ -55,7 +56,7 @@ static bool GetTabById(int tab_id, Profile* profile, bool include_incognito, Browser** browser, TabStripModel** tab_strip, - TabContents** contents, + TabContentsWrapper** contents, int* tab_index, std::string* error_message); // Takes |url_string| and returns a GURL which is either valid and absolute @@ -104,7 +105,7 @@ ListValue* ExtensionTabUtil::CreateTabList(const Browser* browser) { TabStripModel* tab_strip = browser->tabstrip_model(); for (int i = 0; i < tab_strip->count(); ++i) { tab_list->Append(ExtensionTabUtil::CreateTabValue( - tab_strip->GetTabContentsAt(i), tab_strip, i)); + tab_strip->GetTabContentsAt(i)->tab_contents(), tab_strip, i)); } return tab_list; @@ -174,7 +175,7 @@ bool ExtensionTabUtil::GetTabStripModel(const TabContents* tab_contents, for (BrowserList::const_iterator it = BrowserList::begin(); it != BrowserList::end(); ++it) { TabStripModel* tab_strip = (*it)->tabstrip_model(); - int index = tab_strip->GetIndexOfTabContents(tab_contents); + int index = tab_strip->GetWrapperIndex(tab_contents); if (index != -1) { *tab_strip_model = tab_strip; *tab_index = index; @@ -185,16 +186,17 @@ bool ExtensionTabUtil::GetTabStripModel(const TabContents* tab_contents, return false; } -bool ExtensionTabUtil::GetDefaultTab(Browser* browser, TabContents** contents, +bool ExtensionTabUtil::GetDefaultTab(Browser* browser, + TabContentsWrapper** contents, int* tab_id) { DCHECK(browser); DCHECK(contents); DCHECK(tab_id); - *contents = browser->tabstrip_model()->GetSelectedTabContents(); + *contents = browser->GetSelectedTabContentsWrapper(); if (*contents) { if (tab_id) - *tab_id = ExtensionTabUtil::GetTabId(*contents); + *tab_id = ExtensionTabUtil::GetTabId((*contents)->tab_contents()); return true; } @@ -205,22 +207,20 @@ bool ExtensionTabUtil::GetTabById(int tab_id, Profile* profile, bool include_incognito, Browser** browser, TabStripModel** tab_strip, - TabContents** contents, + TabContentsWrapper** contents, int* tab_index) { - Browser* target_browser; - TabStripModel* target_tab_strip; - TabContents* target_contents; Profile* incognito_profile = include_incognito && profile->HasOffTheRecordProfile() ? profile->GetOffTheRecordProfile() : NULL; for (BrowserList::const_iterator iter = BrowserList::begin(); iter != BrowserList::end(); ++iter) { - target_browser = *iter; + Browser* target_browser = *iter; if (target_browser->profile() == profile || target_browser->profile() == incognito_profile) { - target_tab_strip = target_browser->tabstrip_model(); + TabStripModel* target_tab_strip = target_browser->tabstrip_model(); for (int i = 0; i < target_tab_strip->count(); ++i) { - target_contents = target_tab_strip->GetTabContentsAt(i); + TabContentsWrapper* target_contents = + target_tab_strip->GetTabContentsAt(i); if (target_contents->controller().session_id().id() == tab_id) { if (browser) *browser = target_browser; @@ -542,12 +542,13 @@ bool GetSelectedTabFunction::RunImpl() { return false; TabStripModel* tab_strip = browser->tabstrip_model(); - TabContents* contents = tab_strip->GetSelectedTabContents(); + TabContentsWrapper* contents = tab_strip->GetSelectedTabContents(); if (!contents) { error_ = keys::kNoSelectedTabError; return false; } - result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, + result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), + tab_strip, tab_strip->selected_index())); return true; } @@ -664,7 +665,7 @@ bool CreateTabFunction::RunImpl() { // Return data about the newly created tab. if (has_callback()) { result_.reset(ExtensionTabUtil::CreateTabValue( - params.target_contents, + params.target_contents->tab_contents(), params.browser->tabstrip_model(), params.browser->tabstrip_model()->GetIndexOfTabContents( params.target_contents))); @@ -678,13 +679,14 @@ bool GetTabFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); TabStripModel* tab_strip = NULL; - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; int tab_index = -1; if (!GetTabById(tab_id, profile(), include_incognito(), NULL, &tab_strip, &contents, &tab_index, &error_)) return false; - result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, + result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), + tab_strip, tab_index)); return true; } @@ -706,7 +708,7 @@ bool UpdateTabFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); TabStripModel* tab_strip = NULL; - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; int tab_index = -1; if (!GetTabById(tab_id, profile(), include_incognito(), NULL, &tab_strip, &contents, &tab_index, &error_)) @@ -738,7 +740,7 @@ bool UpdateTabFunction::RunImpl() { const std::vector<URLPattern> host_permissions = extension->host_permissions(); if (!Extension::CanExecuteScriptOnPage( - contents->GetURL(), + contents->tab_contents()->GetURL(), extension->CanExecuteScriptEverywhere(), &host_permissions, NULL, @@ -756,7 +758,7 @@ bool UpdateTabFunction::RunImpl() { // The URL of a tab contents never actually changes to a JavaScript URL, so // this check only makes sense in other cases. if (!url.SchemeIs(chrome::kJavaScriptScheme)) - DCHECK_EQ(url.spec(), contents->GetURL().spec()); + DCHECK_EQ(url.spec(), contents->tab_contents()->GetURL().spec()); } bool selected = false; @@ -771,7 +773,7 @@ bool UpdateTabFunction::RunImpl() { tab_strip->SelectTabContentsAt(tab_index, false); DCHECK_EQ(contents, tab_strip->GetSelectedTabContents()); } - contents->Focus(); + contents->tab_contents()->Focus(); } } @@ -786,7 +788,8 @@ bool UpdateTabFunction::RunImpl() { } if (has_callback()) - result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, + result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), + tab_strip, tab_index)); return true; @@ -805,7 +808,7 @@ bool MoveTabFunction::RunImpl() { Browser* source_browser = NULL; TabStripModel* source_tab_strip = NULL; - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; int tab_index = -1; if (!GetTabById(tab_id, profile(), include_incognito(), &source_browser, &source_tab_strip, &contents, @@ -852,7 +855,7 @@ bool MoveTabFunction::RunImpl() { TabStripModel::ADD_NONE); if (has_callback()) - result_.reset(ExtensionTabUtil::CreateTabValue(contents, + result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), target_tab_strip, new_index)); return true; @@ -869,7 +872,8 @@ bool MoveTabFunction::RunImpl() { source_tab_strip->MoveTabContentsAt(tab_index, new_index, false); if (has_callback()) - result_.reset(ExtensionTabUtil::CreateTabValue(contents, source_tab_strip, + result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(), + source_tab_strip, new_index)); return true; } @@ -880,7 +884,7 @@ bool RemoveTabFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); Browser* browser = NULL; - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; if (!GetTabById(tab_id, profile(), include_incognito(), &browser, NULL, &contents, NULL, &error_)) return false; @@ -1059,7 +1063,7 @@ void CaptureVisibleTabFunction::SendResultFromBitmap( bool DetectTabLanguageFunction::RunImpl() { int tab_id = 0; Browser* browser = NULL; - TabContents* contents = NULL; + TabContentsWrapper* contents = NULL; // If |tab_id| is specified, look for it. Otherwise default to selected tab // in the current window. @@ -1088,18 +1092,18 @@ bool DetectTabLanguageFunction::RunImpl() { AddRef(); // Balanced in GotLanguage() - if (!contents->language_state().original_language().empty()) { + if (!contents->tab_contents()->language_state().original_language().empty()) { // Delay the callback invocation until after the current JS call has // returned. MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( this, &DetectTabLanguageFunction::GotLanguage, - contents->language_state().original_language())); + contents->tab_contents()->language_state().original_language())); return true; } // The tab contents does not know its language yet. Let's wait until it // receives it, or until the tab is closed/navigates to some other page. registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, - Source<TabContents>(contents)); + Source<TabContents>(contents->tab_contents())); registrar_.Add(this, NotificationType::TAB_CLOSING, Source<NavigationController>(&(contents->controller()))); registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, @@ -1156,7 +1160,7 @@ static bool GetTabById(int tab_id, Profile* profile, bool include_incognito, Browser** browser, TabStripModel** tab_strip, - TabContents** contents, + TabContentsWrapper** contents, int* tab_index, std::string* error_message) { if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito, diff --git a/chrome/browser/extensions/extension_tabs_module.h b/chrome/browser/extensions/extension_tabs_module.h index 9bf36cb..4307c90 100644 --- a/chrome/browser/extensions/extension_tabs_module.h +++ b/chrome/browser/extensions/extension_tabs_module.h @@ -19,35 +19,35 @@ class DictionaryValue; class ListValue; class SkBitmap; class TabContents; +class TabContentsWrapper; class TabStripModel; -class ExtensionTabUtil { - public: - static int GetWindowId(const Browser* browser); - static int GetTabId(const TabContents* tab_contents); - static std::string GetTabStatusText(bool is_loading); - static int GetWindowIdOfTab(const TabContents* tab_contents); - static ListValue* CreateTabList(const Browser* browser); - static DictionaryValue* CreateTabValue(const TabContents* tab_contents); - static DictionaryValue* CreateTabValue(const TabContents* tab_contents, - TabStripModel* tab_strip, - int tab_index); - static DictionaryValue* CreateWindowValue(const Browser* browser, - bool populate_tabs); - // Gets the |tab_strip_model| and |tab_index| for the given |tab_contents|. - static bool GetTabStripModel(const TabContents* tab_contents, - TabStripModel** tab_strip_model, - int* tab_index); - static bool GetDefaultTab(Browser* browser, TabContents** contents, - int* tab_id); - // Any out parameter (|browser|, |tab_strip|, |contents|, & |tab_index|) may - // be NULL and will not be set within the function. - static bool GetTabById(int tab_id, Profile* profile, bool incognito_enabled, - Browser** browser, - TabStripModel** tab_strip, - TabContents** contents, - int* tab_index); -}; +namespace ExtensionTabUtil { +int GetWindowId(const Browser* browser); +int GetTabId(const TabContents* tab_contents); +std::string GetTabStatusText(bool is_loading); +int GetWindowIdOfTab(const TabContents* tab_contents); +ListValue* CreateTabList(const Browser* browser); +DictionaryValue* CreateTabValue(const TabContents* tab_contents); +DictionaryValue* CreateTabValue(const TabContents* tab_contents, + TabStripModel* tab_strip, + int tab_index); +DictionaryValue* CreateWindowValue(const Browser* browser, + bool populate_tabs); +// Gets the |tab_strip_model| and |tab_index| for the given |tab_contents|. +bool GetTabStripModel(const TabContents* tab_contents, + TabStripModel** tab_strip_model, + int* tab_index); +bool GetDefaultTab(Browser* browser, TabContentsWrapper** contents, + int* tab_id); +// Any out parameter (|browser|, |tab_strip|, |contents|, & |tab_index|) may +// be NULL and will not be set within the function. +bool GetTabById(int tab_id, Profile* profile, bool incognito_enabled, + Browser** browser, + TabStripModel** tab_strip, + TabContentsWrapper** contents, + int* tab_index); +} // Windows class GetWindowFunction : public SyncExtensionFunction { diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 20dd209..46f4c82 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -69,6 +69,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/tab_contents/tab_contents_view.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/themes/browser_theme_provider.h" @@ -737,7 +738,7 @@ void BrowserWindowGtk::ShelfVisibilityChanged() { void BrowserWindowGtk::UpdateDevTools() { UpdateDevToolsForContents( - browser_->tabstrip_model()->GetSelectedTabContents()); + browser_->GetSelectedTabContents()); } void BrowserWindowGtk::UpdateLoadingAnimations(bool should_animate) { @@ -837,9 +838,9 @@ void BrowserWindowGtk::UpdateReloadStopState(bool is_loading, bool force) { force); } -void BrowserWindowGtk::UpdateToolbar(TabContents* contents, +void BrowserWindowGtk::UpdateToolbar(TabContentsWrapper* contents, bool should_restore_state) { - toolbar_->UpdateTabContents(contents, should_restore_state); + toolbar_->UpdateTabContents(contents->tab_contents(), should_restore_state); } void BrowserWindowGtk::FocusToolbar() { @@ -1145,44 +1146,44 @@ void BrowserWindowGtk::Observe(NotificationType type, } } -void BrowserWindowGtk::TabDetachedAt(TabContents* contents, int index) { +void BrowserWindowGtk::TabDetachedAt(TabContentsWrapper* contents, int index) { // We use index here rather than comparing |contents| because by this time // the model has already removed |contents| from its list, so // browser_->GetSelectedTabContents() will return NULL or something else. if (index == browser_->tabstrip_model()->selected_index()) infobar_container_->ChangeTabContents(NULL); - contents_container_->DetachTabContents(contents); + contents_container_->DetachTabContents(contents->tab_contents()); UpdateDevToolsForContents(NULL); } -void BrowserWindowGtk::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, +void BrowserWindowGtk::TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture) { DCHECK(old_contents != new_contents); - if (old_contents && !old_contents->is_being_destroyed()) + if (old_contents && !old_contents->tab_contents()->is_being_destroyed()) old_contents->view()->StoreFocus(); // Update various elements that are interested in knowing the current // TabContents. - infobar_container_->ChangeTabContents(new_contents); - contents_container_->SetTabContents(new_contents); - UpdateDevToolsForContents(new_contents); + infobar_container_->ChangeTabContents(new_contents->tab_contents()); + contents_container_->SetTabContents(new_contents->tab_contents()); + UpdateDevToolsForContents(new_contents->tab_contents()); - new_contents->DidBecomeSelected(); + new_contents->tab_contents()->DidBecomeSelected(); // TODO(estade): after we manage browser activation, add a check to make sure // we are the active browser before calling RestoreFocus(). if (!browser_->tabstrip_model()->closing_all()) { new_contents->view()->RestoreFocus(); - if (new_contents->find_ui_active()) + if (new_contents->tab_contents()->find_ui_active()) browser_->GetFindBarController()->find_bar()->SetFocusAndSelection(); } // Update all the UI bits. UpdateTitleBar(); UpdateToolbar(new_contents, true); - UpdateUIForContents(new_contents); + UpdateUIForContents(new_contents->tab_contents()); } void BrowserWindowGtk::TabStripEmpty() { @@ -1861,7 +1862,7 @@ gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { // If a widget besides the native view is focused, we have to try to handle // the custom accelerators before letting it handle them. TabContents* current_tab_contents = - browser()->tabstrip_model()->GetSelectedTabContents(); + browser()->GetSelectedTabContents(); // The current tab might not have a render view if it crashed. if (!current_tab_contents || !current_tab_contents->GetContentNativeView() || !gtk_widget_is_focus(current_tab_contents->GetContentNativeView())) { diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index b1b8502..4e6041e 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -75,7 +75,7 @@ class BrowserWindowGtk : public BrowserWindow, virtual LocationBar* GetLocationBar() const; virtual void SetFocusToLocationBar(bool select_all); virtual void UpdateReloadStopState(bool is_loading, bool force); - virtual void UpdateToolbar(TabContents* contents, + virtual void UpdateToolbar(TabContentsWrapper* contents, bool should_restore_state); virtual void FocusToolbar(); virtual void FocusAppMenu(); @@ -135,9 +135,9 @@ class BrowserWindowGtk : public BrowserWindow, const NotificationDetails& details); // Overridden from TabStripModelObserver: - virtual void TabDetachedAt(TabContents* contents, int index); - virtual void TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabDetachedAt(TabContentsWrapper* contents, int index); + virtual void TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture); virtual void TabStripEmpty(); diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 65b9545..05fefc3e 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -536,7 +536,7 @@ void LocationBarViewGtk::OnChanged() { if (update_instant_ && instant && GetTabContents()) { if (location_entry_->model()->user_input_in_progress() && location_entry_->model()->popup_model()->IsOpen()) { - instant->Update(GetTabContents(), + instant->Update(browser_->GetSelectedTabContentsWrapper(), location_entry_->model()->CurrentMatch(), WideToUTF16(location_entry_->GetText()), &suggested_text); diff --git a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc index 8ae9fd5..00546c6 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc @@ -13,6 +13,7 @@ #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/platform_util.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/notification_service.h" @@ -90,7 +91,7 @@ bool DraggedTabControllerGtk::EndDrag(bool canceled) { TabGtk* DraggedTabControllerGtk::GetDragSourceTabForContents( TabContents* contents) const { if (attached_tabstrip_ == source_tabstrip_) - return contents == dragged_contents_ ? source_tab_ : NULL; + return contents == dragged_contents_->tab_contents() ? source_tab_ : NULL; return NULL; } @@ -195,7 +196,7 @@ void DraggedTabControllerGtk::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); - DCHECK(Source<TabContents>(source).ptr() == dragged_contents_); + DCHECK(Source<TabContentsWrapper>(source).ptr() == dragged_contents_); EndDragImpl(TAB_DESTROYED); } @@ -209,11 +210,12 @@ gfx::Point DraggedTabControllerGtk::GetWindowCreatePoint() const { cursor_point.y() - window_create_point_.y()); } -void DraggedTabControllerGtk::SetDraggedContents(TabContents* new_contents) { +void DraggedTabControllerGtk::SetDraggedContents( + TabContentsWrapper* new_contents) { if (dragged_contents_) { registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(dragged_contents_)); + Source<TabContentsWrapper>(dragged_contents_)); if (original_delegate_) dragged_contents_->set_delegate(original_delegate_); } @@ -222,7 +224,7 @@ void DraggedTabControllerGtk::SetDraggedContents(TabContents* new_contents) { if (dragged_contents_) { registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(dragged_contents_)); + Source<TabContentsWrapper>(dragged_contents_)); // We need to be the delegate so we receive messages about stuff, // otherwise our dragged_contents() may be replaced and subsequently @@ -380,7 +382,7 @@ void DraggedTabControllerGtk::Attach(TabStripGtk* attached_tabstrip, original_delegate_ = NULL; // Return the TabContents' to normalcy. - dragged_contents_->set_capturing_contents(false); + dragged_contents_->tab_contents()->set_capturing_contents(false); // We need to ask the tabstrip we're attached to ensure that the ideal // bounds for all its tabs are correctly generated, because the calculation @@ -685,10 +687,10 @@ bool DraggedTabControllerGtk::CompleteDrag() { void DraggedTabControllerGtk::EnsureDraggedTab() { if (!dragged_tab_.get()) { gfx::Rect rect; - dragged_contents_->GetContainerBounds(&rect); + dragged_contents_->tab_contents()->GetContainerBounds(&rect); - dragged_tab_.reset(new DraggedTabGtk(dragged_contents_, mouse_offset_, - rect.size(), mini_)); + dragged_tab_.reset(new DraggedTabGtk(dragged_contents_->tab_contents(), + mouse_offset_, rect.size(), mini_)); } } diff --git a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h index b8b8eb3..1802441 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h +++ b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h @@ -21,6 +21,7 @@ class DraggedTabGtk; class TabGtk; class TabStripGtk; +class TabContentsWrapper; class DraggedTabControllerGtk : public NotificationObserver, public TabContentsDelegate { @@ -105,7 +106,7 @@ class DraggedTabControllerGtk : public NotificationObserver, gfx::Point GetWindowCreatePoint() const; // Sets the TabContents being dragged with the specified |new_contents|. - void SetDraggedContents(TabContents* new_contents); + void SetDraggedContents(TabContentsWrapper* new_contents); // Move the DraggedTabView according to the current mouse screen position, // potentially updating the source and other TabStrips. @@ -199,7 +200,7 @@ class DraggedTabControllerGtk : public NotificationObserver, NotificationRegistrar registrar_; // The TabContents being dragged. - TabContents* dragged_contents_; + TabContentsWrapper* dragged_contents_; // The original TabContentsDelegate of |dragged_contents_|, before it was // detached from the browser window. We store this so that we can forward diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 41d1e27..0960cec 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -20,6 +20,7 @@ #include "chrome/browser/gtk/tabs/dragged_tab_controller_gtk.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_delegate.h" #include "chrome/browser/themes/browser_theme_provider.h" #include "chrome/browser/ui/browser.h" @@ -813,10 +814,10 @@ void TabStripGtk::UpdateLoadingAnimations() { --index; } else { TabRendererGtk::AnimationState state; - TabContents* contents = model_->GetTabContentsAt(index); - if (!contents || !contents->is_loading()) { + TabContentsWrapper* contents = model_->GetTabContentsAt(index); + if (!contents || !contents->tab_contents()->is_loading()) { state = TabGtk::ANIMATION_NONE; - } else if (contents->waiting_for_response()) { + } else if (contents->tab_contents()->waiting_for_response()) { state = TabGtk::ANIMATION_WAITING; } else { state = TabGtk::ANIMATION_LOADING; @@ -925,7 +926,7 @@ GtkWidget* TabStripGtk::GetWidgetForViewID(ViewID view_id) { //////////////////////////////////////////////////////////////////////////////// // TabStripGtk, TabStripModelObserver implementation: -void TabStripGtk::TabInsertedAt(TabContents* contents, +void TabStripGtk::TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground) { DCHECK(contents); @@ -940,7 +941,8 @@ void TabStripGtk::TabInsertedAt(TabContents* contents, // has the Tab already constructed and we can just insert it into our list // again. if (IsDragSessionActive()) { - tab = drag_controller_->GetDragSourceTabForContents(contents); + tab = drag_controller_->GetDragSourceTabForContents( + contents->tab_contents()); if (tab) { // If the Tab was detached, it would have been animated closed but not // removed, so we need to reset this property. @@ -964,7 +966,7 @@ void TabStripGtk::TabInsertedAt(TabContents* contents, if (!contains_tab) { TabData d = { tab, gfx::Rect() }; tab_data_.insert(tab_data_.begin() + index, d); - tab->UpdateData(contents, model_->IsAppTab(index), false); + tab->UpdateData(contents->tab_contents(), model_->IsAppTab(index), false); } tab->set_mini(model_->IsMiniTab(index)); tab->set_app(model_->IsAppTab(index)); @@ -985,17 +987,17 @@ void TabStripGtk::TabInsertedAt(TabContents* contents, } } -void TabStripGtk::TabDetachedAt(TabContents* contents, int index) { +void TabStripGtk::TabDetachedAt(TabContentsWrapper* contents, int index) { GenerateIdealBounds(); - StartRemoveTabAnimation(index, contents); + StartRemoveTabAnimation(index, contents->tab_contents()); // Have to do this _after_ calling StartRemoveTabAnimation, so that any // previous remove is completed fully and index is valid in sync with the // model index. GetTabAt(index)->set_closing(true); } -void TabStripGtk::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, +void TabStripGtk::TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture) { DCHECK(index >= 0 && index < static_cast<int>(GetTabCount())); @@ -1015,7 +1017,7 @@ void TabStripGtk::TabSelectedAt(TabContents* old_contents, } } -void TabStripGtk::TabMoved(TabContents* contents, +void TabStripGtk::TabMoved(TabContentsWrapper* contents, int from_index, int to_index) { gfx::Rect start_bounds = GetIdealBounds(from_index); @@ -1029,7 +1031,7 @@ void TabStripGtk::TabMoved(TabContents* contents, StartMoveTabAnimation(from_index, to_index); } -void TabStripGtk::TabChangedAt(TabContents* contents, int index, +void TabStripGtk::TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type) { // Index is in terms of the model. Need to make sure we adjust that index in // case we have an animation going. @@ -1040,19 +1042,19 @@ void TabStripGtk::TabChangedAt(TabContents* contents, int index, // We'll receive another notification of the change asynchronously. return; } - tab->UpdateData(contents, + tab->UpdateData(contents->tab_contents(), model_->IsAppTab(index), change_type == LOADING_ONLY); tab->UpdateFromModel(); } -void TabStripGtk::TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, +void TabStripGtk::TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index) { TabChangedAt(new_contents, index, ALL); } -void TabStripGtk::TabMiniStateChanged(TabContents* contents, int index) { +void TabStripGtk::TabMiniStateChanged(TabContentsWrapper* contents, int index) { // Don't do anything if we've already picked up the change from TabMoved. if (GetTabAt(index)->mini() == model_->IsMiniTab(index)) return; @@ -1068,7 +1070,8 @@ void TabStripGtk::TabMiniStateChanged(TabContents* contents, int index) { } } -void TabStripGtk::TabBlockedStateChanged(TabContents* contents, int index) { +void TabStripGtk::TabBlockedStateChanged(TabContentsWrapper* contents, + int index) { GetTabAt(index)->SetBlocked(model_->IsTabBlocked(index)); } diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h index bc03bcf..0095ebe5b 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.h +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h @@ -99,24 +99,24 @@ class TabStripGtk : public TabStripModelObserver, protected: // TabStripModelObserver implementation: - virtual void TabInsertedAt(TabContents* contents, + virtual void TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground); - virtual void TabDetachedAt(TabContents* contents, int index); - virtual void TabSelectedAt(TabContents* old_contents, - TabContents* contents, + virtual void TabDetachedAt(TabContentsWrapper* contents, int index); + virtual void TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* contents, int index, bool user_gesture); - virtual void TabMoved(TabContents* contents, + virtual void TabMoved(TabContentsWrapper* contents, int from_index, int to_index); - virtual void TabChangedAt(TabContents* contents, int index, + virtual void TabChangedAt(TabContentsWrapper* contents, int index, TabChangeType change_type); - virtual void TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index); - virtual void TabMiniStateChanged(TabContents* contents, int index); - virtual void TabBlockedStateChanged(TabContents* contents, + virtual void TabMiniStateChanged(TabContentsWrapper* contents, int index); + virtual void TabBlockedStateChanged(TabContentsWrapper* contents, int index); // TabGtk::TabDelegate implementation: diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index 449cf4e..2259618 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -16,6 +16,7 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/in_process_browser_test.h" @@ -68,7 +69,7 @@ class InstantTest : public InProcessBrowserTest { // Wait for instant to load and ensure it is in the state we expect. void SetupPreview() { - preview_ = browser()->instant()->GetPreviewContents(); + preview_ = browser()->instant()->GetPreviewContents()->tab_contents(); ASSERT_TRUE(preview_); ui_test_utils::WaitForNavigation(&preview_->controller()); diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 54c12dd..c6587fa 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -19,6 +19,7 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" @@ -155,8 +156,7 @@ void InstantController::Disable(Profile* profile) { UMA_HISTOGRAM_CUSTOM_COUNTS(name, delta.InMinutes(), 1, 60 * 24 * 10, 50); } - -void InstantController::Update(TabContents* tab_contents, +void InstantController::Update(TabContentsWrapper* tab_contents, const AutocompleteMatch& match, const string16& user_text, string16* suggested_text) { @@ -230,9 +230,9 @@ bool InstantController::IsCurrent() { void InstantController::CommitCurrentPreview(InstantCommitType type) { DCHECK(loader_manager_.get()); DCHECK(loader_manager_->current_loader()); - TabContents* tab = ReleasePreviewContents(type); + TabContentsWrapper* tab = ReleasePreviewContents(type); delegate_->CommitInstant(tab); - CompleteRelease(tab); + CompleteRelease(tab->tab_contents()); } void InstantController::SetCommitOnMouseUp() { @@ -251,13 +251,14 @@ void InstantController::OnAutocompleteLostFocus( return; RenderWidgetHostView* rwhv = - GetPreviewContents()->GetRenderWidgetHostView(); + GetPreviewContents()->tab_contents()->GetRenderWidgetHostView(); if (!view_gaining_focus || !rwhv) { DestroyPreviewContents(); return; } - gfx::NativeView tab_view = GetPreviewContents()->GetNativeView(); + gfx::NativeView tab_view = + GetPreviewContents()->tab_contents()->GetNativeView(); // Focus is going to the renderer. if (rwhv->GetNativeView() == view_gaining_focus || tab_view == view_gaining_focus) { @@ -299,12 +300,13 @@ void InstantController::OnAutocompleteLostFocus( DestroyPreviewContents(); } -TabContents* InstantController::ReleasePreviewContents(InstantCommitType type) { +TabContentsWrapper* InstantController::ReleasePreviewContents( + InstantCommitType type) { if (!loader_manager_.get()) return NULL; scoped_ptr<InstantLoader> loader(loader_manager_->ReleaseCurrentLoader()); - TabContents* tab = loader->ReleasePreviewContents(type); + TabContentsWrapper* tab = loader->ReleasePreviewContents(type); ClearBlacklist(); is_active_ = false; @@ -319,7 +321,7 @@ void InstantController::CompleteRelease(TabContents* tab) { tab->SetAllContentsBlocked(false); } -TabContents* InstantController::GetPreviewContents() { +TabContentsWrapper* InstantController::GetPreviewContents() { return loader_manager_.get() ? loader_manager_->current_loader()->preview_contents() : NULL; } diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 1d989cb..f4e464c 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -26,6 +26,7 @@ class InstantLoaderManager; class PrefService; class Profile; class TabContents; +class TabContentsWrapper; class TemplateURL; // InstantController maintains a TabContents that is intended to give a preview @@ -77,7 +78,7 @@ class InstantController : public InstantLoaderDelegate { // the url is empty and there is a preview TabContents it is destroyed. If url // is non-empty and the preview TabContents has not been created it is // created. - void Update(TabContents* tab_contents, + void Update(TabContentsWrapper* tab_contents, const AutocompleteMatch& match, const string16& user_text, string16* suggested_text); @@ -120,17 +121,17 @@ class InstantController : public InstantLoaderDelegate { // not notify the delegate. // WARNING: be sure and invoke CompleteRelease after adding the returned // TabContents to a tabstrip. - TabContents* ReleasePreviewContents(InstantCommitType type); + TabContentsWrapper* ReleasePreviewContents(InstantCommitType type); // Does cleanup after the preview contents has been added to the tabstrip. // Invoke this if you explicitly invoke ReleasePreviewContents. void CompleteRelease(TabContents* tab); // TabContents the match is being shown for. - TabContents* tab_contents() const { return tab_contents_; } + TabContentsWrapper* tab_contents() const { return tab_contents_; } // The preview TabContents; may be null. - TabContents* GetPreviewContents(); + TabContentsWrapper* GetPreviewContents(); // Returns true if the preview TabContents is active. In some situations this // may return false yet preview_contents() returns non-NULL. @@ -193,7 +194,7 @@ class InstantController : public InstantLoaderDelegate { InstantDelegate* delegate_; // The TabContents last passed to |Update|. - TabContents* tab_contents_; + TabContentsWrapper* tab_contents_; // Has notification been sent out that the preview TabContents is ready to be // shown? diff --git a/chrome/browser/instant/instant_delegate.h b/chrome/browser/instant/instant_delegate.h index 90f58a2..32d94e6 100644 --- a/chrome/browser/instant/instant_delegate.h +++ b/chrome/browser/instant/instant_delegate.h @@ -8,7 +8,7 @@ #include "base/string16.h" -class TabContents; +class TabContentsWrapper; namespace gfx { class Rect; @@ -24,7 +24,7 @@ class InstantDelegate { virtual void PrepareForInstant() = 0; // Invoked when the instant TabContents should be shown. - virtual void ShowInstant(TabContents* preview_contents) = 0; + virtual void ShowInstant(TabContentsWrapper* preview_contents) = 0; // Invoked when the instant TabContents should be hidden. virtual void HideInstant() = 0; @@ -32,7 +32,7 @@ class InstantDelegate { // Invoked when the user does something that should result in the preview // TabContents becoming the active TabContents. The delegate takes ownership // of the supplied TabContents. - virtual void CommitInstant(TabContents* preview_contents) = 0; + virtual void CommitInstant(TabContentsWrapper* preview_contents) = 0; // Invoked when the suggested text is to change to |text|. virtual void SetSuggestedText(const string16& text) = 0; diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index a74f26f..30c8ba6 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -26,6 +26,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" @@ -152,7 +153,7 @@ class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate { // Commits the currently buffered history. void CommitHistory() { - TabContents* tab = loader_->preview_contents(); + TabContents* tab = loader_->preview_contents()->tab_contents(); if (tab->profile()->IsOffTheRecord()) return; @@ -310,7 +311,7 @@ class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate { virtual void OnSetSuggestions(int32 page_id, const std::vector<std::string>& suggestions) { - TabContents* source = loader_->preview_contents(); + TabContentsWrapper* source = loader_->preview_contents(); if (!source->controller().GetActiveEntry() || page_id != source->controller().GetActiveEntry()->page_id()) return; @@ -324,7 +325,7 @@ class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate { } virtual void OnInstantSupportDetermined(int32 page_id, bool result) { - TabContents* source = loader_->preview_contents(); + TabContents* source = loader_->preview_contents()->tab_contents(); if (!source->controller().GetActiveEntry() || page_id != source->controller().GetActiveEntry()->page_id()) return; @@ -390,7 +391,7 @@ InstantLoader::~InstantLoader() { preview_contents_.reset(NULL); } -void InstantLoader::Update(TabContents* tab_contents, +void InstantLoader::Update(TabContentsWrapper* tab_contents, const TemplateURL* template_url, const GURL& url, PageTransition::Type transition_type, @@ -407,18 +408,19 @@ void InstantLoader::Update(TabContents* tab_contents, bool created_preview_contents; if (preview_contents_.get() == NULL) { - preview_contents_.reset( - new TabContents(tab_contents->profile(), NULL, MSG_ROUTING_NONE, - NULL, NULL)); - preview_contents_->SetAllContentsBlocked(true); + TabContents* new_contents = + new TabContents( + tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); + preview_contents_.reset(new TabContentsWrapper(new_contents)); + new_contents->SetAllContentsBlocked(true); // Propagate the max page id. That way if we end up merging the two // NavigationControllers (which happens if we commit) none of the page ids // will overlap. - int32 max_page_id = tab_contents->GetMaxPageID(); + int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID(); if (max_page_id != -1) preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); - preview_contents_->set_delegate(preview_tab_contents_delegate_.get()); + new_contents->set_delegate(preview_tab_contents_delegate_.get()); gfx::Rect tab_bounds; tab_contents->view()->GetContainerBounds(&tab_bounds); @@ -428,8 +430,8 @@ void InstantLoader::Update(TabContents* tab_contents, // If |preview_contents_| does not currently have a RWHV, we will call // SetTakesFocusOnlyOnMouseDown() as a result of the // RENDER_VIEW_HOST_CHANGED notification. - if (preview_contents_->GetRenderWidgetHostView()) { - preview_contents_->GetRenderWidgetHostView()-> + if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { + preview_contents_->tab_contents()->GetRenderWidgetHostView()-> SetTakesFocusOnlyOnMouseDown(true); } registrar_.Add( @@ -438,7 +440,7 @@ void InstantLoader::Update(TabContents* tab_contents, Source<NavigationController>(&preview_contents_->controller())); #endif - preview_contents_->ShowContents(); + preview_contents_->tab_contents()->ShowContents(); created_preview_contents = true; } else { created_preview_contents = false; @@ -484,7 +486,8 @@ void InstantLoader::Update(TabContents* tab_contents, preview_contents_->controller().LoadURL( instant_url, GURL(), transition_type); frame_load_observer_.reset( - new FrameLoadObserver(preview_contents(), user_text_)); + new FrameLoadObserver(preview_contents()->tab_contents(), + user_text_)); } } else { DCHECK(template_url_id_ == 0); @@ -515,7 +518,8 @@ bool InstantLoader::IsMouseDownFromActivate() { return preview_tab_contents_delegate_->is_mouse_down_from_activate(); } -TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type) { +TabContentsWrapper* InstantLoader::ReleasePreviewContents( + InstantCommitType type) { if (!preview_contents_.get()) return NULL; @@ -540,11 +544,11 @@ TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type) { preview_tab_contents_delegate_->CommitHistory(); // Destroy the paint observer. // RenderWidgetHostView may be null during shutdown. - if (preview_contents_->GetRenderWidgetHostView()) { - preview_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()-> - set_paint_observer(NULL); + if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { + preview_contents_->tab_contents()->GetRenderWidgetHostView()-> + GetRenderWidgetHost()->set_paint_observer(NULL); #if defined(OS_MACOSX) - preview_contents_->GetRenderWidgetHostView()-> + preview_contents_->tab_contents()->GetRenderWidgetHostView()-> SetTakesFocusOnlyOnMouseDown(false); registrar_.Remove( this, @@ -626,8 +630,8 @@ void InstantLoader::Observe(NotificationType type, const NotificationDetails& details) { #if defined(OS_MACOSX) if (type.value == NotificationType::RENDER_VIEW_HOST_CHANGED) { - if (preview_contents_->GetRenderWidgetHostView()) { - preview_contents_->GetRenderWidgetHostView()-> + if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { + preview_contents_->tab_contents()->GetRenderWidgetHostView()-> SetTakesFocusOnlyOnMouseDown(true); } return; diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index b2dfb66..223fffb 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -21,6 +21,7 @@ class InstantLoaderDelegate; class InstantLoaderManagerTest; class TabContents; +class TabContentsWrapper; class TemplateURL; // InstantLoader does the loading of a particular URL for InstantController. @@ -40,7 +41,7 @@ class InstantLoader : public NotificationObserver { // Invoked to load a URL. |tab_contents| is the TabContents the preview is // going to be shown on top of and potentially replace. - void Update(TabContents* tab_contents, + void Update(TabContentsWrapper* tab_contents, const TemplateURL* template_url, const GURL& url, PageTransition::Type transition_type, @@ -59,7 +60,7 @@ class InstantLoader : public NotificationObserver { // Releases the preview TabContents passing ownership to the caller. This is // intended to be called when the preview TabContents is committed. This does // not notify the delegate. - TabContents* ReleasePreviewContents(InstantCommitType type); + TabContentsWrapper* ReleasePreviewContents(InstantCommitType type); // Calls through to method of same name on delegate. bool ShouldCommitInstantOnMouseUp(); @@ -74,7 +75,9 @@ class InstantLoader : public NotificationObserver { const NotificationDetails& details); // The preview TabContents; may be null. - TabContents* preview_contents() const { return preview_contents_.get(); } + TabContentsWrapper* preview_contents() const { + return preview_contents_.get(); + } // Returns true if the preview TabContents is ready to be shown. bool ready() const { return ready_; } @@ -145,7 +148,7 @@ class InstantLoader : public NotificationObserver { scoped_ptr<TabContentsDelegateImpl> preview_tab_contents_delegate_; // The preview TabContents; may be null. - scoped_ptr<TabContents> preview_contents_; + scoped_ptr<TabContentsWrapper> preview_contents_; // Is the preview_contents ready to be shown? bool ready_; diff --git a/chrome/browser/instant/instant_loader_manager.cc b/chrome/browser/instant/instant_loader_manager.cc index 3020f2f..f2bdd9f 100644 --- a/chrome/browser/instant/instant_loader_manager.cc +++ b/chrome/browser/instant/instant_loader_manager.cc @@ -8,6 +8,7 @@ #include "chrome/browser/instant/instant_loader.h" #include "chrome/browser/instant/instant_loader_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" InstantLoaderManager::InstantLoaderManager( InstantLoaderDelegate* loader_delegate) @@ -67,7 +68,7 @@ InstantLoader* InstantLoaderManager::UpdateLoader( // preview_contents() may be null for tests. if (!current_loader_->template_url_id() && current_loader_->preview_contents()) { - current_loader_->preview_contents()->Stop(); + current_loader_->preview_contents()->tab_contents()->Stop(); } pending_loader_ = loader; } diff --git a/chrome/browser/login_prompt.cc b/chrome/browser/login_prompt.cc index f9fb0f7..69e0f20 100644 --- a/chrome/browser/login_prompt.cc +++ b/chrome/browser/login_prompt.cc @@ -18,6 +18,7 @@ #include "chrome/browser/tab_contents/constrained_window.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "grit/generated_resources.h" @@ -372,8 +373,12 @@ class LoginDialogTask : public Task { } // Tell the password manager to look for saved passwords. - PasswordManager* password_manager = - parent_contents->GetPasswordManager(); + TabContentsWrapper** wrapper = + TabContentsWrapper::property_accessor()->GetProperty( + parent_contents->property_bag()); + if (!wrapper) + return; + PasswordManager* password_manager = (*wrapper)->GetPasswordManager(); std::vector<PasswordForm> v; MakeInputForPasswordManager(&v); password_manager->PasswordFormsFound(v); diff --git a/chrome/browser/login_prompt.h b/chrome/browser/login_prompt.h index 31bf9264..e5a8928 100644 --- a/chrome/browser/login_prompt.h +++ b/chrome/browser/login_prompt.h @@ -21,7 +21,6 @@ class AuthChallengeInfo; class ConstrainedWindow; class GURL; -class TabContents; class URLRequest; // This is the base implementation for the OS-specific classes that route diff --git a/chrome/browser/password_manager/password_manager.cc b/chrome/browser/password_manager/password_manager.cc index 9933f8f..3e7e5fd 100644 --- a/chrome/browser/password_manager/password_manager.cc +++ b/chrome/browser/password_manager/password_manager.cc @@ -17,6 +17,7 @@ #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" +#include "chrome/common/render_messages_params.h" #include "grit/generated_resources.h" using webkit_glue::PasswordForm; diff --git a/chrome/browser/password_manager/password_manager.h b/chrome/browser/password_manager/password_manager.h index 017f5aa..79ea5c9 100644 --- a/chrome/browser/password_manager/password_manager.h +++ b/chrome/browser/password_manager/password_manager.h @@ -11,10 +11,12 @@ #include "chrome/browser/login_model.h" #include "chrome/browser/password_manager/password_form_manager.h" #include "chrome/browser/prefs/pref_member.h" +#include "chrome/browser/tab_contents/web_navigation_observer.h" #include "webkit/glue/password_form.h" #include "webkit/glue/password_form_dom_manager.h" class PasswordManagerDelegate; +class PasswordManagerTest; class PasswordFormManager; class PrefService; @@ -22,13 +24,14 @@ class PrefService; // receiving password form data from the renderer and managing the password // database through the WebDataService. The PasswordManager is a LoginModel // for purposes of supporting HTTP authentication dialogs. -class PasswordManager : public LoginModel { +class PasswordManager : public LoginModel, + public WebNavigationObserver { public: static void RegisterUserPrefs(PrefService* prefs); // The delegate passed in is required to outlive the PasswordManager. explicit PasswordManager(PasswordManagerDelegate* delegate); - ~PasswordManager(); + virtual ~PasswordManager(); // Called by a PasswordFormManager when it decides a form can be autofilled // on the page. @@ -37,34 +40,24 @@ class PasswordManager : public LoginModel { const webkit_glue::PasswordForm* const preferred_match, bool wait_for_username) const; - // Notification that the user navigated away from the current page. - // Unless this is a password form submission, for our purposes this - // means we're done with the current page, so we can clean-up. - void DidNavigate(); - - // Show a prompt to save submitted password if it is a new username for - // the form, or else just update the stored value. - void DidStopLoading(); - - // Notifies the password manager that password forms were parsed on the page. - void PasswordFormsFound(const std::vector<webkit_glue::PasswordForm>& forms); - - // Notifies the password manager which password forms are initially visible. - void PasswordFormsVisible( - const std::vector<webkit_glue::PasswordForm>& visible_forms); + // LoginModel implementation. + virtual void SetObserver(LoginModelObserver* observer); // When a form is submitted, we prepare to save the password but wait // until we decide the user has successfully logged in. This is step 1 // of 2 (see SavePassword). void ProvisionallySavePassword(webkit_glue::PasswordForm form); - // Clear any pending saves - void ClearProvisionalSave(); - - // LoginModel implementation. - virtual void SetObserver(LoginModelObserver* observer); + // WebNavigationObserver overrides. + virtual void DidStopLoading(); + virtual void PasswordFormsFound( + const std::vector<webkit_glue::PasswordForm>& forms); + virtual void PasswordFormsVisible( + const std::vector<webkit_glue::PasswordForm>& visible_forms); private: + FRIEND_TEST_ALL_PREFIXES(PasswordManagerTest, FormSeenThenLeftPage); + // Note about how a PasswordFormManager can transition from // pending_login_managers_ to provisional_save_manager_ and the infobar. // @@ -78,6 +71,15 @@ class PasswordManager : public LoginModel { // // When a form is "seen" on a page, a PasswordFormManager is created // and stored in this collection until user navigates away from page. + + // Clear any pending saves + void ClearProvisionalSave(); + + // Notification that the user navigated away from the current page. + // Unless this is a password form submission, for our purposes this + // means we're done with the current page, so we can clean-up. + void DidNavigate(); + typedef std::vector<PasswordFormManager*> LoginManagers; LoginManagers pending_login_managers_; diff --git a/chrome/browser/password_manager_delegate_impl.cc b/chrome/browser/password_manager_delegate_impl.cc new file mode 100644 index 0000000..466ee34 --- /dev/null +++ b/chrome/browser/password_manager_delegate_impl.cc @@ -0,0 +1,120 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/password_manager_delegate_impl.h" + +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "base/metrics/histogram.h" +#include "base/singleton.h" +#include "chrome/browser/password_manager/password_form_manager.h" +#include "chrome/browser/password_manager/password_manager.h" +#include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "grit/theme_resources.h" +#include "webkit/glue/password_form.h" + +// After a successful *new* login attempt, we take the PasswordFormManager in +// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while +// the user makes up their mind with the "save password" infobar. Note if the +// login is one we already know about, the end of the line is +// provisional_save_manager_ because we just update it on success and so such +// forms never end up in an infobar. +class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + SavePasswordInfoBarDelegate(TabContents* tab_contents, + PasswordFormManager* form_to_save) + : ConfirmInfoBarDelegate(tab_contents), + form_to_save_(form_to_save), + infobar_response_(NO_RESPONSE) {} + + virtual ~SavePasswordInfoBarDelegate() {} + + // Begin ConfirmInfoBarDelegate implementation. + virtual void InfoBarClosed() { + UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", + infobar_response_, NUM_RESPONSE_TYPES); + delete this; + } + + virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; } + + virtual string16 GetMessageText() const { + return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); + } + + virtual SkBitmap* GetIcon() const { + return ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_INFOBAR_SAVE_PASSWORD); + } + + virtual int GetButtons() const { + return BUTTON_OK | BUTTON_CANCEL; + } + + virtual string16 GetButtonLabel(InfoBarButton button) const { + if (button == BUTTON_OK) + return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON); + if (button == BUTTON_CANCEL) + return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); + NOTREACHED(); + return string16(); + } + + virtual bool Accept() { + DCHECK(form_to_save_.get()); + form_to_save_->Save(); + infobar_response_ = REMEMBER_PASSWORD; + return true; + } + + virtual bool Cancel() { + DCHECK(form_to_save_.get()); + form_to_save_->PermanentlyBlacklist(); + infobar_response_ = DONT_REMEMBER_PASSWORD; + return true; + } + // End ConfirmInfoBarDelegate implementation. + + private: + // The PasswordFormManager managing the form we're asking the user about, + // and should update as per her decision. + scoped_ptr<PasswordFormManager> form_to_save_; + + // Used to track the results we get from the info bar. + enum ResponseType { + NO_RESPONSE = 0, + REMEMBER_PASSWORD, + DONT_REMEMBER_PASSWORD, + NUM_RESPONSE_TYPES, + }; + ResponseType infobar_response_; + + DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); +}; + +//---------------------------------------------------------------------------- + +void PasswordManagerDelegateImpl::FillPasswordForm( + const webkit_glue::PasswordFormFillData& form_data) { + tab_contents_->render_view_host()->FillPasswordForm(form_data); +} + +void PasswordManagerDelegateImpl::AddSavePasswordInfoBar( + PasswordFormManager* form_to_save) { + tab_contents_->AddInfoBar( + new SavePasswordInfoBarDelegate(tab_contents_, form_to_save)); +} + +Profile* PasswordManagerDelegateImpl::GetProfileForPasswordManager() { + return tab_contents_->profile(); +} + +bool PasswordManagerDelegateImpl::DidLastPageLoadEncounterSSLErrors() { + return tab_contents_->controller().ssl_manager()-> + ProcessedSSLErrorFromRequest(); +} diff --git a/chrome/browser/password_manager_delegate_impl.h b/chrome/browser/password_manager_delegate_impl.h new file mode 100644 index 0000000..d7a0650 --- /dev/null +++ b/chrome/browser/password_manager_delegate_impl.h @@ -0,0 +1,29 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PASSWORD_MANAGER_DELEGATE_IMPL_H_ +#define CHROME_BROWSER_PASSWORD_MANAGER_DELEGATE_IMPL_H_ + +#include "base/basictypes.h" +#include "chrome/browser/password_manager/password_manager_delegate.h" + +class TabContents; + +class PasswordManagerDelegateImpl : public PasswordManagerDelegate { + public: + explicit PasswordManagerDelegateImpl(TabContents* contents) + : tab_contents_(contents) { } + + // PasswordManagerDelegate implementation. + virtual void FillPasswordForm( + const webkit_glue::PasswordFormFillData& form_data); + virtual void AddSavePasswordInfoBar(PasswordFormManager* form_to_save); + virtual Profile* GetProfileForPasswordManager(); + virtual bool DidLastPageLoadEncounterSSLErrors(); + private: + TabContents* tab_contents_; + DISALLOW_COPY_AND_ASSIGN(PasswordManagerDelegateImpl); +}; + +#endif // CHROME_BROWSER_PASSWORD_MANAGER_DELEGATE_IMPL_H_ diff --git a/chrome/browser/printing/print_preview_tab_controller.cc b/chrome/browser/printing/print_preview_tab_controller.cc index 0396583..69a5763 100644 --- a/chrome/browser/printing/print_preview_tab_controller.cc +++ b/chrome/browser/printing/print_preview_tab_controller.cc @@ -6,6 +6,7 @@ #include "chrome/browser/browser_process.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/browser/ui/browser_list.h" @@ -97,19 +98,19 @@ TabContents* PrintPreviewTabController::CreatePrintPreviewTab( PageTransition::LINK); params.disposition = NEW_FOREGROUND_TAB; params.tabstrip_index = current_browser->tabstrip_model()-> - GetIndexOfTabContents(initiator_tab) + 1; + GetWrapperIndex(initiator_tab) + 1; browser::Navigate(¶ms); - TabContents* preview_tab = params.target_contents; - preview_tab->Activate(); + TabContentsWrapper* preview_tab = params.target_contents; + preview_tab->tab_contents()->Activate(); // Add an entry to the map. - preview_tab_map_[preview_tab] = initiator_tab; + preview_tab_map_[preview_tab->tab_contents()] = initiator_tab; waiting_for_new_preview_page_ = true; AddObservers(initiator_tab); - AddObservers(preview_tab); + AddObservers(preview_tab->tab_contents()); - return preview_tab; + return preview_tab->tab_contents(); } void PrintPreviewTabController::Observe(NotificationType type, diff --git a/chrome/browser/printing/print_preview_tab_controller_unittest.cc b/chrome/browser/printing/print_preview_tab_controller_unittest.cc index 40b630a..736b34d 100644 --- a/chrome/browser/printing/print_preview_tab_controller_unittest.cc +++ b/chrome/browser/printing/print_preview_tab_controller_unittest.cc @@ -95,8 +95,8 @@ TEST_F(PrintPreviewTabControllerTest, MultiplePreviewTabs) { TabStripModel* model = browser()->tabstrip_model(); ASSERT_TRUE(model); - int preview_tab_1_index = model->GetIndexOfTabContents(preview_tab_1); - int preview_tab_2_index = model->GetIndexOfTabContents(preview_tab_2); + int preview_tab_1_index = model->GetWrapperIndex(preview_tab_1); + int preview_tab_2_index = model->GetWrapperIndex(preview_tab_2); EXPECT_NE(-1, preview_tab_1_index); EXPECT_NE(-1, preview_tab_2_index); diff --git a/chrome/browser/ssl/ssl_browser_tests.cc b/chrome/browser/ssl/ssl_browser_tests.cc index fcaaaed..424413f 100644 --- a/chrome/browser/ssl/ssl_browser_tests.cc +++ b/chrome/browser/ssl/ssl_browser_tests.cc @@ -9,6 +9,7 @@ #include "chrome/browser/tab_contents/interstitial_page.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/ui/browser.h" #include "chrome/browser/ui/browser_navigator.h" @@ -396,7 +397,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSErrorWithNoNavEntry) { ASSERT_TRUE(https_server_expired_.Start()); GURL url = https_server_expired_.GetURL("files/ssl/google.htm"); - TabContents* tab2 = + TabContentsWrapper* tab2 = browser()->AddSelectedTabWithURL(url, PageTransition::TYPED); ui_test_utils::WaitForLoadStop(&(tab2->controller())); @@ -404,7 +405,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSErrorWithNoNavEntry) { EXPECT_FALSE(browser()->command_updater()->IsCommandEnabled(IDC_BACK)); // We should have an interstitial page showing. - ASSERT_TRUE(tab2->interstitial_page()); + ASSERT_TRUE(tab2->tab_contents()->interstitial_page()); } // @@ -526,10 +527,10 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentTwoTabs) { ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("files/ssl/blank_page.html")); - TabContents* tab1 = browser()->GetSelectedTabContents(); + TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); // This tab should be fine. - CheckAuthenticatedState(tab1, false); + CheckAuthenticatedState(tab1->tab_contents(), false); // Create a new tab. std::string replacement_path; @@ -544,14 +545,14 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentTwoTabs) { params.tabstrip_index = 0; params.source_contents = tab1; browser::Navigate(¶ms); - TabContents* tab2 = params.target_contents; + TabContentsWrapper* tab2 = params.target_contents; ui_test_utils::WaitForNavigation(&(tab2->controller())); // The new tab has insecure content. - CheckAuthenticatedState(tab2, true); + CheckAuthenticatedState(tab2->tab_contents(), true); // The original tab should not be contaminated. - CheckAuthenticatedState(tab1, false); + CheckAuthenticatedState(tab1->tab_contents(), false); } // Visits two pages from the same origin: one that runs insecure content and one @@ -564,10 +565,10 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecureContentTwoTabs) { ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("files/ssl/blank_page.html")); - TabContents* tab1 = browser()->GetSelectedTabContents(); + TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); // This tab should be fine. - CheckAuthenticatedState(tab1, false); + CheckAuthenticatedState(tab1->tab_contents(), false); std::string replacement_path; ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( @@ -581,15 +582,15 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecureContentTwoTabs) { params.disposition = NEW_FOREGROUND_TAB; params.source_contents = tab1; browser::Navigate(¶ms); - TabContents* tab2 = params.target_contents; + TabContentsWrapper* tab2 = params.target_contents; ui_test_utils::WaitForNavigation(&(tab2->controller())); // The new tab has insecure content. - CheckAuthenticationBrokenState(tab2, 0, true, false); + CheckAuthenticationBrokenState(tab2->tab_contents(), 0, true, false); // Which means the origin for the first tab has also been contaminated with // insecure content. - CheckAuthenticationBrokenState(tab1, 0, true, false); + CheckAuthenticationBrokenState(tab1->tab_contents(), 0, true, false); } // Visits a page with an image over http. Visits another page over https @@ -743,7 +744,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) { // Let's add another tab to make sure the browser does not exit when we close // the first tab. GURL url = test_server()->GetURL("files/ssl/google.html"); - TabContents* tab2 = + TabContentsWrapper* tab2 = browser()->AddSelectedTabWithURL(url, PageTransition::TYPED); ui_test_utils::WaitForNavigation(&(tab2->controller())); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 26b77ce..5f091ee 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -55,7 +55,6 @@ #include "chrome/browser/metrics/metric_event_duration_details.h" #include "chrome/browser/modal_html_dialog_delegate.h" #include "chrome/browser/omnibox_search_hint.h" -#include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/plugin_installer.h" #include "chrome/browser/prefs/pref_service.h" @@ -82,6 +81,7 @@ #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" +#include "chrome/browser/tab_contents/web_navigation_observer.h" #include "chrome/browser/translate/page_translated_details.h" #include "chrome/common/bindings_policy.h" #include "chrome/common/chrome_switches.h" @@ -330,7 +330,6 @@ TabContents::TabContents(Profile* profile, save_package_(), autocomplete_history_manager_(), autofill_manager_(), - password_manager_(), plugin_installer_(), bookmark_drag_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)), @@ -566,12 +565,6 @@ AutoFillManager* TabContents::GetAutoFillManager() { return autofill_manager_.get(); } -PasswordManager* TabContents::GetPasswordManager() { - if (password_manager_.get() == NULL) - password_manager_.reset(new PasswordManager(this)); - return password_manager_.get(); -} - PluginInstaller* TabContents::GetPluginInstaller() { if (plugin_installer_.get() == NULL) plugin_installer_.reset(new PluginInstaller(this)); @@ -767,6 +760,14 @@ std::wstring TabContents::GetStatusText() const { return std::wstring(); } +void TabContents::AddNavigationObserver(WebNavigationObserver* observer) { + web_navigation_observers_.AddObserver(observer); +} + +void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) { + web_navigation_observers_.RemoveObserver(observer); +} + void TabContents::SetIsCrashed(bool state) { if (state == is_crashed_) return; @@ -899,10 +900,9 @@ bool TabContents::NavigateToEntry( return false; } - // Clear any provisional password saves - this stops password infobars - // showing up on pages the user navigates to while the right page is - // loading. - GetPasswordManager()->ClearProvisionalSave(); + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + NavigateToPendingEntry()); if (reload_type != NavigationController::NO_RELOAD && !profile()->IsOffTheRecord()) { @@ -1642,13 +1642,6 @@ void TabContents::DidNavigateMainFramePostCommit( // clear the bubble when a user navigates to a named anchor in the same // page. UpdateTargetURL(details.entry->page_id(), GURL()); - - // UpdateHelpersForDidNavigate will handle the case where the password_form - // origin is valid. - // TODO(brettw) bug 1343111: Password manager stuff in here needs to be - // cleaned up and covered by tests. - if (!params.password_form.origin.is_valid()) - GetPasswordManager()->DidNavigate(); } // The keyword generator uses the navigation entries, so must be called after @@ -1710,6 +1703,10 @@ void TabContents::DidNavigateMainFramePostCommit( // Update the starred state. UpdateStarredStateForCurrentURL(); + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + DidNavigateMainFramePostCommit(details, params)); + // Clear the cache of forms in AutoFill. if (autofill_manager_.get()) autofill_manager_->Reset(); @@ -1724,11 +1721,9 @@ void TabContents::DidNavigateAnyFramePostCommit( // reload the page to stop blocking. suppress_javascript_messages_ = false; - // Notify the password manager of the navigation or form submit. - // TODO(brettw) bug 1343111: Password manager stuff in here needs to be - // cleaned up and covered by tests. - if (params.password_form.origin.is_valid()) - GetPasswordManager()->ProvisionallySavePassword(params.password_form); + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + DidNavigateAnyFramePostCommit(details, params)); // Let the LanguageState clear its state. language_state_.DidNavigate(details); @@ -2640,10 +2635,15 @@ void TabContents::RequestMove(const gfx::Rect& new_bounds) { void TabContents::DidStartLoading() { SetIsLoading(true, NULL); + if (content_restrictions_) { content_restrictions_= 0; delegate()->ContentRestrictionsChanged(this); } + + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + DidStartLoading()); } void TabContents::DidStopLoading() { @@ -2663,11 +2663,11 @@ void TabContents::DidStopLoading() { controller_.GetCurrentEntryIndex())); } - // Tell PasswordManager we've finished a page load, which serves as a - // green light to save pending passwords and reset itself. - GetPasswordManager()->DidStopLoading(); - SetIsLoading(false, details.get()); + + // Notify observers about navigation. + FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_, + DidStopLoading()); } void TabContents::DocumentOnLoadCompletedInMainFrame( @@ -2789,16 +2789,6 @@ void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height, } } -void TabContents::PasswordFormsFound( - const std::vector<webkit_glue::PasswordForm>& forms) { - GetPasswordManager()->PasswordFormsFound(forms); -} - -void TabContents::PasswordFormsVisible( - const std::vector<webkit_glue::PasswordForm>& visible_forms) { - GetPasswordManager()->PasswordFormsVisible(visible_forms); -} - // Checks to see if we should generate a keyword based on the OSDD, and if // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. void TabContents::PageHasOSDD( @@ -3233,99 +3223,3 @@ void TabContents::SetAppIcon(const SkBitmap& app_icon) { app_icon_ = app_icon; NotifyNavigationStateChanged(INVALIDATE_TITLE); } - -// After a successful *new* login attempt, we take the PasswordFormManager in -// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while -// the user makes up their mind with the "save password" infobar. Note if the -// login is one we already know about, the end of the line is -// provisional_save_manager_ because we just update it on success and so such -// forms never end up in an infobar. -class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { - public: - SavePasswordInfoBarDelegate(TabContents* tab_contents, - PasswordFormManager* form_to_save) - : ConfirmInfoBarDelegate(tab_contents), - form_to_save_(form_to_save), - infobar_response_(NO_RESPONSE) {} - - virtual ~SavePasswordInfoBarDelegate() {} - - // Begin ConfirmInfoBarDelegate implementation. - virtual void InfoBarClosed() { - UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", - infobar_response_, NUM_RESPONSE_TYPES); - delete this; - } - - virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; } - - virtual string16 GetMessageText() const { - return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); - } - - virtual SkBitmap* GetIcon() const { - return ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_INFOBAR_SAVE_PASSWORD); - } - - virtual int GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; - } - - virtual string16 GetButtonLabel(InfoBarButton button) const { - if (button == BUTTON_OK) - return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON); - if (button == BUTTON_CANCEL) - return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); - NOTREACHED(); - return string16(); - } - - virtual bool Accept() { - DCHECK(form_to_save_.get()); - form_to_save_->Save(); - infobar_response_ = REMEMBER_PASSWORD; - return true; - } - - virtual bool Cancel() { - DCHECK(form_to_save_.get()); - form_to_save_->PermanentlyBlacklist(); - infobar_response_ = DONT_REMEMBER_PASSWORD; - return true; - } - // End ConfirmInfoBarDelegate implementation. - - private: - // The PasswordFormManager managing the form we're asking the user about, - // and should update as per her decision. - scoped_ptr<PasswordFormManager> form_to_save_; - - // Used to track the results we get from the info bar. - enum ResponseType { - NO_RESPONSE = 0, - REMEMBER_PASSWORD, - DONT_REMEMBER_PASSWORD, - NUM_RESPONSE_TYPES, - }; - ResponseType infobar_response_; - - DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); -}; - -void TabContents::FillPasswordForm( - const webkit_glue::PasswordFormFillData& form_data) { - render_view_host()->FillPasswordForm(form_data); -} - -void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) { - AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save)); -} - -Profile* TabContents::GetProfileForPasswordManager() { - return profile(); -} - -bool TabContents::DidLastPageLoadEncounterSSLErrors() { - return controller().ssl_manager()->ProcessedSSLErrorFromRequest(); -} diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index f8bad82..2a69a14 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -25,7 +25,6 @@ #include "chrome/browser/find_notification_details.h" #include "chrome/browser/js_modal_dialog.h" #include "chrome/browser/prefs/pref_change_registrar.h" -#include "chrome/browser/password_manager/password_manager_delegate.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/tab_contents/constrained_window.h" #include "chrome/browser/tab_contents/language_state.h" @@ -72,7 +71,6 @@ class FileSelectHelper; class InfoBarDelegate; class LoadNotificationDetails; class OmniboxSearchHint; -class PasswordManager; class PluginInstaller; class Profile; struct RendererPreferences; @@ -88,6 +86,7 @@ class URLPattern; struct ThumbnailScore; struct ViewHostMsg_DomMessage_Params; struct ViewHostMsg_FrameNavigate_Params; +class WebNavigationObserver; struct WebPreferences; // Describes what goes in the main content area of a tab. TabContents is @@ -100,7 +99,6 @@ class TabContents : public PageNavigator, public RenderViewHostManager::Delegate, public JavaScriptAppModalDialogDelegate, public ImageLoadingTracker::Observer, - public PasswordManagerDelegate, public TabSpecificContentSettings::Delegate { public: // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it @@ -157,9 +155,6 @@ class TabContents : public PageNavigator, // Returns the AutoFillManager, creating it if necessary. AutoFillManager* GetAutoFillManager(); - // Returns the PasswordManager, creating it if necessary. - PasswordManager* GetPasswordManager(); - // Returns the PluginInstaller, creating it if necessary. PluginInstaller* GetPluginInstaller(); @@ -269,6 +264,13 @@ class TabContents : public PageNavigator, // Returns a human-readable description the tab's loading state. virtual std::wstring GetStatusText() const; + // Add and remove observers for page navigation notifications. Adding or + // removing multiple times has no effect. The order in which notifications + // are sent to observers is undefined. Clients must be sure to remove the + // observer before they go away. + void AddNavigationObserver(WebNavigationObserver* observer); + void RemoveNavigationObserver(WebNavigationObserver* observer); + // Return whether this tab contents is loading a resource. bool is_loading() const { return is_loading_; } @@ -695,13 +697,6 @@ class TabContents : public PageNavigator, // state by various UI elements. TabSpecificContentSettings* GetTabSpecificContentSettings() const; - // PasswordManagerDelegate implementation. - virtual void FillPasswordForm( - const webkit_glue::PasswordFormFillData& form_data); - virtual void AddSavePasswordInfoBar(PasswordFormManager* form_to_save); - virtual Profile* GetProfileForPasswordManager(); - virtual bool DidLastPageLoadEncounterSSLErrors(); - // Updates history with the specified navigation. This is called by // OnMsgNavigate to update history state. void UpdateHistoryForNavigation( @@ -982,10 +977,6 @@ class TabContents : public PageNavigator, virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, const std::string& json_arguments, IPC::Message* reply_msg); - virtual void PasswordFormsFound( - const std::vector<webkit_glue::PasswordForm>& forms); - virtual void PasswordFormsVisible( - const std::vector<webkit_glue::PasswordForm>& visible_forms); virtual void PageHasOSDD(RenderViewHost* render_view_host, int32 page_id, const GURL& url, @@ -1095,9 +1086,6 @@ class TabContents : public PageNavigator, // AutoFillManager, lazily created. scoped_ptr<AutoFillManager> autofill_manager_; - // PasswordManager, lazily created. - scoped_ptr<PasswordManager> password_manager_; - // PluginInstaller, lazily created. scoped_ptr<PluginInstaller> plugin_installer_; @@ -1304,6 +1292,9 @@ class TabContents : public PageNavigator, // remember it. bool temporary_zoom_settings_; + // A list of observers notified when page state changes. Weak references. + ObserverList<WebNavigationObserver> web_navigation_observers_; + // Content restrictions, used to disable print/copy etc based on content's // (full-page plugins for now only) permissions. int content_restrictions_; diff --git a/chrome/browser/tab_contents/web_navigation_observer.h b/chrome/browser/tab_contents/web_navigation_observer.h new file mode 100644 index 0000000..b42e658 --- /dev/null +++ b/chrome/browser/tab_contents/web_navigation_observer.h @@ -0,0 +1,57 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_NAVIGATION_OBSERVER_H_ +#define CHROME_BROWSER_TAB_CONTENTS_WEB_NAVIGATION_OBSERVER_H_ + +#include "chrome/browser/tab_contents/navigation_controller.h" + +struct ViewHostMsg_FrameNavigate_Params; + +// An observer API implemented by classes which are interested in various page +// load events from TabContents. + +// TODO(pink): Is it worth having a bitfield where certain clients can only +// register for certain events? Is the extra function call worth the added pain +// on the caller to build the bitfield? + +class WebNavigationObserver { + public: + // For removing PasswordManager deps... + + virtual void NavigateToPendingEntry() { } + + virtual void DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { } + virtual void DidNavigateAnyFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { } + + virtual void DidStartLoading() { } + virtual void DidStopLoading() { } + + // TODO(pinkerton): Not sure the best place for these. + virtual void PasswordFormsFound( + const std::vector<webkit_glue::PasswordForm>& forms) { } + virtual void PasswordFormsVisible( + const std::vector<webkit_glue::PasswordForm>& visible_forms) { } + +#if 0 + // For unifying with delegate... + + // Notifies the delegate that this contents is starting or is done loading + // some resource. The delegate should use this notification to represent + // loading feedback. See TabContents::is_loading() + virtual void LoadingStateChanged(TabContents* contents) { } + // Called to inform the delegate that the tab content's navigation state + // changed. The |changed_flags| indicates the parts of the navigation state + // that have been updated, and is any combination of the + // |TabContents::InvalidateTypes| bits. + virtual void NavigationStateChanged(const TabContents* source, + unsigned changed_flags) { } +#endif +}; + +#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_NAVIGATION_OBSERVER_H_ diff --git a/chrome/browser/tab_contents_wrapper.cc b/chrome/browser/tab_contents_wrapper.cc new file mode 100644 index 0000000..707e240 --- /dev/null +++ b/chrome/browser/tab_contents_wrapper.cc @@ -0,0 +1,49 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/tab_contents_wrapper.h" + +#include "chrome/browser/password_manager/password_manager.h" +#include "chrome/browser/password_manager_delegate_impl.h" +#include "chrome/browser/tab_contents/tab_contents.h" + + +TabContentsWrapper::TabContentsWrapper(TabContents* contents) + : tab_contents_(contents) { + DCHECK(contents); + // Stash this in the property bag so it can be retrieved without having to + // go to a Browser. + property_accessor()->SetProperty(contents->property_bag(), this); +} + +TabContentsWrapper::~TabContentsWrapper() { + // Unregister observers (TabContents outlives supporting objects). + tab_contents()->RemoveNavigationObserver(password_manager_.get()); +} + +PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { + return Singleton< PropertyAccessor<TabContentsWrapper*> >::get(); +} + +PasswordManager* TabContentsWrapper::GetPasswordManager() { + if (!password_manager_.get()) { + // Create the delegate then create the manager. + password_manager_delegate_.reset( + new PasswordManagerDelegateImpl(tab_contents())); + password_manager_.reset( + new PasswordManager(password_manager_delegate_.get())); + // Register the manager to receive navigation notifications. + tab_contents()->AddNavigationObserver(password_manager_.get()); + } + return password_manager_.get(); +} + +TabContentsWrapper* TabContentsWrapper::Clone() { + TabContents* new_contents = tab_contents()->Clone(); + TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); + // Instantiate the passowrd manager if it has been instantiated here. + if (password_manager_.get()) + new_wrapper->GetPasswordManager(); + return new_wrapper; +} diff --git a/chrome/browser/tab_contents_wrapper.h b/chrome/browser/tab_contents_wrapper.h new file mode 100644 index 0000000..abed5f5 --- /dev/null +++ b/chrome/browser/tab_contents_wrapper.h @@ -0,0 +1,75 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_TAB_CONTENTS_WRAPPER_H_ +#define CHROME_BROWSER_TAB_CONTENTS_WRAPPER_H_ +#pragma once + +#include "base/scoped_ptr.h" +#include "chrome/browser/tab_contents/tab_contents.h" + +class Extension; +class NavigationController; +class PasswordManager; +class PasswordManagerDelegate; +class TabContentsDelegate; + +// Wraps TabContents and all of its supporting objetcs in order to control +// their ownership and lifetime, while allowing TabContents to remain generic +// and re-usable in other projects. +// TODO(pinkerton): Eventually, this class will become TabContents as far as +// the browser front-end is concerned, and the current TabContents will be +// renamed to something like WebPage or WebView (ben's suggestions). +class TabContentsWrapper { + public: + // Takes ownership of |contents|, which must be heap-allocated (as it lives + // in a scoped_ptr) and can not be NULL. + explicit TabContentsWrapper(TabContents* contents); + ~TabContentsWrapper(); + + // Used to retrieve this object from |tab_contents_|, which is placed in + // its property bag to avoid adding additional interfaces. + static PropertyAccessor<TabContentsWrapper*>* property_accessor(); + + // Create a TabContentsWrapper with the same state as this one. The returned + // heap-allocated pointer is owned by the caller. + TabContentsWrapper* Clone(); + + TabContents* tab_contents() const { return tab_contents_.get(); } + NavigationController& controller() const { + return tab_contents()->controller(); + } + TabContentsView* view() const { return tab_contents()->view(); } + RenderViewHost* render_view_host() const { + return tab_contents()->render_view_host(); + } + Profile* profile() const { return tab_contents()->profile(); } + TabContentsDelegate* delegate() const { return tab_contents()->delegate(); } + void set_delegate(TabContentsDelegate* d) { tab_contents()->set_delegate(d); } + + // Convenience methods until extensions are removed from TabContents. + void SetExtensionAppById(const std::string& extension_app_id) { + tab_contents()->SetExtensionAppById(extension_app_id); + } + const Extension* extension_app() const { + return tab_contents()->extension_app(); + } + bool is_app() const { return tab_contents()->is_app(); } + + // Returns the PasswordManager, creating it if necessary. + PasswordManager* GetPasswordManager(); + + private: + // PasswordManager and its delegate, lazily created. The delegate must + // outlive the manager, per documentation in password_manager.h. + scoped_ptr<PasswordManagerDelegate> password_manager_delegate_; + scoped_ptr<PasswordManager> password_manager_; + + // The supporting objects need to outlive the TabContents dtor (as they may + // be called upon during its execution). As a result, this must come last + // in the list. + scoped_ptr<TabContents> tab_contents_; +}; + +#endif // CHROME_BROWSER_TAB_CONTENTS_WRAPPER_H_ 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 diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index c64818f..2f02b64 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -82,6 +82,7 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tab_menu_model.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_navigator.h" @@ -328,7 +329,8 @@ Browser* Browser::CreateForPopup(Type type, Browser* browser = new Browser(type, profile); browser->set_override_bounds(initial_bounds); browser->CreateBrowserWindow(); - browser->tabstrip_model()->AppendTabContents(new_contents, true); + TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); + browser->tabstrip_model()->AppendTabContents(wrapper, true); return browser; } @@ -561,8 +563,9 @@ TabContents* Browser::OpenApplicationWindow( bool as_panel = extension && (container == extension_misc::LAUNCH_PANEL); Browser* browser = Browser::CreateForApp(app_name, extension, profile, as_panel); - TabContents* contents = + TabContentsWrapper* wrapper = browser->AddSelectedTabWithURL(url, PageTransition::START_PAGE); + TabContents* contents = wrapper->tab_contents(); contents->GetMutableRendererPrefs()->can_accept_load_drops = false; contents->render_view_host()->SyncRendererPrefs(); browser->window()->Show(); @@ -619,13 +622,13 @@ TabContents* Browser::OpenApplicationTab(Profile* profile, // Launch the application in the existing TabContents, if it was supplied. if (existing_tab) { TabStripModel* model = browser->tabstrip_model(); - int tab_index = model->GetIndexOfTabContents(existing_tab); + int tab_index = model->GetWrapperIndex(existing_tab); existing_tab->OpenURL(extension->GetFullLaunchURL(), existing_tab->GetURL(), CURRENT_TAB, PageTransition::LINK); if (params.tabstrip_add_types & TabStripModel::ADD_PINNED) { model->SetTabPinned(tab_index, true); - tab_index = model->GetIndexOfTabContents(existing_tab); + tab_index = model->GetWrapperIndex(existing_tab); } if (params.tabstrip_add_types & TabStripModel::ADD_SELECTED) model->SelectTabContentsAt(tab_index, true); @@ -634,7 +637,7 @@ TabContents* Browser::OpenApplicationTab(Profile* profile, } else { params.disposition = NEW_FOREGROUND_TAB; browser::Navigate(¶ms); - contents = params.target_contents; + contents = params.target_contents->tab_contents(); } if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN) @@ -764,8 +767,7 @@ SkBitmap Browser::GetCurrentPageIcon() const { } string16 Browser::GetWindowTitleForCurrentTab() const { - TabContents* contents = - tab_handler_->GetTabStripModel()->GetSelectedTabContents(); + TabContents* contents = GetSelectedTabContents(); string16 title; // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the @@ -897,12 +899,25 @@ int Browser::GetIndexOfController( return tab_handler_->GetTabStripModel()->GetIndexOfController(controller); } -TabContents* Browser::GetTabContentsAt(int index) const { - return tab_handler_->GetTabStripModel()->GetTabContentsAt(index); +TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { + return tabstrip_model()->GetSelectedTabContents(); +} +TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const { + return tabstrip_model()->GetTabContentsAt(index); } TabContents* Browser::GetSelectedTabContents() const { - return tab_handler_->GetTabStripModel()->GetSelectedTabContents(); + TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); + if (wrapper) + return wrapper->tab_contents(); + return NULL; +} + +TabContents* Browser::GetTabContentsAt(int index) const { + TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); + if (wrapper) + return wrapper->tab_contents(); + return NULL; } void Browser::SelectTabContentsAt(int index, bool user_gesture) { @@ -921,7 +936,7 @@ int Browser::GetIndexForInsertionDuringRestore(int relative_index) { TabStripModel::INSERT_AFTER) ? tab_count() : relative_index; } -TabContents* Browser::AddSelectedTabWithURL(const GURL& url, +TabContentsWrapper* Browser::AddSelectedTabWithURL(const GURL& url, PageTransition::Type transition) { browser::NavigateParams params(this, url, transition); params.disposition = NEW_FOREGROUND_TAB; @@ -929,11 +944,11 @@ TabContents* Browser::AddSelectedTabWithURL(const GURL& url, return params.target_contents; } -TabContents* Browser::AddTab(TabContents* tab_contents, +TabContents* Browser::AddTab(TabContentsWrapper* tab_contents, PageTransition::Type type) { tab_handler_->GetTabStripModel()->AddTabContents( tab_contents, -1, type, TabStripModel::ADD_SELECTED); - return tab_contents; + return tab_contents->tab_contents(); } void Browser::AddTabContents(TabContents* new_contents, @@ -969,10 +984,11 @@ TabContents* Browser::AddRestoredTab( bool pin, bool from_last_session, SessionStorageNamespace* session_storage_namespace) { - TabContents* new_tab = new TabContents( - profile(), NULL, MSG_ROUTING_NONE, - tab_handler_->GetTabStripModel()->GetSelectedTabContents(), + TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL, + MSG_ROUTING_NONE, + GetSelectedTabContents(), session_storage_namespace); + TabContents* new_tab = wrapper->tab_contents(); new_tab->SetExtensionAppById(extension_app_id); new_tab->controller().RestoreFromState(navigations, selected_navigation, from_last_session); @@ -980,7 +996,7 @@ TabContents* Browser::AddRestoredTab( bool really_pin = (pin && tab_index == tabstrip_model()->IndexOfFirstNonMiniTab()); tab_handler_->GetTabStripModel()->InsertTabContentsAt( - tab_index, new_tab, + tab_index, wrapper, select ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE); if (really_pin) tab_handler_->GetTabStripModel()->SetTabPinned(tab_index, true); @@ -1010,17 +1026,18 @@ void Browser::ReplaceRestoredTab( bool from_last_session, const std::string& extension_app_id, SessionStorageNamespace* session_storage_namespace) { - TabContents* replacement = new TabContents(profile(), NULL, + TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL, MSG_ROUTING_NONE, - tab_handler_->GetTabStripModel()->GetSelectedTabContents(), + GetSelectedTabContents(), session_storage_namespace); + TabContents* replacement = wrapper->tab_contents(); replacement->SetExtensionAppById(extension_app_id); replacement->controller().RestoreFromState(navigations, selected_navigation, from_last_session); tab_handler_->GetTabStripModel()->ReplaceNavigationControllerAt( tab_handler_->GetTabStripModel()->selected_index(), - &replacement->controller()); + wrapper); } bool Browser::CanRestoreTab() { @@ -1111,7 +1128,7 @@ bool Browser::ShouldOpenNewTabForWindowDisposition( TabContents* Browser::GetOrCloneTabForDisposition( WindowOpenDisposition disposition) { - TabContents* current_tab = GetSelectedTabContents(); + TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); if (ShouldOpenNewTabForWindowDisposition(disposition)) { current_tab = current_tab->Clone(); tab_handler_->GetTabStripModel()->AddTabContents( @@ -1119,7 +1136,7 @@ TabContents* Browser::GetOrCloneTabForDisposition( disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE); } - return current_tab; + return current_tab->tab_contents(); } void Browser::UpdateTabStripModelInsertionPolicy() { @@ -1182,12 +1199,13 @@ bool Browser::IsClosingPermitted() { void Browser::GoBack(WindowOpenDisposition disposition) { UserMetrics::RecordAction(UserMetricsAction("Back"), profile_); - TabContents* current_tab = GetSelectedTabContents(); + TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); if (current_tab->controller().CanGoBack()) { TabContents* new_tab = GetOrCloneTabForDisposition(disposition); // If we are on an interstitial page and clone the tab, it won't be copied // to the new tab, so we don't need to go back. - if (current_tab->showing_interstitial_page() && (new_tab != current_tab)) + if (current_tab->tab_contents()->showing_interstitial_page() && + (new_tab != current_tab->tab_contents())) return; new_tab->controller().GoBack(); } @@ -1195,7 +1213,7 @@ void Browser::GoBack(WindowOpenDisposition disposition) { void Browser::GoForward(WindowOpenDisposition disposition) { UserMetrics::RecordAction(UserMetricsAction("Forward"), profile_); - if (GetSelectedTabContents()->controller().CanGoForward()) + if (GetSelectedTabContentsWrapper()->controller().CanGoForward()) GetOrCloneTabForDisposition(disposition)->controller().GoForward(); } @@ -1221,13 +1239,13 @@ void Browser::ReloadInternal(WindowOpenDisposition disposition, } // As this is caused by a user action, give the focus to the page. - current_tab = GetOrCloneTabForDisposition(disposition); - if (!current_tab->FocusLocationBarByDefault()) - current_tab->Focus(); + TabContents* tab = GetOrCloneTabForDisposition(disposition); + if (!tab->FocusLocationBarByDefault()) + tab->Focus(); if (ignore_cache) - current_tab->controller().ReloadIgnoringCache(true); + tab->controller().ReloadIgnoringCache(true); else - current_tab->controller().Reload(true); + tab->controller().Reload(true); } void Browser::Home(WindowOpenDisposition disposition) { @@ -1257,7 +1275,7 @@ void Browser::OpenCurrentURL() { void Browser::Stop() { UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); - GetSelectedTabContents()->Stop(); + GetSelectedTabContentsWrapper()->tab_contents()->Stop(); } void Browser::NewWindow() { @@ -1297,7 +1315,7 @@ void Browser::NewTab() { // The call to AddBlankTab above did not set the focus to the tab as its // window was not active, so we have to do it explicitly. // See http://crbug.com/6380. - b->GetSelectedTabContents()->view()->RestoreFocus(); + b->GetSelectedTabContentsWrapper()->view()->RestoreFocus(); } } @@ -1391,7 +1409,7 @@ void Browser::WriteCurrentURLToClipboard() { void Browser::ConvertPopupToTabbedBrowser() { UserMetrics::RecordAction(UserMetricsAction("ShowAsTab"), profile_); int tab_strip_index = tab_handler_->GetTabStripModel()->selected_index(); - TabContents* contents = + TabContentsWrapper* contents = tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); Browser* browser = Browser::Create(profile_); browser->tabstrip_model()->AppendTabContents(contents, true); @@ -1587,7 +1605,7 @@ void Browser::Zoom(PageZoom::Function zoom_function) { UserMetrics::RecordAction(kActions[zoom_function - PageZoom::ZOOM_OUT], profile_); - TabContents* tab_contents = GetSelectedTabContents(); + TabContentsWrapper* tab_contents = GetSelectedTabContentsWrapper(); tab_contents->render_view_host()->Zoom(zoom_function); } @@ -1658,9 +1676,10 @@ void Browser::OpenFile() { void Browser::OpenCreateShortcutsDialog() { UserMetrics::RecordAction(UserMetricsAction("CreateShortcut"), profile_); #if defined(OS_WIN) || defined(OS_LINUX) - TabContents* current_tab = GetSelectedTabContents(); - DCHECK(current_tab && web_app::IsValidUrl(current_tab->GetURL())) << - "Menu item should be disabled."; + TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); + DCHECK(current_tab && + web_app::IsValidUrl(current_tab->tab_contents()->GetURL())) << + "Menu item should be disabled."; NavigationEntry* entry = current_tab->controller().GetLastCommittedEntry(); if (!entry) @@ -1692,7 +1711,7 @@ void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) { } UserMetrics::RecordAction(UserMetricsAction(uma_string.c_str()), profile_); DevToolsManager::GetInstance()->ToggleDevToolsWindow( - GetSelectedTabContents()->render_view_host(), action); + GetSelectedTabContentsWrapper()->render_view_host(), action); } void Browser::OpenTaskManager() { @@ -2043,7 +2062,7 @@ void Browser::ExecuteCommandWithDisposition( // tab. However, Ben says he tried removing this before and got lots of // crashes, e.g. from Windows sending WM_COMMANDs at random times during // window construction. This probably could use closer examination someday. - if (!GetSelectedTabContents()) + if (!GetSelectedTabContentsWrapper()) return; DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command"; @@ -2248,12 +2267,12 @@ int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { return last_blocked_command_id_; } -void Browser::UpdateUIForNavigationInTab(TabContents* contents, +void Browser::UpdateUIForNavigationInTab(TabContentsWrapper* contents, PageTransition::Type transition, bool user_initiated) { tabstrip_model()->TabNavigating(contents, transition); - bool contents_is_selected = contents == GetSelectedTabContents(); + bool contents_is_selected = contents == GetSelectedTabContentsWrapper(); if (user_initiated && contents_is_selected && window()->GetLocationBar()) { // Forcibly reset the location bar if the url is going to change in the // current tab, since otherwise it won't discard any ongoing user edits, @@ -2270,10 +2289,10 @@ void Browser::UpdateUIForNavigationInTab(TabContents* contents, // displaying a favicon, which controls the throbber. If we updated it here, // the throbber will show the default favicon for a split second when // navigating away from the new tab page. - ScheduleUIUpdate(contents, TabContents::INVALIDATE_URL); + ScheduleUIUpdate(contents->tab_contents(), TabContents::INVALIDATE_URL); if (contents_is_selected) - contents->Focus(); + contents->tab_contents()->Focus(); } GURL Browser::GetHomePage() const { @@ -2333,11 +2352,11 @@ Browser* Browser::AsBrowser() { /////////////////////////////////////////////////////////////////////////////// // Browser, TabStripModelDelegate implementation: -TabContents* Browser::AddBlankTab(bool foreground) { +TabContentsWrapper* Browser::AddBlankTab(bool foreground) { return AddBlankTabAt(-1, foreground); } -TabContents* Browser::AddBlankTabAt(int index, bool foreground) { +TabContentsWrapper* Browser::AddBlankTabAt(int index, bool foreground) { // Time new tab page creation time. We keep track of the timing data in // TabContents, but we want to include the time it takes to create the // TabContents object too. @@ -2347,14 +2366,16 @@ TabContents* Browser::AddBlankTabAt(int index, bool foreground) { params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; params.tabstrip_index = index; browser::Navigate(¶ms); - params.target_contents->set_new_tab_start_time(new_tab_start_time); + params.target_contents->tab_contents()->set_new_tab_start_time( + new_tab_start_time); return params.target_contents; } -Browser* Browser::CreateNewStripWithContents(TabContents* detached_contents, - const gfx::Rect& window_bounds, - const DockInfo& dock_info, - bool maximize) { +Browser* Browser::CreateNewStripWithContents( + TabContentsWrapper* detached_contents, + const gfx::Rect& window_bounds, + const DockInfo& dock_info, + bool maximize) { DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); gfx::Rect new_window_bounds = window_bounds; @@ -2370,18 +2391,18 @@ Browser* Browser::CreateNewStripWithContents(TabContents* detached_contents, browser->tabstrip_model()->AppendTabContents(detached_contents, true); // Make sure the loading state is updated correctly, otherwise the throbber // won't start if the page is loading. - browser->LoadingStateChanged(detached_contents); + browser->LoadingStateChanged(detached_contents->tab_contents()); return browser; } -void Browser::ContinueDraggingDetachedTab(TabContents* contents, +void Browser::ContinueDraggingDetachedTab(TabContentsWrapper* contents, const gfx::Rect& window_bounds, const gfx::Rect& tab_bounds) { Browser* browser = new Browser(TYPE_NORMAL, profile_); browser->set_override_bounds(window_bounds); browser->CreateBrowserWindow(); browser->tabstrip_model()->AppendTabContents(contents, true); - browser->LoadingStateChanged(contents); + browser->LoadingStateChanged(contents->tab_contents()); browser->window()->Show(); browser->window()->ContinueDraggingDetachedTab(tab_bounds); } @@ -2391,14 +2412,13 @@ int Browser::GetDragActions() const { TabStripModelDelegate::TAB_MOVE_ACTION : 0); } -TabContents* Browser::CreateTabContentsForURL( +TabContentsWrapper* Browser::CreateTabContentsForURL( const GURL& url, const GURL& referrer, Profile* profile, PageTransition::Type transition, bool defer_load, SiteInstance* instance) const { - TabContents* contents = new TabContents(profile, instance, + TabContentsWrapper* contents = TabContentsFactory(profile, instance, MSG_ROUTING_NONE, - tab_handler_->GetTabStripModel()->GetSelectedTabContents(), NULL); - + GetSelectedTabContents(), NULL); if (!defer_load) { // Load the initial URL before adding the new tab contents to the tab strip // so that the tab contents has navigation state. @@ -2414,7 +2434,7 @@ bool Browser::CanDuplicateContentsAt(int index) { } void Browser::DuplicateContentsAt(int index) { - TabContents* contents = GetTabContentsAt(index); + TabContentsWrapper* contents = GetTabContentsWrapperAt(index); TabContents* new_contents = NULL; DCHECK(contents); bool pinned = false; @@ -2422,13 +2442,14 @@ void Browser::DuplicateContentsAt(int index) { if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { // If this is a tabbed browser, just create a duplicate tab inside the same // window next to the tab being duplicated. - new_contents = contents->Clone(); + TabContentsWrapper* wrapper = contents->Clone(); + new_contents = wrapper->tab_contents(); pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index); int add_types = TabStripModel::ADD_SELECTED | TabStripModel::ADD_INHERIT_GROUP | (pinned ? TabStripModel::ADD_PINNED : 0); tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, - new_contents, + wrapper, add_types); } else { Browser* browser = NULL; @@ -2452,9 +2473,7 @@ void Browser::DuplicateContentsAt(int index) { browser->window()->Show(); // The page transition below is only for the purpose of inserting the tab. - new_contents = browser->AddTab( - contents->Clone()->controller().tab_contents(), - PageTransition::LINK); + new_contents = browser->AddTab(contents->Clone(), PageTransition::LINK); } if (profile_->HasSessionService()) { @@ -2475,7 +2494,7 @@ void Browser::CloseFrameAfterDragSession() { #endif } -void Browser::CreateHistoricalTab(TabContents* contents) { +void Browser::CreateHistoricalTab(TabContentsWrapper* contents) { // We don't create historical tabs for incognito windows or windows without // profiles. if (!profile() || profile()->IsOffTheRecord() || @@ -2490,8 +2509,8 @@ void Browser::CreateHistoricalTab(TabContents* contents) { } } -bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) { - return Browser::RunUnloadEventsHelper(contents); +bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { + return Browser::RunUnloadEventsHelper(contents->tab_contents()); } bool Browser::CanReloadContents(TabContents* source) const { @@ -2550,26 +2569,26 @@ bool Browser::LargeIconsPermitted() const { /////////////////////////////////////////////////////////////////////////////// // Browser, TabStripModelObserver implementation: -void Browser::TabInsertedAt(TabContents* contents, +void Browser::TabInsertedAt(TabContentsWrapper* contents, int index, bool foreground) { - contents->set_delegate(this); + contents->tab_contents()->set_delegate(this); contents->controller().SetWindowID(session_id()); SyncHistoryWithTabs(index); // Make sure the loading state is updated correctly, otherwise the throbber // won't start if the page is loading. - LoadingStateChanged(contents); + LoadingStateChanged(contents->tab_contents()); // If the tab crashes in the beforeunload or unload handler, it won't be // able to ack. But we know we can close it. registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, - Source<TabContents>(contents)); + Source<TabContentsWrapper>(contents)); } void Browser::TabClosingAt(TabStripModel* tab_strip_model, - TabContents* contents, + TabContentsWrapper* contents, int index) { NotificationService::current()->Notify( NotificationType::TAB_CLOSING, @@ -2577,24 +2596,24 @@ void Browser::TabClosingAt(TabStripModel* tab_strip_model, NotificationService::NoDetails()); // Sever the TabContents' connection back to us. - contents->set_delegate(NULL); + contents->tab_contents()->set_delegate(NULL); } -void Browser::TabDetachedAt(TabContents* contents, int index) { +void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); } -void Browser::TabDeselectedAt(TabContents* contents, int index) { +void Browser::TabDeselectedAt(TabContentsWrapper* contents, int index) { if (instant()) instant()->DestroyPreviewContents(); // Save what the user's currently typing, so it can be restored when we // switch back to this tab. - window_->GetLocationBar()->SaveStateToContents(contents); + window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); } -void Browser::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, +void Browser::TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture) { DCHECK(old_contents != new_contents); @@ -2607,7 +2626,7 @@ void Browser::TabSelectedAt(TabContents* old_contents, UpdateToolbar(true); // Update reload/stop state. - UpdateReloadStopState(new_contents->is_loading(), true); + UpdateReloadStopState(new_contents->tab_contents()->is_loading(), true); // Update commands to reflect current state. UpdateCommandsForTabState(); @@ -2623,7 +2642,7 @@ void Browser::TabSelectedAt(TabContents* old_contents, } if (HasFindBarController()) { - find_bar_controller_->ChangeTabContents(new_contents); + find_bar_controller_->ChangeTabContents(new_contents->tab_contents()); find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); } @@ -2638,7 +2657,7 @@ void Browser::TabSelectedAt(TabContents* old_contents, } } -void Browser::TabMoved(TabContents* contents, +void Browser::TabMoved(TabContentsWrapper* contents, int from_index, int to_index) { DCHECK(from_index >= 0 && to_index >= 0); @@ -2646,8 +2665,8 @@ void Browser::TabMoved(TabContents* contents, SyncHistoryWithTabs(std::min(from_index, to_index)); } -void Browser::TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, +void Browser::TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index) { TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); TabInsertedAt(new_contents, index, @@ -2671,7 +2690,7 @@ void Browser::TabReplacedAt(TabContents* old_contents, } } -void Browser::TabPinnedStateChanged(TabContents* contents, int index) { +void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { if (!profile()->HasSessionService()) return; SessionService* session_service = profile()->GetSessionService(); @@ -2705,7 +2724,9 @@ void Browser::OpenURLFromTab(TabContents* source, WindowOpenDisposition disposition, PageTransition::Type transition) { browser::NavigateParams params(this, url, transition); - params.source_contents = source; + params.source_contents = + tabstrip_model()->GetTabContentsAt( + tabstrip_model()->GetWrapperIndex(source)); params.referrer = referrer; params.disposition = disposition; params.tabstrip_add_types = TabStripModel::ADD_NONE; @@ -2752,16 +2773,19 @@ void Browser::AddNewContents(TabContents* source, } #endif - browser::NavigateParams params(this, new_contents); - params.source_contents = source; - params.disposition = disposition; - params.window_bounds = initial_pos; - browser::Navigate(¶ms); + TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); + browser::NavigateParams params(this, wrapper); + params.source_contents = + tabstrip_model()->GetTabContentsAt( + tabstrip_model()->GetWrapperIndex(source)); + params.disposition = disposition; + params.window_bounds = initial_pos; + browser::Navigate(¶ms); } void Browser::ActivateContents(TabContents* contents) { tab_handler_->GetTabStripModel()->SelectTabContentsAt( - tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents), false); + tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); window_->Activate(); } @@ -2774,7 +2798,8 @@ void Browser::LoadingStateChanged(TabContents* source) { tab_handler_->GetTabStripModel()->TabsAreLoading()); window_->UpdateTitleBar(); - if (source == GetSelectedTabContents()) { + TabContents* selected_contents = GetSelectedTabContents(); + if (source == selected_contents) { UpdateReloadStopState(source->is_loading(), false); if (GetStatusBubble()) { GetStatusBubble()->SetStatus(WideToUTF16( @@ -2807,7 +2832,7 @@ void Browser::CloseContents(TabContents* source) { return; } - int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents(source); + int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); if (index == TabStripModel::kNoTab) { NOTREACHED() << "CloseContents called for tab not in our strip"; return; @@ -2826,7 +2851,7 @@ void Browser::MoveContents(TabContents* source, const gfx::Rect& pos) { } void Browser::DetachContents(TabContents* source) { - int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents(source); + int index = tab_handler_->GetTabStripModel()->GetWrapperIndex(source); if (index >= 0) tab_handler_->GetTabStripModel()->DetachTabContentsAt(index); } @@ -2890,7 +2915,7 @@ void Browser::OnContentSettingsChange(TabContents* source) { } void Browser::SetTabContentBlocked(TabContents* contents, bool blocked) { - int index = tabstrip_model()->GetIndexOfTabContents(contents); + int index = tabstrip_model()->GetWrapperIndex(contents); if (index == TabStripModel::kNoTab) { NOTREACHED(); return; @@ -2921,8 +2946,9 @@ void Browser::ConvertContentsToApplication(TabContents* contents) { DetachContents(contents); Browser* browser = Browser::CreateForApp(app_name, NULL, profile_, false); - browser->tabstrip_model()->AppendTabContents(contents, true); - TabContents* tab_contents = browser->GetSelectedTabContents(); + TabContentsWrapper* wrapper = new TabContentsWrapper(contents); + browser->tabstrip_model()->AppendTabContents(wrapper, true); + TabContents* tab_contents = GetSelectedTabContents(); tab_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; tab_contents->render_view_host()->SyncRendererPrefs(); browser->window()->Show(); @@ -3186,7 +3212,7 @@ void Browser::Observe(NotificationType type, const Extension* extension = Details<const Extension>(details).ptr(); TabStripModel* model = tab_handler_->GetTabStripModel(); for (int i = model->count() - 1; i >= 0; --i) { - TabContents* tc = model->GetTabContentsAt(i); + TabContents* tc = model->GetTabContentsAt(i)->tab_contents(); if (tc->GetURL().SchemeIs(chrome::kExtensionScheme) && tc->GetURL().host() == extension->id()) { CloseTabContents(tc); @@ -3316,20 +3342,20 @@ void Browser::PrepareForInstant() { window_->PrepareForInstant(); } -void Browser::ShowInstant(TabContents* preview_contents) { - DCHECK(instant_->tab_contents() == GetSelectedTabContents()); - window_->ShowInstant(preview_contents); +void Browser::ShowInstant(TabContentsWrapper* preview_contents) { + DCHECK(instant_->tab_contents() == GetSelectedTabContentsWrapper()); + window_->ShowInstant(preview_contents->tab_contents()); } void Browser::HideInstant() { window_->HideInstant(); } -void Browser::CommitInstant(TabContents* preview_contents) { - TabContents* tab_contents = instant_->tab_contents(); - int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents( - tab_contents); - DCHECK_NE(-1, index); +void Browser::CommitInstant(TabContentsWrapper* preview_contents) { + TabContentsWrapper* tab_contents = instant_->tab_contents(); + int index = + tab_handler_->GetTabStripModel()->GetIndexOfTabContents(tab_contents); + DCHECK_NE(TabStripModel::kNoTab, index); preview_contents->controller().CopyStateFromAndPrune( &tab_contents->controller()); // TabStripModel takes ownership of preview_contents. @@ -3604,7 +3630,7 @@ void Browser::UpdateCommandsForDevTools() { // Browser, UI update coalescing and handling (private): void Browser::UpdateToolbar(bool should_restore_state) { - window_->UpdateToolbar(GetSelectedTabContents(), should_restore_state); + window_->UpdateToolbar(GetSelectedTabContentsWrapper(), should_restore_state); } void Browser::ScheduleUIUpdate(const TabContents* source, @@ -3718,7 +3744,7 @@ void Browser::ProcessPendingUIUpdates() { // Updates that don't depend upon the selected state go here. if (flags & (TabContents::INVALIDATE_TAB | TabContents::INVALIDATE_TITLE)) { tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( - tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents), + tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), TabStripModelObserver::ALL); } @@ -3986,22 +4012,22 @@ void Browser::CloseFrame() { window_->Close(); } -void Browser::TabDetachedAtImpl(TabContents* contents, int index, +void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index, DetachType type) { if (type == DETACH_TYPE_DETACH) { // Save the current location bar state, but only if the tab being detached // is the selected tab. Because saving state can conditionally revert the // location bar, saving the current tab's location bar state to a // non-selected tab can corrupt both tabs. - if (contents == GetSelectedTabContents()) - window_->GetLocationBar()->SaveStateToContents(contents); + if (contents == GetSelectedTabContentsWrapper()) + window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); if (!tab_handler_->GetTabStripModel()->closing_all()) SyncHistoryWithTabs(0); } - contents->set_delegate(NULL); - RemoveScheduledUpdatesFor(contents); + contents->tab_contents()->set_delegate(NULL); + RemoveScheduledUpdatesFor(contents->tab_contents()); if (find_bar_controller_.get() && index == tab_handler_->GetTabStripModel()->selected_index()) { @@ -4009,7 +4035,7 @@ void Browser::TabDetachedAtImpl(TabContents* contents, int index, } registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED, - Source<TabContents>(contents)); + Source<TabContentsWrapper>(contents)); } // static @@ -4049,6 +4075,21 @@ void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { tab_restore_service_ = NULL; } +// Centralized method for creating a TabContents, configuring and installing +// all its supporting objects and observers. +TabContentsWrapper* Browser::TabContentsFactory( + Profile* profile, + SiteInstance* site_instance, + int routing_id, + const TabContents* base_tab_contents, + SessionStorageNamespace* session_storage_namespace) { + TabContents* new_contents = new TabContents(profile, site_instance, + routing_id, base_tab_contents, + session_storage_namespace); + TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); + return wrapper; +} + bool Browser::OpenInstant(WindowOpenDisposition disposition) { if (!instant() || !instant()->is_active() || !instant()->IsCurrent()) return false; @@ -4059,7 +4100,7 @@ bool Browser::OpenInstant(WindowOpenDisposition disposition) { } if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { HideInstant(); - TabContents* preview_contents = instant()->ReleasePreviewContents( + TabContentsWrapper* preview_contents = instant()->ReleasePreviewContents( INSTANT_COMMIT_PRESSED_ENTER); preview_contents->controller().PruneAllButActive(); tab_handler_->GetTabStripModel()->AddTabContents( @@ -4068,7 +4109,7 @@ bool Browser::OpenInstant(WindowOpenDisposition disposition) { instant()->last_transition_type(), disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE); - instant()->CompleteRelease(preview_contents); + instant()->CompleteRelease(preview_contents->tab_contents()); return true; } // The omnibox currently doesn't use other dispositions, so we don't attempt diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 3b1e2b5..b70049b 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -325,8 +325,16 @@ class Browser : public TabHandlerDelegate, int tab_count() const; int selected_index() const; int GetIndexOfController(const NavigationController* controller) const; - TabContents* GetTabContentsAt(int index) const; + TabContentsWrapper* GetSelectedTabContentsWrapper() const; + TabContentsWrapper* GetTabContentsWrapperAt(int index) const; + // Same as above but correctly handles if GetSelectedTabContents() is NULL + // in the model before dereferencing to get the raw TabContents. + // TODO(pinkerton): These should really be returning TabContentsWrapper + // objects, but that would require changing about 50+ other files. In order + // to keep changes localized, the default is to return a TabContents. Note + // this differs from the TabStripModel because it has far fewer clients. TabContents* GetSelectedTabContents() const; + TabContents* GetTabContentsAt(int index) const; void SelectTabContentsAt(int index, bool user_gesture); void CloseAllTabs(); @@ -340,12 +348,14 @@ class Browser : public TabHandlerDelegate, // Adds a selected tab with the specified URL and transition, returns the // created TabContents. - TabContents* AddSelectedTabWithURL(const GURL& url, - PageTransition::Type transition); + TabContentsWrapper* AddSelectedTabWithURL( + const GURL& url, + PageTransition::Type transition); // Add a new tab, given a TabContents. A TabContents appropriate to // display the last committed entry is created and returned. - TabContents* AddTab(TabContents* tab_contents, PageTransition::Type type); + TabContents* AddTab(TabContentsWrapper* tab_contents, + PageTransition::Type type); // Add a tab with its session history restored from the SessionRestore // system. If select is true, the tab is selected. |tab_index| gives the index @@ -597,7 +607,7 @@ class Browser : public TabHandlerDelegate, // Called by browser::Navigate() when a navigation has occurred in a tab in // this Browser. Updates the UI for the start of this navigation. - void UpdateUIForNavigationInTab(TabContents* contents, + void UpdateUIForNavigationInTab(TabContentsWrapper* contents, PageTransition::Type transition, bool user_initiated); @@ -619,25 +629,34 @@ class Browser : public TabHandlerDelegate, virtual void TabRestoreServiceChanged(TabRestoreService* service); virtual void TabRestoreServiceDestroyed(TabRestoreService* service); + // Centralized method for creating a TabContents, configuring and installing + // all its supporting objects and observers. + static TabContentsWrapper* + TabContentsFactory(Profile* profile, + SiteInstance* site_instance, + int routing_id, + const TabContents* base_tab_contents, + SessionStorageNamespace* session_storage_namespace); // Overridden from TabHandlerDelegate: virtual Profile* GetProfile() const; virtual Browser* AsBrowser(); // 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; // Construct a TabContents for a given URL, profile and transition type. // If instance is not null, its process will be used to render the tab. - virtual TabContents* CreateTabContentsForURL(const GURL& url, + virtual TabContentsWrapper* CreateTabContentsForURL(const GURL& url, const GURL& referrer, Profile* profile, PageTransition::Type transition, @@ -646,8 +665,8 @@ class Browser : public TabHandlerDelegate, 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(); @@ -658,25 +677,25 @@ class Browser : public TabHandlerDelegate, virtual bool LargeIconsPermitted() 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: @@ -774,9 +793,9 @@ class Browser : public TabHandlerDelegate, // Overriden from InstantDelegate: virtual void PrepareForInstant(); - virtual void ShowInstant(TabContents* preview_contents); + virtual void ShowInstant(TabContentsWrapper* preview_contents); virtual void HideInstant(); - virtual void CommitInstant(TabContents* preview_contents); + virtual void CommitInstant(TabContentsWrapper* preview_contents); virtual void SetSuggestedText(const string16& text); virtual gfx::Rect GetInstantBounds(); @@ -906,7 +925,8 @@ class Browser : public TabHandlerDelegate, // after a return to the message loop. void CloseFrame(); - void TabDetachedAtImpl(TabContents* contents, int index, DetachType type); + void TabDetachedAtImpl(TabContentsWrapper* contents, + int index, DetachType type); // Create a preference dictionary for the provided application name. This is // done only once per application name / per session. diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index 84c85ff..9085033 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -48,6 +48,7 @@ #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/pinned_tab_codec.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_navigator.h" @@ -777,8 +778,8 @@ Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser( browser::Navigate(¶ms); if (profile_ && first_tab && process_startup) { - AddCrashedInfoBarIfNecessary(params.target_contents); - AddBadFlagsInfoBarIfNecessary(params.target_contents); + AddCrashedInfoBarIfNecessary(params.target_contents->tab_contents()); + AddBadFlagsInfoBarIfNecessary(params.target_contents->tab_contents()); } first_tab = false; diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc index 7143bdf..cde98d9 100644 --- a/chrome/browser/ui/browser_navigator.cc +++ b/chrome/browser/ui/browser_navigator.cc @@ -14,6 +14,7 @@ #include "chrome/browser/status_bubble.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/url_constants.h" @@ -82,16 +83,18 @@ int GetIndexOfSingletonTab(browser::NavigateParams* params) { &reverse_on_redirect); for (int i = 0; i < params->browser->tab_count(); ++i) { - TabContents* tab = params->browser->GetTabContentsAt(i); + TabContentsWrapper* tab = + params->browser->GetTabContentsWrapperAt(i); url_canon::Replacements<char> replacements; replacements.ClearRef(); if (params->ignore_path) replacements.ClearPath(); - if (CompareURLsWithReplacements(tab->GetURL(), params->url, replacements) || - CompareURLsWithReplacements(tab->GetURL(), rewritten_url, - replacements)) { + if (CompareURLsWithReplacements(tab->tab_contents()->GetURL(), + params->url, replacements) || + CompareURLsWithReplacements(tab->tab_contents()->GetURL(), + rewritten_url, replacements)) { params->target_contents = tab; return i; } @@ -130,7 +133,8 @@ Browser* GetBrowserForDisposition(browser::NavigateParams* params) { // target browser. This must happen first, before GetBrowserForDisposition() // has a chance to replace |params->browser| with another one. if (!params->source_contents && params->browser) - params->source_contents = params->browser->GetSelectedTabContents(); + params->source_contents = + params->browser->GetSelectedTabContentsWrapper(); Profile* profile = params->browser ? params->browser->profile() : params->profile; @@ -158,7 +162,8 @@ Browser* GetBrowserForDisposition(browser::NavigateParams* params) { // |source| represents an app. Browser::Type type = Browser::TYPE_POPUP; if ((params->browser && params->browser->type() == Browser::TYPE_APP) || - (params->source_contents && params->source_contents->is_app())) { + (params->source_contents && + params->source_contents->is_app())) { type = Browser::TYPE_APP_POPUP; } if (profile) { @@ -272,13 +277,13 @@ class ScopedTargetContentsOwner { } // Relinquishes ownership of |params_|' target_contents. - TabContents* ReleaseOwnership() { + TabContentsWrapper* ReleaseOwnership() { return target_contents_owner_.release(); } private: browser::NavigateParams* params_; - scoped_ptr<TabContents> target_contents_owner_; + scoped_ptr<TabContentsWrapper> target_contents_owner_; DISALLOW_COPY_AND_ASSIGN(ScopedTargetContentsOwner); }; @@ -303,7 +308,7 @@ NavigateParams::NavigateParams( } NavigateParams::NavigateParams(Browser* a_browser, - TabContents* a_target_contents) + TabContentsWrapper* a_target_contents) : target_contents(a_target_contents), source_contents(NULL), disposition(CURRENT_TAB), @@ -354,12 +359,15 @@ void Navigate(NavigateParams* params) { // supposed to target a new tab. if (!params->target_contents) { if (params->disposition != CURRENT_TAB) { + TabContents* source_contents = params->source_contents ? + params->source_contents->tab_contents() : NULL; params->target_contents = - new TabContents(params->browser->profile(), - GetSiteInstance(params->source_contents, params->url), - MSG_ROUTING_NONE, - params->source_contents, - NULL); + Browser::TabContentsFactory( + params->browser->profile(), + GetSiteInstance(source_contents, params->url), + MSG_ROUTING_NONE, + source_contents, + NULL); // This function takes ownership of |params->target_contents| until it // is added to a TabStripModel. target_contents_owner.TakeOwnership(); @@ -370,7 +378,7 @@ void Navigate(NavigateParams* params) { // in the background, tell it that it's hidden. if ((params->tabstrip_add_types & TabStripModel::ADD_SELECTED) == 0) { // TabStripModel::AddTabContents invokes HideContents if not foreground. - params->target_contents->WasHidden(); + params->target_contents->tab_contents()->WasHidden(); } } else { // ... otherwise if we're loading in the current tab, the target is the @@ -381,7 +389,7 @@ void Navigate(NavigateParams* params) { if (user_initiated) { RenderViewHostDelegate::BrowserIntegration* integration = - params->target_contents; + params->target_contents->tab_contents(); integration->OnUserGesture(); } @@ -397,10 +405,11 @@ void Navigate(NavigateParams* params) { } if (params->source_contents == params->target_contents) { - // The navigation occurred in the source tab, so update the UI. - params->browser->UpdateUIForNavigationInTab(params->target_contents, - params->transition, - user_initiated); + // The navigation occurred in the source tab. + params->browser->UpdateUIForNavigationInTab( + params->target_contents, + params->transition, + user_initiated); } else { // The navigation occurred in some other tab. int singleton_index = GetIndexOfSingletonTab(params); diff --git a/chrome/browser/ui/browser_navigator.h b/chrome/browser/ui/browser_navigator.h index 67bebbd..bdc8d8c 100644 --- a/chrome/browser/ui/browser_navigator.h +++ b/chrome/browser/ui/browser_navigator.h @@ -15,7 +15,7 @@ class Browser; class Profile; -class TabContents; +class TabContentsWrapper; namespace browser { @@ -44,7 +44,7 @@ struct NavigateParams { NavigateParams(Browser* browser, const GURL& a_url, PageTransition::Type a_transition); - NavigateParams(Browser* browser, TabContents* a_target_contents); + NavigateParams(Browser* browser, TabContentsWrapper* a_target_contents); ~NavigateParams(); // The URL/referrer to be loaded. Ignored if |target_contents| is non-NULL. @@ -63,13 +63,13 @@ struct NavigateParams { // a new TabContents, this field will remain NULL and the TabContents // deleted if the TabContents it created is not added to a TabStripModel // before Navigate() returns. - TabContents* target_contents; + TabContentsWrapper* target_contents; // [in] The TabContents that initiated the Navigate() request if such context // is necessary. Default is NULL, i.e. no context. // [out] If NULL, this value will be set to the selected TabContents in the // originating browser prior to the operation performed by Navigate(). - TabContents* source_contents; + TabContentsWrapper* source_contents; // The disposition requested by the navigation source. Default is // CURRENT_TAB. What follows is a set of coercions that happen to this value diff --git a/chrome/browser/ui/browser_navigator_browsertest.cc b/chrome/browser/ui/browser_navigator_browsertest.cc index 7bad301..dc9d661 100644 --- a/chrome/browser/ui/browser_navigator_browsertest.cc +++ b/chrome/browser/ui/browser_navigator_browsertest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" @@ -40,12 +41,13 @@ class BrowserNavigatorTest : public InProcessBrowserTest { return browser; } - TabContents* CreateTabContents() { - return new TabContents(browser()->profile(), - NULL, - MSG_ROUTING_NONE, - browser()->GetSelectedTabContents(), - NULL); + TabContentsWrapper* CreateTabContents() { + return Browser::TabContentsFactory( + browser()->profile(), + NULL, + MSG_ROUTING_NONE, + browser()->GetSelectedTabContents(), + NULL); } void RunSuppressTest(WindowOpenDisposition disposition) { @@ -131,7 +133,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) { p.disposition = NEW_FOREGROUND_TAB; browser::Navigate(&p); EXPECT_NE(old_contents, browser()->GetSelectedTabContents()); - EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents); + EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); EXPECT_EQ(2, browser()->tab_count()); } @@ -347,7 +349,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) { // Navigate() should have opened the contents in a new foreground in the // current Browser. EXPECT_EQ(browser(), p.browser); - EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents); + EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); // We should have one window, with two tabs. EXPECT_EQ(1u, BrowserList::size()); @@ -382,7 +384,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_Popup) { // All platforms should respect size however provided width > 400 (Mac has a // minimum window width of 400). EXPECT_EQ(p.window_bounds.size(), - p.target_contents->view()->GetContainerSize()); + p.target_contents->tab_contents()->view()->GetContainerSize()); // We should have two windows, the new popup and the browser() provided by the // framework. @@ -407,7 +409,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) { // Navigate() should have inserted a new tab at slot 0 in the tabstrip. EXPECT_EQ(browser(), p.browser); EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents( - static_cast<const TabContents*>(p.target_contents))); + static_cast<const TabContentsWrapper*>(p.target_contents))); // We should have one window - the browser() provided by the framework. EXPECT_EQ(1u, BrowserList::size()); @@ -428,7 +430,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) { // Navigate() should have found browser() and create a new tab. EXPECT_EQ(browser(), p.browser); EXPECT_NE(old_contents, browser()->GetSelectedTabContents()); - EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents); + EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); EXPECT_EQ(2, browser()->tab_count()); } @@ -447,7 +449,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) { // Navigate() should have found incognito, not browser(). EXPECT_EQ(incognito, p.browser); - EXPECT_EQ(incognito->GetSelectedTabContents(), p.target_contents); + EXPECT_EQ(incognito->GetSelectedTabContentsWrapper(), p.target_contents); EXPECT_EQ(1, incognito->tab_count()); } diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h index 31c1d560..acff556 100644 --- a/chrome/browser/ui/browser_window.h +++ b/chrome/browser/ui/browser_window.h @@ -20,6 +20,7 @@ class LocationBar; class Profile; class StatusBubble; class TabContents; +class TabContentsWrapper; class TemplateURL; class TemplateURLModel; #if !defined(OS_MACOSX) @@ -139,7 +140,7 @@ class BrowserWindow { virtual void UpdateReloadStopState(bool is_loading, bool force) = 0; // Updates the toolbar with the state for the specified |contents|. - virtual void UpdateToolbar(TabContents* contents, + virtual void UpdateToolbar(TabContentsWrapper* contents, bool should_restore_state) = 0; // Focuses the toolbar (for accessibility). diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 8675cfe..4552de4 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -37,6 +37,7 @@ #include "chrome/browser/sidebar/sidebar_manager.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/themes/browser_theme_provider.h" #include "chrome/browser/ui/browser.h" @@ -670,6 +671,10 @@ TabContents* BrowserView::GetSelectedTabContents() const { return browser_->GetSelectedTabContents(); } +TabContentsWrapper* BrowserView::GetSelectedTabContentsWrapper() const { + return browser_->GetSelectedTabContentsWrapper(); +} + SkBitmap BrowserView::GetOTRAvatarIcon() { static SkBitmap* otr_avatar_ = new SkBitmap(); @@ -774,10 +779,10 @@ StatusBubble* BrowserView::GetStatusBubble() { void BrowserView::SelectedTabToolbarSizeChanged(bool is_animating) { if (is_animating) { contents_container_->SetFastResize(true); - UpdateUIForContents(browser_->GetSelectedTabContents()); + UpdateUIForContents(browser_->GetSelectedTabContentsWrapper()); contents_container_->SetFastResize(false); } else { - UpdateUIForContents(browser_->GetSelectedTabContents()); + UpdateUIForContents(browser_->GetSelectedTabContentsWrapper()); // When transitioning from animating to not animating we need to make sure // the contents_container_ gets layed out. If we don't do this and the // bounds haven't changed contents_container_ won't get a Layout out and @@ -798,7 +803,7 @@ void BrowserView::ShelfVisibilityChanged() { } void BrowserView::UpdateDevTools() { - UpdateDevToolsForContents(GetSelectedTabContents()); + UpdateDevToolsForContents(GetSelectedTabContentsWrapper()); Layout(); } @@ -885,9 +890,9 @@ void BrowserView::UpdateReloadStopState(bool is_loading, bool force) { is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD, force); } -void BrowserView::UpdateToolbar(TabContents* contents, +void BrowserView::UpdateToolbar(TabContentsWrapper* contents, bool should_restore_state) { - toolbar_->Update(contents, should_restore_state); + toolbar_->Update(contents->tab_contents(), should_restore_state); } void BrowserView::FocusToolbar() { @@ -1422,7 +1427,7 @@ void BrowserView::Observe(NotificationType type, switch (type.value) { case NotificationType::PREF_CHANGED: if (*Details<std::string>(details).ptr() == prefs::kShowBookmarkBar && - MaybeShowBookmarkBar(browser_->GetSelectedTabContents())) { + MaybeShowBookmarkBar(browser_->GetSelectedTabContentsWrapper())) { Layout(); } break; @@ -1443,7 +1448,7 @@ void BrowserView::Observe(NotificationType type, /////////////////////////////////////////////////////////////////////////////// // BrowserView, TabStripModelObserver implementation: -void BrowserView::TabDetachedAt(TabContents* contents, int index) { +void BrowserView::TabDetachedAt(TabContentsWrapper* contents, int index) { // We use index here rather than comparing |contents| because by this time // the model has already removed |contents| from its list, so // browser_->GetSelectedTabContents() will return NULL or something else. @@ -1458,16 +1463,16 @@ void BrowserView::TabDetachedAt(TabContents* contents, int index) { } } -void BrowserView::TabDeselectedAt(TabContents* contents, int index) { +void BrowserView::TabDeselectedAt(TabContentsWrapper* contents, int index) { // We do not store the focus when closing the tab to work-around bug 4633. // Some reports seem to show that the focus manager and/or focused view can // be garbage at that point, it is not clear why. - if (!contents->is_being_destroyed()) + if (!contents->tab_contents()->is_being_destroyed()) contents->view()->StoreFocus(); } -void BrowserView::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, +void BrowserView::TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture) { DCHECK(old_contents != new_contents); @@ -1475,8 +1480,8 @@ void BrowserView::TabSelectedAt(TabContents* old_contents, ProcessTabSelected(new_contents, true); } -void BrowserView::TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, +void BrowserView::TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index) { if (index != browser_->tabstrip_model()->selected_index()) return; @@ -2014,7 +2019,7 @@ void BrowserView::LayoutStatusBubble() { status_bubble_->SetBounds(origin.x(), origin.y(), width() / 3, height); } -bool BrowserView::MaybeShowBookmarkBar(TabContents* contents) { +bool BrowserView::MaybeShowBookmarkBar(TabContentsWrapper* contents) { views::View* new_bookmark_bar_view = NULL; if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR) && contents) { @@ -2028,7 +2033,7 @@ bool BrowserView::MaybeShowBookmarkBar(TabContents* contents) { } else { bookmark_bar_view_->SetProfile(contents->profile()); } - bookmark_bar_view_->SetPageNavigator(contents); + bookmark_bar_view_->SetPageNavigator(contents->tab_contents()); bookmark_bar_view_-> SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_BOOKMARKS)); new_bookmark_bar_view = bookmark_bar_view_.get(); @@ -2036,7 +2041,7 @@ bool BrowserView::MaybeShowBookmarkBar(TabContents* contents) { return UpdateChildViewAndLayout(new_bookmark_bar_view, &active_bookmark_bar_); } -bool BrowserView::MaybeShowInfoBar(TabContents* contents) { +bool BrowserView::MaybeShowInfoBar(TabContentsWrapper* contents) { // TODO(beng): Remove this function once the interface between // InfoBarContainer, DownloadShelfView and TabContents and this // view is sorted out. @@ -2044,11 +2049,11 @@ bool BrowserView::MaybeShowInfoBar(TabContents* contents) { } void BrowserView::UpdateSidebar() { - UpdateSidebarForContents(GetSelectedTabContents()); + UpdateSidebarForContents(GetSelectedTabContentsWrapper()); Layout(); } -void BrowserView::UpdateSidebarForContents(TabContents* tab_contents) { +void BrowserView::UpdateSidebarForContents(TabContentsWrapper* tab_contents) { if (!sidebar_container_) return; // Happens when sidebar is not allowed. if (!SidebarManager::GetInstance()) @@ -2057,7 +2062,7 @@ void BrowserView::UpdateSidebarForContents(TabContents* tab_contents) { TabContents* sidebar_contents = NULL; if (tab_contents) { SidebarContainer* client_host = SidebarManager::GetInstance()-> - GetActiveSidebarContainerFor(tab_contents); + GetActiveSidebarContainerFor(tab_contents->tab_contents()); if (client_host) sidebar_contents = client_host->sidebar_contents(); } @@ -2104,7 +2109,8 @@ void BrowserView::UpdateSidebarForContents(TabContents* tab_contents) { } } -void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) { +void BrowserView::UpdateDevToolsForContents(TabContentsWrapper* wrapper) { + TabContents* tab_contents = wrapper ? wrapper->tab_contents() : NULL; TabContents* devtools_contents = DevToolsWindow::GetDevToolsContents(tab_contents); @@ -2150,7 +2156,7 @@ void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) { } } -void BrowserView::UpdateUIForContents(TabContents* contents) { +void BrowserView::UpdateUIForContents(TabContentsWrapper* contents) { bool needs_layout = MaybeShowBookmarkBar(contents); needs_layout |= MaybeShowInfoBar(contents); if (needs_layout) @@ -2460,7 +2466,7 @@ void BrowserView::InitHangMonitor() { #endif } -void BrowserView::ProcessTabSelected(TabContents* new_contents, +void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents, bool change_tab_contents) { // Update various elements that are interested in knowing the current // TabContents. @@ -2470,10 +2476,10 @@ void BrowserView::ProcessTabSelected(TabContents* new_contents, // avoid an unnecessary resize and re-layout of a TabContents. if (change_tab_contents) contents_container_->ChangeTabContents(NULL); - infobar_container_->ChangeTabContents(new_contents); + infobar_container_->ChangeTabContents(new_contents->tab_contents()); UpdateUIForContents(new_contents); if (change_tab_contents) - contents_container_->ChangeTabContents(new_contents); + contents_container_->ChangeTabContents(new_contents->tab_contents()); UpdateSidebarForContents(new_contents); UpdateDevToolsForContents(new_contents); @@ -2481,7 +2487,7 @@ void BrowserView::ProcessTabSelected(TabContents* new_contents, // am striving for parity now rather than cleanliness. This is // required to make features like Duplicate Tab, Undo Close Tab, // etc not result in sad tab. - new_contents->DidBecomeSelected(); + new_contents->tab_contents()->DidBecomeSelected(); if (BrowserList::GetLastActive() == browser_ && !browser_->tabstrip_model()->closing_all() && GetWindow()->IsVisible()) { // We only restore focus if our window is visible, to avoid invoking blur diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 7d25a79..628620c 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -183,13 +183,14 @@ class BrowserView : public BrowserBubbleHost, // activated, false if none was shown. bool ActivateAppModalDialog() const; - // Returns the selected TabContents. Used by our NonClientView's + // Returns the selected TabContents[Wrapper]. Used by our NonClientView's // TabIconView::TabContentsProvider implementations. // TODO(beng): exposing this here is a bit bogus, since it's only used to // determine loading state. It'd be nicer if we could change this to be // bool IsSelectedTabLoading() const; or something like that. We could even // move it to a WindowDelegate subclass. TabContents* GetSelectedTabContents() const; + TabContentsWrapper* GetSelectedTabContentsWrapper() const; // Retrieves the icon to use in the frame to indicate an OTR window. SkBitmap GetOTRAvatarIcon(); @@ -263,7 +264,8 @@ class BrowserView : public BrowserBubbleHost, virtual LocationBar* GetLocationBar() const; virtual void SetFocusToLocationBar(bool select_all); virtual void UpdateReloadStopState(bool is_loading, bool force); - virtual void UpdateToolbar(TabContents* contents, bool should_restore_state); + virtual void UpdateToolbar(TabContentsWrapper* contents, + bool should_restore_state); virtual void FocusToolbar(); virtual void FocusAppMenu(); virtual void FocusBookmarksToolbar(); @@ -337,14 +339,14 @@ class BrowserView : public BrowserBubbleHost, const NotificationDetails& details); // Overridden from TabStripModelObserver: - 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 TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index); virtual void TabStripEmpty(); @@ -442,28 +444,28 @@ class BrowserView : public BrowserBubbleHost, // true if the Bookmark Bar can be shown (i.e. it's supported for this // Browser type) and there should be a subsequent re-layout to show it. // |contents| can be NULL. - bool MaybeShowBookmarkBar(TabContents* contents); + bool MaybeShowBookmarkBar(TabContentsWrapper* contents); // Prepare to show an Info Bar for the specified TabContents. Returns true // if there is an Info Bar to show and one is supported for this Browser // type, and there should be a subsequent re-layout to show it. // |contents| can be NULL. - bool MaybeShowInfoBar(TabContents* contents); + bool MaybeShowInfoBar(TabContentsWrapper* contents); // Updates sidebar UI according to the current tab and sidebar state. void UpdateSidebar(); // Displays active sidebar linked to the |tab_contents| or hides sidebar UI, // if there's no such sidebar. - void UpdateSidebarForContents(TabContents* tab_contents); + void UpdateSidebarForContents(TabContentsWrapper* tab_contents); // Updated devtools window for given contents. - void UpdateDevToolsForContents(TabContents* tab_contents); + void UpdateDevToolsForContents(TabContentsWrapper* tab_contents); // Updates various optional child Views, e.g. Bookmarks Bar, Info Bar or the // Download Shelf in response to a change notification from the specified // |contents|. |contents| can be NULL. In this case, all optional UI will be // removed. - void UpdateUIForContents(TabContents* contents); + void UpdateUIForContents(TabContentsWrapper* contents); // Updates an optional child View, e.g. Bookmarks Bar, Info Bar, Download // Shelf. If |*old_view| differs from new_view, the old_view is removed and @@ -502,7 +504,8 @@ class BrowserView : public BrowserBubbleHost, // |change_tab_contents| is true, |new_contents| is added to the view // hierarchy, if |change_tab_contents| is false, it's assumed |new_contents| // has already been added to the view hierarchy. - void ProcessTabSelected(TabContents* new_contents, bool change_tab_contents); + void ProcessTabSelected(TabContentsWrapper* new_contents, + bool change_tab_contents); // Last focused view that issued a tab traversal. int last_focused_view_storage_id_; diff --git a/chrome/browser/ui/views/location_bar/click_handler.cc b/chrome/browser/ui/views/location_bar/click_handler.cc index e9c414c..92b2bb7 100644 --- a/chrome/browser/ui/views/location_bar/click_handler.cc +++ b/chrome/browser/ui/views/location_bar/click_handler.cc @@ -6,6 +6,7 @@ #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/views/location_bar/location_bar_view.h" #include "views/view.h" @@ -25,7 +26,7 @@ void ClickHandler::OnMouseReleased(const views::MouseEvent& event, if (location_bar_->location_entry()->IsEditingOrEmpty()) return; - TabContents* tab = location_bar_->GetTabContents(); + TabContents* tab = location_bar_->GetTabContentsWrapper()->tab_contents(); NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); if (!nav_entry) { NOTREACHED(); diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc index 2d5af65..2ddb4b0 100644 --- a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc +++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc @@ -9,6 +9,7 @@ #include "chrome/browser/content_setting_bubble_model.h" #include "chrome/browser/content_setting_image_model.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/views/content_setting_bubble_contents.h" #include "chrome/browser/views/location_bar/location_bar_view.h" @@ -56,7 +57,7 @@ void ContentSettingImageView::OnMouseReleased(const views::MouseEvent& event, if (canceled || !HitTest(event.location())) return; - TabContents* tab_contents = parent_->GetTabContents(); + TabContents* tab_contents = parent_->GetTabContentsWrapper()->tab_contents(); if (!tab_contents) return; diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index d7a8920..59c191d 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -25,6 +25,7 @@ #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/browser_dialogs.h" @@ -50,6 +51,13 @@ using views::View; +namespace { +TabContents* GetTabContentsFromDelegate(LocationBarView::Delegate* delegate) { + const TabContentsWrapper* wrapper = delegate->GetTabContentsWrapper(); + return wrapper ? wrapper->tab_contents() : NULL; +} +} // namespace + // static const int LocationBarView::kNormalHorizontalEdgeThickness = 1; const int LocationBarView::kVerticalEdgeThickness = 2; @@ -335,8 +343,8 @@ void LocationBarView::SetProfile(Profile* profile) { } } -TabContents* LocationBarView::GetTabContents() const { - return delegate_->GetTabContents(); +TabContentsWrapper* LocationBarView::GetTabContentsWrapper() const { + return delegate_->GetTabContentsWrapper(); } void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, @@ -345,7 +353,7 @@ void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, return; DCHECK(page_action); - TabContents* contents = delegate_->GetTabContents(); + TabContents* contents = GetTabContentsFromDelegate(delegate_); RefreshPageActionViews(); PageActionWithBadgeView* page_action_view = @@ -839,10 +847,10 @@ void LocationBarView::OnChanged() { InstantController* instant = delegate_->GetInstant(); string16 suggested_text; - if (update_instant_ && instant && GetTabContents()) { + if (update_instant_ && instant && GetTabContentsWrapper()) { if (location_entry_->model()->user_input_in_progress() && location_entry_->model()->popup_model()->IsOpen()) { - instant->Update(GetTabContents(), + instant->Update(GetTabContentsWrapper(), location_entry_->model()->CurrentMatch(), WideToUTF16(location_entry_->GetText()), &suggested_text); @@ -876,15 +884,11 @@ void LocationBarView::OnSetFocus() { } SkBitmap LocationBarView::GetFavIcon() const { - DCHECK(delegate_); - DCHECK(delegate_->GetTabContents()); - return delegate_->GetTabContents()->GetFavIcon(); + return GetTabContentsFromDelegate(delegate_)->GetFavIcon(); } std::wstring LocationBarView::GetTitle() const { - DCHECK(delegate_); - DCHECK(delegate_->GetTabContents()); - return UTF16ToWideHack(delegate_->GetTabContents()->GetTitle()); + return UTF16ToWideHack(GetTabContentsFromDelegate(delegate_)->GetTitle()); } int LocationBarView::AvailableWidth(int location_bar_width) { @@ -911,11 +915,10 @@ void LocationBarView::LayoutView(views::View* view, } void LocationBarView::RefreshContentSettingViews() { - const TabContents* tab_contents = delegate_->GetTabContents(); for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); i != content_setting_views_.end(); ++i) { (*i)->UpdateFromTabContents( - model_->input_in_progress() ? NULL : tab_contents); + model_->input_in_progress() ? NULL : GetTabContentsFromDelegate(delegate_)); } } @@ -964,7 +967,7 @@ void LocationBarView::RefreshPageActionViews() { } } - TabContents* contents = delegate_->GetTabContents(); + TabContents* contents = GetTabContentsFromDelegate(delegate_); if (!page_action_views_.empty() && contents) { GURL url = GURL(WideToUTF8(model_->GetText())); @@ -1067,7 +1070,7 @@ void LocationBarView::WriteDragData(views::View* sender, OSExchangeData* data) { DCHECK(GetDragOperations(sender, press_pt) != DragDropTypes::DRAG_NONE); - TabContents* tab_contents = delegate_->GetTabContents(); + TabContents* tab_contents = GetTabContentsFromDelegate(delegate_); DCHECK(tab_contents); drag_utils::SetURLAndDragImage(tab_contents->GetURL(), UTF16ToWideHack(tab_contents->GetTitle()), @@ -1077,7 +1080,7 @@ void LocationBarView::WriteDragData(views::View* sender, int LocationBarView::GetDragOperations(views::View* sender, const gfx::Point& p) { DCHECK((sender == location_icon_view_) || (sender == ev_bubble_view_)); - TabContents* tab_contents = delegate_->GetTabContents(); + TabContents* tab_contents = GetTabContentsFromDelegate(delegate_); return (tab_contents && tab_contents->GetURL().is_valid() && !location_entry()->IsEditingOrEmpty()) ? (DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK) : diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index 563d0f9..7f0f0a8 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -44,6 +44,7 @@ class Profile; class SelectedKeywordView; class StarView; class SuggestedTextView; +class TabContentsWrapper; class TemplateURLModel; namespace views { @@ -72,7 +73,7 @@ class LocationBarView : public LocationBar, class Delegate { public: // Should return the current tab contents. - virtual TabContents* GetTabContents() = 0; + virtual TabContentsWrapper* GetTabContentsWrapper() = 0; // Returns the InstantController, or NULL if there isn't one. virtual InstantController* GetInstant() = 0; @@ -129,8 +130,8 @@ class LocationBarView : public LocationBar, void SetProfile(Profile* profile); Profile* profile() const { return profile_; } - // Returns the current TabContents. - TabContents* GetTabContents() const; + // Returns the current TabContentsWrapper. + TabContentsWrapper* GetTabContentsWrapper() const; // Sets |preview_enabled| for the PageAction View associated with this // |page_action|. If |preview_enabled| is true, the view will display the diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc index d77ff6f..0ecfacf 100644 --- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc +++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc @@ -10,6 +10,7 @@ #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/browser/tab_menu_model.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser.h" @@ -199,7 +200,7 @@ bool BrowserTabStripController::IsTabCloseable(int model_index) const { bool BrowserTabStripController::IsNewTabPage(int model_index) const { return model_->ContainsIndex(model_index) && - model_->GetTabContentsAt(model_index)->GetURL() == + model_->GetTabContentsAt(model_index)->tab_contents()->GetURL() == GURL(chrome::kChromeUINewTabURL); } @@ -229,8 +230,9 @@ void BrowserTabStripController::UpdateLoadingAnimations() { BaseTab* tab = tabstrip_->base_tab_at_tab_index(tab_index); int model_index = tabstrip_->GetModelIndexOfBaseTab(tab); if (model_->ContainsIndex(model_index)) { - TabContents* contents = model_->GetTabContentsAt(model_index); - tab->UpdateLoadingAnimation(TabContentsNetworkState(contents)); + TabContentsWrapper* contents = model_->GetTabContentsAt(model_index); + tab->UpdateLoadingAnimation( + TabContentsNetworkState(contents->tab_contents())); } } } @@ -247,7 +249,7 @@ void BrowserTabStripController::PerformDrop(bool drop_before, model_->profile()); // Insert a new tab. - TabContents* contents = model_->delegate()->CreateTabContentsForURL( + TabContentsWrapper* contents = model_->delegate()->CreateTabContentsForURL( url, GURL(), model_->profile(), PageTransition::TYPED, false, NULL); model_->AddTabContents(contents, index, PageTransition::GENERATED, TabStripModel::ADD_SELECTED); @@ -277,7 +279,7 @@ void BrowserTabStripController::CreateNewTab() { //////////////////////////////////////////////////////////////////////////////// // BrowserTabStripController, TabStripModelObserver implementation: -void BrowserTabStripController::TabInsertedAt(TabContents* contents, +void BrowserTabStripController::TabInsertedAt(TabContentsWrapper* contents, int model_index, bool foreground) { DCHECK(contents); @@ -289,35 +291,35 @@ void BrowserTabStripController::TabInsertedAt(TabContents* contents, contents->controller().window_id().id()); TabRendererData data; - SetTabRendererDataFromModel(contents, model_index, &data); + SetTabRendererDataFromModel(contents->tab_contents(), model_index, &data); tabstrip_->AddTabAt(model_index, foreground, data); } -void BrowserTabStripController::TabDetachedAt(TabContents* contents, +void BrowserTabStripController::TabDetachedAt(TabContentsWrapper* contents, int model_index) { tabstrip_->RemoveTabAt(model_index); } -void BrowserTabStripController::TabSelectedAt(TabContents* old_contents, - TabContents* contents, +void BrowserTabStripController::TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* contents, int model_index, bool user_gesture) { tabstrip_->SelectTabAt(model_->GetIndexOfTabContents(old_contents), model_index); } -void BrowserTabStripController::TabMoved(TabContents* contents, +void BrowserTabStripController::TabMoved(TabContentsWrapper* contents, int from_model_index, int to_model_index) { // Update the data first as the pinned state may have changed. TabRendererData data; - SetTabRendererDataFromModel(contents, to_model_index, &data); + SetTabRendererDataFromModel(contents->tab_contents(), to_model_index, &data); tabstrip_->SetTabData(from_model_index, data); tabstrip_->MoveTab(from_model_index, to_model_index); } -void BrowserTabStripController::TabChangedAt(TabContents* contents, +void BrowserTabStripController::TabChangedAt(TabContentsWrapper* contents, int model_index, TabChangeType change_type) { if (change_type == TITLE_NOT_LOADING) { @@ -329,32 +331,35 @@ void BrowserTabStripController::TabChangedAt(TabContents* contents, SetTabDataAt(contents, model_index); } -void BrowserTabStripController::TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, +void BrowserTabStripController::TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int model_index) { SetTabDataAt(new_contents, model_index); } -void BrowserTabStripController::TabPinnedStateChanged(TabContents* contents, - int model_index) { +void BrowserTabStripController::TabPinnedStateChanged( + TabContentsWrapper* contents, + int model_index) { // Currently none of the renderers render pinned state differently. } void BrowserTabStripController::TabMiniStateChanged( - TabContents* contents, + TabContentsWrapper* contents, int model_index) { SetTabDataAt(contents, model_index); } -void BrowserTabStripController::TabBlockedStateChanged(TabContents* contents, - int model_index) { +void BrowserTabStripController::TabBlockedStateChanged( + TabContentsWrapper* contents, + int model_index) { SetTabDataAt(contents, model_index); } -void BrowserTabStripController::SetTabDataAt(TabContents* contents, - int model_index) { +void BrowserTabStripController::SetTabDataAt( + TabContentsWrapper* contents, + int model_index) { TabRendererData data; - SetTabRendererDataFromModel(contents, model_index, &data); + SetTabRendererDataFromModel(contents->tab_contents(), model_index, &data); tabstrip_->SetTabData(model_index, data); } diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h index 8cfb548..5fd7e11 100644 --- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h +++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h @@ -19,7 +19,7 @@ class Browser; struct TabRendererData; // An implementation of TabStripController that sources data from the -// TabContentses in a TabStripModel. +// TabContentsWrappers in a TabStripModel. class BrowserTabStripController : public TabStripController, public TabStripModelObserver, public NotificationObserver { @@ -57,26 +57,29 @@ class BrowserTabStripController : public TabStripController, virtual void CreateNewTab(); // TabStripModelObserver implementation: - virtual void TabInsertedAt(TabContents* contents, + virtual void TabInsertedAt(TabContentsWrapper* contents, int model_index, bool foreground); - virtual void TabDetachedAt(TabContents* contents, int model_index); - virtual void TabSelectedAt(TabContents* old_contents, - TabContents* contents, + virtual void TabDetachedAt(TabContentsWrapper* contents, int model_index); + virtual void TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* contents, int model_index, bool user_gesture); - virtual void TabMoved(TabContents* contents, + virtual void TabMoved(TabContentsWrapper* contents, int from_model_index, int to_model_index); - virtual void TabChangedAt(TabContents* contents, + virtual void TabChangedAt(TabContentsWrapper* contents, int model_index, TabChangeType change_type); - virtual void TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, + virtual void TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int model_index); - virtual void TabPinnedStateChanged(TabContents* contents, int model_index); - virtual void TabMiniStateChanged(TabContents* contents, int model_index); - virtual void TabBlockedStateChanged(TabContents* contents, int model_index); + virtual void TabPinnedStateChanged(TabContentsWrapper* contents, + int model_index); + virtual void TabMiniStateChanged(TabContentsWrapper* contents, + int model_index); + virtual void TabBlockedStateChanged(TabContentsWrapper* contents, + int model_index); // NotificationObserver implementation: virtual void Observe(NotificationType type, const NotificationSource& source, @@ -86,7 +89,7 @@ class BrowserTabStripController : public TabStripController, class TabContextMenuContents; // Invokes tabstrip_->SetTabData. - void SetTabDataAt(TabContents* contents, int model_index); + void SetTabDataAt(TabContentsWrapper* contents, int model_index); // Sets the TabRendererData from the TabStripModel. void SetTabRendererDataFromModel(TabContents* contents, diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc index 8a3b173..691f99fa 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc @@ -475,7 +475,8 @@ void DraggedTabController::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); - DCHECK(Source<TabContents>(source).ptr() == dragged_contents_); + DCHECK(Source<TabContents>(source).ptr() == + dragged_contents_->tab_contents()); EndDragImpl(TAB_DESTROYED); } @@ -577,11 +578,12 @@ void DraggedTabController::UpdateDockInfo(const gfx::Point& screen_point) { } } -void DraggedTabController::SetDraggedContents(TabContents* new_contents) { +void DraggedTabController::SetDraggedContents( + TabContentsWrapper* new_contents) { if (dragged_contents_) { registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(dragged_contents_)); + Source<TabContents>(dragged_contents_->tab_contents())); if (original_delegate_) dragged_contents_->set_delegate(original_delegate_); } @@ -590,7 +592,7 @@ void DraggedTabController::SetDraggedContents(TabContents* new_contents) { if (dragged_contents_) { registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, - Source<TabContents>(dragged_contents_)); + Source<TabContents>(dragged_contents_->tab_contents())); // We need to be the delegate so we receive messages about stuff, // otherwise our dragged_contents() may be replaced and subsequently @@ -833,7 +835,7 @@ void DraggedTabController::Attach(BaseTabStrip* attached_tabstrip, original_delegate_ = NULL; // Return the TabContents' to normalcy. - dragged_contents_->set_capturing_contents(false); + dragged_contents_->tab_contents()->set_capturing_contents(false); // Inserting counts as a move. We don't want the tabs to jitter when the // user moves the tab immediately after attaching it. @@ -872,7 +874,7 @@ void DraggedTabController::Attach(BaseTabStrip* attached_tabstrip, void DraggedTabController::Detach() { // Prevent the TabContents' HWND from being hidden by any of the model // operations performed during the drag. - dragged_contents_->set_capturing_contents(true); + dragged_contents_->tab_contents()->set_capturing_contents(true); // Update the Model. TabRendererData tab_data = attached_tab_->data(); @@ -893,8 +895,8 @@ void DraggedTabController::Detach() { // Set up the photo booth to start capturing the contents of the dragged // TabContents. if (!photobooth_.get()) { - photobooth_.reset( - NativeViewPhotobooth::Create(dragged_contents_->GetNativeView())); + photobooth_.reset(NativeViewPhotobooth::Create( + dragged_contents_->tab_contents()->GetNativeView())); } // Create the dragged view. @@ -1228,7 +1230,7 @@ void DraggedTabController::CompleteDrag() { void DraggedTabController::EnsureDraggedView(const TabRendererData& data) { if (!view_.get()) { gfx::Rect tab_bounds; - dragged_contents_->GetContainerBounds(&tab_bounds); + dragged_contents_->tab_contents()->GetContainerBounds(&tab_bounds); BaseTab* renderer = source_tabstrip_->CreateTabForDragging(); renderer->SetData(data); // DraggedTabView takes ownership of renderer. diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.h b/chrome/browser/ui/views/tabs/dragged_tab_controller.h index d0c4480..2d00ac6 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_controller.h +++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.h @@ -11,6 +11,7 @@ #include "base/timer.h" #include "chrome/browser/dock_info.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "gfx/rect.h" @@ -67,7 +68,7 @@ class DraggedTabController : public TabContentsDelegate, // begun. void EndDrag(bool canceled); - TabContents* dragged_contents() { return dragged_contents_; } + TabContentsWrapper* dragged_contents() { return dragged_contents_; } // Returns true if a drag started. bool started_drag() const { return started_drag_; } @@ -141,7 +142,7 @@ class DraggedTabController : public TabContentsDelegate, void UpdateDockInfo(const gfx::Point& screen_point); // Sets the TabContents being dragged with the specified |new_contents|. - void SetDraggedContents(TabContents* new_contents); + void SetDraggedContents(TabContentsWrapper* new_contents); // Saves focus in the window that the drag initiated from. Focus will be // restored appropriately if the drag ends within this same window. @@ -241,8 +242,8 @@ class DraggedTabController : public TabContentsDelegate, // Handles registering for notifications. NotificationRegistrar registrar_; - // The TabContents being dragged. - TabContents* dragged_contents_; + // The TabContentsWrapper being dragged. + TabContentsWrapper* dragged_contents_; // The original TabContentsDelegate of |dragged_contents_|, before it was // detached from the browser window. We store this so that we can forward diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index 71f1387..34261fe 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -327,8 +327,8 @@ cleanup: //////////////////////////////////////////////////////////////////////////////// // ToolbarView, LocationBarView::Delegate implementation: -TabContents* ToolbarView::GetTabContents() { - return browser_->GetSelectedTabContents(); +TabContentsWrapper* ToolbarView::GetTabContentsWrapper() { + return browser_->GetSelectedTabContentsWrapper(); } InstantController* ToolbarView::GetInstant() { diff --git a/chrome/browser/ui/views/toolbar_view.h b/chrome/browser/ui/views/toolbar_view.h index ccae7fa2..bea00f3 100644 --- a/chrome/browser/ui/views/toolbar_view.h +++ b/chrome/browser/ui/views/toolbar_view.h @@ -96,7 +96,7 @@ class ToolbarView : public AccessiblePaneView, virtual void RunMenu(views::View* source, const gfx::Point& pt); // Overridden from LocationBarView::Delegate: - virtual TabContents* GetTabContents(); + virtual TabContentsWrapper* GetTabContentsWrapper(); virtual InstantController* GetInstant(); virtual void OnInputInProgress(bool in_progress); diff --git a/chrome/browser/wrench_menu_model.cc b/chrome/browser/wrench_menu_model.cc index 52bfe19..1e7258da 100644 --- a/chrome/browser/wrench_menu_model.cc +++ b/chrome/browser/wrench_menu_model.cc @@ -293,8 +293,8 @@ bool WrenchMenuModel::GetAcceleratorForCommandId( return provider_->GetAcceleratorForCommandId(command_id, accelerator); } -void WrenchMenuModel::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, +void WrenchMenuModel::TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index, bool user_gesture) { // The user has switched between tabs and the new tab may have a different @@ -302,8 +302,9 @@ void WrenchMenuModel::TabSelectedAt(TabContents* old_contents, UpdateZoomControls(); } -void WrenchMenuModel::TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, int index) { +void WrenchMenuModel::TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, + int index) { UpdateZoomControls(); } diff --git a/chrome/browser/wrench_menu_model.h b/chrome/browser/wrench_menu_model.h index c9ebe3c..39f67b1 100644 --- a/chrome/browser/wrench_menu_model.h +++ b/chrome/browser/wrench_menu_model.h @@ -93,12 +93,12 @@ class WrenchMenuModel : public menus::SimpleMenuModel, menus::Accelerator* accelerator); // 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); - virtual void TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, int index); + virtual void TabReplacedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, int index); virtual void TabStripModelDeleted(); // Overridden from NotificationObserver: diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 675fa77..ae9ad86 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2374,6 +2374,8 @@ 'browser/password_manager/password_store_win.h', 'browser/password_manager/password_store_x.cc', 'browser/password_manager/password_store_x.h', + 'browser/password_manager_delegate_impl.cc', + 'browser/password_manager_delegate_impl.h', 'browser/platform_util.h', 'browser/platform_util_linux.cc', 'browser/platform_util_chromeos.cc', @@ -2927,6 +2929,9 @@ 'browser/tab_contents/web_drag_utils_win.h', 'browser/tab_contents/web_drop_target_win.cc', 'browser/tab_contents/web_drop_target_win.h', + 'browser/tab_contents/web_navigation_observer.h', + 'browser/tab_contents_wrapper.cc', + 'browser/tab_contents_wrapper.h', 'browser/tab_menu_model.cc', 'browser/tab_menu_model.h', 'browser/tabs/default_tab_handler.cc', diff --git a/chrome/common/property_bag.h b/chrome/common/property_bag.h index d0d7c89..0a44892 100644 --- a/chrome/common/property_bag.h +++ b/chrome/common/property_bag.h @@ -36,11 +36,11 @@ class PropertyAccessorBase; // // void doit(SomeObjectThatImplementsPropertyBag* object) { // PropertyAccessor<int>* accessor = my_accessor(); -// int* property = accessor.GetProperty(object); +// int* property = accessor->GetProperty(object); // if (property) // ... use property ... // -// accessor.SetProperty(object, 22); +// accessor->SetProperty(object, 22); // } class PropertyBag { public: diff --git a/chrome/test/browser_with_test_window_test.cc b/chrome/test/browser_with_test_window_test.cc index fa61362..0871256 100644 --- a/chrome/test/browser_with_test_window_test.cc +++ b/chrome/test/browser_with_test_window_test.cc @@ -11,6 +11,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/ui/browser.h" #include "chrome/browser/ui/browser_navigator.h" diff --git a/chrome/test/live_sync/live_sessions_sync_test.h b/chrome/test/live_sync/live_sessions_sync_test.h index 48c9d63..b4a03c5 100644 --- a/chrome/test/live_sync/live_sessions_sync_test.h +++ b/chrome/test/live_sync/live_sessions_sync_test.h @@ -20,6 +20,7 @@ #include "chrome/browser/sessions/base_session_service.h" #include "chrome/browser/sessions/session_service_test_helper.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents_wrapper.h" #include "chrome/test/live_sync/live_sync_test.h" #include "chrome/test/ui_test_utils.h" #include "googleurl/src/gurl.h" @@ -194,7 +195,7 @@ class LiveSessionsSyncTest : public LiveSyncTest { // to ensure the tab opened successsfully. TabContents* OpenTab(int index, GURL url) WARN_UNUSED_RESULT { TabContents* tab = GetBrowser(index)-> - AddSelectedTabWithURL(url, PageTransition::START_PAGE); + AddSelectedTabWithURL(url, PageTransition::START_PAGE)->tab_contents(); // Wait for the page to finish loading. ui_test_utils::WaitForNavigation( diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h index 1ae5f26..71a15e4 100644 --- a/chrome/test/test_browser_window.h +++ b/chrome/test/test_browser_window.h @@ -45,7 +45,7 @@ class TestBrowserWindow : public BrowserWindow { } virtual void SetFocusToLocationBar(bool select_all) {} virtual void UpdateReloadStopState(bool is_loading, bool force) {} - virtual void UpdateToolbar(TabContents* contents, + virtual void UpdateToolbar(TabContentsWrapper* contents, bool should_restore_state) {} virtual void FocusToolbar() {} virtual void FocusAppMenu() {} |