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 "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #if defined(USE_ASH) | 53 #if defined(USE_ASH) |
54 #include "chrome/browser/ui/ash/ash_util.h" | 54 #include "chrome/browser/ui/ash/ash_util.h" |
55 #endif | 55 #endif |
56 | 56 |
57 using content::NavigationEntry; | 57 using content::NavigationEntry; |
58 using content::NavigationController; | 58 using content::NavigationController; |
59 using content::WebContents; | 59 using content::WebContents; |
60 | 60 |
61 namespace { | 61 namespace { |
62 | 62 |
| 63 enum WindowState { |
| 64 // Not in fullscreen mode. |
| 65 WINDOW_STATE_NOT_FULLSCREEN, |
| 66 |
| 67 // Fullscreen mode, occupying the whole screen. |
| 68 WINDOW_STATE_FULLSCREEN, |
| 69 |
| 70 // Fullscreen mode for metro snap, occupying the full height and 20% of |
| 71 // the screen width. |
| 72 WINDOW_STATE_METRO_SNAP, |
| 73 }; |
| 74 |
63 // Returns |true| if entry has an internal chrome:// URL, |false| otherwise. | 75 // Returns |true| if entry has an internal chrome:// URL, |false| otherwise. |
64 bool HasInternalURL(const NavigationEntry* entry) { | 76 bool HasInternalURL(const NavigationEntry* entry) { |
65 if (!entry) | 77 if (!entry) |
66 return false; | 78 return false; |
67 | 79 |
68 // Check the |virtual_url()| first. This catches regular chrome:// URLs | 80 // Check the |virtual_url()| first. This catches regular chrome:// URLs |
69 // including URLs that were rewritten (such as chrome://bookmarks). | 81 // including URLs that were rewritten (such as chrome://bookmarks). |
70 if (entry->GetVirtualURL().SchemeIs(chrome::kChromeUIScheme)) | 82 if (entry->GetVirtualURL().SchemeIs(chrome::kChromeUIScheme)) |
71 return true; | 83 return true; |
72 | 84 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 base::Unretained(this))); | 202 base::Unretained(this))); |
191 profile_pref_registrar_.Add( | 203 profile_pref_registrar_.Add( |
192 prefs::kIncognitoModeAvailability, | 204 prefs::kIncognitoModeAvailability, |
193 base::Bind( | 205 base::Bind( |
194 &BrowserCommandController::UpdateCommandsForIncognitoAvailability, | 206 &BrowserCommandController::UpdateCommandsForIncognitoAvailability, |
195 base::Unretained(this))); | 207 base::Unretained(this))); |
196 profile_pref_registrar_.Add( | 208 profile_pref_registrar_.Add( |
197 prefs::kPrintingEnabled, | 209 prefs::kPrintingEnabled, |
198 base::Bind(&BrowserCommandController::UpdatePrintingState, | 210 base::Bind(&BrowserCommandController::UpdatePrintingState, |
199 base::Unretained(this))); | 211 base::Unretained(this))); |
| 212 #if !defined(OS_MACOSX) |
| 213 profile_pref_registrar_.Add( |
| 214 prefs::kFullscreenAllowed, |
| 215 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode, |
| 216 base::Unretained(this))); |
| 217 #endif |
200 pref_signin_allowed_.Init( | 218 pref_signin_allowed_.Init( |
201 prefs::kSigninAllowed, | 219 prefs::kSigninAllowed, |
202 profile()->GetOriginalProfile()->GetPrefs(), | 220 profile()->GetOriginalProfile()->GetPrefs(), |
203 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange, | 221 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange, |
204 base::Unretained(this))); | 222 base::Unretained(this))); |
205 | 223 |
206 InitCommandState(); | 224 InitCommandState(); |
207 | 225 |
208 TabRestoreService* tab_restore_service = | 226 TabRestoreService* tab_restore_service = |
209 TabRestoreServiceFactory::GetForProfile(profile()); | 227 TabRestoreServiceFactory::GetForProfile(profile()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 297 |
280 void BrowserCommandController::TabStateChanged() { | 298 void BrowserCommandController::TabStateChanged() { |
281 UpdateCommandsForTabState(); | 299 UpdateCommandsForTabState(); |
282 } | 300 } |
283 | 301 |
284 void BrowserCommandController::ContentRestrictionsChanged() { | 302 void BrowserCommandController::ContentRestrictionsChanged() { |
285 UpdateCommandsForContentRestrictionState(); | 303 UpdateCommandsForContentRestrictionState(); |
286 } | 304 } |
287 | 305 |
288 void BrowserCommandController::FullscreenStateChanged() { | 306 void BrowserCommandController::FullscreenStateChanged() { |
289 FullScreenMode fullscreen_mode = FULLSCREEN_DISABLED; | 307 UpdateCommandsForFullscreenMode(); |
290 if (window()->IsFullscreen()) { | |
291 #if defined(OS_WIN) | |
292 fullscreen_mode = window()->IsInMetroSnapMode() ? FULLSCREEN_METRO_SNAP : | |
293 FULLSCREEN_NORMAL; | |
294 #else | |
295 fullscreen_mode = FULLSCREEN_NORMAL; | |
296 #endif | |
297 } | |
298 UpdateCommandsForFullscreenMode(fullscreen_mode); | |
299 } | 308 } |
300 | 309 |
301 void BrowserCommandController::PrintingStateChanged() { | 310 void BrowserCommandController::PrintingStateChanged() { |
302 UpdatePrintingState(); | 311 UpdatePrintingState(); |
303 } | 312 } |
304 | 313 |
305 void BrowserCommandController::LoadingStateChanged(bool is_loading, | 314 void BrowserCommandController::LoadingStateChanged(bool is_loading, |
306 bool force) { | 315 bool force) { |
307 UpdateReloadStopState(is_loading, force); | 316 UpdateReloadStopState(is_loading, force); |
308 } | 317 } |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 // The upgrade entry and the view incompatibility entry should always be | 938 // The upgrade entry and the view incompatibility entry should always be |
930 // enabled. Whether they are visible is a separate matter determined on menu | 939 // enabled. Whether they are visible is a separate matter determined on menu |
931 // show. | 940 // show. |
932 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); | 941 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); |
933 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true); | 942 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true); |
934 | 943 |
935 // Toggle speech input | 944 // Toggle speech input |
936 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true); | 945 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true); |
937 | 946 |
938 // Initialize other commands whose state changes based on fullscreen mode. | 947 // Initialize other commands whose state changes based on fullscreen mode. |
939 UpdateCommandsForFullscreenMode(FULLSCREEN_DISABLED); | 948 UpdateCommandsForFullscreenMode(); |
940 | 949 |
941 UpdateCommandsForContentRestrictionState(); | 950 UpdateCommandsForContentRestrictionState(); |
942 | 951 |
943 UpdateCommandsForBookmarkEditing(); | 952 UpdateCommandsForBookmarkEditing(); |
944 | 953 |
945 UpdateCommandsForIncognitoAvailability(); | 954 UpdateCommandsForIncognitoAvailability(); |
946 } | 955 } |
947 | 956 |
948 // static | 957 // static |
949 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( | 958 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 browser_defaults::bookmarks_enabled && | 1089 browser_defaults::bookmarks_enabled && |
1081 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && | 1090 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar) && |
1082 IsShowingMainUI()); | 1091 IsShowingMainUI()); |
1083 } | 1092 } |
1084 | 1093 |
1085 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { | 1094 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { |
1086 UpdateSaveAsState(); | 1095 UpdateSaveAsState(); |
1087 UpdateOpenFileState(&command_updater_); | 1096 UpdateOpenFileState(&command_updater_); |
1088 } | 1097 } |
1089 | 1098 |
1090 void BrowserCommandController::UpdateCommandsForFullscreenMode( | 1099 void BrowserCommandController::UpdateCommandsForFullscreenMode() { |
1091 FullScreenMode fullscreen_mode) { | 1100 WindowState window_state = WINDOW_STATE_NOT_FULLSCREEN; |
| 1101 if (window() && window()->IsFullscreen()) { |
| 1102 window_state = WINDOW_STATE_FULLSCREEN; |
| 1103 #if defined(OS_WIN) |
| 1104 if (window()->IsInMetroSnapMode()) |
| 1105 window_state = WINDOW_STATE_METRO_SNAP; |
| 1106 #endif |
| 1107 } |
1092 bool show_main_ui = IsShowingMainUI(); | 1108 bool show_main_ui = IsShowingMainUI(); |
1093 bool main_not_fullscreen = show_main_ui && | 1109 bool main_not_fullscreen = |
1094 (fullscreen_mode == FULLSCREEN_DISABLED); | 1110 show_main_ui && window_state == WINDOW_STATE_NOT_FULLSCREEN; |
1095 | 1111 |
1096 // Navigation commands | 1112 // Navigation commands |
1097 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); | 1113 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); |
1098 | 1114 |
1099 // Window management commands | 1115 // Window management commands |
1100 command_updater_.UpdateCommandEnabled( | 1116 command_updater_.UpdateCommandEnabled( |
1101 IDC_SHOW_AS_TAB, | 1117 IDC_SHOW_AS_TAB, |
1102 !browser_->is_type_tabbed() && fullscreen_mode == FULLSCREEN_DISABLED); | 1118 !browser_->is_type_tabbed() && |
| 1119 window_state == WINDOW_STATE_NOT_FULLSCREEN); |
1103 | 1120 |
1104 // Focus various bits of UI | 1121 // Focus various bits of UI |
1105 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); | 1122 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); |
1106 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); | 1123 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); |
1107 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); | 1124 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); |
1108 command_updater_.UpdateCommandEnabled( | 1125 command_updater_.UpdateCommandEnabled( |
1109 IDC_FOCUS_MENU_BAR, main_not_fullscreen); | 1126 IDC_FOCUS_MENU_BAR, main_not_fullscreen); |
1110 command_updater_.UpdateCommandEnabled( | 1127 command_updater_.UpdateCommandEnabled( |
1111 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); | 1128 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
1112 command_updater_.UpdateCommandEnabled( | 1129 command_updater_.UpdateCommandEnabled( |
(...skipping 18 matching lines...) Expand all Loading... |
1131 | 1148 |
1132 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1149 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
1133 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 1150 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
1134 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 1151 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
1135 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 1152 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
1136 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) | 1153 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
1137 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 1154 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
1138 #endif | 1155 #endif |
1139 | 1156 |
1140 // Disable explicit fullscreen toggling when in metro snap mode. | 1157 // Disable explicit fullscreen toggling when in metro snap mode. |
1141 bool fullscreen_enabled = fullscreen_mode != FULLSCREEN_METRO_SNAP; | 1158 bool fullscreen_enabled = window_state != WINDOW_STATE_METRO_SNAP; |
1142 #if defined(OS_MACOSX) | 1159 #if defined(OS_MACOSX) |
1143 // The Mac implementation doesn't support switching to fullscreen while | 1160 // The Mac implementation doesn't support switching to fullscreen while |
1144 // a tab modal dialog is displayed. | 1161 // a tab modal dialog is displayed. |
1145 int tab_index = chrome::IndexOfFirstBlockedTab(browser_->tab_strip_model()); | 1162 int tab_index = chrome::IndexOfFirstBlockedTab(browser_->tab_strip_model()); |
1146 bool has_blocked_tab = tab_index != browser_->tab_strip_model()->count(); | 1163 bool has_blocked_tab = tab_index != browser_->tab_strip_model()->count(); |
1147 fullscreen_enabled &= !has_blocked_tab; | 1164 fullscreen_enabled &= !has_blocked_tab; |
| 1165 #else |
| 1166 if (window_state == WINDOW_STATE_NOT_FULLSCREEN && |
| 1167 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { |
| 1168 // Disable toggling into fullscreen mode if disallowed by pref. |
| 1169 fullscreen_enabled = false; |
| 1170 } |
1148 #endif | 1171 #endif |
1149 | 1172 |
1150 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); | 1173 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); |
1151 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE, | 1174 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE, |
1152 fullscreen_enabled); | 1175 fullscreen_enabled); |
1153 | 1176 |
1154 UpdateCommandsForBookmarkBar(); | 1177 UpdateCommandsForBookmarkBar(); |
1155 UpdateCommandsForMultipleProfiles(); | 1178 UpdateCommandsForMultipleProfiles(); |
1156 } | 1179 } |
1157 | 1180 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 | 1261 |
1239 BrowserWindow* BrowserCommandController::window() { | 1262 BrowserWindow* BrowserCommandController::window() { |
1240 return browser_->window(); | 1263 return browser_->window(); |
1241 } | 1264 } |
1242 | 1265 |
1243 Profile* BrowserCommandController::profile() { | 1266 Profile* BrowserCommandController::profile() { |
1244 return browser_->profile(); | 1267 return browser_->profile(); |
1245 } | 1268 } |
1246 | 1269 |
1247 } // namespace chrome | 1270 } // namespace chrome |
OLD | NEW |