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