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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); | 871 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); |
872 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); | 872 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); |
873 | 873 |
874 // Zoom | 874 // Zoom |
875 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); | 875 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
876 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); | 876 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
877 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); | 877 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); |
878 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); | 878 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
879 | 879 |
880 // Show various bits of UI | 880 // Show various bits of UI |
881 UpdateOpenFileState(); | 881 UpdateOpenFileState(&command_updater_); |
882 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); | 882 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); |
883 UpdateCommandsForDevTools(); | 883 UpdateCommandsForDevTools(); |
884 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); | 884 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); |
885 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, | 885 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, |
886 !profile()->IsGuestSession()); | 886 !profile()->IsGuestSession()); |
887 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 887 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
888 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); | 888 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
889 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 889 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
890 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, | 890 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, |
891 !profile()->IsGuestSession()); | 891 !profile()->IsGuestSession()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 // Initialize other commands whose state changes based on fullscreen mode. | 946 // Initialize other commands whose state changes based on fullscreen mode. |
947 UpdateCommandsForFullscreenMode(FULLSCREEN_DISABLED); | 947 UpdateCommandsForFullscreenMode(FULLSCREEN_DISABLED); |
948 | 948 |
949 UpdateCommandsForContentRestrictionState(); | 949 UpdateCommandsForContentRestrictionState(); |
950 | 950 |
951 UpdateCommandsForBookmarkEditing(); | 951 UpdateCommandsForBookmarkEditing(); |
952 | 952 |
953 UpdateCommandsForIncognitoAvailability(); | 953 UpdateCommandsForIncognitoAvailability(); |
954 } | 954 } |
955 | 955 |
956 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { | 956 // static |
| 957 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( |
| 958 CommandUpdater* command_updater, |
| 959 Profile* profile) { |
957 IncognitoModePrefs::Availability incognito_availability = | 960 IncognitoModePrefs::Availability incognito_availability = |
958 IncognitoModePrefs::GetAvailability(profile()->GetPrefs()); | 961 IncognitoModePrefs::GetAvailability(profile->GetPrefs()); |
959 command_updater_.UpdateCommandEnabled( | 962 command_updater->UpdateCommandEnabled( |
960 IDC_NEW_WINDOW, | 963 IDC_NEW_WINDOW, |
961 incognito_availability != IncognitoModePrefs::FORCED); | 964 incognito_availability != IncognitoModePrefs::FORCED); |
962 command_updater_.UpdateCommandEnabled( | 965 command_updater->UpdateCommandEnabled( |
963 IDC_NEW_INCOGNITO_WINDOW, | 966 IDC_NEW_INCOGNITO_WINDOW, |
964 incognito_availability != IncognitoModePrefs::DISABLED); | 967 incognito_availability != IncognitoModePrefs::DISABLED); |
965 | 968 |
966 // Bookmark manager and settings page/subpages are forced to open in normal | 969 // Bookmark manager and settings page/subpages are forced to open in normal |
967 // mode. For this reason we disable these commands when incognito is forced. | 970 // mode. For this reason we disable these commands when incognito is forced. |
968 const bool command_enabled = | 971 const bool command_enabled = |
969 incognito_availability != IncognitoModePrefs::FORCED; | 972 incognito_availability != IncognitoModePrefs::FORCED; |
970 command_updater_.UpdateCommandEnabled( | 973 command_updater->UpdateCommandEnabled( |
971 IDC_SHOW_BOOKMARK_MANAGER, | 974 IDC_SHOW_BOOKMARK_MANAGER, |
972 browser_defaults::bookmarks_enabled && command_enabled); | 975 browser_defaults::bookmarks_enabled && command_enabled); |
973 ExtensionService* extension_service = profile()->GetExtensionService(); | 976 ExtensionService* extension_service = profile->GetExtensionService(); |
974 bool enable_extensions = | 977 bool enable_extensions = |
975 extension_service && extension_service->extensions_enabled(); | 978 extension_service && extension_service->extensions_enabled(); |
976 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, | 979 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
977 enable_extensions && command_enabled); | 980 enable_extensions && command_enabled); |
978 | 981 |
| 982 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, command_enabled); |
| 983 command_updater->UpdateCommandEnabled(IDC_OPTIONS, command_enabled); |
| 984 } |
| 985 |
| 986 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { |
| 987 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); |
| 988 |
979 const bool show_main_ui = | 989 const bool show_main_ui = |
980 IsShowingMainUI(window() && window()->IsFullscreen()); | 990 IsShowingMainUI(window() && window()->IsFullscreen()); |
981 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, | 991 if (!show_main_ui) { |
982 show_main_ui && command_enabled); | 992 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); |
983 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, | 993 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); |
984 show_main_ui && command_enabled); | 994 } |
985 } | 995 } |
986 | 996 |
987 void BrowserCommandController::UpdateCommandsForTabState() { | 997 void BrowserCommandController::UpdateCommandsForTabState() { |
988 WebContents* current_web_contents = chrome::GetActiveWebContents(browser_); | 998 WebContents* current_web_contents = chrome::GetActiveWebContents(browser_); |
989 if (!current_web_contents) // May be NULL during tab restore. | 999 if (!current_web_contents) // May be NULL during tab restore. |
990 return; | 1000 return; |
991 | 1001 |
992 // Navigation commands | 1002 // Navigation commands |
993 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); | 1003 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); |
994 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_)); | 1004 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_)); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 const bool show_main_ui = | 1087 const bool show_main_ui = |
1078 IsShowingMainUI(window() && window()->IsFullscreen()); | 1088 IsShowingMainUI(window() && window()->IsFullscreen()); |
1079 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, | 1089 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, |
1080 browser_defaults::bookmarks_enabled && | 1090 browser_defaults::bookmarks_enabled && |
1081 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && | 1091 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && |
1082 show_main_ui); | 1092 show_main_ui); |
1083 } | 1093 } |
1084 | 1094 |
1085 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { | 1095 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { |
1086 UpdateSaveAsState(); | 1096 UpdateSaveAsState(); |
1087 UpdateOpenFileState(); | 1097 UpdateOpenFileState(&command_updater_); |
1088 } | 1098 } |
1089 | 1099 |
1090 void BrowserCommandController::UpdateCommandsForFullscreenMode( | 1100 void BrowserCommandController::UpdateCommandsForFullscreenMode( |
1091 FullScreenMode fullscreen_mode) { | 1101 FullScreenMode fullscreen_mode) { |
1092 const bool show_main_ui = | 1102 const bool show_main_ui = |
1093 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED); | 1103 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED); |
1094 bool main_not_fullscreen = show_main_ui && | 1104 bool main_not_fullscreen = show_main_ui && |
1095 (fullscreen_mode == FULLSCREEN_DISABLED); | 1105 (fullscreen_mode == FULLSCREEN_DISABLED); |
1096 | 1106 |
1097 // Navigation commands | 1107 // Navigation commands |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 if (metro_enable_printing) | 1196 if (metro_enable_printing) |
1187 metro_enable_printing(print_enabled); | 1197 metro_enable_printing(print_enabled); |
1188 } | 1198 } |
1189 #endif | 1199 #endif |
1190 } | 1200 } |
1191 | 1201 |
1192 void BrowserCommandController::UpdateSaveAsState() { | 1202 void BrowserCommandController::UpdateSaveAsState() { |
1193 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); | 1203 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
1194 } | 1204 } |
1195 | 1205 |
1196 void BrowserCommandController::UpdateOpenFileState() { | 1206 // static |
| 1207 void BrowserCommandController::UpdateOpenFileState( |
| 1208 CommandUpdater* command_updater) { |
1197 bool enabled = true; | 1209 bool enabled = true; |
1198 PrefService* local_state = g_browser_process->local_state(); | 1210 PrefService* local_state = g_browser_process->local_state(); |
1199 if (local_state) | 1211 if (local_state) |
1200 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); | 1212 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
1201 | 1213 |
1202 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, enabled); | 1214 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
1203 } | 1215 } |
1204 | 1216 |
1205 void BrowserCommandController::UpdateReloadStopState(bool is_loading, | 1217 void BrowserCommandController::UpdateReloadStopState(bool is_loading, |
1206 bool force) { | 1218 bool force) { |
1207 window()->UpdateReloadStopState(is_loading, force); | 1219 window()->UpdateReloadStopState(is_loading, force); |
1208 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 1220 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
1209 } | 1221 } |
1210 | 1222 |
1211 void BrowserCommandController::UpdateCommandsForFind() { | 1223 void BrowserCommandController::UpdateCommandsForFind() { |
1212 TabStripModel* model = browser_->tab_strip_model(); | 1224 TabStripModel* model = browser_->tab_strip_model(); |
(...skipping 22 matching lines...) Expand all Loading... |
1235 | 1247 |
1236 BrowserWindow* BrowserCommandController::window() { | 1248 BrowserWindow* BrowserCommandController::window() { |
1237 return browser_->window(); | 1249 return browser_->window(); |
1238 } | 1250 } |
1239 | 1251 |
1240 Profile* BrowserCommandController::profile() { | 1252 Profile* BrowserCommandController::profile() { |
1241 return browser_->profile(); | 1253 return browser_->profile(); |
1242 } | 1254 } |
1243 | 1255 |
1244 } // namespace chrome | 1256 } // namespace chrome |
OLD | NEW |