Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1154)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 9297043: Cleanup: Use TabStripModel pass-thrus in more places, use to be removed tabstrip_model() accessor i… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 int Browser::active_index() const { 1185 int Browser::active_index() const {
1186 return tab_handler_->GetTabStripModel()->active_index(); 1186 return tab_handler_->GetTabStripModel()->active_index();
1187 } 1187 }
1188 1188
1189 int Browser::GetIndexOfController( 1189 int Browser::GetIndexOfController(
1190 const NavigationController* controller) const { 1190 const NavigationController* controller) const {
1191 return tab_handler_->GetTabStripModel()->GetIndexOfController(controller); 1191 return tab_handler_->GetTabStripModel()->GetIndexOfController(controller);
1192 } 1192 }
1193 1193
1194 TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { 1194 TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const {
1195 return tabstrip_model()->GetActiveTabContents(); 1195 return tab_handler_->GetTabStripModel()->GetActiveTabContents();
1196 } 1196 }
1197 1197
1198 WebContents* Browser::GetSelectedWebContents() const { 1198 WebContents* Browser::GetSelectedWebContents() const {
1199 TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); 1199 TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper();
1200 return wrapper ? wrapper->web_contents() : NULL; 1200 return wrapper ? wrapper->web_contents() : NULL;
1201 } 1201 }
1202 1202
1203 TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const { 1203 TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const {
1204 return tabstrip_model()->GetTabContentsAt(index); 1204 return tab_handler_->GetTabStripModel()->GetTabContentsAt(index);
1205 } 1205 }
1206 1206
1207 WebContents* Browser::GetWebContentsAt(int index) const { 1207 WebContents* Browser::GetWebContentsAt(int index) const {
1208 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); 1208 TabContentsWrapper* wrapper = GetTabContentsWrapperAt(index);
1209 if (wrapper) 1209 if (wrapper)
1210 return wrapper->web_contents(); 1210 return wrapper->web_contents();
1211 return NULL; 1211 return NULL;
1212 } 1212 }
1213 1213
1214 void Browser::ActivateTabAt(int index, bool user_gesture) { 1214 void Browser::ActivateTabAt(int index, bool user_gesture) {
1215 tab_handler_->GetTabStripModel()->ActivateTabAt(index, user_gesture); 1215 tab_handler_->GetTabStripModel()->ActivateTabAt(index, user_gesture);
1216 } 1216 }
1217 1217
1218 bool Browser::IsTabPinned(int index) const { 1218 bool Browser::IsTabPinned(int index) const {
1219 return tabstrip_model()->IsTabPinned(index); 1219 return tab_handler_->GetTabStripModel()->IsTabPinned(index);
1220 } 1220 }
1221 1221
1222 bool Browser::IsTabDiscarded(int index) const { 1222 bool Browser::IsTabDiscarded(int index) const {
1223 return tab_handler_->GetTabStripModel()->IsTabDiscarded(index); 1223 return tab_handler_->GetTabStripModel()->IsTabDiscarded(index);
1224 } 1224 }
1225 1225
1226 void Browser::CloseAllTabs() { 1226 void Browser::CloseAllTabs() {
1227 tab_handler_->GetTabStripModel()->CloseAllTabs(); 1227 tab_handler_->GetTabStripModel()->CloseAllTabs();
1228 } 1228 }
1229 1229
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 std::vector<NavigationEntry*> entries; 1320 std::vector<NavigationEntry*> entries;
1321 TabNavigation::CreateNavigationEntriesFromTabNavigations( 1321 TabNavigation::CreateNavigationEntriesFromTabNavigations(
1322 profile_, navigations, &entries); 1322 profile_, navigations, &entries);
1323 new_tab->GetController().Restore( 1323 new_tab->GetController().Restore(
1324 selected_navigation, from_last_session, &entries); 1324 selected_navigation, from_last_session, &entries);
1325 DCHECK_EQ(0u, entries.size()); 1325 DCHECK_EQ(0u, entries.size());
1326 1326
1327 int add_types = select ? TabStripModel::ADD_ACTIVE : 1327 int add_types = select ? TabStripModel::ADD_ACTIVE :
1328 TabStripModel::ADD_NONE; 1328 TabStripModel::ADD_NONE;
1329 if (pin) { 1329 if (pin) {
1330 tab_index = std::min(tab_index, tabstrip_model()->IndexOfFirstNonMiniTab()); 1330 int first_mini_tab_idx =
1331 tab_handler_->GetTabStripModel()->IndexOfFirstNonMiniTab();
1332 tab_index = std::min(tab_index, first_mini_tab_idx);
1331 add_types |= TabStripModel::ADD_PINNED; 1333 add_types |= TabStripModel::ADD_PINNED;
1332 } 1334 }
1333 tab_handler_->GetTabStripModel()->InsertTabContentsAt(tab_index, wrapper, 1335 tab_handler_->GetTabStripModel()->InsertTabContentsAt(tab_index, wrapper,
1334 add_types); 1336 add_types);
1335 if (select) { 1337 if (select) {
1336 window_->Activate(); 1338 window_->Activate();
1337 } else { 1339 } else {
1338 // We set the size of the view here, before WebKit does its initial 1340 // We set the size of the view here, before WebKit does its initial
1339 // layout. If we don't, the initial layout of background tabs will be 1341 // layout. If we don't, the initial layout of background tabs will be
1340 // performed with a view width of 0, which may cause script outputs and 1342 // performed with a view width of 0, which may cause script outputs and
(...skipping 27 matching lines...) Expand all
1368 wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); 1370 wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id);
1369 WebContents* replacement = wrapper->web_contents(); 1371 WebContents* replacement = wrapper->web_contents();
1370 std::vector<NavigationEntry*> entries; 1372 std::vector<NavigationEntry*> entries;
1371 TabNavigation::CreateNavigationEntriesFromTabNavigations( 1373 TabNavigation::CreateNavigationEntriesFromTabNavigations(
1372 profile_, navigations, &entries); 1374 profile_, navigations, &entries);
1373 replacement->GetController().Restore( 1375 replacement->GetController().Restore(
1374 selected_navigation, from_last_session, &entries); 1376 selected_navigation, from_last_session, &entries);
1375 DCHECK_EQ(0u, entries.size()); 1377 DCHECK_EQ(0u, entries.size());
1376 1378
1377 tab_handler_->GetTabStripModel()->ReplaceNavigationControllerAt( 1379 tab_handler_->GetTabStripModel()->ReplaceNavigationControllerAt(
1378 tab_handler_->GetTabStripModel()->active_index(), 1380 active_index(), wrapper);
1379 wrapper);
1380 } 1381 }
1381 1382
1382 bool Browser::CanRestoreTab() { 1383 bool Browser::CanRestoreTab() {
1383 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); 1384 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB);
1384 } 1385 }
1385 1386
1386 bool Browser::NavigateToIndexWithDisposition(int index, 1387 bool Browser::NavigateToIndexWithDisposition(int index,
1387 WindowOpenDisposition disp) { 1388 WindowOpenDisposition disp) {
1388 NavigationController& controller = 1389 NavigationController& controller =
1389 GetOrCloneTabForDisposition(disp)->GetController(); 1390 GetOrCloneTabForDisposition(disp)->GetController();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 DCHECK(profile_->GetExtensionService()); 1628 DCHECK(profile_->GetExtensionService());
1628 if (profile_->GetExtensionService()->IsInstalledApp(url)) { 1629 if (profile_->GetExtensionService()->IsInstalledApp(url)) {
1629 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, 1630 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram,
1630 extension_misc::APP_LAUNCH_OMNIBOX_LOCATION, 1631 extension_misc::APP_LAUNCH_OMNIBOX_LOCATION,
1631 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); 1632 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
1632 } 1633 }
1633 } 1634 }
1634 1635
1635 void Browser::Stop() { 1636 void Browser::Stop() {
1636 content::RecordAction(UserMetricsAction("Stop")); 1637 content::RecordAction(UserMetricsAction("Stop"));
1637 GetSelectedTabContentsWrapper()->web_contents()->Stop(); 1638 GetSelectedWebContents()->Stop();
1638 } 1639 }
1639 1640
1640 void Browser::NewWindow() { 1641 void Browser::NewWindow() {
1641 if (browser_defaults::kAlwaysOpenIncognitoWindow && 1642 if (browser_defaults::kAlwaysOpenIncognitoWindow &&
1642 IncognitoModePrefs::ShouldLaunchIncognito( 1643 IncognitoModePrefs::ShouldLaunchIncognito(
1643 *CommandLine::ForCurrentProcess(), profile_->GetPrefs())) { 1644 *CommandLine::ForCurrentProcess(), profile_->GetPrefs())) {
1644 NewIncognitoWindow(); 1645 NewIncognitoWindow();
1645 return; 1646 return;
1646 } 1647 }
1647 content::RecordAction(UserMetricsAction("NewWindow")); 1648 content::RecordAction(UserMetricsAction("NewWindow"));
(...skipping 19 matching lines...) Expand all
1667 void Browser::CloseWindow() { 1668 void Browser::CloseWindow() {
1668 content::RecordAction(UserMetricsAction("CloseWindow")); 1669 content::RecordAction(UserMetricsAction("CloseWindow"));
1669 window_->Close(); 1670 window_->Close();
1670 } 1671 }
1671 1672
1672 void Browser::NewTab() { 1673 void Browser::NewTab() {
1673 content::RecordAction(UserMetricsAction("NewTab")); 1674 content::RecordAction(UserMetricsAction("NewTab"));
1674 1675
1675 if (is_type_tabbed()) { 1676 if (is_type_tabbed()) {
1676 AddBlankTab(true); 1677 AddBlankTab(true);
1677 GetSelectedTabContentsWrapper()->web_contents()->GetView()->RestoreFocus(); 1678 GetSelectedWebContents()->GetView()->RestoreFocus();
1678 } else { 1679 } else {
1679 Browser* b = GetOrCreateTabbedBrowser(profile_); 1680 Browser* b = GetOrCreateTabbedBrowser(profile_);
1680 b->AddBlankTab(true); 1681 b->AddBlankTab(true);
1681 b->window()->Show(); 1682 b->window()->Show();
1682 // The call to AddBlankTab above did not set the focus to the tab as its 1683 // The call to AddBlankTab above did not set the focus to the tab as its
1683 // window was not active, so we have to do it explicitly. 1684 // window was not active, so we have to do it explicitly.
1684 // See http://crbug.com/6380. 1685 // See http://crbug.com/6380.
1685 b->GetSelectedTabContentsWrapper()->web_contents()->GetView()-> 1686 b->GetSelectedWebContents()->GetView()->RestoreFocus();
1686 RestoreFocus();
1687 } 1687 }
1688 } 1688 }
1689 1689
1690 void Browser::CloseTab() { 1690 void Browser::CloseTab() {
1691 content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); 1691 content::RecordAction(UserMetricsAction("CloseTab_Accelerator"));
1692 if (CanCloseTab()) 1692 if (CanCloseTab())
1693 tab_handler_->GetTabStripModel()->CloseSelectedTabs(); 1693 tab_handler_->GetTabStripModel()->CloseSelectedTabs();
1694 } 1694 }
1695 1695
1696 void Browser::SelectNextTab() { 1696 void Browser::SelectNextTab() {
(...skipping 26 matching lines...) Expand all
1723 } 1723 }
1724 1724
1725 void Browser::MoveTabPrevious() { 1725 void Browser::MoveTabPrevious() {
1726 content::RecordAction(UserMetricsAction("MoveTabPrevious")); 1726 content::RecordAction(UserMetricsAction("MoveTabPrevious"));
1727 tab_handler_->GetTabStripModel()->MoveTabPrevious(); 1727 tab_handler_->GetTabStripModel()->MoveTabPrevious();
1728 } 1728 }
1729 1729
1730 void Browser::SelectNumberedTab(int index) { 1730 void Browser::SelectNumberedTab(int index) {
1731 if (index < tab_count()) { 1731 if (index < tab_count()) {
1732 content::RecordAction(UserMetricsAction("SelectNumberedTab")); 1732 content::RecordAction(UserMetricsAction("SelectNumberedTab"));
1733 tab_handler_->GetTabStripModel()->ActivateTabAt(index, true); 1733 ActivateTabAt(index, true);
1734 } 1734 }
1735 } 1735 }
1736 1736
1737 void Browser::SelectLastTab() { 1737 void Browser::SelectLastTab() {
1738 content::RecordAction(UserMetricsAction("SelectLastTab")); 1738 content::RecordAction(UserMetricsAction("SelectLastTab"));
1739 tab_handler_->GetTabStripModel()->SelectLastTab(); 1739 tab_handler_->GetTabStripModel()->SelectLastTab();
1740 } 1740 }
1741 1741
1742 void Browser::DuplicateTab() { 1742 void Browser::DuplicateTab() {
1743 content::RecordAction(UserMetricsAction("Duplicate")); 1743 content::RecordAction(UserMetricsAction("Duplicate"));
(...skipping 20 matching lines...) Expand all
1764 return; 1764 return;
1765 1765
1766 chrome_browser_net::WriteURLToClipboard( 1766 chrome_browser_net::WriteURLToClipboard(
1767 contents->GetURL(), 1767 contents->GetURL(),
1768 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1768 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1769 g_browser_process->clipboard()); 1769 g_browser_process->clipboard());
1770 } 1770 }
1771 1771
1772 void Browser::ConvertPopupToTabbedBrowser() { 1772 void Browser::ConvertPopupToTabbedBrowser() {
1773 content::RecordAction(UserMetricsAction("ShowAsTab")); 1773 content::RecordAction(UserMetricsAction("ShowAsTab"));
1774 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index();
1775 TabContentsWrapper* contents = 1774 TabContentsWrapper* contents =
1776 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); 1775 tab_handler_->GetTabStripModel()->DetachTabContentsAt(active_index());
1777 Browser* browser = Browser::Create(profile_); 1776 Browser* browser = Browser::Create(profile_);
1778 browser->tabstrip_model()->AppendTabContents(contents, true); 1777 browser->tabstrip_model()->AppendTabContents(contents, true);
1779 browser->window()->Show(); 1778 browser->window()->Show();
1780 } 1779 }
1781 1780
1782 // TODO(koz): Change |for_tab| to an enum. 1781 // TODO(koz): Change |for_tab| to an enum.
1783 void Browser::ToggleFullscreenMode(bool for_tab) { 1782 void Browser::ToggleFullscreenMode(bool for_tab) {
1784 fullscreen_controller_->ToggleFullscreenMode(for_tab); 1783 fullscreen_controller_->ToggleFullscreenMode(for_tab);
1785 } 1784 }
1786 1785
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 1959
1961 void Browser::FindPrevious() { 1960 void Browser::FindPrevious() {
1962 content::RecordAction(UserMetricsAction("FindPrevious")); 1961 content::RecordAction(UserMetricsAction("FindPrevious"));
1963 FindInPage(true, false); 1962 FindInPage(true, false);
1964 } 1963 }
1965 1964
1966 void Browser::Zoom(content::PageZoom zoom) { 1965 void Browser::Zoom(content::PageZoom zoom) {
1967 if (is_devtools()) 1966 if (is_devtools())
1968 return; 1967 return;
1969 1968
1970 RenderViewHost* host = 1969 RenderViewHost* host = GetSelectedWebContents()->GetRenderViewHost();
1971 GetSelectedTabContentsWrapper()->web_contents()->GetRenderViewHost();
1972 if (zoom == content::PAGE_ZOOM_RESET) { 1970 if (zoom == content::PAGE_ZOOM_RESET) {
1973 host->SetZoomLevel(0); 1971 host->SetZoomLevel(0);
1974 content::RecordAction(UserMetricsAction("ZoomNormal")); 1972 content::RecordAction(UserMetricsAction("ZoomNormal"));
1975 return; 1973 return;
1976 } 1974 }
1977 1975
1978 double current_zoom_level = GetSelectedWebContents()->GetZoomLevel(); 1976 double current_zoom_level = GetSelectedWebContents()->GetZoomLevel();
1979 double default_zoom_level = 1977 double default_zoom_level =
1980 profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); 1978 profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel);
1981 1979
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 #endif 2097 #endif
2100 } 2098 }
2101 2099
2102 void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) { 2100 void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) {
2103 if (action == DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE) 2101 if (action == DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE)
2104 content::RecordAction(UserMetricsAction("DevTools_ToggleConsole")); 2102 content::RecordAction(UserMetricsAction("DevTools_ToggleConsole"));
2105 else 2103 else
2106 content::RecordAction(UserMetricsAction("DevTools_ToggleWindow")); 2104 content::RecordAction(UserMetricsAction("DevTools_ToggleWindow"));
2107 2105
2108 DevToolsWindow::ToggleDevToolsWindow( 2106 DevToolsWindow::ToggleDevToolsWindow(
2109 GetSelectedTabContentsWrapper()->web_contents()->GetRenderViewHost(), 2107 GetSelectedWebContents()->GetRenderViewHost(),
2110 action); 2108 action);
2111 } 2109 }
2112 2110
2113 void Browser::OpenTaskManager(bool highlight_background_resources) { 2111 void Browser::OpenTaskManager(bool highlight_background_resources) {
2114 content::RecordAction(UserMetricsAction("TaskManager")); 2112 content::RecordAction(UserMetricsAction("TaskManager"));
2115 if (highlight_background_resources) 2113 if (highlight_background_resources)
2116 window_->ShowBackgroundPages(); 2114 window_->ShowBackgroundPages();
2117 else 2115 else
2118 window_->ShowTaskManager(); 2116 window_->ShowTaskManager();
2119 } 2117 }
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 return true; 2603 return true;
2606 } 2604 }
2607 return false; 2605 return false;
2608 } 2606 }
2609 2607
2610 // static 2608 // static
2611 Browser* Browser::GetBrowserForController( 2609 Browser* Browser::GetBrowserForController(
2612 const NavigationController* controller, int* index_result) { 2610 const NavigationController* controller, int* index_result) {
2613 BrowserList::const_iterator it; 2611 BrowserList::const_iterator it;
2614 for (it = BrowserList::begin(); it != BrowserList::end(); ++it) { 2612 for (it = BrowserList::begin(); it != BrowserList::end(); ++it) {
2615 int index = (*it)->tab_handler_->GetTabStripModel()->GetIndexOfController( 2613 int index = (*it)->GetIndexOfController(controller);
2616 controller);
2617 if (index != TabStripModel::kNoTab) { 2614 if (index != TabStripModel::kNoTab) {
2618 if (index_result) 2615 if (index_result)
2619 *index_result = index; 2616 *index_result = index;
2620 return *it; 2617 return *it;
2621 } 2618 }
2622 } 2619 }
2623 2620
2624 return NULL; 2621 return NULL;
2625 } 2622 }
2626 2623
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
3080 3077
3081 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { 3078 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) {
3082 if (disposition) 3079 if (disposition)
3083 *disposition = last_blocked_command_disposition_; 3080 *disposition = last_blocked_command_disposition_;
3084 return last_blocked_command_id_; 3081 return last_blocked_command_id_;
3085 } 3082 }
3086 3083
3087 void Browser::UpdateUIForNavigationInTab(TabContentsWrapper* contents, 3084 void Browser::UpdateUIForNavigationInTab(TabContentsWrapper* contents,
3088 content::PageTransition transition, 3085 content::PageTransition transition,
3089 bool user_initiated) { 3086 bool user_initiated) {
3090 tabstrip_model()->TabNavigating(contents, transition); 3087 tab_handler_->GetTabStripModel()->TabNavigating(contents, transition);
3091 3088
3092 bool contents_is_selected = contents == GetSelectedTabContentsWrapper(); 3089 bool contents_is_selected = contents == GetSelectedTabContentsWrapper();
3093 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { 3090 if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
3094 // Forcibly reset the location bar if the url is going to change in the 3091 // Forcibly reset the location bar if the url is going to change in the
3095 // current tab, since otherwise it won't discard any ongoing user edits, 3092 // current tab, since otherwise it won't discard any ongoing user edits,
3096 // since it doesn't realize this is a user-initiated action. 3093 // since it doesn't realize this is a user-initiated action.
3097 window()->GetLocationBar()->Revert(); 3094 window()->GetLocationBar()->Revert();
3098 } 3095 }
3099 3096
3100 if (GetStatusBubble()) 3097 if (GetStatusBubble())
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
3214 TabContentsWrapper* contents = GetTabContentsWrapperAt(index); 3211 TabContentsWrapper* contents = GetTabContentsWrapperAt(index);
3215 CHECK(contents); 3212 CHECK(contents);
3216 TabContentsWrapper* contents_dupe = contents->Clone(); 3213 TabContentsWrapper* contents_dupe = contents->Clone();
3217 3214
3218 bool pinned = false; 3215 bool pinned = false;
3219 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 3216 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
3220 // If this is a tabbed browser, just create a duplicate tab inside the same 3217 // If this is a tabbed browser, just create a duplicate tab inside the same
3221 // window next to the tab being duplicated. 3218 // window next to the tab being duplicated.
3222 int index = tab_handler_->GetTabStripModel()-> 3219 int index = tab_handler_->GetTabStripModel()->
3223 GetIndexOfTabContents(contents); 3220 GetIndexOfTabContents(contents);
3224 pinned = tab_handler_->GetTabStripModel()->IsTabPinned(index); 3221 pinned = IsTabPinned(index);
3225 int add_types = TabStripModel::ADD_ACTIVE | 3222 int add_types = TabStripModel::ADD_ACTIVE |
3226 TabStripModel::ADD_INHERIT_GROUP | 3223 TabStripModel::ADD_INHERIT_GROUP |
3227 (pinned ? TabStripModel::ADD_PINNED : 0); 3224 (pinned ? TabStripModel::ADD_PINNED : 0);
3228 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, 3225 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1,
3229 contents_dupe, 3226 contents_dupe,
3230 add_types); 3227 add_types);
3231 } else { 3228 } else {
3232 Browser* browser = NULL; 3229 Browser* browser = NULL;
3233 if (is_app()) { 3230 if (is_app()) {
3234 CHECK(!is_type_popup()); 3231 CHECK(!is_type_popup());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3303 TabCloseableStateWatcher* watcher = 3300 TabCloseableStateWatcher* watcher =
3304 g_browser_process->tab_closeable_state_watcher(); 3301 g_browser_process->tab_closeable_state_watcher();
3305 bool can_close_all = !watcher || watcher->CanCloseTabs(this, indices); 3302 bool can_close_all = !watcher || watcher->CanCloseTabs(this, indices);
3306 if (indices->empty()) // Cannot close any tab. 3303 if (indices->empty()) // Cannot close any tab.
3307 return false; 3304 return false;
3308 // Now, handle cases where at least one tab can be closed. 3305 // Now, handle cases where at least one tab can be closed.
3309 // If we are closing all the tabs for this browser, make sure to check for 3306 // If we are closing all the tabs for this browser, make sure to check for
3310 // in-progress downloads. 3307 // in-progress downloads.
3311 // Note that the next call when it returns false will ask the user for 3308 // Note that the next call when it returns false will ask the user for
3312 // confirmation before closing the browser if the user decides so. 3309 // confirmation before closing the browser if the user decides so.
3313 if (tab_handler_->GetTabStripModel()->count() == 3310 if (tab_count() == static_cast<int>(indices->size()) &&
3314 static_cast<int>(indices->size()) &&
3315 !CanCloseWithInProgressDownloads()) { 3311 !CanCloseWithInProgressDownloads()) {
3316 indices->clear(); 3312 indices->clear();
3317 can_close_all = false; 3313 can_close_all = false;
3318 } 3314 }
3319 return can_close_all; 3315 return can_close_all;
3320 } 3316 }
3321 3317
3322 bool Browser::CanBookmarkAllTabs() const { 3318 bool Browser::CanBookmarkAllTabs() const {
3323 BookmarkModel* model = profile()->GetBookmarkModel(); 3319 BookmarkModel* model = profile()->GetBookmarkModel();
3324 return (model && model->IsLoaded()) && 3320 return (model && model->IsLoaded()) &&
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3445 if (HasFindBarController()) { 3441 if (HasFindBarController()) {
3446 find_bar_controller_->ChangeTabContents(new_contents); 3442 find_bar_controller_->ChangeTabContents(new_contents);
3447 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); 3443 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
3448 } 3444 }
3449 3445
3450 // Update sessions. Don't force creation of sessions. If sessions doesn't 3446 // Update sessions. Don't force creation of sessions. If sessions doesn't
3451 // exist, the change will be picked up by sessions when created. 3447 // exist, the change will be picked up by sessions when created.
3452 SessionService* session_service = 3448 SessionService* session_service =
3453 SessionServiceFactory::GetForProfileIfExisting(profile_); 3449 SessionServiceFactory::GetForProfileIfExisting(profile_);
3454 if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) { 3450 if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) {
3455 session_service->SetSelectedTabInWindow( 3451 session_service->SetSelectedTabInWindow(session_id(), active_index());
3456 session_id(), tab_handler_->GetTabStripModel()->active_index());
3457 } 3452 }
3458 3453
3459 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); 3454 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH);
3460 } 3455 }
3461 3456
3462 void Browser::TabMoved(TabContentsWrapper* contents, 3457 void Browser::TabMoved(TabContentsWrapper* contents,
3463 int from_index, 3458 int from_index,
3464 int to_index) { 3459 int to_index) {
3465 DCHECK(from_index >= 0 && to_index >= 0); 3460 DCHECK(from_index >= 0 && to_index >= 0);
3466 // Notify the history service. 3461 // Notify the history service.
3467 SyncHistoryWithTabs(std::min(from_index, to_index)); 3462 SyncHistoryWithTabs(std::min(from_index, to_index));
3468 } 3463 }
3469 3464
3470 void Browser::TabReplacedAt(TabStripModel* tab_strip_model, 3465 void Browser::TabReplacedAt(TabStripModel* tab_strip_model,
3471 TabContentsWrapper* old_contents, 3466 TabContentsWrapper* old_contents,
3472 TabContentsWrapper* new_contents, 3467 TabContentsWrapper* new_contents,
3473 int index) { 3468 int index) {
3474 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); 3469 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE);
3475 TabInsertedAt(new_contents, index, 3470 TabInsertedAt(new_contents, index, (index == active_index()));
3476 (index == tab_handler_->GetTabStripModel()->active_index()));
3477 3471
3478 int entry_count = 3472 int entry_count =
3479 new_contents->web_contents()->GetController().GetEntryCount(); 3473 new_contents->web_contents()->GetController().GetEntryCount();
3480 if (entry_count > 0) { 3474 if (entry_count > 0) {
3481 // Send out notification so that observers are updated appropriately. 3475 // Send out notification so that observers are updated appropriately.
3482 new_contents->web_contents()->GetController().NotifyEntryChanged( 3476 new_contents->web_contents()->GetController().NotifyEntryChanged(
3483 new_contents->web_contents()->GetController().GetEntryAtIndex( 3477 new_contents->web_contents()->GetController().GetEntryAtIndex(
3484 entry_count - 1), 3478 entry_count - 1),
3485 entry_count - 1); 3479 entry_count - 1);
3486 } 3480 }
3487 3481
3488 SessionService* session_service = 3482 SessionService* session_service =
3489 SessionServiceFactory::GetForProfile(profile()); 3483 SessionServiceFactory::GetForProfile(profile());
3490 if (session_service) { 3484 if (session_service) {
3491 // The new_contents may end up with a different navigation stack. Force 3485 // The new_contents may end up with a different navigation stack. Force
3492 // the session service to update itself. 3486 // the session service to update itself.
3493 session_service->TabRestored( 3487 session_service->TabRestored(new_contents, IsTabPinned(index));
3494 new_contents, tab_handler_->GetTabStripModel()->IsTabPinned(index));
3495 } 3488 }
3496 3489
3497 content::DevToolsManager::GetInstance()->TabReplaced( 3490 content::DevToolsManager::GetInstance()->TabReplaced(
3498 old_contents->web_contents(), new_contents->web_contents()); 3491 old_contents->web_contents(), new_contents->web_contents());
3499 } 3492 }
3500 3493
3501 void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { 3494 void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) {
3502 SessionService* session_service = 3495 SessionService* session_service =
3503 SessionServiceFactory::GetForProfileIfExisting(profile()); 3496 SessionServiceFactory::GetForProfileIfExisting(profile());
3504 if (session_service) { 3497 if (session_service) {
3505 session_service->SetPinnedState( 3498 session_service->SetPinnedState(
3506 session_id(), 3499 session_id(),
3507 GetTabContentsWrapperAt(index)->restore_tab_helper()->session_id(), 3500 GetTabContentsWrapperAt(index)->restore_tab_helper()->session_id(),
3508 tab_handler_->GetTabStripModel()->IsTabPinned(index)); 3501 IsTabPinned(index));
3509 } 3502 }
3510 } 3503 }
3511 3504
3512 void Browser::TabStripEmpty() { 3505 void Browser::TabStripEmpty() {
3513 // Close the frame after we return to the message loop (not immediately, 3506 // Close the frame after we return to the message loop (not immediately,
3514 // otherwise it will destroy this object before the stack has a chance to 3507 // otherwise it will destroy this object before the stack has a chance to
3515 // cleanly unwind.) 3508 // cleanly unwind.)
3516 // Note: This will be called several times if TabStripEmpty is called several 3509 // Note: This will be called several times if TabStripEmpty is called several
3517 // times. This is because it does not close the window if tabs are 3510 // times. This is because it does not close the window if tabs are
3518 // still present. 3511 // still present.
3519 // NOTE: If you change to be immediate (no invokeLater) then you'll need to 3512 // NOTE: If you change to be immediate (no invokeLater) then you'll need to
3520 // update BrowserList::CloseAllBrowsers. 3513 // update BrowserList::CloseAllBrowsers.
3521 MessageLoop::current()->PostTask( 3514 MessageLoop::current()->PostTask(
3522 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); 3515 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr()));
3523 } 3516 }
3524 3517
3525 /////////////////////////////////////////////////////////////////////////////// 3518 ///////////////////////////////////////////////////////////////////////////////
3526 // Browser, content::WebContentsDelegate implementation: 3519 // Browser, content::WebContentsDelegate implementation:
3527 3520
3528 WebContents* Browser::OpenURLFromTab(WebContents* source, 3521 WebContents* Browser::OpenURLFromTab(WebContents* source,
3529 const OpenURLParams& params) { 3522 const OpenURLParams& params) {
3530 browser::NavigateParams nav_params(this, params.url, params.transition); 3523 browser::NavigateParams nav_params(this, params.url, params.transition);
3531 nav_params.source_contents = 3524 nav_params.source_contents = GetTabContentsWrapperAt(
3532 tabstrip_model()->GetTabContentsAt( 3525 tab_handler_->GetTabStripModel()->GetWrapperIndex(source));
3533 tabstrip_model()->GetWrapperIndex(source));
3534 nav_params.referrer = params.referrer; 3526 nav_params.referrer = params.referrer;
3535 nav_params.disposition = params.disposition; 3527 nav_params.disposition = params.disposition;
3536 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; 3528 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
3537 nav_params.window_action = browser::NavigateParams::SHOW_WINDOW; 3529 nav_params.window_action = browser::NavigateParams::SHOW_WINDOW;
3538 nav_params.user_gesture = true; 3530 nav_params.user_gesture = true;
3539 nav_params.override_encoding = params.override_encoding; 3531 nav_params.override_encoding = params.override_encoding;
3540 nav_params.is_renderer_initiated = params.is_renderer_initiated; 3532 nav_params.is_renderer_initiated = params.is_renderer_initiated;
3541 nav_params.transferred_global_request_id = 3533 nav_params.transferred_global_request_id =
3542 params.transferred_global_request_id; 3534 params.transferred_global_request_id;
3543 browser::Navigate(&nav_params); 3535 browser::Navigate(&nav_params);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3602 GetConstrainingContentsWrapper(source_wrapper)-> 3594 GetConstrainingContentsWrapper(source_wrapper)->
3603 blocked_content_tab_helper()-> 3595 blocked_content_tab_helper()->
3604 AddPopup(new_wrapper, initial_pos, user_gesture); 3596 AddPopup(new_wrapper, initial_pos, user_gesture);
3605 return; 3597 return;
3606 } 3598 }
3607 3599
3608 new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); 3600 new_contents->GetRenderViewHost()->DisassociateFromPopupCount();
3609 } 3601 }
3610 3602
3611 browser::NavigateParams params(this, new_wrapper); 3603 browser::NavigateParams params(this, new_wrapper);
3612 params.source_contents = 3604 params.source_contents = source ? GetTabContentsWrapperAt(
3613 source ? tabstrip_model()->GetTabContentsAt( 3605 tab_handler_->GetTabStripModel()->GetWrapperIndex(source))
3614 tabstrip_model()->GetWrapperIndex(source)) 3606 : NULL;
3615 : NULL;
3616 params.disposition = disposition; 3607 params.disposition = disposition;
3617 params.window_bounds = initial_pos; 3608 params.window_bounds = initial_pos;
3618 params.window_action = browser::NavigateParams::SHOW_WINDOW; 3609 params.window_action = browser::NavigateParams::SHOW_WINDOW;
3619 params.user_gesture = user_gesture; 3610 params.user_gesture = user_gesture;
3620 browser::Navigate(&params); 3611 browser::Navigate(&params);
3621 } 3612 }
3622 3613
3623 void Browser::ActivateContents(WebContents* contents) { 3614 void Browser::ActivateContents(WebContents* contents) {
3624 tab_handler_->GetTabStripModel()->ActivateTabAt( 3615 ActivateTabAt(tab_handler_->GetTabStripModel()->GetWrapperIndex(contents),
3625 tab_handler_->GetTabStripModel()->GetWrapperIndex(contents), false); 3616 false);
3626 window_->Activate(); 3617 window_->Activate();
3627 } 3618 }
3628 3619
3629 void Browser::DeactivateContents(WebContents* contents) { 3620 void Browser::DeactivateContents(WebContents* contents) {
3630 window_->Deactivate(); 3621 window_->Deactivate();
3631 } 3622 }
3632 3623
3633 void Browser::LoadingStateChanged(WebContents* source) { 3624 void Browser::LoadingStateChanged(WebContents* source) {
3634 window_->UpdateLoadingAnimations( 3625 window_->UpdateLoadingAnimations(
3635 tab_handler_->GetTabStripModel()->TabsAreLoading()); 3626 tab_handler_->GetTabStripModel()->TabsAreLoading());
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
3879 void Browser::ShowPageInfo(content::BrowserContext* browser_context, 3870 void Browser::ShowPageInfo(content::BrowserContext* browser_context,
3880 const GURL& url, 3871 const GURL& url,
3881 const SSLStatus& ssl, 3872 const SSLStatus& ssl,
3882 bool show_history) { 3873 bool show_history) {
3883 Profile* profile = Profile::FromBrowserContext(browser_context); 3874 Profile* profile = Profile::FromBrowserContext(browser_context);
3884 window()->ShowPageInfo(profile, url, ssl, show_history); 3875 window()->ShowPageInfo(profile, url, ssl, show_history);
3885 } 3876 }
3886 3877
3887 void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { 3878 void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) {
3888 DCHECK(source); 3879 DCHECK(source);
3889 int index = tabstrip_model()->GetWrapperIndex(source); 3880 TabContentsWrapper* wrapper = GetTabContentsWrapperAt(
3890 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); 3881 tab_handler_->GetTabStripModel()->GetWrapperIndex(source));
3891 ViewSource(wrapper); 3882 ViewSource(wrapper);
3892 } 3883 }
3893 3884
3894 void Browser::ViewSourceForFrame(WebContents* source, 3885 void Browser::ViewSourceForFrame(WebContents* source,
3895 const GURL& frame_url, 3886 const GURL& frame_url,
3896 const std::string& frame_content_state) { 3887 const std::string& frame_content_state) {
3897 DCHECK(source); 3888 DCHECK(source);
3898 int index = tabstrip_model()->GetWrapperIndex(source); 3889 TabContentsWrapper* wrapper = GetTabContentsWrapperAt(
3899 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); 3890 tab_handler_->GetTabStripModel()->GetWrapperIndex(source));
3900 ViewSource(wrapper, frame_url, frame_content_state); 3891 ViewSource(wrapper, frame_url, frame_content_state);
3901 } 3892 }
3902 3893
3903 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 3894 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
3904 bool* is_keyboard_shortcut) { 3895 bool* is_keyboard_shortcut) {
3905 // Escape exits tabbed fullscreen mode. 3896 // Escape exits tabbed fullscreen mode.
3906 // TODO(koz): Write a test for this http://crbug.com/100441. 3897 // TODO(koz): Write a test for this http://crbug.com/100441.
3907 if (event.windowsKeyCode == 27 && 3898 if (event.windowsKeyCode == 27 &&
3908 fullscreen_controller_->HandleUserPressedEscape()) { 3899 fullscreen_controller_->HandleUserPressedEscape()) {
3909 return true; 3900 return true;
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
4439 void Browser::SwapTabContents(TabContentsWrapper* old_tab_contents, 4430 void Browser::SwapTabContents(TabContentsWrapper* old_tab_contents,
4440 TabContentsWrapper* new_tab_contents) { 4431 TabContentsWrapper* new_tab_contents) {
4441 int index = 4432 int index =
4442 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(old_tab_contents); 4433 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(old_tab_contents);
4443 DCHECK_NE(TabStripModel::kNoTab, index); 4434 DCHECK_NE(TabStripModel::kNoTab, index);
4444 tab_handler_->GetTabStripModel()->ReplaceTabContentsAt(index, 4435 tab_handler_->GetTabStripModel()->ReplaceTabContentsAt(index,
4445 new_tab_contents); 4436 new_tab_contents);
4446 } 4437 }
4447 4438
4448 void Browser::SetTabContentBlocked(TabContentsWrapper* wrapper, bool blocked) { 4439 void Browser::SetTabContentBlocked(TabContentsWrapper* wrapper, bool blocked) {
4449 int index = tabstrip_model()->GetIndexOfTabContents(wrapper); 4440 int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents(wrapper);
4450 if (index == TabStripModel::kNoTab) { 4441 if (index == TabStripModel::kNoTab) {
4451 NOTREACHED(); 4442 NOTREACHED();
4452 return; 4443 return;
4453 } 4444 }
4454 tabstrip_model()->SetTabBlocked(index, blocked); 4445 tab_handler_->GetTabStripModel()->SetTabBlocked(index, blocked);
4455 UpdatePrintingState(wrapper->web_contents()->GetContentRestrictions()); 4446 UpdatePrintingState(wrapper->web_contents()->GetContentRestrictions());
4456 } 4447 }
4457 4448
4458 void Browser::SetSuggestedText(const string16& text, 4449 void Browser::SetSuggestedText(const string16& text,
4459 InstantCompleteBehavior behavior) { 4450 InstantCompleteBehavior behavior) {
4460 if (window()->GetLocationBar()) 4451 if (window()->GetLocationBar())
4461 window()->GetLocationBar()->SetSuggestedText(text, behavior); 4452 window()->GetLocationBar()->SetSuggestedText(text, behavior);
4462 } 4453 }
4463 4454
4464 gfx::Rect Browser::GetInstantBounds() { 4455 gfx::Rect Browser::GetInstantBounds() {
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
4905 // the navigation commands since those would have already been updated 4896 // the navigation commands since those would have already been updated
4906 // synchronously by NavigationStateChanged. 4897 // synchronously by NavigationStateChanged.
4907 UpdateToolbar(false); 4898 UpdateToolbar(false);
4908 changed_flags &= ~content::INVALIDATE_TYPE_URL; 4899 changed_flags &= ~content::INVALIDATE_TYPE_URL;
4909 } 4900 }
4910 if (changed_flags & content::INVALIDATE_TYPE_LOAD) { 4901 if (changed_flags & content::INVALIDATE_TYPE_LOAD) {
4911 // Update the loading state synchronously. This is so the throbber will 4902 // Update the loading state synchronously. This is so the throbber will
4912 // immediately start/stop, which gives a more snappy feel. We want to do 4903 // immediately start/stop, which gives a more snappy feel. We want to do
4913 // this for any tab so they start & stop quickly. 4904 // this for any tab so they start & stop quickly.
4914 tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( 4905 tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt(
4915 tab_handler_->GetTabStripModel()->GetIndexOfController( 4906 GetIndexOfController(&source->GetController()),
4916 &source->GetController()),
4917 TabStripModelObserver::LOADING_ONLY); 4907 TabStripModelObserver::LOADING_ONLY);
4918 // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too, 4908 // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too,
4919 // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from 4909 // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from
4920 // changed_flags. 4910 // changed_flags.
4921 } 4911 }
4922 4912
4923 if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) { 4913 if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) {
4924 // To correctly calculate whether the title changed while not loading 4914 // To correctly calculate whether the title changed while not loading
4925 // we need to process the update synchronously. This state only matters for 4915 // we need to process the update synchronously. This state only matters for
4926 // the TabStripModel, so we notify the TabStripModel now and notify others 4916 // the TabStripModel, so we notify the TabStripModel now and notify others
4927 // asynchronously. 4917 // asynchronously.
4928 tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt( 4918 tab_handler_->GetTabStripModel()->UpdateTabContentsStateAt(
4929 tab_handler_->GetTabStripModel()->GetIndexOfController( 4919 GetIndexOfController(&source->GetController()),
4930 &source->GetController()),
4931 TabStripModelObserver::TITLE_NOT_LOADING); 4920 TabStripModelObserver::TITLE_NOT_LOADING);
4932 } 4921 }
4933 4922
4934 // If the only updates were synchronously handled above, we're done. 4923 // If the only updates were synchronously handled above, we're done.
4935 if (changed_flags == 0) 4924 if (changed_flags == 0)
4936 return; 4925 return;
4937 4926
4938 // Save the dirty bits. 4927 // Save the dirty bits.
4939 scheduled_updates_[source] |= changed_flags; 4928 scheduled_updates_[source] |= changed_flags;
4940 4929
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
5045 SessionServiceFactory::GetForProfileIfExisting(profile()); 5034 SessionServiceFactory::GetForProfileIfExisting(profile());
5046 if (session_service) { 5035 if (session_service) {
5047 for (int i = index; i < tab_count(); ++i) { 5036 for (int i = index; i < tab_count(); ++i) {
5048 TabContentsWrapper* tab = GetTabContentsWrapperAt(i); 5037 TabContentsWrapper* tab = GetTabContentsWrapperAt(i);
5049 if (tab) { 5038 if (tab) {
5050 session_service->SetTabIndexInWindow( 5039 session_service->SetTabIndexInWindow(
5051 session_id(), tab->restore_tab_helper()->session_id(), i); 5040 session_id(), tab->restore_tab_helper()->session_id(), i);
5052 session_service->SetPinnedState( 5041 session_service->SetPinnedState(
5053 session_id(), 5042 session_id(),
5054 tab->restore_tab_helper()->session_id(), 5043 tab->restore_tab_helper()->session_id(),
5055 tab_handler_->GetTabStripModel()->IsTabPinned(i)); 5044 IsTabPinned(i));
5056 } 5045 }
5057 } 5046 }
5058 } 5047 }
5059 } 5048 }
5060 5049
5061 /////////////////////////////////////////////////////////////////////////////// 5050 ///////////////////////////////////////////////////////////////////////////////
5062 // Browser, OnBeforeUnload handling (private): 5051 // Browser, OnBeforeUnload handling (private):
5063 5052
5064 void Browser::ProcessPendingTabs() { 5053 void Browser::ProcessPendingTabs() {
5065 if (!is_attempting_to_close_browser_) { 5054 if (!is_attempting_to_close_browser_) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
5244 location_bar->SaveStateToContents(contents->web_contents()); 5233 location_bar->SaveStateToContents(contents->web_contents());
5245 } 5234 }
5246 5235
5247 if (!tab_handler_->GetTabStripModel()->closing_all()) 5236 if (!tab_handler_->GetTabStripModel()->closing_all())
5248 SyncHistoryWithTabs(0); 5237 SyncHistoryWithTabs(0);
5249 } 5238 }
5250 5239
5251 SetAsDelegate(contents, NULL); 5240 SetAsDelegate(contents, NULL);
5252 RemoveScheduledUpdatesFor(contents->web_contents()); 5241 RemoveScheduledUpdatesFor(contents->web_contents());
5253 5242
5254 if (find_bar_controller_.get() && 5243 if (find_bar_controller_.get() && index == active_index()) {
5255 index == tab_handler_->GetTabStripModel()->active_index()) {
5256 find_bar_controller_->ChangeTabContents(NULL); 5244 find_bar_controller_->ChangeTabContents(NULL);
5257 } 5245 }
5258 5246
5259 if (is_attempting_to_close_browser_) { 5247 if (is_attempting_to_close_browser_) {
5260 // If this is the last tab with unload handlers, then ProcessPendingTabs 5248 // If this is the last tab with unload handlers, then ProcessPendingTabs
5261 // would call back into the TabStripModel (which is invoking this method on 5249 // would call back into the TabStripModel (which is invoking this method on
5262 // us). Avoid that by passing in false so that the call to 5250 // us). Avoid that by passing in false so that the call to
5263 // ProcessPendingTabs is delayed. 5251 // ProcessPendingTabs is delayed.
5264 ClearUnloadState(contents->web_contents(), false); 5252 ClearUnloadState(contents->web_contents(), false);
5265 } 5253 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
5396 active_entry->SetContentState( 5384 active_entry->SetContentState(
5397 webkit_glue::RemoveScrollOffsetFromHistoryState(content_state)); 5385 webkit_glue::RemoveScrollOffsetFromHistoryState(content_state));
5398 5386
5399 // Do not restore title, derive it from the url. 5387 // Do not restore title, derive it from the url.
5400 active_entry->SetTitle(string16()); 5388 active_entry->SetTitle(string16());
5401 5389
5402 // Now show view-source entry. 5390 // Now show view-source entry.
5403 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 5391 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
5404 // If this is a tabbed browser, just create a duplicate tab inside the same 5392 // If this is a tabbed browser, just create a duplicate tab inside the same
5405 // window next to the tab being duplicated. 5393 // window next to the tab being duplicated.
5406 int index = tab_handler_->GetTabStripModel()-> 5394 int index =
5407 GetIndexOfTabContents(contents); 5395 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents);
5408 int add_types = TabStripModel::ADD_ACTIVE | 5396 int add_types = TabStripModel::ADD_ACTIVE |
5409 TabStripModel::ADD_INHERIT_GROUP; 5397 TabStripModel::ADD_INHERIT_GROUP;
5410 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1, 5398 tab_handler_->GetTabStripModel()->InsertTabContentsAt(index + 1,
5411 view_source_contents, 5399 view_source_contents,
5412 add_types); 5400 add_types);
5413 } else { 5401 } else {
5414 Browser* browser = Browser::CreateForType(TYPE_TABBED, profile_); 5402 Browser* browser = Browser::CreateForType(TYPE_TABBED, profile_);
5415 5403
5416 // Preserve the size of the original window. The new window has already 5404 // Preserve the size of the original window. The new window has already
5417 // been given an offset by the OS, so we shouldn't copy the old bounds. 5405 // been given an offset by the OS, so we shouldn't copy the old bounds.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
5491 ProfileSyncService* service = 5479 ProfileSyncService* service =
5492 ProfileSyncServiceFactory::GetInstance()->GetForProfile( 5480 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
5493 profile()->GetOriginalProfile()); 5481 profile()->GetOriginalProfile());
5494 if (service->HasSyncSetupCompleted()) 5482 if (service->HasSyncSetupCompleted())
5495 ShowOptionsTab(chrome::kPersonalOptionsSubPage); 5483 ShowOptionsTab(chrome::kPersonalOptionsSubPage);
5496 else 5484 else
5497 service->ShowLoginDialog(); 5485 service->ShowLoginDialog();
5498 } 5486 }
5499 5487
5500 void Browser::ToggleSpeechInput() { 5488 void Browser::ToggleSpeechInput() {
5501 GetSelectedTabContentsWrapper()->web_contents()->GetRenderViewHost()-> 5489 GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput();
5502 ToggleSpeechInput();
5503 } 5490 }
5504 5491
5505 void Browser::OnWindowDidShow() { 5492 void Browser::OnWindowDidShow() {
5506 if (window_has_shown_) 5493 if (window_has_shown_)
5507 return; 5494 return;
5508 window_has_shown_ = true; 5495 window_has_shown_ = true;
5509 5496
5510 // Nothing to do for non-tabbed windows. 5497 // Nothing to do for non-tabbed windows.
5511 if (!is_type_tabbed()) 5498 if (!is_type_tabbed())
5512 return; 5499 return;
(...skipping 10 matching lines...) Expand all
5523 local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, false); 5510 local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, false);
5524 window_->GetLocationBar()->ShowFirstRunBubble(); 5511 window_->GetLocationBar()->ShowFirstRunBubble();
5525 } else { 5512 } else {
5526 GlobalErrorService* service = 5513 GlobalErrorService* service =
5527 GlobalErrorServiceFactory::GetForProfile(profile()); 5514 GlobalErrorServiceFactory::GetForProfile(profile());
5528 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); 5515 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
5529 if (error) 5516 if (error)
5530 error->ShowBubbleView(this); 5517 error->ShowBubbleView(this);
5531 } 5518 }
5532 } 5519 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698