Chromium Code Reviews| 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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 // Initialize other commands whose state changes based on various conditions. | 841 // Initialize other commands whose state changes based on various conditions. |
| 842 UpdateCommandsForFullscreenMode(); | 842 UpdateCommandsForFullscreenMode(); |
| 843 UpdateCommandsForContentRestrictionState(); | 843 UpdateCommandsForContentRestrictionState(); |
| 844 UpdateCommandsForBookmarkEditing(); | 844 UpdateCommandsForBookmarkEditing(); |
| 845 UpdateCommandsForIncognitoAvailability(); | 845 UpdateCommandsForIncognitoAvailability(); |
| 846 } | 846 } |
| 847 | 847 |
| 848 // static | 848 // static |
| 849 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( | 849 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( |
| 850 CommandUpdater* command_updater, | 850 CommandUpdater* command_updater, |
| 851 Profile* profile) { | 851 Profile* profile, |
| 852 bool is_fullscreen) { | |
| 852 const bool guest_session = profile->IsGuestSession(); | 853 const bool guest_session = profile->IsGuestSession(); |
| 853 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession(). | 854 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession(). |
| 854 IncognitoModePrefs::Availability incognito_availability = | 855 IncognitoModePrefs::Availability incognito_availability = |
| 855 IncognitoModePrefs::GetAvailability(profile->GetPrefs()); | 856 IncognitoModePrefs::GetAvailability(profile->GetPrefs()); |
| 856 command_updater->UpdateCommandEnabled( | 857 command_updater->UpdateCommandEnabled( |
| 857 IDC_NEW_WINDOW, | 858 IDC_NEW_WINDOW, |
| 858 incognito_availability != IncognitoModePrefs::FORCED); | 859 !is_fullscreen && incognito_availability != IncognitoModePrefs::FORCED); |
| 859 command_updater->UpdateCommandEnabled( | 860 command_updater->UpdateCommandEnabled( |
| 860 IDC_NEW_INCOGNITO_WINDOW, | 861 IDC_NEW_INCOGNITO_WINDOW, |
| 861 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session); | 862 !is_fullscreen && |
| 863 incognito_availability != IncognitoModePrefs::DISABLED && | |
| 864 !guest_session); | |
| 862 | 865 |
| 863 const bool forced_incognito = | 866 const bool forced_incognito = |
| 864 incognito_availability == IncognitoModePrefs::FORCED || | 867 incognito_availability == IncognitoModePrefs::FORCED || |
| 865 guest_session; // Guest always runs in Incognito mode. | 868 guest_session; // Guest always runs in Incognito mode. |
| 866 command_updater->UpdateCommandEnabled( | 869 command_updater->UpdateCommandEnabled( |
| 867 IDC_SHOW_BOOKMARK_MANAGER, | 870 IDC_SHOW_BOOKMARK_MANAGER, |
| 868 browser_defaults::bookmarks_enabled && !forced_incognito); | 871 browser_defaults::bookmarks_enabled && !forced_incognito); |
| 869 ExtensionService* extension_service = | 872 ExtensionService* extension_service = |
| 870 extensions::ExtensionSystem::Get(profile)->extension_service(); | 873 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 871 const bool enable_extensions = | 874 const bool enable_extensions = |
| 872 extension_service && extension_service->extensions_enabled(); | 875 extension_service && extension_service->extensions_enabled(); |
| 873 | 876 |
| 874 // Bookmark manager and settings page/subpages are forced to open in normal | 877 // Bookmark manager and settings page/subpages are forced to open in normal |
| 875 // mode. For this reason we disable these commands when incognito is forced. | 878 // mode. For this reason we disable these commands when incognito is forced. |
| 876 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, | 879 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
| 877 enable_extensions && !forced_incognito); | 880 enable_extensions && !forced_incognito); |
| 878 | 881 |
| 879 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito); | 882 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito); |
| 880 command_updater->UpdateCommandEnabled(IDC_OPTIONS, | 883 command_updater->UpdateCommandEnabled(IDC_OPTIONS, |
| 881 !forced_incognito || guest_session); | 884 !forced_incognito || guest_session); |
| 882 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); | 885 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); |
| 883 } | 886 } |
| 884 | 887 |
| 885 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { | 888 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { |
| 886 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); | 889 const bool is_fullscreen = window() && window()->IsFullscreen(); |
| 890 UpdateSharedCommandsForIncognitoAvailability( | |
| 891 &command_updater_, profile(), is_fullscreen); | |
| 887 | 892 |
| 888 if (!IsShowingMainUI()) { | 893 if (!IsShowingMainUI()) { |
| 889 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); | 894 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); |
|
msw
2017/02/14 22:34:50
aside: these two commands (IDC_IMPORT_SETTINGS and
Hzj_jie
2017/02/15 02:00:49
I think this is by design, since UpdateSharedComma
msw
2017/02/15 18:40:51
It seems like the pattern here is to call UpdateSh
Hzj_jie
2017/02/15 21:20:16
Good suggestion. Thank you.
| |
| 890 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); | 895 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); |
| 891 } | 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 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 1057 // Settings page/subpages are forced to open in normal mode. We disable these |
| 1053 // commands for guest sessions and when incognito is forced. | 1058 // commands for guest sessions and when incognito is forced. |
| 1054 const bool options_enabled = show_main_ui && | 1059 const bool options_enabled = show_main_ui && |
| 1055 IncognitoModePrefs::GetAvailability( | 1060 IncognitoModePrefs::GetAvailability( |
| 1056 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 1061 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 1057 const bool guest_session = profile()->IsGuestSession(); | 1062 const bool guest_session = profile()->IsGuestSession(); |
| 1058 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); | 1063 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
|
msw
2017/02/14 22:34:50
These two commands (IDC_OPTIONS and IDC_IMPORT_SET
Hzj_jie
2017/02/15 02:00:49
These several lines are duplicated with UpdateComm
| |
| 1059 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, | 1064 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, |
| 1060 options_enabled && !guest_session); | 1065 options_enabled && !guest_session); |
| 1061 | 1066 |
| 1062 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1067 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1063 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 1068 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1064 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 1069 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 1065 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 1070 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| 1066 | 1071 |
| 1067 if (base::debug::IsProfilingSupported()) | 1072 if (base::debug::IsProfilingSupported()) |
| 1068 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 1073 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 1069 | 1074 |
| 1070 #if !defined(OS_MACOSX) | 1075 #if !defined(OS_MACOSX) |
| 1071 // Disable toggling into fullscreen mode if disallowed by pref. | 1076 // Disable toggling into fullscreen mode if disallowed by pref. |
| 1072 const bool fullscreen_enabled = is_fullscreen || | 1077 const bool fullscreen_enabled = is_fullscreen || |
| 1073 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed); | 1078 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed); |
| 1074 #else | 1079 #else |
| 1075 const bool fullscreen_enabled = true; | 1080 const bool fullscreen_enabled = true; |
| 1076 #endif | 1081 #endif |
| 1077 | 1082 |
| 1078 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); | 1083 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); |
| 1079 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, | 1084 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, |
| 1080 fullscreen_enabled); | 1085 fullscreen_enabled); |
| 1081 | 1086 |
| 1082 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, !is_fullscreen); | 1087 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, !is_fullscreen); |
| 1083 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, !is_fullscreen); | 1088 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); | 1089 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); | 1090 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, !is_fullscreen); |
| 1090 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 1091 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| 1091 !is_fullscreen); | 1092 !is_fullscreen); |
| 1092 | 1093 |
| 1093 UpdateCommandsForBookmarkBar(); | 1094 UpdateCommandsForBookmarkBar(); |
| 1095 UpdateCommandsForIncognitoAvailability(); | |
| 1096 UpdateTabRestoreCommandState(); | |
| 1094 } | 1097 } |
| 1095 | 1098 |
| 1096 void BrowserCommandController::UpdatePrintingState() { | 1099 void BrowserCommandController::UpdatePrintingState() { |
| 1097 bool print_enabled = CanPrint(browser_); | 1100 bool print_enabled = CanPrint(browser_); |
| 1098 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); | 1101 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
| 1099 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 1102 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1100 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, | 1103 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, |
| 1101 CanBasicPrint(browser_)); | 1104 CanBasicPrint(browser_)); |
| 1102 #endif // ENABLE_BASIC_PRINTING | 1105 #endif // ENABLE_BASIC_PRINTING |
| 1103 } | 1106 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1122 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); | 1125 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 1123 } | 1126 } |
| 1124 | 1127 |
| 1125 void BrowserCommandController::UpdateReloadStopState(bool is_loading, | 1128 void BrowserCommandController::UpdateReloadStopState(bool is_loading, |
| 1126 bool force) { | 1129 bool force) { |
| 1127 window()->UpdateReloadStopState(is_loading, force); | 1130 window()->UpdateReloadStopState(is_loading, force); |
| 1128 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | 1131 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 1129 } | 1132 } |
| 1130 | 1133 |
| 1131 void BrowserCommandController::UpdateTabRestoreCommandState() { | 1134 void BrowserCommandController::UpdateTabRestoreCommandState() { |
| 1135 const bool is_fullscreen = window() && window()->IsFullscreen(); | |
| 1132 sessions::TabRestoreService* tab_restore_service = | 1136 sessions::TabRestoreService* tab_restore_service = |
| 1133 TabRestoreServiceFactory::GetForProfile(profile()); | 1137 TabRestoreServiceFactory::GetForProfile(profile()); |
| 1134 // The command is enabled if the service hasn't loaded yet to trigger loading. | 1138 // The command is enabled if the service hasn't loaded yet to trigger loading. |
| 1135 // The command is updated once the load completes. | 1139 // The command is updated once the load completes. |
| 1136 command_updater_.UpdateCommandEnabled( | 1140 command_updater_.UpdateCommandEnabled( |
| 1137 IDC_RESTORE_TAB, | 1141 IDC_RESTORE_TAB, |
| 1142 !is_fullscreen && | |
| 1138 tab_restore_service && | 1143 tab_restore_service && |
| 1139 (!tab_restore_service->IsLoaded() || | 1144 (!tab_restore_service->IsLoaded() || |
| 1140 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE)); | 1145 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE)); |
| 1141 } | 1146 } |
| 1142 | 1147 |
| 1143 void BrowserCommandController::UpdateCommandsForFind() { | 1148 void BrowserCommandController::UpdateCommandsForFind() { |
| 1144 TabStripModel* model = browser_->tab_strip_model(); | 1149 TabStripModel* model = browser_->tab_strip_model(); |
| 1145 bool enabled = !model->IsTabBlocked(model->active_index()) && | 1150 bool enabled = !model->IsTabBlocked(model->active_index()) && |
| 1146 !browser_->is_devtools(); | 1151 !browser_->is_devtools(); |
| 1147 | 1152 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1173 | 1178 |
| 1174 BrowserWindow* BrowserCommandController::window() { | 1179 BrowserWindow* BrowserCommandController::window() { |
| 1175 return browser_->window(); | 1180 return browser_->window(); |
| 1176 } | 1181 } |
| 1177 | 1182 |
| 1178 Profile* BrowserCommandController::profile() { | 1183 Profile* BrowserCommandController::profile() { |
| 1179 return browser_->profile(); | 1184 return browser_->profile(); |
| 1180 } | 1185 } |
| 1181 | 1186 |
| 1182 } // namespace chrome | 1187 } // namespace chrome |
| OLD | NEW |