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