[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/ui/browser_command_controller.h" |
| 6 | |
[email protected] | 488e395 | 2013-11-18 05:29:14 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 8 | #include "base/prefs/pref_service.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 9 | #include "chrome/app/chrome_command_ids.h" |
| 10 | #include "chrome/browser/browser_process.h" |
[email protected] | dcc8fbc | 2013-07-12 00:54:09 | [diff] [blame] | 11 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 12 | #include "chrome/browser/defaults.h" |
| 13 | #include "chrome/browser/extensions/extension_service.h" |
benwells | 39f23ae | 2014-08-27 08:01:52 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 15 | #include "chrome/browser/lifetime/application_lifetime.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 16 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profile.h" |
mlerman | e01e6de | 2014-09-29 19:26:47 | [diff] [blame] | 18 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 19 | #include "chrome/browser/sessions/tab_restore_service.h" |
| 20 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 21 | #include "chrome/browser/shell_integration.h" |
[email protected] | 3d27d27 | 2013-07-31 03:15:16 | [diff] [blame] | 22 | #include "chrome/browser/signin/signin_promo.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 23 | #include "chrome/browser/sync/profile_sync_service.h" |
| 24 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 25 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 26 | #include "chrome/browser/ui/browser.h" |
| 27 | #include "chrome/browser/ui/browser_commands.h" |
| 28 | #include "chrome/browser/ui/browser_window.h" |
| 29 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 30 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 00a1cc5b | 2012-11-07 13:44:51 | [diff] [blame] | 31 | #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" |
[email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 32 | #include "chrome/browser/ui/webui/inspect_ui.h" |
[email protected] | 488e395 | 2013-11-18 05:29:14 | [diff] [blame] | 33 | #include "chrome/common/chrome_switches.h" |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 34 | #include "chrome/common/content_restriction.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 35 | #include "chrome/common/pref_names.h" |
| 36 | #include "chrome/common/profiling.h" |
| 37 | #include "content/public/browser/native_web_keyboard_event.h" |
| 38 | #include "content/public/browser/navigation_controller.h" |
| 39 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 6708dbc | 2012-11-04 00:17:22 | [diff] [blame] | 40 | #include "content/public/browser/user_metrics.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 41 | #include "content/public/browser/web_contents.h" |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 42 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 43 | #include "content/public/common/url_constants.h" |
[email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 44 | #include "extensions/browser/extension_system.h" |
[email protected] | 7e9acd08 | 2013-09-17 23:31:16 | [diff] [blame] | 45 | #include "ui/events/keycodes/keyboard_codes.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 46 | |
[email protected] | 9c4d6833 | 2013-01-30 13:34:41 | [diff] [blame] | 47 | #if defined(OS_MACOSX) |
| 48 | #include "chrome/browser/ui/browser_commands_mac.h" |
| 49 | #endif |
| 50 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 51 | #if defined(OS_WIN) |
| 52 | #include "base/win/metro.h" |
[email protected] | a43ed00 | 2013-02-05 19:47:54 | [diff] [blame] | 53 | #include "base/win/windows_version.h" |
[email protected] | 471e1e8 | 2013-08-14 09:53:52 | [diff] [blame] | 54 | #include "chrome/browser/ui/apps/apps_metro_handler_win.h" |
[email protected] | 2d0f80f | 2013-11-01 22:47:18 | [diff] [blame] | 55 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 56 | #endif |
| 57 | |
[email protected] | 4b0bcef | 2012-09-27 00:20:56 | [diff] [blame] | 58 | #if defined(USE_ASH) |
[email protected] | fa941276 | 2013-09-04 23:31:33 | [diff] [blame] | 59 | #include "ash/accelerators/accelerator_commands.h" |
[email protected] | 4b0bcef | 2012-09-27 00:20:56 | [diff] [blame] | 60 | #include "chrome/browser/ui/ash/ash_util.h" |
| 61 | #endif |
| 62 | |
[email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 63 | #if defined(OS_CHROMEOS) |
[email protected] | 7c43e7fe | 2013-11-01 13:35:17 | [diff] [blame] | 64 | #include "ash/multi_profile_uma.h" |
[email protected] | fdf74bf | 2014-04-30 21:24:02 | [diff] [blame] | 65 | #include "ash/session/session_state_delegate.h" |
[email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 66 | #include "ash/shell.h" |
[email protected] | 0c93081 | 2014-01-30 18:01:47 | [diff] [blame] | 67 | #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" |
[email protected] | 5226f1e | 2013-11-09 04:12:10 | [diff] [blame] | 68 | #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
caelyn | 4e4e08a | 2015-02-04 21:27:49 | [diff] [blame] | 69 | #include "chrome/browser/ui/browser_commands_chromeos.h" |
[email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 70 | #endif |
| 71 | |
[email protected] | d5bedb6d | 2014-04-08 10:49:32 | [diff] [blame] | 72 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 73 | #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" |
[email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 74 | #endif |
| 75 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 76 | using content::NavigationEntry; |
| 77 | using content::NavigationController; |
| 78 | using content::WebContents; |
| 79 | |
| 80 | namespace { |
| 81 | |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 82 | enum WindowState { |
| 83 | // Not in fullscreen mode. |
| 84 | WINDOW_STATE_NOT_FULLSCREEN, |
| 85 | |
| 86 | // Fullscreen mode, occupying the whole screen. |
| 87 | WINDOW_STATE_FULLSCREEN, |
| 88 | |
| 89 | // Fullscreen mode for metro snap, occupying the full height and 20% of |
| 90 | // the screen width. |
| 91 | WINDOW_STATE_METRO_SNAP, |
| 92 | }; |
| 93 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 94 | // Returns |true| if entry has an internal chrome:// URL, |false| otherwise. |
| 95 | bool HasInternalURL(const NavigationEntry* entry) { |
| 96 | if (!entry) |
| 97 | return false; |
| 98 | |
| 99 | // Check the |virtual_url()| first. This catches regular chrome:// URLs |
| 100 | // including URLs that were rewritten (such as chrome://bookmarks). |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 101 | if (entry->GetVirtualURL().SchemeIs(content::kChromeUIScheme)) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 102 | return true; |
| 103 | |
| 104 | // If the |virtual_url()| isn't a chrome:// URL, check if it's actually |
| 105 | // view-source: of a chrome:// URL. |
[email protected] | dbdda540 | 2013-05-30 22:13:48 | [diff] [blame] | 106 | if (entry->GetVirtualURL().SchemeIs(content::kViewSourceScheme)) |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 107 | return entry->GetURL().SchemeIs(content::kChromeUIScheme); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 108 | |
| 109 | return false; |
| 110 | } |
| 111 | |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 112 | #if defined(OS_WIN) |
| 113 | // Windows 8 specific helper class to manage DefaultBrowserWorker. It does the |
| 114 | // following asynchronous actions in order: |
| 115 | // 1- Check that chrome is the default browser |
| 116 | // 2- If we are the default, restart chrome in metro and exit |
| 117 | // 3- If not the default browser show the 'select default browser' system dialog |
| 118 | // 4- When dialog dismisses check again who got made the default |
| 119 | // 5- If we are the default then restart chrome in metro and exit |
| 120 | // 6- If we are not the default exit. |
| 121 | // |
| 122 | // Note: this class deletes itself. |
[email protected] | 24ced7dc0 | 2013-04-04 08:32:39 | [diff] [blame] | 123 | class SwitchToMetroUIHandler |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 124 | : public ShellIntegration::DefaultWebClientObserver { |
| 125 | public: |
[email protected] | 24ced7dc0 | 2013-04-04 08:32:39 | [diff] [blame] | 126 | SwitchToMetroUIHandler() |
[email protected] | d4b2d23 | 2013-04-30 21:14:23 | [diff] [blame] | 127 | : default_browser_worker_( |
| 128 | new ShellIntegration::DefaultBrowserWorker(this)), |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 129 | first_check_(true) { |
| 130 | default_browser_worker_->StartCheckIsDefault(); |
| 131 | } |
| 132 | |
nick | ddb02ac | 2015-04-24 20:45:38 | [diff] [blame] | 133 | ~SwitchToMetroUIHandler() override { |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 134 | default_browser_worker_->ObserverDestroyed(); |
| 135 | } |
| 136 | |
| 137 | private: |
nick | ddb02ac | 2015-04-24 20:45:38 | [diff] [blame] | 138 | void SetDefaultWebClientUIState( |
mostynb | 205d625 | 2014-10-04 00:49:22 | [diff] [blame] | 139 | ShellIntegration::DefaultWebClientUIState state) override { |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 140 | switch (state) { |
| 141 | case ShellIntegration::STATE_PROCESSING: |
| 142 | return; |
| 143 | case ShellIntegration::STATE_UNKNOWN : |
| 144 | break; |
| 145 | case ShellIntegration::STATE_IS_DEFAULT: |
[email protected] | d51373d | 2013-10-31 15:22:00 | [diff] [blame] | 146 | chrome::AttemptRestartToMetroMode(); |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 147 | break; |
| 148 | case ShellIntegration::STATE_NOT_DEFAULT: |
| 149 | if (first_check_) { |
| 150 | default_browser_worker_->StartSetAsDefault(); |
| 151 | return; |
| 152 | } |
| 153 | break; |
| 154 | default: |
| 155 | NOTREACHED(); |
| 156 | } |
| 157 | delete this; |
| 158 | } |
| 159 | |
nick | ddb02ac | 2015-04-24 20:45:38 | [diff] [blame] | 160 | void OnSetAsDefaultConcluded(bool success) override { |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 161 | if (!success) { |
| 162 | delete this; |
| 163 | return; |
| 164 | } |
| 165 | first_check_ = false; |
| 166 | default_browser_worker_->StartCheckIsDefault(); |
| 167 | } |
| 168 | |
nick | ddb02ac | 2015-04-24 20:45:38 | [diff] [blame] | 169 | bool IsInteractiveSetDefaultPermitted() override { |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 170 | return true; |
| 171 | } |
| 172 | |
| 173 | scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_; |
| 174 | bool first_check_; |
| 175 | |
[email protected] | 24ced7dc0 | 2013-04-04 08:32:39 | [diff] [blame] | 176 | DISALLOW_COPY_AND_ASSIGN(SwitchToMetroUIHandler); |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 177 | }; |
| 178 | #endif // defined(OS_WIN) |
| 179 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 180 | } // namespace |
| 181 | |
| 182 | namespace chrome { |
| 183 | |
| 184 | /////////////////////////////////////////////////////////////////////////////// |
| 185 | // BrowserCommandController, public: |
| 186 | |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 187 | BrowserCommandController::BrowserCommandController(Browser* browser) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 188 | : browser_(browser), |
[email protected] | d4b2d23 | 2013-04-30 21:14:23 | [diff] [blame] | 189 | command_updater_(this), |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 190 | block_command_execution_(false), |
| 191 | last_blocked_command_id_(-1), |
| 192 | last_blocked_command_disposition_(CURRENT_TAB) { |
| 193 | browser_->tab_strip_model()->AddObserver(this); |
| 194 | PrefService* local_state = g_browser_process->local_state(); |
| 195 | if (local_state) { |
| 196 | local_pref_registrar_.Init(local_state); |
[email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 197 | local_pref_registrar_.Add( |
| 198 | prefs::kAllowFileSelectionDialogs, |
| 199 | base::Bind( |
| 200 | &BrowserCommandController::UpdateCommandsForFileSelectionDialogs, |
| 201 | base::Unretained(this))); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | profile_pref_registrar_.Init(profile()->GetPrefs()); |
[email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 205 | profile_pref_registrar_.Add( |
| 206 | prefs::kDevToolsDisabled, |
| 207 | base::Bind(&BrowserCommandController::UpdateCommandsForDevTools, |
| 208 | base::Unretained(this))); |
| 209 | profile_pref_registrar_.Add( |
tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 210 | bookmarks::prefs::kEditBookmarksEnabled, |
[email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 211 | base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing, |
| 212 | base::Unretained(this))); |
| 213 | profile_pref_registrar_.Add( |
tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 214 | bookmarks::prefs::kShowBookmarkBar, |
[email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 215 | base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar, |
| 216 | base::Unretained(this))); |
| 217 | profile_pref_registrar_.Add( |
| 218 | prefs::kIncognitoModeAvailability, |
| 219 | base::Bind( |
| 220 | &BrowserCommandController::UpdateCommandsForIncognitoAvailability, |
| 221 | base::Unretained(this))); |
| 222 | profile_pref_registrar_.Add( |
| 223 | prefs::kPrintingEnabled, |
| 224 | base::Bind(&BrowserCommandController::UpdatePrintingState, |
| 225 | base::Unretained(this))); |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 226 | #if !defined(OS_MACOSX) |
| 227 | profile_pref_registrar_.Add( |
| 228 | prefs::kFullscreenAllowed, |
| 229 | base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode, |
| 230 | base::Unretained(this))); |
| 231 | #endif |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 232 | pref_signin_allowed_.Init( |
| 233 | prefs::kSigninAllowed, |
| 234 | profile()->GetOriginalProfile()->GetPrefs(), |
| 235 | base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange, |
| 236 | base::Unretained(this))); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 237 | |
| 238 | InitCommandState(); |
| 239 | |
| 240 | TabRestoreService* tab_restore_service = |
| 241 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 242 | if (tab_restore_service) { |
| 243 | tab_restore_service->AddObserver(this); |
| 244 | TabRestoreServiceChanged(tab_restore_service); |
| 245 | } |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | BrowserCommandController::~BrowserCommandController() { |
[email protected] | 95e3947 | 2012-10-05 23:37:36 | [diff] [blame] | 249 | // TabRestoreService may have been shutdown by the time we get here. Don't |
| 250 | // trigger creating it. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 251 | TabRestoreService* tab_restore_service = |
[email protected] | 95e3947 | 2012-10-05 23:37:36 | [diff] [blame] | 252 | TabRestoreServiceFactory::GetForProfileIfExisting(profile()); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 253 | if (tab_restore_service) |
| 254 | tab_restore_service->RemoveObserver(this); |
| 255 | profile_pref_registrar_.RemoveAll(); |
| 256 | local_pref_registrar_.RemoveAll(); |
| 257 | browser_->tab_strip_model()->RemoveObserver(this); |
| 258 | } |
| 259 | |
| 260 | bool BrowserCommandController::IsReservedCommandOrKey( |
| 261 | int command_id, |
| 262 | const content::NativeWebKeyboardEvent& event) { |
| 263 | // In Apps mode, no keys are reserved. |
| 264 | if (browser_->is_app()) |
| 265 | return false; |
| 266 | |
| 267 | #if defined(OS_CHROMEOS) |
[email protected] | 397abd3 | 2013-08-21 05:44:19 | [diff] [blame] | 268 | // On Chrome OS, the top row of keys are mapped to browser actions like |
| 269 | // back/forward or refresh. We don't want web pages to be able to change the |
| 270 | // behavior of these keys. Ash handles F4 and up; this leaves us needing to |
| 271 | // reserve browser back/forward and refresh here. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 272 | ui::KeyboardCode key_code = |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 273 | static_cast<ui::KeyboardCode>(event.windowsKeyCode); |
[email protected] | 397abd3 | 2013-08-21 05:44:19 | [diff] [blame] | 274 | if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) || |
| 275 | (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) || |
| 276 | (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 277 | return true; |
| 278 | } |
| 279 | #endif |
| 280 | |
| 281 | if (window()->IsFullscreen() && command_id == IDC_FULLSCREEN) |
| 282 | return true; |
[email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 283 | |
[email protected] | 893124a2 | 2014-04-15 00:45:28 | [diff] [blame] | 284 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
[email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 285 | // If this key was registered by the user as a content editing hotkey, then |
| 286 | // it is not reserved. |
[email protected] | d5bedb6d | 2014-04-08 10:49:32 | [diff] [blame] | 287 | ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
[email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 288 | ui::GetTextEditKeyBindingsDelegate(); |
[email protected] | 47e8e754 | 2014-04-03 07:52:42 | [diff] [blame] | 289 | if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL)) |
[email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 290 | return false; |
| 291 | #endif |
| 292 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 293 | return command_id == IDC_CLOSE_TAB || |
| 294 | command_id == IDC_CLOSE_WINDOW || |
| 295 | command_id == IDC_NEW_INCOGNITO_WINDOW || |
| 296 | command_id == IDC_NEW_TAB || |
| 297 | command_id == IDC_NEW_WINDOW || |
| 298 | command_id == IDC_RESTORE_TAB || |
| 299 | command_id == IDC_SELECT_NEXT_TAB || |
| 300 | command_id == IDC_SELECT_PREVIOUS_TAB || |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 301 | command_id == IDC_EXIT; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void BrowserCommandController::SetBlockCommandExecution(bool block) { |
| 305 | block_command_execution_ = block; |
| 306 | if (block) { |
| 307 | last_blocked_command_id_ = -1; |
| 308 | last_blocked_command_disposition_ = CURRENT_TAB; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | int BrowserCommandController::GetLastBlockedCommand( |
| 313 | WindowOpenDisposition* disposition) { |
| 314 | if (disposition) |
| 315 | *disposition = last_blocked_command_disposition_; |
| 316 | return last_blocked_command_id_; |
| 317 | } |
| 318 | |
| 319 | void BrowserCommandController::TabStateChanged() { |
| 320 | UpdateCommandsForTabState(); |
| 321 | } |
| 322 | |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 323 | void BrowserCommandController::ZoomStateChanged() { |
| 324 | UpdateCommandsForZoomState(); |
| 325 | } |
| 326 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 327 | void BrowserCommandController::ContentRestrictionsChanged() { |
| 328 | UpdateCommandsForContentRestrictionState(); |
| 329 | } |
| 330 | |
| 331 | void BrowserCommandController::FullscreenStateChanged() { |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 332 | UpdateCommandsForFullscreenMode(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | void BrowserCommandController::PrintingStateChanged() { |
| 336 | UpdatePrintingState(); |
| 337 | } |
| 338 | |
| 339 | void BrowserCommandController::LoadingStateChanged(bool is_loading, |
| 340 | bool force) { |
| 341 | UpdateReloadStopState(is_loading, force); |
| 342 | } |
| 343 | |
wittman | 76df71db3 | 2014-12-18 23:26:58 | [diff] [blame] | 344 | void BrowserCommandController::ExtensionStateChanged() { |
| 345 | // Extensions may disable the bookmark editing commands. |
| 346 | UpdateCommandsForBookmarkEditing(); |
| 347 | } |
| 348 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 349 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | de0d0f4 | 2012-12-06 21:27:11 | [diff] [blame] | 350 | // BrowserCommandController, CommandUpdaterDelegate implementation: |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 351 | |
| 352 | void BrowserCommandController::ExecuteCommandWithDisposition( |
[email protected] | de0d0f4 | 2012-12-06 21:27:11 | [diff] [blame] | 353 | int id, |
| 354 | WindowOpenDisposition disposition) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 355 | // No commands are enabled if there is not yet any selected tab. |
| 356 | // TODO(pkasting): It seems like we should not need this, because either |
| 357 | // most/all commands should not have been enabled yet anyway or the ones that |
| 358 | // are enabled should be global, or safe themselves against having no selected |
| 359 | // tab. However, Ben says he tried removing this before and got lots of |
| 360 | // crashes, e.g. from Windows sending WM_COMMANDs at random times during |
| 361 | // window construction. This probably could use closer examination someday. |
[email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 362 | if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 363 | return; |
| 364 | |
| 365 | DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " |
| 366 | << id; |
| 367 | |
| 368 | // If command execution is blocked then just record the command and return. |
| 369 | if (block_command_execution_) { |
| 370 | // We actually only allow no more than one blocked command, otherwise some |
| 371 | // commands maybe lost. |
| 372 | DCHECK_EQ(last_blocked_command_id_, -1); |
| 373 | last_blocked_command_id_ = id; |
| 374 | last_blocked_command_disposition_ = disposition; |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | // The order of commands in this switch statement must match the function |
| 379 | // declaration order in browser.h! |
| 380 | switch (id) { |
| 381 | // Navigation commands |
| 382 | case IDC_BACK: |
| 383 | GoBack(browser_, disposition); |
| 384 | break; |
| 385 | case IDC_FORWARD: |
| 386 | GoForward(browser_, disposition); |
| 387 | break; |
| 388 | case IDC_RELOAD: |
| 389 | Reload(browser_, disposition); |
| 390 | break; |
[email protected] | 58e2903 | 2012-08-06 20:19:57 | [diff] [blame] | 391 | case IDC_RELOAD_CLEARING_CACHE: |
| 392 | ClearCache(browser_); |
| 393 | // FALL THROUGH |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 394 | case IDC_RELOAD_IGNORING_CACHE: |
| 395 | ReloadIgnoringCache(browser_, disposition); |
| 396 | break; |
| 397 | case IDC_HOME: |
| 398 | Home(browser_, disposition); |
| 399 | break; |
| 400 | case IDC_OPEN_CURRENT_URL: |
| 401 | OpenCurrentURL(browser_); |
| 402 | break; |
| 403 | case IDC_STOP: |
| 404 | Stop(browser_); |
| 405 | break; |
| 406 | |
| 407 | // Window management commands |
| 408 | case IDC_NEW_WINDOW: |
| 409 | NewWindow(browser_); |
| 410 | break; |
| 411 | case IDC_NEW_INCOGNITO_WINDOW: |
| 412 | NewIncognitoWindow(browser_); |
| 413 | break; |
| 414 | case IDC_CLOSE_WINDOW: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 415 | content::RecordAction(base::UserMetricsAction("CloseWindowByKey")); |
[email protected] | 04b9e69 | 2012-08-24 14:49:09 | [diff] [blame] | 416 | CloseWindow(browser_); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 417 | break; |
| 418 | case IDC_NEW_TAB: |
| 419 | NewTab(browser_); |
| 420 | break; |
| 421 | case IDC_CLOSE_TAB: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 422 | content::RecordAction(base::UserMetricsAction("CloseTabByKey")); |
[email protected] | 04b9e69 | 2012-08-24 14:49:09 | [diff] [blame] | 423 | CloseTab(browser_); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 424 | break; |
| 425 | case IDC_SELECT_NEXT_TAB: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 426 | content::RecordAction(base::UserMetricsAction("Accel_SelectNextTab")); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 427 | SelectNextTab(browser_); |
| 428 | break; |
| 429 | case IDC_SELECT_PREVIOUS_TAB: |
[email protected] | 0db969d | 2013-05-30 18:26:16 | [diff] [blame] | 430 | content::RecordAction( |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 431 | base::UserMetricsAction("Accel_SelectPreviousTab")); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 432 | SelectPreviousTab(browser_); |
| 433 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 434 | case IDC_MOVE_TAB_NEXT: |
| 435 | MoveTabNext(browser_); |
| 436 | break; |
| 437 | case IDC_MOVE_TAB_PREVIOUS: |
| 438 | MoveTabPrevious(browser_); |
| 439 | break; |
| 440 | case IDC_SELECT_TAB_0: |
| 441 | case IDC_SELECT_TAB_1: |
| 442 | case IDC_SELECT_TAB_2: |
| 443 | case IDC_SELECT_TAB_3: |
| 444 | case IDC_SELECT_TAB_4: |
| 445 | case IDC_SELECT_TAB_5: |
| 446 | case IDC_SELECT_TAB_6: |
| 447 | case IDC_SELECT_TAB_7: |
| 448 | SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0); |
| 449 | break; |
| 450 | case IDC_SELECT_LAST_TAB: |
| 451 | SelectLastTab(browser_); |
| 452 | break; |
| 453 | case IDC_DUPLICATE_TAB: |
| 454 | DuplicateTab(browser_); |
| 455 | break; |
| 456 | case IDC_RESTORE_TAB: |
| 457 | RestoreTab(browser_); |
| 458 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 459 | case IDC_SHOW_AS_TAB: |
| 460 | ConvertPopupToTabbedBrowser(browser_); |
| 461 | break; |
| 462 | case IDC_FULLSCREEN: |
[email protected] | 9c4d6833 | 2013-01-30 13:34:41 | [diff] [blame] | 463 | #if defined(OS_MACOSX) |
andresantoso | b575385 | 2014-11-21 23:07:56 | [diff] [blame] | 464 | chrome::ToggleFullscreenWithToolbarOrFallback(browser_); |
[email protected] | 9c4d6833 | 2013-01-30 13:34:41 | [diff] [blame] | 465 | #else |
[email protected] | 3f32b9b | 2012-07-09 16:59:28 | [diff] [blame] | 466 | chrome::ToggleFullscreenMode(browser_); |
[email protected] | 9c4d6833 | 2013-01-30 13:34:41 | [diff] [blame] | 467 | #endif |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 468 | break; |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 469 | |
[email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 470 | #if defined(OS_CHROMEOS) |
| 471 | case IDC_VISIT_DESKTOP_OF_LRU_USER_2: |
[email protected] | 0c93081 | 2014-01-30 18:01:47 | [diff] [blame] | 472 | case IDC_VISIT_DESKTOP_OF_LRU_USER_3: |
| 473 | ExecuteVisitDesktopCommand(id, browser_->window()->GetNativeWindow()); |
| 474 | break; |
[email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 475 | #endif |
| 476 | |
[email protected] | 893124a2 | 2014-04-15 00:45:28 | [diff] [blame] | 477 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
[email protected] | af97be4c6 | 2014-02-13 14:43:34 | [diff] [blame] | 478 | case IDC_USE_SYSTEM_TITLE_BAR: { |
| 479 | PrefService* prefs = browser_->profile()->GetPrefs(); |
| 480 | prefs->SetBoolean(prefs::kUseCustomChromeFrame, |
| 481 | !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); |
| 482 | break; |
| 483 | } |
| 484 | #endif |
| 485 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 486 | #if defined(OS_WIN) |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 487 | // Windows 8 specific commands. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 488 | case IDC_METRO_SNAP_ENABLE: |
| 489 | browser_->SetMetroSnapMode(true); |
| 490 | break; |
| 491 | case IDC_METRO_SNAP_DISABLE: |
| 492 | browser_->SetMetroSnapMode(false); |
| 493 | break; |
ananta | 196db19 | 2014-08-28 21:37:55 | [diff] [blame] | 494 | case IDC_WIN_DESKTOP_RESTART: |
| 495 | if (!VerifyASHSwitchForApps(window()->GetNativeWindow(), id)) |
[email protected] | 396de687 | 2013-11-08 08:50:37 | [diff] [blame] | 496 | break; |
| 497 | |
[email protected] | d51373d | 2013-10-31 15:22:00 | [diff] [blame] | 498 | chrome::AttemptRestartToDesktopMode(); |
ananta | 196db19 | 2014-08-28 21:37:55 | [diff] [blame] | 499 | if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 500 | content::RecordAction(base::UserMetricsAction("Win8DesktopRestart")); |
| 501 | } else { |
| 502 | content::RecordAction(base::UserMetricsAction("Win7DesktopRestart")); |
| 503 | } |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 504 | break; |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 505 | case IDC_WIN8_METRO_RESTART: |
ananta | 196db19 | 2014-08-28 21:37:55 | [diff] [blame] | 506 | case IDC_WIN_CHROMEOS_RESTART: |
| 507 | if (!VerifyASHSwitchForApps(window()->GetNativeWindow(), id)) |
[email protected] | 24ced7dc0 | 2013-04-04 08:32:39 | [diff] [blame] | 508 | break; |
ananta | 196db19 | 2014-08-28 21:37:55 | [diff] [blame] | 509 | if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 510 | // SwitchToMetroUIHandler deletes itself. |
| 511 | new SwitchToMetroUIHandler; |
| 512 | content::RecordAction(base::UserMetricsAction("Win8MetroRestart")); |
| 513 | } else { |
| 514 | content::RecordAction(base::UserMetricsAction("Win7ASHRestart")); |
| 515 | chrome::AttemptRestartToMetroMode(); |
| 516 | } |
[email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 517 | break; |
thestig | 5149d27 | 2014-10-30 07:25:29 | [diff] [blame] | 518 | case IDC_PIN_TO_START_SCREEN: |
| 519 | TogglePagePinnedToStartScreen(browser_); |
| 520 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 521 | #endif |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 522 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 523 | #if defined(OS_MACOSX) |
| 524 | case IDC_PRESENTATION_MODE: |
[email protected] | 9c4d6833 | 2013-01-30 13:34:41 | [diff] [blame] | 525 | chrome::ToggleFullscreenMode(browser_); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 526 | break; |
| 527 | #endif |
| 528 | case IDC_EXIT: |
| 529 | Exit(); |
| 530 | break; |
| 531 | |
| 532 | // Page-related commands |
| 533 | case IDC_SAVE_PAGE: |
| 534 | SavePage(browser_); |
| 535 | break; |
| 536 | case IDC_BOOKMARK_PAGE: |
deepak.m1 | 54a7f39 | 2014-12-15 04:41:43 | [diff] [blame] | 537 | BookmarkCurrentPageAllowingExtensionOverrides(browser_); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 538 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 539 | case IDC_BOOKMARK_ALL_TABS: |
| 540 | BookmarkAllTabs(browser_); |
| 541 | break; |
| 542 | case IDC_VIEW_SOURCE: |
| 543 | ViewSelectedSource(browser_); |
| 544 | break; |
| 545 | case IDC_EMAIL_PAGE_LOCATION: |
| 546 | EmailPageLocation(browser_); |
| 547 | break; |
| 548 | case IDC_PRINT: |
| 549 | Print(browser_); |
| 550 | break; |
vitalybuka | e29991c | 2014-11-05 21:15:12 | [diff] [blame] | 551 | #if defined(ENABLE_BASIC_PRINTING) |
vitalybuka | f9433e4 | 2014-09-08 10:04:55 | [diff] [blame] | 552 | case IDC_BASIC_PRINT: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 553 | content::RecordAction(base::UserMetricsAction("Accel_Advanced_Print")); |
vitalybuka | f9433e4 | 2014-09-08 10:04:55 | [diff] [blame] | 554 | BasicPrint(browser_); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 555 | break; |
vitalybuka | e29991c | 2014-11-05 21:15:12 | [diff] [blame] | 556 | #endif // ENABLE_BASIC_PRINTING |
[email protected] | e625b760 | 2013-10-28 09:24:56 | [diff] [blame] | 557 | case IDC_TRANSLATE_PAGE: |
| 558 | Translate(browser_); |
| 559 | break; |
[email protected] | 4bee443 | 2014-05-05 13:11:41 | [diff] [blame] | 560 | case IDC_MANAGE_PASSWORDS_FOR_PAGE: |
| 561 | ManagePasswordsForPage(browser_); |
| 562 | break; |
| 563 | |
| 564 | // Page encoding commands |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 565 | case IDC_ENCODING_AUTO_DETECT: |
| 566 | browser_->ToggleEncodingAutoDetect(); |
| 567 | break; |
| 568 | case IDC_ENCODING_UTF8: |
| 569 | case IDC_ENCODING_UTF16LE: |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 570 | case IDC_ENCODING_WINDOWS1252: |
| 571 | case IDC_ENCODING_GBK: |
| 572 | case IDC_ENCODING_GB18030: |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 573 | case IDC_ENCODING_BIG5: |
| 574 | case IDC_ENCODING_KOREAN: |
| 575 | case IDC_ENCODING_SHIFTJIS: |
| 576 | case IDC_ENCODING_ISO2022JP: |
| 577 | case IDC_ENCODING_EUCJP: |
| 578 | case IDC_ENCODING_THAI: |
| 579 | case IDC_ENCODING_ISO885915: |
| 580 | case IDC_ENCODING_MACINTOSH: |
| 581 | case IDC_ENCODING_ISO88592: |
| 582 | case IDC_ENCODING_WINDOWS1250: |
| 583 | case IDC_ENCODING_ISO88595: |
| 584 | case IDC_ENCODING_WINDOWS1251: |
| 585 | case IDC_ENCODING_KOI8R: |
| 586 | case IDC_ENCODING_KOI8U: |
jshin | 03456dca | 2015-03-24 20:51:34 | [diff] [blame] | 587 | case IDC_ENCODING_IBM866: |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 588 | case IDC_ENCODING_ISO88597: |
| 589 | case IDC_ENCODING_WINDOWS1253: |
| 590 | case IDC_ENCODING_ISO88594: |
| 591 | case IDC_ENCODING_ISO885913: |
| 592 | case IDC_ENCODING_WINDOWS1257: |
| 593 | case IDC_ENCODING_ISO88593: |
| 594 | case IDC_ENCODING_ISO885910: |
| 595 | case IDC_ENCODING_ISO885914: |
| 596 | case IDC_ENCODING_ISO885916: |
| 597 | case IDC_ENCODING_WINDOWS1254: |
| 598 | case IDC_ENCODING_ISO88596: |
| 599 | case IDC_ENCODING_WINDOWS1256: |
| 600 | case IDC_ENCODING_ISO88598: |
| 601 | case IDC_ENCODING_ISO88598I: |
| 602 | case IDC_ENCODING_WINDOWS1255: |
| 603 | case IDC_ENCODING_WINDOWS1258: |
| 604 | browser_->OverrideEncoding(id); |
| 605 | break; |
| 606 | |
| 607 | // Clipboard commands |
| 608 | case IDC_CUT: |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 609 | case IDC_COPY: |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 610 | case IDC_PASTE: |
pkasting | cd3f08bce | 2015-04-18 13:37:12 | [diff] [blame] | 611 | CutCopyPaste(browser_, id); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 612 | break; |
| 613 | |
| 614 | // Find-in-page |
| 615 | case IDC_FIND: |
| 616 | Find(browser_); |
| 617 | break; |
| 618 | case IDC_FIND_NEXT: |
| 619 | FindNext(browser_); |
| 620 | break; |
| 621 | case IDC_FIND_PREVIOUS: |
| 622 | FindPrevious(browser_); |
| 623 | break; |
| 624 | |
| 625 | // Zoom |
| 626 | case IDC_ZOOM_PLUS: |
| 627 | Zoom(browser_, content::PAGE_ZOOM_IN); |
| 628 | break; |
| 629 | case IDC_ZOOM_NORMAL: |
| 630 | Zoom(browser_, content::PAGE_ZOOM_RESET); |
| 631 | break; |
| 632 | case IDC_ZOOM_MINUS: |
| 633 | Zoom(browser_, content::PAGE_ZOOM_OUT); |
| 634 | break; |
| 635 | |
| 636 | // Focus various bits of UI |
| 637 | case IDC_FOCUS_TOOLBAR: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 638 | content::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar")); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 639 | FocusToolbar(browser_); |
| 640 | break; |
| 641 | case IDC_FOCUS_LOCATION: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 642 | content::RecordAction(base::UserMetricsAction("Accel_Focus_Location")); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 643 | FocusLocationBar(browser_); |
| 644 | break; |
| 645 | case IDC_FOCUS_SEARCH: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 646 | content::RecordAction(base::UserMetricsAction("Accel_Focus_Search")); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 647 | FocusSearch(browser_); |
| 648 | break; |
| 649 | case IDC_FOCUS_MENU_BAR: |
| 650 | FocusAppMenu(browser_); |
| 651 | break; |
| 652 | case IDC_FOCUS_BOOKMARKS: |
[email protected] | 9fbc190 | 2013-12-06 01:49:45 | [diff] [blame] | 653 | content::RecordAction( |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 654 | base::UserMetricsAction("Accel_Focus_Bookmarks")); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 655 | FocusBookmarksToolbar(browser_); |
| 656 | break; |
[email protected] | 822ca8c6 | 2013-04-19 00:49:15 | [diff] [blame] | 657 | case IDC_FOCUS_INFOBARS: |
| 658 | FocusInfobars(browser_); |
| 659 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 660 | case IDC_FOCUS_NEXT_PANE: |
| 661 | FocusNextPane(browser_); |
| 662 | break; |
| 663 | case IDC_FOCUS_PREVIOUS_PANE: |
| 664 | FocusPreviousPane(browser_); |
| 665 | break; |
| 666 | |
| 667 | // Show various bits of UI |
| 668 | case IDC_OPEN_FILE: |
| 669 | browser_->OpenFile(); |
| 670 | break; |
| 671 | case IDC_CREATE_SHORTCUTS: |
[email protected] | 619f8618 | 2012-07-03 21:30:18 | [diff] [blame] | 672 | CreateApplicationShortcuts(browser_); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 673 | break; |
[email protected] | 488e395 | 2013-11-18 05:29:14 | [diff] [blame] | 674 | case IDC_CREATE_HOSTED_APP: |
[email protected] | 9208654 | 2014-04-08 08:45:29 | [diff] [blame] | 675 | CreateBookmarkAppFromCurrentWebContents(browser_); |
[email protected] | 488e395 | 2013-11-18 05:29:14 | [diff] [blame] | 676 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 677 | case IDC_DEV_TOOLS: |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 678 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show()); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 679 | break; |
| 680 | case IDC_DEV_TOOLS_CONSOLE: |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 681 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsole()); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 682 | break; |
[email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 683 | case IDC_DEV_TOOLS_DEVICES: |
| 684 | InspectUI::InspectDevices(browser_); |
| 685 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 686 | case IDC_DEV_TOOLS_INSPECT: |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 687 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect()); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 688 | break; |
[email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 689 | case IDC_DEV_TOOLS_TOGGLE: |
[email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 690 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle()); |
[email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 691 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 692 | case IDC_TASK_MANAGER: |
[email protected] | 29c262de | 2013-06-22 15:39:38 | [diff] [blame] | 693 | OpenTaskManager(browser_); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 694 | break; |
caelyn | 4e4e08a | 2015-02-04 21:27:49 | [diff] [blame] | 695 | #if defined(OS_CHROMEOS) |
| 696 | case IDC_TAKE_SCREENSHOT: |
| 697 | TakeScreenshot(); |
| 698 | break; |
| 699 | #endif |
[email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 700 | #if defined(GOOGLE_CHROME_BUILD) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 701 | case IDC_FEEDBACK: |
| 702 | OpenFeedbackDialog(browser_); |
| 703 | break; |
[email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 704 | #endif |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 705 | case IDC_SHOW_BOOKMARK_BAR: |
| 706 | ToggleBookmarkBar(browser_); |
| 707 | break; |
| 708 | case IDC_PROFILING_ENABLED: |
| 709 | Profiling::Toggle(); |
| 710 | break; |
| 711 | |
| 712 | case IDC_SHOW_BOOKMARK_MANAGER: |
| 713 | ShowBookmarkManager(browser_); |
| 714 | break; |
| 715 | case IDC_SHOW_APP_MENU: |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 716 | content::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu")); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 717 | ShowAppMenu(browser_); |
| 718 | break; |
| 719 | case IDC_SHOW_AVATAR_MENU: |
| 720 | ShowAvatarMenu(browser_); |
| 721 | break; |
anthonyvd | 7dc985da | 2015-03-23 16:53:19 | [diff] [blame] | 722 | case IDC_SHOW_FAST_USER_SWITCHER: |
| 723 | ShowFastUserSwitcher(browser_); |
| 724 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 725 | case IDC_SHOW_HISTORY: |
| 726 | ShowHistory(browser_); |
| 727 | break; |
| 728 | case IDC_SHOW_DOWNLOADS: |
| 729 | ShowDownloads(browser_); |
| 730 | break; |
| 731 | case IDC_MANAGE_EXTENSIONS: |
[email protected] | bc9833c3 | 2013-02-28 04:05:08 | [diff] [blame] | 732 | ShowExtensions(browser_, std::string()); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 733 | break; |
| 734 | case IDC_OPTIONS: |
| 735 | ShowSettings(browser_); |
| 736 | break; |
| 737 | case IDC_EDIT_SEARCH_ENGINES: |
| 738 | ShowSearchEngineSettings(browser_); |
| 739 | break; |
| 740 | case IDC_VIEW_PASSWORDS: |
| 741 | ShowPasswordManager(browser_); |
| 742 | break; |
| 743 | case IDC_CLEAR_BROWSING_DATA: |
| 744 | ShowClearBrowsingDataDialog(browser_); |
| 745 | break; |
| 746 | case IDC_IMPORT_SETTINGS: |
| 747 | ShowImportDialog(browser_); |
| 748 | break; |
[email protected] | 9b7ab88 | 2012-09-10 23:46:36 | [diff] [blame] | 749 | case IDC_TOGGLE_REQUEST_TABLET_SITE: |
| 750 | ToggleRequestTabletSite(browser_); |
| 751 | break; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 752 | case IDC_ABOUT: |
| 753 | ShowAboutChrome(browser_); |
| 754 | break; |
| 755 | case IDC_UPGRADE_DIALOG: |
| 756 | OpenUpdateChromeDialog(browser_); |
| 757 | break; |
| 758 | case IDC_VIEW_INCOMPATIBILITIES: |
| 759 | ShowConflicts(browser_); |
| 760 | break; |
| 761 | case IDC_HELP_PAGE_VIA_KEYBOARD: |
| 762 | ShowHelp(browser_, HELP_SOURCE_KEYBOARD); |
| 763 | break; |
| 764 | case IDC_HELP_PAGE_VIA_MENU: |
| 765 | ShowHelp(browser_, HELP_SOURCE_MENU); |
| 766 | break; |
[email protected] | 08fafe4 | 2013-02-03 08:10:49 | [diff] [blame] | 767 | case IDC_SHOW_SIGNIN: |
rockot | b2fdf0b | 2015-01-23 03:42:35 | [diff] [blame] | 768 | ShowBrowserSigninOrSettings(browser_, signin_metrics::SOURCE_MENU); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 769 | break; |
| 770 | case IDC_TOGGLE_SPEECH_INPUT: |
| 771 | ToggleSpeechInput(browser_); |
| 772 | break; |
[email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 773 | case IDC_DISTILL_PAGE: |
| 774 | DistillCurrentPage(browser_); |
| 775 | break; |
kpschoedel | f8e9274e | 2014-10-07 18:32:41 | [diff] [blame] | 776 | #if defined(OS_CHROMEOS) |
| 777 | case IDC_TOUCH_HUD_PROJECTION_TOGGLE: |
| 778 | ash::accelerators::ToggleTouchHudProjection(); |
| 779 | break; |
| 780 | #endif |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 781 | |
| 782 | default: |
| 783 | LOG(WARNING) << "Received Unimplemented Command: " << id; |
| 784 | break; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 789 | // BrowserCommandController, SigninPrefObserver implementation: |
| 790 | |
| 791 | void BrowserCommandController::OnSigninAllowedPrefChange() { |
| 792 | // For unit tests, we don't have a window. |
| 793 | if (!window()) |
| 794 | return; |
| 795 | UpdateShowSyncState(IsShowingMainUI()); |
| 796 | } |
| 797 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 798 | // BrowserCommandController, TabStripModelObserver implementation: |
| 799 | |
[email protected] | 409ea297 | 2012-11-10 19:54:43 | [diff] [blame] | 800 | void BrowserCommandController::TabInsertedAt(WebContents* contents, |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 801 | int index, |
| 802 | bool foreground) { |
| 803 | AddInterstitialObservers(contents); |
| 804 | } |
| 805 | |
[email protected] | e89cfcb | 2012-11-11 14:47:24 | [diff] [blame] | 806 | void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 807 | RemoveInterstitialObservers(contents); |
| 808 | } |
| 809 | |
| 810 | void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model, |
[email protected] | b624ddc | 2012-11-15 18:04:13 | [diff] [blame] | 811 | WebContents* old_contents, |
| 812 | WebContents* new_contents, |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 813 | int index) { |
[email protected] | b624ddc | 2012-11-15 18:04:13 | [diff] [blame] | 814 | RemoveInterstitialObservers(old_contents); |
| 815 | AddInterstitialObservers(new_contents); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 816 | } |
| 817 | |
[email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 818 | void BrowserCommandController::TabBlockedStateChanged( |
| 819 | content::WebContents* contents, |
| 820 | int index) { |
| 821 | PrintingStateChanged(); |
| 822 | FullscreenStateChanged(); |
| 823 | UpdateCommandsForFind(); |
| 824 | } |
| 825 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 826 | //////////////////////////////////////////////////////////////////////////////// |
| 827 | // BrowserCommandController, TabRestoreServiceObserver implementation: |
| 828 | |
| 829 | void BrowserCommandController::TabRestoreServiceChanged( |
| 830 | TabRestoreService* service) { |
[email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 831 | UpdateTabRestoreCommandState(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | void BrowserCommandController::TabRestoreServiceDestroyed( |
| 835 | TabRestoreService* service) { |
| 836 | service->RemoveObserver(this); |
| 837 | } |
| 838 | |
[email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 839 | void BrowserCommandController::TabRestoreServiceLoaded( |
| 840 | TabRestoreService* service) { |
| 841 | UpdateTabRestoreCommandState(); |
| 842 | } |
| 843 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 844 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 845 | // BrowserCommandController, private: |
| 846 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 847 | class BrowserCommandController::InterstitialObserver |
| 848 | : public content::WebContentsObserver { |
| 849 | public: |
| 850 | InterstitialObserver(BrowserCommandController* controller, |
| 851 | content::WebContents* web_contents) |
| 852 | : WebContentsObserver(web_contents), |
| 853 | controller_(controller) { |
| 854 | } |
| 855 | |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 856 | void DidAttachInterstitialPage() override { |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 857 | controller_->UpdateCommandsForTabState(); |
| 858 | } |
| 859 | |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 860 | void DidDetachInterstitialPage() override { |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 861 | controller_->UpdateCommandsForTabState(); |
| 862 | } |
| 863 | |
| 864 | private: |
| 865 | BrowserCommandController* controller_; |
| 866 | |
| 867 | DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); |
| 868 | }; |
| 869 | |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 870 | bool BrowserCommandController::IsShowingMainUI() { |
| 871 | bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen(); |
| 872 | return browser_->is_type_tabbed() && !should_hide_ui; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | void BrowserCommandController::InitCommandState() { |
| 876 | // All browser commands whose state isn't set automagically some other way |
| 877 | // (like Back & Forward with initial page load) must have their state |
| 878 | // initialized here, otherwise they will be forever disabled. |
| 879 | |
| 880 | // Navigation commands |
| 881 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
| 882 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); |
[email protected] | 58e2903 | 2012-08-06 20:19:57 | [diff] [blame] | 883 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 884 | |
| 885 | // Window management commands |
| 886 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 887 | command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); |
| 888 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); |
| 889 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); |
[email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 890 | UpdateTabRestoreCommandState(); |
[email protected] | 6ed406c | 2013-03-12 17:57:11 | [diff] [blame] | 891 | #if defined(OS_WIN) && defined(USE_ASH) |
| 892 | if (browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) |
| 893 | command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
| 894 | #else |
[email protected] | d28d378 | 2013-02-26 16:31:55 | [diff] [blame] | 895 | command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
[email protected] | 6ed406c | 2013-03-12 17:57:11 | [diff] [blame] | 896 | #endif |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 897 | command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); |
[email protected] | fa941276 | 2013-09-04 23:31:33 | [diff] [blame] | 898 | #if defined(USE_ASH) |
| 899 | command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true); |
| 900 | #endif |
[email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 901 | #if defined(OS_CHROMEOS) |
| 902 | command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true); |
| 903 | command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true); |
| 904 | #endif |
[email protected] | 893124a2 | 2014-04-15 00:45:28 | [diff] [blame] | 905 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
[email protected] | af97be4c6 | 2014-02-13 14:43:34 | [diff] [blame] | 906 | command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true); |
| 907 | #endif |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 908 | |
| 909 | // Page-related commands |
| 910 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); |
[email protected] | 4bee443 | 2014-05-05 13:11:41 | [diff] [blame] | 911 | command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 912 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true); |
| 913 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true); |
| 914 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 915 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true); |
| 916 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true); |
| 917 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 918 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5, true); |
| 919 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_THAI, true); |
| 920 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOREAN, true); |
| 921 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS, true); |
| 922 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP, true); |
| 923 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_EUCJP, true); |
| 924 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885915, true); |
| 925 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH, true); |
| 926 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88592, true); |
| 927 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250, true); |
| 928 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88595, true); |
| 929 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251, true); |
| 930 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8R, true); |
| 931 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8U, true); |
jshin | 03456dca | 2015-03-24 20:51:34 | [diff] [blame] | 932 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_IBM866, true); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 933 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88597, true); |
| 934 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253, true); |
| 935 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88594, true); |
| 936 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885913, true); |
| 937 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257, true); |
| 938 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88593, true); |
| 939 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885910, true); |
| 940 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885914, true); |
| 941 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885916, true); |
| 942 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254, true); |
| 943 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88596, true); |
| 944 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true); |
| 945 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true); |
| 946 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true); |
| 947 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true); |
| 948 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true); |
| 949 | |
| 950 | // Zoom |
| 951 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
| 952 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 953 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 954 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
| 955 | |
| 956 | // Show various bits of UI |
mlerman | 7831f57d | 2015-05-25 11:40:15 | [diff] [blame] | 957 | const bool guest_session = profile()->IsGuestSession() || |
| 958 | profile()->IsSystemProfile(); |
| 959 | DCHECK(!profile()->IsSystemProfile()) |
| 960 | << "Ought to never have browser for the system profile."; |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 961 | const bool normal_window = browser_->is_type_tabbed(); |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 962 | UpdateOpenFileState(&command_updater_); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 963 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false); |
| 964 | UpdateCommandsForDevTools(); |
| 965 | command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 966 | command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 967 | command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
[email protected] | 674b6567 | 2014-06-02 23:21:56 | [diff] [blame] | 968 | command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 969 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
| 970 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 971 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session); |
[email protected] | 2f1acc21 | 2012-11-13 10:43:51 | [diff] [blame] | 972 | command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 973 | !guest_session && |
[email protected] | 2f1acc21 | 2012-11-13 10:43:51 | [diff] [blame] | 974 | !profile()->IsOffTheRecord()); |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 975 | command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window); |
[email protected] | 39d4759 | 2014-01-10 21:42:45 | [diff] [blame] | 976 | #if defined(OS_CHROMEOS) |
caelyn | 4e4e08a | 2015-02-04 21:27:49 | [diff] [blame] | 977 | command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true); |
kpschoedel | f8e9274e | 2014-10-07 18:32:41 | [diff] [blame] | 978 | command_updater_.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE, true); |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 979 | #else |
| 980 | // Chrome OS uses the system tray menu to handle multi-profiles. |
anthonyvd | 7dc985da | 2015-03-23 16:53:19 | [diff] [blame] | 981 | if (normal_window && (guest_session || !profile()->IsOffTheRecord())) { |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 982 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true); |
anthonyvd | 7dc985da | 2015-03-23 16:53:19 | [diff] [blame] | 983 | command_updater_.UpdateCommandEnabled(IDC_SHOW_FAST_USER_SWITCHER, true); |
| 984 | } |
[email protected] | 39d4759 | 2014-01-10 21:42:45 | [diff] [blame] | 985 | #endif |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 986 | |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 987 | UpdateShowSyncState(true); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 988 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 989 | // Navigation commands |
[email protected] | c9f983d | 2014-02-05 09:00:24 | [diff] [blame] | 990 | command_updater_.UpdateCommandEnabled( |
| 991 | IDC_HOME, |
benwells | c431c0ae | 2015-01-27 22:04:06 | [diff] [blame] | 992 | normal_window || |
| 993 | (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app())); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 994 | |
| 995 | // Window management commands |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 996 | command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 997 | command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| 998 | normal_window); |
| 999 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); |
| 1000 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); |
| 1001 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); |
| 1002 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); |
| 1003 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); |
| 1004 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); |
| 1005 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); |
| 1006 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); |
| 1007 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); |
| 1008 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); |
| 1009 | command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); |
| 1010 | #if defined(OS_WIN) |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 1011 | bool metro = browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH; |
| 1012 | command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro); |
| 1013 | command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro); |
ananta | 196db19 | 2014-08-28 21:37:55 | [diff] [blame] | 1014 | int restart_mode = metro ? IDC_WIN_DESKTOP_RESTART : |
| 1015 | (base::win::GetVersion() >= base::win::VERSION_WIN8 ? |
| 1016 | IDC_WIN8_METRO_RESTART : IDC_WIN_CHROMEOS_RESTART); |
[email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 1017 | command_updater_.UpdateCommandEnabled(restart_mode, normal_window); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1018 | #endif |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1019 | |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 1020 | // These are always enabled; the menu determines their menu item visibility. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1021 | command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); |
| 1022 | command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true); |
| 1023 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1024 | // Toggle speech input |
| 1025 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true); |
| 1026 | |
[email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 1027 | // Distill current page. |
| 1028 | command_updater_.UpdateCommandEnabled( |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 1029 | IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1030 | switches::kEnableDomDistiller)); |
[email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 1031 | |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 1032 | // Initialize other commands whose state changes based on various conditions. |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1033 | UpdateCommandsForFullscreenMode(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1034 | UpdateCommandsForContentRestrictionState(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1035 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1036 | UpdateCommandsForIncognitoAvailability(); |
| 1037 | } |
| 1038 | |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1039 | // static |
| 1040 | void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( |
| 1041 | CommandUpdater* command_updater, |
| 1042 | Profile* profile) { |
mlerman | e01e6de | 2014-09-29 19:26:47 | [diff] [blame] | 1043 | const bool guest_session = profile->IsGuestSession(); |
| 1044 | // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession(). |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1045 | IncognitoModePrefs::Availability incognito_availability = |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1046 | IncognitoModePrefs::GetAvailability(profile->GetPrefs()); |
| 1047 | command_updater->UpdateCommandEnabled( |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1048 | IDC_NEW_WINDOW, |
| 1049 | incognito_availability != IncognitoModePrefs::FORCED); |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1050 | command_updater->UpdateCommandEnabled( |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1051 | IDC_NEW_INCOGNITO_WINDOW, |
mlerman | e01e6de | 2014-09-29 19:26:47 | [diff] [blame] | 1052 | incognito_availability != IncognitoModePrefs::DISABLED && !guest_session); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1053 | |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1054 | const bool forced_incognito = |
| 1055 | incognito_availability == IncognitoModePrefs::FORCED || |
| 1056 | guest_session; // Guest always runs in Incognito mode. |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1057 | command_updater->UpdateCommandEnabled( |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1058 | IDC_SHOW_BOOKMARK_MANAGER, |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1059 | browser_defaults::bookmarks_enabled && !forced_incognito); |
[email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 1060 | ExtensionService* extension_service = |
| 1061 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1062 | const bool enable_extensions = |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1063 | extension_service && extension_service->extensions_enabled(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1064 | |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1065 | // Bookmark manager and settings page/subpages are forced to open in normal |
| 1066 | // mode. For this reason we disable these commands when incognito is forced. |
| 1067 | command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
| 1068 | enable_extensions && !forced_incognito); |
| 1069 | |
| 1070 | command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito); |
| 1071 | command_updater->UpdateCommandEnabled(IDC_OPTIONS, |
| 1072 | !forced_incognito || guest_session); |
| 1073 | command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { |
| 1077 | UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); |
| 1078 | |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 1079 | if (!IsShowingMainUI()) { |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1080 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); |
| 1081 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); |
| 1082 | } |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | void BrowserCommandController::UpdateCommandsForTabState() { |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 1086 | WebContents* current_web_contents = |
| 1087 | browser_->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 1088 | if (!current_web_contents) // May be NULL during tab restore. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1089 | return; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1090 | |
| 1091 | // Navigation commands |
| 1092 | command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); |
| 1093 | command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_)); |
| 1094 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_)); |
| 1095 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, |
| 1096 | CanReload(browser_)); |
[email protected] | 58e2903 | 2012-08-06 20:19:57 | [diff] [blame] | 1097 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, |
| 1098 | CanReload(browser_)); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1099 | |
| 1100 | // Window management commands |
| 1101 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, |
| 1102 | !browser_->is_app() && CanDuplicateTab(browser_)); |
| 1103 | |
| 1104 | // Page-related commands |
| 1105 | window()->SetStarredState( |
[email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 1106 | BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred()); |
[email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 1107 | window()->ZoomChangedForActiveTab(false); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1108 | command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, |
| 1109 | CanViewSource(browser_)); |
| 1110 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, |
| 1111 | CanEmailPageLocation(browser_)); |
| 1112 | if (browser_->is_devtools()) |
| 1113 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); |
| 1114 | |
| 1115 | // Changing the encoding is not possible on Chrome-internal webpages. |
| 1116 | NavigationController& nc = current_web_contents->GetController(); |
[email protected] | 9717489 | 2014-06-03 09:06:12 | [diff] [blame] | 1117 | bool is_chrome_internal = HasInternalURL(nc.GetLastCommittedEntry()) || |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1118 | current_web_contents->ShowingInterstitialPage(); |
| 1119 | command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU, |
| 1120 | !is_chrome_internal && current_web_contents->IsSavable()); |
| 1121 | |
| 1122 | // Show various bits of UI |
| 1123 | // TODO(pinkerton): Disable app-mode in the model until we implement it |
| 1124 | // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148 |
| 1125 | #if !defined(OS_MACOSX) |
| 1126 | command_updater_.UpdateCommandEnabled( |
| 1127 | IDC_CREATE_SHORTCUTS, |
| 1128 | CanCreateApplicationShortcuts(browser_)); |
mitchelljones | 6d1594de | 2014-12-02 01:42:44 | [diff] [blame] | 1129 | #endif |
[email protected] | 9208654 | 2014-04-08 08:45:29 | [diff] [blame] | 1130 | command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP, |
| 1131 | CanCreateBookmarkApp(browser_)); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1132 | |
[email protected] | 9b7ab88 | 2012-09-10 23:46:36 | [diff] [blame] | 1133 | command_updater_.UpdateCommandEnabled( |
| 1134 | IDC_TOGGLE_REQUEST_TABLET_SITE, |
| 1135 | CanRequestTabletSite(current_web_contents)); |
| 1136 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1137 | UpdateCommandsForContentRestrictionState(); |
| 1138 | UpdateCommandsForBookmarkEditing(); |
[email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 1139 | UpdateCommandsForFind(); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 1140 | // Update the zoom commands when an active tab is selected. |
| 1141 | UpdateCommandsForZoomState(); |
| 1142 | } |
| 1143 | |
| 1144 | void BrowserCommandController::UpdateCommandsForZoomState() { |
| 1145 | WebContents* contents = |
| 1146 | browser_->tab_strip_model()->GetActiveWebContents(); |
| 1147 | if (!contents) |
| 1148 | return; |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 1149 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, |
| 1150 | CanZoomIn(contents)); |
| 1151 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 1152 | CanResetZoom(contents)); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 1153 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, |
| 1154 | CanZoomOut(contents)); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | void BrowserCommandController::UpdateCommandsForContentRestrictionState() { |
| 1158 | int restrictions = GetContentRestrictions(browser_); |
| 1159 | |
| 1160 | command_updater_.UpdateCommandEnabled( |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1161 | IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY)); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1162 | command_updater_.UpdateCommandEnabled( |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1163 | IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT)); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1164 | command_updater_.UpdateCommandEnabled( |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1165 | IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE)); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1166 | UpdateSaveAsState(); |
| 1167 | UpdatePrintingState(); |
| 1168 | } |
| 1169 | |
| 1170 | void BrowserCommandController::UpdateCommandsForDevTools() { |
| 1171 | bool dev_tools_enabled = |
| 1172 | !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); |
| 1173 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, |
| 1174 | dev_tools_enabled); |
| 1175 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, |
| 1176 | dev_tools_enabled); |
[email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 1177 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES, |
| 1178 | dev_tools_enabled); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1179 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT, |
| 1180 | dev_tools_enabled); |
[email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 1181 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE, |
| 1182 | dev_tools_enabled); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | void BrowserCommandController::UpdateCommandsForBookmarkEditing() { |
| 1186 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, |
| 1187 | CanBookmarkCurrentPage(browser_)); |
| 1188 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, |
| 1189 | CanBookmarkAllTabs(browser_)); |
thestig | 5149d27 | 2014-10-30 07:25:29 | [diff] [blame] | 1190 | #if defined(OS_WIN) |
| 1191 | command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true); |
| 1192 | #endif |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | void BrowserCommandController::UpdateCommandsForBookmarkBar() { |
tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 1196 | command_updater_.UpdateCommandEnabled( |
| 1197 | IDC_SHOW_BOOKMARK_BAR, |
| 1198 | browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() && |
mlerman | 7831f57d | 2015-05-25 11:40:15 | [diff] [blame] | 1199 | !profile()->IsSystemProfile() && |
tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 1200 | !profile()->GetPrefs()->IsManagedPreference( |
| 1201 | bookmarks::prefs::kShowBookmarkBar) && |
| 1202 | IsShowingMainUI()); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1203 | } |
| 1204 | |
[email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 1205 | void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { |
| 1206 | UpdateSaveAsState(); |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1207 | UpdateOpenFileState(&command_updater_); |
[email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 1208 | } |
| 1209 | |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1210 | void BrowserCommandController::UpdateCommandsForFullscreenMode() { |
| 1211 | WindowState window_state = WINDOW_STATE_NOT_FULLSCREEN; |
| 1212 | if (window() && window()->IsFullscreen()) { |
| 1213 | window_state = WINDOW_STATE_FULLSCREEN; |
| 1214 | #if defined(OS_WIN) |
| 1215 | if (window()->IsInMetroSnapMode()) |
| 1216 | window_state = WINDOW_STATE_METRO_SNAP; |
| 1217 | #endif |
| 1218 | } |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 1219 | bool show_main_ui = IsShowingMainUI(); |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1220 | bool main_not_fullscreen = |
| 1221 | show_main_ui && window_state == WINDOW_STATE_NOT_FULLSCREEN; |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1222 | |
| 1223 | // Navigation commands |
| 1224 | command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); |
| 1225 | |
| 1226 | // Window management commands |
| 1227 | command_updater_.UpdateCommandEnabled( |
| 1228 | IDC_SHOW_AS_TAB, |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1229 | !browser_->is_type_tabbed() && |
| 1230 | window_state == WINDOW_STATE_NOT_FULLSCREEN); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1231 | |
| 1232 | // Focus various bits of UI |
| 1233 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); |
| 1234 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui); |
| 1235 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); |
| 1236 | command_updater_.UpdateCommandEnabled( |
| 1237 | IDC_FOCUS_MENU_BAR, main_not_fullscreen); |
| 1238 | command_updater_.UpdateCommandEnabled( |
| 1239 | IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
| 1240 | command_updater_.UpdateCommandEnabled( |
| 1241 | IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 1242 | command_updater_.UpdateCommandEnabled( |
| 1243 | IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
[email protected] | 822ca8c6 | 2013-04-19 00:49:15 | [diff] [blame] | 1244 | command_updater_.UpdateCommandEnabled( |
| 1245 | IDC_FOCUS_INFOBARS, main_not_fullscreen); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1246 | |
| 1247 | // Show various bits of UI |
| 1248 | command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
[email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 1249 | #if defined(GOOGLE_CHROME_BUILD) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1250 | command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
[email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 1251 | #endif |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 1252 | UpdateShowSyncState(show_main_ui); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1253 | |
| 1254 | // Settings page/subpages are forced to open in normal mode. We disable these |
[email protected] | 90efc3e | 2014-04-22 18:39:03 | [diff] [blame] | 1255 | // commands for guest sessions and when incognito is forced. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1256 | const bool options_enabled = show_main_ui && |
| 1257 | IncognitoModePrefs::GetAvailability( |
| 1258 | profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1259 | const bool guest_session = profile()->IsGuestSession(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1260 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1261 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, |
| 1262 | options_enabled && !guest_session); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1263 | |
| 1264 | command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1265 | command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1266 | command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 1267 | command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| 1268 | #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 1269 | command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 1270 | #endif |
| 1271 | |
[email protected] | 7efaed36 | 2013-04-04 09:33:32 | [diff] [blame] | 1272 | // Disable explicit fullscreen toggling when in metro snap mode. |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1273 | bool fullscreen_enabled = window_state != WINDOW_STATE_METRO_SNAP; |
[email protected] | aeafc385 | 2014-04-29 16:51:29 | [diff] [blame] | 1274 | #if !defined(OS_MACOSX) |
[email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1275 | if (window_state == WINDOW_STATE_NOT_FULLSCREEN && |
| 1276 | !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) { |
| 1277 | // Disable toggling into fullscreen mode if disallowed by pref. |
| 1278 | fullscreen_enabled = false; |
| 1279 | } |
[email protected] | 00a1cc5b | 2012-11-07 13:44:51 | [diff] [blame] | 1280 | #endif |
| 1281 | |
| 1282 | command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); |
| 1283 | command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE, |
| 1284 | fullscreen_enabled); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1285 | |
| 1286 | UpdateCommandsForBookmarkBar(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | void BrowserCommandController::UpdatePrintingState() { |
[email protected] | d53e403 | 2012-06-29 18:58:34 | [diff] [blame] | 1290 | bool print_enabled = CanPrint(browser_); |
| 1291 | command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
vitalybuka | e29991c | 2014-11-05 21:15:12 | [diff] [blame] | 1292 | #if defined(ENABLE_BASIC_PRINTING) |
vitalybuka | f9433e4 | 2014-09-08 10:04:55 | [diff] [blame] | 1293 | command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, |
| 1294 | CanBasicPrint(browser_)); |
vitalybuka | e29991c | 2014-11-05 21:15:12 | [diff] [blame] | 1295 | #endif // ENABLE_BASIC_PRINTING |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | void BrowserCommandController::UpdateSaveAsState() { |
| 1299 | command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
| 1300 | } |
| 1301 | |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 1302 | void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) { |
| 1303 | command_updater_.UpdateCommandEnabled( |
| 1304 | IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue()); |
| 1305 | } |
| 1306 | |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1307 | // static |
| 1308 | void BrowserCommandController::UpdateOpenFileState( |
| 1309 | CommandUpdater* command_updater) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1310 | bool enabled = true; |
| 1311 | PrefService* local_state = g_browser_process->local_state(); |
| 1312 | if (local_state) |
| 1313 | enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 1314 | |
[email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1315 | command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | void BrowserCommandController::UpdateReloadStopState(bool is_loading, |
| 1319 | bool force) { |
| 1320 | window()->UpdateReloadStopState(is_loading, force); |
| 1321 | command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 1322 | } |
| 1323 | |
[email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 1324 | void BrowserCommandController::UpdateTabRestoreCommandState() { |
| 1325 | TabRestoreService* tab_restore_service = |
| 1326 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 1327 | // The command is enabled if the service hasn't loaded yet to trigger loading. |
| 1328 | // The command is updated once the load completes. |
| 1329 | command_updater_.UpdateCommandEnabled( |
| 1330 | IDC_RESTORE_TAB, |
| 1331 | tab_restore_service && |
| 1332 | (!tab_restore_service->IsLoaded() || |
| 1333 | GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE)); |
| 1334 | } |
| 1335 | |
[email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 1336 | void BrowserCommandController::UpdateCommandsForFind() { |
| 1337 | TabStripModel* model = browser_->tab_strip_model(); |
| 1338 | bool enabled = !model->IsTabBlocked(model->active_index()) && |
| 1339 | !browser_->is_devtools(); |
| 1340 | |
| 1341 | command_updater_.UpdateCommandEnabled(IDC_FIND, enabled); |
| 1342 | command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled); |
| 1343 | command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled); |
| 1344 | } |
| 1345 | |
[email protected] | 409ea297 | 2012-11-10 19:54:43 | [diff] [blame] | 1346 | void BrowserCommandController::AddInterstitialObservers(WebContents* contents) { |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 1347 | interstitial_observers_.push_back(new InterstitialObserver(this, contents)); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | void BrowserCommandController::RemoveInterstitialObservers( |
[email protected] | e89cfcb | 2012-11-11 14:47:24 | [diff] [blame] | 1351 | WebContents* contents) { |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 1352 | for (size_t i = 0; i < interstitial_observers_.size(); i++) { |
| 1353 | if (interstitial_observers_[i]->web_contents() != contents) |
| 1354 | continue; |
| 1355 | |
| 1356 | delete interstitial_observers_[i]; |
| 1357 | interstitial_observers_.erase(interstitial_observers_.begin() + i); |
| 1358 | return; |
| 1359 | } |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | BrowserWindow* BrowserCommandController::window() { |
| 1363 | return browser_->window(); |
| 1364 | } |
| 1365 | |
| 1366 | Profile* BrowserCommandController::profile() { |
| 1367 | return browser_->profile(); |
| 1368 | } |
| 1369 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1370 | } // namespace chrome |