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