| 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/printing/print_preview_tab_controller.h" | 13 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/sessions/tab_restore_service.h" | 16 #include "chrome/browser/sessions/tab_restore_service.h" |
| 17 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 17 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 18 #include "chrome/browser/shell_integration.h" | 18 #include "chrome/browser/shell_integration.h" |
| 19 #include "chrome/browser/sync/profile_sync_service.h" | 19 #include "chrome/browser/sync/profile_sync_service.h" |
| 20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 21 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 21 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
| 24 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
| 25 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| 26 #include "chrome/browser/ui/chrome_pages.h" | 26 #include "chrome/browser/ui/chrome_pages.h" |
| 27 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 29 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" |
| 29 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 30 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 30 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
| 31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/profiling.h" | 33 #include "chrome/common/profiling.h" |
| 33 #include "content/public/browser/native_web_keyboard_event.h" | 34 #include "content/public/browser/native_web_keyboard_event.h" |
| 34 #include "content/public/browser/navigation_controller.h" | 35 #include "content/public/browser/navigation_controller.h" |
| 35 #include "content/public/browser/navigation_entry.h" | 36 #include "content/public/browser/navigation_entry.h" |
| 36 #include "content/public/browser/notification_details.h" | 37 #include "content/public/browser/notification_details.h" |
| 37 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
| 38 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 command_updater_.UpdateCommandEnabled( | 856 command_updater_.UpdateCommandEnabled( |
| 856 IDC_SHOW_SYNC_SETUP, profile()->GetOriginalProfile()->IsSyncAccessible()); | 857 IDC_SHOW_SYNC_SETUP, profile()->GetOriginalProfile()->IsSyncAccessible()); |
| 857 | 858 |
| 858 // Initialize other commands based on the window type. | 859 // Initialize other commands based on the window type. |
| 859 bool normal_window = browser_->is_type_tabbed(); | 860 bool normal_window = browser_->is_type_tabbed(); |
| 860 | 861 |
| 861 // Navigation commands | 862 // Navigation commands |
| 862 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 863 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
| 863 | 864 |
| 864 // Window management commands | 865 // Window management commands |
| 865 // TODO(rohitrao): Disable fullscreen on non-Lion? | |
| 866 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, | |
| 867 !(browser_->is_type_panel() && browser_->is_app())); | |
| 868 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 866 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 869 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 867 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| 870 normal_window); | 868 normal_window); |
| 871 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); | 869 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); |
| 872 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); | 870 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); |
| 873 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); | 871 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); |
| 874 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); | 872 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); |
| 875 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); | 873 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); |
| 876 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); | 874 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); |
| 877 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); | 875 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); |
| 878 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); | 876 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); |
| 879 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); | 877 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); |
| 880 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); | 878 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); |
| 881 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); | 879 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); |
| 882 #if defined(OS_WIN) | 880 #if defined(OS_WIN) |
| 883 const bool metro_mode = base::win::IsMetroProcess(); | 881 const bool metro_mode = base::win::IsMetroProcess(); |
| 884 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro_mode); | 882 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro_mode); |
| 885 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro_mode); | 883 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro_mode); |
| 886 int restart_mode = metro_mode ? | 884 int restart_mode = metro_mode ? |
| 887 IDC_WIN8_DESKTOP_RESTART : IDC_WIN8_METRO_RESTART; | 885 IDC_WIN8_DESKTOP_RESTART : IDC_WIN8_METRO_RESTART; |
| 888 command_updater_.UpdateCommandEnabled(restart_mode, normal_window); | 886 command_updater_.UpdateCommandEnabled(restart_mode, normal_window); |
| 889 #endif | 887 #endif |
| 890 #if defined(OS_MACOSX) | |
| 891 command_updater_.UpdateCommandEnabled(IDC_TABPOSE, normal_window); | 888 command_updater_.UpdateCommandEnabled(IDC_TABPOSE, normal_window); |
| 892 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE, | |
| 893 !(browser_->is_type_panel() && browser_->is_app())); | |
| 894 #endif | |
| 895 | 889 |
| 896 // Find-in-page | 890 // Find-in-page |
| 897 command_updater_.UpdateCommandEnabled(IDC_FIND, !browser_->is_devtools()); | 891 command_updater_.UpdateCommandEnabled(IDC_FIND, !browser_->is_devtools()); |
| 898 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, | 892 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, |
| 899 !browser_->is_devtools()); | 893 !browser_->is_devtools()); |
| 900 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, | 894 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, |
| 901 !browser_->is_devtools()); | 895 !browser_->is_devtools()); |
| 902 | 896 |
| 903 // Show various bits of UI | 897 // Show various bits of UI |
| 904 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window); | 898 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 | 1092 |
| 1099 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1093 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1100 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 1094 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1101 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 1095 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 1102 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 1096 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| 1103 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) | 1097 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 1104 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 1098 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 1105 #endif | 1099 #endif |
| 1106 | 1100 |
| 1107 // Disable explicit fullscreen toggling when in metro snap mode. | 1101 // Disable explicit fullscreen toggling when in metro snap mode. |
| 1108 command_updater_.UpdateCommandEnabled( | 1102 bool fullscreen_enabled = !browser_->is_type_panel() && |
| 1109 IDC_FULLSCREEN, | 1103 !browser_->is_app() && |
| 1110 fullscreen_mode != FULLSCREEN_METRO_SNAP); | 1104 fullscreen_mode != FULLSCREEN_METRO_SNAP; |
| 1105 #if defined(OS_MACOSX) |
| 1106 // The Mac implementation doesn't support switching to fullscreen while |
| 1107 // a tab modal dialog is displayed. |
| 1108 int tabIndex = chrome::IndexOfFirstBlockedTab(browser_->tab_strip_model()); |
| 1109 bool has_blocked_tab = tabIndex != browser_->tab_strip_model()->count(); |
| 1110 fullscreen_enabled &= !has_blocked_tab; |
| 1111 #endif |
| 1112 |
| 1113 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); |
| 1114 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE, |
| 1115 fullscreen_enabled); |
| 1111 | 1116 |
| 1112 UpdateCommandsForBookmarkBar(); | 1117 UpdateCommandsForBookmarkBar(); |
| 1113 UpdateCommandsForMultipleProfiles(); | 1118 UpdateCommandsForMultipleProfiles(); |
| 1114 } | 1119 } |
| 1115 | 1120 |
| 1116 void BrowserCommandController::UpdateCommandsForMultipleProfiles() { | 1121 void BrowserCommandController::UpdateCommandsForMultipleProfiles() { |
| 1117 bool show_main_ui = IsShowingMainUI(window() && window()->IsFullscreen()); | 1122 bool show_main_ui = IsShowingMainUI(window() && window()->IsFullscreen()); |
| 1118 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, | 1123 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, |
| 1119 show_main_ui && | 1124 show_main_ui && |
| 1120 !profile()->IsOffTheRecord() && | 1125 !profile()->IsOffTheRecord() && |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 | 1182 |
| 1178 BrowserWindow* BrowserCommandController::window() { | 1183 BrowserWindow* BrowserCommandController::window() { |
| 1179 return browser_->window(); | 1184 return browser_->window(); |
| 1180 } | 1185 } |
| 1181 | 1186 |
| 1182 Profile* BrowserCommandController::profile() { | 1187 Profile* BrowserCommandController::profile() { |
| 1183 return browser_->profile(); | 1188 return browser_->profile(); |
| 1184 } | 1189 } |
| 1185 | 1190 |
| 1186 } // namespace chrome | 1191 } // namespace chrome |
| OLD | NEW |