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