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