| [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; |
| Tina Wang | 4c32470 | 2019-04-25 18:35:15 | [diff] [blame^] | 512 | case IDC_SEND_TAB_TO_SELF: |
| 513 | // TODO(crbug/950388): add implementation. |
| 514 | NOTIMPLEMENTED(); |
| 515 | break; |
| [email protected] | 4bee443 | 2014-05-05 13:11:41 | [diff] [blame] | 516 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 517 | // Clipboard commands |
| 518 | case IDC_CUT: |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 519 | case IDC_COPY: |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 520 | case IDC_PASTE: |
| pkasting | cd3f08bce | 2015-04-18 13:37:12 | [diff] [blame] | 521 | CutCopyPaste(browser_, id); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 522 | break; |
| 523 | |
| 524 | // Find-in-page |
| 525 | case IDC_FIND: |
| 526 | Find(browser_); |
| 527 | break; |
| 528 | case IDC_FIND_NEXT: |
| 529 | FindNext(browser_); |
| 530 | break; |
| 531 | case IDC_FIND_PREVIOUS: |
| 532 | FindPrevious(browser_); |
| 533 | break; |
| 534 | |
| 535 | // Zoom |
| 536 | case IDC_ZOOM_PLUS: |
| 537 | Zoom(browser_, content::PAGE_ZOOM_IN); |
| 538 | break; |
| 539 | case IDC_ZOOM_NORMAL: |
| 540 | Zoom(browser_, content::PAGE_ZOOM_RESET); |
| 541 | break; |
| 542 | case IDC_ZOOM_MINUS: |
| 543 | Zoom(browser_, content::PAGE_ZOOM_OUT); |
| 544 | break; |
| 545 | |
| 546 | // Focus various bits of UI |
| 547 | case IDC_FOCUS_TOOLBAR: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 548 | base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 549 | FocusToolbar(browser_); |
| 550 | break; |
| 551 | case IDC_FOCUS_LOCATION: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 552 | base::RecordAction(base::UserMetricsAction("Accel_Focus_Location")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 553 | FocusLocationBar(browser_); |
| 554 | break; |
| 555 | case IDC_FOCUS_SEARCH: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 556 | base::RecordAction(base::UserMetricsAction("Accel_Focus_Search")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 557 | FocusSearch(browser_); |
| 558 | break; |
| 559 | case IDC_FOCUS_MENU_BAR: |
| 560 | FocusAppMenu(browser_); |
| 561 | break; |
| 562 | case IDC_FOCUS_BOOKMARKS: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 563 | base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 564 | FocusBookmarksToolbar(browser_); |
| 565 | break; |
| David Tseng | c0b1b64 | 2018-01-24 07:12:27 | [diff] [blame] | 566 | case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY: |
| 567 | FocusInactivePopupForAccessibility(browser_); |
| [email protected] | 822ca8c6 | 2013-04-19 00:49:15 | [diff] [blame] | 568 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 569 | case IDC_FOCUS_NEXT_PANE: |
| 570 | FocusNextPane(browser_); |
| 571 | break; |
| 572 | case IDC_FOCUS_PREVIOUS_PANE: |
| 573 | FocusPreviousPane(browser_); |
| 574 | break; |
| 575 | |
| 576 | // Show various bits of UI |
| 577 | case IDC_OPEN_FILE: |
| 578 | browser_->OpenFile(); |
| 579 | break; |
| Alan Cutter | 81ac72668 | 2018-09-25 00:18:36 | [diff] [blame] | 580 | case IDC_CREATE_SHORTCUT: |
| 581 | CreateBookmarkAppFromCurrentWebContents(browser_, |
| 582 | true /* force_shortcut_app */); |
| 583 | break; |
| 584 | case IDC_INSTALL_PWA: |
| 585 | CreateBookmarkAppFromCurrentWebContents(browser_, |
| 586 | false /* force_shortcut_app */); |
| [email protected] | 488e395 | 2013-11-18 05:29:14 | [diff] [blame] | 587 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 588 | case IDC_DEV_TOOLS: |
| [email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 589 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 590 | break; |
| 591 | case IDC_DEV_TOOLS_CONSOLE: |
| einbinder | dfa567b | 2016-12-16 01:15:52 | [diff] [blame] | 592 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 593 | break; |
| [email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 594 | case IDC_DEV_TOOLS_DEVICES: |
| 595 | InspectUI::InspectDevices(browser_); |
| 596 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 597 | case IDC_DEV_TOOLS_INSPECT: |
| [email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 598 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 599 | break; |
| [email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 600 | case IDC_DEV_TOOLS_TOGGLE: |
| [email protected] | c934c38 | 2013-11-01 00:36:01 | [diff] [blame] | 601 | ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle()); |
| [email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 602 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 603 | case IDC_TASK_MANAGER: |
| [email protected] | 29c262de | 2013-06-22 15:39:38 | [diff] [blame] | 604 | OpenTaskManager(browser_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 605 | break; |
| caelyn | 4e4e08a | 2015-02-04 21:27:49 | [diff] [blame] | 606 | #if defined(OS_CHROMEOS) |
| 607 | case IDC_TAKE_SCREENSHOT: |
| 608 | TakeScreenshot(); |
| 609 | break; |
| 610 | #endif |
| [email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 611 | #if defined(GOOGLE_CHROME_BUILD) |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 612 | case IDC_FEEDBACK: |
| afakhry | f4575bd | 2017-04-28 02:21:04 | [diff] [blame] | 613 | OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 614 | break; |
| [email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 615 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 616 | case IDC_SHOW_BOOKMARK_BAR: |
| 617 | ToggleBookmarkBar(browser_); |
| 618 | break; |
| 619 | case IDC_PROFILING_ENABLED: |
| Bryce Thomas | 96b0777 | 2018-11-07 03:04:15 | [diff] [blame] | 620 | content::Profiling::Toggle(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 621 | break; |
| 622 | |
| 623 | case IDC_SHOW_BOOKMARK_MANAGER: |
| 624 | ShowBookmarkManager(browser_); |
| 625 | break; |
| 626 | case IDC_SHOW_APP_MENU: |
| bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 627 | base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu")); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 628 | ShowAppMenu(browser_); |
| 629 | break; |
| 630 | case IDC_SHOW_AVATAR_MENU: |
| 631 | ShowAvatarMenu(browser_); |
| 632 | break; |
| 633 | case IDC_SHOW_HISTORY: |
| 634 | ShowHistory(browser_); |
| 635 | break; |
| 636 | case IDC_SHOW_DOWNLOADS: |
| 637 | ShowDownloads(browser_); |
| 638 | break; |
| 639 | case IDC_MANAGE_EXTENSIONS: |
| [email protected] | bc9833c3 | 2013-02-28 04:05:08 | [diff] [blame] | 640 | ShowExtensions(browser_, std::string()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 641 | break; |
| 642 | case IDC_OPTIONS: |
| 643 | ShowSettings(browser_); |
| 644 | break; |
| 645 | case IDC_EDIT_SEARCH_ENGINES: |
| 646 | ShowSearchEngineSettings(browser_); |
| 647 | break; |
| 648 | case IDC_VIEW_PASSWORDS: |
| 649 | ShowPasswordManager(browser_); |
| 650 | break; |
| 651 | case IDC_CLEAR_BROWSING_DATA: |
| 652 | ShowClearBrowsingDataDialog(browser_); |
| 653 | break; |
| 654 | case IDC_IMPORT_SETTINGS: |
| 655 | ShowImportDialog(browser_); |
| 656 | break; |
| [email protected] | 9b7ab88 | 2012-09-10 23:46:36 | [diff] [blame] | 657 | case IDC_TOGGLE_REQUEST_TABLET_SITE: |
| 658 | ToggleRequestTabletSite(browser_); |
| 659 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 660 | case IDC_ABOUT: |
| 661 | ShowAboutChrome(browser_); |
| 662 | break; |
| 663 | case IDC_UPGRADE_DIALOG: |
| 664 | OpenUpdateChromeDialog(browser_); |
| 665 | break; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 666 | case IDC_HELP_PAGE_VIA_KEYBOARD: |
| 667 | ShowHelp(browser_, HELP_SOURCE_KEYBOARD); |
| 668 | break; |
| 669 | case IDC_HELP_PAGE_VIA_MENU: |
| 670 | ShowHelp(browser_, HELP_SOURCE_MENU); |
| 671 | break; |
| Bret Sepulveda | 2d01866 | 2017-05-18 21:31:48 | [diff] [blame] | 672 | case IDC_SHOW_BETA_FORUM: |
| 673 | ShowBetaForum(browser_); |
| 674 | break; |
| David Roger | 7e25dff | 2019-02-07 09:03:17 | [diff] [blame] | 675 | #if !defined(OS_CHROMEOS) |
| estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 676 | case IDC_SHOW_SIGNIN: |
| gogerald | 71bf6c90 | 2015-12-08 00:49:37 | [diff] [blame] | 677 | ShowBrowserSigninOrSettings( |
| 678 | browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU); |
| estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 679 | break; |
| David Roger | 7e25dff | 2019-02-07 09:03:17 | [diff] [blame] | 680 | #endif |
| [email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 681 | case IDC_DISTILL_PAGE: |
| 682 | DistillCurrentPage(browser_); |
| 683 | break; |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 684 | case IDC_ROUTE_MEDIA: |
| 685 | RouteMedia(browser_); |
| 686 | break; |
| Tommy Steimel | c447798 | 2017-11-29 18:07:18 | [diff] [blame] | 687 | case IDC_WINDOW_MUTE_SITE: |
| 688 | MuteSite(browser_); |
| ellyjones | 0101ba0 | 2017-05-19 15:50:26 | [diff] [blame] | 689 | break; |
| 690 | case IDC_WINDOW_PIN_TAB: |
| 691 | PinTab(browser_); |
| 692 | break; |
| Yann Dago | cd13225a | 2019-03-07 18:39:05 | [diff] [blame] | 693 | case IDC_SHOW_MANAGEMENT_PAGE: { |
| Yann Dago | c1d1c4af | 2019-04-17 13:40:51 | [diff] [blame] | 694 | ShowSingletonTab(browser_, GURL(kChromeUIManagementURL)); |
| Nicolas Ouellet-payeur | 82eb65b | 2018-11-05 16:49:27 | [diff] [blame] | 695 | break; |
| Yann Dago | cd13225a | 2019-03-07 18:39:05 | [diff] [blame] | 696 | } |
| Christopher Lam | 0dbac2b | 2017-11-14 07:12:10 | [diff] [blame] | 697 | // Hosted App commands |
| 698 | case IDC_COPY_URL: |
| 699 | CopyURL(browser_); |
| 700 | break; |
| 701 | case IDC_OPEN_IN_CHROME: |
| 702 | OpenInChrome(browser_); |
| 703 | break; |
| 704 | case IDC_SITE_SETTINGS: |
| 705 | ShowSiteSettings( |
| 706 | browser_, |
| 707 | browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL()); |
| 708 | break; |
| Alan Cutter | 0c313230 | 2018-02-21 05:09:02 | [diff] [blame] | 709 | case IDC_HOSTED_APP_MENU_APP_INFO: |
| 710 | ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(), |
| Alan Cutter | 689f89a | 2018-03-08 05:09:54 | [diff] [blame] | 711 | bubble_anchor_util::kAppMenuButton); |
| Christopher Lam | 86b5271 | 2017-12-04 01:58:33 | [diff] [blame] | 712 | break; |
| Christopher Lam | 0dbac2b | 2017-11-14 07:12:10 | [diff] [blame] | 713 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 714 | default: |
| 715 | LOG(WARNING) << "Received Unimplemented Command: " << id; |
| 716 | break; |
| 717 | } |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 718 | |
| 719 | return true; |
| 720 | } |
| 721 | |
| 722 | void BrowserCommandController::AddCommandObserver(int id, |
| 723 | CommandObserver* observer) { |
| 724 | command_updater_.AddCommandObserver(id, observer); |
| 725 | } |
| 726 | |
| 727 | void BrowserCommandController::RemoveCommandObserver( |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 728 | int id, |
| 729 | CommandObserver* observer) { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 730 | command_updater_.RemoveCommandObserver(id, observer); |
| 731 | } |
| 732 | |
| 733 | void BrowserCommandController::RemoveCommandObserver( |
| 734 | CommandObserver* observer) { |
| 735 | command_updater_.RemoveCommandObserver(observer); |
| 736 | } |
| 737 | |
| 738 | bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) { |
| 739 | if (is_locked_fullscreen_) |
| 740 | return false; |
| 741 | |
| 742 | return command_updater_.UpdateCommandEnabled(id, state); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 743 | } |
| 744 | |
| Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 745 | //////////////////////////////////////////////////////////////////////////////// |
| 746 | // BrowserCommandController, SigninPrefObserver implementation: |
| 747 | |
| 748 | void BrowserCommandController::OnSigninAllowedPrefChange() { |
| 749 | // For unit tests, we don't have a window. |
| 750 | if (!window()) |
| 751 | return; |
| 752 | UpdateShowSyncState(IsShowingMainUI()); |
| 753 | } |
| 754 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 755 | // BrowserCommandController, TabStripModelObserver implementation: |
| 756 | |
| sangwoo.ko | 1ae265f1 | 2018-10-18 08:30:28 | [diff] [blame] | 757 | void BrowserCommandController::OnTabStripModelChanged( |
| 758 | TabStripModel* tab_strip_model, |
| 759 | const TabStripModelChange& change, |
| 760 | const TabStripSelectionChange& selection) { |
| 761 | if (change.type() != TabStripModelChange::kInserted && |
| 762 | change.type() != TabStripModelChange::kReplaced && |
| 763 | change.type() != TabStripModelChange::kRemoved) |
| 764 | return; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 765 | |
| sangwoo.ko | 1ae265f1 | 2018-10-18 08:30:28 | [diff] [blame] | 766 | for (const auto& delta : change.deltas()) { |
| 767 | content::WebContents* new_contents = nullptr; |
| 768 | content::WebContents* old_contents = nullptr; |
| 769 | if (change.type() == TabStripModelChange::kInserted) { |
| 770 | new_contents = delta.insert.contents; |
| 771 | } else if (change.type() == TabStripModelChange::kReplaced) { |
| 772 | new_contents = delta.replace.new_contents; |
| 773 | old_contents = delta.replace.old_contents; |
| 774 | } else { |
| 775 | old_contents = delta.remove.contents; |
| 776 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 777 | |
| sangwoo.ko | 1ae265f1 | 2018-10-18 08:30:28 | [diff] [blame] | 778 | if (old_contents) |
| 779 | RemoveInterstitialObservers(old_contents); |
| 780 | if (new_contents) |
| 781 | AddInterstitialObservers(new_contents); |
| 782 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 783 | } |
| 784 | |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 785 | void BrowserCommandController::TabBlockedStateChanged( |
| 786 | content::WebContents* contents, |
| 787 | int index) { |
| 788 | PrintingStateChanged(); |
| 789 | FullscreenStateChanged(); |
| 790 | UpdateCommandsForFind(); |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 791 | UpdateCommandsForMediaRouter(); |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 792 | } |
| 793 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 794 | //////////////////////////////////////////////////////////////////////////////// |
| 795 | // BrowserCommandController, TabRestoreServiceObserver implementation: |
| 796 | |
| 797 | void BrowserCommandController::TabRestoreServiceChanged( |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 798 | sessions::TabRestoreService* service) { |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 799 | UpdateTabRestoreCommandState(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void BrowserCommandController::TabRestoreServiceDestroyed( |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 803 | sessions::TabRestoreService* service) { |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 804 | service->RemoveObserver(this); |
| 805 | } |
| 806 | |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 807 | void BrowserCommandController::TabRestoreServiceLoaded( |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 808 | sessions::TabRestoreService* service) { |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 809 | UpdateTabRestoreCommandState(); |
| 810 | } |
| 811 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 812 | //////////////////////////////////////////////////////////////////////////////// |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 813 | // BrowserCommandController, private: |
| 814 | |
| [email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 815 | class BrowserCommandController::InterstitialObserver |
| 816 | : public content::WebContentsObserver { |
| 817 | public: |
| 818 | InterstitialObserver(BrowserCommandController* controller, |
| 819 | content::WebContents* web_contents) |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 820 | : WebContentsObserver(web_contents), controller_(controller) {} |
| [email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 821 | |
| dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 822 | void DidAttachInterstitialPage() override { |
| [email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 823 | controller_->UpdateCommandsForTabState(); |
| 824 | } |
| 825 | |
| dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 826 | void DidDetachInterstitialPage() override { |
| [email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 827 | controller_->UpdateCommandsForTabState(); |
| 828 | } |
| 829 | |
| 830 | private: |
| 831 | BrowserCommandController* controller_; |
| 832 | |
| 833 | DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); |
| 834 | }; |
| 835 | |
| [email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 836 | bool BrowserCommandController::IsShowingMainUI() { |
| manuk | f1a11639 | 2018-10-25 16:28:24 | [diff] [blame] | 837 | return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP); |
| 838 | } |
| 839 | |
| 840 | bool BrowserCommandController::IsShowingLocationBar() { |
| 841 | return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | void BrowserCommandController::InitCommandState() { |
| 845 | // All browser commands whose state isn't set automagically some other way |
| 846 | // (like Back & Forward with initial page load) must have their state |
| 847 | // initialized here, otherwise they will be forever disabled. |
| 848 | |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 849 | if (is_locked_fullscreen_) |
| 850 | return; |
| 851 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 852 | // Navigation commands |
| 853 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
| toyoshim | 7dad4b118 | 2016-04-01 14:28:05 | [diff] [blame] | 854 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true); |
| [email protected] | 58e2903 | 2012-08-06 20:19:57 | [diff] [blame] | 855 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 856 | |
| 857 | // Window management commands |
| 858 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 859 | command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); |
| 860 | command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); |
| 861 | command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 862 | UpdateTabRestoreCommandState(); |
| [email protected] | d28d378 | 2013-02-26 16:31:55 | [diff] [blame] | 863 | command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 864 | command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 865 | #if defined(OS_CHROMEOS) |
| James Cook | 934abaf | 2017-09-19 22:21:58 | [diff] [blame] | 866 | command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true); |
| [email protected] | d12cc5e | 2013-10-19 18:25:06 | [diff] [blame] | 867 | command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true); |
| 868 | command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true); |
| 869 | #endif |
| [email protected] | 893124a2 | 2014-04-15 00:45:28 | [diff] [blame] | 870 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| Tom Anderson | f15ede50 | 2017-11-10 03:17:15 | [diff] [blame] | 871 | command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true); |
| 872 | command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true); |
| 873 | command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true); |
| Maksim Sisov | ac76759 | 2018-08-10 08:00:15 | [diff] [blame] | 874 | bool use_system_title_bar = true; |
| 875 | #if defined(USE_OZONE) |
| 876 | use_system_title_bar = ui::OzonePlatform::GetInstance() |
| 877 | ->GetPlatformProperties() |
| 878 | .use_system_title_bar; |
| 879 | #endif |
| 880 | command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, |
| 881 | use_system_title_bar); |
| [email protected] | af97be4c6 | 2014-02-13 14:43:34 | [diff] [blame] | 882 | #endif |
| Alan Cutter | 0996580 | 2018-03-27 07:25:29 | [diff] [blame] | 883 | command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 884 | |
| 885 | // Page-related commands |
| 886 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); |
| [email protected] | 4bee443 | 2014-05-05 13:11:41 | [diff] [blame] | 887 | command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 888 | |
| 889 | // Zoom |
| 890 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
| 891 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
| [email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 892 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 893 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
| 894 | |
| 895 | // Show various bits of UI |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 896 | const bool guest_session = |
| 897 | profile()->IsGuestSession() || profile()->IsSystemProfile(); |
| mlerman | 7831f57d | 2015-05-25 11:40:15 | [diff] [blame] | 898 | DCHECK(!profile()->IsSystemProfile()) |
| 899 | << "Ought to never have browser for the system profile."; |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 900 | const bool normal_window = browser_->is_type_tabbed(); |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 901 | UpdateOpenFileState(&command_updater_); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 902 | UpdateCommandsForDevTools(); |
| 903 | command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 904 | command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 905 | command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| [email protected] | 674b6567 | 2014-06-02 23:21:56 | [diff] [blame] | 906 | command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 907 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
| 908 | command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
| Bret Sepulveda | 2d01866 | 2017-05-18 21:31:48 | [diff] [blame] | 909 | command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true); |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 910 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 911 | command_updater_.UpdateCommandEnabled( |
| 912 | IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord()); |
| tsergeant | 341a827 | 2017-04-18 03:54:33 | [diff] [blame] | 913 | command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, |
| 914 | !guest_session); |
| [email protected] | 39d4759 | 2014-01-10 21:42:45 | [diff] [blame] | 915 | #if defined(OS_CHROMEOS) |
| caelyn | 4e4e08a | 2015-02-04 21:27:49 | [diff] [blame] | 916 | command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true); |
| Ramin Halavati | f362b7a | 2019-04-17 05:24:50 | [diff] [blame] | 917 | // Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu |
| 918 | // is only required in incognito mode. |
| 919 | if (profile()->IsIncognito()) |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 920 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true); |
| Ramin Halavati | f362b7a | 2019-04-17 05:24:50 | [diff] [blame] | 921 | #else |
| 922 | if (normal_window) |
| 923 | command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true); |
| [email protected] | 39d4759 | 2014-01-10 21:42:45 | [diff] [blame] | 924 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 925 | |
| Mihai Sardarescu | 2ec520568 | 2018-09-26 09:20:05 | [diff] [blame] | 926 | UpdateShowSyncState(true); |
| 927 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 928 | // Navigation commands |
| Christopher Cameron | e138574 | 2019-04-05 20:37:25 | [diff] [blame] | 929 | command_updater_.UpdateCommandEnabled(IDC_HOME, |
| 930 | normal_window || browser_->is_app()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 931 | |
| Christopher Lam | 0dbac2b | 2017-11-14 07:12:10 | [diff] [blame] | 932 | const bool is_experimental_hosted_app = |
| Yining Wang | 9ba7465f3 | 2019-04-12 19:58:24 | [diff] [blame] | 933 | WebAppBrowserController::IsForExperimentalWebAppBrowser(browser_); |
| Christopher Lam | 0dbac2b | 2017-11-14 07:12:10 | [diff] [blame] | 934 | // Hosted app browser commands. |
| 935 | command_updater_.UpdateCommandEnabled(IDC_COPY_URL, |
| 936 | is_experimental_hosted_app); |
| 937 | command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME, |
| 938 | is_experimental_hosted_app); |
| 939 | command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS, |
| 940 | is_experimental_hosted_app); |
| Alan Cutter | 0c313230 | 2018-02-21 05:09:02 | [diff] [blame] | 941 | command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO, |
| Christopher Lam | 86b5271 | 2017-12-04 01:58:33 | [diff] [blame] | 942 | is_experimental_hosted_app); |
| Christopher Lam | 0dbac2b | 2017-11-14 07:12:10 | [diff] [blame] | 943 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 944 | // Window management commands |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 945 | command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 946 | command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, normal_window); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 947 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window); |
| 948 | command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window); |
| 949 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window); |
| 950 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window); |
| 951 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window); |
| 952 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window); |
| 953 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window); |
| 954 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window); |
| 955 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window); |
| 956 | command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); |
| 957 | command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 958 | |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 959 | // These are always enabled; the menu determines their menu item visibility. |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 960 | command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 961 | |
| [email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 962 | // Distill current page. |
| 963 | command_updater_.UpdateCommandEnabled( |
| avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 964 | IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 965 | switches::kEnableDomDistiller)); |
| [email protected] | 6bd370b | 2014-05-28 14:19:47 | [diff] [blame] | 966 | |
| Tommy Steimel | c447798 | 2017-11-29 18:07:18 | [diff] [blame] | 967 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window); |
| ellyjones | 0101ba0 | 2017-05-19 15:50:26 | [diff] [blame] | 968 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window); |
| 969 | |
| [email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 970 | // Initialize other commands whose state changes based on various conditions. |
| [email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 971 | UpdateCommandsForFullscreenMode(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 972 | UpdateCommandsForContentRestrictionState(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 973 | UpdateCommandsForBookmarkEditing(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 974 | UpdateCommandsForIncognitoAvailability(); |
| 975 | } |
| 976 | |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 977 | // static |
| 978 | void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( |
| 979 | CommandUpdater* command_updater, |
| 980 | Profile* profile) { |
| mlerman | e01e6de | 2014-09-29 19:26:47 | [diff] [blame] | 981 | const bool guest_session = profile->IsGuestSession(); |
| 982 | // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession(). |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 983 | IncognitoModePrefs::Availability incognito_availability = |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 984 | IncognitoModePrefs::GetAvailability(profile->GetPrefs()); |
| 985 | command_updater->UpdateCommandEnabled( |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 986 | IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED); |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 987 | command_updater->UpdateCommandEnabled( |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 988 | IDC_NEW_INCOGNITO_WINDOW, |
| mlerman | e01e6de | 2014-09-29 19:26:47 | [diff] [blame] | 989 | incognito_availability != IncognitoModePrefs::DISABLED && !guest_session); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 990 | |
| [email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 991 | const bool forced_incognito = |
| 992 | incognito_availability == IncognitoModePrefs::FORCED || |
| 993 | guest_session; // Guest always runs in Incognito mode. |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 994 | command_updater->UpdateCommandEnabled( |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 995 | IDC_SHOW_BOOKMARK_MANAGER, |
| [email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 996 | browser_defaults::bookmarks_enabled && !forced_incognito); |
| Devlin Cronin | 21dba42 | 2018-05-30 15:45:16 | [diff] [blame] | 997 | extensions::ExtensionService* extension_service = |
| [email protected] | 03d2581 | 2014-06-22 19:41:55 | [diff] [blame] | 998 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| [email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 999 | const bool enable_extensions = |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1000 | extension_service && extension_service->extensions_enabled(); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1001 | |
| [email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 1002 | // Bookmark manager and settings page/subpages are forced to open in normal |
| 1003 | // mode. For this reason we disable these commands when incognito is forced. |
| 1004 | command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS, |
| 1005 | enable_extensions && !forced_incognito); |
| 1006 | |
| 1007 | command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito); |
| 1008 | command_updater->UpdateCommandEnabled(IDC_OPTIONS, |
| 1009 | !forced_incognito || guest_session); |
| estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 1010 | command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | void BrowserCommandController::UpdateCommandsForIncognitoAvailability() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1014 | if (is_locked_fullscreen_) |
| 1015 | return; |
| 1016 | |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1017 | UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile()); |
| 1018 | |
| [email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 1019 | if (!IsShowingMainUI()) { |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1020 | command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false); |
| 1021 | command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false); |
| 1022 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | void BrowserCommandController::UpdateCommandsForTabState() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1026 | if (is_locked_fullscreen_) |
| 1027 | return; |
| 1028 | |
| [email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 1029 | WebContents* current_web_contents = |
| 1030 | browser_->tab_strip_model()->GetActiveWebContents(); |
| [email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 1031 | if (!current_web_contents) // May be NULL during tab restore. |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1032 | return; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1033 | |
| 1034 | // Navigation commands |
| 1035 | command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_)); |
| 1036 | command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_)); |
| 1037 | command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_)); |
| toyoshim | 7dad4b118 | 2016-04-01 14:28:05 | [diff] [blame] | 1038 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1039 | CanReload(browser_)); |
| [email protected] | 58e2903 | 2012-08-06 20:19:57 | [diff] [blame] | 1040 | command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, |
| 1041 | CanReload(browser_)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1042 | |
| 1043 | // Window management commands |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1044 | command_updater_.UpdateCommandEnabled( |
| 1045 | IDC_DUPLICATE_TAB, !browser_->is_app() && CanDuplicateTab(browser_)); |
| Tommy Steimel | c447798 | 2017-11-29 18:07:18 | [diff] [blame] | 1046 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, |
| ellyjones | 0101ba0 | 2017-05-19 15:50:26 | [diff] [blame] | 1047 | !browser_->is_app()); |
| 1048 | command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, |
| 1049 | !browser_->is_app()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1050 | |
| 1051 | // Page-related commands |
| 1052 | window()->SetStarredState( |
| [email protected] | 1c5119c | 2012-09-19 00:08:57 | [diff] [blame] | 1053 | BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred()); |
| [email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 1054 | window()->ZoomChangedForActiveTab(false); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1055 | command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE, |
| 1056 | CanViewSource(browser_)); |
| 1057 | command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, |
| 1058 | CanEmailPageLocation(browser_)); |
| 1059 | if (browser_->is_devtools()) |
| 1060 | command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false); |
| 1061 | |
| Alan Cutter | 81ac72668 | 2018-09-25 00:18:36 | [diff] [blame] | 1062 | bool can_create_bookmark_app = CanCreateBookmarkApp(browser_); |
| 1063 | command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA, |
| 1064 | can_create_bookmark_app); |
| 1065 | command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT, |
| 1066 | can_create_bookmark_app); |
| Alan Cutter | 403cebb | 2018-05-17 05:22:45 | [diff] [blame] | 1067 | command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, |
| Alan Cutter | 81ac72668 | 2018-09-25 00:18:36 | [diff] [blame] | 1068 | can_create_bookmark_app); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1069 | |
| [email protected] | 9b7ab88 | 2012-09-10 23:46:36 | [diff] [blame] | 1070 | command_updater_.UpdateCommandEnabled( |
| 1071 | IDC_TOGGLE_REQUEST_TABLET_SITE, |
| 1072 | CanRequestTabletSite(current_web_contents)); |
| 1073 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1074 | UpdateCommandsForContentRestrictionState(); |
| 1075 | UpdateCommandsForBookmarkEditing(); |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 1076 | UpdateCommandsForFind(); |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 1077 | UpdateCommandsForMediaRouter(); |
| [email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 1078 | // Update the zoom commands when an active tab is selected. |
| 1079 | UpdateCommandsForZoomState(); |
| 1080 | } |
| 1081 | |
| 1082 | void BrowserCommandController::UpdateCommandsForZoomState() { |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1083 | WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents(); |
| [email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 1084 | if (!contents) |
| 1085 | return; |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1086 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents)); |
| a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 1087 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, |
| ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 1088 | CanResetZoom(contents)); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1089 | command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | void BrowserCommandController::UpdateCommandsForContentRestrictionState() { |
| 1093 | int restrictions = GetContentRestrictions(browser_); |
| 1094 | |
| 1095 | command_updater_.UpdateCommandEnabled( |
| [email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1096 | IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1097 | command_updater_.UpdateCommandEnabled( |
| [email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1098 | IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1099 | command_updater_.UpdateCommandEnabled( |
| [email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 1100 | IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1101 | UpdateSaveAsState(); |
| 1102 | UpdatePrintingState(); |
| 1103 | } |
| 1104 | |
| 1105 | void BrowserCommandController::UpdateCommandsForDevTools() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1106 | if (is_locked_fullscreen_) |
| 1107 | return; |
| 1108 | |
| Pavol Marko | 56df027 | 2018-07-04 17:55:04 | [diff] [blame] | 1109 | bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor( |
| 1110 | profile(), browser_->tab_strip_model()->GetActiveWebContents()); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1111 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1112 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE, |
| 1113 | dev_tools_enabled); |
| [email protected] | 2056c319 | 2013-10-21 22:40:51 | [diff] [blame] | 1114 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES, |
| 1115 | dev_tools_enabled); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1116 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT, |
| 1117 | dev_tools_enabled); |
| [email protected] | d16657c | 2012-09-03 14:25:10 | [diff] [blame] | 1118 | command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE, |
| 1119 | dev_tools_enabled); |
| spqchan | 2c5d541e | 2017-10-25 07:07:11 | [diff] [blame] | 1120 | #if defined(OS_MACOSX) |
| 1121 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS, |
| 1122 | dev_tools_enabled); |
| 1123 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | void BrowserCommandController::UpdateCommandsForBookmarkEditing() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1127 | if (is_locked_fullscreen_) |
| 1128 | return; |
| 1129 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1130 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, |
| 1131 | CanBookmarkCurrentPage(browser_)); |
| 1132 | command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, |
| 1133 | CanBookmarkAllTabs(browser_)); |
| thestig | 5149d27 | 2014-10-30 07:25:29 | [diff] [blame] | 1134 | #if defined(OS_WIN) |
| 1135 | command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true); |
| 1136 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | void BrowserCommandController::UpdateCommandsForBookmarkBar() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1140 | if (is_locked_fullscreen_) |
| 1141 | return; |
| 1142 | |
| tfarina | 3bddbe11 | 2014-08-28 05:29:32 | [diff] [blame] | 1143 | command_updater_.UpdateCommandEnabled( |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1144 | IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled && |
| 1145 | !profile()->IsGuestSession() && |
| 1146 | !profile()->IsSystemProfile() && |
| 1147 | !profile()->GetPrefs()->IsManagedPreference( |
| 1148 | bookmarks::prefs::kShowBookmarkBar) && |
| 1149 | IsShowingMainUI()); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1150 | } |
| 1151 | |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 1152 | void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1153 | if (is_locked_fullscreen_) |
| 1154 | return; |
| 1155 | |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 1156 | UpdateSaveAsState(); |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1157 | UpdateOpenFileState(&command_updater_); |
| [email protected] | 9ec3ea5b | 2012-12-03 18:14:30 | [diff] [blame] | 1158 | } |
| 1159 | |
| [email protected] | 32dfede | 2013-08-25 15:48:25 | [diff] [blame] | 1160 | void BrowserCommandController::UpdateCommandsForFullscreenMode() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1161 | if (is_locked_fullscreen_) |
| 1162 | return; |
| 1163 | |
| zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 1164 | const bool is_fullscreen = window() && window()->IsFullscreen(); |
| 1165 | const bool show_main_ui = IsShowingMainUI(); |
| manuk | f1a11639 | 2018-10-25 16:28:24 | [diff] [blame] | 1166 | const bool show_location_bar = IsShowingLocationBar(); |
| 1167 | |
| zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 1168 | const bool main_not_fullscreen = show_main_ui && !is_fullscreen; |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1169 | |
| 1170 | // Navigation commands |
| 1171 | command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui); |
| 1172 | |
| 1173 | // Window management commands |
| 1174 | command_updater_.UpdateCommandEnabled( |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1175 | IDC_SHOW_AS_TAB, !browser_->is_type_tabbed() && !is_fullscreen); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1176 | |
| 1177 | // Focus various bits of UI |
| 1178 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui); |
| manuk | f1a11639 | 2018-10-25 16:28:24 | [diff] [blame] | 1179 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1180 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1181 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR, |
| 1182 | main_not_fullscreen); |
| 1183 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, |
| 1184 | main_not_fullscreen); |
| 1185 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, |
| 1186 | main_not_fullscreen); |
| 1187 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS, |
| 1188 | main_not_fullscreen); |
| [email protected] | 822ca8c6 | 2013-04-19 00:49:15 | [diff] [blame] | 1189 | command_updater_.UpdateCommandEnabled( |
| David Tseng | c0b1b64 | 2018-01-24 07:12:27 | [diff] [blame] | 1190 | IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1191 | |
| 1192 | // Show various bits of UI |
| 1193 | command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| [email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 1194 | #if defined(GOOGLE_CHROME_BUILD) |
| Fabio Rocha | 19bf426 | 2019-04-04 01:05:18 | [diff] [blame] | 1195 | command_updater_.UpdateCommandEnabled( |
| 1196 | IDC_FEEDBACK, show_main_ui || browser_->is_devtools()); |
| [email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 1197 | #endif |
| Mihai Sardarescu | 2ec520568 | 2018-09-26 09:20:05 | [diff] [blame] | 1198 | UpdateShowSyncState(show_main_ui); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1199 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1200 | command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 1201 | command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 1202 | command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 1203 | command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| Tina Wang | f09681ac | 2019-03-27 20:52:10 | [diff] [blame] | 1204 | command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui); |
| Yann Dago | 70ca3dd | 2019-02-27 01:12:35 | [diff] [blame] | 1205 | command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true); |
| primiano | d3a81ab | 2016-01-25 22:21:15 | [diff] [blame] | 1206 | |
| 1207 | if (base::debug::IsProfilingSupported()) |
| 1208 | command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1209 | |
| [email protected] | aeafc385 | 2014-04-29 16:51:29 | [diff] [blame] | 1210 | #if !defined(OS_MACOSX) |
| zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 1211 | // Disable toggling into fullscreen mode if disallowed by pref. |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1212 | const bool fullscreen_enabled = |
| 1213 | is_fullscreen || |
| zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 1214 | profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed); |
| 1215 | #else |
| 1216 | const bool fullscreen_enabled = true; |
| [email protected] | 00a1cc5b | 2012-11-07 13:44:51 | [diff] [blame] | 1217 | #endif |
| 1218 | |
| 1219 | command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled); |
| spqchan | b8ffc7d | 2015-11-17 01:17:21 | [diff] [blame] | 1220 | command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR, |
| 1221 | fullscreen_enabled); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1222 | |
| 1223 | UpdateCommandsForBookmarkBar(); |
| zijiehe | db473d55 | 2017-02-24 01:13:41 | [diff] [blame] | 1224 | UpdateCommandsForIncognitoAvailability(); |
| Alan Cutter | 167dfe8 | 2018-04-11 09:06:00 | [diff] [blame] | 1225 | UpdateCommandsForHostedAppAvailability(); |
| 1226 | } |
| 1227 | |
| 1228 | void BrowserCommandController::UpdateCommandsForHostedAppAvailability() { |
| 1229 | bool has_toolbar = |
| 1230 | browser_->is_type_tabbed() || |
| Yining Wang | 9ba7465f3 | 2019-04-12 19:58:24 | [diff] [blame] | 1231 | WebAppBrowserController::IsForExperimentalWebAppBrowser(browser_); |
| Alan Cutter | 167dfe8 | 2018-04-11 09:06:00 | [diff] [blame] | 1232 | if (window() && window()->ShouldHideUIForFullscreen()) |
| 1233 | has_toolbar = false; |
| 1234 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar); |
| 1235 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar); |
| 1236 | command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar); |
| 1237 | command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1238 | } |
| 1239 | |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1240 | #if defined(OS_CHROMEOS) |
| 1241 | namespace { |
| 1242 | |
| 1243 | #if DCHECK_IS_ON() |
| 1244 | // Makes sure that all commands that are not whitelisted are disabled. DCHECKs |
| 1245 | // otherwise. Compiled only in debug mode. |
| 1246 | void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) { |
| Ivan Sandrk | 6ac9c9a | 2018-12-14 14:15:07 | [diff] [blame] | 1247 | constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE}; |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1248 | |
| 1249 | // Go through all the command ids, skip the whitelisted ones. |
| 1250 | for (int id : command_updater->GetAllIds()) { |
| Haeun Kim | 3f612350 | 2018-08-26 18:03:04 | [diff] [blame] | 1251 | if (base::ContainsValue(kWhitelistedIds, id)) { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1252 | continue; |
| 1253 | } |
| 1254 | DCHECK(!command_updater->IsCommandEnabled(id)); |
| 1255 | } |
| 1256 | } |
| 1257 | #endif |
| 1258 | |
| 1259 | } // namespace |
| 1260 | |
| 1261 | void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() { |
| Ivan Sandrk | e0e9245 | 2019-03-21 09:32:48 | [diff] [blame] | 1262 | bool is_locked_fullscreen = |
| 1263 | platform_util::IsBrowserLockedFullscreen(browser_); |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1264 | // Sanity check to make sure this function is called only on state change. |
| 1265 | DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_); |
| 1266 | if (is_locked_fullscreen == is_locked_fullscreen_) |
| 1267 | return; |
| 1268 | is_locked_fullscreen_ = is_locked_fullscreen; |
| 1269 | |
| 1270 | if (is_locked_fullscreen_) { |
| 1271 | command_updater_.DisableAllCommands(); |
| 1272 | // Update the state of whitelisted commands: |
| 1273 | // IDC_CUT/IDC_COPY/IDC_PASTE, |
| 1274 | UpdateCommandsForContentRestrictionState(); |
| Ivan Sandrk | 6ac9c9a | 2018-12-14 14:15:07 | [diff] [blame] | 1275 | // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen. |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1276 | // All other commands will be disabled (there is an early return in their |
| 1277 | // corresponding UpdateCommandsFor* functions). |
| 1278 | #if DCHECK_IS_ON() |
| 1279 | NonWhitelistedCommandsAreDisabled(&command_updater_); |
| 1280 | #endif |
| 1281 | } else { |
| 1282 | // Do an init call to re-initialize command state after the |
| 1283 | // DisableAllCommands. |
| 1284 | InitCommandState(); |
| 1285 | } |
| 1286 | } |
| 1287 | #endif |
| 1288 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1289 | void BrowserCommandController::UpdatePrintingState() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1290 | if (is_locked_fullscreen_) |
| 1291 | return; |
| 1292 | |
| [email protected] | d53e403 | 2012-06-29 18:58:34 | [diff] [blame] | 1293 | bool print_enabled = CanPrint(browser_); |
| 1294 | command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled); |
| Lei Zhang | 48a4a526 | 2018-04-17 20:18:44 | [diff] [blame] | 1295 | #if BUILDFLAG(ENABLE_PRINTING) |
| vitalybuka | f9433e4 | 2014-09-08 10:04:55 | [diff] [blame] | 1296 | command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT, |
| 1297 | CanBasicPrint(browser_)); |
| Lei Zhang | 48a4a526 | 2018-04-17 20:18:44 | [diff] [blame] | 1298 | #endif |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | void BrowserCommandController::UpdateSaveAsState() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1302 | if (is_locked_fullscreen_) |
| 1303 | return; |
| 1304 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1305 | command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
| 1306 | } |
| 1307 | |
| Mihai Sardarescu | 2ec520568 | 2018-09-26 09:20:05 | [diff] [blame] | 1308 | void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) { |
| 1309 | if (is_locked_fullscreen_) |
| 1310 | return; |
| 1311 | |
| Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 1312 | command_updater_.UpdateCommandEnabled( |
| Mihai Sardarescu | 290bc88 | 2018-10-12 10:48:14 | [diff] [blame] | 1313 | IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue()); |
| Mihai Sardarescu | 2ec520568 | 2018-09-26 09:20:05 | [diff] [blame] | 1314 | } |
| 1315 | |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1316 | // static |
| 1317 | void BrowserCommandController::UpdateOpenFileState( |
| 1318 | CommandUpdater* command_updater) { |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1319 | bool enabled = true; |
| 1320 | PrefService* local_state = g_browser_process->local_state(); |
| 1321 | if (local_state) |
| 1322 | enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 1323 | |
| [email protected] | 0545453 | 2013-01-22 21:09:08 | [diff] [blame] | 1324 | command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | void BrowserCommandController::UpdateReloadStopState(bool is_loading, |
| 1328 | bool force) { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1329 | if (is_locked_fullscreen_) |
| 1330 | return; |
| 1331 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1332 | window()->UpdateReloadStopState(is_loading, force); |
| 1333 | command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); |
| 1334 | } |
| 1335 | |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 1336 | void BrowserCommandController::UpdateTabRestoreCommandState() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1337 | if (is_locked_fullscreen_) |
| 1338 | return; |
| 1339 | |
| blundell | 74001adc | 2015-09-18 11:04:25 | [diff] [blame] | 1340 | sessions::TabRestoreService* tab_restore_service = |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 1341 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 1342 | // The command is enabled if the service hasn't loaded yet to trigger loading. |
| 1343 | // The command is updated once the load completes. |
| 1344 | command_updater_.UpdateCommandEnabled( |
| 1345 | IDC_RESTORE_TAB, |
| 1346 | tab_restore_service && |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1347 | (!tab_restore_service->IsLoaded() || |
| 1348 | GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE)); |
| [email protected] | 2e9369e | 2014-08-15 09:12:53 | [diff] [blame] | 1349 | } |
| 1350 | |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 1351 | void BrowserCommandController::UpdateCommandsForFind() { |
| 1352 | TabStripModel* model = browser_->tab_strip_model(); |
| Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 1353 | bool enabled = |
| 1354 | !model->IsTabBlocked(model->active_index()) && !browser_->is_devtools(); |
| [email protected] | 3cac8723 | 2012-11-20 01:48:27 | [diff] [blame] | 1355 | |
| 1356 | command_updater_.UpdateCommandEnabled(IDC_FIND, enabled); |
| 1357 | command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled); |
| 1358 | command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled); |
| 1359 | } |
| 1360 | |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 1361 | void BrowserCommandController::UpdateCommandsForMediaRouter() { |
| Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 1362 | if (is_locked_fullscreen_) |
| 1363 | return; |
| 1364 | |
| apacible | 45cbfc9 | 2015-09-28 22:45:41 | [diff] [blame] | 1365 | command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA, |
| 1366 | CanRouteMedia(browser_)); |
| 1367 | } |
| 1368 | |
| [email protected] | 409ea297 | 2012-11-10 19:54:43 | [diff] [blame] | 1369 | void BrowserCommandController::AddInterstitialObservers(WebContents* contents) { |
| [email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 1370 | interstitial_observers_.push_back(new InterstitialObserver(this, contents)); |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | void BrowserCommandController::RemoveInterstitialObservers( |
| [email protected] | e89cfcb | 2012-11-11 14:47:24 | [diff] [blame] | 1374 | WebContents* contents) { |
| [email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 1375 | for (size_t i = 0; i < interstitial_observers_.size(); i++) { |
| 1376 | if (interstitial_observers_[i]->web_contents() != contents) |
| 1377 | continue; |
| 1378 | |
| 1379 | delete interstitial_observers_[i]; |
| 1380 | interstitial_observers_.erase(interstitial_observers_.begin() + i); |
| 1381 | return; |
| 1382 | } |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | BrowserWindow* BrowserCommandController::window() { |
| 1386 | return browser_->window(); |
| 1387 | } |
| 1388 | |
| 1389 | Profile* BrowserCommandController::profile() { |
| 1390 | return browser_->profile(); |
| 1391 | } |
| 1392 | |
| [email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1393 | } // namespace chrome |