| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); | 882 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); |
| 883 } | 883 } |
| 884 | 884 |
| 885 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { | 885 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { |
| 886 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); | 886 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); |
| 887 | 887 |
| 888 if (!IsShowingMainUI()) { | 888 if (!IsShowingMainUI()) { |
| 889 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); | 889 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); |
| 890 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); | 890 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); |
| 891 } | 891 } |
| 892 |
| 893 if (window() && window()->IsFullscreen()) { |
| 894 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, false); |
| 895 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, false); |
| 896 } |
| 892 } | 897 } |
| 893 | 898 |
| 894 void BrowserCommandController::UpdateCommandsForTabState() { | 899 void BrowserCommandController::UpdateCommandsForTabState() { |
| 895 WebContents* current_web_contents = | 900 WebContents* current_web_contents = |
| 896 browser_->tab_strip_model()->GetActiveWebContents(); | 901 browser_->tab_strip_model()->GetActiveWebContents(); |
| 897 if (!current_web_contents) // May be NULL during tab restore. | 902 if (!current_web_contents) // May be NULL during tab restore. |
| 898 return; | 903 return; |
| 899 | 904 |
| 900 // Navigation commands | 905 // Navigation commands |
| 901 command_updater_.UpdateCommandEnabled(IDC_BACKSPACE_BACK, | 906 command_updater_.UpdateCommandEnabled(IDC_BACKSPACE_BACK, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 command_updater_.UpdateCommandEnabled( | 1047 command_updater_.UpdateCommandEnabled( |
| 1043 IDC_FOCUS_INFOBARS, main_not_fullscreen); | 1048 IDC_FOCUS_INFOBARS, main_not_fullscreen); |
| 1044 | 1049 |
| 1045 // Show various bits of UI | 1050 // Show various bits of UI |
| 1046 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 1051 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 1047 #if defined(GOOGLE_CHROME_BUILD) | 1052 #if defined(GOOGLE_CHROME_BUILD) |
| 1048 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 1053 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
| 1049 #endif | 1054 #endif |
| 1050 UpdateShowSyncState(show_main_ui); | 1055 UpdateShowSyncState(show_main_ui); |
| 1051 | 1056 |
| 1052 // Settings page/subpages are forced to open in normal mode. We disable these | |
| 1053 // commands for guest sessions and when incognito is forced. | |
| 1054 const bool options_enabled = show_main_ui && | |
| 1055 IncognitoModePrefs::GetAvailability( | |
| 1056 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | |
| 1057 const bool guest_session = profile()->IsGuestSession(); | |
| 1058 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); | |
| 1059 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, | |
| 1060 options_enabled && !guest_session); | |
| 1061 | |
| 1062 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1057 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1063 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 1058 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1064 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 1059 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 1065 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 1060 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| 1066 | 1061 |
| 1067 if (base::debug::IsProfilingSupported()) | 1062 if (base::debug::IsProfilingSupported()) |
| 1068 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 1063 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 1069 | 1064 |
| 1070 #if !defined(OS_MACOSX) | 1065 #if !defined(OS_MACOSX) |
| 1071 // Disable toggling into fullscreen mode if disallowed by pref. | 1066 // Disable toggling into fullscreen mode if disallowed by pref. |
| 1072 const bool fullscreen_enabled = is_fullscreen || | 1067 const bool fullscreen_enabled = is_fullscreen || |
| 1073 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed); | 1068 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed); |
| 1074 #else | 1069 #else |
| 1075 const bool fullscreen_enabled = true; | 1070 const bool fullscreen_enabled = true; |
| 1076 #endif | 1071 #endif |
| 1077 | 1072 |
| 1078 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); | 1073 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); |
| 1079 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, | 1074 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, |
| 1080 fullscreen_enabled); | 1075 fullscreen_enabled); |
| 1081 | 1076 |
| 1082 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, !is_fullscreen); | 1077 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, !is_fullscreen); |
| 1083 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, !is_fullscreen); | 1078 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, !is_fullscreen); |
| 1084 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, | |
| 1085 !is_fullscreen); | |
| 1086 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, !is_fullscreen); | 1079 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, !is_fullscreen); |
| 1087 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, !is_fullscreen); | |
| 1088 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, !is_fullscreen); | |
| 1089 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, !is_fullscreen); | 1080 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, !is_fullscreen); |
| 1090 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 1081 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| 1091 !is_fullscreen); | 1082 !is_fullscreen); |
| 1092 | 1083 |
| 1093 UpdateCommandsForBookmarkBar(); | 1084 UpdateCommandsForBookmarkBar(); |
| 1085 UpdateCommandsForIncognitoAvailability(); |
| 1086 UpdateTabRestoreCommandState(); |
| 1094 } | 1087 } |
| 1095 | 1088 |
| 1096 void BrowserCommandController::UpdatePrintingState() { | 1089 void BrowserCommandController::UpdatePrintingState() { |
| 1097 bool print_enabled = CanPrint(browser_); | 1090 bool print_enabled = CanPrint(browser_); |
| 1098 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); | 1091 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
| 1099 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 1092 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1100 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, | 1093 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, |
| 1101 CanBasicPrint(browser_)); | 1094 CanBasicPrint(browser_)); |
| 1102 #endif // ENABLE_BASIC_PRINTING | 1095 #endif // ENABLE_BASIC_PRINTING |
| 1103 } | 1096 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1122 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); | 1115 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 1123 } | 1116 } |
| 1124 | 1117 |
| 1125 void BrowserCommandController::UpdateReloadStopState(bool is_loading, | 1118 void BrowserCommandController::UpdateReloadStopState(bool is_loading, |
| 1126 bool force) { | 1119 bool force) { |
| 1127 window()->UpdateReloadStopState(is_loading, force); | 1120 window()->UpdateReloadStopState(is_loading, force); |
| 1128 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 1121 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 1129 } | 1122 } |
| 1130 | 1123 |
| 1131 void BrowserCommandController::UpdateTabRestoreCommandState() { | 1124 void BrowserCommandController::UpdateTabRestoreCommandState() { |
| 1125 const bool is_fullscreen = window() && window()->IsFullscreen(); |
| 1132 sessions::TabRestoreService* tab_restore_service = | 1126 sessions::TabRestoreService* tab_restore_service = |
| 1133 TabRestoreServiceFactory::GetForProfile(profile()); | 1127 TabRestoreServiceFactory::GetForProfile(profile()); |
| 1134 // The command is enabled if the service hasn't loaded yet to trigger loading. | 1128 // The command is enabled if the service hasn't loaded yet to trigger loading. |
| 1135 // The command is updated once the load completes. | 1129 // The command is updated once the load completes. |
| 1136 command_updater_.UpdateCommandEnabled( | 1130 command_updater_.UpdateCommandEnabled( |
| 1137 IDC_RESTORE_TAB, | 1131 IDC_RESTORE_TAB, |
| 1138 tab_restore_service && | 1132 !is_fullscreen && tab_restore_service && |
| 1139 (!tab_restore_service->IsLoaded() || | 1133 (!tab_restore_service->IsLoaded() || |
| 1140 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE)); | 1134 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE)); |
| 1141 } | 1135 } |
| 1142 | 1136 |
| 1143 void BrowserCommandController::UpdateCommandsForFind() { | 1137 void BrowserCommandController::UpdateCommandsForFind() { |
| 1144 TabStripModel* model = browser_->tab_strip_model(); | 1138 TabStripModel* model = browser_->tab_strip_model(); |
| 1145 bool enabled = !model->IsTabBlocked(model->active_index()) && | 1139 bool enabled = !model->IsTabBlocked(model->active_index()) && |
| 1146 !browser_->is_devtools(); | 1140 !browser_->is_devtools(); |
| 1147 | 1141 |
| 1148 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled); | 1142 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled); |
| 1149 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled); | 1143 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled); |
| 1150 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled); | 1144 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1173 | 1167 |
| 1174 BrowserWindow* BrowserCommandController::window() { | 1168 BrowserWindow* BrowserCommandController::window() { |
| 1175 return browser_->window(); | 1169 return browser_->window(); |
| 1176 } | 1170 } |
| 1177 | 1171 |
| 1178 Profile* BrowserCommandController::profile() { | 1172 Profile* BrowserCommandController::profile() { |
| 1179 return browser_->profile(); | 1173 return browser_->profile(); |
| 1180 } | 1174 } |
| 1181 | 1175 |
| 1182 } // namespace chrome | 1176 } // namespace chrome |
| OLD | NEW |