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