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/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 19 #include "chrome/browser/sync/profile_sync_service_factory.h" |
20 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 20 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
| 23 #include "chrome/browser/ui/browser_tabstrip.h" |
23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/chrome_pages.h" | 25 #include "chrome/browser/ui/chrome_pages.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
27 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 28 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/profiling.h" | 31 #include "chrome/common/profiling.h" |
31 #include "content/public/browser/native_web_keyboard_event.h" | 32 #include "content/public/browser/native_web_keyboard_event.h" |
32 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 222 |
222 void BrowserCommandController::ExecuteCommandWithDisposition( | 223 void BrowserCommandController::ExecuteCommandWithDisposition( |
223 int id, WindowOpenDisposition disposition) { | 224 int id, WindowOpenDisposition disposition) { |
224 // No commands are enabled if there is not yet any selected tab. | 225 // No commands are enabled if there is not yet any selected tab. |
225 // TODO(pkasting): It seems like we should not need this, because either | 226 // TODO(pkasting): It seems like we should not need this, because either |
226 // most/all commands should not have been enabled yet anyway or the ones that | 227 // most/all commands should not have been enabled yet anyway or the ones that |
227 // are enabled should be global, or safe themselves against having no selected | 228 // are enabled should be global, or safe themselves against having no selected |
228 // tab. However, Ben says he tried removing this before and got lots of | 229 // tab. However, Ben says he tried removing this before and got lots of |
229 // crashes, e.g. from Windows sending WM_COMMANDs at random times during | 230 // crashes, e.g. from Windows sending WM_COMMANDs at random times during |
230 // window construction. This probably could use closer examination someday. | 231 // window construction. This probably could use closer examination someday. |
231 if (!browser_->GetActiveTabContents()) | 232 if (!chrome::GetActiveTabContents(browser_)) |
232 return; | 233 return; |
233 | 234 |
234 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " | 235 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " |
235 << id; | 236 << id; |
236 | 237 |
237 // If command execution is blocked then just record the command and return. | 238 // If command execution is blocked then just record the command and return. |
238 if (block_command_execution_) { | 239 if (block_command_execution_) { |
239 // We actually only allow no more than one blocked command, otherwise some | 240 // We actually only allow no more than one blocked command, otherwise some |
240 // commands maybe lost. | 241 // commands maybe lost. |
241 DCHECK_EQ(last_blocked_command_id_, -1); | 242 DCHECK_EQ(last_blocked_command_id_, -1); |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 | 850 |
850 const bool show_main_ui = | 851 const bool show_main_ui = |
851 IsShowingMainUI(window() && window()->IsFullscreen()); | 852 IsShowingMainUI(window() && window()->IsFullscreen()); |
852 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, | 853 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, |
853 show_main_ui && command_enabled); | 854 show_main_ui && command_enabled); |
854 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, | 855 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, |
855 show_main_ui && command_enabled); | 856 show_main_ui && command_enabled); |
856 } | 857 } |
857 | 858 |
858 void BrowserCommandController::UpdateCommandsForTabState() { | 859 void BrowserCommandController::UpdateCommandsForTabState() { |
859 TabContents* current_tab_contents = browser_->GetActiveTabContents(); | 860 TabContents* current_tab_contents = chrome::GetActiveTabContents(browser_); |
860 if (!current_tab_contents) // May be NULL during tab restore. | 861 if (!current_tab_contents) // May be NULL during tab restore. |
861 return; | 862 return; |
862 WebContents* current_web_contents = current_tab_contents->web_contents(); | 863 WebContents* current_web_contents = current_tab_contents->web_contents(); |
863 | 864 |
864 // Navigation commands | 865 // Navigation commands |
865 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); | 866 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); |
866 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_)); | 867 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_)); |
867 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_)); | 868 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_)); |
868 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, | 869 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, |
869 CanReload(browser_)); | 870 CanReload(browser_)); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 | 1072 |
1072 BrowserWindow* BrowserCommandController::window() { | 1073 BrowserWindow* BrowserCommandController::window() { |
1073 return browser_->window(); | 1074 return browser_->window(); |
1074 } | 1075 } |
1075 | 1076 |
1076 Profile* BrowserCommandController::profile() { | 1077 Profile* BrowserCommandController::profile() { |
1077 return browser_->profile(); | 1078 return browser_->profile(); |
1078 } | 1079 } |
1079 | 1080 |
1080 } // namespace chrome | 1081 } // namespace chrome |
OLD | NEW |