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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 base::Unretained(this))); | 203 base::Unretained(this))); |
204 | 204 |
205 InitCommandState(); | 205 InitCommandState(); |
206 | 206 |
207 TabRestoreService* tab_restore_service = | 207 TabRestoreService* tab_restore_service = |
208 TabRestoreServiceFactory::GetForProfile(profile()); | 208 TabRestoreServiceFactory::GetForProfile(profile()); |
209 if (tab_restore_service) { | 209 if (tab_restore_service) { |
210 tab_restore_service->AddObserver(this); | 210 tab_restore_service->AddObserver(this); |
211 TabRestoreServiceChanged(tab_restore_service); | 211 TabRestoreServiceChanged(tab_restore_service); |
212 } | 212 } |
213 | |
214 ProfileSyncService* service = | |
215 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile()); | |
216 if (service) | |
217 service->AddObserver(this); | |
218 } | 213 } |
219 | 214 |
220 BrowserCommandController::~BrowserCommandController() { | 215 BrowserCommandController::~BrowserCommandController() { |
221 ProfileSyncService* service = | |
222 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile()); | |
223 if (service) | |
224 service->RemoveObserver(this); | |
225 | |
226 // TabRestoreService may have been shutdown by the time we get here. Don't | 216 // TabRestoreService may have been shutdown by the time we get here. Don't |
227 // trigger creating it. | 217 // trigger creating it. |
228 TabRestoreService* tab_restore_service = | 218 TabRestoreService* tab_restore_service = |
229 TabRestoreServiceFactory::GetForProfileIfExisting(profile()); | 219 TabRestoreServiceFactory::GetForProfileIfExisting(profile()); |
230 if (tab_restore_service) | 220 if (tab_restore_service) |
231 tab_restore_service->RemoveObserver(this); | 221 tab_restore_service->RemoveObserver(this); |
232 profile_pref_registrar_.RemoveAll(); | 222 profile_pref_registrar_.RemoveAll(); |
233 local_pref_registrar_.RemoveAll(); | 223 local_pref_registrar_.RemoveAll(); |
234 browser_->tab_strip_model()->RemoveObserver(this); | 224 browser_->tab_strip_model()->RemoveObserver(this); |
235 if (profile_manager_) | 225 if (profile_manager_) |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 break; | 673 break; |
684 case IDC_VIEW_INCOMPATIBILITIES: | 674 case IDC_VIEW_INCOMPATIBILITIES: |
685 ShowConflicts(browser_); | 675 ShowConflicts(browser_); |
686 break; | 676 break; |
687 case IDC_HELP_PAGE_VIA_KEYBOARD: | 677 case IDC_HELP_PAGE_VIA_KEYBOARD: |
688 ShowHelp(browser_, HELP_SOURCE_KEYBOARD); | 678 ShowHelp(browser_, HELP_SOURCE_KEYBOARD); |
689 break; | 679 break; |
690 case IDC_HELP_PAGE_VIA_MENU: | 680 case IDC_HELP_PAGE_VIA_MENU: |
691 ShowHelp(browser_, HELP_SOURCE_MENU); | 681 ShowHelp(browser_, HELP_SOURCE_MENU); |
692 break; | 682 break; |
693 case IDC_SHOW_SYNC_SETUP: | 683 case IDC_SHOW_SIGNIN: |
694 ShowSyncSetup(browser_, SyncPromoUI::SOURCE_MENU); | 684 ShowBrowserSignin(browser_, SyncPromoUI::SOURCE_MENU); |
695 break; | 685 break; |
696 case IDC_TOGGLE_SPEECH_INPUT: | 686 case IDC_TOGGLE_SPEECH_INPUT: |
697 ToggleSpeechInput(browser_); | 687 ToggleSpeechInput(browser_); |
698 break; | 688 break; |
699 | 689 |
700 default: | 690 default: |
701 LOG(WARNING) << "Received Unimplemented Command: " << id; | 691 LOG(WARNING) << "Received Unimplemented Command: " << id; |
702 break; | 692 break; |
703 } | 693 } |
704 } | 694 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 void BrowserCommandController::OnProfileNameChanged( | 735 void BrowserCommandController::OnProfileNameChanged( |
746 const FilePath& profile_path, | 736 const FilePath& profile_path, |
747 const string16& old_profile_name) { | 737 const string16& old_profile_name) { |
748 } | 738 } |
749 | 739 |
750 void BrowserCommandController::OnProfileAvatarChanged( | 740 void BrowserCommandController::OnProfileAvatarChanged( |
751 const FilePath& profile_path) { | 741 const FilePath& profile_path) { |
752 } | 742 } |
753 | 743 |
754 //////////////////////////////////////////////////////////////////////////////// | 744 //////////////////////////////////////////////////////////////////////////////// |
755 // BrowserCommandController, ProfileSyncServiceObserver implementation: | |
756 | |
757 void BrowserCommandController::OnStateChanged() { | |
758 DCHECK(ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( | |
759 profile())); | |
760 // For unit tests, we don't have a window. | |
761 if (!window()) | |
762 return; | |
763 const bool show_main_ui = IsShowingMainUI(window()->IsFullscreen()); | |
764 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, | |
765 show_main_ui && profile()->GetOriginalProfile()->IsSyncAccessible()); | |
766 } | |
767 | |
768 //////////////////////////////////////////////////////////////////////////////// | |
769 // BrowserCommandController, TabStripModelObserver implementation: | 745 // BrowserCommandController, TabStripModelObserver implementation: |
770 | 746 |
771 void BrowserCommandController::TabInsertedAt(WebContents* contents, | 747 void BrowserCommandController::TabInsertedAt(WebContents* contents, |
772 int index, | 748 int index, |
773 bool foreground) { | 749 bool foreground) { |
774 AddInterstitialObservers(contents); | 750 AddInterstitialObservers(contents); |
775 } | 751 } |
776 | 752 |
777 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { | 753 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { |
778 RemoveInterstitialObservers(contents); | 754 RemoveInterstitialObservers(contents); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 !profile()->IsGuestSession()); | 874 !profile()->IsGuestSession()); |
899 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 875 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
900 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); | 876 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
901 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 877 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
902 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, | 878 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, |
903 !profile()->IsGuestSession()); | 879 !profile()->IsGuestSession()); |
904 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, | 880 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, |
905 !profile()->IsGuestSession() && | 881 !profile()->IsGuestSession() && |
906 !profile()->IsOffTheRecord()); | 882 !profile()->IsOffTheRecord()); |
907 | 883 |
908 command_updater_.UpdateCommandEnabled( | 884 command_updater_.UpdateCommandEnabled(IDC_SHOW_SIGNIN, true); |
909 IDC_SHOW_SYNC_SETUP, profile()->GetOriginalProfile()->IsSyncAccessible()); | |
910 | 885 |
911 // Initialize other commands based on the window type. | 886 // Initialize other commands based on the window type. |
912 bool normal_window = browser_->is_type_tabbed(); | 887 bool normal_window = browser_->is_type_tabbed(); |
913 | 888 |
914 // Navigation commands | 889 // Navigation commands |
915 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 890 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
916 | 891 |
917 // Window management commands | 892 // Window management commands |
918 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 893 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
919 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 894 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 command_updater_.UpdateCommandEnabled( | 1109 command_updater_.UpdateCommandEnabled( |
1135 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); | 1110 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
1136 command_updater_.UpdateCommandEnabled( | 1111 command_updater_.UpdateCommandEnabled( |
1137 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); | 1112 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
1138 command_updater_.UpdateCommandEnabled( | 1113 command_updater_.UpdateCommandEnabled( |
1139 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); | 1114 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
1140 | 1115 |
1141 // Show various bits of UI | 1116 // Show various bits of UI |
1142 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 1117 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
1143 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 1118 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
1144 command_updater_.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP, | |
1145 show_main_ui && profile()->GetOriginalProfile()->IsSyncAccessible()); | |
1146 | 1119 |
1147 // Settings page/subpages are forced to open in normal mode. We disable these | 1120 // Settings page/subpages are forced to open in normal mode. We disable these |
1148 // commands when incognito is forced. | 1121 // commands when incognito is forced. |
1149 const bool options_enabled = show_main_ui && | 1122 const bool options_enabled = show_main_ui && |
1150 IncognitoModePrefs::GetAvailability( | 1123 IncognitoModePrefs::GetAvailability( |
1151 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 1124 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
1152 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); | 1125 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
1153 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); | 1126 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); |
1154 | 1127 |
1155 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1128 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 | 1232 |
1260 BrowserWindow* BrowserCommandController::window() { | 1233 BrowserWindow* BrowserCommandController::window() { |
1261 return browser_->window(); | 1234 return browser_->window(); |
1262 } | 1235 } |
1263 | 1236 |
1264 Profile* BrowserCommandController::profile() { | 1237 Profile* BrowserCommandController::profile() { |
1265 return browser_->profile(); | 1238 return browser_->profile(); |
1266 } | 1239 } |
1267 | 1240 |
1268 } // namespace chrome | 1241 } // namespace chrome |
OLD | NEW |