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