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