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" |
11 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 11 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/sessions/tab_restore_service.h" | 15 #include "chrome/browser/sessions/tab_restore_service.h" |
16 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 16 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
17 #include "chrome/browser/shell_integration.h" | 17 #include "chrome/browser/shell_integration.h" |
18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
20 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 20 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_command_controller_base.h" | |
22 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
23 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
24 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
25 #include "chrome/browser/ui/chrome_pages.h" | 26 #include "chrome/browser/ui/chrome_pages.h" |
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
27 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" |
28 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 29 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
29 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
31 #include "chrome/common/profiling.h" | 32 #include "chrome/common/profiling.h" |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); | 872 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); |
872 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); | 873 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); |
873 | 874 |
874 // Zoom | 875 // Zoom |
875 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); | 876 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
876 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); | 877 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
877 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); | 878 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); |
878 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); | 879 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
879 | 880 |
880 // Show various bits of UI | 881 // Show various bits of UI |
881 UpdateOpenFileState(); | 882 BrowserCommandControllerBase::UpdateOpenFileState(&command_updater_); |
882 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); | 883 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); |
883 UpdateCommandsForDevTools(); | 884 UpdateCommandsForDevTools(); |
884 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); | 885 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); |
885 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, | 886 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, |
886 !profile()->IsGuestSession()); | 887 !profile()->IsGuestSession()); |
887 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 888 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
888 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); | 889 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
889 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 890 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
890 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, | 891 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, |
891 !profile()->IsGuestSession()); | 892 !profile()->IsGuestSession()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 UpdateCommandsForFullscreenMode(FULLSCREEN_DISABLED); | 948 UpdateCommandsForFullscreenMode(FULLSCREEN_DISABLED); |
948 | 949 |
949 UpdateCommandsForContentRestrictionState(); | 950 UpdateCommandsForContentRestrictionState(); |
950 | 951 |
951 UpdateCommandsForBookmarkEditing(); | 952 UpdateCommandsForBookmarkEditing(); |
952 | 953 |
953 UpdateCommandsForIncognitoAvailability(); | 954 UpdateCommandsForIncognitoAvailability(); |
954 } | 955 } |
955 | 956 |
956 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { | 957 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { |
957 IncognitoModePrefs::Availability incognito_availability = | 958 BrowserCommandControllerBase:: |
958 IncognitoModePrefs::GetAvailability(profile()->GetPrefs()); | 959 UpdateCommandsForIncognitoAvailability(&command_updater_, profile()); |
959 command_updater_.UpdateCommandEnabled( | |
960 IDC_NEW_WINDOW, | |
961 incognito_availability != IncognitoModePrefs::FORCED); | |
962 command_updater_.UpdateCommandEnabled( | |
963 IDC_NEW_INCOGNITO_WINDOW, | |
964 incognito_availability != IncognitoModePrefs::DISABLED); | |
965 | |
966 // 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. | |
968 const bool command_enabled = | |
969 incognito_availability != IncognitoModePrefs::FORCED; | |
970 command_updater_.UpdateCommandEnabled( | |
971 IDC_SHOW_BOOKMARK_MANAGER, | |
972 browser_defaults::bookmarks_enabled && command_enabled); | |
973 ExtensionService* extension_service = profile()->GetExtensionService(); | |
974 bool enable_extensions = | |
975 extension_service && extension_service->extensions_enabled(); | |
976 command_updater_.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, | |
977 enable_extensions && command_enabled); | |
978 | 960 |
979 const bool show_main_ui = | 961 const bool show_main_ui = |
980 IsShowingMainUI(window() && window()->IsFullscreen()); | 962 IsShowingMainUI(window() && window()->IsFullscreen()); |
981 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, | 963 if (!show_main_ui) { |
Robert Sesek
2013/01/15 22:27:18
Why this change? You should probably be updating t
Avi (use Gerrit)
2013/01/15 22:35:06
This is not a change.
The old code enabled the co
Robert Sesek
2013/01/15 22:44:37
Ah, got it.
| |
982 show_main_ui && command_enabled); | 964 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); |
983 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, | 965 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); |
984 show_main_ui && command_enabled); | 966 } |
985 } | 967 } |
986 | 968 |
987 void BrowserCommandController::UpdateCommandsForTabState() { | 969 void BrowserCommandController::UpdateCommandsForTabState() { |
988 WebContents* current_web_contents = chrome::GetActiveWebContents(browser_); | 970 WebContents* current_web_contents = chrome::GetActiveWebContents(browser_); |
989 if (!current_web_contents) // May be NULL during tab restore. | 971 if (!current_web_contents) // May be NULL during tab restore. |
990 return; | 972 return; |
991 | 973 |
992 // Navigation commands | 974 // Navigation commands |
993 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); | 975 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); |
994 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_)); | 976 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 = | 1059 const bool show_main_ui = |
1078 IsShowingMainUI(window() && window()->IsFullscreen()); | 1060 IsShowingMainUI(window() && window()->IsFullscreen()); |
1079 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, | 1061 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, |
1080 browser_defaults::bookmarks_enabled && | 1062 browser_defaults::bookmarks_enabled && |
1081 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && | 1063 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && |
1082 show_main_ui); | 1064 show_main_ui); |
1083 } | 1065 } |
1084 | 1066 |
1085 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { | 1067 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { |
1086 UpdateSaveAsState(); | 1068 UpdateSaveAsState(); |
1087 UpdateOpenFileState(); | 1069 BrowserCommandControllerBase::UpdateOpenFileState(&command_updater_); |
1088 } | 1070 } |
1089 | 1071 |
1090 void BrowserCommandController::UpdateCommandsForFullscreenMode( | 1072 void BrowserCommandController::UpdateCommandsForFullscreenMode( |
1091 FullScreenMode fullscreen_mode) { | 1073 FullScreenMode fullscreen_mode) { |
1092 const bool show_main_ui = | 1074 const bool show_main_ui = |
1093 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED); | 1075 IsShowingMainUI(fullscreen_mode != FULLSCREEN_DISABLED); |
1094 bool main_not_fullscreen = show_main_ui && | 1076 bool main_not_fullscreen = show_main_ui && |
1095 (fullscreen_mode == FULLSCREEN_DISABLED); | 1077 (fullscreen_mode == FULLSCREEN_DISABLED); |
1096 | 1078 |
1097 // Navigation commands | 1079 // Navigation commands |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1186 if (metro_enable_printing) | 1168 if (metro_enable_printing) |
1187 metro_enable_printing(print_enabled); | 1169 metro_enable_printing(print_enabled); |
1188 } | 1170 } |
1189 #endif | 1171 #endif |
1190 } | 1172 } |
1191 | 1173 |
1192 void BrowserCommandController::UpdateSaveAsState() { | 1174 void BrowserCommandController::UpdateSaveAsState() { |
1193 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); | 1175 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
1194 } | 1176 } |
1195 | 1177 |
1196 void BrowserCommandController::UpdateOpenFileState() { | |
1197 bool enabled = true; | |
1198 PrefService* local_state = g_browser_process->local_state(); | |
1199 if (local_state) | |
1200 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); | |
1201 | |
1202 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, enabled); | |
1203 } | |
1204 | |
1205 void BrowserCommandController::UpdateReloadStopState(bool is_loading, | 1178 void BrowserCommandController::UpdateReloadStopState(bool is_loading, |
1206 bool force) { | 1179 bool force) { |
1207 window()->UpdateReloadStopState(is_loading, force); | 1180 window()->UpdateReloadStopState(is_loading, force); |
1208 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 1181 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
1209 } | 1182 } |
1210 | 1183 |
1211 void BrowserCommandController::UpdateCommandsForFind() { | 1184 void BrowserCommandController::UpdateCommandsForFind() { |
1212 TabStripModel* model = browser_->tab_strip_model(); | 1185 TabStripModel* model = browser_->tab_strip_model(); |
1213 bool enabled = !model->IsTabBlocked(model->active_index()) && | 1186 bool enabled = !model->IsTabBlocked(model->active_index()) && |
1214 !browser_->is_devtools(); | 1187 !browser_->is_devtools(); |
(...skipping 20 matching lines...) Expand all Loading... | |
1235 | 1208 |
1236 BrowserWindow* BrowserCommandController::window() { | 1209 BrowserWindow* BrowserCommandController::window() { |
1237 return browser_->window(); | 1210 return browser_->window(); |
1238 } | 1211 } |
1239 | 1212 |
1240 Profile* BrowserCommandController::profile() { | 1213 Profile* BrowserCommandController::profile() { |
1241 return browser_->profile(); | 1214 return browser_->profile(); |
1242 } | 1215 } |
1243 | 1216 |
1244 } // namespace chrome | 1217 } // namespace chrome |
OLD | NEW |