| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 profile_pref_registrar_.Add( | 222 profile_pref_registrar_.Add( |
| 223 prefs::kPrintingEnabled, | 223 prefs::kPrintingEnabled, |
| 224 base::Bind(&BrowserCommandController::UpdatePrintingState, | 224 base::Bind(&BrowserCommandController::UpdatePrintingState, |
| 225 base::Unretained(this))); | 225 base::Unretained(this))); |
| 226 #if !defined(OS_MACOSX) | 226 #if !defined(OS_MACOSX) |
| 227 profile_pref_registrar_.Add( | 227 profile_pref_registrar_.Add( |
| 228 prefs::kFullscreenAllowed, | 228 prefs::kFullscreenAllowed, |
| 229 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode, | 229 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode, |
| 230 base::Unretained(this))); | 230 base::Unretained(this))); |
| 231 #endif | 231 #endif |
| 232 pref_signin_allowed_.Init( | |
| 233 prefs::kSigninAllowed, | |
| 234 profile()->GetOriginalProfile()->GetPrefs(), | |
| 235 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange, | |
| 236 base::Unretained(this))); | |
| 237 | 232 |
| 238 InitCommandState(); | 233 InitCommandState(); |
| 239 | 234 |
| 240 TabRestoreService* tab_restore_service = | 235 TabRestoreService* tab_restore_service = |
| 241 TabRestoreServiceFactory::GetForProfile(profile()); | 236 TabRestoreServiceFactory::GetForProfile(profile()); |
| 242 if (tab_restore_service) { | 237 if (tab_restore_service) { |
| 243 tab_restore_service->AddObserver(this); | 238 tab_restore_service->AddObserver(this); |
| 244 TabRestoreServiceChanged(tab_restore_service); | 239 TabRestoreServiceChanged(tab_restore_service); |
| 245 } | 240 } |
| 246 } | 241 } |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 break; | 752 break; |
| 758 case IDC_VIEW_INCOMPATIBILITIES: | 753 case IDC_VIEW_INCOMPATIBILITIES: |
| 759 ShowConflicts(browser_); | 754 ShowConflicts(browser_); |
| 760 break; | 755 break; |
| 761 case IDC_HELP_PAGE_VIA_KEYBOARD: | 756 case IDC_HELP_PAGE_VIA_KEYBOARD: |
| 762 ShowHelp(browser_, HELP_SOURCE_KEYBOARD); | 757 ShowHelp(browser_, HELP_SOURCE_KEYBOARD); |
| 763 break; | 758 break; |
| 764 case IDC_HELP_PAGE_VIA_MENU: | 759 case IDC_HELP_PAGE_VIA_MENU: |
| 765 ShowHelp(browser_, HELP_SOURCE_MENU); | 760 ShowHelp(browser_, HELP_SOURCE_MENU); |
| 766 break; | 761 break; |
| 767 case IDC_SHOW_SIGNIN: | |
| 768 ShowBrowserSigninOrSettings(browser_, signin_metrics::SOURCE_MENU); | |
| 769 break; | |
| 770 case IDC_TOGGLE_SPEECH_INPUT: | 762 case IDC_TOGGLE_SPEECH_INPUT: |
| 771 ToggleSpeechInput(browser_); | 763 ToggleSpeechInput(browser_); |
| 772 break; | 764 break; |
| 773 case IDC_DISTILL_PAGE: | 765 case IDC_DISTILL_PAGE: |
| 774 DistillCurrentPage(browser_); | 766 DistillCurrentPage(browser_); |
| 775 break; | 767 break; |
| 776 #if defined(OS_CHROMEOS) | 768 #if defined(OS_CHROMEOS) |
| 777 case IDC_TOUCH_HUD_PROJECTION_TOGGLE: | 769 case IDC_TOUCH_HUD_PROJECTION_TOGGLE: |
| 778 ash::accelerators::ToggleTouchHudProjection(); | 770 ash::accelerators::ToggleTouchHudProjection(); |
| 779 break; | 771 break; |
| 780 #endif | 772 #endif |
| 781 | 773 |
| 782 default: | 774 default: |
| 783 LOG(WARNING) << "Received Unimplemented Command: " << id; | 775 LOG(WARNING) << "Received Unimplemented Command: " << id; |
| 784 break; | 776 break; |
| 785 } | 777 } |
| 786 } | 778 } |
| 787 | 779 |
| 788 //////////////////////////////////////////////////////////////////////////////// | |
| 789 // BrowserCommandController, SigninPrefObserver implementation: | |
| 790 | |
| 791 void BrowserCommandController::OnSigninAllowedPrefChange() { | |
| 792 // For unit tests, we don't have a window. | |
| 793 if (!window()) | |
| 794 return; | |
| 795 UpdateShowSyncState(IsShowingMainUI()); | |
| 796 } | |
| 797 | |
| 798 // BrowserCommandController, TabStripModelObserver implementation: | 780 // BrowserCommandController, TabStripModelObserver implementation: |
| 799 | 781 |
| 800 void BrowserCommandController::TabInsertedAt(WebContents* contents, | 782 void BrowserCommandController::TabInsertedAt(WebContents* contents, |
| 801 int index, | 783 int index, |
| 802 bool foreground) { | 784 bool foreground) { |
| 803 AddInterstitialObservers(contents); | 785 AddInterstitialObservers(contents); |
| 804 } | 786 } |
| 805 | 787 |
| 806 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { | 788 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { |
| 807 RemoveInterstitialObservers(contents); | 789 RemoveInterstitialObservers(contents); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true); | 959 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true); |
| 978 command_updater_.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE, true); | 960 command_updater_.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE, true); |
| 979 #else | 961 #else |
| 980 // Chrome OS uses the system tray menu to handle multi-profiles. | 962 // Chrome OS uses the system tray menu to handle multi-profiles. |
| 981 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) { | 963 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) { |
| 982 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true); | 964 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true); |
| 983 command_updater_.UpdateCommandEnabled(IDC_SHOW_FAST_USER_SWITCHER, true); | 965 command_updater_.UpdateCommandEnabled(IDC_SHOW_FAST_USER_SWITCHER, true); |
| 984 } | 966 } |
| 985 #endif | 967 #endif |
| 986 | 968 |
| 987 UpdateShowSyncState(true); | |
| 988 | |
| 989 // Navigation commands | 969 // Navigation commands |
| 990 command_updater_.UpdateCommandEnabled( | 970 command_updater_.UpdateCommandEnabled( |
| 991 IDC_HOME, | 971 IDC_HOME, |
| 992 normal_window || | 972 normal_window || |
| 993 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app())); | 973 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app())); |
| 994 | 974 |
| 995 // Window management commands | 975 // Window management commands |
| 996 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 976 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 997 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 977 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| 998 normal_window); | 978 normal_window); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 extension_service && extension_service->extensions_enabled(); | 1043 extension_service && extension_service->extensions_enabled(); |
| 1064 | 1044 |
| 1065 // Bookmark manager and settings page/subpages are forced to open in normal | 1045 // Bookmark manager and settings page/subpages are forced to open in normal |
| 1066 // mode. For this reason we disable these commands when incognito is forced. | 1046 // mode. For this reason we disable these commands when incognito is forced. |
| 1067 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, | 1047 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
| 1068 enable_extensions && !forced_incognito); | 1048 enable_extensions && !forced_incognito); |
| 1069 | 1049 |
| 1070 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito); | 1050 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito); |
| 1071 command_updater->UpdateCommandEnabled(IDC_OPTIONS, | 1051 command_updater->UpdateCommandEnabled(IDC_OPTIONS, |
| 1072 !forced_incognito || guest_session); | 1052 !forced_incognito || guest_session); |
| 1073 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); | |
| 1074 } | 1053 } |
| 1075 | 1054 |
| 1076 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { | 1055 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { |
| 1077 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); | 1056 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); |
| 1078 | 1057 |
| 1079 if (!IsShowingMainUI()) { | 1058 if (!IsShowingMainUI()) { |
| 1080 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); | 1059 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); |
| 1081 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); | 1060 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); |
| 1082 } | 1061 } |
| 1083 } | 1062 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 command_updater_.UpdateCommandEnabled( | 1221 command_updater_.UpdateCommandEnabled( |
| 1243 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); | 1222 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 1244 command_updater_.UpdateCommandEnabled( | 1223 command_updater_.UpdateCommandEnabled( |
| 1245 IDC_FOCUS_INFOBARS, main_not_fullscreen); | 1224 IDC_FOCUS_INFOBARS, main_not_fullscreen); |
| 1246 | 1225 |
| 1247 // Show various bits of UI | 1226 // Show various bits of UI |
| 1248 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 1227 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 1249 #if defined(GOOGLE_CHROME_BUILD) | 1228 #if defined(GOOGLE_CHROME_BUILD) |
| 1250 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 1229 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
| 1251 #endif | 1230 #endif |
| 1252 UpdateShowSyncState(show_main_ui); | |
| 1253 | 1231 |
| 1254 // Settings page/subpages are forced to open in normal mode. We disable these | 1232 // Settings page/subpages are forced to open in normal mode. We disable these |
| 1255 // commands for guest sessions and when incognito is forced. | 1233 // commands for guest sessions and when incognito is forced. |
| 1256 const bool options_enabled = show_main_ui && | 1234 const bool options_enabled = show_main_ui && |
| 1257 IncognitoModePrefs::GetAvailability( | 1235 IncognitoModePrefs::GetAvailability( |
| 1258 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 1236 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 1259 const bool guest_session = profile()->IsGuestSession(); | 1237 const bool guest_session = profile()->IsGuestSession(); |
| 1260 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); | 1238 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
| 1261 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, | 1239 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, |
| 1262 options_enabled && !guest_session); | 1240 options_enabled && !guest_session); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1292 #if defined(ENABLE_BASIC_PRINTING) | 1270 #if defined(ENABLE_BASIC_PRINTING) |
| 1293 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, | 1271 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, |
| 1294 CanBasicPrint(browser_)); | 1272 CanBasicPrint(browser_)); |
| 1295 #endif // ENABLE_BASIC_PRINTING | 1273 #endif // ENABLE_BASIC_PRINTING |
| 1296 } | 1274 } |
| 1297 | 1275 |
| 1298 void BrowserCommandController::UpdateSaveAsState() { | 1276 void BrowserCommandController::UpdateSaveAsState() { |
| 1299 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); | 1277 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
| 1300 } | 1278 } |
| 1301 | 1279 |
| 1302 void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) { | |
| 1303 command_updater_.UpdateCommandEnabled( | |
| 1304 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue()); | |
| 1305 } | |
| 1306 | |
| 1307 // static | 1280 // static |
| 1308 void BrowserCommandController::UpdateOpenFileState( | 1281 void BrowserCommandController::UpdateOpenFileState( |
| 1309 CommandUpdater* command_updater) { | 1282 CommandUpdater* command_updater) { |
| 1310 bool enabled = true; | 1283 bool enabled = true; |
| 1311 PrefService* local_state = g_browser_process->local_state(); | 1284 PrefService* local_state = g_browser_process->local_state(); |
| 1312 if (local_state) | 1285 if (local_state) |
| 1313 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); | 1286 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 1314 | 1287 |
| 1315 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); | 1288 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 1316 } | 1289 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 | 1334 |
| 1362 BrowserWindow* BrowserCommandController::window() { | 1335 BrowserWindow* BrowserCommandController::window() { |
| 1363 return browser_->window(); | 1336 return browser_->window(); |
| 1364 } | 1337 } |
| 1365 | 1338 |
| 1366 Profile* BrowserCommandController::profile() { | 1339 Profile* BrowserCommandController::profile() { |
| 1367 return browser_->profile(); | 1340 return browser_->profile(); |
| 1368 } | 1341 } |
| 1369 | 1342 |
| 1370 } // namespace chrome | 1343 } // namespace chrome |
| OLD | NEW |