| [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 | |
| Sebastien Marchand | f1349f5 | 2019-01-25 03:16:41 | [diff] [blame] | 11 | #include "base/bind.h" |
| [email protected] | 488e395 | 2013-11-18 05:29:14 | [diff] [blame] | 12 | #include "base/command_line.h" |
| Scott Violet | 4416579 | 2018-02-22 02:08:08 | [diff] [blame] | 13 | #include "base/debug/debugging_buildflags.h" |
| primiano | d3a81ab | 2016-01-25 22:21:15 | [diff] [blame] | 14 | #include "base/debug/profiler.h" |
| avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 15 | #include "base/macros.h" |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 16 | #include "base/metrics/user_metrics.h" |
| Haeun Kim | 3f612350 | 2018-08-26 18:03:04 | [diff] [blame] | 17 | #include "base/stl_util.h" |
| Nico Weber | 0cc7112 | 2019-07-29 17:30:40 | [diff] [blame] | 18 | #include "build/branding_buildflags.h" |
| avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 19 | #include "build/build_config.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 20 | #include "chrome/app/chrome_command_ids.h" |
| 21 | #include "chrome/browser/browser_process.h" |
| [email protected] | dcc8fbc | 2013-07-12 00:54:09 | [diff] [blame] | 22 | #include "chrome/browser/chrome_notification_types.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 23 | #include "chrome/browser/defaults.h" |
| Pavol Marko | 56df027 | 2018-07-04 17:55:04 | [diff] [blame] | 24 | #include "chrome/browser/devtools/devtools_window.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 25 | #include "chrome/browser/extensions/extension_service.h" |
| [email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 26 | #include "chrome/browser/lifetime/application_lifetime.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 27 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 28 | #include "chrome/browser/profiles/profile.h" |
| mlerman | e01e6de | 2014-09-29 19:26:47 | [diff] [blame] | 29 | #include "chrome/browser/profiles/profile_manager.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 30 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| [email protected] | 0b32f9b6 | 2012-09-17 19:08:03 | [diff] [blame] | 31 | #include "chrome/browser/shell_integration.h" |
| [email protected] | 3d27d27 | 2013-07-31 03:15:16 | [diff] [blame] | 32 | #include "chrome/browser/signin/signin_promo.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 33 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
| Christopher Lam | 86b5271 | 2017-12-04 01:58:33 | [diff] [blame] | 34 | #include "chrome/browser/ui/apps/app_info_dialog.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 35 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 36 | #include "chrome/browser/ui/browser.h" |
| 37 | #include "chrome/browser/ui/browser_commands.h" |
| Dana Fried | 08b774a | 2019-05-10 18:21:48 | [diff] [blame] | 38 | #include "chrome/browser/ui/browser_finder.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 39 | #include "chrome/browser/ui/browser_window.h" |
| 40 | #include "chrome/browser/ui/chrome_pages.h" |
| Alan Cutter | 0c313230 | 2018-02-21 05:09:02 | [diff] [blame] | 41 | #include "chrome/browser/ui/page_info/page_info_dialog.h" |
| Nicolas Ouellet-payeur | 82eb65b | 2018-11-05 16:49:27 | [diff] [blame] | 42 | #include "chrome/browser/ui/singleton_tabs.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 43 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| Yuheng Huang | 092c72a9 | 2020-08-10 22:39:30 | [diff] [blame] | 44 | #include "chrome/browser/ui/ui_features.h" |
| Eric Willigers | 4a5f7a9 | 2019-05-10 19:19:26 | [diff] [blame] | 45 | #include "chrome/browser/ui/web_applications/app_browser_controller.h" |
| Glen Robertson | b9d2741 | 2020-01-09 06:48:13 | [diff] [blame] | 46 | #include "chrome/browser/ui/web_applications/web_app_dialog_utils.h" |
| Eric Willigers | e2ca235a | 2019-08-17 01:01:06 | [diff] [blame] | 47 | #include "chrome/browser/ui/web_applications/web_app_launch_utils.h" |
| [email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 48 | #include "chrome/browser/ui/webui/inspect_ui.h" |
| [email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 49 | #include "chrome/common/content_restriction.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 50 | #include "chrome/common/pref_names.h" |
| Nicolas Ouellet-payeur | 82eb65b | 2018-11-05 16:49:27 | [diff] [blame] | 51 | #include "chrome/common/url_constants.h" |
| brettw | e1f0af8b | 2015-10-09 21:30:46 | [diff] [blame] | 52 | #include "components/bookmarks/common/bookmark_pref_names.h" |
| Aran Gilman | 7b6ccf5d | 2019-09-05 19:16:02 | [diff] [blame] | 53 | #include "components/dom_distiller/core/dom_distiller_features.h" |
| Elly Fong-Jones | 2d688ae | 2020-03-31 20:41:47 | [diff] [blame] | 54 | #include "components/omnibox/common/omnibox_features.h" |
| brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 55 | #include "components/prefs/pref_service.h" |
| blundell | a08c5dd | 2015-09-18 06:14:16 | [diff] [blame] | 56 | #include "components/sessions/core/tab_restore_service.h" |
| Colin Blundell | 3517170e | 2019-07-11 08:16:34 | [diff] [blame] | 57 | #include "components/signin/public/base/signin_pref_names.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 58 | #include "content/public/browser/native_web_keyboard_event.h" |
| 59 | #include "content/public/browser/navigation_controller.h" |
| 60 | #include "content/public/browser/navigation_entry.h" |
| Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 61 | #include "content/public/browser/render_frame_host.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 62 | #include "content/public/browser/web_contents.h" |
| [email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 63 | #include "content/public/browser/web_contents_observer.h" |
| Bryce Thomas | 96b0777 | 2018-11-07 03:04:15 | [diff] [blame] | 64 | #include "content/public/common/profiling.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 65 | #include "content/public/common/url_constants.h" |
| [email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 66 | #include "extensions/browser/extension_system.h" |
| Scott Violet | 318a55f | 2018-03-30 19:08:19 | [diff] [blame] | 67 | #include "printing/buildflags/buildflags.h" |
| [email protected] | 7e9acd08 | 2013-09-17 23:31:16 | [diff] [blame] | 68 | #include "ui/events/keycodes/keyboard_codes.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 69 | |
| Avi Drissman | 73ea864d | 2020-07-29 19:56:15 | [diff] [blame] | 70 | #if defined(OS_MAC) |
| [email protected] | 9c4d6833 | 2013-01-30 13:34:41 | [diff] [blame] | 71 | #include "chrome/browser/ui/browser_commands_mac.h" |
| 72 | #endif |
| 73 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 74 | #if defined(OS_WIN) |
| [email protected] | a43ed00 | 2013-02-05 19:47:54 | [diff] [blame] | 75 | #include "base/win/windows_version.h" |
| [email protected] | 2d0f80f | 2013-11-01 22:47:18 | [diff] [blame] | 76 | #include "content/public/browser/gpu_data_manager.h" |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 77 | #endif |
| 78 | |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 79 | #if defined(OS_CHROMEOS) |
| Ivan Sandrk | e0e9245 | 2019-03-21 09:32:48 | [diff] [blame] | 80 | #include "chrome/browser/platform_util.h" |
| [email protected] | 0c93081 | 2014-01-30 18:01:47 | [diff] [blame] | 81 | #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" |
| caelyn | 4e4e08a | 2015-02-04 21:27:49 | [diff] [blame] | 82 | #include "chrome/browser/ui/browser_commands_chromeos.h" |
| anina koehler | 038555b | 2020-02-24 13:30:32 | [diff] [blame] | 83 | #include "components/session_manager/core/session_manager.h" |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 84 | #endif |
| 85 | |
| [email protected] | d5bedb6d | 2014-04-08 10:49:32 | [diff] [blame] | 86 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| Eliot Courtney | 830e005 | 2020-06-16 11:43:34 | [diff] [blame] | 87 | #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" // nogncheck |
| [email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 88 | #endif |
| 89 | |
| Maksim Sisov | ac76759 | 2018-08-10 08:00:15 | [diff] [blame] | 90 | #if defined(USE_OZONE) |
| Maksim Sisov | b0643ebd | 2020-06-22 11:47:31 | [diff] [blame] | 91 | #include "ui/base/ui_base_features.h" |
| Maksim Sisov | ac76759 | 2018-08-10 08:00:15 | [diff] [blame] | 92 | #include "ui/ozone/public/ozone_platform.h" |
| 93 | #endif |
| 94 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 95 | using content::NavigationController; |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 96 | using content::NavigationEntry; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 97 | using content::WebContents; |
| 98 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 99 | namespace chrome { |
| 100 | |
| Dana Fried | 08b774a | 2019-05-10 18:21:48 | [diff] [blame] | 101 | namespace { |
| 102 | |
| 103 | // Ensures that - if we have not popped up an infobar to prompt the user to e.g. |
| 104 | // reload the current page - that the content pane of the browser is refocused. |
| 105 | void AppInfoDialogClosedCallback(content::WebContents* web_contents, |
| Dana Fried | 98c0380e | 2019-05-14 16:58:32 | [diff] [blame] | 106 | views::Widget::ClosedReason closed_reason, |
| Dana Fried | 08b774a | 2019-05-10 18:21:48 | [diff] [blame] | 107 | bool reload_prompt) { |
| 108 | if (reload_prompt) |
| 109 | return; |
| 110 | |
| Dana Fried | 98c0380e | 2019-05-14 16:58:32 | [diff] [blame] | 111 | // If the user clicked on something specific or focus was changed, don't |
| 112 | // override the focus. |
| 113 | if (closed_reason != views::Widget::ClosedReason::kEscKeyPressed && |
| 114 | closed_reason != views::Widget::ClosedReason::kCloseButtonClicked) { |
| 115 | return; |
| 116 | } |
| 117 | |
| Dana Fried | 08b774a | 2019-05-10 18:21:48 | [diff] [blame] | 118 | // Ensure that the web contents handle we have is still valid. It's possible |
| 119 | // (though unlikely) that either the browser or web contents has been pulled |
| 120 | // out from underneath us. |
| 121 | Browser* const browser = chrome::FindBrowserWithWebContents(web_contents); |
| 122 | if (!browser) |
| 123 | return; |
| 124 | |
| 125 | // We want to focus the active web contents, which again, might not be the |
| 126 | // original web contents (though it should be the vast majority of the time). |
| 127 | content::WebContents* const active_contents = |
| 128 | browser->tab_strip_model()->GetActiveWebContents(); |
| 129 | if (active_contents) |
| 130 | active_contents->Focus(); |
| 131 | } |
| 132 | |
| 133 | } // namespace |
| 134 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 135 | /////////////////////////////////////////////////////////////////////////////// |
| 136 | // BrowserCommandController, public: |
| 137 | |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 138 | BrowserCommandController::BrowserCommandController(Browser* browser) |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 139 | : browser_(browser), command_updater_(nullptr) { |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 140 | browser_->tab_strip_model()->AddObserver(this); |
| 141 | PrefService* local_state = g_browser_process->local_state(); |
| 142 | if (local_state) { |
| 143 | local_pref_registrar_.Init(local_state); |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 144 | local_pref_registrar_.Add( |
| 145 | prefs::kAllowFileSelectionDialogs, |
| 146 | base::Bind( |
| 147 | &BrowserCommandController::UpdateCommandsForFileSelectionDialogs, |
| 148 | base::Unretained(this))); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | profile_pref_registrar_.Init(profile()->GetPrefs()); |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 152 | profile_pref_registrar_.Add( |
| Pavol Marko | debb0ff | 2018-05-07 18:35:41 | [diff] [blame] | 153 | prefs::kDevToolsAvailability, |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 154 | base::Bind(&BrowserCommandController::UpdateCommandsForDevTools, |
| 155 | base::Unretained(this))); |
| 156 | profile_pref_registrar_.Add( |
| tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 157 | bookmarks::prefs::kEditBookmarksEnabled, |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 158 | base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing, |
| 159 | base::Unretained(this))); |
| 160 | profile_pref_registrar_.Add( |
| tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 161 | bookmarks::prefs::kShowBookmarkBar, |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 162 | base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar, |
| 163 | base::Unretained(this))); |
| 164 | profile_pref_registrar_.Add( |
| 165 | prefs::kIncognitoModeAvailability, |
| 166 | base::Bind( |
| 167 | &BrowserCommandController::UpdateCommandsForIncognitoAvailability, |
| 168 | base::Unretained(this))); |
| 169 | profile_pref_registrar_.Add( |
| 170 | prefs::kPrintingEnabled, |
| 171 | base::Bind(&BrowserCommandController::UpdatePrintingState, |
| 172 | base::Unretained(this))); |
| Avi Drissman | 73ea864d | 2020-07-29 19:56:15 | [diff] [blame] | 173 | #if !defined(OS_MAC) |
| [email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 174 | profile_pref_registrar_.Add( |
| 175 | prefs::kFullscreenAllowed, |
| 176 | base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode, |
| 177 | base::Unretained(this))); |
| 178 | #endif |
| Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 179 | pref_signin_allowed_.Init( |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 180 | prefs::kSigninAllowed, profile()->GetOriginalProfile()->GetPrefs(), |
| Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 181 | base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange, |
| 182 | base::Unretained(this))); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 183 | |
| 184 | InitCommandState(); |
| 185 | |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 186 | sessions::TabRestoreService* tab_restore_service = |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 187 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 188 | if (tab_restore_service) { |
| 189 | tab_restore_service->AddObserver(this); |
| Cliff Smolinsky | 2c9586e | 2019-02-08 18:48:30 | [diff] [blame] | 190 | if (!tab_restore_service->IsLoaded()) |
| 191 | tab_restore_service->LoadTabsFromLastSession(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 192 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | BrowserCommandController::~BrowserCommandController() { |
| [email protected] | 95e3947 | 2012-10-05 23:37:36 | [diff] [blame] | 196 | // TabRestoreService may have been shutdown by the time we get here. Don't |
| 197 | // trigger creating it. |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 198 | sessions::TabRestoreService* tab_restore_service = |
| [email protected] | 95e3947 | 2012-10-05 23:37:36 | [diff] [blame] | 199 | TabRestoreServiceFactory::GetForProfileIfExisting(profile()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 200 | if (tab_restore_service) |
| 201 | tab_restore_service->RemoveObserver(this); |
| 202 | profile_pref_registrar_.RemoveAll(); |
| 203 | local_pref_registrar_.RemoveAll(); |
| 204 | browser_->tab_strip_model()->RemoveObserver(this); |
| 205 | } |
| 206 | |
| 207 | bool BrowserCommandController::IsReservedCommandOrKey( |
| 208 | int command_id, |
| 209 | const content::NativeWebKeyboardEvent& event) { |
| 210 | // In Apps mode, no keys are reserved. |
| Leonard Grey | 345662a8 | 2020-02-07 21:20:03 | [diff] [blame] | 211 | if (browser_->is_type_app() || browser_->is_type_app_popup()) |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 212 | return false; |
| 213 | |
| 214 | #if defined(OS_CHROMEOS) |
| [email protected] | 397abd3 | 2013-08-21 05:44:19 | [diff] [blame] | 215 | // On Chrome OS, the top row of keys are mapped to browser actions like |
| 216 | // back/forward or refresh. We don't want web pages to be able to change the |
| 217 | // behavior of these keys. Ash handles F4 and up; this leaves us needing to |
| 218 | // reserve browser back/forward and refresh here. |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 219 | ui::KeyboardCode key_code = |
| Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 220 | static_cast<ui::KeyboardCode>(event.windows_key_code); |
| [email protected] | 397abd3 | 2013-08-21 05:44:19 | [diff] [blame] | 221 | if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) || |
| 222 | (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) || |
| 223 | (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) { |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 224 | return true; |
| 225 | } |
| 226 | #endif |
| 227 | |
| zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 228 | if (window()->IsFullscreen()) { |
| 229 | // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should |
| 230 | // be delivered to the web page. The intent to implement and ship can be |
| 231 | // found in http://crbug.com/680809. |
| 232 | const bool is_exit_fullscreen = |
| 233 | (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN); |
| Avi Drissman | 73ea864d | 2020-07-29 19:56:15 | [diff] [blame] | 234 | #if defined(OS_MAC) |
| zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 235 | // This behavior is different on Mac OS, which has a unique user-initiated |
| 236 | // full-screen mode. According to the discussion in http://crbug.com/702251, |
| 237 | // the commands should be reserved for browser-side handling if the browser |
| 238 | // window's toolbar is visible. |
| 239 | if (window()->IsToolbarShowing()) { |
| 240 | if (command_id == IDC_FULLSCREEN) |
| 241 | return true; |
| 242 | } else { |
| 243 | return is_exit_fullscreen; |
| 244 | } |
| 245 | #else |
| 246 | return is_exit_fullscreen; |
| 247 | #endif |
| 248 | } |
| [email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 249 | |
| [email protected] | 893124a2 | 2014-04-15 00:45:28 | [diff] [blame] | 250 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| [email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 251 | // If this key was registered by the user as a content editing hotkey, then |
| 252 | // it is not reserved. |
| [email protected] | d5bedb6d | 2014-04-08 10:49:32 | [diff] [blame] | 253 | ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
| [email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 254 | ui::GetTextEditKeyBindingsDelegate(); |
| [email protected] | 47e8e754 | 2014-04-03 07:52:42 | [diff] [blame] | 255 | if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL)) |
| [email protected] | 1e2172f | 2014-04-01 17:32:34 | [diff] [blame] | 256 | return false; |
| 257 | #endif |
| 258 | |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 259 | return command_id == IDC_CLOSE_TAB || command_id == IDC_CLOSE_WINDOW || |
| 260 | command_id == IDC_NEW_INCOGNITO_WINDOW || command_id == IDC_NEW_TAB || |
| 261 | command_id == IDC_NEW_WINDOW || command_id == IDC_RESTORE_TAB || |
| zijiehe | 1320780 | 2017-02-16 08:06:10 | [diff] [blame] | 262 | command_id == IDC_SELECT_NEXT_TAB || |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 263 | command_id == IDC_SELECT_PREVIOUS_TAB || command_id == IDC_EXIT; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 264 | } |
| 265 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 266 | void BrowserCommandController::TabStateChanged() { |
| 267 | UpdateCommandsForTabState(); |
| Dominic Mazzoni | 1e0e5125 | 2020-10-19 19:36:18 | [diff] [blame^] | 268 | UpdateCommandsForWebContentsFocus(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 269 | } |
| 270 | |
| [email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 271 | void BrowserCommandController::ZoomStateChanged() { |
| 272 | UpdateCommandsForZoomState(); |
| 273 | } |
| 274 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 275 | void BrowserCommandController::ContentRestrictionsChanged() { |
| 276 | UpdateCommandsForContentRestrictionState(); |
| 277 | } |
| 278 | |
| 279 | void BrowserCommandController::FullscreenStateChanged() { |
| [email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 280 | UpdateCommandsForFullscreenMode(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 281 | } |
| 282 | |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 283 | #if defined(OS_CHROMEOS) |
| 284 | void BrowserCommandController::LockedFullscreenStateChanged() { |
| 285 | UpdateCommandsForLockedFullscreenMode(); |
| 286 | } |
| 287 | #endif |
| 288 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 289 | void BrowserCommandController::PrintingStateChanged() { |
| 290 | UpdatePrintingState(); |
| 291 | } |
| 292 | |
| 293 | void BrowserCommandController::LoadingStateChanged(bool is_loading, |
| 294 | bool force) { |
| 295 | UpdateReloadStopState(is_loading, force); |
| 296 | } |
| 297 | |
| Jeff Fisher | 6cc1ce7b | 2019-06-28 23:02:38 | [diff] [blame] | 298 | void BrowserCommandController::FindBarVisibilityChanged() { |
| 299 | if (is_locked_fullscreen_) |
| 300 | return; |
| 301 | UpdateCloseFindOrStop(); |
| 302 | } |
| 303 | |
| wittman | 76df71db3 | 2014-12-18 23:26:58 | [diff] [blame] | 304 | void BrowserCommandController::ExtensionStateChanged() { |
| 305 | // Extensions may disable the bookmark editing commands. |
| 306 | UpdateCommandsForBookmarkEditing(); |
| 307 | } |
| 308 | |
| Elly Fong-Jones | 5e6baaf | 2019-10-10 23:17:14 | [diff] [blame] | 309 | void BrowserCommandController::TabKeyboardFocusChangedTo( |
| 310 | base::Optional<int> index) { |
| 311 | UpdateCommandsForTabKeyboardFocus(index); |
| 312 | } |
| 313 | |
| Dominic Mazzoni | 1e0e5125 | 2020-10-19 19:36:18 | [diff] [blame^] | 314 | void BrowserCommandController::WebContentsFocusChanged() { |
| 315 | UpdateCommandsForWebContentsFocus(); |
| 316 | } |
| 317 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 318 | //////////////////////////////////////////////////////////////////////////////// |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 319 | // BrowserCommandController, CommandUpdater implementation: |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 320 | |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 321 | bool BrowserCommandController::SupportsCommand(int id) const { |
| 322 | return command_updater_.SupportsCommand(id); |
| 323 | } |
| 324 | |
| 325 | bool BrowserCommandController::IsCommandEnabled(int id) const { |
| 326 | return command_updater_.IsCommandEnabled(id); |
| 327 | } |
| 328 | |
| Edwin Joe | 6f6fc1e | 2019-02-27 20:00:37 | [diff] [blame] | 329 | bool BrowserCommandController::ExecuteCommand(int id, |
| 330 | base::TimeTicks time_stamp) { |
| 331 | return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB, |
| 332 | time_stamp); |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | bool BrowserCommandController::ExecuteCommandWithDisposition( |
| Edwin Joe | 6f6fc1e | 2019-02-27 20:00:37 | [diff] [blame] | 336 | int id, |
| 337 | WindowOpenDisposition disposition, |
| 338 | base::TimeTicks time_stamp) { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 339 | // Doesn't go through the command_updater_ to avoid dealing with having a |
| 340 | // naming collision for ExecuteCommandWithDisposition (both |
| 341 | // CommandUpdaterDelegate and CommandUpdater declare this function so we |
| 342 | // choose to not implement CommandUpdaterDelegate inside this class and |
| 343 | // therefore command_updater_ doesn't have the delegate set). |
| 344 | if (!SupportsCommand(id) || !IsCommandEnabled(id)) |
| 345 | return false; |
| 346 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 347 | // No commands are enabled if there is not yet any selected tab. |
| 348 | // TODO(pkasting): It seems like we should not need this, because either |
| 349 | // most/all commands should not have been enabled yet anyway or the ones that |
| 350 | // are enabled should be global, or safe themselves against having no selected |
| 351 | // tab. However, Ben says he tried removing this before and got lots of |
| 352 | // crashes, e.g. from Windows sending WM_COMMANDs at random times during |
| 353 | // window construction. This probably could use closer examination someday. |
| [email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 354 | if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab) |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 355 | return true; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 356 | |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 357 | DCHECK(command_updater_.IsCommandEnabled(id)) |
| 358 | << "Invalid/disabled command " << id; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 359 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 360 | // The order of commands in this switch statement must match the function |
| 361 | // declaration order in browser.h! |
| 362 | switch (id) { |
| 363 | // Navigation commands |
| 364 | case IDC_BACK: |
| 365 | GoBack(browser_, disposition); |
| 366 | break; |
| 367 | case IDC_FORWARD: |
| 368 | GoForward(browser_, disposition); |
| 369 | break; |
| 370 | case IDC_RELOAD: |
| 371 | Reload(browser_, disposition); |
| 372 | break; |
| [email protected] | 58e2903 | 2012-08-06 20:19:57 | [diff] [blame] | 373 | case IDC_RELOAD_CLEARING_CACHE: |
| 374 | ClearCache(browser_); |
| Nico Weber | a745ef7 | 2018-01-29 23:45:57 | [diff] [blame] | 375 | FALLTHROUGH; |
| toyoshim | 7dad4b118 | 2016-04-01 14:28:05 | [diff] [blame] | 376 | case IDC_RELOAD_BYPASSING_CACHE: |
| 377 | ReloadBypassingCache(browser_, disposition); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 378 | break; |
| 379 | case IDC_HOME: |
| 380 | Home(browser_, disposition); |
| 381 | break; |
| 382 | case IDC_OPEN_CURRENT_URL: |
| 383 | OpenCurrentURL(browser_); |
| 384 | break; |
| 385 | case IDC_STOP: |
| 386 | Stop(browser_); |
| 387 | break; |
| Yuheng Huang | 092c72a9 | 2020-08-10 22:39:30 | [diff] [blame] | 388 | case IDC_TAB_SEARCH: |
| 389 | ShowTabSearch(browser_); |
| 390 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 391 | |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 392 | // Window management commands |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 393 | case IDC_NEW_WINDOW: |
| 394 | NewWindow(browser_); |
| 395 | break; |
| 396 | case IDC_NEW_INCOGNITO_WINDOW: |
| Orin Jaworski | 5e4bcd0c | 2018-10-16 19:35:05 | [diff] [blame] | 397 | NewIncognitoWindow(profile()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 398 | break; |
| 399 | case IDC_CLOSE_WINDOW: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 400 | base::RecordAction(base::UserMetricsAction("CloseWindowByKey")); |
| [email protected] | 04b9e69 | 2012-08-24 14:49:09 | [diff] [blame] | 401 | CloseWindow(browser_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 402 | break; |
| Bettina Dea | 0a450592 | 2017-09-28 00:53:32 | [diff] [blame] | 403 | case IDC_NEW_TAB: { |
| 404 | NewTab(browser_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 405 | break; |
| Bettina Dea | 0a450592 | 2017-09-28 00:53:32 | [diff] [blame] | 406 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 407 | case IDC_CLOSE_TAB: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 408 | base::RecordAction(base::UserMetricsAction("CloseTabByKey")); |
| [email protected] | 04b9e69 | 2012-08-24 14:49:09 | [diff] [blame] | 409 | CloseTab(browser_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 410 | break; |
| 411 | case IDC_SELECT_NEXT_TAB: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 412 | base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab")); |
| Edwin Joe | 6f6fc1e | 2019-02-27 20:00:37 | [diff] [blame] | 413 | SelectNextTab(browser_, |
| 414 | {TabStripModel::GestureType::kKeyboard, time_stamp}); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 415 | break; |
| 416 | case IDC_SELECT_PREVIOUS_TAB: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 417 | base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab")); |
| Edwin Joe | 6f6fc1e | 2019-02-27 20:00:37 | [diff] [blame] | 418 | SelectPreviousTab(browser_, |
| 419 | {TabStripModel::GestureType::kKeyboard, time_stamp}); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 420 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 421 | case IDC_MOVE_TAB_NEXT: |
| 422 | MoveTabNext(browser_); |
| 423 | break; |
| 424 | case IDC_MOVE_TAB_PREVIOUS: |
| 425 | MoveTabPrevious(browser_); |
| 426 | break; |
| 427 | case IDC_SELECT_TAB_0: |
| 428 | case IDC_SELECT_TAB_1: |
| 429 | case IDC_SELECT_TAB_2: |
| 430 | case IDC_SELECT_TAB_3: |
| 431 | case IDC_SELECT_TAB_4: |
| 432 | case IDC_SELECT_TAB_5: |
| 433 | case IDC_SELECT_TAB_6: |
| 434 | case IDC_SELECT_TAB_7: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 435 | base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab")); |
| Edwin Joe | 6f6fc1e | 2019-02-27 20:00:37 | [diff] [blame] | 436 | SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0, |
| 437 | {TabStripModel::GestureType::kKeyboard, time_stamp}); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 438 | break; |
| 439 | case IDC_SELECT_LAST_TAB: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 440 | base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab")); |
| Edwin Joe | 6f6fc1e | 2019-02-27 20:00:37 | [diff] [blame] | 441 | SelectLastTab(browser_, |
| 442 | {TabStripModel::GestureType::kKeyboard, time_stamp}); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 443 | break; |
| 444 | case IDC_DUPLICATE_TAB: |
| 445 | DuplicateTab(browser_); |
| 446 | break; |
| 447 | case IDC_RESTORE_TAB: |
| 448 | RestoreTab(browser_); |
| Collin Baker | 9bbe1d8 | 2019-03-08 01:16:27 | [diff] [blame] | 449 | browser_->window()->OnTabRestored(IDC_RESTORE_TAB); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 450 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 451 | case IDC_SHOW_AS_TAB: |
| 452 | ConvertPopupToTabbedBrowser(browser_); |
| 453 | break; |
| 454 | case IDC_FULLSCREEN: |
| [email protected] | 3f32b9b | 2012-07-09 16:59:28 | [diff] [blame] | 455 | chrome::ToggleFullscreenMode(browser_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 456 | break; |
| Alan Cutter | 0996580 | 2018-03-27 07:25:29 | [diff] [blame] | 457 | case IDC_OPEN_IN_PWA_WINDOW: |
| 458 | base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow")); |
| Alan Cutter | 4235602 | 2020-02-20 06:44:13 | [diff] [blame] | 459 | web_app::ReparentWebAppForActiveTab(browser_); |
| Alan Cutter | 0996580 | 2018-03-27 07:25:29 | [diff] [blame] | 460 | break; |
| Leonard Grey | f13493b | 2019-12-19 18:12:57 | [diff] [blame] | 461 | case IDC_MOVE_TAB_TO_NEW_WINDOW: |
| Leonard Grey | a8ecaa3 | 2020-01-07 20:57:41 | [diff] [blame] | 462 | MoveActiveTabToNewWindow(browser_); |
| Leonard Grey | f13493b | 2019-12-19 18:12:57 | [diff] [blame] | 463 | break; |
| [email protected] | 770c6d8 | 2012-09-06 22:21:32 | [diff] [blame] | 464 | |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 465 | #if defined(OS_CHROMEOS) |
| 466 | case IDC_VISIT_DESKTOP_OF_LRU_USER_2: |
| [email protected] | 0c93081 | 2014-01-30 18:01:47 | [diff] [blame] | 467 | case IDC_VISIT_DESKTOP_OF_LRU_USER_3: |
| anina koehler | 038555b | 2020-02-24 13:30:32 | [diff] [blame] | 468 | case IDC_VISIT_DESKTOP_OF_LRU_USER_4: |
| 469 | case IDC_VISIT_DESKTOP_OF_LRU_USER_5: |
| zijiehe | 4dde807 | 2017-02-13 20:38:35 | [diff] [blame] | 470 | ExecuteVisitDesktopCommand(id, window()->GetNativeWindow()); |
| [email protected] | 0c93081 | 2014-01-30 18:01:47 | [diff] [blame] | 471 | break; |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 472 | #endif |
| 473 | |
| [email protected] | 893124a2 | 2014-04-15 00:45:28 | [diff] [blame] | 474 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| Tom Anderson | f15ede50 | 2017-11-10 03:17:15 | [diff] [blame] | 475 | case IDC_MINIMIZE_WINDOW: |
| 476 | browser_->window()->Minimize(); |
| 477 | break; |
| 478 | case IDC_MAXIMIZE_WINDOW: |
| 479 | browser_->window()->Maximize(); |
| 480 | break; |
| 481 | case IDC_RESTORE_WINDOW: |
| 482 | browser_->window()->Restore(); |
| 483 | break; |
| [email protected] | af97be4c6 | 2014-02-13 14:43:34 | [diff] [blame] | 484 | case IDC_USE_SYSTEM_TITLE_BAR: { |
| zijiehe | 4dde807 | 2017-02-13 20:38:35 | [diff] [blame] | 485 | PrefService* prefs = profile()->GetPrefs(); |
| [email protected] | af97be4c6 | 2014-02-13 14:43:34 | [diff] [blame] | 486 | prefs->SetBoolean(prefs::kUseCustomChromeFrame, |
| 487 | !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); |
| 488 | break; |
| 489 | } |
| 490 | #endif |
| 491 | |
| Avi Drissman | 73ea864d | 2020-07-29 19:56:15 | [diff] [blame] | 492 | #if defined(OS_MAC) |
| spqchan | b8ffc7d | 2015-11-17 01:17:21 | [diff] [blame] | 493 | case IDC_TOGGLE_FULLSCREEN_TOOLBAR: |
| 494 | chrome::ToggleFullscreenToolbar(browser_); |
| 495 | break; |
| spqchan | 2c5d541e | 2017-10-25 07:07:11 | [diff] [blame] | 496 | case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: { |
| Robert Sesek | 0328261 | 2018-10-31 15:48:06 | [diff] [blame] | 497 | chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_); |
| spqchan | 2c5d541e | 2017-10-25 07:07:11 | [diff] [blame] | 498 | break; |
| 499 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 500 | #endif |
| 501 | case IDC_EXIT: |
| 502 | Exit(); |
| 503 | break; |
| 504 | |
| 505 | // Page-related commands |
| 506 | case IDC_SAVE_PAGE: |
| 507 | SavePage(browser_); |
| 508 | break; |
| Peter Kasting | 32bb260 | 2019-08-22 19:01:43 | [diff] [blame] | 509 | case IDC_BOOKMARK_THIS_TAB: |
| Devlin Cronin | bf700d0 | 2020-03-30 20:23:58 | [diff] [blame] | 510 | BookmarkCurrentTab(browser_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 511 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 512 | case IDC_BOOKMARK_ALL_TABS: |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 513 | BookmarkAllTabs(browser_); |
| 514 | break; |
| 515 | case IDC_VIEW_SOURCE: |
| Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 516 | browser_->tab_strip_model() |
| 517 | ->GetActiveWebContents() |
| 518 | ->GetMainFrame() |
| 519 | ->ViewSource(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 520 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 521 | case IDC_PRINT: |
| 522 | Print(browser_); |
| 523 | break; |
| bondd | 052b5f8 | 2015-10-28 22:39:32 | [diff] [blame] | 524 | |
| Lei Zhang | 48a4a526 | 2018-04-17 20:18:44 | [diff] [blame] | 525 | #if BUILDFLAG(ENABLE_PRINTING) |
| vitalybuka | f9433e4 | 2014-09-08 10:04:55 | [diff] [blame] | 526 | case IDC_BASIC_PRINT: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 527 | base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print")); |
| vitalybuka | f9433e4 | 2014-09-08 10:04:55 | [diff] [blame] | 528 | BasicPrint(browser_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 529 | break; |
| Lei Zhang | 48a4a526 | 2018-04-17 20:18:44 | [diff] [blame] | 530 | #endif // ENABLE_PRINTING |
| bondd | 052b5f8 | 2015-10-28 22:39:32 | [diff] [blame] | 531 | |
| bondd | 052b5f8 | 2015-10-28 22:39:32 | [diff] [blame] | 532 | case IDC_SAVE_CREDIT_CARD_FOR_PAGE: |
| 533 | SaveCreditCard(browser_); |
| 534 | break; |
| siyua | 3e599eaa | 2018-07-13 00:23:06 | [diff] [blame] | 535 | case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE: |
| 536 | MigrateLocalCards(browser_); |
| 537 | break; |
| siyua | c6e018d | 2019-10-18 01:19:30 | [diff] [blame] | 538 | case IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE: |
| 539 | MaybeShowSaveLocalCardSignInPromo(browser_); |
| 540 | break; |
| 541 | case IDC_CLOSE_SIGN_IN_PROMO: |
| 542 | CloseSaveLocalCardSignInPromo(browser_); |
| 543 | break; |
| [email protected] | e625b760 | 2013-10-28 09:24:56 | [diff] [blame] | 544 | case IDC_TRANSLATE_PAGE: |
| 545 | Translate(browser_); |
| 546 | break; |
| [email protected] | 4bee443 | 2014-05-05 13:11:41 | [diff] [blame] | 547 | case IDC_MANAGE_PASSWORDS_FOR_PAGE: |
| 548 | ManagePasswordsForPage(browser_); |
| 549 | break; |
| Tina Wang | 4c32470 | 2019-04-25 18:35:15 | [diff] [blame] | 550 | case IDC_SEND_TAB_TO_SELF: |
| Tina Wang | 0e7e6e9 | 2019-05-14 21:03:03 | [diff] [blame] | 551 | SendTabToSelfFromPageAction(browser_); |
| Tina Wang | 4c32470 | 2019-04-25 18:35:15 | [diff] [blame] | 552 | break; |
| Travis Skare | 5193bbe1 | 2020-04-15 18:31:03 | [diff] [blame] | 553 | case IDC_QRCODE_GENERATOR: |
| 554 | GenerateQRCodeFromPageAction(browser_); |
| 555 | break; |
| [email protected] | 4bee443 | 2014-05-05 13:11:41 | [diff] [blame] | 556 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 557 | // Clipboard commands |
| 558 | case IDC_CUT: |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 559 | case IDC_COPY: |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 560 | case IDC_PASTE: |
| pkasting | cd3f08bce | 2015-04-18 13:37:12 | [diff] [blame] | 561 | CutCopyPaste(browser_, id); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 562 | break; |
| 563 | |
| 564 | // Find-in-page |
| 565 | case IDC_FIND: |
| 566 | Find(browser_); |
| 567 | break; |
| 568 | case IDC_FIND_NEXT: |
| 569 | FindNext(browser_); |
| 570 | break; |
| 571 | case IDC_FIND_PREVIOUS: |
| 572 | FindPrevious(browser_); |
| 573 | break; |
| Jeff Fisher | 6cc1ce7b | 2019-06-28 23:02:38 | [diff] [blame] | 574 | case IDC_CLOSE_FIND_OR_STOP: |
| 575 | if (CanCloseFind(browser_)) |
| 576 | CloseFind(browser_); |
| 577 | else if (IsCommandEnabled(IDC_STOP)) |
| 578 | ExecuteCommand(IDC_STOP); |
| 579 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 580 | |
| 581 | // Zoom |
| 582 | case IDC_ZOOM_PLUS: |
| 583 | Zoom(browser_, content::PAGE_ZOOM_IN); |
| 584 | break; |
| 585 | case IDC_ZOOM_NORMAL: |
| 586 | Zoom(browser_, content::PAGE_ZOOM_RESET); |
| 587 | break; |
| 588 | case IDC_ZOOM_MINUS: |
| 589 | Zoom(browser_, content::PAGE_ZOOM_OUT); |
| 590 | break; |
| 591 | |
| 592 | // Focus various bits of UI |
| 593 | case IDC_FOCUS_TOOLBAR: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 594 | base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 595 | FocusToolbar(browser_); |
| 596 | break; |
| 597 | case IDC_FOCUS_LOCATION: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 598 | base::RecordAction(base::UserMetricsAction("Accel_Focus_Location")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 599 | FocusLocationBar(browser_); |
| 600 | break; |
| 601 | case IDC_FOCUS_SEARCH: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 602 | base::RecordAction(base::UserMetricsAction("Accel_Focus_Search")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 603 | FocusSearch(browser_); |
| 604 | break; |
| 605 | case IDC_FOCUS_MENU_BAR: |
| 606 | FocusAppMenu(browser_); |
| 607 | break; |
| 608 | case IDC_FOCUS_BOOKMARKS: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 609 | base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 610 | FocusBookmarksToolbar(browser_); |
| 611 | break; |
| David Tseng | c0b1b64 | 2018-01-24 07:12:27 | [diff] [blame] | 612 | case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY: |
| 613 | FocusInactivePopupForAccessibility(browser_); |
| [email protected] | 822ca8c6 | 2013-04-19 00:49:15 | [diff] [blame] | 614 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 615 | case IDC_FOCUS_NEXT_PANE: |
| 616 | FocusNextPane(browser_); |
| 617 | break; |
| 618 | case IDC_FOCUS_PREVIOUS_PANE: |
| 619 | FocusPreviousPane(browser_); |
| 620 | break; |
| 621 | |
| 622 | // Show various bits of UI |
| 623 | case IDC_OPEN_FILE: |
| 624 | browser_->OpenFile(); |
| 625 | break; |
| Alan Cutter | 81ac72668 | 2018-09-25 00:18:36 | [diff] [blame] | 626 | case IDC_CREATE_SHORTCUT: |
| Alan Cutter | 98844a9fa | 2019-06-19 21:11:40 | [diff] [blame] | 627 | base::RecordAction(base::UserMetricsAction("CreateShortcut")); |
| Glen Robertson | b9d2741 | 2020-01-09 06:48:13 | [diff] [blame] | 628 | web_app::CreateWebAppFromCurrentWebContents( |
| 629 | browser_, true /* force_shortcut_app */); |
| Alan Cutter | 81ac72668 | 2018-09-25 00:18:36 | [diff] [blame] | 630 | break; |
| 631 | case IDC_INSTALL_PWA: |
| Alan Cutter | 98844a9fa | 2019-06-19 21:11:40 | [diff] [blame] | 632 | base::RecordAction(base::UserMetricsAction("InstallWebAppFromMenu")); |
| Glen Robertson | b9d2741 | 2020-01-09 06:48:13 | [diff] [blame] | 633 | web_app::CreateWebAppFromCurrentWebContents( |
| 634 | browser_, false /* force_shortcut_app */); |
| [email protected] | 488e395 | 2013-11-18 05:29:14 | [diff] [blame] | 635 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 636 | case IDC_DEV_TOOLS: |
| [email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 637 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 638 | break; |
| 639 | case IDC_DEV_TOOLS_CONSOLE: |
| einbinder | dfa567b | 2016-12-16 01:15:52 | [diff] [blame] | 640 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 641 | break; |
| [email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 642 | case IDC_DEV_TOOLS_DEVICES: |
| 643 | InspectUI::InspectDevices(browser_); |
| 644 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 645 | case IDC_DEV_TOOLS_INSPECT: |
| [email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 646 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 647 | break; |
| [email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 648 | case IDC_DEV_TOOLS_TOGGLE: |
| [email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 649 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle()); |
| [email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 650 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 651 | case IDC_TASK_MANAGER: |
| [email protected] | 29c262de | 2013-06-22 15:39:38 | [diff] [blame] | 652 | OpenTaskManager(browser_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 653 | break; |
| caelyn | 4e4e08a | 2015-02-04 21:27:49 | [diff] [blame] | 654 | #if defined(OS_CHROMEOS) |
| 655 | case IDC_TAKE_SCREENSHOT: |
| 656 | TakeScreenshot(); |
| 657 | break; |
| 658 | #endif |
| Nico Weber | 0cc7112 | 2019-07-29 17:30:40 | [diff] [blame] | 659 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 660 | case IDC_FEEDBACK: |
| afakhry | f4575bd | 2017-04-28 02:21:04 | [diff] [blame] | 661 | OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 662 | break; |
| [email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 663 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 664 | case IDC_SHOW_BOOKMARK_BAR: |
| 665 | ToggleBookmarkBar(browser_); |
| 666 | break; |
| Elly Fong-Jones | 2d688ae | 2020-03-31 20:41:47 | [diff] [blame] | 667 | case IDC_SHOW_FULL_URLS: |
| 668 | ToggleShowFullURLs(browser_); |
| 669 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 670 | case IDC_PROFILING_ENABLED: |
| Bryce Thomas | 96b0777 | 2018-11-07 03:04:15 | [diff] [blame] | 671 | content::Profiling::Toggle(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 672 | break; |
| Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 673 | case IDC_CARET_BROWSING_TOGGLE: |
| 674 | ToggleCaretBrowsing(browser_); |
| 675 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 676 | |
| 677 | case IDC_SHOW_BOOKMARK_MANAGER: |
| 678 | ShowBookmarkManager(browser_); |
| 679 | break; |
| 680 | case IDC_SHOW_APP_MENU: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 681 | base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 682 | ShowAppMenu(browser_); |
| 683 | break; |
| 684 | case IDC_SHOW_AVATAR_MENU: |
| 685 | ShowAvatarMenu(browser_); |
| 686 | break; |
| 687 | case IDC_SHOW_HISTORY: |
| 688 | ShowHistory(browser_); |
| 689 | break; |
| 690 | case IDC_SHOW_DOWNLOADS: |
| 691 | ShowDownloads(browser_); |
| 692 | break; |
| 693 | case IDC_MANAGE_EXTENSIONS: |
| [email protected] | bc9833c3 | 2013-02-28 04:05:08 | [diff] [blame] | 694 | ShowExtensions(browser_, std::string()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 695 | break; |
| 696 | case IDC_OPTIONS: |
| 697 | ShowSettings(browser_); |
| 698 | break; |
| 699 | case IDC_EDIT_SEARCH_ENGINES: |
| 700 | ShowSearchEngineSettings(browser_); |
| 701 | break; |
| 702 | case IDC_VIEW_PASSWORDS: |
| 703 | ShowPasswordManager(browser_); |
| 704 | break; |
| 705 | case IDC_CLEAR_BROWSING_DATA: |
| 706 | ShowClearBrowsingDataDialog(browser_); |
| 707 | break; |
| 708 | case IDC_IMPORT_SETTINGS: |
| 709 | ShowImportDialog(browser_); |
| 710 | break; |
| [email protected] | 9b7ab88 | 2012-09-10 23:46:36 | [diff] [blame] | 711 | case IDC_TOGGLE_REQUEST_TABLET_SITE: |
| 712 | ToggleRequestTabletSite(browser_); |
| 713 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 714 | case IDC_ABOUT: |
| 715 | ShowAboutChrome(browser_); |
| 716 | break; |
| 717 | case IDC_UPGRADE_DIALOG: |
| 718 | OpenUpdateChromeDialog(browser_); |
| 719 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 720 | case IDC_HELP_PAGE_VIA_KEYBOARD: |
| 721 | ShowHelp(browser_, HELP_SOURCE_KEYBOARD); |
| 722 | break; |
| 723 | case IDC_HELP_PAGE_VIA_MENU: |
| 724 | ShowHelp(browser_, HELP_SOURCE_MENU); |
| 725 | break; |
| Bret Sepulveda | 2d01866 | 2017-05-18 21:31:48 | [diff] [blame] | 726 | case IDC_SHOW_BETA_FORUM: |
| 727 | ShowBetaForum(browser_); |
| 728 | break; |
| David Roger | 7e25dff | 2019-02-07 09:03:17 | [diff] [blame] | 729 | #if !defined(OS_CHROMEOS) |
| estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 730 | case IDC_SHOW_SIGNIN: |
| gogerald | 71bf6c90 | 2015-12-08 00:49:37 | [diff] [blame] | 731 | ShowBrowserSigninOrSettings( |
| 732 | browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU); |
| estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 733 | break; |
| David Roger | 7e25dff | 2019-02-07 09:03:17 | [diff] [blame] | 734 | #endif |
| [email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 735 | case IDC_DISTILL_PAGE: |
| Aran Gilman | 6586e8f | 2019-06-03 18:50:56 | [diff] [blame] | 736 | ToggleDistilledView(browser_); |
| [email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 737 | break; |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 738 | case IDC_ROUTE_MEDIA: |
| Takumi Fujimoto | a8bc3c9 | 2019-12-26 20:12:10 | [diff] [blame] | 739 | RouteMediaInvokedFromAppMenu(browser_); |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 740 | break; |
| Tommy Steimel | c447798 | 2017-11-29 18:07:18 | [diff] [blame] | 741 | case IDC_WINDOW_MUTE_SITE: |
| 742 | MuteSite(browser_); |
| ellyjones | 0101ba0 | 2017-05-19 15:50:26 | [diff] [blame] | 743 | break; |
| 744 | case IDC_WINDOW_PIN_TAB: |
| 745 | PinTab(browser_); |
| 746 | break; |
| Connie Wan | 303e29e | 2020-01-31 18:16:56 | [diff] [blame] | 747 | case IDC_WINDOW_GROUP_TAB: |
| 748 | GroupTab(browser_); |
| 749 | break; |
| Elly Fong-Jones | 2d0443cb | 2019-11-14 15:04:20 | [diff] [blame] | 750 | case IDC_WINDOW_CLOSE_TABS_TO_RIGHT: |
| 751 | CloseTabsToRight(browser_); |
| 752 | break; |
| 753 | case IDC_WINDOW_CLOSE_OTHER_TABS: |
| 754 | CloseOtherTabs(browser_); |
| 755 | break; |
| Yann Dago | cd13225a | 2019-03-07 18:39:05 | [diff] [blame] | 756 | case IDC_SHOW_MANAGEMENT_PAGE: { |
| Yann Dago | c1d1c4af | 2019-04-17 13:40:51 | [diff] [blame] | 757 | ShowSingletonTab(browser_, GURL(kChromeUIManagementURL)); |
| Nicolas Ouellet-payeur | 82eb65b | 2018-11-05 16:49:27 | [diff] [blame] | 758 | break; |
| Yann Dago | cd13225a | 2019-03-07 18:39:05 | [diff] [blame] | 759 | } |
| Elly Fong-Jones | 5e6baaf | 2019-10-10 23:17:14 | [diff] [blame] | 760 | case IDC_MUTE_TARGET_SITE: |
| 761 | MuteSiteForKeyboardFocusedTab(browser_); |
| 762 | break; |
| 763 | case IDC_PIN_TARGET_TAB: |
| 764 | PinKeyboardFocusedTab(browser_); |
| 765 | break; |
| Connie Wan | 303e29e | 2020-01-31 18:16:56 | [diff] [blame] | 766 | case IDC_GROUP_TARGET_TAB: |
| 767 | GroupKeyboardFocusedTab(browser_); |
| 768 | break; |
| Elly Fong-Jones | 5e6baaf | 2019-10-10 23:17:14 | [diff] [blame] | 769 | case IDC_DUPLICATE_TARGET_TAB: |
| 770 | DuplicateKeyboardFocusedTab(browser_); |
| 771 | break; |
| Christopher Lam | 0dbac2b | 2017-11-14 07:12:10 | [diff] [blame] | 772 | // Hosted App commands |
| 773 | case IDC_COPY_URL: |
| 774 | CopyURL(browser_); |
| 775 | break; |
| 776 | case IDC_OPEN_IN_CHROME: |
| 777 | OpenInChrome(browser_); |
| 778 | break; |
| 779 | case IDC_SITE_SETTINGS: |
| 780 | ShowSiteSettings( |
| 781 | browser_, |
| 782 | browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL()); |
| 783 | break; |
| Alan Cutter | a99d152 | 2019-09-12 02:09:22 | [diff] [blame] | 784 | case IDC_WEB_APP_MENU_APP_INFO: { |
| Dana Fried | 08b774a | 2019-05-10 18:21:48 | [diff] [blame] | 785 | content::WebContents* const web_contents = |
| 786 | browser_->tab_strip_model()->GetActiveWebContents(); |
| 787 | if (web_contents) { |
| 788 | ShowPageInfoDialog(web_contents, |
| 789 | base::BindOnce(&AppInfoDialogClosedCallback, |
| 790 | base::Unretained(web_contents)), |
| 791 | bubble_anchor_util::kAppMenuButton); |
| 792 | } |
| Christopher Lam | 86b5271 | 2017-12-04 01:58:33 | [diff] [blame] | 793 | break; |
| Dana Fried | 08b774a | 2019-05-10 18:21:48 | [diff] [blame] | 794 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 795 | default: |
| 796 | LOG(WARNING) << "Received Unimplemented Command: " << id; |
| 797 | break; |
| 798 | } |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 799 | |
| 800 | return true; |
| 801 | } |
| 802 | |
| 803 | void BrowserCommandController::AddCommandObserver(int id, |
| 804 | CommandObserver* observer) { |
| 805 | command_updater_.AddCommandObserver(id, observer); |
| 806 | } |
| 807 | |
| 808 | void BrowserCommandController::RemoveCommandObserver( |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 809 | int id, |
| 810 | CommandObserver* observer) { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 811 | command_updater_.RemoveCommandObserver(id, observer); |
| 812 | } |
| 813 | |
| 814 | void BrowserCommandController::RemoveCommandObserver( |
| 815 | CommandObserver* observer) { |
| 816 | command_updater_.RemoveCommandObserver(observer); |
| 817 | } |
| 818 | |
| 819 | bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) { |
| 820 | if (is_locked_fullscreen_) |
| 821 | return false; |
| 822 | |
| 823 | return command_updater_.UpdateCommandEnabled(id, state); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 824 | } |
| 825 | |
| Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 826 | //////////////////////////////////////////////////////////////////////////////// |
| 827 | // BrowserCommandController, SigninPrefObserver implementation: |
| 828 | |
| 829 | void BrowserCommandController::OnSigninAllowedPrefChange() { |
| 830 | // For unit tests, we don't have a window. |
| 831 | if (!window()) |
| 832 | return; |
| 833 | UpdateShowSyncState(IsShowingMainUI()); |
| 834 | } |
| 835 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 836 | // BrowserCommandController, TabStripModelObserver implementation: |
| 837 | |
| sangwoo.ko | 1ae265f1 | 2018-10-18 08:30:28 | [diff] [blame] | 838 | void BrowserCommandController::OnTabStripModelChanged( |
| 839 | TabStripModel* tab_strip_model, |
| 840 | const TabStripModelChange& change, |
| 841 | const TabStripSelectionChange& selection) { |
| Dana Fried | a391e6ce | 2019-05-08 00:00:20 | [diff] [blame] | 842 | std::vector<content::WebContents*> new_contents; |
| 843 | std::vector<content::WebContents*> old_contents; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 844 | |
| Dana Fried | a391e6ce | 2019-05-08 00:00:20 | [diff] [blame] | 845 | switch (change.type()) { |
| 846 | case TabStripModelChange::kInserted: |
| 847 | for (const auto& contents : change.GetInsert()->contents) |
| 848 | new_contents.push_back(contents.contents); |
| 849 | break; |
| 850 | case TabStripModelChange::kReplaced: { |
| 851 | auto* replace = change.GetReplace(); |
| 852 | new_contents.push_back(replace->new_contents); |
| 853 | old_contents.push_back(replace->old_contents); |
| 854 | break; |
| sangwoo.ko | 1ae265f1 | 2018-10-18 08:30:28 | [diff] [blame] | 855 | } |
| Dana Fried | a391e6ce | 2019-05-08 00:00:20 | [diff] [blame] | 856 | case TabStripModelChange::kRemoved: |
| 857 | for (const auto& contents : change.GetRemove()->contents) |
| 858 | old_contents.push_back(contents.contents); |
| 859 | break; |
| 860 | default: |
| 861 | break; |
| sangwoo.ko | 1ae265f1 | 2018-10-18 08:30:28 | [diff] [blame] | 862 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 863 | } |
| 864 | |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 865 | void BrowserCommandController::TabBlockedStateChanged( |
| 866 | content::WebContents* contents, |
| 867 | int index) { |
| 868 | PrintingStateChanged(); |
| 869 | FullscreenStateChanged(); |
| 870 | UpdateCommandsForFind(); |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 871 | UpdateCommandsForMediaRouter(); |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 872 | } |
| 873 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 874 | //////////////////////////////////////////////////////////////////////////////// |
| 875 | // BrowserCommandController, TabRestoreServiceObserver implementation: |
| 876 | |
| 877 | void BrowserCommandController::TabRestoreServiceChanged( |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 878 | sessions::TabRestoreService* service) { |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 879 | UpdateTabRestoreCommandState(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | void BrowserCommandController::TabRestoreServiceDestroyed( |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 883 | sessions::TabRestoreService* service) { |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 884 | service->RemoveObserver(this); |
| 885 | } |
| 886 | |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 887 | void BrowserCommandController::TabRestoreServiceLoaded( |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 888 | sessions::TabRestoreService* service) { |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 889 | UpdateTabRestoreCommandState(); |
| 890 | } |
| 891 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 892 | //////////////////////////////////////////////////////////////////////////////// |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 893 | // BrowserCommandController, private: |
| 894 | |
| [email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 895 | bool BrowserCommandController::IsShowingMainUI() { |
| manuk | f1a11639 | 2018-10-25 16:28:24 | [diff] [blame] | 896 | return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP); |
| 897 | } |
| 898 | |
| 899 | bool BrowserCommandController::IsShowingLocationBar() { |
| 900 | return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | void BrowserCommandController::InitCommandState() { |
| 904 | // All browser commands whose state isn't set automagically some other way |
| 905 | // (like Back & Forward with initial page load) must have their state |
| 906 | // initialized here, otherwise they will be forever disabled. |
| 907 | |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 908 | if (is_locked_fullscreen_) |
| 909 | return; |
| 910 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 911 | // Navigation commands |
| 912 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
| toyoshim | 7dad4b118 | 2016-04-01 14:28:05 | [diff] [blame] | 913 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true); |
| [email protected] | 58e2903 | 2012-08-06 20:19:57 | [diff] [blame] | 914 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 915 | |
| 916 | // Window management commands |
| 917 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 918 | command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); |
| 919 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); |
| 920 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 921 | UpdateTabRestoreCommandState(); |
| [email protected] | d28d378 | 2013-02-26 16:31:55 | [diff] [blame] | 922 | command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 923 | command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 924 | #if defined(OS_CHROMEOS) |
| James Cook | 934abaf | 2017-09-19 22:21:58 | [diff] [blame] | 925 | command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true); |
| anina koehler | 038555b | 2020-02-24 13:30:32 | [diff] [blame] | 926 | // The VisitDesktop command is only supported for up to 5 logged in users |
| 927 | // because that's the max number of user sessions. If that number is increased |
| 928 | // the IDC_VISIT_DESKTOP_OF_LRU_USER_ command ids should be updated as well. |
| 929 | // crbug.com/940461 |
| 930 | static_assert( |
| 931 | session_manager::kMaximumNumberOfUserSessions <= |
| 932 | IDC_VISIT_DESKTOP_OF_LRU_USER_LAST - |
| 933 | IDC_VISIT_DESKTOP_OF_LRU_USER_NEXT + 2, |
| 934 | "The max number of user sessions exceeds the number of users supported."); |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 935 | command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true); |
| 936 | command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true); |
| anina koehler | 038555b | 2020-02-24 13:30:32 | [diff] [blame] | 937 | command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_4, true); |
| 938 | command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_5, true); |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 939 | #endif |
| [email protected] | 893124a2 | 2014-04-15 00:45:28 | [diff] [blame] | 940 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| Tom Anderson | f15ede50 | 2017-11-10 03:17:15 | [diff] [blame] | 941 | command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true); |
| 942 | command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true); |
| 943 | command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true); |
| Maksim Sisov | ac76759 | 2018-08-10 08:00:15 | [diff] [blame] | 944 | bool use_system_title_bar = true; |
| 945 | #if defined(USE_OZONE) |
| Maksim Sisov | b0643ebd | 2020-06-22 11:47:31 | [diff] [blame] | 946 | if (features::IsUsingOzonePlatform()) { |
| 947 | use_system_title_bar = ui::OzonePlatform::GetInstance() |
| 948 | ->GetPlatformProperties() |
| 949 | .use_system_title_bar; |
| 950 | } |
| Maksim Sisov | ac76759 | 2018-08-10 08:00:15 | [diff] [blame] | 951 | #endif |
| 952 | command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, |
| 953 | use_system_title_bar); |
| [email protected] | af97be4c6 | 2014-02-13 14:43:34 | [diff] [blame] | 954 | #endif |
| Alan Cutter | 0996580 | 2018-03-27 07:25:29 | [diff] [blame] | 955 | command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 956 | |
| 957 | // Page-related commands |
| [email protected] | 4bee443 | 2014-05-05 13:11:41 | [diff] [blame] | 958 | command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 959 | |
| 960 | // Zoom |
| 961 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
| 962 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
| [email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 963 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 964 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
| 965 | |
| 966 | // Show various bits of UI |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 967 | const bool guest_session = |
| 968 | profile()->IsGuestSession() || profile()->IsSystemProfile(); |
| mlerman | 7831f57d | 2015-05-25 11:40:15 | [diff] [blame] | 969 | DCHECK(!profile()->IsSystemProfile()) |
| 970 | << "Ought to never have browser for the system profile."; |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 971 | const bool normal_window = browser_->is_type_normal(); |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 972 | UpdateOpenFileState(&command_updater_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 973 | UpdateCommandsForDevTools(); |
| 974 | command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 975 | command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 976 | command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| [email protected] | 674b6567 | 2014-06-02 23:21:56 | [diff] [blame] | 977 | command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 978 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
| 979 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
| Bret Sepulveda | 2d01866 | 2017-05-18 21:31:48 | [diff] [blame] | 980 | command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true); |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 981 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 982 | command_updater_.UpdateCommandEnabled( |
| 983 | IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord()); |
| Rohit Agarwal | 2a2230b | 2019-08-21 15:53:41 | [diff] [blame] | 984 | command_updater_.UpdateCommandEnabled( |
| 985 | IDC_CLEAR_BROWSING_DATA, |
| 986 | !guest_session && !profile()->IsIncognitoProfile()); |
| [email protected] | 39d4759 | 2014-01-10 21:42:45 | [diff] [blame] | 987 | #if defined(OS_CHROMEOS) |
| caelyn | 4e4e08a | 2015-02-04 21:27:49 | [diff] [blame] | 988 | command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true); |
| Ramin Halavati | f362b7a | 2019-04-17 05:24:50 | [diff] [blame] | 989 | // Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu |
| 990 | // is only required in incognito mode. |
| Ramin Halavati | 2394dc45 | 2019-05-21 16:21:58 | [diff] [blame] | 991 | if (profile()->IsIncognitoProfile()) |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 992 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true); |
| Ramin Halavati | f362b7a | 2019-04-17 05:24:50 | [diff] [blame] | 993 | #else |
| 994 | if (normal_window) |
| 995 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true); |
| [email protected] | 39d4759 | 2014-01-10 21:42:45 | [diff] [blame] | 996 | #endif |
| siyua | c6e018d | 2019-10-18 01:19:30 | [diff] [blame] | 997 | command_updater_.UpdateCommandEnabled( |
| 998 | IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE, true); |
| 999 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_SIGN_IN_PROMO, true); |
| Dominic Mazzoni | 554089e | 2020-07-31 22:12:04 | [diff] [blame] | 1000 | command_updater_.UpdateCommandEnabled(IDC_CARET_BROWSING_TOGGLE, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1001 | |
| Mihai Sardarescu | 2ec520568 | 2018-09-26 09:20:05 | [diff] [blame] | 1002 | UpdateShowSyncState(true); |
| 1003 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1004 | // Navigation commands |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1005 | command_updater_.UpdateCommandEnabled( |
| 1006 | IDC_HOME, normal_window || browser_->deprecated_is_app()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1007 | |
| Mugdha Lakhani | 23954ef2 | 2020-06-25 21:56:21 | [diff] [blame] | 1008 | const bool is_web_app_or_custom_tab = |
| 1009 | #if defined(OS_CHROMEOS) |
| 1010 | browser_->is_type_custom_tab() || |
| 1011 | #endif |
| Alan Cutter | d0bd5190 | 2019-05-22 04:15:23 | [diff] [blame] | 1012 | web_app::AppBrowserController::IsForWebAppBrowser(browser_); |
| Christopher Lam | 0dbac2b | 2017-11-14 07:12:10 | [diff] [blame] | 1013 | // Hosted app browser commands. |
| Mugdha Lakhani | 23954ef2 | 2020-06-25 21:56:21 | [diff] [blame] | 1014 | command_updater_.UpdateCommandEnabled(IDC_COPY_URL, is_web_app_or_custom_tab); |
| 1015 | command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME, |
| 1016 | is_web_app_or_custom_tab); |
| 1017 | command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS, |
| 1018 | is_web_app_or_custom_tab); |
| 1019 | command_updater_.UpdateCommandEnabled(IDC_WEB_APP_MENU_APP_INFO, |
| 1020 | is_web_app_or_custom_tab); |
| Christopher Lam | 0dbac2b | 2017-11-14 07:12:10 | [diff] [blame] | 1021 | |
| Joel Hockey | 43afbd8 | 2020-02-19 23:55:37 | [diff] [blame] | 1022 | // Tab management commands |
| 1023 | const bool supports_tabs = |
| 1024 | browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP); |
| 1025 | command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, supports_tabs); |
| 1026 | command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, supports_tabs); |
| 1027 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, supports_tabs); |
| 1028 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, supports_tabs); |
| 1029 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, supports_tabs); |
| 1030 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, supports_tabs); |
| 1031 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, supports_tabs); |
| 1032 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, supports_tabs); |
| 1033 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, supports_tabs); |
| 1034 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, supports_tabs); |
| 1035 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, supports_tabs); |
| 1036 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, supports_tabs); |
| 1037 | command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, supports_tabs); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1038 | |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 1039 | // These are always enabled; the menu determines their menu item visibility. |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1040 | command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1041 | |
| [email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 1042 | // Distill current page. |
| Aran Gilman | 7b6ccf5d | 2019-09-05 19:16:02 | [diff] [blame] | 1043 | command_updater_.UpdateCommandEnabled(IDC_DISTILL_PAGE, |
| 1044 | dom_distiller::IsDomDistillerEnabled()); |
| [email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 1045 | |
| Tommy Steimel | c447798 | 2017-11-29 18:07:18 | [diff] [blame] | 1046 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window); |
| ellyjones | 0101ba0 | 2017-05-19 15:50:26 | [diff] [blame] | 1047 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window); |
| Connie Wan | 303e29e | 2020-01-31 18:16:56 | [diff] [blame] | 1048 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB, normal_window); |
| Elly Fong-Jones | 2d0443cb | 2019-11-14 15:04:20 | [diff] [blame] | 1049 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT, |
| 1050 | normal_window); |
| 1051 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS, |
| 1052 | normal_window); |
| ellyjones | 0101ba0 | 2017-05-19 15:50:26 | [diff] [blame] | 1053 | |
| Yuheng Huang | 092c72a9 | 2020-08-10 22:39:30 | [diff] [blame] | 1054 | command_updater_.UpdateCommandEnabled( |
| 1055 | IDC_TAB_SEARCH, base::FeatureList::IsEnabled(features::kTabSearch) && |
| 1056 | browser_->is_type_normal() && |
| 1057 | !browser_->profile()->IsIncognitoProfile()); |
| 1058 | |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 1059 | // Initialize other commands whose state changes based on various conditions. |
| [email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1060 | UpdateCommandsForFullscreenMode(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1061 | UpdateCommandsForContentRestrictionState(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1062 | UpdateCommandsForBookmarkEditing(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1063 | UpdateCommandsForIncognitoAvailability(); |
| Elly Fong-Jones | 5e6baaf | 2019-10-10 23:17:14 | [diff] [blame] | 1064 | UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_)); |
| Dominic Mazzoni | 1e0e5125 | 2020-10-19 19:36:18 | [diff] [blame^] | 1065 | UpdateCommandsForWebContentsFocus(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1066 | } |
| 1067 | |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1068 | // static |
| 1069 | void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( |
| 1070 | CommandUpdater* command_updater, |
| 1071 | Profile* profile) { |
| mlerman | e01e6de | 2014-09-29 19:26:47 | [diff] [blame] | 1072 | const bool guest_session = profile->IsGuestSession(); |
| 1073 | // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession(). |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1074 | IncognitoModePrefs::Availability incognito_availability = |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1075 | IncognitoModePrefs::GetAvailability(profile->GetPrefs()); |
| 1076 | command_updater->UpdateCommandEnabled( |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1077 | IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED); |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1078 | command_updater->UpdateCommandEnabled( |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1079 | IDC_NEW_INCOGNITO_WINDOW, |
| mlerman | e01e6de | 2014-09-29 19:26:47 | [diff] [blame] | 1080 | incognito_availability != IncognitoModePrefs::DISABLED && !guest_session); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1081 | |
| [email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1082 | const bool forced_incognito = |
| 1083 | incognito_availability == IncognitoModePrefs::FORCED || |
| 1084 | guest_session; // Guest always runs in Incognito mode. |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1085 | command_updater->UpdateCommandEnabled( |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1086 | IDC_SHOW_BOOKMARK_MANAGER, |
| [email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1087 | browser_defaults::bookmarks_enabled && !forced_incognito); |
| Devlin Cronin | 21dba42 | 2018-05-30 15:45:16 | [diff] [blame] | 1088 | extensions::ExtensionService* extension_service = |
| [email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 1089 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| [email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1090 | const bool enable_extensions = |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1091 | extension_service && extension_service->extensions_enabled(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1092 | |
| Elly Fong-Jones | 2d688ae | 2020-03-31 20:41:47 | [diff] [blame] | 1093 | command_updater->UpdateCommandEnabled( |
| 1094 | IDC_SHOW_FULL_URLS, |
| 1095 | base::FeatureList::IsEnabled(omnibox::kOmniboxContextMenuShowFullUrls)); |
| 1096 | |
| [email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1097 | // Bookmark manager and settings page/subpages are forced to open in normal |
| 1098 | // mode. For this reason we disable these commands when incognito is forced. |
| 1099 | command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
| 1100 | enable_extensions && !forced_incognito); |
| 1101 | |
| 1102 | command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito); |
| 1103 | command_updater->UpdateCommandEnabled(IDC_OPTIONS, |
| 1104 | !forced_incognito || guest_session); |
| estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 1105 | command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1109 | if (is_locked_fullscreen_) |
| 1110 | return; |
| 1111 | |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1112 | UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); |
| 1113 | |
| [email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 1114 | if (!IsShowingMainUI()) { |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1115 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); |
| 1116 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); |
| 1117 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | void BrowserCommandController::UpdateCommandsForTabState() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1121 | if (is_locked_fullscreen_) |
| 1122 | return; |
| 1123 | |
| [email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 1124 | WebContents* current_web_contents = |
| 1125 | browser_->tab_strip_model()->GetActiveWebContents(); |
| [email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 1126 | if (!current_web_contents) // May be NULL during tab restore. |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1127 | return; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1128 | |
| 1129 | // Navigation commands |
| 1130 | command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); |
| 1131 | command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_)); |
| 1132 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_)); |
| toyoshim | 7dad4b118 | 2016-04-01 14:28:05 | [diff] [blame] | 1133 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1134 | CanReload(browser_)); |
| [email protected] | 58e2903 | 2012-08-06 20:19:57 | [diff] [blame] | 1135 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, |
| 1136 | CanReload(browser_)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1137 | |
| 1138 | // Window management commands |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1139 | command_updater_.UpdateCommandEnabled( |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1140 | IDC_DUPLICATE_TAB, |
| 1141 | !browser_->deprecated_is_app() && CanDuplicateTab(browser_)); |
| Tommy Steimel | c447798 | 2017-11-29 18:07:18 | [diff] [blame] | 1142 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1143 | !browser_->deprecated_is_app()); |
| ellyjones | 0101ba0 | 2017-05-19 15:50:26 | [diff] [blame] | 1144 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1145 | !browser_->deprecated_is_app()); |
| Connie Wan | 303e29e | 2020-01-31 18:16:56 | [diff] [blame] | 1146 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB, |
| 1147 | !browser_->deprecated_is_app()); |
| Elly Fong-Jones | 2d0443cb | 2019-11-14 15:04:20 | [diff] [blame] | 1148 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT, |
| 1149 | CanCloseTabsToRight(browser_)); |
| 1150 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS, |
| 1151 | CanCloseOtherTabs(browser_)); |
| Leonard Grey | f13493b | 2019-12-19 18:12:57 | [diff] [blame] | 1152 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_TO_NEW_WINDOW, |
| Leonard Grey | a8ecaa3 | 2020-01-07 20:57:41 | [diff] [blame] | 1153 | CanMoveActiveTabToNewWindow(browser_)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1154 | |
| 1155 | // Page-related commands |
| 1156 | window()->SetStarredState( |
| [email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 1157 | BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred()); |
| [email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 1158 | window()->ZoomChangedForActiveTab(false); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1159 | command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, |
| 1160 | CanViewSource(browser_)); |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1161 | if (browser_->is_type_devtools()) |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1162 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); |
| 1163 | |
| Glen Robertson | b9d2741 | 2020-01-09 06:48:13 | [diff] [blame] | 1164 | bool can_create_web_app = web_app::CanCreateWebApp(browser_); |
| 1165 | command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA, can_create_web_app); |
| Alan Cutter | 81ac72668 | 2018-09-25 00:18:36 | [diff] [blame] | 1166 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT, |
| Glen Robertson | b9d2741 | 2020-01-09 06:48:13 | [diff] [blame] | 1167 | can_create_web_app); |
| 1168 | // Note that additional logic in AppMenuModel::Build() controls the presence |
| 1169 | // of this command. |
| Alan Cutter | 403cebb | 2018-05-17 05:22:45 | [diff] [blame] | 1170 | command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, |
| Glen Robertson | b9d2741 | 2020-01-09 06:48:13 | [diff] [blame] | 1171 | web_app::CanPopOutWebApp(profile())); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1172 | |
| [email protected] | 9b7ab88 | 2012-09-10 23:46:36 | [diff] [blame] | 1173 | command_updater_.UpdateCommandEnabled( |
| 1174 | IDC_TOGGLE_REQUEST_TABLET_SITE, |
| 1175 | CanRequestTabletSite(current_web_contents)); |
| 1176 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1177 | UpdateCommandsForContentRestrictionState(); |
| 1178 | UpdateCommandsForBookmarkEditing(); |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 1179 | UpdateCommandsForFind(); |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 1180 | UpdateCommandsForMediaRouter(); |
| [email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 1181 | // Update the zoom commands when an active tab is selected. |
| 1182 | UpdateCommandsForZoomState(); |
| Elly Fong-Jones | 5e6baaf | 2019-10-10 23:17:14 | [diff] [blame] | 1183 | UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_)); |
| [email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | void BrowserCommandController::UpdateCommandsForZoomState() { |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1187 | WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents(); |
| [email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 1188 | if (!contents) |
| 1189 | return; |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1190 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents)); |
| a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 1191 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, |
| ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 1192 | CanResetZoom(contents)); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1193 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | void BrowserCommandController::UpdateCommandsForContentRestrictionState() { |
| 1197 | int restrictions = GetContentRestrictions(browser_); |
| 1198 | |
| 1199 | command_updater_.UpdateCommandEnabled( |
| [email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1200 | IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1201 | command_updater_.UpdateCommandEnabled( |
| [email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1202 | IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1203 | command_updater_.UpdateCommandEnabled( |
| [email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1204 | IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1205 | UpdateSaveAsState(); |
| 1206 | UpdatePrintingState(); |
| 1207 | } |
| 1208 | |
| 1209 | void BrowserCommandController::UpdateCommandsForDevTools() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1210 | if (is_locked_fullscreen_) |
| 1211 | return; |
| 1212 | |
| Pavol Marko | 56df027 | 2018-07-04 17:55:04 | [diff] [blame] | 1213 | bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor( |
| 1214 | profile(), browser_->tab_strip_model()->GetActiveWebContents()); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1215 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1216 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, |
| 1217 | dev_tools_enabled); |
| [email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 1218 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES, |
| 1219 | dev_tools_enabled); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1220 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT, |
| 1221 | dev_tools_enabled); |
| [email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 1222 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE, |
| 1223 | dev_tools_enabled); |
| Avi Drissman | 73ea864d | 2020-07-29 19:56:15 | [diff] [blame] | 1224 | #if defined(OS_MAC) |
| spqchan | 2c5d541e | 2017-10-25 07:07:11 | [diff] [blame] | 1225 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS, |
| 1226 | dev_tools_enabled); |
| 1227 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | void BrowserCommandController::UpdateCommandsForBookmarkEditing() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1231 | if (is_locked_fullscreen_) |
| 1232 | return; |
| 1233 | |
| Peter Kasting | 32bb260 | 2019-08-22 19:01:43 | [diff] [blame] | 1234 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_THIS_TAB, |
| 1235 | CanBookmarkCurrentTab(browser_)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1236 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, |
| 1237 | CanBookmarkAllTabs(browser_)); |
| thestig | 5149d27 | 2014-10-30 07:25:29 | [diff] [blame] | 1238 | #if defined(OS_WIN) |
| 1239 | command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true); |
| 1240 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | void BrowserCommandController::UpdateCommandsForBookmarkBar() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1244 | if (is_locked_fullscreen_) |
| 1245 | return; |
| 1246 | |
| tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 1247 | command_updater_.UpdateCommandEnabled( |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1248 | IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled && |
| 1249 | !profile()->IsGuestSession() && |
| 1250 | !profile()->IsSystemProfile() && |
| 1251 | !profile()->GetPrefs()->IsManagedPreference( |
| 1252 | bookmarks::prefs::kShowBookmarkBar) && |
| 1253 | IsShowingMainUI()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1254 | } |
| 1255 | |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 1256 | void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1257 | if (is_locked_fullscreen_) |
| 1258 | return; |
| 1259 | |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 1260 | UpdateSaveAsState(); |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1261 | UpdateOpenFileState(&command_updater_); |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 1262 | } |
| 1263 | |
| [email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1264 | void BrowserCommandController::UpdateCommandsForFullscreenMode() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1265 | if (is_locked_fullscreen_) |
| 1266 | return; |
| 1267 | |
| zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 1268 | const bool is_fullscreen = window() && window()->IsFullscreen(); |
| 1269 | const bool show_main_ui = IsShowingMainUI(); |
| manuk | f1a11639 | 2018-10-25 16:28:24 | [diff] [blame] | 1270 | const bool show_location_bar = IsShowingLocationBar(); |
| 1271 | |
| zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 1272 | const bool main_not_fullscreen = show_main_ui && !is_fullscreen; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1273 | |
| 1274 | // Navigation commands |
| 1275 | command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); |
| 1276 | |
| 1277 | // Window management commands |
| 1278 | command_updater_.UpdateCommandEnabled( |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1279 | IDC_SHOW_AS_TAB, !browser_->is_type_normal() && !is_fullscreen); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1280 | |
| 1281 | // Focus various bits of UI |
| 1282 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); |
| manuk | f1a11639 | 2018-10-25 16:28:24 | [diff] [blame] | 1283 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1284 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1285 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR, |
| 1286 | main_not_fullscreen); |
| 1287 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, |
| 1288 | main_not_fullscreen); |
| 1289 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, |
| 1290 | main_not_fullscreen); |
| 1291 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS, |
| 1292 | main_not_fullscreen); |
| [email protected] | 822ca8c6 | 2013-04-19 00:49:15 | [diff] [blame] | 1293 | command_updater_.UpdateCommandEnabled( |
| David Tseng | c0b1b64 | 2018-01-24 07:12:27 | [diff] [blame] | 1294 | IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1295 | |
| 1296 | // Show various bits of UI |
| 1297 | command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| Nico Weber | 0cc7112 | 2019-07-29 17:30:40 | [diff] [blame] | 1298 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
| Fabio Rocha | 19bf426 | 2019-04-04 01:05:18 | [diff] [blame] | 1299 | command_updater_.UpdateCommandEnabled( |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1300 | IDC_FEEDBACK, show_main_ui || browser_->is_type_devtools()); |
| [email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 1301 | #endif |
| Mihai Sardarescu | 2ec520568 | 2018-09-26 09:20:05 | [diff] [blame] | 1302 | UpdateShowSyncState(show_main_ui); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1303 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1304 | command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1305 | command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1306 | command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| Travis Skare | 5193bbe1 | 2020-04-15 18:31:03 | [diff] [blame] | 1307 | command_updater_.UpdateCommandEnabled(IDC_QRCODE_GENERATOR, show_main_ui); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1308 | command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| Tina Wang | f09681ac | 2019-03-27 20:52:10 | [diff] [blame] | 1309 | command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui); |
| Tina Wang | fa01699 | 2019-05-31 00:01:15 | [diff] [blame] | 1310 | command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF_SINGLE_TARGET, |
| 1311 | show_main_ui); |
| Yann Dago | 70ca3dd | 2019-02-27 01:12:35 | [diff] [blame] | 1312 | command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true); |
| primiano | d3a81ab | 2016-01-25 22:21:15 | [diff] [blame] | 1313 | |
| 1314 | if (base::debug::IsProfilingSupported()) |
| 1315 | command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1316 | |
| Avi Drissman | 73ea864d | 2020-07-29 19:56:15 | [diff] [blame] | 1317 | #if !defined(OS_MAC) |
| zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 1318 | // Disable toggling into fullscreen mode if disallowed by pref. |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1319 | const bool fullscreen_enabled = |
| 1320 | is_fullscreen || |
| zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 1321 | profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed); |
| 1322 | #else |
| 1323 | const bool fullscreen_enabled = true; |
| [email protected] | 00a1cc5b | 2012-11-07 13:44:51 | [diff] [blame] | 1324 | #endif |
| 1325 | |
| 1326 | command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); |
| spqchan | b8ffc7d | 2015-11-17 01:17:21 | [diff] [blame] | 1327 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, |
| 1328 | fullscreen_enabled); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1329 | |
| 1330 | UpdateCommandsForBookmarkBar(); |
| zijiehe | db473d55 | 2017-02-24 01:13:41 | [diff] [blame] | 1331 | UpdateCommandsForIncognitoAvailability(); |
| Alan Cutter | 167dfe8 | 2018-04-11 09:06:00 | [diff] [blame] | 1332 | UpdateCommandsForHostedAppAvailability(); |
| 1333 | } |
| 1334 | |
| 1335 | void BrowserCommandController::UpdateCommandsForHostedAppAvailability() { |
| 1336 | bool has_toolbar = |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1337 | browser_->is_type_normal() || |
| Alan Cutter | d0bd5190 | 2019-05-22 04:15:23 | [diff] [blame] | 1338 | web_app::AppBrowserController::IsForWebAppBrowser(browser_); |
| Alan Cutter | 167dfe8 | 2018-04-11 09:06:00 | [diff] [blame] | 1339 | if (window() && window()->ShouldHideUIForFullscreen()) |
| 1340 | has_toolbar = false; |
| 1341 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar); |
| 1342 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar); |
| 1343 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar); |
| 1344 | command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1345 | } |
| 1346 | |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1347 | #if defined(OS_CHROMEOS) |
| 1348 | namespace { |
| 1349 | |
| 1350 | #if DCHECK_IS_ON() |
| Dana Fried | 88e6f47 | 2020-06-30 22:47:40 | [diff] [blame] | 1351 | // Makes sure that all commands that are not allowlisted are disabled. DCHECKs |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1352 | // otherwise. Compiled only in debug mode. |
| Dana Fried | 88e6f47 | 2020-06-30 22:47:40 | [diff] [blame] | 1353 | void NonAllowlistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) { |
| 1354 | constexpr int kAllowlistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE}; |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1355 | |
| Dana Fried | 88e6f47 | 2020-06-30 22:47:40 | [diff] [blame] | 1356 | // Go through all the command ids, skip the allowlisted ones. |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1357 | for (int id : command_updater->GetAllIds()) { |
| Dana Fried | 88e6f47 | 2020-06-30 22:47:40 | [diff] [blame] | 1358 | if (base::Contains(kAllowlistedIds, id)) { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1359 | continue; |
| 1360 | } |
| 1361 | DCHECK(!command_updater->IsCommandEnabled(id)); |
| 1362 | } |
| 1363 | } |
| 1364 | #endif |
| 1365 | |
| 1366 | } // namespace |
| 1367 | |
| 1368 | void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() { |
| Ivan Sandrk | e0e9245 | 2019-03-21 09:32:48 | [diff] [blame] | 1369 | bool is_locked_fullscreen = |
| 1370 | platform_util::IsBrowserLockedFullscreen(browser_); |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1371 | // Sanity check to make sure this function is called only on state change. |
| 1372 | DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_); |
| 1373 | if (is_locked_fullscreen == is_locked_fullscreen_) |
| 1374 | return; |
| 1375 | is_locked_fullscreen_ = is_locked_fullscreen; |
| 1376 | |
| 1377 | if (is_locked_fullscreen_) { |
| 1378 | command_updater_.DisableAllCommands(); |
| Dana Fried | 88e6f47 | 2020-06-30 22:47:40 | [diff] [blame] | 1379 | // Update the state of allowlisted commands: |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1380 | // IDC_CUT/IDC_COPY/IDC_PASTE, |
| 1381 | UpdateCommandsForContentRestrictionState(); |
| Ivan Sandrk | 6ac9c9a | 2018-12-14 14:15:07 | [diff] [blame] | 1382 | // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen. |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1383 | // All other commands will be disabled (there is an early return in their |
| 1384 | // corresponding UpdateCommandsFor* functions). |
| 1385 | #if DCHECK_IS_ON() |
| Dana Fried | 88e6f47 | 2020-06-30 22:47:40 | [diff] [blame] | 1386 | NonAllowlistedCommandsAreDisabled(&command_updater_); |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1387 | #endif |
| 1388 | } else { |
| 1389 | // Do an init call to re-initialize command state after the |
| 1390 | // DisableAllCommands. |
| 1391 | InitCommandState(); |
| 1392 | } |
| 1393 | } |
| 1394 | #endif |
| 1395 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1396 | void BrowserCommandController::UpdatePrintingState() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1397 | if (is_locked_fullscreen_) |
| 1398 | return; |
| 1399 | |
| [email protected] | d53e403 | 2012-06-29 18:58:34 | [diff] [blame] | 1400 | bool print_enabled = CanPrint(browser_); |
| 1401 | command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
| Lei Zhang | 48a4a526 | 2018-04-17 20:18:44 | [diff] [blame] | 1402 | #if BUILDFLAG(ENABLE_PRINTING) |
| vitalybuka | f9433e4 | 2014-09-08 10:04:55 | [diff] [blame] | 1403 | command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, |
| 1404 | CanBasicPrint(browser_)); |
| Lei Zhang | 48a4a526 | 2018-04-17 20:18:44 | [diff] [blame] | 1405 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | void BrowserCommandController::UpdateSaveAsState() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1409 | if (is_locked_fullscreen_) |
| 1410 | return; |
| 1411 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1412 | command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
| 1413 | } |
| 1414 | |
| Mihai Sardarescu | 2ec520568 | 2018-09-26 09:20:05 | [diff] [blame] | 1415 | void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) { |
| 1416 | if (is_locked_fullscreen_) |
| 1417 | return; |
| 1418 | |
| Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 1419 | command_updater_.UpdateCommandEnabled( |
| Mihai Sardarescu | 290bc88 | 2018-10-12 10:48:14 | [diff] [blame] | 1420 | IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue()); |
| Mihai Sardarescu | 2ec520568 | 2018-09-26 09:20:05 | [diff] [blame] | 1421 | } |
| 1422 | |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1423 | // static |
| 1424 | void BrowserCommandController::UpdateOpenFileState( |
| 1425 | CommandUpdater* command_updater) { |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1426 | bool enabled = true; |
| 1427 | PrefService* local_state = g_browser_process->local_state(); |
| 1428 | if (local_state) |
| 1429 | enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 1430 | |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1431 | command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | void BrowserCommandController::UpdateReloadStopState(bool is_loading, |
| 1435 | bool force) { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1436 | if (is_locked_fullscreen_) |
| 1437 | return; |
| 1438 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1439 | window()->UpdateReloadStopState(is_loading, force); |
| 1440 | command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| Jeff Fisher | 6cc1ce7b | 2019-06-28 23:02:38 | [diff] [blame] | 1441 | UpdateCloseFindOrStop(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1442 | } |
| 1443 | |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 1444 | void BrowserCommandController::UpdateTabRestoreCommandState() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1445 | if (is_locked_fullscreen_) |
| 1446 | return; |
| 1447 | |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 1448 | sessions::TabRestoreService* tab_restore_service = |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 1449 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 1450 | // The command is enabled if the service hasn't loaded yet to trigger loading. |
| 1451 | // The command is updated once the load completes. |
| 1452 | command_updater_.UpdateCommandEnabled( |
| 1453 | IDC_RESTORE_TAB, |
| Peter Kasting | 32bb260 | 2019-08-22 19:01:43 | [diff] [blame] | 1454 | tab_restore_service && (!tab_restore_service->IsLoaded() || |
| 1455 | !tab_restore_service->entries().empty())); |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 1456 | } |
| 1457 | |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 1458 | void BrowserCommandController::UpdateCommandsForFind() { |
| 1459 | TabStripModel* model = browser_->tab_strip_model(); |
| Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 1460 | bool enabled = !model->IsTabBlocked(model->active_index()) && |
| 1461 | !browser_->is_type_devtools(); |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 1462 | |
| 1463 | command_updater_.UpdateCommandEnabled(IDC_FIND, enabled); |
| 1464 | command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled); |
| 1465 | command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled); |
| 1466 | } |
| 1467 | |
| Jeff Fisher | 6cc1ce7b | 2019-06-28 23:02:38 | [diff] [blame] | 1468 | void BrowserCommandController::UpdateCloseFindOrStop() { |
| 1469 | bool enabled = CanCloseFind(browser_) || IsCommandEnabled(IDC_STOP); |
| 1470 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_FIND_OR_STOP, enabled); |
| 1471 | } |
| 1472 | |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 1473 | void BrowserCommandController::UpdateCommandsForMediaRouter() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1474 | if (is_locked_fullscreen_) |
| 1475 | return; |
| 1476 | |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 1477 | command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA, |
| 1478 | CanRouteMedia(browser_)); |
| 1479 | } |
| 1480 | |
| Elly Fong-Jones | 5e6baaf | 2019-10-10 23:17:14 | [diff] [blame] | 1481 | void BrowserCommandController::UpdateCommandsForTabKeyboardFocus( |
| 1482 | base::Optional<int> target_index) { |
| 1483 | command_updater_.UpdateCommandEnabled( |
| 1484 | IDC_DUPLICATE_TARGET_TAB, !browser_->deprecated_is_app() && |
| 1485 | target_index.has_value() && |
| 1486 | CanDuplicateTabAt(browser_, *target_index)); |
| 1487 | const bool normal_window = browser_->is_type_normal(); |
| 1488 | command_updater_.UpdateCommandEnabled( |
| 1489 | IDC_MUTE_TARGET_SITE, normal_window && target_index.has_value()); |
| 1490 | command_updater_.UpdateCommandEnabled( |
| 1491 | IDC_PIN_TARGET_TAB, normal_window && target_index.has_value()); |
| Connie Wan | 303e29e | 2020-01-31 18:16:56 | [diff] [blame] | 1492 | command_updater_.UpdateCommandEnabled( |
| 1493 | IDC_GROUP_TARGET_TAB, normal_window && target_index.has_value()); |
| Elly Fong-Jones | 5e6baaf | 2019-10-10 23:17:14 | [diff] [blame] | 1494 | } |
| 1495 | |
| Dominic Mazzoni | 1e0e5125 | 2020-10-19 19:36:18 | [diff] [blame^] | 1496 | void BrowserCommandController::UpdateCommandsForWebContentsFocus() { |
| 1497 | #if defined(OS_MAC) |
| 1498 | // On Mac, toggling caret browsing changes whether it's enabled or not |
| 1499 | // based on web contents focus. |
| 1500 | command_updater_.UpdateCommandEnabled(IDC_CARET_BROWSING_TOGGLE, |
| 1501 | CanToggleCaretBrowsing(browser_)); |
| 1502 | #endif // defined(OS_MAC) |
| 1503 | } |
| 1504 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1505 | BrowserWindow* BrowserCommandController::window() { |
| 1506 | return browser_->window(); |
| 1507 | } |
| 1508 | |
| 1509 | Profile* BrowserCommandController::profile() { |
| 1510 | return browser_->profile(); |
| 1511 | } |
| 1512 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1513 | } // namespace chrome |