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