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

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

Issue 10677009: Move command handling and updating off Browser and onto a helper object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 #include "chrome/browser/sync/sync_ui_util.h" 88 #include "chrome/browser/sync/sync_ui_util.h"
89 #include "chrome/browser/tab_contents/background_contents.h" 89 #include "chrome/browser/tab_contents/background_contents.h"
90 #include "chrome/browser/tab_contents/retargeting_details.h" 90 #include "chrome/browser/tab_contents/retargeting_details.h"
91 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" 91 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
92 #include "chrome/browser/tab_contents/tab_util.h" 92 #include "chrome/browser/tab_contents/tab_util.h"
93 #include "chrome/browser/themes/theme_service.h" 93 #include "chrome/browser/themes/theme_service.h"
94 #include "chrome/browser/themes/theme_service_factory.h" 94 #include "chrome/browser/themes/theme_service_factory.h"
95 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" 95 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h"
96 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 96 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
97 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 97 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
98 #include "chrome/browser/ui/browser_command_controller.h"
98 #include "chrome/browser/ui/browser_commands.h" 99 #include "chrome/browser/ui/browser_commands.h"
99 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" 100 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
100 #include "chrome/browser/ui/browser_dialogs.h" 101 #include "chrome/browser/ui/browser_dialogs.h"
101 #include "chrome/browser/ui/browser_finder.h" 102 #include "chrome/browser/ui/browser_finder.h"
102 #include "chrome/browser/ui/browser_list.h" 103 #include "chrome/browser/ui/browser_list.h"
103 #include "chrome/browser/ui/browser_navigator.h" 104 #include "chrome/browser/ui/browser_navigator.h"
104 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" 105 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
105 #include "chrome/browser/ui/browser_toolbar_model_delegate.h" 106 #include "chrome/browser/ui/browser_toolbar_model_delegate.h"
106 #include "chrome/browser/ui/browser_ui_prefs.h" 107 #include "chrome/browser/ui/browser_ui_prefs.h"
107 #include "chrome/browser/ui/browser_window.h" 108 #include "chrome/browser/ui/browser_window.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 "https://www.google.com/support/chrome/bin/request.py?contact_type=" 231 "https://www.google.com/support/chrome/bin/request.py?contact_type="
231 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; 232 "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2";
232 233
233 // The URL for the privacy dashboard. 234 // The URL for the privacy dashboard.
234 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; 235 const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard";
235 236
236 // How long we wait before updating the browser chrome while loading a page. 237 // How long we wait before updating the browser chrome while loading a page.
237 const int kUIUpdateCoalescingTimeMS = 200; 238 const int kUIUpdateCoalescingTimeMS = 200;
238 239
239 // Returns |true| if entry has an internal chrome:// URL, |false| otherwise. 240 // Returns |true| if entry has an internal chrome:// URL, |false| otherwise.
240 bool HasInternalURL(const NavigationEntry* entry) { 241 bool HasInternalURL(const NavigationEntry* entry) {
sky 2012/06/27 03:09:28 Can this be remove from browser.cc now?
241 if (!entry) 242 if (!entry)
242 return false; 243 return false;
243 244
244 // Check the |virtual_url()| first. This catches regular chrome:// URLs 245 // Check the |virtual_url()| first. This catches regular chrome:// URLs
245 // including URLs that were rewritten (such as chrome://bookmarks). 246 // including URLs that were rewritten (such as chrome://bookmarks).
246 if (entry->GetVirtualURL().SchemeIs(chrome::kChromeUIScheme)) 247 if (entry->GetVirtualURL().SchemeIs(chrome::kChromeUIScheme))
247 return true; 248 return true;
248 249
249 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually 250 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually
250 // view-source: of a chrome:// URL. 251 // view-source: of a chrome:// URL.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 310
310 /////////////////////////////////////////////////////////////////////////////// 311 ///////////////////////////////////////////////////////////////////////////////
311 // Browser, Constructors, Creation, Showing: 312 // Browser, Constructors, Creation, Showing:
312 313
313 Browser::Browser(Type type, Profile* profile) 314 Browser::Browser(Type type, Profile* profile)
314 : type_(type), 315 : type_(type),
315 profile_(profile), 316 profile_(profile),
316 window_(NULL), 317 window_(NULL),
317 ALLOW_THIS_IN_INITIALIZER_LIST( 318 ALLOW_THIS_IN_INITIALIZER_LIST(
318 tab_strip_model_(new TabStripModel(this, profile))), 319 tab_strip_model_(new TabStripModel(this, profile))),
319 command_updater_(this),
320 app_type_(APP_TYPE_HOST), 320 app_type_(APP_TYPE_HOST),
321 chrome_updater_factory_(this), 321 chrome_updater_factory_(this),
322 is_attempting_to_close_browser_(false), 322 is_attempting_to_close_browser_(false),
323 cancel_download_confirmation_state_(NOT_PROMPTED), 323 cancel_download_confirmation_state_(NOT_PROMPTED),
324 initial_show_state_(ui::SHOW_STATE_DEFAULT), 324 initial_show_state_(ui::SHOW_STATE_DEFAULT),
325 is_session_restore_(false), 325 is_session_restore_(false),
326 weak_factory_(this), 326 weak_factory_(this),
327 block_command_execution_(false),
328 last_blocked_command_id_(-1),
329 last_blocked_command_disposition_(CURRENT_TAB),
330 pending_web_app_action_(NONE), 327 pending_web_app_action_(NONE),
331 ALLOW_THIS_IN_INITIALIZER_LIST( 328 ALLOW_THIS_IN_INITIALIZER_LIST(
332 content_setting_bubble_model_delegate_( 329 content_setting_bubble_model_delegate_(
333 new BrowserContentSettingBubbleModelDelegate(this))), 330 new BrowserContentSettingBubbleModelDelegate(this))),
334 ALLOW_THIS_IN_INITIALIZER_LIST( 331 ALLOW_THIS_IN_INITIALIZER_LIST(
335 toolbar_model_delegate_( 332 toolbar_model_delegate_(
336 new BrowserToolbarModelDelegate(this))), 333 new BrowserToolbarModelDelegate(this))),
337 ALLOW_THIS_IN_INITIALIZER_LIST( 334 ALLOW_THIS_IN_INITIALIZER_LIST(
338 tab_restore_service_delegate_( 335 tab_restore_service_delegate_(
339 new BrowserTabRestoreServiceDelegate(this))), 336 new BrowserTabRestoreServiceDelegate(this))),
340 ALLOW_THIS_IN_INITIALIZER_LIST( 337 ALLOW_THIS_IN_INITIALIZER_LIST(
341 synced_window_delegate_( 338 synced_window_delegate_(
342 new BrowserSyncedWindowDelegate(this))), 339 new BrowserSyncedWindowDelegate(this))),
343 bookmark_bar_state_(BookmarkBar::HIDDEN), 340 bookmark_bar_state_(BookmarkBar::HIDDEN),
341 ALLOW_THIS_IN_INITIALIZER_LIST(
342 command_controller_(new chrome::BrowserCommandController(this))),
344 window_has_shown_(false) { 343 window_has_shown_(false) {
345 tab_strip_model_->AddObserver(this); 344 tab_strip_model_->AddObserver(this);
346 345
347 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get())); 346 toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get()));
348 search_model_.reset(new chrome::search::SearchModel(NULL)); 347 search_model_.reset(new chrome::search::SearchModel(NULL));
349 search_delegate_.reset( 348 search_delegate_.reset(
350 new chrome::search::SearchDelegate(search_model_.get())); 349 new chrome::search::SearchDelegate(search_model_.get()));
351 350
352 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, 351 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED,
353 content::NotificationService::AllSources()); 352 content::NotificationService::AllSources());
354 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 353 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
355 content::Source<Profile>(profile_->GetOriginalProfile())); 354 content::Source<Profile>(profile_->GetOriginalProfile()));
356 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 355 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
357 content::Source<Profile>(profile_->GetOriginalProfile())); 356 content::Source<Profile>(profile_->GetOriginalProfile()));
358 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 357 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
359 content::Source<Profile>(profile_->GetOriginalProfile())); 358 content::Source<Profile>(profile_->GetOriginalProfile()));
360 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 359 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
361 content::NotificationService::AllSources()); 360 content::NotificationService::AllSources());
362 #if defined(ENABLE_THEMES) 361 #if defined(ENABLE_THEMES)
363 registrar_.Add( 362 registrar_.Add(
364 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 363 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
365 content::Source<ThemeService>( 364 content::Source<ThemeService>(
366 ThemeServiceFactory::GetForProfile(profile_))); 365 ThemeServiceFactory::GetForProfile(profile_)));
367 #endif 366 #endif
368 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 367 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
369 content::NotificationService::AllSources()); 368 content::NotificationService::AllSources());
370 369
371 PrefService* local_state = g_browser_process->local_state();
372 if (local_state) {
373 local_pref_registrar_.Init(local_state);
374 local_pref_registrar_.Add(prefs::kPrintingEnabled, this);
375 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this);
376 local_pref_registrar_.Add(prefs::kInManagedMode, this);
377 }
378
379 profile_pref_registrar_.Init(profile_->GetPrefs()); 370 profile_pref_registrar_.Init(profile_->GetPrefs());
380 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); 371 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this);
381 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this);
382 profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this); 372 profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this);
383 profile_pref_registrar_.Add(prefs::kHomePage, this); 373 profile_pref_registrar_.Add(prefs::kHomePage, this);
384 profile_pref_registrar_.Add(prefs::kInstantEnabled, this); 374 profile_pref_registrar_.Add(prefs::kInstantEnabled, this);
385 profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this);
386 375
387 InitCommandState();
388 BrowserList::AddBrowser(this); 376 BrowserList::AddBrowser(this);
389 377
390 // NOTE: These prefs all need to be explicitly destroyed in the destructor 378 // NOTE: These prefs all need to be explicitly destroyed in the destructor
391 // or you'll get a nasty surprise when you run the incognito tests. 379 // or you'll get a nasty surprise when you run the incognito tests.
392 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, 380 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
393 profile_->GetPrefs(), NULL); 381 profile_->GetPrefs(), NULL);
394 382
395 tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile);
396 if (tab_restore_service_) {
397 tab_restore_service_->AddObserver(this);
398 TabRestoreServiceChanged(tab_restore_service_);
399 }
400
401 ProfileSyncService* service =
402 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
403 if (service)
404 service->AddObserver(this);
405
406 CreateInstantIfNecessary(); 383 CreateInstantIfNecessary();
407 384
408 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); 385 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
409 386
410 FilePath profile_path = profile->GetPath(); 387 FilePath profile_path = profile->GetPath();
411 ProfileMetrics::LogProfileLaunch(profile_path); 388 ProfileMetrics::LogProfileLaunch(profile_path);
412 } 389 }
413 390
414 Browser::~Browser() { 391 Browser::~Browser() {
415 ProfileSyncService* service =
416 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
417 if (service)
418 service->RemoveObserver(this);
419
420 // The tab strip should not have any tabs at this point. 392 // The tab strip should not have any tabs at this point.
421 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) 393 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers())
422 DCHECK(tab_strip_model_->empty()); 394 DCHECK(tab_strip_model_->empty());
423 tab_strip_model_->RemoveObserver(this); 395 tab_strip_model_->RemoveObserver(this);
424 396
425 BrowserList::RemoveBrowser(this); 397 BrowserList::RemoveBrowser(this);
426 398
427 SessionService* session_service = 399 SessionService* session_service =
428 SessionServiceFactory::GetForProfile(profile_); 400 SessionServiceFactory::GetForProfile(profile_);
429 if (session_service) 401 if (session_service)
(...skipping 13 matching lines...) Expand all
443 // thread tries to use the IO thread (or another thread) that is no longer 415 // thread tries to use the IO thread (or another thread) that is no longer
444 // valid. 416 // valid.
445 // This isn't a valid assumption for Mac OS, as it stays running after 417 // This isn't a valid assumption for Mac OS, as it stays running after
446 // the last browser has closed. The Mac equivalent is in its app 418 // the last browser has closed. The Mac equivalent is in its app
447 // controller. 419 // controller.
448 TabRestoreServiceFactory::ResetForProfile(profile_); 420 TabRestoreServiceFactory::ResetForProfile(profile_);
449 } 421 }
450 #endif 422 #endif
451 423
452 profile_pref_registrar_.RemoveAll(); 424 profile_pref_registrar_.RemoveAll();
453 local_pref_registrar_.RemoveAll();
454 425
455 encoding_auto_detect_.Destroy(); 426 encoding_auto_detect_.Destroy();
456 427
457 if (profile_->IsOffTheRecord() && 428 if (profile_->IsOffTheRecord() &&
458 !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) { 429 !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) {
459 // An incognito profile is no longer needed, this indirectly frees 430 // An incognito profile is no longer needed, this indirectly frees
460 // its cache and cookies once it gets destroyed at the appropriate time. 431 // its cache and cookies once it gets destroyed at the appropriate time.
461 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); 432 ProfileDestroyer::DestroyProfileWhenAppropriate(profile_);
462 } 433 }
463 434
464 // There may be pending file dialogs, we need to tell them that we've gone 435 // There may be pending file dialogs, we need to tell them that we've gone
465 // away so they don't try and call back to us. 436 // away so they don't try and call back to us.
466 if (select_file_dialog_.get()) 437 if (select_file_dialog_.get())
467 select_file_dialog_->ListenerDestroyed(); 438 select_file_dialog_->ListenerDestroyed();
468
469 TabRestoreServiceDestroyed(tab_restore_service_);
470 } 439 }
471 440
472 // static 441 // static
473 Browser* Browser::Create(Profile* profile) { 442 Browser* Browser::Create(Profile* profile) {
474 Browser* browser = new Browser(TYPE_TABBED, profile); 443 Browser* browser = new Browser(TYPE_TABBED, profile);
475 browser->InitBrowserWindow(); 444 browser->InitBrowserWindow();
476 return browser; 445 return browser;
477 } 446 }
478 447
479 // static 448 // static
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 profile_, navigations, &entries); 900 profile_, navigations, &entries);
932 replacement->GetController().Restore( 901 replacement->GetController().Restore(
933 selected_navigation, from_last_session, &entries); 902 selected_navigation, from_last_session, &entries);
934 DCHECK_EQ(0u, entries.size()); 903 DCHECK_EQ(0u, entries.size());
935 904
936 tab_strip_model_->ReplaceNavigationControllerAt(active_index(), tab_contents); 905 tab_strip_model_->ReplaceNavigationControllerAt(active_index(), tab_contents);
937 } 906 }
938 907
939 void Browser::WindowFullscreenStateChanged() { 908 void Browser::WindowFullscreenStateChanged() {
940 fullscreen_controller_->WindowFullscreenStateChanged(); 909 fullscreen_controller_->WindowFullscreenStateChanged();
941 FullScreenMode fullscreen_mode = FULLSCREEN_DISABLED; 910 command_controller_->FullscreenStateChanged();
942 if (window_->IsFullscreen()) {
943 #if defined(OS_WIN)
944 fullscreen_mode = window_->IsInMetroSnapMode() ? FULLSCREEN_METRO_SNAP :
945 FULLSCREEN_NORMAL;
946 #else
947 fullscreen_mode = FULLSCREEN_NORMAL;
948 #endif
949 }
950 UpdateCommandsForFullscreenMode(fullscreen_mode);
951 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); 911 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN);
952 } 912 }
953 913
954 /////////////////////////////////////////////////////////////////////////////// 914 ///////////////////////////////////////////////////////////////////////////////
955 // Browser, Assorted browser commands: 915 // Browser, Assorted browser commands:
956 916
957 void Browser::ToggleFullscreenMode() { 917 void Browser::ToggleFullscreenMode() {
958 fullscreen_controller_->ToggleFullscreenMode(); 918 fullscreen_controller_->ToggleFullscreenMode();
959 } 919 }
960 920
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 if (!tab_contents || !tab_contents->find_tab_helper()) 1142 if (!tab_contents || !tab_contents->find_tab_helper())
1183 return; 1143 return;
1184 1144
1185 tab_contents->find_tab_helper()->HandleFindReply(request_id, 1145 tab_contents->find_tab_helper()->HandleFindReply(request_id,
1186 number_of_matches, 1146 number_of_matches,
1187 selection_rect, 1147 selection_rect,
1188 active_match_ordinal, 1148 active_match_ordinal,
1189 final_update); 1149 final_update);
1190 } 1150 }
1191 1151
1192 void Browser::ExecuteCommand(int id) {
1193 ExecuteCommandWithDisposition(id, CURRENT_TAB);
1194 }
1195
1196 void Browser::ExecuteCommand(int id, int event_flags) {
1197 ExecuteCommandWithDisposition(
1198 id, browser::DispositionFromEventFlags(event_flags));
1199 }
1200
1201 bool Browser::ExecuteCommandIfEnabled(int id) {
1202 if (command_updater_.SupportsCommand(id) &&
1203 command_updater_.IsCommandEnabled(id)) {
1204 ExecuteCommand(id);
1205 return true;
1206 }
1207 return false;
1208 }
1209
1210 bool Browser::IsReservedCommandOrKey(int command_id,
1211 const NativeWebKeyboardEvent& event) {
1212 // In Apps mode, no keys are reserved.
1213 if (is_app())
1214 return false;
1215
1216 #if defined(OS_CHROMEOS)
1217 // Chrome OS's top row of keys produces F1-10. Make sure that web pages
1218 // aren't able to block Chrome from performing the standard actions for F1-F4.
1219 // We should not handle F5-10 here since they are processed by Ash. See also:
1220 // crbug.com/127333#c8
1221 ui::KeyboardCode key_code =
1222 static_cast<ui::KeyboardCode>(event.windowsKeyCode);
1223 if ((key_code == ui::VKEY_F1 ||
1224 key_code == ui::VKEY_F2 ||
1225 key_code == ui::VKEY_F3 ||
1226 key_code == ui::VKEY_F4) &&
1227 // Make sure it's a browser shortcut (i.e. not an Ash one like Alt+F4).
1228 command_id != -1) {
1229 return true;
1230 }
1231 #endif
1232
1233 if (window_->IsFullscreen() && command_id == IDC_FULLSCREEN)
1234 return true;
1235 return command_id == IDC_CLOSE_TAB ||
1236 command_id == IDC_CLOSE_WINDOW ||
1237 command_id == IDC_NEW_INCOGNITO_WINDOW ||
1238 command_id == IDC_NEW_TAB ||
1239 command_id == IDC_NEW_WINDOW ||
1240 command_id == IDC_RESTORE_TAB ||
1241 command_id == IDC_SELECT_NEXT_TAB ||
1242 command_id == IDC_SELECT_PREVIOUS_TAB ||
1243 command_id == IDC_TABPOSE ||
1244 command_id == IDC_EXIT ||
1245 command_id == IDC_SEARCH;
1246 }
1247
1248 void Browser::SetBlockCommandExecution(bool block) {
1249 block_command_execution_ = block;
1250 if (block) {
1251 last_blocked_command_id_ = -1;
1252 last_blocked_command_disposition_ = CURRENT_TAB;
1253 }
1254 }
1255
1256 int Browser::GetLastBlockedCommand(WindowOpenDisposition* disposition) {
1257 if (disposition)
1258 *disposition = last_blocked_command_disposition_;
1259 return last_blocked_command_id_;
1260 }
1261
1262 void Browser::UpdateUIForNavigationInTab(TabContents* contents, 1152 void Browser::UpdateUIForNavigationInTab(TabContents* contents,
1263 content::PageTransition transition, 1153 content::PageTransition transition,
1264 bool user_initiated) { 1154 bool user_initiated) {
1265 tab_strip_model_->TabNavigating(contents, transition); 1155 tab_strip_model_->TabNavigating(contents, transition);
1266 1156
1267 bool contents_is_selected = contents == GetActiveTabContents(); 1157 bool contents_is_selected = contents == GetActiveTabContents();
1268 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { 1158 if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
1269 // Forcibly reset the location bar if the url is going to change in the 1159 // Forcibly reset the location bar if the url is going to change in the
1270 // current tab, since otherwise it won't discard any ongoing user edits, 1160 // current tab, since otherwise it won't discard any ongoing user edits,
1271 // since it doesn't realize this is a user-initiated action. 1161 // since it doesn't realize this is a user-initiated action.
(...skipping 15 matching lines...) Expand all
1287 contents->web_contents()->Focus(); 1177 contents->web_contents()->Focus();
1288 } 1178 }
1289 1179
1290 /////////////////////////////////////////////////////////////////////////////// 1180 ///////////////////////////////////////////////////////////////////////////////
1291 // Browser, PageNavigator implementation: 1181 // Browser, PageNavigator implementation:
1292 1182
1293 WebContents* Browser::OpenURL(const OpenURLParams& params) { 1183 WebContents* Browser::OpenURL(const OpenURLParams& params) {
1294 return OpenURLFromTab(NULL, params); 1184 return OpenURLFromTab(NULL, params);
1295 } 1185 }
1296 1186
1297 ///////////////////////////////////////////////////////////////////////////////
1298 // Browser, CommandUpdater::CommandUpdaterDelegate implementation:
1299
1300 void Browser::ExecuteCommandWithDisposition(
1301 int id, WindowOpenDisposition disposition) {
1302 // No commands are enabled if there is not yet any selected tab.
1303 // TODO(pkasting): It seems like we should not need this, because either
1304 // most/all commands should not have been enabled yet anyway or the ones that
1305 // are enabled should be global, or safe themselves against having no selected
1306 // tab. However, Ben says he tried removing this before and got lots of
1307 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
1308 // window construction. This probably could use closer examination someday.
1309 if (!GetActiveTabContents())
1310 return;
1311
1312 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
1313 << id;
1314
1315 // If command execution is blocked then just record the command and return.
1316 if (block_command_execution_) {
1317 // We actually only allow no more than one blocked command, otherwise some
1318 // commands maybe lost.
1319 DCHECK_EQ(last_blocked_command_id_, -1);
1320 last_blocked_command_id_ = id;
1321 last_blocked_command_disposition_ = disposition;
1322 return;
1323 }
1324
1325 // The order of commands in this switch statement must match the function
1326 // declaration order in browser.h!
1327 switch (id) {
1328 // Navigation commands
1329 case IDC_BACK: chrome::GoBack(this, disposition);break;
1330 case IDC_FORWARD:
1331 chrome::GoForward(this, disposition);
1332 break;
1333 case IDC_RELOAD: chrome::Reload(this, disposition);break;
1334 case IDC_RELOAD_IGNORING_CACHE:
1335 chrome::ReloadIgnoringCache(this, disposition);
1336 break;
1337 case IDC_HOME: chrome::Home(this, disposition); break;
1338 case IDC_OPEN_CURRENT_URL: chrome::OpenCurrentURL(this); break;
1339 case IDC_STOP: chrome::Stop(this); break;
1340
1341 // Window management commands
1342 case IDC_NEW_WINDOW: chrome::NewWindow(this); break;
1343 case IDC_NEW_INCOGNITO_WINDOW: chrome::NewIncognitoWindow(this); break;
1344 case IDC_CLOSE_WINDOW: chrome::CloseWindow(this); break;
1345 case IDC_NEW_TAB: chrome::NewTab(this); break;
1346 case IDC_CLOSE_TAB: chrome::CloseTab(this); break;
1347 case IDC_SELECT_NEXT_TAB: chrome::SelectNextTab(this); break;
1348 case IDC_SELECT_PREVIOUS_TAB: chrome::SelectPreviousTab(this); break;
1349 case IDC_TABPOSE: chrome::OpenTabpose(this); break;
1350 case IDC_MOVE_TAB_NEXT: chrome::MoveTabNext(this); break;
1351 case IDC_MOVE_TAB_PREVIOUS: chrome::MoveTabPrevious(this); break;
1352 case IDC_SELECT_TAB_0:
1353 case IDC_SELECT_TAB_1:
1354 case IDC_SELECT_TAB_2:
1355 case IDC_SELECT_TAB_3:
1356 case IDC_SELECT_TAB_4:
1357 case IDC_SELECT_TAB_5:
1358 case IDC_SELECT_TAB_6:
1359 case IDC_SELECT_TAB_7:
1360 chrome::SelectNumberedTab(this, id - IDC_SELECT_TAB_0);
1361 break;
1362 case IDC_SELECT_LAST_TAB: chrome::SelectLastTab(this); break;
1363 case IDC_DUPLICATE_TAB: chrome::DuplicateTab(this); break;
1364 case IDC_RESTORE_TAB: RestoreTab(); break;
1365 case IDC_COPY_URL:
1366 chrome::WriteCurrentURLToClipboard(this);
1367 break;
1368 case IDC_SHOW_AS_TAB:
1369 chrome::ConvertPopupToTabbedBrowser(this);
1370 break;
1371 case IDC_FULLSCREEN: ToggleFullscreenMode(); break;
1372 #if defined(OS_WIN)
1373 case IDC_METRO_SNAP_ENABLE: SetMetroSnapMode(true); break;
1374 case IDC_METRO_SNAP_DISABLE: SetMetroSnapMode(false); break;
1375 #endif
1376 #if defined(OS_MACOSX)
1377 case IDC_PRESENTATION_MODE: TogglePresentationMode(); break;
1378 #endif
1379 case IDC_EXIT: chrome::Exit(); break;
1380
1381 // Page-related commands
1382 case IDC_SAVE_PAGE: chrome::SavePage(this); break;
1383 case IDC_BOOKMARK_PAGE: chrome::BookmarkCurrentPage(this);break;
1384 case IDC_PIN_TO_START_SCREEN:
1385 chrome::PinCurrentPageToStartScreen(this);
1386 break;
1387 case IDC_BOOKMARK_ALL_TABS: BookmarkAllTabs(); break;
1388 case IDC_VIEW_SOURCE: chrome::ViewSelectedSource(this); break;
1389 case IDC_EMAIL_PAGE_LOCATION: chrome::EmailPageLocation(this); break;
1390 case IDC_PRINT: chrome::Print(this); break;
1391 case IDC_ADVANCED_PRINT: chrome::AdvancedPrint(this); break;
1392 case IDC_CHROME_TO_MOBILE_PAGE:
1393 chrome::ShowChromeToMobileBubble(this);
1394 break;
1395 case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break;
1396 case IDC_ENCODING_UTF8:
1397 case IDC_ENCODING_UTF16LE:
1398 case IDC_ENCODING_ISO88591:
1399 case IDC_ENCODING_WINDOWS1252:
1400 case IDC_ENCODING_GBK:
1401 case IDC_ENCODING_GB18030:
1402 case IDC_ENCODING_BIG5HKSCS:
1403 case IDC_ENCODING_BIG5:
1404 case IDC_ENCODING_KOREAN:
1405 case IDC_ENCODING_SHIFTJIS:
1406 case IDC_ENCODING_ISO2022JP:
1407 case IDC_ENCODING_EUCJP:
1408 case IDC_ENCODING_THAI:
1409 case IDC_ENCODING_ISO885915:
1410 case IDC_ENCODING_MACINTOSH:
1411 case IDC_ENCODING_ISO88592:
1412 case IDC_ENCODING_WINDOWS1250:
1413 case IDC_ENCODING_ISO88595:
1414 case IDC_ENCODING_WINDOWS1251:
1415 case IDC_ENCODING_KOI8R:
1416 case IDC_ENCODING_KOI8U:
1417 case IDC_ENCODING_ISO88597:
1418 case IDC_ENCODING_WINDOWS1253:
1419 case IDC_ENCODING_ISO88594:
1420 case IDC_ENCODING_ISO885913:
1421 case IDC_ENCODING_WINDOWS1257:
1422 case IDC_ENCODING_ISO88593:
1423 case IDC_ENCODING_ISO885910:
1424 case IDC_ENCODING_ISO885914:
1425 case IDC_ENCODING_ISO885916:
1426 case IDC_ENCODING_WINDOWS1254:
1427 case IDC_ENCODING_ISO88596:
1428 case IDC_ENCODING_WINDOWS1256:
1429 case IDC_ENCODING_ISO88598:
1430 case IDC_ENCODING_ISO88598I:
1431 case IDC_ENCODING_WINDOWS1255:
1432 case IDC_ENCODING_WINDOWS1258: OverrideEncoding(id); break;
1433
1434 // Clipboard commands
1435 case IDC_CUT: chrome::Cut(this); break;
1436 case IDC_COPY: chrome::Copy(this); break;
1437 case IDC_PASTE: chrome::Paste(this); break;
1438
1439 // Find-in-page
1440 case IDC_FIND: chrome::Find(this); break;
1441 case IDC_FIND_NEXT: chrome::FindNext(this); break;
1442 case IDC_FIND_PREVIOUS: chrome::FindPrevious(this); break;
1443
1444 // Zoom
1445 case IDC_ZOOM_PLUS:
1446 chrome::Zoom(this, content::PAGE_ZOOM_IN);
1447 break;
1448 case IDC_ZOOM_NORMAL:
1449 chrome::Zoom(this, content::PAGE_ZOOM_RESET);
1450 break;
1451 case IDC_ZOOM_MINUS:
1452 chrome::Zoom(this, content::PAGE_ZOOM_OUT);
1453 break;
1454
1455 // Focus various bits of UI
1456 case IDC_FOCUS_TOOLBAR: chrome::FocusToolbar(this); break;
1457 case IDC_FOCUS_LOCATION: chrome::FocusLocationBar(this); break;
1458 case IDC_FOCUS_SEARCH: chrome::FocusSearch(this); break;
1459 case IDC_FOCUS_MENU_BAR: chrome::FocusAppMenu(this); break;
1460 case IDC_FOCUS_BOOKMARKS:
1461 chrome::FocusBookmarksToolbar(this);
1462 break;
1463 case IDC_FOCUS_NEXT_PANE: chrome::FocusNextPane(this); break;
1464 case IDC_FOCUS_PREVIOUS_PANE: chrome::FocusPreviousPane(this); break;
1465
1466 // Show various bits of UI
1467 case IDC_OPEN_FILE: OpenFile(); break;
1468 case IDC_CREATE_SHORTCUTS: OpenCreateShortcutsDialog(); break;
1469 case IDC_DEV_TOOLS:
1470 chrome::ToggleDevToolsWindow(this, DEVTOOLS_TOGGLE_ACTION_NONE);
1471 break;
1472 case IDC_DEV_TOOLS_CONSOLE:
1473 chrome::ToggleDevToolsWindow(this, DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE);
1474 break;
1475 case IDC_DEV_TOOLS_INSPECT:
1476 chrome::ToggleDevToolsWindow(this, DEVTOOLS_TOGGLE_ACTION_INSPECT);
1477 break;
1478 case IDC_TASK_MANAGER:
1479 chrome::OpenTaskManager(this, false);
1480 break;
1481 case IDC_VIEW_BACKGROUND_PAGES:
1482 chrome::OpenTaskManager(this, true);
1483 break;
1484 case IDC_FEEDBACK:
1485 chrome::OpenFeedbackDialog(this);
1486 break;
1487
1488 case IDC_SHOW_BOOKMARK_BAR: chrome::ToggleBookmarkBar(this); break;
1489 case IDC_PROFILING_ENABLED: Profiling::Toggle(); break;
1490
1491 case IDC_SHOW_BOOKMARK_MANAGER: chrome::ShowBookmarkManager(this);break;
1492 case IDC_SHOW_APP_MENU: chrome::ShowAppMenu(this); break;
1493 case IDC_SHOW_AVATAR_MENU: chrome::ShowAvatarMenu(this); break;
1494 case IDC_SHOW_HISTORY: chrome::ShowHistory(this); break;
1495 case IDC_SHOW_DOWNLOADS: chrome::ShowDownloads(this); break;
1496 case IDC_MANAGE_EXTENSIONS: chrome::ShowExtensions(this); break;
1497 case IDC_OPTIONS: chrome::ShowSettings(this); break;
1498 case IDC_EDIT_SEARCH_ENGINES:
1499 chrome::ShowSearchEngineSettings(this);
1500 break;
1501 case IDC_VIEW_PASSWORDS: chrome::ShowPasswordManager(this);break;
1502 case IDC_CLEAR_BROWSING_DATA:
1503 chrome::ShowClearBrowsingDataDialog(this);
1504 break;
1505 case IDC_IMPORT_SETTINGS: chrome::ShowImportDialog(this); break;
1506 case IDC_ABOUT: chrome::ShowAboutChrome(this); break;
1507 case IDC_UPGRADE_DIALOG:
1508 chrome::OpenUpdateChromeDialog(this);
1509 break;
1510 case IDC_VIEW_INCOMPATIBILITIES:
1511 chrome::ShowConflicts(this);
1512 break;
1513 case IDC_HELP_PAGE_VIA_KEYBOARD:
1514 chrome::ShowHelp(this, chrome::HELP_SOURCE_KEYBOARD);
1515 break;
1516 case IDC_HELP_PAGE_VIA_MENU:
1517 chrome::ShowHelp(this, chrome::HELP_SOURCE_MENU);
1518 break;
1519 case IDC_SHOW_SYNC_SETUP:
1520 chrome::ShowSyncSetup(this, SyncPromoUI::SOURCE_MENU);
1521 break;
1522 case IDC_TOGGLE_SPEECH_INPUT: chrome::ToggleSpeechInput(this); break;
1523
1524 default:
1525 LOG(WARNING) << "Received Unimplemented Command: " << id;
1526 break;
1527 }
1528 }
1529
1530 ////////////////////////////////////////////////////////////////////////////////
1531 // Browser, TabRestoreServiceObserver:
1532
1533 void Browser::TabRestoreServiceChanged(TabRestoreService* service) {
1534 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB,
1535 !service->entries().empty());
1536 }
1537
1538 void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) {
1539 if (!tab_restore_service_)
1540 return;
1541
1542 DCHECK_EQ(tab_restore_service_, service);
1543 tab_restore_service_->RemoveObserver(this);
1544 tab_restore_service_ = NULL;
1545 }
1546
1547 // Centralized method for creating a TabContents, configuring and 1187 // Centralized method for creating a TabContents, configuring and
1548 // installing all its supporting objects and observers. 1188 // installing all its supporting objects and observers.
1549 TabContents* Browser::TabContentsFactory( 1189 TabContents* Browser::TabContentsFactory(
1550 Profile* profile, 1190 Profile* profile,
1551 SiteInstance* site_instance, 1191 SiteInstance* site_instance,
1552 int routing_id, 1192 int routing_id,
1553 const WebContents* base_web_contents, 1193 const WebContents* base_web_contents,
1554 content::SessionStorageNamespace* session_storage_namespace) { 1194 content::SessionStorageNamespace* session_storage_namespace) {
1555 WebContents* new_contents = WebContents::Create( 1195 WebContents* new_contents = WebContents::Create(
1556 profile, site_instance, routing_id, base_web_contents, 1196 profile, site_instance, routing_id, base_web_contents,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 service->CreateHistoricalTab(contents->web_contents(), 1348 service->CreateHistoricalTab(contents->web_contents(),
1709 tab_strip_model_->GetIndexOfTabContents(contents)); 1349 tab_strip_model_->GetIndexOfTabContents(contents));
1710 } 1350 }
1711 } 1351 }
1712 1352
1713 bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) { 1353 bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) {
1714 return Browser::RunUnloadEventsHelper(contents->web_contents()); 1354 return Browser::RunUnloadEventsHelper(contents->web_contents());
1715 } 1355 }
1716 1356
1717 bool Browser::CanBookmarkAllTabs() const { 1357 bool Browser::CanBookmarkAllTabs() const {
1718 BookmarkModel* model = profile()->GetBookmarkModel(); 1358 return chrome::CanBookmarkAllTabs(this);
1719 return (model && model->IsLoaded()) &&
1720 tab_count() > 1 &&
1721 profile()->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled);
1722 } 1359 }
1723 1360
1724 void Browser::BookmarkAllTabs() { 1361 void Browser::BookmarkAllTabs() {
1725 BookmarkEditor::ShowBookmarkAllTabsDialog(this); 1362 chrome::BookmarkAllTabs(this);
1726 } 1363 }
1727 1364
1728 bool Browser::CanRestoreTab() { 1365 bool Browser::CanRestoreTab() {
1729 return command_updater_.IsCommandEnabled(IDC_RESTORE_TAB); 1366 return chrome::CanRestoreTab(this);
1730 } 1367 }
1731 1368
1732 void Browser::RestoreTab() { 1369 void Browser::RestoreTab() {
1733 content::RecordAction(UserMetricsAction("RestoreTab")); 1370 chrome::RestoreTab(this);
1734 TabRestoreService* service =
1735 TabRestoreServiceFactory::GetForProfile(profile_);
1736 if (!service)
1737 return;
1738
1739 service->RestoreMostRecentEntry(tab_restore_service_delegate());
1740 } 1371 }
1741 1372
1742 /////////////////////////////////////////////////////////////////////////////// 1373 ///////////////////////////////////////////////////////////////////////////////
1743 // Browser, TabStripModelObserver implementation: 1374 // Browser, TabStripModelObserver implementation:
1744 1375
1745 void Browser::TabInsertedAt(TabContents* contents, 1376 void Browser::TabInsertedAt(TabContents* contents,
1746 int index, 1377 int index,
1747 bool foreground) { 1378 bool foreground) {
1748 SetAsDelegate(contents, this); 1379 SetAsDelegate(contents, this);
1749 contents->restore_tab_helper()->SetWindowID(session_id()); 1380 contents->restore_tab_helper()->SetWindowID(session_id());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 if (chrome_updater_factory_.HasWeakPtrs() && old_contents) 1460 if (chrome_updater_factory_.HasWeakPtrs() && old_contents)
1830 ProcessPendingUIUpdates(); 1461 ProcessPendingUIUpdates();
1831 1462
1832 // Propagate the profile to the location bar. 1463 // Propagate the profile to the location bar.
1833 UpdateToolbar(true); 1464 UpdateToolbar(true);
1834 1465
1835 // Propagate tab state to toolbar, tab-strip, etc. 1466 // Propagate tab state to toolbar, tab-strip, etc.
1836 UpdateSearchState(new_contents); 1467 UpdateSearchState(new_contents);
1837 1468
1838 // Update reload/stop state. 1469 // Update reload/stop state.
1839 UpdateReloadStopState(new_contents->web_contents()->IsLoading(), true); 1470 command_controller_->LoadingStateChanged(
1471 new_contents->web_contents()->IsLoading(), true);
1840 1472
1841 // Update commands to reflect current state. 1473 // Update commands to reflect current state.
1842 UpdateCommandsForTabState(); 1474 command_controller_->TabStateChanged();
1843 1475
1844 // Reset the status bubble. 1476 // Reset the status bubble.
1845 StatusBubble* status_bubble = GetStatusBubble(); 1477 StatusBubble* status_bubble = GetStatusBubble();
1846 if (status_bubble) { 1478 if (status_bubble) {
1847 status_bubble->Hide(); 1479 status_bubble->Hide();
1848 1480
1849 // Show the loading state (if any). 1481 // Show the loading state (if any).
1850 status_bubble->SetStatus( 1482 status_bubble->SetStatus(
1851 GetActiveTabContents()->core_tab_helper()->GetStatusText()); 1483 GetActiveTabContents()->core_tab_helper()->GetStatusText());
1852 } 1484 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 // Only update the UI when something visible has changed. 1672 // Only update the UI when something visible has changed.
2041 if (changed_flags) 1673 if (changed_flags)
2042 ScheduleUIUpdate(source, changed_flags); 1674 ScheduleUIUpdate(source, changed_flags);
2043 1675
2044 // We can synchronously update commands since they will only change once per 1676 // We can synchronously update commands since they will only change once per
2045 // navigation, so we don't have to worry about flickering. We do, however, 1677 // navigation, so we don't have to worry about flickering. We do, however,
2046 // need to update the command state early on load to always present usable 1678 // need to update the command state early on load to always present usable
2047 // actions in the face of slow-to-commit pages. 1679 // actions in the face of slow-to-commit pages.
2048 if (changed_flags & (content::INVALIDATE_TYPE_URL | 1680 if (changed_flags & (content::INVALIDATE_TYPE_URL |
2049 content::INVALIDATE_TYPE_LOAD)) 1681 content::INVALIDATE_TYPE_LOAD))
2050 UpdateCommandsForTabState(); 1682 command_controller_->TabStateChanged();
2051 } 1683 }
2052 1684
2053 void Browser::AddNewContents(WebContents* source, 1685 void Browser::AddNewContents(WebContents* source,
2054 WebContents* new_contents, 1686 WebContents* new_contents,
2055 WindowOpenDisposition disposition, 1687 WindowOpenDisposition disposition,
2056 const gfx::Rect& initial_pos, 1688 const gfx::Rect& initial_pos,
2057 bool user_gesture) { 1689 bool user_gesture) {
2058 // No code for this yet. 1690 // No code for this yet.
2059 DCHECK(disposition != SAVE_TO_DISK); 1691 DCHECK(disposition != SAVE_TO_DISK);
2060 // Can't create a new contents for the current tab - invalid case. 1692 // Can't create a new contents for the current tab - invalid case.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2115 window_->Deactivate(); 1747 window_->Deactivate();
2116 } 1748 }
2117 1749
2118 void Browser::LoadingStateChanged(WebContents* source) { 1750 void Browser::LoadingStateChanged(WebContents* source) {
2119 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading()); 1751 window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading());
2120 window_->UpdateTitleBar(); 1752 window_->UpdateTitleBar();
2121 1753
2122 WebContents* selected_contents = GetActiveWebContents(); 1754 WebContents* selected_contents = GetActiveWebContents();
2123 if (source == selected_contents) { 1755 if (source == selected_contents) {
2124 bool is_loading = source->IsLoading(); 1756 bool is_loading = source->IsLoading();
2125 UpdateReloadStopState(is_loading, false); 1757 command_controller_->LoadingStateChanged(is_loading, false);
2126 if (GetStatusBubble()) { 1758 if (GetStatusBubble()) {
2127 GetStatusBubble()->SetStatus( 1759 GetStatusBubble()->SetStatus(
2128 GetActiveTabContents()->core_tab_helper()->GetStatusText()); 1760 GetActiveTabContents()->core_tab_helper()->GetStatusText());
2129 } 1761 }
2130 1762
2131 if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) { 1763 if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) {
2132 // Schedule a shortcut update when web application info is available if 1764 // Schedule a shortcut update when web application info is available if
2133 // last committed entry is not NULL. Last committed entry could be NULL 1765 // last committed entry is not NULL. Last committed entry could be NULL
2134 // when an interstitial page is injected (e.g. bad https certificate, 1766 // when an interstitial page is injected (e.g. bad https certificate,
2135 // malware site etc). When this happens, we abort the shortcut update. 1767 // malware site etc). When this happens, we abort the shortcut update.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 return; 1831 return;
2200 1832
2201 if (source == GetActiveWebContents()) { 1833 if (source == GetActiveWebContents()) {
2202 GetStatusBubble()->MouseMoved(location, !motion); 1834 GetStatusBubble()->MouseMoved(location, !motion);
2203 if (!motion) 1835 if (!motion)
2204 GetStatusBubble()->SetURL(GURL(), std::string()); 1836 GetStatusBubble()->SetURL(GURL(), std::string());
2205 } 1837 }
2206 } 1838 }
2207 1839
2208 void Browser::ContentsZoomChange(bool zoom_in) { 1840 void Browser::ContentsZoomChange(bool zoom_in) {
2209 ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); 1841 chrome::ExecuteCommand(this, zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS);
2210 } 1842 }
2211 1843
2212 void Browser::WebContentsFocused(WebContents* contents) { 1844 void Browser::WebContentsFocused(WebContents* contents) {
2213 window_->WebContentsFocused(contents); 1845 window_->WebContentsFocused(contents);
2214 } 1846 }
2215 1847
2216 bool Browser::TakeFocus(bool reverse) { 1848 bool Browser::TakeFocus(bool reverse) {
2217 content::NotificationService::current()->Notify( 1849 content::NotificationService::current()->Notify(
2218 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, 1850 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
2219 content::Source<Browser>(this), 1851 content::Source<Browser>(this),
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 details.target_url = target_url; 2029 details.target_url = target_url;
2398 details.target_web_contents = new_contents; 2030 details.target_web_contents = new_contents;
2399 details.not_yet_in_tabstrip = true; 2031 details.not_yet_in_tabstrip = true;
2400 content::NotificationService::current()->Notify( 2032 content::NotificationService::current()->Notify(
2401 chrome::NOTIFICATION_RETARGETING, 2033 chrome::NOTIFICATION_RETARGETING,
2402 content::Source<Profile>(profile_), 2034 content::Source<Profile>(profile_),
2403 content::Details<RetargetingDetails>(&details)); 2035 content::Details<RetargetingDetails>(&details));
2404 } 2036 }
2405 2037
2406 void Browser::ContentRestrictionsChanged(WebContents* source) { 2038 void Browser::ContentRestrictionsChanged(WebContents* source) {
2407 UpdateCommandsForContentRestrictionState(); 2039 command_controller_->ContentRestrictionsChanged();
2408 } 2040 }
2409 2041
2410 void Browser::RendererUnresponsive(WebContents* source) { 2042 void Browser::RendererUnresponsive(WebContents* source) {
2411 // Ignore hangs if print preview is open. 2043 // Ignore hangs if print preview is open.
2412 TabContents* tab_contents = TabContents::FromWebContents(source); 2044 TabContents* tab_contents = TabContents::FromWebContents(source);
2413 if (tab_contents) { 2045 if (tab_contents) {
2414 printing::PrintPreviewTabController* controller = 2046 printing::PrintPreviewTabController* controller =
2415 printing::PrintPreviewTabController::GetInstance(); 2047 printing::PrintPreviewTabController::GetInstance();
2416 if (controller) { 2048 if (controller) {
2417 TabContents* preview_tab = 2049 TabContents* preview_tab =
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2601 // Browser, CoreTabHelperDelegate implementation: 2233 // Browser, CoreTabHelperDelegate implementation:
2602 2234
2603 void Browser::SwapTabContents(TabContents* old_tab_contents, 2235 void Browser::SwapTabContents(TabContents* old_tab_contents,
2604 TabContents* new_tab_contents) { 2236 TabContents* new_tab_contents) {
2605 int index = tab_strip_model_->GetIndexOfTabContents(old_tab_contents); 2237 int index = tab_strip_model_->GetIndexOfTabContents(old_tab_contents);
2606 DCHECK_NE(TabStripModel::kNoTab, index); 2238 DCHECK_NE(TabStripModel::kNoTab, index);
2607 tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents); 2239 tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents);
2608 } 2240 }
2609 2241
2610 bool Browser::CanReloadContents(TabContents* source) const { 2242 bool Browser::CanReloadContents(TabContents* source) const {
2611 return !is_devtools(); 2243 return chrome::CanReload(this);
2612 } 2244 }
2613 2245
2614 bool Browser::CanSaveContents(TabContents* source) const { 2246 bool Browser::CanSaveContents(TabContents* source) const {
2615 return !is_devtools(); 2247 return chrome::CanSavePage(this);
2616 } 2248 }
2617 2249
2618 /////////////////////////////////////////////////////////////////////////////// 2250 ///////////////////////////////////////////////////////////////////////////////
2619 // Browser, SearchEngineTabHelperDelegate implementation: 2251 // Browser, SearchEngineTabHelperDelegate implementation:
2620 2252
2621 void Browser::ConfirmAddSearchProvider(TemplateURL* template_url, 2253 void Browser::ConfirmAddSearchProvider(TemplateURL* template_url,
2622 Profile* profile) { 2254 Profile* profile) {
2623 window()->ConfirmAddSearchProvider(template_url, profile); 2255 window()->ConfirmAddSearchProvider(template_url, profile);
2624 } 2256 }
2625 2257
2626 /////////////////////////////////////////////////////////////////////////////// 2258 ///////////////////////////////////////////////////////////////////////////////
2627 // Browser, ConstrainedWindowTabHelperDelegate implementation: 2259 // Browser, ConstrainedWindowTabHelperDelegate implementation:
2628 2260
2629 void Browser::SetTabContentBlocked(TabContents* tab_contents, bool blocked) { 2261 void Browser::SetTabContentBlocked(TabContents* tab_contents, bool blocked) {
2630 int index = tab_strip_model_->GetIndexOfTabContents(tab_contents); 2262 int index = tab_strip_model_->GetIndexOfTabContents(tab_contents);
2631 if (index == TabStripModel::kNoTab) { 2263 if (index == TabStripModel::kNoTab) {
2632 NOTREACHED(); 2264 NOTREACHED();
2633 return; 2265 return;
2634 } 2266 }
2635 tab_strip_model_->SetTabBlocked(index, blocked); 2267 tab_strip_model_->SetTabBlocked(index, blocked);
2636 UpdatePrintingState(tab_contents->web_contents()->GetContentRestrictions()); 2268 command_controller_->PrintingStateChanged();
2637 if (!blocked && GetActiveTabContents() == tab_contents) 2269 if (!blocked && GetActiveTabContents() == tab_contents)
2638 tab_contents->web_contents()->Focus(); 2270 tab_contents->web_contents()->Focus();
2639 } 2271 }
2640 2272
2641 /////////////////////////////////////////////////////////////////////////////// 2273 ///////////////////////////////////////////////////////////////////////////////
2642 // Browser, BlockedContentTabHelperDelegate implementation: 2274 // Browser, BlockedContentTabHelperDelegate implementation:
2643 2275
2644 TabContents* Browser::GetConstrainingTabContents(TabContents* source) { 2276 TabContents* Browser::GetConstrainingTabContents(TabContents* source) {
2645 return source; 2277 return source;
2646 } 2278 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2814 2446
2815 #if defined(ENABLE_THEMES) 2447 #if defined(ENABLE_THEMES)
2816 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: 2448 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
2817 window()->UserChangedTheme(); 2449 window()->UserChangedTheme();
2818 break; 2450 break;
2819 #endif 2451 #endif
2820 2452
2821 case chrome::NOTIFICATION_PREF_CHANGED: { 2453 case chrome::NOTIFICATION_PREF_CHANGED: {
2822 const std::string& pref_name = 2454 const std::string& pref_name =
2823 *content::Details<std::string>(details).ptr(); 2455 *content::Details<std::string>(details).ptr();
2824 if (pref_name == prefs::kPrintingEnabled) { 2456 if (pref_name == prefs::kInstantEnabled) {
2825 UpdatePrintingState(GetContentRestrictionsForSelectedTab());
2826 } else if (pref_name == prefs::kInstantEnabled) {
2827 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || 2457 if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() ||
2828 !InstantController::IsEnabled(profile())) { 2458 !InstantController::IsEnabled(profile())) {
2829 if (instant()) { 2459 if (instant()) {
2830 instant()->DestroyPreviewContents(); 2460 instant()->DestroyPreviewContents();
2831 instant_.reset(); 2461 instant_.reset();
2832 instant_unload_handler_.reset(); 2462 instant_unload_handler_.reset();
2833 } 2463 }
2834 } else { 2464 } else {
2835 CreateInstantIfNecessary(); 2465 CreateInstantIfNecessary();
2836 } 2466 }
2837 } else if (pref_name == prefs::kIncognitoModeAvailability) {
2838 UpdateCommandsForIncognitoAvailability();
2839 } else if (pref_name == prefs::kDevToolsDisabled) { 2467 } else if (pref_name == prefs::kDevToolsDisabled) {
2840 UpdateCommandsForDevTools();
2841 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 2468 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
2842 content::DevToolsManager::GetInstance()->CloseAllClientHosts(); 2469 content::DevToolsManager::GetInstance()->CloseAllClientHosts();
2843 } else if (pref_name == prefs::kEditBookmarksEnabled) {
2844 UpdateCommandsForBookmarkEditing();
2845 } else if (pref_name == prefs::kShowBookmarkBar) { 2470 } else if (pref_name == prefs::kShowBookmarkBar) {
2846 UpdateCommandsForBookmarkBar();
2847 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); 2471 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE);
2848 } else if (pref_name == prefs::kHomePage) { 2472 } else if (pref_name == prefs::kHomePage) {
2849 PrefService* pref_service = content::Source<PrefService>(source).ptr(); 2473 PrefService* pref_service = content::Source<PrefService>(source).ptr();
2850 MarkHomePageAsChanged(pref_service); 2474 MarkHomePageAsChanged(pref_service);
2851 } else if (pref_name == prefs::kAllowFileSelectionDialogs) {
2852 UpdateSaveAsState(GetContentRestrictionsForSelectedTab());
2853 UpdateOpenFileState();
2854 } else if (pref_name == prefs::kInManagedMode) {
2855 UpdateCommandsForMultipleProfiles();
2856 } else { 2475 } else {
2857 NOTREACHED(); 2476 NOTREACHED();
2858 } 2477 }
2859 break; 2478 break;
2860 } 2479 }
2861 2480
2862 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
sky 2012/06/27 03:09:28 This looks like it was removed from both. Don't we
2863 WebContents* web_contents = content::Source<WebContents>(source).ptr();
2864 if (web_contents == GetActiveWebContents()) {
2865 LocationBar* location_bar = window()->GetLocationBar();
2866 if (location_bar)
2867 location_bar->UpdateContentSettingsIcons();
2868 }
2869 break;
2870 }
2871
2872 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: 2481 case content::NOTIFICATION_INTERSTITIAL_ATTACHED:
2873 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 2482 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
2874 UpdateCommandsForTabState();
2875 break; 2483 break;
2876 2484
2877 case content::NOTIFICATION_INTERSTITIAL_DETACHED: 2485 case content::NOTIFICATION_INTERSTITIAL_DETACHED:
2878 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 2486 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
2879 UpdateCommandsForTabState();
2880 break; 2487 break;
2881 2488
2882 default: 2489 default:
2883 NOTREACHED() << "Got a notification we didn't register for."; 2490 NOTREACHED() << "Got a notification we didn't register for.";
2884 } 2491 }
2885 } 2492 }
2886 2493
2887 /////////////////////////////////////////////////////////////////////////////// 2494 ///////////////////////////////////////////////////////////////////////////////
2888 // Browser, ProfileSyncServiceObserver implementation:
2889
2890 void Browser::OnStateChanged() {
2891 DCHECK(ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
2892 profile_));
2893 // For unit tests, we don't have a window.
2894 if (!window_)
2895 return;
2896 const bool show_main_ui = IsShowingMainUI(window_->IsFullscreen());
2897 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
2898 show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible());
2899 }
2900
2901 ///////////////////////////////////////////////////////////////////////////////
2902 // Browser, InstantDelegate implementation: 2495 // Browser, InstantDelegate implementation:
2903 2496
2904 void Browser::ShowInstant(TabContents* preview_contents) { 2497 void Browser::ShowInstant(TabContents* preview_contents) {
2905 window_->ShowInstant(preview_contents); 2498 window_->ShowInstant(preview_contents);
2906 2499
2907 // TODO(beng): investigate if we can avoid this and instead rely on the 2500 // TODO(beng): investigate if we can avoid this and instead rely on the
2908 // visibility of the WebContentsView 2501 // visibility of the WebContentsView
2909 GetActiveWebContents()->WasHidden(); 2502 GetActiveWebContents()->WasHidden();
2910 preview_contents->web_contents()->WasRestored(); 2503 preview_contents->web_contents()->WasRestored();
2911 } 2504 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2950 window_->WebContentsFocused(instant_->GetPreviewContents()->web_contents()); 2543 window_->WebContentsFocused(instant_->GetPreviewContents()->web_contents());
2951 } 2544 }
2952 2545
2953 TabContents* Browser::GetInstantHostTabContents() const { 2546 TabContents* Browser::GetInstantHostTabContents() const {
2954 return GetActiveTabContents(); 2547 return GetActiveTabContents();
2955 } 2548 }
2956 2549
2957 /////////////////////////////////////////////////////////////////////////////// 2550 ///////////////////////////////////////////////////////////////////////////////
2958 // Browser, Command and state updating (private): 2551 // Browser, Command and state updating (private):
2959 2552
2960 bool Browser::IsShowingMainUI(bool is_fullscreen) {
2961 #if !defined(OS_MACOSX)
2962 return is_type_tabbed() && !is_fullscreen;
2963 #else
2964 return is_type_tabbed();
2965 #endif
2966 }
2967
2968 void Browser::InitCommandState() {
2969 // All browser commands whose state isn't set automagically some other way
2970 // (like Back & Forward with initial page load) must have their state
2971 // initialized here, otherwise they will be forever disabled.
2972
2973 // Navigation commands
2974 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
2975 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true);
2976
2977 // Window management commands
2978 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
2979 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
2980 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
2981 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
2982 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false);
2983 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
2984 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
2985
2986 // Page-related commands
2987 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
2988 command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true);
2989 command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true);
2990 command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true);
2991 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88591, true);
2992 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true);
2993 command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true);
2994 command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true);
2995 command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS, true);
2996 command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5, true);
2997 command_updater_.UpdateCommandEnabled(IDC_ENCODING_THAI, true);
2998 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOREAN, true);
2999 command_updater_.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS, true);
3000 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP, true);
3001 command_updater_.UpdateCommandEnabled(IDC_ENCODING_EUCJP, true);
3002 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885915, true);
3003 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH, true);
3004 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88592, true);
3005 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250, true);
3006 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88595, true);
3007 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251, true);
3008 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8R, true);
3009 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8U, true);
3010 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88597, true);
3011 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253, true);
3012 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88594, true);
3013 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885913, true);
3014 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257, true);
3015 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88593, true);
3016 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885910, true);
3017 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885914, true);
3018 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885916, true);
3019 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254, true);
3020 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88596, true);
3021 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true);
3022 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true);
3023 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true);
3024 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true);
3025 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true);
3026
3027 // Zoom
3028 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
3029 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
3030 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true);
3031 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
3032
3033 // Show various bits of UI
3034 UpdateOpenFileState();
3035 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
3036 UpdateCommandsForDevTools();
3037 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER,
3038 chrome::CanOpenTaskManager());
3039 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, true);
3040 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
3041 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
3042 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
3043 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, true);
3044
3045 command_updater_.UpdateCommandEnabled(
3046 IDC_SHOW_SYNC_SETUP, profile_->GetOriginalProfile()->IsSyncAccessible());
3047
3048 // Initialize other commands based on the window type.
3049 bool normal_window = is_type_tabbed();
3050
3051 // Navigation commands
3052 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window);
3053
3054 // Window management commands
3055 // TODO(rohitrao): Disable fullscreen on non-Lion?
3056 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN,
3057 !(is_type_panel() && is_app()));
3058 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
3059 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
3060 normal_window);
3061 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
3062 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
3063 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
3064 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
3065 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
3066 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
3067 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
3068 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
3069 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
3070 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
3071 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
3072 #if defined(OS_WIN)
3073 const bool metro_mode = base::win::IsMetroProcess();
3074 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro_mode);
3075 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro_mode);
3076 #endif
3077 #if defined(OS_MACOSX)
3078 command_updater_.UpdateCommandEnabled(IDC_TABPOSE, normal_window);
3079 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE,
3080 !(is_type_panel() && is_app()));
3081 #endif
3082
3083 // Clipboard commands
3084 command_updater_.UpdateCommandEnabled(IDC_COPY_URL, !is_devtools());
3085
3086 // Find-in-page
3087 command_updater_.UpdateCommandEnabled(IDC_FIND, !is_devtools());
3088 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, !is_devtools());
3089 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, !is_devtools());
3090
3091 // Show various bits of UI
3092 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
3093
3094 // The upgrade entry and the view incompatibility entry should always be
3095 // enabled. Whether they are visible is a separate matter determined on menu
3096 // show.
3097 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
3098 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
3099
3100 // View Background Pages entry is always enabled, but is hidden if there are
3101 // no background pages.
3102 command_updater_.UpdateCommandEnabled(IDC_VIEW_BACKGROUND_PAGES, true);
3103
3104 // Toggle speech input
3105 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true);
3106
3107 // Initialize other commands whose state changes based on fullscreen mode.
3108 UpdateCommandsForFullscreenMode(FULLSCREEN_DISABLED);
3109
3110 UpdateCommandsForContentRestrictionState();
3111
3112 UpdateCommandsForBookmarkEditing();
3113
3114 UpdateCommandsForIncognitoAvailability();
3115 }
3116
3117 void Browser::UpdateCommandsForIncognitoAvailability() {
3118 IncognitoModePrefs::Availability incognito_availability =
3119 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
3120 command_updater_.UpdateCommandEnabled(
3121 IDC_NEW_WINDOW,
3122 incognito_availability != IncognitoModePrefs::FORCED);
3123 command_updater_.UpdateCommandEnabled(
3124 IDC_NEW_INCOGNITO_WINDOW,
3125 incognito_availability != IncognitoModePrefs::DISABLED);
3126
3127 // Bookmark manager and settings page/subpages are forced to open in normal
3128 // mode. For this reason we disable these commands when incognito is forced.
3129 const bool command_enabled =
3130 incognito_availability != IncognitoModePrefs::FORCED;
3131 command_updater_.UpdateCommandEnabled(
3132 IDC_SHOW_BOOKMARK_MANAGER,
3133 browser_defaults::bookmarks_enabled && command_enabled);
3134 ExtensionService* extension_service = profile()->GetExtensionService();
3135 bool enable_extensions =
3136 extension_service && extension_service->extensions_enabled();
3137 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
3138 enable_extensions && command_enabled);
3139
3140 const bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen());
3141 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS,
3142 show_main_ui && command_enabled);
3143 command_updater_.UpdateCommandEnabled(IDC_OPTIONS,
3144 show_main_ui && command_enabled);
3145 }
3146
3147 void Browser::UpdateCommandsForTabState() {
3148 TabContents* current_tab_contents = GetActiveTabContents();
3149 if (!current_tab_contents) // May be NULL during tab restore.
3150 return;
3151 WebContents* current_web_contents = current_tab_contents->web_contents();
3152
3153 // Navigation commands
3154 NavigationController& nc = current_web_contents->GetController();
3155 command_updater_.UpdateCommandEnabled(IDC_BACK, nc.CanGoBack());
3156 command_updater_.UpdateCommandEnabled(IDC_FORWARD, nc.CanGoForward());
3157 command_updater_.UpdateCommandEnabled(
3158 IDC_RELOAD, CanReloadContents(current_tab_contents));
3159 command_updater_.UpdateCommandEnabled(
3160 IDC_RELOAD_IGNORING_CACHE, CanReloadContents(current_tab_contents));
3161
3162 // Window management commands
3163 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
3164 !is_app() && CanDuplicateContentsAt(active_index()));
3165
3166 // Page-related commands
3167 window_->SetStarredState(
3168 current_tab_contents->bookmark_tab_helper()->is_starred());
3169 window_->SetZoomIconState(
3170 current_tab_contents->zoom_controller()->zoom_icon_state());
3171 window_->SetZoomIconTooltipPercent(
3172 current_tab_contents->zoom_controller()->zoom_percent());
3173 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
3174 current_web_contents->GetController().CanViewSource());
3175 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
3176 toolbar_model_->ShouldDisplayURL() &&
3177 current_web_contents->GetURL().is_valid());
3178 if (is_devtools())
3179 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
3180
3181 // Changing the encoding is not possible on Chrome-internal webpages.
3182 bool is_chrome_internal = HasInternalURL(nc.GetActiveEntry()) ||
3183 current_web_contents->ShowingInterstitialPage();
3184 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU,
3185 !is_chrome_internal && current_web_contents->IsSavable());
3186
3187 // Show various bits of UI
3188 // TODO(pinkerton): Disable app-mode in the model until we implement it
3189 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
3190 #if !defined(OS_MACOSX)
3191 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS,
3192 web_app::IsValidUrl(current_web_contents->GetURL()));
3193 #endif
3194
3195 UpdateCommandsForContentRestrictionState();
3196 UpdateCommandsForBookmarkEditing();
3197 }
3198
3199 void Browser::UpdateCommandsForContentRestrictionState() {
3200 int restrictions = GetContentRestrictionsForSelectedTab();
3201
3202 command_updater_.UpdateCommandEnabled(
3203 IDC_COPY, !(restrictions & content::CONTENT_RESTRICTION_COPY));
3204 command_updater_.UpdateCommandEnabled(
3205 IDC_CUT, !(restrictions & content::CONTENT_RESTRICTION_CUT));
3206 command_updater_.UpdateCommandEnabled(
3207 IDC_PASTE, !(restrictions & content::CONTENT_RESTRICTION_PASTE));
3208 UpdateSaveAsState(restrictions);
3209 UpdatePrintingState(restrictions);
3210 }
3211
3212 void Browser::UpdateCommandsForDevTools() {
3213 bool dev_tools_enabled =
3214 !profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
3215 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
3216 dev_tools_enabled);
3217 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
3218 dev_tools_enabled);
3219 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
3220 dev_tools_enabled);
3221 }
3222
3223 void Browser::UpdateCommandsForBookmarkEditing() {
3224 bool enabled =
3225 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled) &&
3226 browser_defaults::bookmarks_enabled;
3227
3228 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
3229 enabled && is_type_tabbed());
3230 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
3231 enabled && CanBookmarkAllTabs());
3232 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN,
3233 true);
3234 }
3235
3236 void Browser::UpdateCommandsForBookmarkBar() {
3237 const bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen());
3238 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR,
3239 browser_defaults::bookmarks_enabled &&
3240 !profile_->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) &&
3241 show_main_ui);
3242 }
3243
3244 void Browser::MarkHomePageAsChanged(PrefService* pref_service) { 2553 void Browser::MarkHomePageAsChanged(PrefService* pref_service) {
3245 pref_service->SetBoolean(prefs::kHomePageChanged, true); 2554 pref_service->SetBoolean(prefs::kHomePageChanged, true);
3246 } 2555 }
3247 2556
3248 void Browser::UpdateCommandsForFullscreenMode(FullScreenMode fullscreen_mode) {
3249 const bool show_main_ui =
3250 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED);
3251 bool main_not_fullscreen = show_main_ui &&
3252 (fullscreen_mode == FULLSCREEN_DISABLED);
3253
3254 // Navigation commands
3255 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
3256
3257 // Window management commands
3258 command_updater_.UpdateCommandEnabled(IDC_SHOW_AS_TAB,
3259 type_ != TYPE_TABBED && (fullscreen_mode == FULLSCREEN_DISABLED));
3260
3261 // Focus various bits of UI
3262 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
3263 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
3264 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
3265 command_updater_.UpdateCommandEnabled(
3266 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
3267 command_updater_.UpdateCommandEnabled(
3268 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
3269 command_updater_.UpdateCommandEnabled(
3270 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
3271 command_updater_.UpdateCommandEnabled(
3272 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
3273
3274 // Show various bits of UI
3275 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
3276 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
3277 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP,
3278 show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible());
3279
3280 // Settings page/subpages are forced to open in normal mode. We disable these
3281 // commands when incognito is forced.
3282 const bool options_enabled = show_main_ui &&
3283 IncognitoModePrefs::GetAvailability(
3284 profile_->GetPrefs()) != IncognitoModePrefs::FORCED;
3285 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled);
3286 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled);
3287
3288 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
3289 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
3290 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
3291 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
3292 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC)
3293 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
3294 #endif
3295
3296 // Disable explicit fullscreen toggling when in metro snap mode.
3297 command_updater_.UpdateCommandEnabled(
3298 IDC_FULLSCREEN,
3299 fullscreen_mode != FULLSCREEN_METRO_SNAP);
3300
3301 UpdateCommandsForBookmarkBar();
3302 UpdateCommandsForMultipleProfiles();
3303 }
3304
3305 void Browser::UpdateCommandsForMultipleProfiles() {
3306 bool show_main_ui = IsShowingMainUI(window_ && window_->IsFullscreen());
3307 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU,
3308 show_main_ui &&
3309 !profile()->IsOffTheRecord() &&
3310 ProfileManager::IsMultipleProfilesEnabled());
3311 }
3312
3313 void Browser::UpdatePrintingState(int content_restrictions) {
3314 bool print_enabled = true;
3315 bool advanced_print_enabled = true;
3316 if (g_browser_process->local_state()) {
3317 print_enabled =
3318 g_browser_process->local_state()->GetBoolean(prefs::kPrintingEnabled);
3319 advanced_print_enabled = print_enabled;
3320 }
3321 if (print_enabled) {
3322 // Do not print when a constrained window is showing. It's confusing.
3323 TabContents* tab_contents = GetActiveTabContents();
3324 bool has_constrained_window =
3325 tab_contents &&
3326 tab_contents->constrained_window_tab_helper()->
3327 constrained_window_count();
3328 if (has_constrained_window ||
3329 content_restrictions & content::CONTENT_RESTRICTION_PRINT) {
3330 print_enabled = false;
3331 advanced_print_enabled = false;
3332 }
3333
3334 // The exception is print preview,
3335 // where advanced printing is always enabled.
3336 printing::PrintPreviewTabController* controller =
3337 printing::PrintPreviewTabController::GetInstance();
3338 if (controller && (controller->GetPrintPreviewForTab(tab_contents) ||
3339 controller->is_creating_print_preview_tab())) {
3340 advanced_print_enabled = true;
3341 }
3342 }
3343 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
3344 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT,
3345 advanced_print_enabled);
3346 }
3347
3348 void Browser::UpdateSaveAsState(int content_restrictions) {
3349 bool enabled = !(content_restrictions & content::CONTENT_RESTRICTION_SAVE);
3350 enabled = enabled && CanSaveContents(GetActiveTabContents());
3351 PrefService* state = g_browser_process->local_state();
3352 if (state)
3353 enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs);
3354
3355 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled);
3356 }
3357
3358 void Browser::UpdateOpenFileState() {
3359 bool enabled = true;
3360 PrefService* local_state = g_browser_process->local_state();
3361 if (local_state)
3362 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
3363
3364 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
3365 }
3366
3367 void Browser::UpdateReloadStopState(bool is_loading, bool force) {
3368 window_->UpdateReloadStopState(is_loading, force);
3369 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
3370 }
3371
3372 /////////////////////////////////////////////////////////////////////////////// 2557 ///////////////////////////////////////////////////////////////////////////////
3373 // Browser, UI update coalescing and handling (private): 2558 // Browser, UI update coalescing and handling (private):
3374 2559
3375 void Browser::UpdateToolbar(bool should_restore_state) { 2560 void Browser::UpdateToolbar(bool should_restore_state) {
3376 window_->UpdateToolbar(GetActiveTabContents(), should_restore_state); 2561 window_->UpdateToolbar(GetActiveTabContents(), should_restore_state);
3377 } 2562 }
3378 2563
3379 void Browser::UpdateSearchState(TabContents* contents) { 2564 void Browser::UpdateSearchState(TabContents* contents) {
3380 if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) 2565 if (chrome::search::IsInstantExtendedAPIEnabled(profile_))
3381 search_delegate_->OnTabActivated(contents); 2566 search_delegate_->OnTabActivated(contents);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3470 } 2655 }
3471 // Updating the URL happens synchronously in ScheduleUIUpdate. 2656 // Updating the URL happens synchronously in ScheduleUIUpdate.
3472 if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) { 2657 if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) {
3473 GetStatusBubble()->SetStatus( 2658 GetStatusBubble()->SetStatus(
3474 GetActiveTabContents()-> 2659 GetActiveTabContents()->
3475 core_tab_helper()->GetStatusText()); 2660 core_tab_helper()->GetStatusText());
3476 } 2661 }
3477 2662
3478 if (flags & (content::INVALIDATE_TYPE_TAB | 2663 if (flags & (content::INVALIDATE_TYPE_TAB |
3479 content::INVALIDATE_TYPE_TITLE)) { 2664 content::INVALIDATE_TYPE_TITLE)) {
3480 // TODO(pinkerton): Disable app-mode in the model until we implement it
3481 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
3482 #if !defined(OS_MACOSX)
3483 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS,
3484 web_app::IsValidUrl(contents->GetURL()));
3485 #endif
3486 window_->UpdateTitleBar(); 2665 window_->UpdateTitleBar();
3487 } 2666 }
3488 } 2667 }
3489 2668
3490 // Updates that don't depend upon the selected state go here. 2669 // Updates that don't depend upon the selected state go here.
3491 if (flags & 2670 if (flags &
3492 (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { 2671 (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) {
3493 tab_strip_model_->UpdateTabContentsStateAt( 2672 tab_strip_model_->UpdateTabContentsStateAt(
3494 tab_strip_model_->GetIndexOfWebContents(contents), 2673 tab_strip_model_->GetIndexOfWebContents(contents),
3495 TabStripModelObserver::ALL); 2674 TabStripModelObserver::ALL);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
3760 } 2939 }
3761 2940
3762 void Browser::CreateInstantIfNecessary() { 2941 void Browser::CreateInstantIfNecessary() {
3763 if (is_type_tabbed() && InstantController::IsEnabled(profile()) && 2942 if (is_type_tabbed() && InstantController::IsEnabled(profile()) &&
3764 !profile()->IsOffTheRecord()) { 2943 !profile()->IsOffTheRecord()) {
3765 instant_.reset(new InstantController(this, InstantController::INSTANT)); 2944 instant_.reset(new InstantController(this, InstantController::INSTANT));
3766 instant_unload_handler_.reset(new InstantUnloadHandler(this)); 2945 instant_unload_handler_.reset(new InstantUnloadHandler(this));
3767 } 2946 }
3768 } 2947 }
3769 2948
3770 int Browser::GetContentRestrictionsForSelectedTab() {
3771 int content_restrictions = 0;
3772 WebContents* current_tab = GetActiveWebContents();
3773 if (current_tab) {
3774 content_restrictions = current_tab->GetContentRestrictions();
3775 NavigationEntry* active_entry =
3776 current_tab->GetController().GetActiveEntry();
3777 // See comment in UpdateCommandsForTabState about why we call url().
3778 if (!download_util::IsSavableURL(
3779 active_entry ? active_entry->GetURL() : GURL())
3780 || current_tab->ShowingInterstitialPage())
3781 content_restrictions |= content::CONTENT_RESTRICTION_SAVE;
3782 if (current_tab->ShowingInterstitialPage())
3783 content_restrictions |= content::CONTENT_RESTRICTION_PRINT;
3784 }
3785 return content_restrictions;
3786 }
3787
3788 void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { 2949 void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
3789 BookmarkBar::State state; 2950 BookmarkBar::State state;
3790 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page. 2951 // The bookmark bar is hidden in fullscreen mode, unless on the new tab page.
3791 if (browser_defaults::bookmarks_enabled && 2952 if (browser_defaults::bookmarks_enabled &&
3792 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && 2953 profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) &&
3793 (!window_ || !window_->IsFullscreen())) { 2954 (!window_ || !window_->IsFullscreen())) {
3794 state = BookmarkBar::SHOW; 2955 state = BookmarkBar::SHOW;
3795 } else { 2956 } else {
3796 TabContents* tab = GetActiveTabContents(); 2957 TabContents* tab = GetActiveTabContents();
3797 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) 2958 if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar())
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
3899 if (contents && !allow_js_access) { 3060 if (contents && !allow_js_access) {
3900 contents->web_contents()->GetController().LoadURL( 3061 contents->web_contents()->GetController().LoadURL(
3901 target_url, 3062 target_url,
3902 content::Referrer(), 3063 content::Referrer(),
3903 content::PAGE_TRANSITION_LINK, 3064 content::PAGE_TRANSITION_LINK,
3904 std::string()); // No extra headers. 3065 std::string()); // No extra headers.
3905 } 3066 }
3906 3067
3907 return contents != NULL; 3068 return contents != NULL;
3908 } 3069 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698