Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/ui/browser_command_controller.cc

Issue 264303006: Support full-screen and single-profile avatar bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Never enable the command on ChromeOS. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/defaults.h" 12 #include "chrome/browser/defaults.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/lifetime/application_lifetime.h" 14 #include "chrome/browser/lifetime/application_lifetime.h"
15 #include "chrome/browser/prefs/incognito_mode_prefs.h" 15 #include "chrome/browser/prefs/incognito_mode_prefs.h"
16 #include "chrome/browser/profiles/avatar_menu.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/sessions/tab_restore_service.h" 17 #include "chrome/browser/sessions/tab_restore_service.h"
20 #include "chrome/browser/sessions/tab_restore_service_factory.h" 18 #include "chrome/browser/sessions/tab_restore_service_factory.h"
21 #include "chrome/browser/shell_integration.h" 19 #include "chrome/browser/shell_integration.h"
22 #include "chrome/browser/signin/signin_promo.h" 20 #include "chrome/browser/signin/signin_promo.h"
23 #include "chrome/browser/sync/profile_sync_service.h" 21 #include "chrome/browser/sync/profile_sync_service.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 22 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 23 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
26 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_commands.h" 25 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 }; 174 };
177 #endif // defined(OS_WIN) 175 #endif // defined(OS_WIN)
178 176
179 } // namespace 177 } // namespace
180 178
181 namespace chrome { 179 namespace chrome {
182 180
183 /////////////////////////////////////////////////////////////////////////////// 181 ///////////////////////////////////////////////////////////////////////////////
184 // BrowserCommandController, public: 182 // BrowserCommandController, public:
185 183
186 BrowserCommandController::BrowserCommandController( 184 BrowserCommandController::BrowserCommandController(Browser* browser)
187 Browser* browser,
188 ProfileManager* profile_manager)
189 : browser_(browser), 185 : browser_(browser),
190 profile_manager_(profile_manager),
191 command_updater_(this), 186 command_updater_(this),
192 block_command_execution_(false), 187 block_command_execution_(false),
193 last_blocked_command_id_(-1), 188 last_blocked_command_id_(-1),
194 last_blocked_command_disposition_(CURRENT_TAB) { 189 last_blocked_command_disposition_(CURRENT_TAB) {
195 if (profile_manager_)
196 profile_manager_->GetProfileInfoCache().AddObserver(this);
197 browser_->tab_strip_model()->AddObserver(this); 190 browser_->tab_strip_model()->AddObserver(this);
198 PrefService* local_state = g_browser_process->local_state(); 191 PrefService* local_state = g_browser_process->local_state();
199 if (local_state) { 192 if (local_state) {
200 local_pref_registrar_.Init(local_state); 193 local_pref_registrar_.Init(local_state);
201 local_pref_registrar_.Add( 194 local_pref_registrar_.Add(
202 prefs::kAllowFileSelectionDialogs, 195 prefs::kAllowFileSelectionDialogs,
203 base::Bind( 196 base::Bind(
204 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs, 197 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
205 base::Unretained(this))); 198 base::Unretained(this)));
206 } 199 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 BrowserCommandController::~BrowserCommandController() { 245 BrowserCommandController::~BrowserCommandController() {
253 // TabRestoreService may have been shutdown by the time we get here. Don't 246 // TabRestoreService may have been shutdown by the time we get here. Don't
254 // trigger creating it. 247 // trigger creating it.
255 TabRestoreService* tab_restore_service = 248 TabRestoreService* tab_restore_service =
256 TabRestoreServiceFactory::GetForProfileIfExisting(profile()); 249 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
257 if (tab_restore_service) 250 if (tab_restore_service)
258 tab_restore_service->RemoveObserver(this); 251 tab_restore_service->RemoveObserver(this);
259 profile_pref_registrar_.RemoveAll(); 252 profile_pref_registrar_.RemoveAll();
260 local_pref_registrar_.RemoveAll(); 253 local_pref_registrar_.RemoveAll();
261 browser_->tab_strip_model()->RemoveObserver(this); 254 browser_->tab_strip_model()->RemoveObserver(this);
262 if (profile_manager_)
263 profile_manager_->GetProfileInfoCache().RemoveObserver(this);
264 } 255 }
265 256
266 bool BrowserCommandController::IsReservedCommandOrKey( 257 bool BrowserCommandController::IsReservedCommandOrKey(
267 int command_id, 258 int command_id,
268 const content::NativeWebKeyboardEvent& event) { 259 const content::NativeWebKeyboardEvent& event) {
269 // In Apps mode, no keys are reserved. 260 // In Apps mode, no keys are reserved.
270 if (browser_->is_app()) 261 if (browser_->is_app())
271 return false; 262 return false;
272 263
273 #if defined(OS_CHROMEOS) 264 #if defined(OS_CHROMEOS)
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 ToggleSpeechInput(browser_); 766 ToggleSpeechInput(browser_);
776 break; 767 break;
777 768
778 default: 769 default:
779 LOG(WARNING) << "Received Unimplemented Command: " << id; 770 LOG(WARNING) << "Received Unimplemented Command: " << id;
780 break; 771 break;
781 } 772 }
782 } 773 }
783 774
784 //////////////////////////////////////////////////////////////////////////////// 775 ////////////////////////////////////////////////////////////////////////////////
785 // BrowserCommandController, ProfileInfoCacheObserver implementation:
786
787 void BrowserCommandController::OnProfileAdded(
788 const base::FilePath& profile_path) {
789 UpdateCommandsForMultipleProfiles();
790 }
791
792 void BrowserCommandController::OnProfileWasRemoved(
793 const base::FilePath& profile_path,
794 const base::string16& profile_name) {
795 UpdateCommandsForMultipleProfiles();
796 }
797
798 ////////////////////////////////////////////////////////////////////////////////
799 // BrowserCommandController, SigninPrefObserver implementation: 776 // BrowserCommandController, SigninPrefObserver implementation:
800 777
801 void BrowserCommandController::OnSigninAllowedPrefChange() { 778 void BrowserCommandController::OnSigninAllowedPrefChange() {
802 // For unit tests, we don't have a window. 779 // For unit tests, we don't have a window.
803 if (!window()) 780 if (!window())
804 return; 781 return;
805 UpdateShowSyncState(IsShowingMainUI()); 782 UpdateShowSyncState(IsShowingMainUI());
806 } 783 }
807 784
808 // BrowserCommandController, TabStripModelObserver implementation: 785 // BrowserCommandController, TabStripModelObserver implementation:
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); 939 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true);
963 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); 940 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true);
964 941
965 // Zoom 942 // Zoom
966 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); 943 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
967 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); 944 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
968 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); 945 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true);
969 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); 946 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
970 947
971 // Show various bits of UI 948 // Show various bits of UI
949 const bool guest_session = profile()->IsGuestSession();
950 const bool normal_window = browser_->is_type_tabbed();
972 UpdateOpenFileState(&command_updater_); 951 UpdateOpenFileState(&command_updater_);
973 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); 952 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
974 UpdateCommandsForDevTools(); 953 UpdateCommandsForDevTools();
975 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); 954 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
976 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, 955 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
977 !profile()->IsGuestSession());
978 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); 956 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
979 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); 957 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
980 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); 958 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
981 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, 959 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
982 !profile()->IsGuestSession());
983 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, 960 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
984 !profile()->IsGuestSession() && 961 !guest_session &&
985 !profile()->IsOffTheRecord()); 962 !profile()->IsOffTheRecord());
963 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
986 #if defined(OS_CHROMEOS) 964 #if defined(OS_CHROMEOS)
987 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true); 965 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
966 #else
967 // Chrome OS uses the system tray menu to handle multi-profiles.
968 if (normal_window && (guest_session || !profile()->IsOffTheRecord()))
969 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
988 #endif 970 #endif
989 971
990 UpdateShowSyncState(true); 972 UpdateShowSyncState(true);
991 973
992 // Initialize other commands based on the window type.
993 bool normal_window = browser_->is_type_tabbed();
994
995 // Navigation commands 974 // Navigation commands
996 command_updater_.UpdateCommandEnabled( 975 command_updater_.UpdateCommandEnabled(
997 IDC_HOME, 976 IDC_HOME,
998 normal_window || (CommandLine::ForCurrentProcess()->HasSwitch( 977 normal_window || (CommandLine::ForCurrentProcess()->HasSwitch(
999 switches::kEnableStreamlinedHostedApps) && 978 switches::kEnableStreamlinedHostedApps) &&
1000 browser_->is_app())); 979 browser_->is_app()));
1001 980
1002 // Window management commands 981 // Window management commands
1003 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); 982 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
1004 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, 983 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
1005 normal_window); 984 normal_window);
1006 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); 985 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
1007 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); 986 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
1008 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); 987 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
1009 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); 988 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
1010 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); 989 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
1011 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); 990 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
1012 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); 991 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
1013 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); 992 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
1014 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); 993 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
1015 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); 994 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
1016 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); 995 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
1017 #if defined(OS_WIN) 996 #if defined(OS_WIN)
1018 #if !defined(USE_AURA) 997 bool metro = browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH;
1019 const bool metro_mode = base::win::IsMetroProcess(); 998 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro);
1020 #else 999 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro);
1021 const bool metro_mode = 1000 int restart_mode = metro ? IDC_WIN8_DESKTOP_RESTART : IDC_WIN8_METRO_RESTART;
1022 browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ?
1023 true : false;
1024 #endif
1025 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro_mode);
1026 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro_mode);
1027 int restart_mode = metro_mode ?
1028 IDC_WIN8_DESKTOP_RESTART : IDC_WIN8_METRO_RESTART;
1029 command_updater_.UpdateCommandEnabled(restart_mode, normal_window); 1001 command_updater_.UpdateCommandEnabled(restart_mode, normal_window);
1030 #endif 1002 #endif
1031 1003
1032 // Show various bits of UI 1004 // These are always enabled; the menu determines their menu item visibility.
1033 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
1034
1035 // The upgrade entry and the view incompatibility entry should always be
1036 // enabled. Whether they are visible is a separate matter determined on menu
1037 // show.
1038 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); 1005 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
1039 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true); 1006 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
1040 1007
1041 // Toggle speech input 1008 // Toggle speech input
1042 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true); 1009 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true);
1043 1010
1044 // Initialize other commands whose state changes based on fullscreen mode. 1011 // Initialize other commands whose state changes based on various conditions.
1045 UpdateCommandsForFullscreenMode(); 1012 UpdateCommandsForFullscreenMode();
1046
1047 UpdateCommandsForContentRestrictionState(); 1013 UpdateCommandsForContentRestrictionState();
1048
1049 UpdateCommandsForBookmarkEditing(); 1014 UpdateCommandsForBookmarkEditing();
1050
1051 UpdateCommandsForIncognitoAvailability(); 1015 UpdateCommandsForIncognitoAvailability();
1052 } 1016 }
1053 1017
1054 // static 1018 // static
1055 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( 1019 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1056 CommandUpdater* command_updater, 1020 CommandUpdater* command_updater,
1057 Profile* profile) { 1021 Profile* profile) {
1058 IncognitoModePrefs::Availability incognito_availability = 1022 IncognitoModePrefs::Availability incognito_availability =
1059 IncognitoModePrefs::GetAvailability(profile->GetPrefs()); 1023 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
1060 command_updater->UpdateCommandEnabled( 1024 command_updater->UpdateCommandEnabled(
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 // Disable toggling into fullscreen mode if disallowed by pref. 1236 // Disable toggling into fullscreen mode if disallowed by pref.
1273 fullscreen_enabled = false; 1237 fullscreen_enabled = false;
1274 } 1238 }
1275 #endif 1239 #endif
1276 1240
1277 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); 1241 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
1278 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE, 1242 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE,
1279 fullscreen_enabled); 1243 fullscreen_enabled);
1280 1244
1281 UpdateCommandsForBookmarkBar(); 1245 UpdateCommandsForBookmarkBar();
1282 UpdateCommandsForMultipleProfiles();
1283 }
1284
1285 void BrowserCommandController::UpdateCommandsForMultipleProfiles() {
1286 bool is_regular_or_guest_session =
1287 profile()->IsGuestSession() || !profile()->IsOffTheRecord();
1288 bool enable = IsShowingMainUI() &&
1289 is_regular_or_guest_session &&
1290 profile_manager_ &&
1291 AvatarMenu::ShouldShowAvatarMenu();
1292 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU,
1293 enable);
1294 } 1246 }
1295 1247
1296 void BrowserCommandController::UpdatePrintingState() { 1248 void BrowserCommandController::UpdatePrintingState() {
1297 bool print_enabled = CanPrint(browser_); 1249 bool print_enabled = CanPrint(browser_);
1298 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); 1250 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
1299 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT, 1251 command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT,
1300 CanAdvancedPrint(browser_)); 1252 CanAdvancedPrint(browser_));
1301 command_updater_.UpdateCommandEnabled(IDC_PRINT_TO_DESTINATION, 1253 command_updater_.UpdateCommandEnabled(IDC_PRINT_TO_DESTINATION,
1302 print_enabled); 1254 print_enabled);
1303 #if defined(OS_WIN) 1255 #if defined(OS_WIN)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 1319
1368 BrowserWindow* BrowserCommandController::window() { 1320 BrowserWindow* BrowserCommandController::window() {
1369 return browser_->window(); 1321 return browser_->window();
1370 } 1322 }
1371 1323
1372 Profile* BrowserCommandController::profile() { 1324 Profile* BrowserCommandController::profile() {
1373 return browser_->profile(); 1325 return browser_->profile();
1374 } 1326 }
1375 1327
1376 } // namespace chrome 1328 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_command_controller.h ('k') | chrome/browser/ui/browser_command_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698