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