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