| 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 "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/defaults.h" | 10 #include "chrome/browser/defaults.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 base::Unretained(this))); | 194 base::Unretained(this))); |
| 195 profile_pref_registrar_.Add( | 195 profile_pref_registrar_.Add( |
| 196 prefs::kIncognitoModeAvailability, | 196 prefs::kIncognitoModeAvailability, |
| 197 base::Bind( | 197 base::Bind( |
| 198 &BrowserCommandController::UpdateCommandsForIncognitoAvailability, | 198 &BrowserCommandController::UpdateCommandsForIncognitoAvailability, |
| 199 base::Unretained(this))); | 199 base::Unretained(this))); |
| 200 profile_pref_registrar_.Add( | 200 profile_pref_registrar_.Add( |
| 201 prefs::kPrintingEnabled, | 201 prefs::kPrintingEnabled, |
| 202 base::Bind(&BrowserCommandController::UpdatePrintingState, | 202 base::Bind(&BrowserCommandController::UpdatePrintingState, |
| 203 base::Unretained(this))); | 203 base::Unretained(this))); |
| 204 pref_signin_allowed_.Init( |
| 205 prefs::kSigninAllowed, |
| 206 profile()->GetOriginalProfile()->GetPrefs(), |
| 207 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange, |
| 208 base::Unretained(this))); |
| 204 | 209 |
| 205 InitCommandState(); | 210 InitCommandState(); |
| 206 | 211 |
| 207 TabRestoreService* tab_restore_service = | 212 TabRestoreService* tab_restore_service = |
| 208 TabRestoreServiceFactory::GetForProfile(profile()); | 213 TabRestoreServiceFactory::GetForProfile(profile()); |
| 209 if (tab_restore_service) { | 214 if (tab_restore_service) { |
| 210 tab_restore_service->AddObserver(this); | 215 tab_restore_service->AddObserver(this); |
| 211 TabRestoreServiceChanged(tab_restore_service); | 216 TabRestoreServiceChanged(tab_restore_service); |
| 212 } | 217 } |
| 213 } | 218 } |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 void BrowserCommandController::OnProfileNameChanged( | 738 void BrowserCommandController::OnProfileNameChanged( |
| 734 const base::FilePath& profile_path, | 739 const base::FilePath& profile_path, |
| 735 const string16& old_profile_name) { | 740 const string16& old_profile_name) { |
| 736 } | 741 } |
| 737 | 742 |
| 738 void BrowserCommandController::OnProfileAvatarChanged( | 743 void BrowserCommandController::OnProfileAvatarChanged( |
| 739 const base::FilePath& profile_path) { | 744 const base::FilePath& profile_path) { |
| 740 } | 745 } |
| 741 | 746 |
| 742 //////////////////////////////////////////////////////////////////////////////// | 747 //////////////////////////////////////////////////////////////////////////////// |
| 748 // BrowserCommandController, SigninPrefObserver implementation: |
| 749 |
| 750 void BrowserCommandController::OnSigninAllowedPrefChange() { |
| 751 // For unit tests, we don't have a window. |
| 752 if (!window()) |
| 753 return; |
| 754 UpdateShowSyncState(IsShowingMainUI(window()->IsFullscreen())); |
| 755 } |
| 756 |
| 743 // BrowserCommandController, TabStripModelObserver implementation: | 757 // BrowserCommandController, TabStripModelObserver implementation: |
| 744 | 758 |
| 745 void BrowserCommandController::TabInsertedAt(WebContents* contents, | 759 void BrowserCommandController::TabInsertedAt(WebContents* contents, |
| 746 int index, | 760 int index, |
| 747 bool foreground) { | 761 bool foreground) { |
| 748 AddInterstitialObservers(contents); | 762 AddInterstitialObservers(contents); |
| 749 } | 763 } |
| 750 | 764 |
| 751 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { | 765 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { |
| 752 RemoveInterstitialObservers(contents); | 766 RemoveInterstitialObservers(contents); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 !profile()->IsGuestSession()); | 888 !profile()->IsGuestSession()); |
| 875 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 889 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 876 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); | 890 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
| 877 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 891 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
| 878 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, | 892 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, |
| 879 !profile()->IsGuestSession()); | 893 !profile()->IsGuestSession()); |
| 880 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, | 894 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, |
| 881 !profile()->IsGuestSession() && | 895 !profile()->IsGuestSession() && |
| 882 !profile()->IsOffTheRecord()); | 896 !profile()->IsOffTheRecord()); |
| 883 | 897 |
| 884 command_updater_.UpdateCommandEnabled(IDC_SHOW_SIGNIN, true); | 898 UpdateShowSyncState(true); |
| 885 | 899 |
| 886 // Initialize other commands based on the window type. | 900 // Initialize other commands based on the window type. |
| 887 bool normal_window = browser_->is_type_tabbed(); | 901 bool normal_window = browser_->is_type_tabbed(); |
| 888 | 902 |
| 889 // Navigation commands | 903 // Navigation commands |
| 890 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 904 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
| 891 | 905 |
| 892 // Window management commands | 906 // Window management commands |
| 893 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 907 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 894 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 908 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 command_updater_.UpdateCommandEnabled( | 1123 command_updater_.UpdateCommandEnabled( |
| 1110 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); | 1124 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
| 1111 command_updater_.UpdateCommandEnabled( | 1125 command_updater_.UpdateCommandEnabled( |
| 1112 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); | 1126 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 1113 command_updater_.UpdateCommandEnabled( | 1127 command_updater_.UpdateCommandEnabled( |
| 1114 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); | 1128 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 1115 | 1129 |
| 1116 // Show various bits of UI | 1130 // Show various bits of UI |
| 1117 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 1131 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 1118 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 1132 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
| 1133 UpdateShowSyncState(show_main_ui); |
| 1119 | 1134 |
| 1120 // Settings page/subpages are forced to open in normal mode. We disable these | 1135 // Settings page/subpages are forced to open in normal mode. We disable these |
| 1121 // commands when incognito is forced. | 1136 // commands when incognito is forced. |
| 1122 const bool options_enabled = show_main_ui && | 1137 const bool options_enabled = show_main_ui && |
| 1123 IncognitoModePrefs::GetAvailability( | 1138 IncognitoModePrefs::GetAvailability( |
| 1124 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 1139 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 1125 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); | 1140 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
| 1126 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); | 1141 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); |
| 1127 | 1142 |
| 1128 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1143 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 if (metro_enable_printing) | 1196 if (metro_enable_printing) |
| 1182 metro_enable_printing(print_enabled); | 1197 metro_enable_printing(print_enabled); |
| 1183 } | 1198 } |
| 1184 #endif | 1199 #endif |
| 1185 } | 1200 } |
| 1186 | 1201 |
| 1187 void BrowserCommandController::UpdateSaveAsState() { | 1202 void BrowserCommandController::UpdateSaveAsState() { |
| 1188 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); | 1203 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
| 1189 } | 1204 } |
| 1190 | 1205 |
| 1206 void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) { |
| 1207 command_updater_.UpdateCommandEnabled( |
| 1208 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue()); |
| 1209 } |
| 1210 |
| 1191 // static | 1211 // static |
| 1192 void BrowserCommandController::UpdateOpenFileState( | 1212 void BrowserCommandController::UpdateOpenFileState( |
| 1193 CommandUpdater* command_updater) { | 1213 CommandUpdater* command_updater) { |
| 1194 bool enabled = true; | 1214 bool enabled = true; |
| 1195 PrefService* local_state = g_browser_process->local_state(); | 1215 PrefService* local_state = g_browser_process->local_state(); |
| 1196 if (local_state) | 1216 if (local_state) |
| 1197 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); | 1217 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 1198 | 1218 |
| 1199 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); | 1219 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 1200 } | 1220 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 | 1252 |
| 1233 BrowserWindow* BrowserCommandController::window() { | 1253 BrowserWindow* BrowserCommandController::window() { |
| 1234 return browser_->window(); | 1254 return browser_->window(); |
| 1235 } | 1255 } |
| 1236 | 1256 |
| 1237 Profile* BrowserCommandController::profile() { | 1257 Profile* BrowserCommandController::profile() { |
| 1238 return browser_->profile(); | 1258 return browser_->profile(); |
| 1239 } | 1259 } |
| 1240 | 1260 |
| 1241 } // namespace chrome | 1261 } // namespace chrome |
| OLD | NEW |