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

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

Issue 10544033: TabContentsWrapper -> TabContents, part 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/tab_contents/tab_contents.h » ('j') | 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 #include "chrome/browser/ui/global_error_service_factory.h" 119 #include "chrome/browser/ui/global_error_service_factory.h"
120 #include "chrome/browser/ui/hung_plugin_tab_helper.h" 120 #include "chrome/browser/ui/hung_plugin_tab_helper.h"
121 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" 121 #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
122 #include "chrome/browser/ui/omnibox/location_bar.h" 122 #include "chrome/browser/ui/omnibox/location_bar.h"
123 #include "chrome/browser/ui/panels/panel.h" 123 #include "chrome/browser/ui/panels/panel.h"
124 #include "chrome/browser/ui/panels/panel_manager.h" 124 #include "chrome/browser/ui/panels/panel_manager.h"
125 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" 125 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
126 #include "chrome/browser/ui/status_bubble.h" 126 #include "chrome/browser/ui/status_bubble.h"
127 #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" 127 #include "chrome/browser/ui/sync/browser_synced_window_delegate.h"
128 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 128 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
129 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 129 #include "chrome/browser/ui/tab_contents/tab_contents.h"
130 #include "chrome/browser/ui/tabs/dock_info.h" 130 #include "chrome/browser/ui/tabs/dock_info.h"
131 #include "chrome/browser/ui/tabs/tab_finder.h" 131 #include "chrome/browser/ui/tabs/tab_finder.h"
132 #include "chrome/browser/ui/tabs/tab_menu_model.h" 132 #include "chrome/browser/ui/tabs/tab_menu_model.h"
133 #include "chrome/browser/ui/tabs/tab_strip_model.h" 133 #include "chrome/browser/ui/tabs/tab_strip_model.h"
134 #include "chrome/browser/ui/web_applications/web_app_ui.h" 134 #include "chrome/browser/ui/web_applications/web_app_ui.h"
135 #include "chrome/browser/ui/webui/feedback_ui.h" 135 #include "chrome/browser/ui/webui/feedback_ui.h"
136 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 136 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
137 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" 137 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h"
138 #include "chrome/browser/ui/webui/options2/content_settings_handler2.h" 138 #include "chrome/browser/ui/webui/options2/content_settings_handler2.h"
139 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 139 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 579 }
580 580
581 /////////////////////////////////////////////////////////////////////////////// 581 ///////////////////////////////////////////////////////////////////////////////
582 // Getters & Setters 582 // Getters & Setters
583 583
584 FindBarController* Browser::GetFindBarController() { 584 FindBarController* Browser::GetFindBarController() {
585 if (!find_bar_controller_.get()) { 585 if (!find_bar_controller_.get()) {
586 FindBar* find_bar = window_->CreateFindBar(); 586 FindBar* find_bar = window_->CreateFindBar();
587 find_bar_controller_.reset(new FindBarController(find_bar)); 587 find_bar_controller_.reset(new FindBarController(find_bar));
588 find_bar->SetFindBarController(find_bar_controller_.get()); 588 find_bar->SetFindBarController(find_bar_controller_.get());
589 find_bar_controller_->ChangeTabContents(GetSelectedTabContentsWrapper()); 589 find_bar_controller_->ChangeTabContents(GetActiveTabContents());
590 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); 590 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
591 } 591 }
592 return find_bar_controller_.get(); 592 return find_bar_controller_.get();
593 } 593 }
594 594
595 bool Browser::HasFindBarController() const { 595 bool Browser::HasFindBarController() const {
596 return find_bar_controller_.get() != NULL; 596 return find_bar_controller_.get() != NULL;
597 } 597 }
598 598
599 bool Browser::is_app() const { 599 bool Browser::is_app() const {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 842
843 const DictionaryValue* window_pref = 843 const DictionaryValue* window_pref =
844 profile()->GetPrefs()->GetDictionary(GetWindowPlacementKey().c_str()); 844 profile()->GetPrefs()->GetDictionary(GetWindowPlacementKey().c_str());
845 bool maximized = false; 845 bool maximized = false;
846 window_pref->GetBoolean("maximized", &maximized); 846 window_pref->GetBoolean("maximized", &maximized);
847 847
848 return maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_DEFAULT; 848 return maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_DEFAULT;
849 } 849 }
850 850
851 SkBitmap Browser::GetCurrentPageIcon() const { 851 SkBitmap Browser::GetCurrentPageIcon() const {
852 TabContentsWrapper* contents = GetSelectedTabContentsWrapper(); 852 TabContents* contents = GetActiveTabContents();
853 // |contents| can be NULL since GetCurrentPageIcon() is called by the window 853 // |contents| can be NULL since GetCurrentPageIcon() is called by the window
854 // during the window's creation (before tabs have been added). 854 // during the window's creation (before tabs have been added).
855 return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap(); 855 return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap();
856 } 856 }
857 857
858 string16 Browser::GetWindowTitleForCurrentTab() const { 858 string16 Browser::GetWindowTitleForCurrentTab() const {
859 WebContents* contents = GetSelectedWebContents(); 859 WebContents* contents = GetActiveWebContents();
860 string16 title; 860 string16 title;
861 861
862 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the 862 // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the
863 // window during the window's creation (before tabs have been added). 863 // window during the window's creation (before tabs have been added).
864 if (contents) { 864 if (contents) {
865 title = contents->GetTitle(); 865 title = contents->GetTitle();
866 FormatTitleForDisplay(&title); 866 FormatTitleForDisplay(&title);
867 } 867 }
868 if (title.empty()) 868 if (title.empty())
869 title = CoreTabHelper::GetDefaultTitle(); 869 title = CoreTabHelper::GetDefaultTitle();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 chrome::NOTIFICATION_BROWSER_CLOSING, 951 chrome::NOTIFICATION_BROWSER_CLOSING,
952 content::Source<Browser>(this), 952 content::Source<Browser>(this),
953 content::Details<bool>(&exiting)); 953 content::Details<bool>(&exiting));
954 954
955 CloseAllTabs(); 955 CloseAllTabs();
956 } 956 }
957 957
958 void Browser::OnWindowActivated() { 958 void Browser::OnWindowActivated() {
959 // On some platforms we want to automatically reload tabs that are 959 // On some platforms we want to automatically reload tabs that are
960 // killed when the user selects them. 960 // killed when the user selects them.
961 WebContents* contents = GetSelectedWebContents(); 961 WebContents* contents = GetActiveWebContents();
962 if (contents && contents->GetCrashedStatus() == 962 if (contents && contents->GetCrashedStatus() ==
963 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { 963 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
964 if (CommandLine::ForCurrentProcess()->HasSwitch( 964 if (CommandLine::ForCurrentProcess()->HasSwitch(
965 switches::kReloadKilledTabs)) { 965 switches::kReloadKilledTabs)) {
966 Reload(CURRENT_TAB); 966 Reload(CURRENT_TAB);
967 } 967 }
968 } 968 }
969 } 969 }
970 970
971 //////////////////////////////////////////////////////////////////////////////// 971 ////////////////////////////////////////////////////////////////////////////////
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 1054
1055 int Browser::active_index() const { 1055 int Browser::active_index() const {
1056 return tab_strip_model_->active_index(); 1056 return tab_strip_model_->active_index();
1057 } 1057 }
1058 1058
1059 int Browser::GetIndexOfController( 1059 int Browser::GetIndexOfController(
1060 const NavigationController* controller) const { 1060 const NavigationController* controller) const {
1061 return tab_strip_model_->GetIndexOfController(controller); 1061 return tab_strip_model_->GetIndexOfController(controller);
1062 } 1062 }
1063 1063
1064 TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { 1064 // DEPRECATED
1065 TabContents* Browser::GetSelectedTabContentsWrapper() const {
1066 return GetActiveTabContents();
1067 }
1068
1069 TabContents* Browser::GetActiveTabContents() const {
1065 return tab_strip_model_->GetActiveTabContents(); 1070 return tab_strip_model_->GetActiveTabContents();
1066 } 1071 }
1067 1072
1073 // DEPRECATED
1068 WebContents* Browser::GetSelectedWebContents() const { 1074 WebContents* Browser::GetSelectedWebContents() const {
1069 TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); 1075 return GetActiveWebContents();
1070 return wrapper ? wrapper->web_contents() : NULL;
1071 } 1076 }
1072 1077
1073 TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const { 1078 WebContents* Browser::GetActiveWebContents() const {
1079 TabContents* tab_contents = GetActiveTabContents();
1080 return tab_contents ? tab_contents->web_contents() : NULL;
1081 }
1082
1083 // DEPRECATED
1084 TabContents* Browser::GetTabContentsWrapperAt(int index) const {
1085 return GetTabContentsAt(index);
1086 }
1087
1088 TabContents* Browser::GetTabContentsAt(int index) const {
1074 return tab_strip_model_->GetTabContentsAt(index); 1089 return tab_strip_model_->GetTabContentsAt(index);
1075 } 1090 }
1076 1091
1077 WebContents* Browser::GetWebContentsAt(int index) const { 1092 WebContents* Browser::GetWebContentsAt(int index) const {
1078 TabContentsWrapper* wrapper = GetTabContentsWrapperAt(index); 1093 TabContents* tab_contents = GetTabContentsAt(index);
1079 if (wrapper) 1094 if (tab_contents)
1080 return wrapper->web_contents(); 1095 return tab_contents->web_contents();
1081 return NULL; 1096 return NULL;
1082 } 1097 }
1083 1098
1084 void Browser::ActivateTabAt(int index, bool user_gesture) { 1099 void Browser::ActivateTabAt(int index, bool user_gesture) {
1085 tab_strip_model_->ActivateTabAt(index, user_gesture); 1100 tab_strip_model_->ActivateTabAt(index, user_gesture);
1086 } 1101 }
1087 1102
1088 bool Browser::IsTabPinned(int index) const { 1103 bool Browser::IsTabPinned(int index) const {
1089 return tab_strip_model_->IsTabPinned(index); 1104 return tab_strip_model_->IsTabPinned(index);
1090 } 1105 }
(...skipping 11 matching lines...) Expand all
1102 1117
1103 bool Browser::IsTabStripEditable() const { 1118 bool Browser::IsTabStripEditable() const {
1104 return window()->IsTabStripEditable(); 1119 return window()->IsTabStripEditable();
1105 } 1120 }
1106 1121
1107 int Browser::GetIndexForInsertionDuringRestore(int relative_index) { 1122 int Browser::GetIndexForInsertionDuringRestore(int relative_index) {
1108 return (tab_strip_model_->insertion_policy() == TabStripModel::INSERT_AFTER) ? 1123 return (tab_strip_model_->insertion_policy() == TabStripModel::INSERT_AFTER) ?
1109 tab_count() : relative_index; 1124 tab_count() : relative_index;
1110 } 1125 }
1111 1126
1112 TabContentsWrapper* Browser::AddSelectedTabWithURL( 1127 TabContents* Browser::AddSelectedTabWithURL(
1113 const GURL& url, 1128 const GURL& url,
1114 content::PageTransition transition) { 1129 content::PageTransition transition) {
1115 browser::NavigateParams params(this, url, transition); 1130 browser::NavigateParams params(this, url, transition);
1116 params.disposition = NEW_FOREGROUND_TAB; 1131 params.disposition = NEW_FOREGROUND_TAB;
1117 browser::Navigate(&params); 1132 browser::Navigate(&params);
1118 return params.target_contents; 1133 return params.target_contents;
1119 } 1134 }
1120 1135
1121 WebContents* Browser::AddTab(TabContentsWrapper* tab_contents, 1136 WebContents* Browser::AddTab(TabContents* tab_contents,
1122 content::PageTransition type) { 1137 content::PageTransition type) {
1123 tab_strip_model_->AddTabContents(tab_contents, -1, type, 1138 tab_strip_model_->AddTabContents(tab_contents, -1, type,
1124 TabStripModel::ADD_ACTIVE); 1139 TabStripModel::ADD_ACTIVE);
1125 return tab_contents->web_contents(); 1140 return tab_contents->web_contents();
1126 } 1141 }
1127 1142
1128 WebContents* Browser::AddRestoredTab( 1143 WebContents* Browser::AddRestoredTab(
1129 const std::vector<TabNavigation>& navigations, 1144 const std::vector<TabNavigation>& navigations,
1130 int tab_index, 1145 int tab_index,
1131 int selected_navigation, 1146 int selected_navigation,
1132 const std::string& extension_app_id, 1147 const std::string& extension_app_id,
1133 bool select, 1148 bool select,
1134 bool pin, 1149 bool pin,
1135 bool from_last_session, 1150 bool from_last_session,
1136 content::SessionStorageNamespace* session_storage_namespace) { 1151 content::SessionStorageNamespace* session_storage_namespace) {
1137 GURL restore_url = navigations.at(selected_navigation).virtual_url(); 1152 GURL restore_url = navigations.at(selected_navigation).virtual_url();
1138 TabContentsWrapper* wrapper = TabContentsFactory( 1153 TabContents* tab_contents = TabContentsFactory(
1139 profile(), 1154 profile(),
1140 tab_util::GetSiteInstanceForNewTab(profile_, restore_url), 1155 tab_util::GetSiteInstanceForNewTab(profile_, restore_url),
1141 MSG_ROUTING_NONE, 1156 MSG_ROUTING_NONE,
1142 GetSelectedWebContents(), 1157 GetActiveWebContents(),
1143 session_storage_namespace); 1158 session_storage_namespace);
1144 WebContents* new_tab = wrapper->web_contents(); 1159 WebContents* new_tab = tab_contents->web_contents();
1145 wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); 1160 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id);
1146 std::vector<NavigationEntry*> entries; 1161 std::vector<NavigationEntry*> entries;
1147 TabNavigation::CreateNavigationEntriesFromTabNavigations( 1162 TabNavigation::CreateNavigationEntriesFromTabNavigations(
1148 profile_, navigations, &entries); 1163 profile_, navigations, &entries);
1149 new_tab->GetController().Restore( 1164 new_tab->GetController().Restore(
1150 selected_navigation, from_last_session, &entries); 1165 selected_navigation, from_last_session, &entries);
1151 DCHECK_EQ(0u, entries.size()); 1166 DCHECK_EQ(0u, entries.size());
1152 1167
1153 int add_types = select ? TabStripModel::ADD_ACTIVE : 1168 int add_types = select ? TabStripModel::ADD_ACTIVE :
1154 TabStripModel::ADD_NONE; 1169 TabStripModel::ADD_NONE;
1155 if (pin) { 1170 if (pin) {
1156 int first_mini_tab_idx = tab_strip_model_->IndexOfFirstNonMiniTab(); 1171 int first_mini_tab_idx = tab_strip_model_->IndexOfFirstNonMiniTab();
1157 tab_index = std::min(tab_index, first_mini_tab_idx); 1172 tab_index = std::min(tab_index, first_mini_tab_idx);
1158 add_types |= TabStripModel::ADD_PINNED; 1173 add_types |= TabStripModel::ADD_PINNED;
1159 } 1174 }
1160 tab_strip_model_->InsertTabContentsAt(tab_index, wrapper, add_types); 1175 tab_strip_model_->InsertTabContentsAt(tab_index, tab_contents, add_types);
1161 if (select) { 1176 if (select) {
1162 window_->Activate(); 1177 window_->Activate();
1163 } else { 1178 } else {
1164 // We set the size of the view here, before WebKit does its initial 1179 // We set the size of the view here, before WebKit does its initial
1165 // layout. If we don't, the initial layout of background tabs will be 1180 // layout. If we don't, the initial layout of background tabs will be
1166 // performed with a view width of 0, which may cause script outputs and 1181 // performed with a view width of 0, which may cause script outputs and
1167 // anchor link location calculations to be incorrect even after a new 1182 // anchor link location calculations to be incorrect even after a new
1168 // layout with proper view dimensions. TabStripModel::AddTabContents() 1183 // layout with proper view dimensions. TabStripModel::AddTabContents()
1169 // contains similar logic. 1184 // contains similar logic.
1170 new_tab->GetView()->SizeContents(window_->GetRestoredBounds().size()); 1185 new_tab->GetView()->SizeContents(window_->GetRestoredBounds().size());
1171 new_tab->HideContents(); 1186 new_tab->HideContents();
1172 } 1187 }
1173 SessionService* session_service = 1188 SessionService* session_service =
1174 SessionServiceFactory::GetForProfileIfExisting(profile_); 1189 SessionServiceFactory::GetForProfileIfExisting(profile_);
1175 if (session_service) 1190 if (session_service)
1176 session_service->TabRestored(wrapper, pin); 1191 session_service->TabRestored(tab_contents, pin);
1177 return new_tab; 1192 return new_tab;
1178 } 1193 }
1179 1194
1180 void Browser::AddWebContents(WebContents* new_contents, 1195 void Browser::AddWebContents(WebContents* new_contents,
1181 WindowOpenDisposition disposition, 1196 WindowOpenDisposition disposition,
1182 const gfx::Rect& initial_pos, 1197 const gfx::Rect& initial_pos,
1183 bool user_gesture) { 1198 bool user_gesture) {
1184 AddNewContents(NULL, new_contents, disposition, initial_pos, user_gesture); 1199 AddNewContents(NULL, new_contents, disposition, initial_pos, user_gesture);
1185 } 1200 }
1186 1201
(...skipping 18 matching lines...) Expand all
1205 window_->ToolbarSizeChanged(is_animating); 1220 window_->ToolbarSizeChanged(is_animating);
1206 } 1221 }
1207 1222
1208 void Browser::ReplaceRestoredTab( 1223 void Browser::ReplaceRestoredTab(
1209 const std::vector<TabNavigation>& navigations, 1224 const std::vector<TabNavigation>& navigations,
1210 int selected_navigation, 1225 int selected_navigation,
1211 bool from_last_session, 1226 bool from_last_session,
1212 const std::string& extension_app_id, 1227 const std::string& extension_app_id,
1213 content::SessionStorageNamespace* session_storage_namespace) { 1228 content::SessionStorageNamespace* session_storage_namespace) {
1214 GURL restore_url = navigations.at(selected_navigation).virtual_url(); 1229 GURL restore_url = navigations.at(selected_navigation).virtual_url();
1215 TabContentsWrapper* wrapper = TabContentsFactory( 1230 TabContents* tab_contents = TabContentsFactory(
1216 profile(), 1231 profile(),
1217 tab_util::GetSiteInstanceForNewTab(profile_, restore_url), 1232 tab_util::GetSiteInstanceForNewTab(profile_, restore_url),
1218 MSG_ROUTING_NONE, 1233 MSG_ROUTING_NONE,
1219 GetSelectedWebContents(), 1234 GetActiveWebContents(),
1220 session_storage_namespace); 1235 session_storage_namespace);
1221 wrapper->extension_tab_helper()->SetExtensionAppById(extension_app_id); 1236 tab_contents->extension_tab_helper()->SetExtensionAppById(extension_app_id);
1222 WebContents* replacement = wrapper->web_contents(); 1237 WebContents* replacement = tab_contents->web_contents();
1223 std::vector<NavigationEntry*> entries; 1238 std::vector<NavigationEntry*> entries;
1224 TabNavigation::CreateNavigationEntriesFromTabNavigations( 1239 TabNavigation::CreateNavigationEntriesFromTabNavigations(
1225 profile_, navigations, &entries); 1240 profile_, navigations, &entries);
1226 replacement->GetController().Restore( 1241 replacement->GetController().Restore(
1227 selected_navigation, from_last_session, &entries); 1242 selected_navigation, from_last_session, &entries);
1228 DCHECK_EQ(0u, entries.size()); 1243 DCHECK_EQ(0u, entries.size());
1229 1244
1230 tab_strip_model_->ReplaceNavigationControllerAt(active_index(), wrapper); 1245 tab_strip_model_->ReplaceNavigationControllerAt(active_index(), tab_contents);
1231 } 1246 }
1232 1247
1233 bool Browser::NavigateToIndexWithDisposition(int index, 1248 bool Browser::NavigateToIndexWithDisposition(int index,
1234 WindowOpenDisposition disp) { 1249 WindowOpenDisposition disp) {
1235 NavigationController& controller = 1250 NavigationController& controller =
1236 GetOrCloneTabForDisposition(disp)->GetController(); 1251 GetOrCloneTabForDisposition(disp)->GetController();
1237 if (index < 0 || index >= controller.GetEntryCount()) 1252 if (index < 0 || index >= controller.GetEntryCount())
1238 return false; 1253 return false;
1239 controller.GoToIndex(index); 1254 controller.GoToIndex(index);
1240 return true; 1255 return true;
1241 } 1256 }
1242 1257
1243 void Browser::ShowSingletonTab(const GURL& url) { 1258 void Browser::ShowSingletonTab(const GURL& url) {
1244 browser::NavigateParams params(GetSingletonTabNavigateParams(url)); 1259 browser::NavigateParams params(GetSingletonTabNavigateParams(url));
1245 browser::Navigate(&params); 1260 browser::Navigate(&params);
1246 } 1261 }
1247 1262
1248 void Browser::ShowSingletonTabRespectRef(const GURL& url) { 1263 void Browser::ShowSingletonTabRespectRef(const GURL& url) {
1249 browser::NavigateParams params(GetSingletonTabNavigateParams(url)); 1264 browser::NavigateParams params(GetSingletonTabNavigateParams(url));
1250 params.ref_behavior = browser::NavigateParams::RESPECT_REF; 1265 params.ref_behavior = browser::NavigateParams::RESPECT_REF;
1251 browser::Navigate(&params); 1266 browser::Navigate(&params);
1252 } 1267 }
1253 1268
1254 void Browser::ShowSingletonTabOverwritingNTP( 1269 void Browser::ShowSingletonTabOverwritingNTP(
1255 const browser::NavigateParams& params) { 1270 const browser::NavigateParams& params) {
1256 browser::NavigateParams local_params(params); 1271 browser::NavigateParams local_params(params);
1257 WebContents* contents = GetSelectedWebContents(); 1272 WebContents* contents = GetActiveWebContents();
1258 if (contents) { 1273 if (contents) {
1259 const GURL& contents_url = contents->GetURL(); 1274 const GURL& contents_url = contents->GetURL();
1260 if ((contents_url == GURL(chrome::kChromeUINewTabURL) || 1275 if ((contents_url == GURL(chrome::kChromeUINewTabURL) ||
1261 contents_url == GURL(chrome::kAboutBlankURL)) && 1276 contents_url == GURL(chrome::kAboutBlankURL)) &&
1262 browser::GetIndexOfSingletonTab(&local_params) < 0) { 1277 browser::GetIndexOfSingletonTab(&local_params) < 0) {
1263 local_params.disposition = CURRENT_TAB; 1278 local_params.disposition = CURRENT_TAB;
1264 } 1279 }
1265 } 1280 }
1266 1281
1267 browser::Navigate(&local_params); 1282 browser::Navigate(&local_params);
(...skipping 12 matching lines...) Expand all
1280 void Browser::WindowFullscreenStateChanged() { 1295 void Browser::WindowFullscreenStateChanged() {
1281 fullscreen_controller_->WindowFullscreenStateChanged(); 1296 fullscreen_controller_->WindowFullscreenStateChanged();
1282 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); 1297 UpdateCommandsForFullscreenMode(window_->IsFullscreen());
1283 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); 1298 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN);
1284 } 1299 }
1285 1300
1286 /////////////////////////////////////////////////////////////////////////////// 1301 ///////////////////////////////////////////////////////////////////////////////
1287 // Browser, Assorted browser commands: 1302 // Browser, Assorted browser commands:
1288 1303
1289 bool Browser::CanGoBack() const { 1304 bool Browser::CanGoBack() const {
1290 return GetSelectedWebContents()->GetController().CanGoBack(); 1305 return GetActiveWebContents()->GetController().CanGoBack();
1291 } 1306 }
1292 1307
1293 void Browser::GoBack(WindowOpenDisposition disposition) { 1308 void Browser::GoBack(WindowOpenDisposition disposition) {
1294 content::RecordAction(UserMetricsAction("Back")); 1309 content::RecordAction(UserMetricsAction("Back"));
1295 1310
1296 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); 1311 TabContents* current_tab = GetActiveTabContents();
1297 if (CanGoBack()) { 1312 if (CanGoBack()) {
1298 WebContents* new_tab = GetOrCloneTabForDisposition(disposition); 1313 WebContents* new_tab = GetOrCloneTabForDisposition(disposition);
1299 // If we are on an interstitial page and clone the tab, it won't be copied 1314 // If we are on an interstitial page and clone the tab, it won't be copied
1300 // to the new tab, so we don't need to go back. 1315 // to the new tab, so we don't need to go back.
1301 if (current_tab->web_contents()->ShowingInterstitialPage() && 1316 if (current_tab->web_contents()->ShowingInterstitialPage() &&
1302 (new_tab != current_tab->web_contents())) 1317 (new_tab != current_tab->web_contents()))
1303 return; 1318 return;
1304 new_tab->GetController().GoBack(); 1319 new_tab->GetController().GoBack();
1305 } 1320 }
1306 } 1321 }
1307 1322
1308 bool Browser::CanGoForward() const { 1323 bool Browser::CanGoForward() const {
1309 return GetSelectedWebContents()->GetController().CanGoForward(); 1324 return GetActiveWebContents()->GetController().CanGoForward();
1310 } 1325 }
1311 1326
1312 void Browser::GoForward(WindowOpenDisposition disposition) { 1327 void Browser::GoForward(WindowOpenDisposition disposition) {
1313 content::RecordAction(UserMetricsAction("Forward")); 1328 content::RecordAction(UserMetricsAction("Forward"));
1314 if (CanGoForward()) 1329 if (CanGoForward())
1315 GetOrCloneTabForDisposition(disposition)->GetController().GoForward(); 1330 GetOrCloneTabForDisposition(disposition)->GetController().GoForward();
1316 } 1331 }
1317 1332
1318 void Browser::Reload(WindowOpenDisposition disposition) { 1333 void Browser::Reload(WindowOpenDisposition disposition) {
1319 content::RecordAction(UserMetricsAction("Reload")); 1334 content::RecordAction(UserMetricsAction("Reload"));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 1385
1371 DCHECK(profile_->GetExtensionService()); 1386 DCHECK(profile_->GetExtensionService());
1372 if (profile_->GetExtensionService()->IsInstalledApp(url)) { 1387 if (profile_->GetExtensionService()->IsInstalledApp(url)) {
1373 AppLauncherHandler::RecordAppLaunchType( 1388 AppLauncherHandler::RecordAppLaunchType(
1374 extension_misc::APP_LAUNCH_OMNIBOX_LOCATION); 1389 extension_misc::APP_LAUNCH_OMNIBOX_LOCATION);
1375 } 1390 }
1376 } 1391 }
1377 1392
1378 void Browser::Stop() { 1393 void Browser::Stop() {
1379 content::RecordAction(UserMetricsAction("Stop")); 1394 content::RecordAction(UserMetricsAction("Stop"));
1380 GetSelectedWebContents()->Stop(); 1395 GetActiveWebContents()->Stop();
1381 } 1396 }
1382 1397
1383 #if !defined(OS_WIN) 1398 #if !defined(OS_WIN)
1384 void Browser::NewWindow() { 1399 void Browser::NewWindow() {
1385 NewEmptyWindow(profile_->GetOriginalProfile()); 1400 NewEmptyWindow(profile_->GetOriginalProfile());
1386 } 1401 }
1387 1402
1388 void Browser::NewIncognitoWindow() { 1403 void Browser::NewIncognitoWindow() {
1389 NewEmptyWindow(profile_->GetOffTheRecordProfile()); 1404 NewEmptyWindow(profile_->GetOffTheRecordProfile());
1390 } 1405 }
1391 #endif // OS_WIN 1406 #endif // OS_WIN
1392 1407
1393 void Browser::CloseWindow() { 1408 void Browser::CloseWindow() {
1394 content::RecordAction(UserMetricsAction("CloseWindow")); 1409 content::RecordAction(UserMetricsAction("CloseWindow"));
1395 window_->Close(); 1410 window_->Close();
1396 } 1411 }
1397 1412
1398 void Browser::NewTab() { 1413 void Browser::NewTab() {
1399 content::RecordAction(UserMetricsAction("NewTab")); 1414 content::RecordAction(UserMetricsAction("NewTab"));
1400 1415
1401 if (is_type_tabbed()) { 1416 if (is_type_tabbed()) {
1402 AddBlankTab(true); 1417 AddBlankTab(true);
1403 GetSelectedWebContents()->GetView()->RestoreFocus(); 1418 GetActiveWebContents()->GetView()->RestoreFocus();
1404 } else { 1419 } else {
1405 Browser* b = browser::FindOrCreateTabbedBrowser(profile_); 1420 Browser* b = browser::FindOrCreateTabbedBrowser(profile_);
1406 b->AddBlankTab(true); 1421 b->AddBlankTab(true);
1407 b->window()->Show(); 1422 b->window()->Show();
1408 // The call to AddBlankTab above did not set the focus to the tab as its 1423 // The call to AddBlankTab above did not set the focus to the tab as its
1409 // window was not active, so we have to do it explicitly. 1424 // window was not active, so we have to do it explicitly.
1410 // See http://crbug.com/6380. 1425 // See http://crbug.com/6380.
1411 b->GetSelectedWebContents()->GetView()->RestoreFocus(); 1426 b->GetActiveWebContents()->GetView()->RestoreFocus();
1412 } 1427 }
1413 } 1428 }
1414 1429
1415 void Browser::CloseTab() { 1430 void Browser::CloseTab() {
1416 content::RecordAction(UserMetricsAction("CloseTab_Accelerator")); 1431 content::RecordAction(UserMetricsAction("CloseTab_Accelerator"));
1417 if (CanCloseTab()) 1432 if (CanCloseTab())
1418 tab_strip_model_->CloseSelectedTabs(); 1433 tab_strip_model_->CloseSelectedTabs();
1419 } 1434 }
1420 1435
1421 void Browser::SelectNextTab() { 1436 void Browser::SelectNextTab() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 void Browser::DuplicateTab() { 1482 void Browser::DuplicateTab() {
1468 content::RecordAction(UserMetricsAction("Duplicate")); 1483 content::RecordAction(UserMetricsAction("Duplicate"));
1469 DuplicateContentsAt(active_index()); 1484 DuplicateContentsAt(active_index());
1470 } 1485 }
1471 1486
1472 void Browser::WriteCurrentURLToClipboard() { 1487 void Browser::WriteCurrentURLToClipboard() {
1473 // TODO(ericu): There isn't currently a metric for this. Should there be? 1488 // TODO(ericu): There isn't currently a metric for this. Should there be?
1474 // We don't appear to track the action when it comes from the 1489 // We don't appear to track the action when it comes from the
1475 // RenderContextViewMenu. 1490 // RenderContextViewMenu.
1476 1491
1477 WebContents* contents = GetSelectedWebContents(); 1492 WebContents* contents = GetActiveWebContents();
1478 if (!toolbar_model_->ShouldDisplayURL()) 1493 if (!toolbar_model_->ShouldDisplayURL())
1479 return; 1494 return;
1480 1495
1481 chrome_common_net::WriteURLToClipboard( 1496 chrome_common_net::WriteURLToClipboard(
1482 contents->GetURL(), 1497 contents->GetURL(),
1483 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), 1498 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
1484 g_browser_process->clipboard()); 1499 g_browser_process->clipboard());
1485 } 1500 }
1486 1501
1487 void Browser::ConvertPopupToTabbedBrowser() { 1502 void Browser::ConvertPopupToTabbedBrowser() {
1488 content::RecordAction(UserMetricsAction("ShowAsTab")); 1503 content::RecordAction(UserMetricsAction("ShowAsTab"));
1489 TabContentsWrapper* contents = tab_strip_model_->DetachTabContentsAt( 1504 TabContents* contents = tab_strip_model_->DetachTabContentsAt(active_index());
1490 active_index());
1491 Browser* browser = Browser::Create(profile_); 1505 Browser* browser = Browser::Create(profile_);
1492 browser->tab_strip_model()->AppendTabContents(contents, true); 1506 browser->tab_strip_model()->AppendTabContents(contents, true);
1493 browser->window()->Show(); 1507 browser->window()->Show();
1494 } 1508 }
1495 1509
1496 void Browser::ToggleFullscreenMode() { 1510 void Browser::ToggleFullscreenMode() {
1497 fullscreen_controller_->ToggleFullscreenMode(); 1511 fullscreen_controller_->ToggleFullscreenMode();
1498 } 1512 }
1499 1513
1500 void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) { 1514 void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) {
(...skipping 13 matching lines...) Expand all
1514 1528
1515 void Browser::BookmarkCurrentPage() { 1529 void Browser::BookmarkCurrentPage() {
1516 content::RecordAction(UserMetricsAction("Star")); 1530 content::RecordAction(UserMetricsAction("Star"));
1517 1531
1518 BookmarkModel* model = profile()->GetBookmarkModel(); 1532 BookmarkModel* model = profile()->GetBookmarkModel();
1519 if (!model || !model->IsLoaded()) 1533 if (!model || !model->IsLoaded())
1520 return; // Ignore requests until bookmarks are loaded. 1534 return; // Ignore requests until bookmarks are loaded.
1521 1535
1522 GURL url; 1536 GURL url;
1523 string16 title; 1537 string16 title;
1524 TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); 1538 TabContents* tab = GetActiveTabContents();
1525 bookmark_utils::GetURLAndTitleToBookmark(tab->web_contents(), &url, &title); 1539 bookmark_utils::GetURLAndTitleToBookmark(tab->web_contents(), &url, &title);
1526 bool was_bookmarked = model->IsBookmarked(url); 1540 bool was_bookmarked = model->IsBookmarked(url);
1527 if (!was_bookmarked && profile_->IsOffTheRecord()) { 1541 if (!was_bookmarked && profile_->IsOffTheRecord()) {
1528 // If we're incognito the favicon may not have been saved. Save it now 1542 // If we're incognito the favicon may not have been saved. Save it now
1529 // so that bookmarks have an icon for the page. 1543 // so that bookmarks have an icon for the page.
1530 tab->favicon_tab_helper()->SaveFavicon(); 1544 tab->favicon_tab_helper()->SaveFavicon();
1531 } 1545 }
1532 bookmark_utils::AddIfNotBookmarked(model, url, title); 1546 bookmark_utils::AddIfNotBookmarked(model, url, title);
1533 // Make sure the model actually added a bookmark before showing the star. A 1547 // Make sure the model actually added a bookmark before showing the star. A
1534 // bookmark isn't created if the url is invalid. 1548 // bookmark isn't created if the url is invalid.
1535 if (window_->IsActive() && model->IsBookmarked(url)) { 1549 if (window_->IsActive() && model->IsBookmarked(url)) {
1536 // Only show the bubble if the window is active, otherwise we may get into 1550 // Only show the bubble if the window is active, otherwise we may get into
1537 // weird situations where the bubble is deleted as soon as it is shown. 1551 // weird situations where the bubble is deleted as soon as it is shown.
1538 window_->ShowBookmarkBubble(url, was_bookmarked); 1552 window_->ShowBookmarkBubble(url, was_bookmarked);
1539 } 1553 }
1540 } 1554 }
1541 1555
1542 void Browser::SavePage() { 1556 void Browser::SavePage() {
1543 content::RecordAction(UserMetricsAction("SavePage")); 1557 content::RecordAction(UserMetricsAction("SavePage"));
1544 WebContents* current_tab = GetSelectedWebContents(); 1558 WebContents* current_tab = GetActiveWebContents();
1545 if (current_tab && current_tab->GetContentsMimeType() == "application/pdf") 1559 if (current_tab && current_tab->GetContentsMimeType() == "application/pdf")
1546 content::RecordAction(UserMetricsAction("PDF.SavePage")); 1560 content::RecordAction(UserMetricsAction("PDF.SavePage"));
1547 GetSelectedWebContents()->OnSavePage(); 1561 GetActiveWebContents()->OnSavePage();
1548 } 1562 }
1549 1563
1550 void Browser::ViewSelectedSource() { 1564 void Browser::ViewSelectedSource() {
1551 ViewSource(GetSelectedTabContentsWrapper()); 1565 ViewSource(GetActiveTabContents());
1552 } 1566 }
1553 1567
1554 void Browser::ShowFindBar() { 1568 void Browser::ShowFindBar() {
1555 GetFindBarController()->Show(); 1569 GetFindBarController()->Show();
1556 } 1570 }
1557 1571
1558 void Browser::ShowPageInfo(content::WebContents* web_contents, 1572 void Browser::ShowPageInfo(content::WebContents* web_contents,
1559 const GURL& url, 1573 const GURL& url,
1560 const SSLStatus& ssl, 1574 const SSLStatus& ssl,
1561 bool show_history) { 1575 bool show_history) {
1562 Profile* profile = Profile::FromBrowserContext( 1576 Profile* profile = Profile::FromBrowserContext(
1563 web_contents->GetBrowserContext()); 1577 web_contents->GetBrowserContext());
1564 TabContentsWrapper* wrapper = 1578 TabContents* tab_contents =
1565 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); 1579 TabContents::GetOwningTabContentsForWebContents(web_contents);
1566 1580
1567 if (CommandLine::ForCurrentProcess()->HasSwitch( 1581 if (CommandLine::ForCurrentProcess()->HasSwitch(
1568 switches::kEnableWebsiteSettings)) { 1582 switches::kEnableWebsiteSettings)) {
1569 window()->ShowWebsiteSettings(profile, wrapper, url, ssl, show_history); 1583 window()->ShowWebsiteSettings(
1584 profile, tab_contents, url, ssl, show_history);
1570 } else { 1585 } else {
1571 window()->ShowPageInfo(profile, url, ssl, show_history); 1586 window()->ShowPageInfo(profile, url, ssl, show_history);
1572 } 1587 }
1573 } 1588 }
1574 1589
1575 void Browser::ShowChromeToMobileBubble() { 1590 void Browser::ShowChromeToMobileBubble() {
1576 // Only show the bubble if the window is active, otherwise we may get into 1591 // Only show the bubble if the window is active, otherwise we may get into
1577 // weird situations where the bubble is deleted as soon as it is shown. 1592 // weird situations where the bubble is deleted as soon as it is shown.
1578 if (window_->IsActive()) 1593 if (window_->IsActive())
1579 window_->ShowChromeToMobileBubble(); 1594 window_->ShowChromeToMobileBubble();
1580 } 1595 }
1581 1596
1582 bool Browser::SupportsWindowFeature(WindowFeature feature) const { 1597 bool Browser::SupportsWindowFeature(WindowFeature feature) const {
1583 return SupportsWindowFeatureImpl(feature, true); 1598 return SupportsWindowFeatureImpl(feature, true);
1584 } 1599 }
1585 1600
1586 bool Browser::CanSupportWindowFeature(WindowFeature feature) const { 1601 bool Browser::CanSupportWindowFeature(WindowFeature feature) const {
1587 return SupportsWindowFeatureImpl(feature, false); 1602 return SupportsWindowFeatureImpl(feature, false);
1588 } 1603 }
1589 1604
1590 void Browser::Print() { 1605 void Browser::Print() {
1591 if (g_browser_process->local_state()->GetBoolean( 1606 if (g_browser_process->local_state()->GetBoolean(
1592 prefs::kPrintPreviewDisabled)) { 1607 prefs::kPrintPreviewDisabled)) {
1593 GetSelectedTabContentsWrapper()->print_view_manager()->PrintNow(); 1608 GetActiveTabContents()->print_view_manager()->PrintNow();
1594 } else { 1609 } else {
1595 GetSelectedTabContentsWrapper()->print_view_manager()->PrintPreviewNow(); 1610 GetActiveTabContents()->print_view_manager()->PrintPreviewNow();
1596 } 1611 }
1597 } 1612 }
1598 1613
1599 void Browser::AdvancedPrint() { 1614 void Browser::AdvancedPrint() {
1600 GetSelectedTabContentsWrapper()->print_view_manager()->AdvancedPrintNow(); 1615 GetActiveTabContents()->print_view_manager()->AdvancedPrintNow();
1601 } 1616 }
1602 1617
1603 void Browser::EmailPageLocation() { 1618 void Browser::EmailPageLocation() {
1604 content::RecordAction(UserMetricsAction("EmailPageLocation")); 1619 content::RecordAction(UserMetricsAction("EmailPageLocation"));
1605 WebContents* wc = GetSelectedWebContents(); 1620 WebContents* wc = GetActiveWebContents();
1606 DCHECK(wc); 1621 DCHECK(wc);
1607 1622
1608 std::string title = net::EscapeQueryParamValue( 1623 std::string title = net::EscapeQueryParamValue(
1609 UTF16ToUTF8(wc->GetTitle()), false); 1624 UTF16ToUTF8(wc->GetTitle()), false);
1610 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false); 1625 std::string page_url = net::EscapeQueryParamValue(wc->GetURL().spec(), false);
1611 std::string mailto = std::string("mailto:?subject=Fwd:%20") + 1626 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1612 title + "&body=%0A%0A" + page_url; 1627 title + "&body=%0A%0A" + page_url;
1613 platform_util::OpenExternal(GURL(mailto)); 1628 platform_util::OpenExternal(GURL(mailto));
1614 } 1629 }
1615 1630
1616 void Browser::ToggleEncodingAutoDetect() { 1631 void Browser::ToggleEncodingAutoDetect() {
1617 content::RecordAction(UserMetricsAction("AutoDetectChange")); 1632 content::RecordAction(UserMetricsAction("AutoDetectChange"));
1618 encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); 1633 encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue());
1619 // If "auto detect" is turned on, then any current override encoding 1634 // If "auto detect" is turned on, then any current override encoding
1620 // is cleared. This also implicitly performs a reload. 1635 // is cleared. This also implicitly performs a reload.
1621 // OTOH, if "auto detect" is turned off, we don't change the currently 1636 // OTOH, if "auto detect" is turned off, we don't change the currently
1622 // active encoding. 1637 // active encoding.
1623 if (encoding_auto_detect_.GetValue()) { 1638 if (encoding_auto_detect_.GetValue()) {
1624 WebContents* contents = GetSelectedWebContents(); 1639 WebContents* contents = GetActiveWebContents();
1625 if (contents) 1640 if (contents)
1626 contents->ResetOverrideEncoding(); 1641 contents->ResetOverrideEncoding();
1627 } 1642 }
1628 } 1643 }
1629 1644
1630 void Browser::OverrideEncoding(int encoding_id) { 1645 void Browser::OverrideEncoding(int encoding_id) {
1631 content::RecordAction(UserMetricsAction("OverrideEncoding")); 1646 content::RecordAction(UserMetricsAction("OverrideEncoding"));
1632 const std::string selected_encoding = 1647 const std::string selected_encoding =
1633 CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); 1648 CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id);
1634 WebContents* contents = GetSelectedWebContents(); 1649 WebContents* contents = GetActiveWebContents();
1635 if (!selected_encoding.empty() && contents) 1650 if (!selected_encoding.empty() && contents)
1636 contents->SetOverrideEncoding(selected_encoding); 1651 contents->SetOverrideEncoding(selected_encoding);
1637 // Update the list of recently selected encodings. 1652 // Update the list of recently selected encodings.
1638 std::string new_selected_encoding_list; 1653 std::string new_selected_encoding_list;
1639 if (CharacterEncoding::UpdateRecentlySelectedEncoding( 1654 if (CharacterEncoding::UpdateRecentlySelectedEncoding(
1640 profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), 1655 profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding),
1641 encoding_id, 1656 encoding_id,
1642 &new_selected_encoding_list)) { 1657 &new_selected_encoding_list)) {
1643 profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, 1658 profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding,
1644 new_selected_encoding_list); 1659 new_selected_encoding_list);
(...skipping 27 matching lines...) Expand all
1672 1687
1673 void Browser::FindPrevious() { 1688 void Browser::FindPrevious() {
1674 content::RecordAction(UserMetricsAction("FindPrevious")); 1689 content::RecordAction(UserMetricsAction("FindPrevious"));
1675 FindInPage(true, false); 1690 FindInPage(true, false);
1676 } 1691 }
1677 1692
1678 void Browser::Zoom(content::PageZoom zoom) { 1693 void Browser::Zoom(content::PageZoom zoom) {
1679 if (is_devtools()) 1694 if (is_devtools())
1680 return; 1695 return;
1681 1696
1682 content::RenderViewHost* host = GetSelectedWebContents()->GetRenderViewHost(); 1697 content::RenderViewHost* host = GetActiveWebContents()->GetRenderViewHost();
1683 if (zoom == content::PAGE_ZOOM_RESET) { 1698 if (zoom == content::PAGE_ZOOM_RESET) {
1684 host->SetZoomLevel(0); 1699 host->SetZoomLevel(0);
1685 content::RecordAction(UserMetricsAction("ZoomNormal")); 1700 content::RecordAction(UserMetricsAction("ZoomNormal"));
1686 return; 1701 return;
1687 } 1702 }
1688 1703
1689 double current_zoom_level = GetSelectedWebContents()->GetZoomLevel(); 1704 double current_zoom_level = GetActiveWebContents()->GetZoomLevel();
1690 double default_zoom_level = 1705 double default_zoom_level =
1691 profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); 1706 profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel);
1692 1707
1693 // Generate a vector of zoom levels from an array of known presets along with 1708 // Generate a vector of zoom levels from an array of known presets along with
1694 // the default level added if necessary. 1709 // the default level added if necessary.
1695 std::vector<double> zoom_levels = 1710 std::vector<double> zoom_levels =
1696 chrome_page_zoom::PresetZoomLevels(default_zoom_level); 1711 chrome_page_zoom::PresetZoomLevels(default_zoom_level);
1697 1712
1698 if (zoom == content::PAGE_ZOOM_OUT) { 1713 if (zoom == content::PAGE_ZOOM_OUT) {
1699 // Iterate through the zoom levels in reverse order to find the next 1714 // Iterate through the zoom levels in reverse order to find the next
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 if (!select_file_dialog_.get()) 1784 if (!select_file_dialog_.get())
1770 select_file_dialog_ = SelectFileDialog::Create(this); 1785 select_file_dialog_ = SelectFileDialog::Create(this);
1771 1786
1772 const FilePath directory = profile_->last_selected_directory(); 1787 const FilePath directory = profile_->last_selected_directory();
1773 1788
1774 // TODO(beng): figure out how to juggle this. 1789 // TODO(beng): figure out how to juggle this.
1775 gfx::NativeWindow parent_window = window_->GetNativeHandle(); 1790 gfx::NativeWindow parent_window = window_->GetNativeHandle();
1776 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, 1791 select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE,
1777 string16(), directory, 1792 string16(), directory,
1778 NULL, 0, FILE_PATH_LITERAL(""), 1793 NULL, 0, FILE_PATH_LITERAL(""),
1779 GetSelectedWebContents(), 1794 GetActiveWebContents(),
1780 parent_window, NULL); 1795 parent_window, NULL);
1781 } 1796 }
1782 1797
1783 void Browser::OpenCreateShortcutsDialog() { 1798 void Browser::OpenCreateShortcutsDialog() {
1784 content::RecordAction(UserMetricsAction("CreateShortcut")); 1799 content::RecordAction(UserMetricsAction("CreateShortcut"));
1785 #if !defined(OS_MACOSX) 1800 #if !defined(OS_MACOSX)
1786 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); 1801 TabContents* current_tab = GetActiveTabContents();
1787 DCHECK(current_tab && 1802 DCHECK(current_tab &&
1788 web_app::IsValidUrl(current_tab->web_contents()->GetURL())) << 1803 web_app::IsValidUrl(current_tab->web_contents()->GetURL())) <<
1789 "Menu item should be disabled."; 1804 "Menu item should be disabled.";
1790 1805
1791 NavigationEntry* entry = 1806 NavigationEntry* entry =
1792 current_tab->web_contents()->GetController().GetLastCommittedEntry(); 1807 current_tab->web_contents()->GetController().GetLastCommittedEntry();
1793 if (!entry) 1808 if (!entry)
1794 return; 1809 return;
1795 1810
1796 // RVH's GetApplicationInfo should not be called before it returns. 1811 // RVH's GetApplicationInfo should not be called before it returns.
1797 DCHECK(pending_web_app_action_ == NONE); 1812 DCHECK(pending_web_app_action_ == NONE);
1798 pending_web_app_action_ = CREATE_SHORTCUT; 1813 pending_web_app_action_ = CREATE_SHORTCUT;
1799 1814
1800 // Start fetching web app info for CreateApplicationShortcut dialog and show 1815 // Start fetching web app info for CreateApplicationShortcut dialog and show
1801 // the dialog when the data is available in OnDidGetApplicationInfo. 1816 // the dialog when the data is available in OnDidGetApplicationInfo.
1802 current_tab->extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); 1817 current_tab->extension_tab_helper()->GetApplicationInfo(entry->GetPageID());
1803 #else 1818 #else
1804 NOTIMPLEMENTED(); 1819 NOTIMPLEMENTED();
1805 #endif 1820 #endif
1806 } 1821 }
1807 1822
1808 void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) { 1823 void Browser::ToggleDevToolsWindow(DevToolsToggleAction action) {
1809 if (action == DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE) 1824 if (action == DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE)
1810 content::RecordAction(UserMetricsAction("DevTools_ToggleConsole")); 1825 content::RecordAction(UserMetricsAction("DevTools_ToggleConsole"));
1811 else 1826 else
1812 content::RecordAction(UserMetricsAction("DevTools_ToggleWindow")); 1827 content::RecordAction(UserMetricsAction("DevTools_ToggleWindow"));
1813 1828
1814 DevToolsWindow::ToggleDevToolsWindow( 1829 DevToolsWindow::ToggleDevToolsWindow(
1815 GetSelectedWebContents()->GetRenderViewHost(), 1830 GetActiveWebContents()->GetRenderViewHost(),
1816 action); 1831 action);
1817 } 1832 }
1818 1833
1819 void Browser::OpenTaskManager(bool highlight_background_resources) { 1834 void Browser::OpenTaskManager(bool highlight_background_resources) {
1820 content::RecordAction(UserMetricsAction("TaskManager")); 1835 content::RecordAction(UserMetricsAction("TaskManager"));
1821 if (highlight_background_resources) 1836 if (highlight_background_resources)
1822 window_->ShowBackgroundPages(); 1837 window_->ShowBackgroundPages();
1823 else 1838 else
1824 window_->ShowTaskManager(); 1839 window_->ShowTaskManager();
1825 } 1840 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 browser::NavigateParams params(GetSingletonTabNavigateParams(GURL(url))); 2023 browser::NavigateParams params(GetSingletonTabNavigateParams(GURL(url)));
2009 params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; 2024 params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
2010 ShowSingletonTabOverwritingNTP(params); 2025 ShowSingletonTabOverwritingNTP(params);
2011 } else { 2026 } else {
2012 LoginUIServiceFactory::GetForProfile( 2027 LoginUIServiceFactory::GetForProfile(
2013 profile()->GetOriginalProfile())->ShowLoginUI(); 2028 profile()->GetOriginalProfile())->ShowLoginUI();
2014 } 2029 }
2015 } 2030 }
2016 2031
2017 void Browser::ToggleSpeechInput() { 2032 void Browser::ToggleSpeechInput() {
2018 GetSelectedWebContents()->GetRenderViewHost()->ToggleSpeechInput(); 2033 GetActiveWebContents()->GetRenderViewHost()->ToggleSpeechInput();
2019 } 2034 }
2020 2035
2021 void Browser::UpdateDownloadShelfVisibility(bool visible) { 2036 void Browser::UpdateDownloadShelfVisibility(bool visible) {
2022 if (GetStatusBubble()) 2037 if (GetStatusBubble())
2023 GetStatusBubble()->UpdateDownloadShelfVisibility(visible); 2038 GetStatusBubble()->UpdateDownloadShelfVisibility(visible);
2024 } 2039 }
2025 2040
2026 /////////////////////////////////////////////////////////////////////////////// 2041 ///////////////////////////////////////////////////////////////////////////////
2027 2042
2028 // static 2043 // static
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 // to proceed closing the page or not, which sends us back to this method 2226 // to proceed closing the page or not, which sends us back to this method
2212 // with the NeedToFireBeforeUnload bit cleared. 2227 // with the NeedToFireBeforeUnload bit cleared.
2213 contents->GetRenderViewHost()->FirePageBeforeUnload(false); 2228 contents->GetRenderViewHost()->FirePageBeforeUnload(false);
2214 return true; 2229 return true;
2215 } 2230 }
2216 return false; 2231 return false;
2217 } 2232 }
2218 2233
2219 // static 2234 // static
2220 void Browser::JSOutOfMemoryHelper(WebContents* tab) { 2235 void Browser::JSOutOfMemoryHelper(WebContents* tab) {
2221 TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( 2236 TabContents* tab_contents = TabContents::GetOwningTabContentsForWebContents(
2222 tab); 2237 tab);
2223 if (!tcw) 2238 if (!tab_contents)
2224 return; 2239 return;
2225 2240
2226 InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); 2241 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
2227 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( 2242 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
2228 infobar_helper, 2243 infobar_helper,
2229 NULL, 2244 NULL,
2230 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), 2245 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2231 true)); 2246 true));
2232 } 2247 }
2233 2248
2234 // static 2249 // static
2235 void Browser::RegisterProtocolHandlerHelper(WebContents* tab, 2250 void Browser::RegisterProtocolHandlerHelper(WebContents* tab,
2236 const std::string& protocol, 2251 const std::string& protocol,
2237 const GURL& url, 2252 const GURL& url,
2238 const string16& title, 2253 const string16& title,
2239 bool user_gesture) { 2254 bool user_gesture) {
2240 TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( 2255 TabContents* tab_contents = TabContents::GetOwningTabContentsForWebContents(
2241 tab); 2256 tab);
2242 if (!tcw || tcw->profile()->IsOffTheRecord()) 2257 if (!tab_contents || tab_contents->profile()->IsOffTheRecord())
2243 return; 2258 return;
2244 2259
2245 ProtocolHandler handler = 2260 ProtocolHandler handler =
2246 ProtocolHandler::CreateProtocolHandler(protocol, url, title); 2261 ProtocolHandler::CreateProtocolHandler(protocol, url, title);
2247 2262
2248 ProtocolHandlerRegistry* registry = 2263 ProtocolHandlerRegistry* registry =
2249 tcw->profile()->GetProtocolHandlerRegistry(); 2264 tab_contents->profile()->GetProtocolHandlerRegistry();
2250 2265
2251 if (!registry->SilentlyHandleRegisterHandlerRequest(handler)) { 2266 if (!registry->SilentlyHandleRegisterHandlerRequest(handler)) {
2252 content::RecordAction( 2267 content::RecordAction(
2253 UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); 2268 UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown"));
2254 InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); 2269 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
2255 2270
2256 RegisterProtocolHandlerInfoBarDelegate* rph_delegate = 2271 RegisterProtocolHandlerInfoBarDelegate* rph_delegate =
2257 new RegisterProtocolHandlerInfoBarDelegate(infobar_helper, 2272 new RegisterProtocolHandlerInfoBarDelegate(infobar_helper,
2258 registry, 2273 registry,
2259 handler); 2274 handler);
2260 2275
2261 for (size_t i = 0; i < infobar_helper->infobar_count(); i++) { 2276 for (size_t i = 0; i < infobar_helper->infobar_count(); i++) {
2262 InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i); 2277 InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i);
2263 RegisterProtocolHandlerInfoBarDelegate* cast_delegate = 2278 RegisterProtocolHandlerInfoBarDelegate* cast_delegate =
2264 delegate->AsRegisterProtocolHandlerInfoBarDelegate(); 2279 delegate->AsRegisterProtocolHandlerInfoBarDelegate();
2265 if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) { 2280 if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) {
2266 infobar_helper->ReplaceInfoBar(cast_delegate, rph_delegate); 2281 infobar_helper->ReplaceInfoBar(cast_delegate, rph_delegate);
2267 rph_delegate = NULL; 2282 rph_delegate = NULL;
2268 break; 2283 break;
2269 } 2284 }
2270 } 2285 }
2271 2286
2272 if (rph_delegate != NULL) 2287 if (rph_delegate != NULL)
2273 infobar_helper->AddInfoBar(rph_delegate); 2288 infobar_helper->AddInfoBar(rph_delegate);
2274 } 2289 }
2275 } 2290 }
2276 2291
2277 // static 2292 // static
2278 void Browser::FindReplyHelper(WebContents* tab, 2293 void Browser::FindReplyHelper(WebContents* tab,
2279 int request_id, 2294 int request_id,
2280 int number_of_matches, 2295 int number_of_matches,
2281 const gfx::Rect& selection_rect, 2296 const gfx::Rect& selection_rect,
2282 int active_match_ordinal, 2297 int active_match_ordinal,
2283 bool final_update) { 2298 bool final_update) {
2284 TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( 2299 TabContents* tab_contents = TabContents::GetOwningTabContentsForWebContents(
2285 tab); 2300 tab);
2286 if (!tcw || !tcw->find_tab_helper()) 2301 if (!tab_contents || !tab_contents->find_tab_helper())
2287 return; 2302 return;
2288 2303
2289 tcw->find_tab_helper()->HandleFindReply(request_id, number_of_matches, 2304 tab_contents->find_tab_helper()->HandleFindReply(request_id,
2290 selection_rect, active_match_ordinal, 2305 number_of_matches,
2291 final_update); 2306 selection_rect,
2307 active_match_ordinal,
2308 final_update);
2292 } 2309 }
2293 2310
2294 void Browser::ExecuteCommand(int id) { 2311 void Browser::ExecuteCommand(int id) {
2295 ExecuteCommandWithDisposition(id, CURRENT_TAB); 2312 ExecuteCommandWithDisposition(id, CURRENT_TAB);
2296 } 2313 }
2297 2314
2298 void Browser::ExecuteCommand(int id, int event_flags) { 2315 void Browser::ExecuteCommand(int id, int event_flags) {
2299 ExecuteCommandWithDisposition( 2316 ExecuteCommandWithDisposition(
2300 id, browser::DispositionFromEventFlags(event_flags)); 2317 id, browser::DispositionFromEventFlags(event_flags));
2301 } 2318 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2354 last_blocked_command_disposition_ = CURRENT_TAB; 2371 last_blocked_command_disposition_ = CURRENT_TAB;
2355 } 2372 }
2356 } 2373 }
2357 2374
2358 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) { 2375 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) {
2359 if (disposition) 2376 if (disposition)
2360 *disposition = last_blocked_command_disposition_; 2377 *disposition = last_blocked_command_disposition_;
2361 return last_blocked_command_id_; 2378 return last_blocked_command_id_;
2362 } 2379 }
2363 2380
2364 void Browser::UpdateUIForNavigationInTab(TabContentsWrapper* contents, 2381 void Browser::UpdateUIForNavigationInTab(TabContents* contents,
2365 content::PageTransition transition, 2382 content::PageTransition transition,
2366 bool user_initiated) { 2383 bool user_initiated) {
2367 tab_strip_model_->TabNavigating(contents, transition); 2384 tab_strip_model_->TabNavigating(contents, transition);
2368 2385
2369 bool contents_is_selected = contents == GetSelectedTabContentsWrapper(); 2386 bool contents_is_selected = contents == GetActiveTabContents();
2370 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { 2387 if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
2371 // Forcibly reset the location bar if the url is going to change in the 2388 // Forcibly reset the location bar if the url is going to change in the
2372 // current tab, since otherwise it won't discard any ongoing user edits, 2389 // current tab, since otherwise it won't discard any ongoing user edits,
2373 // since it doesn't realize this is a user-initiated action. 2390 // since it doesn't realize this is a user-initiated action.
2374 window()->GetLocationBar()->Revert(); 2391 window()->GetLocationBar()->Revert();
2375 } 2392 }
2376 2393
2377 if (GetStatusBubble()) 2394 if (GetStatusBubble())
2378 GetStatusBubble()->Hide(); 2395 GetStatusBubble()->Hide();
2379 2396
2380 // Update the location bar. This is synchronous. We specifically don't 2397 // Update the location bar. This is synchronous. We specifically don't
2381 // update the load state since the load hasn't started yet and updating it 2398 // update the load state since the load hasn't started yet and updating it
2382 // will put it out of sync with the actual state like whether we're 2399 // will put it out of sync with the actual state like whether we're
2383 // displaying a favicon, which controls the throbber. If we updated it here, 2400 // displaying a favicon, which controls the throbber. If we updated it here,
2384 // the throbber will show the default favicon for a split second when 2401 // the throbber will show the default favicon for a split second when
2385 // navigating away from the new tab page. 2402 // navigating away from the new tab page.
2386 ScheduleUIUpdate(contents->web_contents(), content::INVALIDATE_TYPE_URL); 2403 ScheduleUIUpdate(contents->web_contents(), content::INVALIDATE_TYPE_URL);
2387 2404
2388 if (contents_is_selected) 2405 if (contents_is_selected)
2389 contents->web_contents()->Focus(); 2406 contents->web_contents()->Focus();
2390 } 2407 }
2391 2408
2392 void Browser::ShowCollectedCookiesDialog(TabContentsWrapper* wrapper) { 2409 void Browser::ShowCollectedCookiesDialog(TabContents* tab_contents) {
2393 browser::ShowCollectedCookiesDialog(window()->GetNativeHandle(), wrapper); 2410 browser::ShowCollectedCookiesDialog(window()->GetNativeHandle(),
2411 tab_contents);
2394 } 2412 }
2395 2413
2396 /////////////////////////////////////////////////////////////////////////////// 2414 ///////////////////////////////////////////////////////////////////////////////
2397 // Browser, PageNavigator implementation: 2415 // Browser, PageNavigator implementation:
2398 2416
2399 WebContents* Browser::OpenURL(const OpenURLParams& params) { 2417 WebContents* Browser::OpenURL(const OpenURLParams& params) {
2400 return OpenURLFromTab(NULL, params); 2418 return OpenURLFromTab(NULL, params);
2401 } 2419 }
2402 2420
2403 /////////////////////////////////////////////////////////////////////////////// 2421 ///////////////////////////////////////////////////////////////////////////////
2404 // Browser, CommandUpdater::CommandUpdaterDelegate implementation: 2422 // Browser, CommandUpdater::CommandUpdaterDelegate implementation:
2405 2423
2406 void Browser::ExecuteCommandWithDisposition( 2424 void Browser::ExecuteCommandWithDisposition(
2407 int id, WindowOpenDisposition disposition) { 2425 int id, WindowOpenDisposition disposition) {
2408 // No commands are enabled if there is not yet any selected tab. 2426 // No commands are enabled if there is not yet any selected tab.
2409 // TODO(pkasting): It seems like we should not need this, because either 2427 // TODO(pkasting): It seems like we should not need this, because either
2410 // most/all commands should not have been enabled yet anyway or the ones that 2428 // most/all commands should not have been enabled yet anyway or the ones that
2411 // are enabled should be global, or safe themselves against having no selected 2429 // are enabled should be global, or safe themselves against having no selected
2412 // tab. However, Ben says he tried removing this before and got lots of 2430 // tab. However, Ben says he tried removing this before and got lots of
2413 // crashes, e.g. from Windows sending WM_COMMANDs at random times during 2431 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
2414 // window construction. This probably could use closer examination someday. 2432 // window construction. This probably could use closer examination someday.
2415 if (!GetSelectedTabContentsWrapper()) 2433 if (!GetActiveTabContents())
2416 return; 2434 return;
2417 2435
2418 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " 2436 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
2419 << id; 2437 << id;
2420 2438
2421 // If command execution is blocked then just record the command and return. 2439 // If command execution is blocked then just record the command and return.
2422 if (block_command_execution_) { 2440 if (block_command_execution_) {
2423 // We actually only allow no more than one blocked command, otherwise some 2441 // We actually only allow no more than one blocked command, otherwise some
2424 // commands maybe lost. 2442 // commands maybe lost.
2425 DCHECK_EQ(last_blocked_command_id_, -1); 2443 DCHECK_EQ(last_blocked_command_id_, -1);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 2615
2598 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { 2616 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) {
2599 if (!tab_restore_service_) 2617 if (!tab_restore_service_)
2600 return; 2618 return;
2601 2619
2602 DCHECK_EQ(tab_restore_service_, service); 2620 DCHECK_EQ(tab_restore_service_, service);
2603 tab_restore_service_->RemoveObserver(this); 2621 tab_restore_service_->RemoveObserver(this);
2604 tab_restore_service_ = NULL; 2622 tab_restore_service_ = NULL;
2605 } 2623 }
2606 2624
2607 // Centralized method for creating a TabContentsWrapper, configuring and 2625 // Centralized method for creating a TabContents, configuring and
2608 // installing all its supporting objects and observers. 2626 // installing all its supporting objects and observers.
2609 TabContentsWrapper* Browser::TabContentsFactory( 2627 TabContents* Browser::TabContentsFactory(
2610 Profile* profile, 2628 Profile* profile,
2611 SiteInstance* site_instance, 2629 SiteInstance* site_instance,
2612 int routing_id, 2630 int routing_id,
2613 const WebContents* base_web_contents, 2631 const WebContents* base_web_contents,
2614 content::SessionStorageNamespace* session_storage_namespace) { 2632 content::SessionStorageNamespace* session_storage_namespace) {
2615 WebContents* new_contents = WebContents::Create( 2633 WebContents* new_contents = WebContents::Create(
2616 profile, site_instance, routing_id, base_web_contents, 2634 profile, site_instance, routing_id, base_web_contents,
2617 session_storage_namespace); 2635 session_storage_namespace);
2618 TabContentsWrapper* wrapper = new TabContentsWrapper(new_contents); 2636 TabContents* tab_contents = new TabContents(new_contents);
2619 return wrapper; 2637 return tab_contents;
2620 } 2638 }
2621 2639
2622 /////////////////////////////////////////////////////////////////////////////// 2640 ///////////////////////////////////////////////////////////////////////////////
2623 // Browser, TabStripModelDelegate implementation: 2641 // Browser, TabStripModelDelegate implementation:
2624 2642
2625 TabContentsWrapper* Browser::AddBlankTab(bool foreground) { 2643 TabContents* Browser::AddBlankTab(bool foreground) {
2626 return AddBlankTabAt(-1, foreground); 2644 return AddBlankTabAt(-1, foreground);
2627 } 2645 }
2628 2646
2629 TabContentsWrapper* Browser::AddBlankTabAt(int index, bool foreground) { 2647 TabContents* Browser::AddBlankTabAt(int index, bool foreground) {
2630 // Time new tab page creation time. We keep track of the timing data in 2648 // Time new tab page creation time. We keep track of the timing data in
2631 // WebContents, but we want to include the time it takes to create the 2649 // WebContents, but we want to include the time it takes to create the
2632 // WebContents object too. 2650 // WebContents object too.
2633 base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); 2651 base::TimeTicks new_tab_start_time = base::TimeTicks::Now();
2634 browser::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL), 2652 browser::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL),
2635 content::PAGE_TRANSITION_TYPED); 2653 content::PAGE_TRANSITION_TYPED);
2636 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; 2654 params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB;
2637 params.tabstrip_index = index; 2655 params.tabstrip_index = index;
2638 browser::Navigate(&params); 2656 browser::Navigate(&params);
2639 params.target_contents->web_contents()->SetNewTabStartTime( 2657 params.target_contents->web_contents()->SetNewTabStartTime(
2640 new_tab_start_time); 2658 new_tab_start_time);
2641 return params.target_contents; 2659 return params.target_contents;
2642 } 2660 }
2643 2661
2644 Browser* Browser::CreateNewStripWithContents( 2662 Browser* Browser::CreateNewStripWithContents(
2645 TabContentsWrapper* detached_contents, 2663 TabContents* detached_contents,
2646 const gfx::Rect& window_bounds, 2664 const gfx::Rect& window_bounds,
2647 const DockInfo& dock_info, 2665 const DockInfo& dock_info,
2648 bool maximize) { 2666 bool maximize) {
2649 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); 2667 DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP));
2650 2668
2651 gfx::Rect new_window_bounds = window_bounds; 2669 gfx::Rect new_window_bounds = window_bounds;
2652 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) 2670 if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize))
2653 dock_info.AdjustOtherWindowBounds(); 2671 dock_info.AdjustOtherWindowBounds();
2654 2672
2655 // Create an empty new browser window the same size as the old one. 2673 // Create an empty new browser window the same size as the old one.
2656 Browser* browser = new Browser(TYPE_TABBED, profile_); 2674 Browser* browser = new Browser(TYPE_TABBED, profile_);
2657 browser->set_override_bounds(new_window_bounds); 2675 browser->set_override_bounds(new_window_bounds);
2658 browser->set_show_state( 2676 browser->set_show_state(
2659 maximize ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL); 2677 maximize ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL);
2660 browser->InitBrowserWindow(); 2678 browser->InitBrowserWindow();
2661 browser->tab_strip_model()->AppendTabContents(detached_contents, true); 2679 browser->tab_strip_model()->AppendTabContents(detached_contents, true);
2662 // Make sure the loading state is updated correctly, otherwise the throbber 2680 // Make sure the loading state is updated correctly, otherwise the throbber
2663 // won't start if the page is loading. 2681 // won't start if the page is loading.
2664 browser->LoadingStateChanged(detached_contents->web_contents()); 2682 browser->LoadingStateChanged(detached_contents->web_contents());
2665 return browser; 2683 return browser;
2666 } 2684 }
2667 2685
2668 int Browser::GetDragActions() const { 2686 int Browser::GetDragActions() const {
2669 return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ? 2687 return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ?
2670 TabStripModelDelegate::TAB_MOVE_ACTION : 0); 2688 TabStripModelDelegate::TAB_MOVE_ACTION : 0);
2671 } 2689 }
2672 2690
2673 TabContentsWrapper* Browser::CreateTabContentsForURL( 2691 TabContents* Browser::CreateTabContentsForURL(
2674 const GURL& url, const content::Referrer& referrer, Profile* profile, 2692 const GURL& url, const content::Referrer& referrer, Profile* profile,
2675 content::PageTransition transition, bool defer_load, 2693 content::PageTransition transition, bool defer_load,
2676 SiteInstance* instance) const { 2694 SiteInstance* instance) const {
2677 TabContentsWrapper* contents = TabContentsFactory(profile, instance, 2695 TabContents* contents = TabContentsFactory(profile, instance,
2678 MSG_ROUTING_NONE, 2696 MSG_ROUTING_NONE, GetActiveWebContents(), NULL);
2679 GetSelectedWebContents(), NULL);
2680 if (!defer_load) { 2697 if (!defer_load) {
2681 // Load the initial URL before adding the new tab contents to the tab strip 2698 // Load the initial URL before adding the new tab contents to the tab strip
2682 // so that the tab contents has navigation state. 2699 // so that the tab contents has navigation state.
2683 contents->web_contents()->GetController().LoadURL( 2700 contents->web_contents()->GetController().LoadURL(
2684 url, referrer, transition, std::string()); 2701 url, referrer, transition, std::string());
2685 } 2702 }
2686 2703
2687 return contents; 2704 return contents;
2688 } 2705 }
2689 2706
2690 bool Browser::CanDuplicateContentsAt(int index) { 2707 bool Browser::CanDuplicateContentsAt(int index) {
2691 NavigationController& nc = GetWebContentsAt(index)->GetController(); 2708 NavigationController& nc = GetWebContentsAt(index)->GetController();
2692 return nc.GetWebContents() && nc.GetLastCommittedEntry(); 2709 return nc.GetWebContents() && nc.GetLastCommittedEntry();
2693 } 2710 }
2694 2711
2695 void Browser::DuplicateContentsAt(int index) { 2712 void Browser::DuplicateContentsAt(int index) {
2696 TabContentsWrapper* contents = GetTabContentsWrapperAt(index); 2713 TabContents* contents = GetTabContentsAt(index);
2697 CHECK(contents); 2714 CHECK(contents);
2698 TabContentsWrapper* contents_dupe = contents->Clone(); 2715 TabContents* contents_dupe = contents->Clone();
2699 2716
2700 bool pinned = false; 2717 bool pinned = false;
2701 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 2718 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
2702 // If this is a tabbed browser, just create a duplicate tab inside the same 2719 // If this is a tabbed browser, just create a duplicate tab inside the same
2703 // window next to the tab being duplicated. 2720 // window next to the tab being duplicated.
2704 int index = tab_strip_model_->GetIndexOfTabContents(contents); 2721 int index = tab_strip_model_->GetIndexOfTabContents(contents);
2705 pinned = IsTabPinned(index); 2722 pinned = IsTabPinned(index);
2706 int add_types = TabStripModel::ADD_ACTIVE | 2723 int add_types = TabStripModel::ADD_ACTIVE |
2707 TabStripModel::ADD_INHERIT_GROUP | 2724 TabStripModel::ADD_INHERIT_GROUP |
2708 (pinned ? TabStripModel::ADD_PINNED : 0); 2725 (pinned ? TabStripModel::ADD_PINNED : 0);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2744 #if !defined(OS_MACOSX) 2761 #if !defined(OS_MACOSX)
2745 // This is scheduled to run after we return to the message loop because 2762 // This is scheduled to run after we return to the message loop because
2746 // otherwise the frame will think the drag session is still active and ignore 2763 // otherwise the frame will think the drag session is still active and ignore
2747 // the request. 2764 // the request.
2748 // TODO(port): figure out what is required here in a cross-platform world 2765 // TODO(port): figure out what is required here in a cross-platform world
2749 MessageLoop::current()->PostTask( 2766 MessageLoop::current()->PostTask(
2750 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); 2767 FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr()));
2751 #endif 2768 #endif
2752 } 2769 }
2753 2770
2754 void Browser::CreateHistoricalTab(TabContentsWrapper* contents) { 2771 void Browser::CreateHistoricalTab(TabContents* contents) {
2755 // We don't create historical tabs for incognito windows or windows without 2772 // We don't create historical tabs for incognito windows or windows without
2756 // profiles. 2773 // profiles.
2757 if (!profile() || profile()->IsOffTheRecord()) 2774 if (!profile() || profile()->IsOffTheRecord())
2758 return; 2775 return;
2759 2776
2760 // We don't create historical tabs for print preview tabs. 2777 // We don't create historical tabs for print preview tabs.
2761 if (contents->web_contents()->GetURL() == GURL(chrome::kChromeUIPrintURL)) 2778 if (contents->web_contents()->GetURL() == GURL(chrome::kChromeUIPrintURL))
2762 return; 2779 return;
2763 2780
2764 TabRestoreService* service = 2781 TabRestoreService* service =
2765 TabRestoreServiceFactory::GetForProfile(profile()); 2782 TabRestoreServiceFactory::GetForProfile(profile());
2766 2783
2767 // We only create historical tab entries for tabbed browser windows. 2784 // We only create historical tab entries for tabbed browser windows.
2768 if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) { 2785 if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) {
2769 service->CreateHistoricalTab(&contents->web_contents()->GetController(), 2786 service->CreateHistoricalTab(&contents->web_contents()->GetController(),
2770 tab_strip_model_->GetIndexOfTabContents(contents)); 2787 tab_strip_model_->GetIndexOfTabContents(contents));
2771 } 2788 }
2772 } 2789 }
2773 2790
2774 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { 2791 bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) {
2775 return Browser::RunUnloadEventsHelper(contents->web_contents()); 2792 return Browser::RunUnloadEventsHelper(contents->web_contents());
2776 } 2793 }
2777 2794
2778 bool Browser::CanCloseContents(std::vector<int>* indices) { 2795 bool Browser::CanCloseContents(std::vector<int>* indices) {
2779 DCHECK(!indices->empty()); 2796 DCHECK(!indices->empty());
2780 TabCloseableStateWatcher* watcher = 2797 TabCloseableStateWatcher* watcher =
2781 g_browser_process->tab_closeable_state_watcher(); 2798 g_browser_process->tab_closeable_state_watcher();
2782 bool can_close_all = !watcher || watcher->CanCloseTabs(this, indices); 2799 bool can_close_all = !watcher || watcher->CanCloseTabs(this, indices);
2783 if (indices->empty()) // Cannot close any tab. 2800 if (indices->empty()) // Cannot close any tab.
2784 return false; 2801 return false;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 bool Browser::LargeIconsPermitted() const { 2846 bool Browser::LargeIconsPermitted() const {
2830 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because 2847 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
2831 // for those windows, we already have a big icon in the top-left outside any 2848 // for those windows, we already have a big icon in the top-left outside any
2832 // tab. Having big tab icons too looks kinda redonk. 2849 // tab. Having big tab icons too looks kinda redonk.
2833 return true; 2850 return true;
2834 } 2851 }
2835 2852
2836 /////////////////////////////////////////////////////////////////////////////// 2853 ///////////////////////////////////////////////////////////////////////////////
2837 // Browser, TabStripModelObserver implementation: 2854 // Browser, TabStripModelObserver implementation:
2838 2855
2839 void Browser::TabInsertedAt(TabContentsWrapper* contents, 2856 void Browser::TabInsertedAt(TabContents* contents,
2840 int index, 2857 int index,
2841 bool foreground) { 2858 bool foreground) {
2842 SetAsDelegate(contents, this); 2859 SetAsDelegate(contents, this);
2843 contents->restore_tab_helper()->SetWindowID(session_id()); 2860 contents->restore_tab_helper()->SetWindowID(session_id());
2844 2861
2845 SyncHistoryWithTabs(index); 2862 SyncHistoryWithTabs(index);
2846 2863
2847 // Make sure the loading state is updated correctly, otherwise the throbber 2864 // Make sure the loading state is updated correctly, otherwise the throbber
2848 // won't start if the page is loading. 2865 // won't start if the page is loading.
2849 LoadingStateChanged(contents->web_contents()); 2866 LoadingStateChanged(contents->web_contents());
2850 2867
2851 // If the tab crashes in the beforeunload or unload handler, it won't be 2868 // If the tab crashes in the beforeunload or unload handler, it won't be
2852 // able to ack. But we know we can close it. 2869 // able to ack. But we know we can close it.
2853 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 2870 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2854 content::Source<WebContents>(contents->web_contents())); 2871 content::Source<WebContents>(contents->web_contents()));
2855 2872
2856 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, 2873 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED,
2857 content::Source<WebContents>(contents->web_contents())); 2874 content::Source<WebContents>(contents->web_contents()));
2858 2875
2859 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, 2876 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED,
2860 content::Source<WebContents>(contents->web_contents())); 2877 content::Source<WebContents>(contents->web_contents()));
2861 } 2878 }
2862 2879
2863 void Browser::TabClosingAt(TabStripModel* tab_strip_model, 2880 void Browser::TabClosingAt(TabStripModel* tab_strip_model,
2864 TabContentsWrapper* contents, 2881 TabContents* contents,
2865 int index) { 2882 int index) {
2866 fullscreen_controller_->OnTabClosing(contents->web_contents()); 2883 fullscreen_controller_->OnTabClosing(contents->web_contents());
2867 content::NotificationService::current()->Notify( 2884 content::NotificationService::current()->Notify(
2868 chrome::NOTIFICATION_TAB_CLOSING, 2885 chrome::NOTIFICATION_TAB_CLOSING,
2869 content::Source<NavigationController>( 2886 content::Source<NavigationController>(
2870 &contents->web_contents()->GetController()), 2887 &contents->web_contents()->GetController()),
2871 content::NotificationService::NoDetails()); 2888 content::NotificationService::NoDetails());
2872 2889
2873 // Sever the WebContents' connection back to us. 2890 // Sever the WebContents' connection back to us.
2874 SetAsDelegate(contents, NULL); 2891 SetAsDelegate(contents, NULL);
2875 } 2892 }
2876 2893
2877 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { 2894 void Browser::TabDetachedAt(TabContents* contents, int index) {
2878 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); 2895 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH);
2879 } 2896 }
2880 2897
2881 void Browser::TabDeactivated(TabContentsWrapper* contents) { 2898 void Browser::TabDeactivated(TabContents* contents) {
2882 fullscreen_controller_->OnTabDeactivated(contents); 2899 fullscreen_controller_->OnTabDeactivated(contents);
2883 if (instant()) 2900 if (instant())
2884 instant()->Hide(); 2901 instant()->Hide();
2885 2902
2886 // Save what the user's currently typing, so it can be restored when we 2903 // Save what the user's currently typing, so it can be restored when we
2887 // switch back to this tab. 2904 // switch back to this tab.
2888 window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); 2905 window_->GetLocationBar()->SaveStateToContents(contents->web_contents());
2889 } 2906 }
2890 2907
2891 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, 2908 void Browser::ActiveTabChanged(TabContents* old_contents,
2892 TabContentsWrapper* new_contents, 2909 TabContents* new_contents,
2893 int index, 2910 int index,
2894 bool user_gesture) { 2911 bool user_gesture) {
2895 // On some platforms we want to automatically reload tabs that are 2912 // On some platforms we want to automatically reload tabs that are
2896 // killed when the user selects them. 2913 // killed when the user selects them.
2897 bool did_reload = false; 2914 bool did_reload = false;
2898 if (user_gesture && new_contents->web_contents()->GetCrashedStatus() == 2915 if (user_gesture && new_contents->web_contents()->GetCrashedStatus() ==
2899 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { 2916 base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
2900 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 2917 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
2901 if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) { 2918 if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) {
2902 LOG(WARNING) << "Reloading killed tab at " << index; 2919 LOG(WARNING) << "Reloading killed tab at " << index;
(...skipping 27 matching lines...) Expand all
2930 // Update commands to reflect current state. 2947 // Update commands to reflect current state.
2931 UpdateCommandsForTabState(); 2948 UpdateCommandsForTabState();
2932 2949
2933 // Reset the status bubble. 2950 // Reset the status bubble.
2934 StatusBubble* status_bubble = GetStatusBubble(); 2951 StatusBubble* status_bubble = GetStatusBubble();
2935 if (status_bubble) { 2952 if (status_bubble) {
2936 status_bubble->Hide(); 2953 status_bubble->Hide();
2937 2954
2938 // Show the loading state (if any). 2955 // Show the loading state (if any).
2939 status_bubble->SetStatus( 2956 status_bubble->SetStatus(
2940 GetSelectedTabContentsWrapper()->core_tab_helper()->GetStatusText()); 2957 GetActiveTabContents()->core_tab_helper()->GetStatusText());
2941 } 2958 }
2942 2959
2943 if (HasFindBarController()) { 2960 if (HasFindBarController()) {
2944 find_bar_controller_->ChangeTabContents(new_contents); 2961 find_bar_controller_->ChangeTabContents(new_contents);
2945 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); 2962 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
2946 } 2963 }
2947 2964
2948 // Update sessions. Don't force creation of sessions. If sessions doesn't 2965 // Update sessions. Don't force creation of sessions. If sessions doesn't
2949 // exist, the change will be picked up by sessions when created. 2966 // exist, the change will be picked up by sessions when created.
2950 SessionService* session_service = 2967 SessionService* session_service =
2951 SessionServiceFactory::GetForProfileIfExisting(profile_); 2968 SessionServiceFactory::GetForProfileIfExisting(profile_);
2952 if (session_service && !tab_strip_model_->closing_all()) { 2969 if (session_service && !tab_strip_model_->closing_all()) {
2953 session_service->SetSelectedTabInWindow(session_id(), active_index()); 2970 session_service->SetSelectedTabInWindow(session_id(), active_index());
2954 } 2971 }
2955 2972
2956 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); 2973 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH);
2957 } 2974 }
2958 2975
2959 void Browser::TabMoved(TabContentsWrapper* contents, 2976 void Browser::TabMoved(TabContents* contents,
2960 int from_index, 2977 int from_index,
2961 int to_index) { 2978 int to_index) {
2962 DCHECK(from_index >= 0 && to_index >= 0); 2979 DCHECK(from_index >= 0 && to_index >= 0);
2963 // Notify the history service. 2980 // Notify the history service.
2964 SyncHistoryWithTabs(std::min(from_index, to_index)); 2981 SyncHistoryWithTabs(std::min(from_index, to_index));
2965 } 2982 }
2966 2983
2967 void Browser::TabReplacedAt(TabStripModel* tab_strip_model, 2984 void Browser::TabReplacedAt(TabStripModel* tab_strip_model,
2968 TabContentsWrapper* old_contents, 2985 TabContents* old_contents,
2969 TabContentsWrapper* new_contents, 2986 TabContents* new_contents,
2970 int index) { 2987 int index) {
2971 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); 2988 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE);
2972 TabInsertedAt(new_contents, index, (index == active_index())); 2989 TabInsertedAt(new_contents, index, (index == active_index()));
2973 2990
2974 int entry_count = 2991 int entry_count =
2975 new_contents->web_contents()->GetController().GetEntryCount(); 2992 new_contents->web_contents()->GetController().GetEntryCount();
2976 if (entry_count > 0) { 2993 if (entry_count > 0) {
2977 // Send out notification so that observers are updated appropriately. 2994 // Send out notification so that observers are updated appropriately.
2978 new_contents->web_contents()->GetController().NotifyEntryChanged( 2995 new_contents->web_contents()->GetController().NotifyEntryChanged(
2979 new_contents->web_contents()->GetController().GetEntryAtIndex( 2996 new_contents->web_contents()->GetController().GetEntryAtIndex(
2980 entry_count - 1), 2997 entry_count - 1),
2981 entry_count - 1); 2998 entry_count - 1);
2982 } 2999 }
2983 3000
2984 SessionService* session_service = 3001 SessionService* session_service =
2985 SessionServiceFactory::GetForProfile(profile()); 3002 SessionServiceFactory::GetForProfile(profile());
2986 if (session_service) { 3003 if (session_service) {
2987 // The new_contents may end up with a different navigation stack. Force 3004 // The new_contents may end up with a different navigation stack. Force
2988 // the session service to update itself. 3005 // the session service to update itself.
2989 session_service->TabRestored(new_contents, IsTabPinned(index)); 3006 session_service->TabRestored(new_contents, IsTabPinned(index));
2990 } 3007 }
2991 3008
2992 content::DevToolsManager::GetInstance()->ContentsReplaced( 3009 content::DevToolsManager::GetInstance()->ContentsReplaced(
2993 old_contents->web_contents(), new_contents->web_contents()); 3010 old_contents->web_contents(), new_contents->web_contents());
2994 } 3011 }
2995 3012
2996 void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { 3013 void Browser::TabPinnedStateChanged(TabContents* contents, int index) {
2997 SessionService* session_service = 3014 SessionService* session_service =
2998 SessionServiceFactory::GetForProfileIfExisting(profile()); 3015 SessionServiceFactory::GetForProfileIfExisting(profile());
2999 if (session_service) { 3016 if (session_service) {
3000 session_service->SetPinnedState( 3017 session_service->SetPinnedState(
3001 session_id(), 3018 session_id(),
3002 GetTabContentsWrapperAt(index)->restore_tab_helper()->session_id(), 3019 GetTabContentsAt(index)->restore_tab_helper()->session_id(),
3003 IsTabPinned(index)); 3020 IsTabPinned(index));
3004 } 3021 }
3005 } 3022 }
3006 3023
3007 void Browser::TabStripEmpty() { 3024 void Browser::TabStripEmpty() {
3008 // Close the frame after we return to the message loop (not immediately, 3025 // Close the frame after we return to the message loop (not immediately,
3009 // otherwise it will destroy this object before the stack has a chance to 3026 // otherwise it will destroy this object before the stack has a chance to
3010 // cleanly unwind.) 3027 // cleanly unwind.)
3011 // Note: This will be called several times if TabStripEmpty is called several 3028 // Note: This will be called several times if TabStripEmpty is called several
3012 // times. This is because it does not close the window if tabs are 3029 // times. This is because it does not close the window if tabs are
(...skipping 11 matching lines...) Expand all
3024 fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type); 3041 fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type);
3025 } 3042 }
3026 3043
3027 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { 3044 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) {
3028 fullscreen_controller_->OnDenyFullscreenPermission(bubble_type); 3045 fullscreen_controller_->OnDenyFullscreenPermission(bubble_type);
3029 } 3046 }
3030 3047
3031 bool Browser::TabsNeedBeforeUnloadFired() { 3048 bool Browser::TabsNeedBeforeUnloadFired() {
3032 if (tabs_needing_before_unload_fired_.empty()) { 3049 if (tabs_needing_before_unload_fired_.empty()) {
3033 for (int i = 0; i < tab_count(); ++i) { 3050 for (int i = 0; i < tab_count(); ++i) {
3034 WebContents* contents = GetTabContentsWrapperAt(i)->web_contents(); 3051 WebContents* contents = GetTabContentsAt(i)->web_contents();
3035 if (contents->NeedToFireBeforeUnload()) 3052 if (contents->NeedToFireBeforeUnload())
3036 tabs_needing_before_unload_fired_.insert(contents); 3053 tabs_needing_before_unload_fired_.insert(contents);
3037 } 3054 }
3038 } 3055 }
3039 return !tabs_needing_before_unload_fired_.empty(); 3056 return !tabs_needing_before_unload_fired_.empty();
3040 } 3057 }
3041 3058
3042 bool Browser::IsFullscreenForTabOrPending() const { 3059 bool Browser::IsFullscreenForTabOrPending() const {
3043 return fullscreen_controller_->IsFullscreenForTabOrPending(); 3060 return fullscreen_controller_->IsFullscreenForTabOrPending();
3044 } 3061 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3085 3102
3086 return BrowserWindow::CreateBrowserWindow(this); 3103 return BrowserWindow::CreateBrowserWindow(this);
3087 } 3104 }
3088 3105
3089 /////////////////////////////////////////////////////////////////////////////// 3106 ///////////////////////////////////////////////////////////////////////////////
3090 // Browser, content::WebContentsDelegate implementation: 3107 // Browser, content::WebContentsDelegate implementation:
3091 3108
3092 WebContents* Browser::OpenURLFromTab(WebContents* source, 3109 WebContents* Browser::OpenURLFromTab(WebContents* source,
3093 const OpenURLParams& params) { 3110 const OpenURLParams& params) {
3094 browser::NavigateParams nav_params(this, params.url, params.transition); 3111 browser::NavigateParams nav_params(this, params.url, params.transition);
3095 nav_params.source_contents = GetTabContentsWrapperAt( 3112 nav_params.source_contents = GetTabContentsAt(
3096 tab_strip_model_->GetWrapperIndex(source)); 3113 tab_strip_model_->GetWrapperIndex(source));
3097 nav_params.referrer = params.referrer; 3114 nav_params.referrer = params.referrer;
3098 nav_params.disposition = params.disposition; 3115 nav_params.disposition = params.disposition;
3099 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; 3116 nav_params.tabstrip_add_types = TabStripModel::ADD_NONE;
3100 nav_params.window_action = browser::NavigateParams::SHOW_WINDOW; 3117 nav_params.window_action = browser::NavigateParams::SHOW_WINDOW;
3101 nav_params.user_gesture = true; 3118 nav_params.user_gesture = true;
3102 nav_params.override_encoding = params.override_encoding; 3119 nav_params.override_encoding = params.override_encoding;
3103 nav_params.is_renderer_initiated = params.is_renderer_initiated; 3120 nav_params.is_renderer_initiated = params.is_renderer_initiated;
3104 nav_params.transferred_global_request_id = 3121 nav_params.transferred_global_request_id =
3105 params.transferred_global_request_id; 3122 params.transferred_global_request_id;
(...skipping 21 matching lines...) Expand all
3127 void Browser::AddNewContents(WebContents* source, 3144 void Browser::AddNewContents(WebContents* source,
3128 WebContents* new_contents, 3145 WebContents* new_contents,
3129 WindowOpenDisposition disposition, 3146 WindowOpenDisposition disposition,
3130 const gfx::Rect& initial_pos, 3147 const gfx::Rect& initial_pos,
3131 bool user_gesture) { 3148 bool user_gesture) {
3132 // No code for this yet. 3149 // No code for this yet.
3133 DCHECK(disposition != SAVE_TO_DISK); 3150 DCHECK(disposition != SAVE_TO_DISK);
3134 // Can't create a new contents for the current tab - invalid case. 3151 // Can't create a new contents for the current tab - invalid case.
3135 DCHECK(disposition != CURRENT_TAB); 3152 DCHECK(disposition != CURRENT_TAB);
3136 3153
3137 TabContentsWrapper* source_wrapper = NULL; 3154 TabContents* source_tab_contents = NULL;
3138 BlockedContentTabHelper* source_blocked_content = NULL; 3155 BlockedContentTabHelper* source_blocked_content = NULL;
3139 TabContentsWrapper* new_wrapper = 3156 TabContents* new_tab_contents =
3140 TabContentsWrapper::GetCurrentWrapperForContents(new_contents); 3157 TabContents::GetOwningTabContentsForWebContents(new_contents);
3141 if (!new_wrapper) { 3158 if (!new_tab_contents) {
3142 new_wrapper = new TabContentsWrapper(new_contents); 3159 new_tab_contents = new TabContents(new_contents);
3143 } 3160 }
3144 if (source) { 3161 if (source) {
3145 source_wrapper = TabContentsWrapper::GetCurrentWrapperForContents(source); 3162 source_tab_contents =
3146 source_blocked_content = source_wrapper->blocked_content_tab_helper(); 3163 TabContents::GetOwningTabContentsForWebContents(source);
3164 source_blocked_content = source_tab_contents->blocked_content_tab_helper();
3147 } 3165 }
3148 3166
3149 if (source_wrapper) { 3167 if (source_tab_contents) {
3150 // Handle blocking of all contents. 3168 // Handle blocking of all contents.
3151 if (source_blocked_content->all_contents_blocked()) { 3169 if (source_blocked_content->all_contents_blocked()) {
3152 source_blocked_content->AddTabContents(new_wrapper, 3170 source_blocked_content->AddTabContents(new_tab_contents,
3153 disposition, 3171 disposition,
3154 initial_pos, 3172 initial_pos,
3155 user_gesture); 3173 user_gesture);
3156 return; 3174 return;
3157 } 3175 }
3158 3176
3159 // Handle blocking of popups. 3177 // Handle blocking of popups.
3160 if ((disposition == NEW_POPUP) && !user_gesture && 3178 if ((disposition == NEW_POPUP) && !user_gesture &&
3161 !CommandLine::ForCurrentProcess()->HasSwitch( 3179 !CommandLine::ForCurrentProcess()->HasSwitch(
3162 switches::kDisablePopupBlocking)) { 3180 switches::kDisablePopupBlocking)) {
3163 // Unrequested popups from normal pages are constrained unless they're in 3181 // Unrequested popups from normal pages are constrained unless they're in
3164 // the whitelist. The popup owner will handle checking this. 3182 // the whitelist. The popup owner will handle checking this.
3165 GetConstrainingContentsWrapper(source_wrapper)-> 3183 GetConstrainingContentsWrapper(source_tab_contents)->
3166 blocked_content_tab_helper()-> 3184 blocked_content_tab_helper()->
3167 AddPopup(new_wrapper, initial_pos, user_gesture); 3185 AddPopup(new_tab_contents, initial_pos, user_gesture);
3168 return; 3186 return;
3169 } 3187 }
3170 3188
3171 new_contents->GetRenderViewHost()->DisassociateFromPopupCount(); 3189 new_contents->GetRenderViewHost()->DisassociateFromPopupCount();
3172 } 3190 }
3173 3191
3174 browser::NavigateParams params(this, new_wrapper); 3192 browser::NavigateParams params(this, new_tab_contents);
3175 params.source_contents = source ? 3193 params.source_contents = source ?
3176 GetTabContentsWrapperAt(tab_strip_model_->GetWrapperIndex(source)): NULL; 3194 GetTabContentsAt(tab_strip_model_->GetWrapperIndex(source)): NULL;
3177 params.disposition = disposition; 3195 params.disposition = disposition;
3178 params.window_bounds = initial_pos; 3196 params.window_bounds = initial_pos;
3179 params.window_action = browser::NavigateParams::SHOW_WINDOW; 3197 params.window_action = browser::NavigateParams::SHOW_WINDOW;
3180 params.user_gesture = user_gesture; 3198 params.user_gesture = user_gesture;
3181 browser::Navigate(&params); 3199 browser::Navigate(&params);
3182 } 3200 }
3183 3201
3184 void Browser::ActivateContents(WebContents* contents) { 3202 void Browser::ActivateContents(WebContents* contents) {
3185 ActivateTabAt(tab_strip_model_->GetWrapperIndex(contents), false); 3203 ActivateTabAt(tab_strip_model_->GetWrapperIndex(contents), false);
3186 window_->Activate(); 3204 window_->Activate();
3187 } 3205 }
3188 3206
3189 void Browser::DeactivateContents(WebContents* contents) { 3207 void Browser::DeactivateContents(WebContents* contents) {
3190 window_->Deactivate(); 3208 window_->Deactivate();
3191 } 3209 }
3192 3210
3193 void Browser::LoadingStateChanged(WebContents* source) { 3211 void Browser::LoadingStateChanged(WebContents* source) {
3194 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading()); 3212 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading());
3195 window_->UpdateTitleBar(); 3213 window_->UpdateTitleBar();
3196 3214
3197 WebContents* selected_contents = GetSelectedWebContents(); 3215 WebContents* selected_contents = GetActiveWebContents();
3198 if (source == selected_contents) { 3216 if (source == selected_contents) {
3199 bool is_loading = source->IsLoading(); 3217 bool is_loading = source->IsLoading();
3200 UpdateReloadStopState(is_loading, false); 3218 UpdateReloadStopState(is_loading, false);
3201 if (GetStatusBubble()) { 3219 if (GetStatusBubble()) {
3202 GetStatusBubble()->SetStatus( 3220 GetStatusBubble()->SetStatus(
3203 GetSelectedTabContentsWrapper()->core_tab_helper()->GetStatusText()); 3221 GetActiveTabContents()->core_tab_helper()->GetStatusText());
3204 } 3222 }
3205 3223
3206 if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) { 3224 if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) {
3207 // Schedule a shortcut update when web application info is available if 3225 // Schedule a shortcut update when web application info is available if
3208 // last committed entry is not NULL. Last committed entry could be NULL 3226 // last committed entry is not NULL. Last committed entry could be NULL
3209 // when an interstitial page is injected (e.g. bad https certificate, 3227 // when an interstitial page is injected (e.g. bad https certificate,
3210 // malware site etc). When this happens, we abort the shortcut update. 3228 // malware site etc). When this happens, we abort the shortcut update.
3211 NavigationEntry* entry = source->GetController().GetLastCommittedEntry(); 3229 NavigationEntry* entry = source->GetController().GetLastCommittedEntry();
3212 if (entry) { 3230 if (entry) {
3213 TabContentsWrapper::GetCurrentWrapperForContents(source)-> 3231 TabContents::GetOwningTabContentsForWebContents(source)->
3214 extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); 3232 extension_tab_helper()->GetApplicationInfo(entry->GetPageID());
3215 } else { 3233 } else {
3216 pending_web_app_action_ = NONE; 3234 pending_web_app_action_ = NONE;
3217 } 3235 }
3218 } 3236 }
3219 } 3237 }
3220 } 3238 }
3221 3239
3222 void Browser::CloseContents(WebContents* source) { 3240 void Browser::CloseContents(WebContents* source) {
3223 if (is_attempting_to_close_browser_) { 3241 if (is_attempting_to_close_browser_) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3259 3277
3260 bool Browser::CanReloadContents(WebContents* source) const { 3278 bool Browser::CanReloadContents(WebContents* source) const {
3261 return !is_devtools(); 3279 return !is_devtools();
3262 } 3280 }
3263 3281
3264 void Browser::UpdateTargetURL(WebContents* source, int32 page_id, 3282 void Browser::UpdateTargetURL(WebContents* source, int32 page_id,
3265 const GURL& url) { 3283 const GURL& url) {
3266 if (!GetStatusBubble()) 3284 if (!GetStatusBubble())
3267 return; 3285 return;
3268 3286
3269 if (source == GetSelectedWebContents()) { 3287 if (source == GetActiveWebContents()) {
3270 PrefService* prefs = profile_->GetPrefs(); 3288 PrefService* prefs = profile_->GetPrefs();
3271 GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages)); 3289 GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages));
3272 } 3290 }
3273 } 3291 }
3274 3292
3275 void Browser::ContentsMouseEvent( 3293 void Browser::ContentsMouseEvent(
3276 WebContents* source, const gfx::Point& location, bool motion) { 3294 WebContents* source, const gfx::Point& location, bool motion) {
3277 if (!GetStatusBubble()) 3295 if (!GetStatusBubble())
3278 return; 3296 return;
3279 3297
3280 if (source == GetSelectedWebContents()) { 3298 if (source == GetActiveWebContents()) {
3281 GetStatusBubble()->MouseMoved(location, !motion); 3299 GetStatusBubble()->MouseMoved(location, !motion);
3282 if (!motion) 3300 if (!motion)
3283 GetStatusBubble()->SetURL(GURL(), std::string()); 3301 GetStatusBubble()->SetURL(GURL(), std::string());
3284 } 3302 }
3285 } 3303 }
3286 3304
3287 void Browser::ContentsZoomChange(bool zoom_in) { 3305 void Browser::ContentsZoomChange(bool zoom_in) {
3288 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); 3306 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS);
3289 } 3307 }
3290 3308
(...skipping 14 matching lines...) Expand all
3305 } 3323 }
3306 3324
3307 void Browser::ConvertContentsToApplication(WebContents* contents) { 3325 void Browser::ConvertContentsToApplication(WebContents* contents) {
3308 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); 3326 const GURL& url = contents->GetController().GetActiveEntry()->GetURL();
3309 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 3327 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
3310 3328
3311 DetachContents(contents); 3329 DetachContents(contents);
3312 Browser* app_browser = Browser::CreateWithParams( 3330 Browser* app_browser = Browser::CreateWithParams(
3313 Browser::CreateParams::CreateForApp( 3331 Browser::CreateParams::CreateForApp(
3314 TYPE_POPUP, app_name, gfx::Rect(), profile_)); 3332 TYPE_POPUP, app_name, gfx::Rect(), profile_));
3315 TabContentsWrapper* wrapper = 3333 TabContents* tab_contents =
3316 TabContentsWrapper::GetCurrentWrapperForContents(contents); 3334 TabContents::GetOwningTabContentsForWebContents(contents);
3317 if (!wrapper) 3335 if (!tab_contents)
3318 wrapper = new TabContentsWrapper(contents); 3336 tab_contents = new TabContents(contents);
3319 app_browser->tab_strip_model()->AppendTabContents(wrapper, true); 3337 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true);
3320 3338
3321 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 3339 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
3322 contents->GetRenderViewHost()->SyncRendererPrefs(); 3340 contents->GetRenderViewHost()->SyncRendererPrefs();
3323 app_browser->window()->Show(); 3341 app_browser->window()->Show();
3324 } 3342 }
3325 3343
3326 gfx::Rect Browser::GetRootWindowResizerRect() const { 3344 gfx::Rect Browser::GetRootWindowResizerRect() const {
3327 return window_->GetRootWindowResizerRect(); 3345 return window_->GetRootWindowResizerRect();
3328 } 3346 }
3329 3347
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3373 void Browser::RenderWidgetShowing() { 3391 void Browser::RenderWidgetShowing() {
3374 window_->DisableInactiveFrame(); 3392 window_->DisableInactiveFrame();
3375 } 3393 }
3376 3394
3377 int Browser::GetExtraRenderViewHeight() const { 3395 int Browser::GetExtraRenderViewHeight() const {
3378 return window_->GetExtraRenderViewHeight(); 3396 return window_->GetExtraRenderViewHeight();
3379 } 3397 }
3380 3398
3381 void Browser::OnStartDownload(WebContents* source, 3399 void Browser::OnStartDownload(WebContents* source,
3382 content::DownloadItem* download) { 3400 content::DownloadItem* download) {
3383 TabContentsWrapper* wrapper = 3401 TabContents* tab_contents =
3384 TabContentsWrapper::GetCurrentWrapperForContents(source); 3402 TabContents::GetOwningTabContentsForWebContents(source);
3385 TabContentsWrapper* constrained = GetConstrainingContentsWrapper(wrapper); 3403 TabContents* constrained = GetConstrainingContentsWrapper(tab_contents);
3386 if (constrained != wrapper) { 3404 if (constrained != tab_contents) {
3387 // Download in a constrained popup is shown in the tab that opened it. 3405 // Download in a constrained popup is shown in the tab that opened it.
3388 WebContents* constrained_tab = constrained->web_contents(); 3406 WebContents* constrained_tab = constrained->web_contents();
3389 constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download); 3407 constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download);
3390 return; 3408 return;
3391 } 3409 }
3392 3410
3393 if (!window()) 3411 if (!window())
3394 return; 3412 return;
3395 3413
3396 if (DisplayOldDownloadsUI()) { 3414 if (DisplayOldDownloadsUI()) {
3397 // GetDownloadShelf creates the download shelf if it was not yet created. 3415 // GetDownloadShelf creates the download shelf if it was not yet created.
3398 DownloadShelf* shelf = window()->GetDownloadShelf(); 3416 DownloadShelf* shelf = window()->GetDownloadShelf();
3399 shelf->AddDownload(new DownloadItemModel(download)); 3417 shelf->AddDownload(new DownloadItemModel(download));
3400 // Don't show the animation for "Save file" downloads. 3418 // Don't show the animation for "Save file" downloads.
3401 // For non-theme extensions, we don't show the download animation. 3419 // For non-theme extensions, we don't show the download animation.
3402 // Show animation in same window as the download shelf. Download shelf 3420 // Show animation in same window as the download shelf. Download shelf
3403 // may not be in the same window that initiated the download, e.g. 3421 // may not be in the same window that initiated the download, e.g.
3404 // Panels. 3422 // Panels.
3405 // Don't show the animation if the selected tab is not visible (i.e. the 3423 // Don't show the animation if the selected tab is not visible (i.e. the
3406 // window is minimized, we're in a unit test, etc.). 3424 // window is minimized, we're in a unit test, etc.).
3407 WebContents* shelf_tab = shelf->browser()->GetSelectedWebContents(); 3425 WebContents* shelf_tab = shelf->browser()->GetActiveWebContents();
3408 if ((download->GetTotalBytes() > 0) && 3426 if ((download->GetTotalBytes() > 0) &&
3409 !download_crx_util::IsExtensionDownload(*download) && 3427 !download_crx_util::IsExtensionDownload(*download) &&
3410 platform_util::IsVisible(shelf_tab->GetNativeView()) && 3428 platform_util::IsVisible(shelf_tab->GetNativeView()) &&
3411 ui::Animation::ShouldRenderRichAnimation()) { 3429 ui::Animation::ShouldRenderRichAnimation()) {
3412 DownloadStartedAnimation::Show(shelf_tab); 3430 DownloadStartedAnimation::Show(shelf_tab);
3413 } 3431 }
3414 } 3432 }
3415 3433
3416 // If the download occurs in a new tab, close it. 3434 // If the download occurs in a new tab, close it.
3417 if (source->GetController().IsInitialNavigation() && tab_count() > 1) 3435 if (source->GetController().IsInitialNavigation() && tab_count() > 1)
3418 CloseContents(source); 3436 CloseContents(source);
3419 } 3437 }
3420 3438
3421 void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { 3439 void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) {
3422 DCHECK(source); 3440 DCHECK(source);
3423 TabContentsWrapper* wrapper = GetTabContentsWrapperAt( 3441 TabContents* tab_contents = GetTabContentsAt(
3424 tab_strip_model_->GetWrapperIndex(source)); 3442 tab_strip_model_->GetWrapperIndex(source));
3425 ViewSource(wrapper); 3443 ViewSource(tab_contents);
3426 } 3444 }
3427 3445
3428 void Browser::ViewSourceForFrame(WebContents* source, 3446 void Browser::ViewSourceForFrame(WebContents* source,
3429 const GURL& frame_url, 3447 const GURL& frame_url,
3430 const std::string& frame_content_state) { 3448 const std::string& frame_content_state) {
3431 DCHECK(source); 3449 DCHECK(source);
3432 TabContentsWrapper* wrapper = GetTabContentsWrapperAt( 3450 TabContents* tab_contents = GetTabContentsAt(
3433 tab_strip_model_->GetWrapperIndex(source)); 3451 tab_strip_model_->GetWrapperIndex(source));
3434 ViewSource(wrapper, frame_url, frame_content_state); 3452 ViewSource(tab_contents, frame_url, frame_content_state);
3435 } 3453 }
3436 3454
3437 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, 3455 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
3438 bool* is_keyboard_shortcut) { 3456 bool* is_keyboard_shortcut) {
3439 // Escape exits tabbed fullscreen mode. 3457 // Escape exits tabbed fullscreen mode.
3440 // TODO(koz): Write a test for this http://crbug.com/100441. 3458 // TODO(koz): Write a test for this http://crbug.com/100441.
3441 if (event.windowsKeyCode == 27 && 3459 if (event.windowsKeyCode == 27 &&
3442 fullscreen_controller_->HandleUserPressedEscape()) { 3460 fullscreen_controller_->HandleUserPressedEscape()) {
3443 return true; 3461 return true;
3444 } 3462 }
3445 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); 3463 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
3446 } 3464 }
3447 3465
3448 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { 3466 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
3449 window()->HandleKeyboardEvent(event); 3467 window()->HandleKeyboardEvent(event);
3450 } 3468 }
3451 3469
3452 void Browser::ShowRepostFormWarningDialog(WebContents* source) { 3470 void Browser::ShowRepostFormWarningDialog(WebContents* source) {
3453 browser::ShowTabModalConfirmDialog( 3471 browser::ShowTabModalConfirmDialog(
3454 new RepostFormWarningController(source), 3472 new RepostFormWarningController(source),
3455 TabContentsWrapper::GetCurrentWrapperForContents(source)); 3473 TabContents::GetOwningTabContentsForWebContents(source));
3456 } 3474 }
3457 3475
3458 bool Browser::ShouldAddNavigationToHistory( 3476 bool Browser::ShouldAddNavigationToHistory(
3459 const history::HistoryAddPageArgs& add_page_args, 3477 const history::HistoryAddPageArgs& add_page_args,
3460 content::NavigationType navigation_type) { 3478 content::NavigationType navigation_type) {
3461 // Don't update history if running as app. 3479 // Don't update history if running as app.
3462 return !IsApplication(); 3480 return !IsApplication();
3463 } 3481 }
3464 3482
3465 bool Browser::ShouldCreateWebContents( 3483 bool Browser::ShouldCreateWebContents(
3466 WebContents* web_contents, 3484 WebContents* web_contents,
3467 int route_id, 3485 int route_id,
3468 WindowContainerType window_container_type, 3486 WindowContainerType window_container_type,
3469 const string16& frame_name, 3487 const string16& frame_name,
3470 const GURL& target_url) { 3488 const GURL& target_url) {
3471 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { 3489 if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
3472 // If a BackgroundContents is created, suppress the normal WebContents. 3490 // If a BackgroundContents is created, suppress the normal WebContents.
3473 return !MaybeCreateBackgroundContents( 3491 return !MaybeCreateBackgroundContents(
3474 route_id, web_contents, frame_name, target_url); 3492 route_id, web_contents, frame_name, target_url);
3475 } 3493 }
3476 3494
3477 return true; 3495 return true;
3478 } 3496 }
3479 3497
3480 void Browser::WebContentsCreated(WebContents* source_contents, 3498 void Browser::WebContentsCreated(WebContents* source_contents,
3481 int64 source_frame_id, 3499 int64 source_frame_id,
3482 const GURL& target_url, 3500 const GURL& target_url,
3483 WebContents* new_contents) { 3501 WebContents* new_contents) {
3484 // Create a TabContentsWrapper now, so all observers are in place, as the 3502 // Create a TabContents now, so all observers are in place, as the network
3485 // network requests for its initial navigation will start immediately. The 3503 // requests for its initial navigation will start immediately. The WebContents
3486 // WebContents will later be inserted into this browser using 3504 // will later be inserted into this browser using Browser::Navigate via
3487 // Browser::Navigate via AddNewContents. The latter will retrieve the newly 3505 // AddNewContents. The latter will retrieve the newly created TabContents from
3488 // created TabContentsWrapper from WebContents object. 3506 // WebContents object.
3489 new TabContentsWrapper(new_contents); 3507 new TabContents(new_contents);
3490 3508
3491 // Notify. 3509 // Notify.
3492 RetargetingDetails details; 3510 RetargetingDetails details;
3493 details.source_web_contents = source_contents; 3511 details.source_web_contents = source_contents;
3494 details.source_frame_id = source_frame_id; 3512 details.source_frame_id = source_frame_id;
3495 details.target_url = target_url; 3513 details.target_url = target_url;
3496 details.target_web_contents = new_contents; 3514 details.target_web_contents = new_contents;
3497 details.not_yet_in_tabstrip = true; 3515 details.not_yet_in_tabstrip = true;
3498 content::NotificationService::current()->Notify( 3516 content::NotificationService::current()->Notify(
3499 chrome::NOTIFICATION_RETARGETING, 3517 chrome::NOTIFICATION_RETARGETING,
3500 content::Source<Profile>(profile_), 3518 content::Source<Profile>(profile_),
3501 content::Details<RetargetingDetails>(&details)); 3519 content::Details<RetargetingDetails>(&details));
3502 } 3520 }
3503 3521
3504 void Browser::ContentRestrictionsChanged(WebContents* source) { 3522 void Browser::ContentRestrictionsChanged(WebContents* source) {
3505 UpdateCommandsForContentRestrictionState(); 3523 UpdateCommandsForContentRestrictionState();
3506 } 3524 }
3507 3525
3508 void Browser::RendererUnresponsive(WebContents* source) { 3526 void Browser::RendererUnresponsive(WebContents* source) {
3509 // Ignore hangs if print preview is open. 3527 // Ignore hangs if print preview is open.
3510 TabContentsWrapper* source_wrapper = 3528 TabContents* tab_contents =
3511 TabContentsWrapper::GetCurrentWrapperForContents(source); 3529 TabContents::GetOwningTabContentsForWebContents(source);
3512 if (source_wrapper) { 3530 if (tab_contents) {
3513 printing::PrintPreviewTabController* controller = 3531 printing::PrintPreviewTabController* controller =
3514 printing::PrintPreviewTabController::GetInstance(); 3532 printing::PrintPreviewTabController::GetInstance();
3515 if (controller) { 3533 if (controller) {
3516 TabContentsWrapper* preview_tab = 3534 TabContents* preview_tab =
3517 controller->GetPrintPreviewForTab(source_wrapper); 3535 controller->GetPrintPreviewForTab(tab_contents);
3518 if (preview_tab && preview_tab != source_wrapper) { 3536 if (preview_tab && preview_tab != tab_contents) {
3519 return; 3537 return;
3520 } 3538 }
3521 } 3539 }
3522 } 3540 }
3523 3541
3524 browser::ShowHungRendererDialog(source); 3542 browser::ShowHungRendererDialog(source);
3525 } 3543 }
3526 3544
3527 void Browser::RendererResponsive(WebContents* source) { 3545 void Browser::RendererResponsive(WebContents* source) {
3528 browser::HideHungRendererDialog(source); 3546 browser::HideHungRendererDialog(source);
3529 } 3547 }
3530 3548
3531 void Browser::WorkerCrashed(WebContents* source) { 3549 void Browser::WorkerCrashed(WebContents* source) {
3532 TabContentsWrapper* wrapper = 3550 TabContents* tab_contents =
3533 TabContentsWrapper::GetCurrentWrapperForContents(source); 3551 TabContents::GetOwningTabContentsForWebContents(source);
3534 InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); 3552 InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper();
3535 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( 3553 infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate(
3536 infobar_helper, 3554 infobar_helper,
3537 NULL, 3555 NULL,
3538 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), 3556 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
3539 true)); 3557 true));
3540 } 3558 }
3541 3559
3542 void Browser::DidNavigateMainFramePostCommit(WebContents* tab) { 3560 void Browser::DidNavigateMainFramePostCommit(WebContents* tab) {
3543 if (tab == GetSelectedWebContents()) 3561 if (tab == GetActiveWebContents())
3544 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 3562 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
3545 } 3563 }
3546 3564
3547 void Browser::DidNavigateToPendingEntry(WebContents* tab) { 3565 void Browser::DidNavigateToPendingEntry(WebContents* tab) {
3548 if (tab == GetSelectedWebContents()) 3566 if (tab == GetActiveWebContents())
3549 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 3567 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
3550 } 3568 }
3551 3569
3552 content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { 3570 content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() {
3553 return GetJavaScriptDialogCreatorInstance(); 3571 return GetJavaScriptDialogCreatorInstance();
3554 } 3572 }
3555 3573
3556 content::ColorChooser* Browser::OpenColorChooser(WebContents* tab, 3574 content::ColorChooser* Browser::OpenColorChooser(WebContents* tab,
3557 int color_chooser_id, 3575 int color_chooser_id,
3558 SkColor color) { 3576 SkColor color) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 RegisterIntentHandlerHelper(tab, data, user_gesture); 3632 RegisterIntentHandlerHelper(tab, data, user_gesture);
3615 } 3633 }
3616 3634
3617 void Browser::WebIntentDispatch( 3635 void Browser::WebIntentDispatch(
3618 WebContents* tab, content::WebIntentsDispatcher* intents_dispatcher) { 3636 WebContents* tab, content::WebIntentsDispatcher* intents_dispatcher) {
3619 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) 3637 if (!web_intents::IsWebIntentsEnabledForProfile(profile_))
3620 return; 3638 return;
3621 3639
3622 UMA_HISTOGRAM_COUNTS("WebIntents.Dispatch", 1); 3640 UMA_HISTOGRAM_COUNTS("WebIntents.Dispatch", 1);
3623 3641
3624 TabContentsWrapper* tcw = 3642 TabContents* tab_contents =
3625 TabContentsWrapper::GetCurrentWrapperForContents(tab); 3643 TabContents::GetOwningTabContentsForWebContents(tab);
3626 tcw->web_intent_picker_controller()->SetIntentsDispatcher(intents_dispatcher); 3644 tab_contents->web_intent_picker_controller()->SetIntentsDispatcher(
3627 tcw->web_intent_picker_controller()->ShowDialog( 3645 intents_dispatcher);
3646 tab_contents->web_intent_picker_controller()->ShowDialog(
3628 intents_dispatcher->GetIntent().action, 3647 intents_dispatcher->GetIntent().action,
3629 intents_dispatcher->GetIntent().type); 3648 intents_dispatcher->GetIntent().type);
3630 } 3649 }
3631 3650
3632 void Browser::UpdatePreferredSize(WebContents* source, 3651 void Browser::UpdatePreferredSize(WebContents* source,
3633 const gfx::Size& pref_size) { 3652 const gfx::Size& pref_size) {
3634 window_->UpdatePreferredSize(source, pref_size); 3653 window_->UpdatePreferredSize(source, pref_size);
3635 } 3654 }
3636 3655
3637 void Browser::ResizeDueToAutoResize(WebContents* source, 3656 void Browser::ResizeDueToAutoResize(WebContents* source,
(...skipping 19 matching lines...) Expand all
3657 last_unlocked_by_target); 3676 last_unlocked_by_target);
3658 } 3677 }
3659 3678
3660 void Browser::LostMouseLock() { 3679 void Browser::LostMouseLock() {
3661 fullscreen_controller_->LostMouseLock(); 3680 fullscreen_controller_->LostMouseLock();
3662 } 3681 }
3663 3682
3664 /////////////////////////////////////////////////////////////////////////////// 3683 ///////////////////////////////////////////////////////////////////////////////
3665 // Browser, CoreTabHelperDelegate implementation: 3684 // Browser, CoreTabHelperDelegate implementation:
3666 3685
3667 void Browser::SwapTabContents(TabContentsWrapper* old_tab_contents, 3686 void Browser::SwapTabContents(TabContents* old_tab_contents,
3668 TabContentsWrapper* new_tab_contents) { 3687 TabContents* new_tab_contents) {
3669 int index = tab_strip_model_->GetIndexOfTabContents(old_tab_contents); 3688 int index = tab_strip_model_->GetIndexOfTabContents(old_tab_contents);
3670 DCHECK_NE(TabStripModel::kNoTab, index); 3689 DCHECK_NE(TabStripModel::kNoTab, index);
3671 tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents); 3690 tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents);
3672 } 3691 }
3673 3692
3674 /////////////////////////////////////////////////////////////////////////////// 3693 ///////////////////////////////////////////////////////////////////////////////
3675 // Browser, SearchEngineTabHelperDelegate implementation: 3694 // Browser, SearchEngineTabHelperDelegate implementation:
3676 3695
3677 void Browser::ConfirmAddSearchProvider(TemplateURL* template_url, 3696 void Browser::ConfirmAddSearchProvider(TemplateURL* template_url,
3678 Profile* profile) { 3697 Profile* profile) {
3679 window()->ConfirmAddSearchProvider(template_url, profile); 3698 window()->ConfirmAddSearchProvider(template_url, profile);
3680 } 3699 }
3681 3700
3682 /////////////////////////////////////////////////////////////////////////////// 3701 ///////////////////////////////////////////////////////////////////////////////
3683 // Browser, ConstrainedWindowTabHelperDelegate implementation: 3702 // Browser, ConstrainedWindowTabHelperDelegate implementation:
3684 3703
3685 void Browser::SetTabContentBlocked(TabContentsWrapper* wrapper, bool blocked) { 3704 void Browser::SetTabContentBlocked(TabContents* tab_contents, bool blocked) {
3686 int index = tab_strip_model_->GetIndexOfTabContents(wrapper); 3705 int index = tab_strip_model_->GetIndexOfTabContents(tab_contents);
3687 if (index == TabStripModel::kNoTab) { 3706 if (index == TabStripModel::kNoTab) {
3688 NOTREACHED(); 3707 NOTREACHED();
3689 return; 3708 return;
3690 } 3709 }
3691 tab_strip_model_->SetTabBlocked(index, blocked); 3710 tab_strip_model_->SetTabBlocked(index, blocked);
3692 UpdatePrintingState(wrapper->web_contents()->GetContentRestrictions()); 3711 UpdatePrintingState(tab_contents->web_contents()->GetContentRestrictions());
3693 if (!blocked && GetSelectedTabContentsWrapper() == wrapper) 3712 if (!blocked && GetActiveTabContents() == tab_contents)
3694 wrapper->web_contents()->Focus(); 3713 tab_contents->web_contents()->Focus();
3695 } 3714 }
3696 3715
3697 /////////////////////////////////////////////////////////////////////////////// 3716 ///////////////////////////////////////////////////////////////////////////////
3698 // Browser, BlockedContentTabHelperDelegate implementation: 3717 // Browser, BlockedContentTabHelperDelegate implementation:
3699 3718
3700 TabContentsWrapper* Browser::GetConstrainingContentsWrapper( 3719 TabContents* Browser::GetConstrainingContentsWrapper(TabContents* source) {
3701 TabContentsWrapper* source) {
3702 return source; 3720 return source;
3703 } 3721 }
3704 3722
3705 /////////////////////////////////////////////////////////////////////////////// 3723 ///////////////////////////////////////////////////////////////////////////////
3706 // Browser, BookmarkTabHelperDelegate implementation: 3724 // Browser, BookmarkTabHelperDelegate implementation:
3707 3725
3708 void Browser::URLStarredChanged(TabContentsWrapper* source, bool starred) { 3726 void Browser::URLStarredChanged(TabContents* source, bool starred) {
3709 if (source == GetSelectedTabContentsWrapper()) 3727 if (source == GetActiveTabContents())
3710 window_->SetStarredState(starred); 3728 window_->SetStarredState(starred);
3711 } 3729 }
3712 3730
3713 /////////////////////////////////////////////////////////////////////////////// 3731 ///////////////////////////////////////////////////////////////////////////////
3714 // Browser, ZoomObserver implementation: 3732 // Browser, ZoomObserver implementation:
3715 3733
3716 void Browser::OnZoomIconChanged(TabContentsWrapper* source, 3734 void Browser::OnZoomIconChanged(TabContents* source,
3717 ZoomController::ZoomIconState state) { 3735 ZoomController::ZoomIconState state) {
3718 if (source == GetSelectedTabContentsWrapper()) 3736 if (source == GetActiveTabContents())
3719 window_->SetZoomIconState(state); 3737 window_->SetZoomIconState(state);
3720 } 3738 }
3721 3739
3722 void Browser::OnZoomChanged(TabContentsWrapper* source, 3740 void Browser::OnZoomChanged(TabContents* source,
3723 int zoom_percent, 3741 int zoom_percent,
3724 bool can_show_bubble) { 3742 bool can_show_bubble) {
3725 if (source == GetSelectedTabContentsWrapper()) { 3743 if (source == GetActiveTabContents()) {
3726 window_->SetZoomIconTooltipPercent(zoom_percent); 3744 window_->SetZoomIconTooltipPercent(zoom_percent);
3727 3745
3728 // Only show the zoom bubble for zoom changes in the active window. 3746 // Only show the zoom bubble for zoom changes in the active window.
3729 if (can_show_bubble && window_->IsActive()) 3747 if (can_show_bubble && window_->IsActive())
3730 window_->ShowZoomBubble(zoom_percent); 3748 window_->ShowZoomBubble(zoom_percent);
3731 } 3749 }
3732 } 3750 }
3733 3751
3734 /////////////////////////////////////////////////////////////////////////////// 3752 ///////////////////////////////////////////////////////////////////////////////
3735 // Browser, ExtensionTabHelperDelegate implementation: 3753 // Browser, ExtensionTabHelperDelegate implementation:
3736 3754
3737 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, 3755 void Browser::OnDidGetApplicationInfo(TabContents* source,
3738 int32 page_id) { 3756 int32 page_id) {
3739 if (GetSelectedTabContentsWrapper() != source) 3757 if (GetActiveTabContents() != source)
3740 return; 3758 return;
3741 3759
3742 NavigationEntry* entry = 3760 NavigationEntry* entry =
3743 source->web_contents()->GetController().GetLastCommittedEntry(); 3761 source->web_contents()->GetController().GetLastCommittedEntry();
3744 if (!entry || (entry->GetPageID() != page_id)) 3762 if (!entry || (entry->GetPageID() != page_id))
3745 return; 3763 return;
3746 3764
3747 switch (pending_web_app_action_) { 3765 switch (pending_web_app_action_) {
3748 case CREATE_SHORTCUT: { 3766 case CREATE_SHORTCUT: {
3749 window()->ShowCreateWebAppShortcutsDialog(source); 3767 window()->ShowCreateWebAppShortcutsDialog(source);
3750 break; 3768 break;
3751 } 3769 }
3752 case UPDATE_SHORTCUT: { 3770 case UPDATE_SHORTCUT: {
3753 web_app::UpdateShortcutForTabContents(source); 3771 web_app::UpdateShortcutForTabContents(source);
3754 break; 3772 break;
3755 } 3773 }
3756 default: 3774 default:
3757 NOTREACHED(); 3775 NOTREACHED();
3758 break; 3776 break;
3759 } 3777 }
3760 3778
3761 pending_web_app_action_ = NONE; 3779 pending_web_app_action_ = NONE;
3762 } 3780 }
3763 3781
3764 void Browser::OnInstallApplication(TabContentsWrapper* source, 3782 void Browser::OnInstallApplication(TabContents* source,
3765 const WebApplicationInfo& web_app) { 3783 const WebApplicationInfo& web_app) {
3766 ExtensionService* extension_service = profile()->GetExtensionService(); 3784 ExtensionService* extension_service = profile()->GetExtensionService();
3767 if (!extension_service) 3785 if (!extension_service)
3768 return; 3786 return;
3769 3787
3770 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create( 3788 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(
3771 extension_service, 3789 extension_service,
3772 extension_service->show_extensions_prompts() ? 3790 extension_service->show_extensions_prompts() ?
3773 new ExtensionInstallUI(profile()) : NULL)); 3791 new ExtensionInstallUI(profile()) : NULL));
3774 installer->InstallWebApp(web_app); 3792 installer->InstallWebApp(web_app);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3809 } 3827 }
3810 break; 3828 break;
3811 3829
3812 case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED: 3830 case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED:
3813 // When the current tab's SSL state changes, we need to update the URL 3831 // When the current tab's SSL state changes, we need to update the URL
3814 // bar to reflect the new state. Note that it's possible for the selected 3832 // bar to reflect the new state. Note that it's possible for the selected
3815 // tab contents to be NULL. This is because we listen for all sources 3833 // tab contents to be NULL. This is because we listen for all sources
3816 // (NavigationControllers) for convenience, so the notification could 3834 // (NavigationControllers) for convenience, so the notification could
3817 // actually be for a different window while we're doing asynchronous 3835 // actually be for a different window while we're doing asynchronous
3818 // closing of this one. 3836 // closing of this one.
3819 if (GetSelectedWebContents() && 3837 if (GetActiveWebContents() &&
3820 &GetSelectedWebContents()->GetController() == 3838 &GetActiveWebContents()->GetController() ==
3821 content::Source<NavigationController>(source).ptr()) 3839 content::Source<NavigationController>(source).ptr())
3822 UpdateToolbar(false); 3840 UpdateToolbar(false);
3823 break; 3841 break;
3824 3842
3825 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 3843 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
3826 if (window()->GetLocationBar()) 3844 if (window()->GetLocationBar())
3827 window()->GetLocationBar()->UpdatePageActions(); 3845 window()->GetLocationBar()->UpdatePageActions();
3828 3846
3829 // Close any tabs from the unloaded extension, unless it's terminated, 3847 // Close any tabs from the unloaded extension, unless it's terminated,
3830 // in which case let the sad tabs remain. 3848 // in which case let the sad tabs remain.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3910 } else if (pref_name == prefs::kInManagedMode) { 3928 } else if (pref_name == prefs::kInManagedMode) {
3911 UpdateCommandsForMultipleProfiles(); 3929 UpdateCommandsForMultipleProfiles();
3912 } else { 3930 } else {
3913 NOTREACHED(); 3931 NOTREACHED();
3914 } 3932 }
3915 break; 3933 break;
3916 } 3934 }
3917 3935
3918 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { 3936 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
3919 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 3937 WebContents* web_contents = content::Source<WebContents>(source).ptr();
3920 if (web_contents == GetSelectedWebContents()) { 3938 if (web_contents == GetActiveWebContents()) {
3921 LocationBar* location_bar = window()->GetLocationBar(); 3939 LocationBar* location_bar = window()->GetLocationBar();
3922 if (location_bar) 3940 if (location_bar)
3923 location_bar->UpdateContentSettingsIcons(); 3941 location_bar->UpdateContentSettingsIcons();
3924 } 3942 }
3925 break; 3943 break;
3926 } 3944 }
3927 3945
3928 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: 3946 case content::NOTIFICATION_INTERSTITIAL_ATTACHED:
3929 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 3947 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
3930 UpdateCommandsForTabState(); 3948 UpdateCommandsForTabState();
(...skipping 19 matching lines...) Expand all
3950 if (!window_) 3968 if (!window_)
3951 return; 3969 return;
3952 const bool show_main_ui = IsShowingMainUI(window_->IsFullscreen()); 3970 const bool show_main_ui = IsShowingMainUI(window_->IsFullscreen());
3953 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, 3971 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
3954 show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible()); 3972 show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible());
3955 } 3973 }
3956 3974
3957 /////////////////////////////////////////////////////////////////////////////// 3975 ///////////////////////////////////////////////////////////////////////////////
3958 // Browser, InstantDelegate implementation: 3976 // Browser, InstantDelegate implementation:
3959 3977
3960 void Browser::ShowInstant(TabContentsWrapper* preview_contents) { 3978 void Browser::ShowInstant(TabContents* preview_contents) {
3961 window_->ShowInstant(preview_contents); 3979 window_->ShowInstant(preview_contents);
3962 3980
3963 GetSelectedWebContents()->HideContents(); 3981 GetActiveWebContents()->HideContents();
3964 preview_contents->web_contents()->ShowContents(); 3982 preview_contents->web_contents()->ShowContents();
3965 } 3983 }
3966 3984
3967 void Browser::HideInstant() { 3985 void Browser::HideInstant() {
3968 window_->HideInstant(); 3986 window_->HideInstant();
3969 if (GetSelectedWebContents()) 3987 if (GetActiveWebContents())
3970 GetSelectedWebContents()->ShowContents(); 3988 GetActiveWebContents()->ShowContents();
3971 if (instant_->GetPreviewContents()) 3989 if (instant_->GetPreviewContents())
3972 instant_->GetPreviewContents()->web_contents()->HideContents(); 3990 instant_->GetPreviewContents()->web_contents()->HideContents();
3973 } 3991 }
3974 3992
3975 void Browser::CommitInstant(TabContentsWrapper* preview_contents) { 3993 void Browser::CommitInstant(TabContents* preview_contents) {
3976 TabContentsWrapper* tab_contents = GetSelectedTabContentsWrapper(); 3994 TabContents* tab_contents = GetActiveTabContents();
3977 int index = tab_strip_model_->GetIndexOfTabContents(tab_contents); 3995 int index = tab_strip_model_->GetIndexOfTabContents(tab_contents);
3978 DCHECK_NE(TabStripModel::kNoTab, index); 3996 DCHECK_NE(TabStripModel::kNoTab, index);
3979 // TabStripModel takes ownership of preview_contents. 3997 // TabStripModel takes ownership of preview_contents.
3980 tab_strip_model_->ReplaceTabContentsAt(index, preview_contents); 3998 tab_strip_model_->ReplaceTabContentsAt(index, preview_contents);
3981 // InstantUnloadHandler takes ownership of tab_contents. 3999 // InstantUnloadHandler takes ownership of tab_contents.
3982 instant_unload_handler_->RunUnloadListenersOrDestroy(tab_contents, index); 4000 instant_unload_handler_->RunUnloadListenersOrDestroy(tab_contents, index);
3983 4001
3984 GURL url = preview_contents->web_contents()->GetURL(); 4002 GURL url = preview_contents->web_contents()->GetURL();
3985 DCHECK(profile_->GetExtensionService()); 4003 DCHECK(profile_->GetExtensionService());
3986 if (profile_->GetExtensionService()->IsInstalledApp(url)) { 4004 if (profile_->GetExtensionService()->IsInstalledApp(url)) {
(...skipping 10 matching lines...) Expand all
3997 4015
3998 gfx::Rect Browser::GetInstantBounds() { 4016 gfx::Rect Browser::GetInstantBounds() {
3999 return window()->GetInstantBounds(); 4017 return window()->GetInstantBounds();
4000 } 4018 }
4001 4019
4002 void Browser::InstantPreviewFocused() { 4020 void Browser::InstantPreviewFocused() {
4003 // NOTE: This is only invoked on aura. 4021 // NOTE: This is only invoked on aura.
4004 window_->WebContentsFocused(instant_->GetPreviewContents()->web_contents()); 4022 window_->WebContentsFocused(instant_->GetPreviewContents()->web_contents());
4005 } 4023 }
4006 4024
4007 TabContentsWrapper* Browser::GetInstantHostTabContents() const { 4025 TabContents* Browser::GetInstantHostTabContents() const {
4008 return GetSelectedTabContentsWrapper(); 4026 return GetActiveTabContents();
4009 } 4027 }
4010 4028
4011
4012
4013 /////////////////////////////////////////////////////////////////////////////// 4029 ///////////////////////////////////////////////////////////////////////////////
4014 // Browser, Command and state updating (private): 4030 // Browser, Command and state updating (private):
4015 4031
4016 bool Browser::IsShowingMainUI(bool is_fullscreen) { 4032 bool Browser::IsShowingMainUI(bool is_fullscreen) {
4017 #if !defined(OS_MACOSX) 4033 #if !defined(OS_MACOSX)
4018 return is_type_tabbed() && !is_fullscreen; 4034 return is_type_tabbed() && !is_fullscreen;
4019 #else 4035 #else
4020 return is_type_tabbed(); 4036 return is_type_tabbed();
4021 #endif 4037 #endif
4022 } 4038 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
4187 enable_extensions && command_enabled); 4203 enable_extensions && command_enabled);
4188 4204
4189 const bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen()); 4205 const bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen());
4190 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, 4206 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS,
4191 show_main_ui && command_enabled); 4207 show_main_ui && command_enabled);
4192 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, 4208 command_updater_.UpdateCommandEnabled(IDC_OPTIONS,
4193 show_main_ui && command_enabled); 4209 show_main_ui && command_enabled);
4194 } 4210 }
4195 4211
4196 void Browser::UpdateCommandsForTabState() { 4212 void Browser::UpdateCommandsForTabState() {
4197 WebContents* current_tab = GetSelectedWebContents(); 4213 TabContents* current_tab_contents = GetActiveTabContents();
4198 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); 4214 if (!current_tab_contents) // May be NULL during tab restore.
4199 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore.
4200 return; 4215 return;
4216 WebContents* current_web_contents = current_tab_contents->web_contents();
4201 4217
4202 // Navigation commands 4218 // Navigation commands
4203 NavigationController& nc = current_tab->GetController(); 4219 NavigationController& nc = current_web_contents->GetController();
4204 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack()); 4220 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack());
4205 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward()); 4221 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward());
4206 command_updater_.UpdateCommandEnabled(IDC_RELOAD, 4222 command_updater_.UpdateCommandEnabled(
4207 CanReloadContents(current_tab)); 4223 IDC_RELOAD, CanReloadContents(current_web_contents));
4208 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, 4224 command_updater_.UpdateCommandEnabled(
4209 CanReloadContents(current_tab)); 4225 IDC_RELOAD_IGNORING_CACHE, CanReloadContents(current_web_contents));
4210 4226
4211 // Window management commands 4227 // Window management commands
4212 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, 4228 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
4213 !is_app() && CanDuplicateContentsAt(active_index())); 4229 !is_app() && CanDuplicateContentsAt(active_index()));
4214 4230
4215 // Page-related commands 4231 // Page-related commands
4216 window_->SetStarredState( 4232 window_->SetStarredState(
4217 current_tab_wrapper->bookmark_tab_helper()->is_starred()); 4233 current_tab_contents->bookmark_tab_helper()->is_starred());
4218 window_->SetZoomIconState( 4234 window_->SetZoomIconState(
4219 current_tab_wrapper->zoom_controller()->zoom_icon_state()); 4235 current_tab_contents->zoom_controller()->zoom_icon_state());
4220 window_->SetZoomIconTooltipPercent( 4236 window_->SetZoomIconTooltipPercent(
4221 current_tab_wrapper->zoom_controller()->zoom_percent()); 4237 current_tab_contents->zoom_controller()->zoom_percent());
4222 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, 4238 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
4223 current_tab->GetController().CanViewSource()); 4239 current_web_contents->GetController().CanViewSource());
4224 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, 4240 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
4225 toolbar_model_->ShouldDisplayURL() && current_tab->GetURL().is_valid()); 4241 toolbar_model_->ShouldDisplayURL() &&
4242 current_web_contents->GetURL().is_valid());
4226 if (is_devtools()) 4243 if (is_devtools())
4227 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); 4244 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
4228 4245
4229 // Changing the encoding is not possible on Chrome-internal webpages. 4246 // Changing the encoding is not possible on Chrome-internal webpages.
4230 bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) || 4247 bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) ||
4231 current_tab->ShowingInterstitialPage(); 4248 current_web_contents->ShowingInterstitialPage();
4232 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, 4249 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU,
4233 !is_chrome_internal && current_tab->IsSavable()); 4250 !is_chrome_internal && current_web_contents->IsSavable());
4234 4251
4235 // Show various bits of UI 4252 // Show various bits of UI
4236 // TODO(pinkerton): Disable app-mode in the model until we implement it 4253 // TODO(pinkerton): Disable app-mode in the model until we implement it
4237 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 4254 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
4238 #if !defined(OS_MACOSX) 4255 #if !defined(OS_MACOSX)
4239 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, 4256 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS,
4240 web_app::IsValidUrl(current_tab->GetURL())); 4257 web_app::IsValidUrl(current_web_contents->GetURL()));
4241 #endif 4258 #endif
4242 4259
4243 UpdateCommandsForContentRestrictionState(); 4260 UpdateCommandsForContentRestrictionState();
4244 UpdateCommandsForBookmarkEditing(); 4261 UpdateCommandsForBookmarkEditing();
4245 } 4262 }
4246 4263
4247 void Browser::UpdateCommandsForContentRestrictionState() { 4264 void Browser::UpdateCommandsForContentRestrictionState() {
4248 int restrictions = GetContentRestrictionsForSelectedTab(); 4265 int restrictions = GetContentRestrictionsForSelectedTab();
4249 4266
4250 command_updater_.UpdateCommandEnabled( 4267 command_updater_.UpdateCommandEnabled(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
4352 void Browser::UpdatePrintingState(int content_restrictions) { 4369 void Browser::UpdatePrintingState(int content_restrictions) {
4353 bool print_enabled = true; 4370 bool print_enabled = true;
4354 bool advanced_print_enabled = true; 4371 bool advanced_print_enabled = true;
4355 if (g_browser_process->local_state()) { 4372 if (g_browser_process->local_state()) {
4356 print_enabled = 4373 print_enabled =
4357 g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled); 4374 g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled);
4358 advanced_print_enabled = print_enabled; 4375 advanced_print_enabled = print_enabled;
4359 } 4376 }
4360 if (print_enabled) { 4377 if (print_enabled) {
4361 // Do not print when a constrained window is showing. It's confusing. 4378 // Do not print when a constrained window is showing. It's confusing.
4362 TabContentsWrapper* wrapper = GetSelectedTabContentsWrapper(); 4379 TabContents* tab_contents = GetActiveTabContents();
4363 bool has_constrained_window = (wrapper && 4380 bool has_constrained_window =
4364 wrapper->constrained_window_tab_helper()->constrained_window_count()); 4381 tab_contents &&
4382 tab_contents->constrained_window_tab_helper()->
4383 constrained_window_count();
4365 if (has_constrained_window || 4384 if (has_constrained_window ||
4366 content_restrictions & content::CONTENT_RESTRICTION_PRINT) { 4385 content_restrictions & content::CONTENT_RESTRICTION_PRINT) {
4367 print_enabled = false; 4386 print_enabled = false;
4368 advanced_print_enabled = false; 4387 advanced_print_enabled = false;
4369 } 4388 }
4370 4389
4371 // The exception is print preview, 4390 // The exception is print preview,
4372 // where advanced printing is always enabled. 4391 // where advanced printing is always enabled.
4373 printing::PrintPreviewTabController* controller = 4392 printing::PrintPreviewTabController* controller =
4374 printing::PrintPreviewTabController::GetInstance(); 4393 printing::PrintPreviewTabController::GetInstance();
4375 if (controller && (controller->GetPrintPreviewForTab(wrapper) || 4394 if (controller && (controller->GetPrintPreviewForTab(tab_contents) ||
4376 controller->is_creating_print_preview_tab())) { 4395 controller->is_creating_print_preview_tab())) {
4377 advanced_print_enabled = true; 4396 advanced_print_enabled = true;
4378 } 4397 }
4379 } 4398 }
4380 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); 4399 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
4381 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT, 4400 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT,
4382 advanced_print_enabled); 4401 advanced_print_enabled);
4383 } 4402 }
4384 4403
4385 void Browser::UpdateSaveAsState(int content_restrictions) { 4404 void Browser::UpdateSaveAsState(int content_restrictions) {
(...skipping 16 matching lines...) Expand all
4402 4421
4403 void Browser::UpdateReloadStopState(bool is_loading, bool force) { 4422 void Browser::UpdateReloadStopState(bool is_loading, bool force) {
4404 window_->UpdateReloadStopState(is_loading, force); 4423 window_->UpdateReloadStopState(is_loading, force);
4405 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); 4424 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
4406 } 4425 }
4407 4426
4408 /////////////////////////////////////////////////////////////////////////////// 4427 ///////////////////////////////////////////////////////////////////////////////
4409 // Browser, UI update coalescing and handling (private): 4428 // Browser, UI update coalescing and handling (private):
4410 4429
4411 void Browser::UpdateToolbar(bool should_restore_state) { 4430 void Browser::UpdateToolbar(bool should_restore_state) {
4412 window_->UpdateToolbar(GetSelectedTabContentsWrapper(), should_restore_state); 4431 window_->UpdateToolbar(GetActiveTabContents(), should_restore_state);
4413 } 4432 }
4414 4433
4415 void Browser::ScheduleUIUpdate(const WebContents* source, 4434 void Browser::ScheduleUIUpdate(const WebContents* source,
4416 unsigned changed_flags) { 4435 unsigned changed_flags) {
4417 if (!source) 4436 if (!source)
4418 return; 4437 return;
4419 4438
4420 // Do some synchronous updates. 4439 // Do some synchronous updates.
4421 if (changed_flags & content::INVALIDATE_TYPE_URL && 4440 if (changed_flags & content::INVALIDATE_TYPE_URL &&
4422 source == GetSelectedWebContents()) { 4441 source == GetActiveWebContents()) {
4423 // Only update the URL for the current tab. Note that we do not update 4442 // Only update the URL for the current tab. Note that we do not update
4424 // the navigation commands since those would have already been updated 4443 // the navigation commands since those would have already been updated
4425 // synchronously by NavigationStateChanged. 4444 // synchronously by NavigationStateChanged.
4426 UpdateToolbar(false); 4445 UpdateToolbar(false);
4427 changed_flags &= ~content::INVALIDATE_TYPE_URL; 4446 changed_flags &= ~content::INVALIDATE_TYPE_URL;
4428 } 4447 }
4429 if (changed_flags & content::INVALIDATE_TYPE_LOAD) { 4448 if (changed_flags & content::INVALIDATE_TYPE_LOAD) {
4430 // Update the loading state synchronously. This is so the throbber will 4449 // Update the loading state synchronously. This is so the throbber will
4431 // immediately start/stop, which gives a more snappy feel. We want to do 4450 // immediately start/stop, which gives a more snappy feel. We want to do
4432 // this for any tab so they start & stop quickly. 4451 // this for any tab so they start & stop quickly.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4484 #endif 4503 #endif
4485 4504
4486 chrome_updater_factory_.InvalidateWeakPtrs(); 4505 chrome_updater_factory_.InvalidateWeakPtrs();
4487 4506
4488 for (UpdateMap::const_iterator i = scheduled_updates_.begin(); 4507 for (UpdateMap::const_iterator i = scheduled_updates_.begin();
4489 i != scheduled_updates_.end(); ++i) { 4508 i != scheduled_updates_.end(); ++i) {
4490 // Do not dereference |contents|, it may be out-of-date! 4509 // Do not dereference |contents|, it may be out-of-date!
4491 const WebContents* contents = i->first; 4510 const WebContents* contents = i->first;
4492 unsigned flags = i->second; 4511 unsigned flags = i->second;
4493 4512
4494 if (contents == GetSelectedWebContents()) { 4513 if (contents == GetActiveWebContents()) {
4495 // Updates that only matter when the tab is selected go here. 4514 // Updates that only matter when the tab is selected go here.
4496 4515
4497 if (flags & content::INVALIDATE_TYPE_PAGE_ACTIONS) { 4516 if (flags & content::INVALIDATE_TYPE_PAGE_ACTIONS) {
4498 LocationBar* location_bar = window()->GetLocationBar(); 4517 LocationBar* location_bar = window()->GetLocationBar();
4499 if (location_bar) 4518 if (location_bar)
4500 location_bar->UpdatePageActions(); 4519 location_bar->UpdatePageActions();
4501 } 4520 }
4502 // Updating the URL happens synchronously in ScheduleUIUpdate. 4521 // Updating the URL happens synchronously in ScheduleUIUpdate.
4503 if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) { 4522 if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) {
4504 GetStatusBubble()->SetStatus( 4523 GetStatusBubble()->SetStatus(
4505 GetSelectedTabContentsWrapper()-> 4524 GetActiveTabContents()->
4506 core_tab_helper()->GetStatusText()); 4525 core_tab_helper()->GetStatusText());
4507 } 4526 }
4508 4527
4509 if (flags & (content::INVALIDATE_TYPE_TAB | 4528 if (flags & (content::INVALIDATE_TYPE_TAB |
4510 content::INVALIDATE_TYPE_TITLE)) { 4529 content::INVALIDATE_TYPE_TITLE)) {
4511 // TODO(pinkerton): Disable app-mode in the model until we implement it 4530 // TODO(pinkerton): Disable app-mode in the model until we implement it
4512 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 4531 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
4513 #if !defined(OS_MACOSX) 4532 #if !defined(OS_MACOSX)
4514 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, 4533 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS,
4515 web_app::IsValidUrl(contents->GetURL())); 4534 web_app::IsValidUrl(contents->GetURL()));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4555 } 4574 }
4556 4575
4557 /////////////////////////////////////////////////////////////////////////////// 4576 ///////////////////////////////////////////////////////////////////////////////
4558 // Browser, Session restore functions (private): 4577 // Browser, Session restore functions (private):
4559 4578
4560 void Browser::SyncHistoryWithTabs(int index) { 4579 void Browser::SyncHistoryWithTabs(int index) {
4561 SessionService* session_service = 4580 SessionService* session_service =
4562 SessionServiceFactory::GetForProfileIfExisting(profile()); 4581 SessionServiceFactory::GetForProfileIfExisting(profile());
4563 if (session_service) { 4582 if (session_service) {
4564 for (int i = index; i < tab_count(); ++i) { 4583 for (int i = index; i < tab_count(); ++i) {
4565 TabContentsWrapper* tab = GetTabContentsWrapperAt(i); 4584 TabContents* tab = GetTabContentsAt(i);
4566 if (tab) { 4585 if (tab) {
4567 session_service->SetTabIndexInWindow( 4586 session_service->SetTabIndexInWindow(
4568 session_id(), tab->restore_tab_helper()->session_id(), i); 4587 session_id(), tab->restore_tab_helper()->session_id(), i);
4569 session_service->SetPinnedState( 4588 session_service->SetPinnedState(
4570 session_id(), 4589 session_id(),
4571 tab->restore_tab_helper()->session_id(), 4590 tab->restore_tab_helper()->session_id(),
4572 IsTabPinned(i)); 4591 IsTabPinned(i));
4573 } 4592 }
4574 } 4593 }
4575 } 4594 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
4701 window_->ConfirmBrowserCloseWithPendingDownloads(); 4720 window_->ConfirmBrowserCloseWithPendingDownloads();
4702 4721
4703 // Return false so the browser does not close. We'll close if the user 4722 // Return false so the browser does not close. We'll close if the user
4704 // confirms in the dialog. 4723 // confirms in the dialog.
4705 return false; 4724 return false;
4706 } 4725 }
4707 4726
4708 /////////////////////////////////////////////////////////////////////////////// 4727 ///////////////////////////////////////////////////////////////////////////////
4709 // Browser, Assorted utility functions (private): 4728 // Browser, Assorted utility functions (private):
4710 4729
4711 void Browser::SetAsDelegate(TabContentsWrapper* tab, Browser* delegate) { 4730 void Browser::SetAsDelegate(TabContents* tab, Browser* delegate) {
4712 // WebContents... 4731 // WebContents...
4713 tab->web_contents()->SetDelegate(delegate); 4732 tab->web_contents()->SetDelegate(delegate);
4714 4733
4715 // ...and all the helpers. 4734 // ...and all the helpers.
4716 tab->blocked_content_tab_helper()->set_delegate(delegate); 4735 tab->blocked_content_tab_helper()->set_delegate(delegate);
4717 tab->bookmark_tab_helper()->set_delegate(delegate); 4736 tab->bookmark_tab_helper()->set_delegate(delegate);
4718 tab->zoom_controller()->set_observer(delegate); 4737 tab->zoom_controller()->set_observer(delegate);
4719 tab->constrained_window_tab_helper()->set_delegate(delegate); 4738 tab->constrained_window_tab_helper()->set_delegate(delegate);
4720 tab->core_tab_helper()->set_delegate(delegate); 4739 tab->core_tab_helper()->set_delegate(delegate);
4721 tab->extension_tab_helper()->set_delegate(delegate); 4740 tab->extension_tab_helper()->set_delegate(delegate);
4722 tab->search_engine_tab_helper()->set_delegate(delegate); 4741 tab->search_engine_tab_helper()->set_delegate(delegate);
4723 } 4742 }
4724 4743
4725 void Browser::FindInPage(bool find_next, bool forward_direction) { 4744 void Browser::FindInPage(bool find_next, bool forward_direction) {
4726 ShowFindBar(); 4745 ShowFindBar();
4727 if (find_next) { 4746 if (find_next) {
4728 string16 find_text; 4747 string16 find_text;
4729 #if defined(OS_MACOSX) 4748 #if defined(OS_MACOSX)
4730 // We always want to search for the contents of the find pasteboard on OS X. 4749 // We always want to search for the contents of the find pasteboard on OS X.
4731 find_text = GetFindPboardText(); 4750 find_text = GetFindPboardText();
4732 #endif 4751 #endif
4733 GetSelectedTabContentsWrapper()-> 4752 GetActiveTabContents()->
4734 find_tab_helper()->StartFinding(find_text, 4753 find_tab_helper()->StartFinding(find_text,
4735 forward_direction, 4754 forward_direction,
4736 false); // Not case sensitive. 4755 false); // Not case sensitive.
4737 } 4756 }
4738 } 4757 }
4739 4758
4740 void Browser::CloseFrame() { 4759 void Browser::CloseFrame() {
4741 window_->Close(); 4760 window_->Close();
4742 } 4761 }
4743 4762
4744 void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index, 4763 void Browser::TabDetachedAtImpl(TabContents* contents, int index,
4745 DetachType type) { 4764 DetachType type) {
4746 if (type == DETACH_TYPE_DETACH) { 4765 if (type == DETACH_TYPE_DETACH) {
4747 // Save the current location bar state, but only if the tab being detached 4766 // Save the current location bar state, but only if the tab being detached
4748 // is the selected tab. Because saving state can conditionally revert the 4767 // is the selected tab. Because saving state can conditionally revert the
4749 // location bar, saving the current tab's location bar state to a 4768 // location bar, saving the current tab's location bar state to a
4750 // non-selected tab can corrupt both tabs. 4769 // non-selected tab can corrupt both tabs.
4751 if (contents == GetSelectedTabContentsWrapper()) { 4770 if (contents == GetActiveTabContents()) {
4752 LocationBar* location_bar = window()->GetLocationBar(); 4771 LocationBar* location_bar = window()->GetLocationBar();
4753 if (location_bar) 4772 if (location_bar)
4754 location_bar->SaveStateToContents(contents->web_contents()); 4773 location_bar->SaveStateToContents(contents->web_contents());
4755 } 4774 }
4756 4775
4757 if (!tab_strip_model_->closing_all()) 4776 if (!tab_strip_model_->closing_all())
4758 SyncHistoryWithTabs(0); 4777 SyncHistoryWithTabs(0);
4759 } 4778 }
4760 4779
4761 SetAsDelegate(contents, NULL); 4780 SetAsDelegate(contents, NULL);
(...skipping 28 matching lines...) Expand all
4790 PrefService* prefs = profile->GetPrefs(); 4809 PrefService* prefs = profile->GetPrefs();
4791 if (!prefs->FindPreference(window_pref.c_str())) { 4810 if (!prefs->FindPreference(window_pref.c_str())) {
4792 prefs->RegisterDictionaryPref(window_pref.c_str(), 4811 prefs->RegisterDictionaryPref(window_pref.c_str(),
4793 PrefService::UNSYNCABLE_PREF); 4812 PrefService::UNSYNCABLE_PREF);
4794 } 4813 }
4795 } 4814 }
4796 4815
4797 void Browser::ReloadInternal(WindowOpenDisposition disposition, 4816 void Browser::ReloadInternal(WindowOpenDisposition disposition,
4798 bool ignore_cache) { 4817 bool ignore_cache) {
4799 // If we are showing an interstitial, treat this as an OpenURL. 4818 // If we are showing an interstitial, treat this as an OpenURL.
4800 WebContents* current_tab = GetSelectedWebContents(); 4819 WebContents* current_tab = GetActiveWebContents();
4801 if (current_tab && current_tab->ShowingInterstitialPage()) { 4820 if (current_tab && current_tab->ShowingInterstitialPage()) {
4802 NavigationEntry* entry = current_tab->GetController().GetActiveEntry(); 4821 NavigationEntry* entry = current_tab->GetController().GetActiveEntry();
4803 DCHECK(entry); // Should exist if interstitial is showing. 4822 DCHECK(entry); // Should exist if interstitial is showing.
4804 OpenURL(OpenURLParams( 4823 OpenURL(OpenURLParams(
4805 entry->GetURL(), Referrer(), disposition, 4824 entry->GetURL(), Referrer(), disposition,
4806 content::PAGE_TRANSITION_RELOAD, false)); 4825 content::PAGE_TRANSITION_RELOAD, false));
4807 return; 4826 return;
4808 } 4827 }
4809 4828
4810 // As this is caused by a user action, give the focus to the page. 4829 // As this is caused by a user action, give the focus to the page.
4811 // 4830 //
4812 // Also notify RenderViewHostDelegate of the user gesture; this is 4831 // Also notify RenderViewHostDelegate of the user gesture; this is
4813 // normally done in Browser::Navigate, but a reload bypasses Navigate. 4832 // normally done in Browser::Navigate, but a reload bypasses Navigate.
4814 WebContents* tab = GetOrCloneTabForDisposition(disposition); 4833 WebContents* tab = GetOrCloneTabForDisposition(disposition);
4815 tab->UserGestureDone(); 4834 tab->UserGestureDone();
4816 if (!tab->FocusLocationBarByDefault()) 4835 if (!tab->FocusLocationBarByDefault())
4817 tab->Focus(); 4836 tab->Focus();
4818 if (ignore_cache) 4837 if (ignore_cache)
4819 tab->GetController().ReloadIgnoringCache(true); 4838 tab->GetController().ReloadIgnoringCache(true);
4820 else 4839 else
4821 tab->GetController().Reload(true); 4840 tab->GetController().Reload(true);
4822 } 4841 }
4823 4842
4824 WebContents* Browser::GetOrCloneTabForDisposition( 4843 WebContents* Browser::GetOrCloneTabForDisposition(
4825 WindowOpenDisposition disposition) { 4844 WindowOpenDisposition disposition) {
4826 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); 4845 TabContents* current_tab = GetActiveTabContents();
4827 switch (disposition) { 4846 switch (disposition) {
4828 case NEW_FOREGROUND_TAB: 4847 case NEW_FOREGROUND_TAB:
4829 case NEW_BACKGROUND_TAB: { 4848 case NEW_BACKGROUND_TAB: {
4830 current_tab = current_tab->Clone(); 4849 current_tab = current_tab->Clone();
4831 tab_strip_model_->AddTabContents( 4850 tab_strip_model_->AddTabContents(
4832 current_tab, -1, content::PAGE_TRANSITION_LINK, 4851 current_tab, -1, content::PAGE_TRANSITION_LINK,
4833 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : 4852 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE :
4834 TabStripModel::ADD_NONE); 4853 TabStripModel::ADD_NONE);
4835 break; 4854 break;
4836 } 4855 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4893 if (!instant() || !instant()->PrepareForCommit() || 4912 if (!instant() || !instant()->PrepareForCommit() ||
4894 disposition == NEW_BACKGROUND_TAB) { 4913 disposition == NEW_BACKGROUND_TAB) {
4895 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't 4914 // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't
4896 // attempt to use the instant preview. 4915 // attempt to use the instant preview.
4897 return false; 4916 return false;
4898 } 4917 }
4899 4918
4900 if (disposition == CURRENT_TAB) { 4919 if (disposition == CURRENT_TAB) {
4901 content::NotificationService::current()->Notify( 4920 content::NotificationService::current()->Notify(
4902 chrome::NOTIFICATION_INSTANT_COMMITTED, 4921 chrome::NOTIFICATION_INSTANT_COMMITTED,
4903 content::Source<TabContentsWrapper>(instant()->CommitCurrentPreview( 4922 content::Source<TabContents>(instant()->CommitCurrentPreview(
4904 INSTANT_COMMIT_PRESSED_ENTER)), 4923 INSTANT_COMMIT_PRESSED_ENTER)),
4905 content::NotificationService::NoDetails()); 4924 content::NotificationService::NoDetails());
4906 return true; 4925 return true;
4907 } 4926 }
4908 if (disposition == NEW_FOREGROUND_TAB) { 4927 if (disposition == NEW_FOREGROUND_TAB) {
4909 TabContentsWrapper* preview_contents = instant()->ReleasePreviewContents( 4928 TabContents* preview_contents = instant()->ReleasePreviewContents(
4910 INSTANT_COMMIT_PRESSED_ENTER, NULL); 4929 INSTANT_COMMIT_PRESSED_ENTER, NULL);
4911 // HideInstant is invoked after release so that InstantController is not 4930 // HideInstant is invoked after release so that InstantController is not
4912 // active when HideInstant asks it for its state. 4931 // active when HideInstant asks it for its state.
4913 HideInstant(); 4932 HideInstant();
4914 preview_contents->web_contents()->GetController().PruneAllButActive(); 4933 preview_contents->web_contents()->GetController().PruneAllButActive();
4915 tab_strip_model_->AddTabContents( 4934 tab_strip_model_->AddTabContents(
4916 preview_contents, 4935 preview_contents,
4917 -1, 4936 -1,
4918 instant()->last_transition_type(), 4937 instant()->last_transition_type(),
4919 TabStripModel::ADD_ACTIVE); 4938 TabStripModel::ADD_ACTIVE);
4920 instant()->CompleteRelease(preview_contents); 4939 instant()->CompleteRelease(preview_contents);
4921 content::NotificationService::current()->Notify( 4940 content::NotificationService::current()->Notify(
4922 chrome::NOTIFICATION_INSTANT_COMMITTED, 4941 chrome::NOTIFICATION_INSTANT_COMMITTED,
4923 content::Source<TabContentsWrapper>(preview_contents), 4942 content::Source<TabContents>(preview_contents),
4924 content::NotificationService::NoDetails()); 4943 content::NotificationService::NoDetails());
4925 return true; 4944 return true;
4926 } 4945 }
4927 // The omnibox currently doesn't use other dispositions, so we don't attempt 4946 // The omnibox currently doesn't use other dispositions, so we don't attempt
4928 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add 4947 // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add
4929 // support for the new disposition. 4948 // support for the new disposition.
4930 NOTREACHED(); 4949 NOTREACHED();
4931 return false; 4950 return false;
4932 } 4951 }
4933 4952
4934 void Browser::CreateInstantIfNecessary() { 4953 void Browser::CreateInstantIfNecessary() {
4935 if (is_type_tabbed() && InstantController::IsEnabled(profile()) && 4954 if (is_type_tabbed() && InstantController::IsEnabled(profile()) &&
4936 !profile()->IsOffTheRecord()) { 4955 !profile()->IsOffTheRecord()) {
4937 instant_.reset(new InstantController(this, InstantController::INSTANT)); 4956 instant_.reset(new InstantController(this, InstantController::INSTANT));
4938 instant_unload_handler_.reset(new InstantUnloadHandler(this)); 4957 instant_unload_handler_.reset(new InstantUnloadHandler(this));
4939 } 4958 }
4940 } 4959 }
4941 4960
4942 void Browser::ViewSource(TabContentsWrapper* contents) { 4961 void Browser::ViewSource(TabContents* contents) {
4943 DCHECK(contents); 4962 DCHECK(contents);
4944 4963
4945 NavigationEntry* active_entry = 4964 NavigationEntry* active_entry =
4946 contents->web_contents()->GetController().GetActiveEntry(); 4965 contents->web_contents()->GetController().GetActiveEntry();
4947 if (!active_entry) 4966 if (!active_entry)
4948 return; 4967 return;
4949 4968
4950 ViewSource(contents, active_entry->GetURL(), active_entry->GetContentState()); 4969 ViewSource(contents, active_entry->GetURL(), active_entry->GetContentState());
4951 } 4970 }
4952 4971
4953 void Browser::ViewSource(TabContentsWrapper* contents, 4972 void Browser::ViewSource(TabContents* contents,
4954 const GURL& url, 4973 const GURL& url,
4955 const std::string& content_state) { 4974 const std::string& content_state) {
4956 content::RecordAction(UserMetricsAction("ViewSource")); 4975 content::RecordAction(UserMetricsAction("ViewSource"));
4957 DCHECK(contents); 4976 DCHECK(contents);
4958 4977
4959 TabContentsWrapper* view_source_contents = contents->Clone(); 4978 TabContents* view_source_contents = contents->Clone();
4960 view_source_contents->web_contents()->GetController().PruneAllButActive(); 4979 view_source_contents->web_contents()->GetController().PruneAllButActive();
4961 NavigationEntry* active_entry = 4980 NavigationEntry* active_entry =
4962 view_source_contents->web_contents()->GetController().GetActiveEntry(); 4981 view_source_contents->web_contents()->GetController().GetActiveEntry();
4963 if (!active_entry) 4982 if (!active_entry)
4964 return; 4983 return;
4965 4984
4966 GURL view_source_url = GURL(chrome::kViewSourceScheme + std::string(":") + 4985 GURL view_source_url = GURL(chrome::kViewSourceScheme + std::string(":") +
4967 url.spec()); 4986 url.spec());
4968 active_entry->SetVirtualURL(view_source_url); 4987 active_entry->SetVirtualURL(view_source_url);
4969 4988
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5002 } 5021 }
5003 5022
5004 SessionService* session_service = 5023 SessionService* session_service =
5005 SessionServiceFactory::GetForProfileIfExisting(profile_); 5024 SessionServiceFactory::GetForProfileIfExisting(profile_);
5006 if (session_service) 5025 if (session_service)
5007 session_service->TabRestored(view_source_contents, false); 5026 session_service->TabRestored(view_source_contents, false);
5008 } 5027 }
5009 5028
5010 int Browser::GetContentRestrictionsForSelectedTab() { 5029 int Browser::GetContentRestrictionsForSelectedTab() {
5011 int content_restrictions = 0; 5030 int content_restrictions = 0;
5012 WebContents* current_tab = GetSelectedWebContents(); 5031 WebContents* current_tab = GetActiveWebContents();
5013 if (current_tab) { 5032 if (current_tab) {
5014 content_restrictions = current_tab->GetContentRestrictions(); 5033 content_restrictions = current_tab->GetContentRestrictions();
5015 NavigationEntry* active_entry = 5034 NavigationEntry* active_entry =
5016 current_tab->GetController().GetActiveEntry(); 5035 current_tab->GetController().GetActiveEntry();
5017 // See comment in UpdateCommandsForTabState about why we call url(). 5036 // See comment in UpdateCommandsForTabState about why we call url().
5018 if (!download_util::IsSavableURL( 5037 if (!download_util::IsSavableURL(
5019 active_entry ? active_entry->GetURL() : GURL()) 5038 active_entry ? active_entry->GetURL() : GURL())
5020 || current_tab->ShowingInterstitialPage()) 5039 || current_tab->ShowingInterstitialPage())
5021 content_restrictions |= content::CONTENT_RESTRICTION_SAVE; 5040 content_restrictions |= content::CONTENT_RESTRICTION_SAVE;
5022 if (current_tab->ShowingInterstitialPage()) 5041 if (current_tab->ShowingInterstitialPage())
5023 content_restrictions |= content::CONTENT_RESTRICTION_PRINT; 5042 content_restrictions |= content::CONTENT_RESTRICTION_PRINT;
5024 } 5043 }
5025 return content_restrictions; 5044 return content_restrictions;
5026 } 5045 }
5027 5046
5028 void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { 5047 void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
5029 BookmarkBar::State state; 5048 BookmarkBar::State state;
5030 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page. 5049 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page.
5031 if (browser_defaults::bookmarks_enabled && 5050 if (browser_defaults::bookmarks_enabled &&
5032 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && 5051 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) &&
5033 (!window_ || !window_->IsFullscreen())) { 5052 (!window_ || !window_->IsFullscreen())) {
5034 state = BookmarkBar::SHOW; 5053 state = BookmarkBar::SHOW;
5035 } else { 5054 } else {
5036 TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); 5055 TabContents* tab = GetActiveTabContents();
5037 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) 5056 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar())
5038 state = BookmarkBar::DETACHED; 5057 state = BookmarkBar::DETACHED;
5039 else 5058 else
5040 state = BookmarkBar::HIDDEN; 5059 state = BookmarkBar::HIDDEN;
5041 } 5060 }
5042 if (state == bookmark_bar_state_) 5061 if (state == bookmark_bar_state_)
5043 return; 5062 return;
5044 5063
5045 bookmark_bar_state_ = state; 5064 bookmark_bar_state_ = state;
5046 5065
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5146 if (contents && !allow_js_access) { 5165 if (contents && !allow_js_access) {
5147 contents->web_contents()->GetController().LoadURL( 5166 contents->web_contents()->GetController().LoadURL(
5148 target_url, 5167 target_url,
5149 content::Referrer(), 5168 content::Referrer(),
5150 content::PAGE_TRANSITION_LINK, 5169 content::PAGE_TRANSITION_LINK,
5151 std::string()); // No extra headers. 5170 std::string()); // No extra headers.
5152 } 5171 }
5153 5172
5154 return contents != NULL; 5173 return contents != NULL;
5155 } 5174 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698