| Index: chrome/browser/ui/browser.cc
|
| ===================================================================
|
| --- chrome/browser/ui/browser.cc (revision 66453)
|
| +++ chrome/browser/ui/browser.cc (working copy)
|
| @@ -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 = 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 @@
|
| 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 @@
|
| // 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 @@
|
| } 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 @@
|
| }
|
|
|
| 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,14 +899,27 @@
|
| 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) {
|
| tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture);
|
| }
|
| @@ -921,7 +936,7 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| 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 @@
|
| 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() {
|
| @@ -1110,7 +1127,7 @@
|
|
|
| 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(
|
| @@ -1118,7 +1135,7 @@
|
| disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED :
|
| TabStripModel::ADD_NONE);
|
| }
|
| - return current_tab;
|
| + return current_tab->tab_contents();
|
| }
|
|
|
| void Browser::UpdateTabStripModelInsertionPolicy() {
|
| @@ -1181,12 +1198,13 @@
|
| 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();
|
| }
|
| @@ -1194,7 +1212,7 @@
|
|
|
| void Browser::GoForward(WindowOpenDisposition disposition) {
|
| UserMetrics::RecordAction(UserMetricsAction("Forward"), profile_);
|
| - if (GetSelectedTabContents()->controller().CanGoForward())
|
| + if (GetSelectedTabContentsWrapper()->controller().CanGoForward())
|
| GetOrCloneTabForDisposition(disposition)->controller().GoForward();
|
| }
|
|
|
| @@ -1220,13 +1238,13 @@
|
| }
|
|
|
| // 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) {
|
| @@ -1256,7 +1274,7 @@
|
|
|
| void Browser::Stop() {
|
| UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_);
|
| - GetSelectedTabContents()->Stop();
|
| + GetSelectedTabContentsWrapper()->tab_contents()->Stop();
|
| }
|
|
|
| void Browser::NewWindow() {
|
| @@ -1296,7 +1314,7 @@
|
| // 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();
|
| }
|
| }
|
|
|
| @@ -1390,7 +1408,7 @@
|
| 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);
|
| @@ -1586,7 +1604,7 @@
|
|
|
| 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);
|
| }
|
|
|
| @@ -1657,9 +1675,10 @@
|
| 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)
|
| @@ -1691,7 +1710,7 @@
|
| }
|
| UserMetrics::RecordAction(UserMetricsAction(uma_string.c_str()), profile_);
|
| DevToolsManager::GetInstance()->ToggleDevToolsWindow(
|
| - GetSelectedTabContents()->render_view_host(), action);
|
| + GetSelectedTabContentsWrapper()->render_view_host(), action);
|
| }
|
|
|
| void Browser::OpenTaskManager() {
|
| @@ -1765,8 +1784,8 @@
|
| // See if there is already an options tab open that we can use.
|
| TabStripModel* model = tab_handler_->GetTabStripModel();
|
| for (int i = 0; i < model->count(); i++) {
|
| - TabContents* tc = model->GetTabContentsAt(i);
|
| - const GURL& tab_url = tc->GetURL();
|
| + TabContentsWrapper* tc = model->GetTabContentsAt(i);
|
| + const GURL& tab_url = tc->tab_contents()->GetURL();
|
|
|
| if (tab_url.scheme() == url.scheme() && tab_url.host() == url.host()) {
|
| // We found an existing options tab, load the URL in this tab. (Note:
|
| @@ -2063,7 +2082,7 @@
|
| // 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";
|
| @@ -2268,12 +2287,12 @@
|
| 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,
|
| @@ -2290,10 +2309,10 @@
|
| // 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 {
|
| @@ -2353,11 +2372,11 @@
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // 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.
|
| @@ -2367,14 +2386,16 @@
|
| 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;
|
| @@ -2390,18 +2411,18 @@
|
| 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);
|
| }
|
| @@ -2411,14 +2432,13 @@
|
| 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.
|
| @@ -2434,7 +2454,7 @@
|
| }
|
|
|
| void Browser::DuplicateContentsAt(int index) {
|
| - TabContents* contents = GetTabContentsAt(index);
|
| + TabContentsWrapper* contents = GetTabContentsWrapperAt(index);
|
| TabContents* new_contents = NULL;
|
| DCHECK(contents);
|
| bool pinned = false;
|
| @@ -2442,13 +2462,14 @@
|
| 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;
|
| @@ -2472,9 +2493,7 @@
|
| 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()) {
|
| @@ -2495,7 +2514,7 @@
|
| #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() ||
|
| @@ -2510,8 +2529,8 @@
|
| }
|
| }
|
|
|
| -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 {
|
| @@ -2570,26 +2589,26 @@
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // 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,
|
| @@ -2597,24 +2616,24 @@
|
| 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);
|
| @@ -2627,7 +2646,7 @@
|
| 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();
|
| @@ -2643,7 +2662,7 @@
|
| }
|
|
|
| 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);
|
| }
|
|
|
| @@ -2658,7 +2677,7 @@
|
| }
|
| }
|
|
|
| -void Browser::TabMoved(TabContents* contents,
|
| +void Browser::TabMoved(TabContentsWrapper* contents,
|
| int from_index,
|
| int to_index) {
|
| DCHECK(from_index >= 0 && to_index >= 0);
|
| @@ -2666,8 +2685,8 @@
|
| 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,
|
| @@ -2691,7 +2710,7 @@
|
| }
|
| }
|
|
|
| -void Browser::TabPinnedStateChanged(TabContents* contents, int index) {
|
| +void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) {
|
| if (!profile()->HasSessionService())
|
| return;
|
| SessionService* session_service = profile()->GetSessionService();
|
| @@ -2725,7 +2744,9 @@
|
| 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;
|
| @@ -2772,16 +2793,19 @@
|
| }
|
| #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();
|
| }
|
|
|
| @@ -2794,7 +2818,8 @@
|
| 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(
|
| @@ -2827,7 +2852,7 @@
|
| 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;
|
| @@ -2846,7 +2871,7 @@
|
| }
|
|
|
| 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);
|
| }
|
| @@ -2910,7 +2935,7 @@
|
| }
|
|
|
| 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;
|
| @@ -2941,8 +2966,9 @@
|
|
|
| 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();
|
| @@ -3206,7 +3232,7 @@
|
| 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);
|
| @@ -3336,20 +3362,20 @@
|
| 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.
|
| @@ -3624,7 +3650,7 @@
|
| // 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,
|
| @@ -3738,7 +3764,7 @@
|
| // 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);
|
| }
|
|
|
| @@ -4006,7 +4032,7 @@
|
| 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
|
| @@ -4014,14 +4040,14 @@
|
| // 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);
|
| + 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()) {
|
| @@ -4029,7 +4055,7 @@
|
| }
|
|
|
| registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
|
| - Source<TabContents>(contents));
|
| + Source<TabContentsWrapper>(contents));
|
| }
|
|
|
| // static
|
| @@ -4069,6 +4095,21 @@
|
| 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;
|
| @@ -4079,7 +4120,7 @@
|
| }
|
| 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(
|
| @@ -4088,7 +4129,7 @@
|
| 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
|
|
|