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