| 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_command_controller.h" | 5 #include "chrome/browser/ui/browser_command_controller.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/defaults.h" | 9 #include "chrome/browser/defaults.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 base::Unretained(this))); | 197 base::Unretained(this))); |
| 198 | 198 |
| 199 InitCommandState(); | 199 InitCommandState(); |
| 200 | 200 |
| 201 TabRestoreService* tab_restore_service = | 201 TabRestoreService* tab_restore_service = |
| 202 TabRestoreServiceFactory::GetForProfile(profile()); | 202 TabRestoreServiceFactory::GetForProfile(profile()); |
| 203 if (tab_restore_service) { | 203 if (tab_restore_service) { |
| 204 tab_restore_service->AddObserver(this); | 204 tab_restore_service->AddObserver(this); |
| 205 TabRestoreServiceChanged(tab_restore_service); | 205 TabRestoreServiceChanged(tab_restore_service); |
| 206 } | 206 } |
| 207 | |
| 208 ProfileSyncService* service = | |
| 209 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile()); | |
| 210 if (service) | |
| 211 service->AddObserver(this); | |
| 212 } | 207 } |
| 213 | 208 |
| 214 BrowserCommandController::~BrowserCommandController() { | 209 BrowserCommandController::~BrowserCommandController() { |
| 215 ProfileSyncService* service = | |
| 216 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile()); | |
| 217 if (service) | |
| 218 service->RemoveObserver(this); | |
| 219 | |
| 220 // TabRestoreService may have been shutdown by the time we get here. Don't | 210 // TabRestoreService may have been shutdown by the time we get here. Don't |
| 221 // trigger creating it. | 211 // trigger creating it. |
| 222 TabRestoreService* tab_restore_service = | 212 TabRestoreService* tab_restore_service = |
| 223 TabRestoreServiceFactory::GetForProfileIfExisting(profile()); | 213 TabRestoreServiceFactory::GetForProfileIfExisting(profile()); |
| 224 if (tab_restore_service) | 214 if (tab_restore_service) |
| 225 tab_restore_service->RemoveObserver(this); | 215 tab_restore_service->RemoveObserver(this); |
| 226 profile_pref_registrar_.RemoveAll(); | 216 profile_pref_registrar_.RemoveAll(); |
| 227 local_pref_registrar_.RemoveAll(); | 217 local_pref_registrar_.RemoveAll(); |
| 228 browser_->tab_strip_model()->RemoveObserver(this); | 218 browser_->tab_strip_model()->RemoveObserver(this); |
| 229 if (profile_manager_) | 219 if (profile_manager_) |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 break; | 660 break; |
| 671 case IDC_VIEW_INCOMPATIBILITIES: | 661 case IDC_VIEW_INCOMPATIBILITIES: |
| 672 ShowConflicts(browser_); | 662 ShowConflicts(browser_); |
| 673 break; | 663 break; |
| 674 case IDC_HELP_PAGE_VIA_KEYBOARD: | 664 case IDC_HELP_PAGE_VIA_KEYBOARD: |
| 675 ShowHelp(browser_, HELP_SOURCE_KEYBOARD); | 665 ShowHelp(browser_, HELP_SOURCE_KEYBOARD); |
| 676 break; | 666 break; |
| 677 case IDC_HELP_PAGE_VIA_MENU: | 667 case IDC_HELP_PAGE_VIA_MENU: |
| 678 ShowHelp(browser_, HELP_SOURCE_MENU); | 668 ShowHelp(browser_, HELP_SOURCE_MENU); |
| 679 break; | 669 break; |
| 680 case IDC_SHOW_SYNC_SETUP: | 670 case IDC_SHOW_SIGNIN: |
| 681 ShowSyncSetup(browser_, SyncPromoUI::SOURCE_MENU); | 671 ShowBrowserSignin(browser_, SyncPromoUI::SOURCE_MENU); |
| 682 break; | 672 break; |
| 683 case IDC_TOGGLE_SPEECH_INPUT: | 673 case IDC_TOGGLE_SPEECH_INPUT: |
| 684 ToggleSpeechInput(browser_); | 674 ToggleSpeechInput(browser_); |
| 685 break; | 675 break; |
| 686 | 676 |
| 687 default: | 677 default: |
| 688 LOG(WARNING) << "Received Unimplemented Command: " << id; | 678 LOG(WARNING) << "Received Unimplemented Command: " << id; |
| 689 break; | 679 break; |
| 690 } | 680 } |
| 691 } | 681 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 void BrowserCommandController::OnProfileNameChanged( | 722 void BrowserCommandController::OnProfileNameChanged( |
| 733 const FilePath& profile_path, | 723 const FilePath& profile_path, |
| 734 const string16& old_profile_name) { | 724 const string16& old_profile_name) { |
| 735 } | 725 } |
| 736 | 726 |
| 737 void BrowserCommandController::OnProfileAvatarChanged( | 727 void BrowserCommandController::OnProfileAvatarChanged( |
| 738 const FilePath& profile_path) { | 728 const FilePath& profile_path) { |
| 739 } | 729 } |
| 740 | 730 |
| 741 //////////////////////////////////////////////////////////////////////////////// | 731 //////////////////////////////////////////////////////////////////////////////// |
| 742 // BrowserCommandController, ProfileSyncServiceObserver implementation: | |
| 743 | |
| 744 void BrowserCommandController::OnStateChanged() { | |
| 745 DCHECK(ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | |
| 746 profile())); | |
| 747 // For unit tests, we don't have a window. | |
| 748 if (!window()) | |
| 749 return; | |
| 750 const bool show_main_ui = IsShowingMainUI(window()->IsFullscreen()); | |
| 751 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, | |
| 752 show_main_ui && profile()->GetOriginalProfile()->IsSyncAccessible()); | |
| 753 } | |
| 754 | |
| 755 //////////////////////////////////////////////////////////////////////////////// | |
| 756 // BrowserCommandController, TabStripModelObserver implementation: | 732 // BrowserCommandController, TabStripModelObserver implementation: |
| 757 | 733 |
| 758 void BrowserCommandController::TabInsertedAt(WebContents* contents, | 734 void BrowserCommandController::TabInsertedAt(WebContents* contents, |
| 759 int index, | 735 int index, |
| 760 bool foreground) { | 736 bool foreground) { |
| 761 AddInterstitialObservers(contents); | 737 AddInterstitialObservers(contents); |
| 762 } | 738 } |
| 763 | 739 |
| 764 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { | 740 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { |
| 765 RemoveInterstitialObservers(contents); | 741 RemoveInterstitialObservers(contents); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 !profile()->IsGuestSession()); | 861 !profile()->IsGuestSession()); |
| 886 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 862 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 887 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); | 863 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
| 888 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 864 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
| 889 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, | 865 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, |
| 890 !profile()->IsGuestSession()); | 866 !profile()->IsGuestSession()); |
| 891 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, | 867 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, |
| 892 !profile()->IsGuestSession() && | 868 !profile()->IsGuestSession() && |
| 893 !profile()->IsOffTheRecord()); | 869 !profile()->IsOffTheRecord()); |
| 894 | 870 |
| 895 command_updater_.UpdateCommandEnabled( | 871 command_updater_.UpdateCommandEnabled(IDC_SHOW_SIGNIN, true); |
| 896 IDC_SHOW_SYNC_SETUP, profile()->GetOriginalProfile()->IsSyncAccessible()); | |
| 897 | 872 |
| 898 // Initialize other commands based on the window type. | 873 // Initialize other commands based on the window type. |
| 899 bool normal_window = browser_->is_type_tabbed(); | 874 bool normal_window = browser_->is_type_tabbed(); |
| 900 | 875 |
| 901 // Navigation commands | 876 // Navigation commands |
| 902 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 877 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
| 903 | 878 |
| 904 // Window management commands | 879 // Window management commands |
| 905 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 880 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 906 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 881 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 command_updater_.UpdateCommandEnabled( | 1096 command_updater_.UpdateCommandEnabled( |
| 1122 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); | 1097 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
| 1123 command_updater_.UpdateCommandEnabled( | 1098 command_updater_.UpdateCommandEnabled( |
| 1124 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); | 1099 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 1125 command_updater_.UpdateCommandEnabled( | 1100 command_updater_.UpdateCommandEnabled( |
| 1126 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); | 1101 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 1127 | 1102 |
| 1128 // Show various bits of UI | 1103 // Show various bits of UI |
| 1129 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 1104 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 1130 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 1105 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
| 1131 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, | |
| 1132 show_main_ui && profile()->GetOriginalProfile()->IsSyncAccessible()); | |
| 1133 | 1106 |
| 1134 // Settings page/subpages are forced to open in normal mode. We disable these | 1107 // Settings page/subpages are forced to open in normal mode. We disable these |
| 1135 // commands when incognito is forced. | 1108 // commands when incognito is forced. |
| 1136 const bool options_enabled = show_main_ui && | 1109 const bool options_enabled = show_main_ui && |
| 1137 IncognitoModePrefs::GetAvailability( | 1110 IncognitoModePrefs::GetAvailability( |
| 1138 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 1111 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 1139 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); | 1112 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
| 1140 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); | 1113 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); |
| 1141 | 1114 |
| 1142 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1115 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 | 1220 |
| 1248 BrowserWindow* BrowserCommandController::window() { | 1221 BrowserWindow* BrowserCommandController::window() { |
| 1249 return browser_->window(); | 1222 return browser_->window(); |
| 1250 } | 1223 } |
| 1251 | 1224 |
| 1252 Profile* BrowserCommandController::profile() { | 1225 Profile* BrowserCommandController::profile() { |
| 1253 return browser_->profile(); | 1226 return browser_->profile(); |
| 1254 } | 1227 } |
| 1255 | 1228 |
| 1256 } // namespace chrome | 1229 } // namespace chrome |
| OLD | NEW |