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