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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 base::Unretained(this))); | 198 base::Unretained(this))); |
199 | 199 |
200 InitCommandState(); | 200 InitCommandState(); |
201 | 201 |
202 TabRestoreService* tab_restore_service = | 202 TabRestoreService* tab_restore_service = |
203 TabRestoreServiceFactory::GetForProfile(profile()); | 203 TabRestoreServiceFactory::GetForProfile(profile()); |
204 if (tab_restore_service) { | 204 if (tab_restore_service) { |
205 tab_restore_service->AddObserver(this); | 205 tab_restore_service->AddObserver(this); |
206 TabRestoreServiceChanged(tab_restore_service); | 206 TabRestoreServiceChanged(tab_restore_service); |
207 } | 207 } |
208 | |
209 ProfileSyncService* service = | |
210 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile()); | |
211 if (service) | |
212 service->AddObserver(this); | |
213 } | 208 } |
214 | 209 |
215 BrowserCommandController::~BrowserCommandController() { | 210 BrowserCommandController::~BrowserCommandController() { |
216 ProfileSyncService* service = | |
217 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile()); | |
218 if (service) | |
219 service->RemoveObserver(this); | |
220 | |
221 // TabRestoreService may have been shutdown by the time we get here. Don't | 211 // TabRestoreService may have been shutdown by the time we get here. Don't |
222 // trigger creating it. | 212 // trigger creating it. |
223 TabRestoreService* tab_restore_service = | 213 TabRestoreService* tab_restore_service = |
224 TabRestoreServiceFactory::GetForProfileIfExisting(profile()); | 214 TabRestoreServiceFactory::GetForProfileIfExisting(profile()); |
225 if (tab_restore_service) | 215 if (tab_restore_service) |
226 tab_restore_service->RemoveObserver(this); | 216 tab_restore_service->RemoveObserver(this); |
227 profile_pref_registrar_.RemoveAll(); | 217 profile_pref_registrar_.RemoveAll(); |
228 local_pref_registrar_.RemoveAll(); | 218 local_pref_registrar_.RemoveAll(); |
229 browser_->tab_strip_model()->RemoveObserver(this); | 219 browser_->tab_strip_model()->RemoveObserver(this); |
230 if (profile_manager_) | 220 if (profile_manager_) |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 break; | 661 break; |
672 case IDC_VIEW_INCOMPATIBILITIES: | 662 case IDC_VIEW_INCOMPATIBILITIES: |
673 ShowConflicts(browser_); | 663 ShowConflicts(browser_); |
674 break; | 664 break; |
675 case IDC_HELP_PAGE_VIA_KEYBOARD: | 665 case IDC_HELP_PAGE_VIA_KEYBOARD: |
676 ShowHelp(browser_, HELP_SOURCE_KEYBOARD); | 666 ShowHelp(browser_, HELP_SOURCE_KEYBOARD); |
677 break; | 667 break; |
678 case IDC_HELP_PAGE_VIA_MENU: | 668 case IDC_HELP_PAGE_VIA_MENU: |
679 ShowHelp(browser_, HELP_SOURCE_MENU); | 669 ShowHelp(browser_, HELP_SOURCE_MENU); |
680 break; | 670 break; |
681 case IDC_SHOW_SYNC_SETUP: | 671 case IDC_SHOW_SIGNIN: |
682 ShowSyncSetup(browser_, SyncPromoUI::SOURCE_MENU); | 672 ShowBrowserSignin(browser_, SyncPromoUI::SOURCE_MENU); |
683 break; | 673 break; |
684 case IDC_TOGGLE_SPEECH_INPUT: | 674 case IDC_TOGGLE_SPEECH_INPUT: |
685 ToggleSpeechInput(browser_); | 675 ToggleSpeechInput(browser_); |
686 break; | 676 break; |
687 | 677 |
688 default: | 678 default: |
689 LOG(WARNING) << "Received Unimplemented Command: " << id; | 679 LOG(WARNING) << "Received Unimplemented Command: " << id; |
690 break; | 680 break; |
691 } | 681 } |
692 } | 682 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 void BrowserCommandController::OnProfileNameChanged( | 723 void BrowserCommandController::OnProfileNameChanged( |
734 const FilePath& profile_path, | 724 const FilePath& profile_path, |
735 const string16& old_profile_name) { | 725 const string16& old_profile_name) { |
736 } | 726 } |
737 | 727 |
738 void BrowserCommandController::OnProfileAvatarChanged( | 728 void BrowserCommandController::OnProfileAvatarChanged( |
739 const FilePath& profile_path) { | 729 const FilePath& profile_path) { |
740 } | 730 } |
741 | 731 |
742 //////////////////////////////////////////////////////////////////////////////// | 732 //////////////////////////////////////////////////////////////////////////////// |
743 // BrowserCommandController, ProfileSyncServiceObserver implementation: | |
744 | |
745 void BrowserCommandController::OnStateChanged() { | |
746 DCHECK(ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | |
747 profile())); | |
748 // For unit tests, we don't have a window. | |
749 if (!window()) | |
750 return; | |
751 const bool show_main_ui = IsShowingMainUI(window()->IsFullscreen()); | |
752 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, | |
753 show_main_ui && profile()->GetOriginalProfile()->IsSyncAccessible()); | |
754 } | |
755 | |
756 //////////////////////////////////////////////////////////////////////////////// | |
757 // BrowserCommandController, TabStripModelObserver implementation: | 733 // BrowserCommandController, TabStripModelObserver implementation: |
758 | 734 |
759 void BrowserCommandController::TabInsertedAt(WebContents* contents, | 735 void BrowserCommandController::TabInsertedAt(WebContents* contents, |
760 int index, | 736 int index, |
761 bool foreground) { | 737 bool foreground) { |
762 AddInterstitialObservers(contents); | 738 AddInterstitialObservers(contents); |
763 } | 739 } |
764 | 740 |
765 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { | 741 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { |
766 RemoveInterstitialObservers(contents); | 742 RemoveInterstitialObservers(contents); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 !profile()->IsGuestSession()); | 862 !profile()->IsGuestSession()); |
887 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 863 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
888 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); | 864 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
889 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 865 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
890 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, | 866 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, |
891 !profile()->IsGuestSession()); | 867 !profile()->IsGuestSession()); |
892 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, | 868 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, |
893 !profile()->IsGuestSession() && | 869 !profile()->IsGuestSession() && |
894 !profile()->IsOffTheRecord()); | 870 !profile()->IsOffTheRecord()); |
895 | 871 |
896 command_updater_.UpdateCommandEnabled( | 872 command_updater_.UpdateCommandEnabled(IDC_SHOW_SIGNIN, true); |
897 IDC_SHOW_SYNC_SETUP, profile()->GetOriginalProfile()->IsSyncAccessible()); | |
898 | 873 |
899 // Initialize other commands based on the window type. | 874 // Initialize other commands based on the window type. |
900 bool normal_window = browser_->is_type_tabbed(); | 875 bool normal_window = browser_->is_type_tabbed(); |
901 | 876 |
902 // Navigation commands | 877 // Navigation commands |
903 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 878 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
904 | 879 |
905 // Window management commands | 880 // Window management commands |
906 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 881 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
907 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 882 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
(...skipping 213 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 |