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); |
|
msw
2017/02/15 18:40:51
I should have asked earlier, but do we actually ne
Hzj_jie
2017/02/15 21:20:16
Yes, patch set 2 of change https://codereview.chro
msw
2017/02/15 22:38:18
My naive understanding is that it would be safe to
| |
| 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); |
| 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(); |
| (...skipping 145 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); | |
|
msw
2017/02/15 18:40:51
Now that I'm looking closer, I'm not sure this is
Hzj_jie
2017/02/15 21:20:16
Yes, as I have replied in the previous comment, we
msw
2017/02/15 22:38:18
If it matches the test expectations, then it's pro
| |
| 1059 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, | |
|
msw
2017/02/15 18:40:51
Similarly, this disables IDC_IMPORT_SETTINGS for g
Hzj_jie
2017/02/15 21:20:17
Ditto.
| |
| 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, |
| 1132 !is_fullscreen && | |
| 1138 tab_restore_service && | 1133 tab_restore_service && |
| 1139 (!tab_restore_service->IsLoaded() || | 1134 (!tab_restore_service->IsLoaded() || |
| 1140 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE)); | 1135 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE)); |
| 1141 } | 1136 } |
| 1142 | 1137 |
| 1143 void BrowserCommandController::UpdateCommandsForFind() { | 1138 void BrowserCommandController::UpdateCommandsForFind() { |
| 1144 TabStripModel* model = browser_->tab_strip_model(); | 1139 TabStripModel* model = browser_->tab_strip_model(); |
| 1145 bool enabled = !model->IsTabBlocked(model->active_index()) && | 1140 bool enabled = !model->IsTabBlocked(model->active_index()) && |
| 1146 !browser_->is_devtools(); | 1141 !browser_->is_devtools(); |
| 1147 | 1142 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1173 | 1168 |
| 1174 BrowserWindow* BrowserCommandController::window() { | 1169 BrowserWindow* BrowserCommandController::window() { |
| 1175 return browser_->window(); | 1170 return browser_->window(); |
| 1176 } | 1171 } |
| 1177 | 1172 |
| 1178 Profile* BrowserCommandController::profile() { | 1173 Profile* BrowserCommandController::profile() { |
| 1179 return browser_->profile(); | 1174 return browser_->profile(); |
| 1180 } | 1175 } |
| 1181 | 1176 |
| 1182 } // namespace chrome | 1177 } // namespace chrome |
| OLD | NEW |