blob: 52aa82e8404217e8cec41859f2e4522109531d23 [file] [log] [blame]
[email protected]5d98294912012-06-27 22:57:401// 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
avi655876a2015-12-25 07:18:157#include <stddef.h>
8
pmonette9c1457f2015-11-19 20:29:319#include <string>
10
Sebastien Marchandf1349f52019-01-25 03:16:4111#include "base/bind.h"
[email protected]488e3952013-11-18 05:29:1412#include "base/command_line.h"
Scott Violet44165792018-02-22 02:08:0813#include "base/debug/debugging_buildflags.h"
primianod3a81ab2016-01-25 22:21:1514#include "base/debug/profiler.h"
avi655876a2015-12-25 07:18:1515#include "base/macros.h"
bratell0a7406f2017-03-28 07:46:3716#include "base/metrics/user_metrics.h"
Haeun Kim3f6123502018-08-26 18:03:0417#include "base/stl_util.h"
Nico Weber0cc71122019-07-29 17:30:4018#include "build/branding_buildflags.h"
avi655876a2015-12-25 07:18:1519#include "build/build_config.h"
[email protected]5d98294912012-06-27 22:57:4020#include "chrome/app/chrome_command_ids.h"
21#include "chrome/browser/browser_process.h"
[email protected]dcc8fbc2013-07-12 00:54:0922#include "chrome/browser/chrome_notification_types.h"
[email protected]5d98294912012-06-27 22:57:4023#include "chrome/browser/defaults.h"
Pavol Marko56df0272018-07-04 17:55:0424#include "chrome/browser/devtools/devtools_window.h"
[email protected]5d98294912012-06-27 22:57:4025#include "chrome/browser/extensions/extension_service.h"
[email protected]2e9d79f2013-08-16 05:45:5626#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4027#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4028#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4729#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4030#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0331#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1632#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4033#include "chrome/browser/sync/profile_sync_service_factory.h"
Christopher Lam86b52712017-12-04 01:58:3334#include "chrome/browser/ui/apps/app_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4035#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
36#include "chrome/browser/ui/browser.h"
37#include "chrome/browser/ui/browser_commands.h"
Dana Fried08b774a2019-05-10 18:21:4838#include "chrome/browser/ui/browser_finder.h"
[email protected]5d98294912012-06-27 22:57:4039#include "chrome/browser/ui/browser_window.h"
40#include "chrome/browser/ui/chrome_pages.h"
Alan Cutter0c3132302018-02-21 05:09:0241#include "chrome/browser/ui/page_info/page_info_dialog.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2742#include "chrome/browser/ui/singleton_tabs.h"
[email protected]5d98294912012-06-27 22:57:4043#include "chrome/browser/ui/tabs/tab_strip_model.h"
Eric Willigers4a5f7a92019-05-10 19:19:2644#include "chrome/browser/ui/web_applications/app_browser_controller.h"
Eric Willigerse2ca235a2019-08-17 01:01:0645#include "chrome/browser/ui/web_applications/web_app_launch_utils.h"
[email protected]2056c3192013-10-21 22:40:5146#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0147#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4048#include "chrome/common/pref_names.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2749#include "chrome/common/url_constants.h"
brettwe1f0af8b2015-10-09 21:30:4650#include "components/bookmarks/common/bookmark_pref_names.h"
Aran Gilman7b6ccf5d2019-09-05 19:16:0251#include "components/dom_distiller/core/dom_distiller_features.h"
Scott Violet9ae82892018-03-01 18:38:1252#include "components/feature_engagement/buildflags.h"
brettwb1fc1b82016-02-02 00:19:0853#include "components/prefs/pref_service.h"
blundella08c5dd2015-09-18 06:14:1654#include "components/sessions/core/tab_restore_service.h"
Colin Blundell3517170e2019-07-11 08:16:3455#include "components/signin/public/base/signin_pref_names.h"
[email protected]5d98294912012-06-27 22:57:4056#include "content/public/browser/native_web_keyboard_event.h"
57#include "content/public/browser/navigation_controller.h"
58#include "content/public/browser/navigation_entry.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:0659#include "content/public/browser/render_frame_host.h"
[email protected]5d98294912012-06-27 22:57:4060#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0761#include "content/public/browser/web_contents_observer.h"
Bryce Thomas96b07772018-11-07 03:04:1562#include "content/public/common/profiling.h"
bend32292b2016-10-07 00:21:5863#include "content/public/common/service_manager_connection.h"
[email protected]5d98294912012-06-27 22:57:4064#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5565#include "extensions/browser/extension_system.h"
Scott Violet318a55f2018-03-30 19:08:1966#include "printing/buildflags/buildflags.h"
[email protected]7e9acd082013-09-17 23:31:1667#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4068
[email protected]9c4d68332013-01-30 13:34:4169#if defined(OS_MACOSX)
70#include "chrome/browser/ui/browser_commands_mac.h"
71#endif
72
[email protected]5d98294912012-06-27 22:57:4073#if defined(OS_WIN)
[email protected]a43ed002013-02-05 19:47:5474#include "base/win/windows_version.h"
[email protected]2d0f80f2013-11-01 22:47:1875#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4076#endif
77
[email protected]d12cc5e2013-10-19 18:25:0678#if defined(OS_CHROMEOS)
Ivan Sandrke0e92452019-03-21 09:32:4879#include "chrome/browser/platform_util.h"
[email protected]0c930812014-01-30 18:01:4780#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
caelyn4e4e08a2015-02-04 21:27:4981#include "chrome/browser/ui/browser_commands_chromeos.h"
[email protected]d12cc5e2013-10-19 18:25:0682#endif
83
[email protected]d5bedb6d2014-04-08 10:49:3284#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
karandeepbe6200332016-06-21 12:26:1085#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3486#endif
87
Collin Baker4ab8ad82019-06-06 17:02:5488#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:1489#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker.h"
90#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker_factory.h"
Catherine Chungbeb884222017-08-01 15:47:5591#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker.h"
92#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker_factory.h"
93#endif
94
Maksim Sisovac767592018-08-10 08:00:1595#if defined(USE_OZONE)
96#include "ui/ozone/public/ozone_platform.h"
97#endif
98
[email protected]5d98294912012-06-27 22:57:4099using content::NavigationController;
Aran Gilmand217b5b2019-04-11 17:45:43100using content::NavigationEntry;
[email protected]5d98294912012-06-27 22:57:40101using content::WebContents;
102
[email protected]5d98294912012-06-27 22:57:40103namespace chrome {
104
Dana Fried08b774a2019-05-10 18:21:48105namespace {
106
107// Ensures that - if we have not popped up an infobar to prompt the user to e.g.
108// reload the current page - that the content pane of the browser is refocused.
109void AppInfoDialogClosedCallback(content::WebContents* web_contents,
Dana Fried98c0380e2019-05-14 16:58:32110 views::Widget::ClosedReason closed_reason,
Dana Fried08b774a2019-05-10 18:21:48111 bool reload_prompt) {
112 if (reload_prompt)
113 return;
114
Dana Fried98c0380e2019-05-14 16:58:32115 // If the user clicked on something specific or focus was changed, don't
116 // override the focus.
117 if (closed_reason != views::Widget::ClosedReason::kEscKeyPressed &&
118 closed_reason != views::Widget::ClosedReason::kCloseButtonClicked) {
119 return;
120 }
121
Dana Fried08b774a2019-05-10 18:21:48122 // Ensure that the web contents handle we have is still valid. It's possible
123 // (though unlikely) that either the browser or web contents has been pulled
124 // out from underneath us.
125 Browser* const browser = chrome::FindBrowserWithWebContents(web_contents);
126 if (!browser)
127 return;
128
129 // We want to focus the active web contents, which again, might not be the
130 // original web contents (though it should be the vast majority of the time).
131 content::WebContents* const active_contents =
132 browser->tab_strip_model()->GetActiveWebContents();
133 if (active_contents)
134 active_contents->Focus();
135}
136
137} // namespace
138
[email protected]5d98294912012-06-27 22:57:40139///////////////////////////////////////////////////////////////////////////////
140// BrowserCommandController, public:
141
[email protected]338416c02014-05-13 16:47:06142BrowserCommandController::BrowserCommandController(Browser* browser)
Aran Gilmand217b5b2019-04-11 17:45:43143 : browser_(browser), command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40144 browser_->tab_strip_model()->AddObserver(this);
145 PrefService* local_state = g_browser_process->local_state();
146 if (local_state) {
147 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30148 local_pref_registrar_.Add(
149 prefs::kAllowFileSelectionDialogs,
150 base::Bind(
151 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
152 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40153 }
154
155 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30156 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41157 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30158 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
159 base::Unretained(this)));
160 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32161 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30162 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
163 base::Unretained(this)));
164 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32165 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30166 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
167 base::Unretained(this)));
168 profile_pref_registrar_.Add(
169 prefs::kIncognitoModeAvailability,
170 base::Bind(
171 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
172 base::Unretained(this)));
173 profile_pref_registrar_.Add(
174 prefs::kPrintingEnabled,
175 base::Bind(&BrowserCommandController::UpdatePrintingState,
176 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25177#if !defined(OS_MACOSX)
178 profile_pref_registrar_.Add(
179 prefs::kFullscreenAllowed,
180 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
181 base::Unretained(this)));
182#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45183 pref_signin_allowed_.Init(
Aran Gilmand217b5b2019-04-11 17:45:43184 prefs::kSigninAllowed, profile()->GetOriginalProfile()->GetPrefs(),
Mihai Sardarescuf87ccc12018-09-26 10:37:45185 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
186 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40187
188 InitCommandState();
189
blundell74001adc2015-09-18 11:04:25190 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40191 TabRestoreServiceFactory::GetForProfile(profile());
192 if (tab_restore_service) {
193 tab_restore_service->AddObserver(this);
Cliff Smolinsky2c9586e2019-02-08 18:48:30194 if (!tab_restore_service->IsLoaded())
195 tab_restore_service->LoadTabsFromLastSession();
[email protected]5d98294912012-06-27 22:57:40196 }
[email protected]5d98294912012-06-27 22:57:40197}
198
199BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36200 // TabRestoreService may have been shutdown by the time we get here. Don't
201 // trigger creating it.
blundell74001adc2015-09-18 11:04:25202 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36203 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40204 if (tab_restore_service)
205 tab_restore_service->RemoveObserver(this);
206 profile_pref_registrar_.RemoveAll();
207 local_pref_registrar_.RemoveAll();
208 browser_->tab_strip_model()->RemoveObserver(this);
209}
210
211bool BrowserCommandController::IsReservedCommandOrKey(
212 int command_id,
213 const content::NativeWebKeyboardEvent& event) {
214 // In Apps mode, no keys are reserved.
Joel Hockey2687ab52019-08-14 23:59:46215 if (browser_->deprecated_is_app())
[email protected]5d98294912012-06-27 22:57:40216 return false;
217
218#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19219 // On Chrome OS, the top row of keys are mapped to browser actions like
220 // back/forward or refresh. We don't want web pages to be able to change the
221 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
222 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40223 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54224 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19225 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
226 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
227 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40228 return true;
229 }
230#endif
231
zijiehe68cd3dc22017-04-07 18:50:29232 if (window()->IsFullscreen()) {
233 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
234 // be delivered to the web page. The intent to implement and ship can be
235 // found in http://crbug.com/680809.
236 const bool is_exit_fullscreen =
237 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
238#if defined(OS_MACOSX)
239 // This behavior is different on Mac OS, which has a unique user-initiated
240 // full-screen mode. According to the discussion in http://crbug.com/702251,
241 // the commands should be reserved for browser-side handling if the browser
242 // window's toolbar is visible.
243 if (window()->IsToolbarShowing()) {
244 if (command_id == IDC_FULLSCREEN)
245 return true;
246 } else {
247 return is_exit_fullscreen;
248 }
249#else
250 return is_exit_fullscreen;
251#endif
252 }
[email protected]1e2172f2014-04-01 17:32:34253
[email protected]893124a22014-04-15 00:45:28254#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34255 // If this key was registered by the user as a content editing hotkey, then
256 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32257 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34258 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42259 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34260 return false;
261#endif
262
Aran Gilmand217b5b2019-04-11 17:45:43263 return command_id == IDC_CLOSE_TAB || command_id == IDC_CLOSE_WINDOW ||
264 command_id == IDC_NEW_INCOGNITO_WINDOW || command_id == IDC_NEW_TAB ||
265 command_id == IDC_NEW_WINDOW || command_id == IDC_RESTORE_TAB ||
zijiehe13207802017-02-16 08:06:10266 command_id == IDC_SELECT_NEXT_TAB ||
Aran Gilmand217b5b2019-04-11 17:45:43267 command_id == IDC_SELECT_PREVIOUS_TAB || command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40268}
269
[email protected]5d98294912012-06-27 22:57:40270void BrowserCommandController::TabStateChanged() {
271 UpdateCommandsForTabState();
272}
273
[email protected]d93dbd12014-08-04 23:42:53274void BrowserCommandController::ZoomStateChanged() {
275 UpdateCommandsForZoomState();
276}
277
[email protected]5d98294912012-06-27 22:57:40278void BrowserCommandController::ContentRestrictionsChanged() {
279 UpdateCommandsForContentRestrictionState();
280}
281
282void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25283 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40284}
285
Ivan Sandrk9669d0e2017-12-15 23:50:20286#if defined(OS_CHROMEOS)
287void BrowserCommandController::LockedFullscreenStateChanged() {
288 UpdateCommandsForLockedFullscreenMode();
289}
290#endif
291
[email protected]5d98294912012-06-27 22:57:40292void BrowserCommandController::PrintingStateChanged() {
293 UpdatePrintingState();
294}
295
296void BrowserCommandController::LoadingStateChanged(bool is_loading,
297 bool force) {
298 UpdateReloadStopState(is_loading, force);
299}
300
Jeff Fisher6cc1ce7b2019-06-28 23:02:38301void BrowserCommandController::FindBarVisibilityChanged() {
302 if (is_locked_fullscreen_)
303 return;
304 UpdateCloseFindOrStop();
305}
306
wittman76df71db32014-12-18 23:26:58307void BrowserCommandController::ExtensionStateChanged() {
308 // Extensions may disable the bookmark editing commands.
309 UpdateCommandsForBookmarkEditing();
310}
311
Elly Fong-Jones5e6baaf2019-10-10 23:17:14312void BrowserCommandController::TabKeyboardFocusChangedTo(
313 base::Optional<int> index) {
314 UpdateCommandsForTabKeyboardFocus(index);
315}
316
[email protected]5d98294912012-06-27 22:57:40317////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20318// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40319
Ivan Sandrk9669d0e2017-12-15 23:50:20320bool BrowserCommandController::SupportsCommand(int id) const {
321 return command_updater_.SupportsCommand(id);
322}
323
324bool BrowserCommandController::IsCommandEnabled(int id) const {
325 return command_updater_.IsCommandEnabled(id);
326}
327
Edwin Joe6f6fc1e2019-02-27 20:00:37328bool BrowserCommandController::ExecuteCommand(int id,
329 base::TimeTicks time_stamp) {
330 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB,
331 time_stamp);
Ivan Sandrk9669d0e2017-12-15 23:50:20332}
333
334bool BrowserCommandController::ExecuteCommandWithDisposition(
Edwin Joe6f6fc1e2019-02-27 20:00:37335 int id,
336 WindowOpenDisposition disposition,
337 base::TimeTicks time_stamp) {
Ivan Sandrk9669d0e2017-12-15 23:50:20338 // Doesn't go through the command_updater_ to avoid dealing with having a
339 // naming collision for ExecuteCommandWithDisposition (both
340 // CommandUpdaterDelegate and CommandUpdater declare this function so we
341 // choose to not implement CommandUpdaterDelegate inside this class and
342 // therefore command_updater_ doesn't have the delegate set).
343 if (!SupportsCommand(id) || !IsCommandEnabled(id))
344 return false;
345
[email protected]5d98294912012-06-27 22:57:40346 // No commands are enabled if there is not yet any selected tab.
347 // TODO(pkasting): It seems like we should not need this, because either
348 // most/all commands should not have been enabled yet anyway or the ones that
349 // are enabled should be global, or safe themselves against having no selected
350 // tab. However, Ben says he tried removing this before and got lots of
351 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
352 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26353 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20354 return true;
[email protected]5d98294912012-06-27 22:57:40355
Aran Gilmand217b5b2019-04-11 17:45:43356 DCHECK(command_updater_.IsCommandEnabled(id))
357 << "Invalid/disabled command " << id;
[email protected]5d98294912012-06-27 22:57:40358
[email protected]5d98294912012-06-27 22:57:40359 // The order of commands in this switch statement must match the function
360 // declaration order in browser.h!
361 switch (id) {
362 // Navigation commands
363 case IDC_BACK:
364 GoBack(browser_, disposition);
365 break;
366 case IDC_FORWARD:
367 GoForward(browser_, disposition);
368 break;
369 case IDC_RELOAD:
370 Reload(browser_, disposition);
371 break;
[email protected]58e29032012-08-06 20:19:57372 case IDC_RELOAD_CLEARING_CACHE:
373 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57374 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05375 case IDC_RELOAD_BYPASSING_CACHE:
376 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40377 break;
378 case IDC_HOME:
379 Home(browser_, disposition);
380 break;
381 case IDC_OPEN_CURRENT_URL:
382 OpenCurrentURL(browser_);
383 break;
384 case IDC_STOP:
385 Stop(browser_);
386 break;
387
Aran Gilmand217b5b2019-04-11 17:45:43388 // Window management commands
[email protected]5d98294912012-06-27 22:57:40389 case IDC_NEW_WINDOW:
390 NewWindow(browser_);
391 break;
392 case IDC_NEW_INCOGNITO_WINDOW:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05393 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40394 break;
395 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37396 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09397 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40398 break;
Bettina Dea0a4505922017-09-28 00:53:32399 case IDC_NEW_TAB: {
400 NewTab(browser_);
Collin Baker4ab8ad82019-06-06 17:02:54401#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55402 // This is not in NewTab() to avoid tracking programmatic creation of new
403 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32404 auto* new_tab_tracker =
405 feature_engagement::NewTabTrackerFactory::GetInstance()
406 ->GetForProfile(profile());
407
408 new_tab_tracker->OnNewTabOpened();
409 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55410#endif
[email protected]5d98294912012-06-27 22:57:40411 break;
Bettina Dea0a4505922017-09-28 00:53:32412 }
[email protected]5d98294912012-06-27 22:57:40413 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37414 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09415 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40416 break;
417 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37418 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37419 SelectNextTab(browser_,
420 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40421 break;
422 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37423 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37424 SelectPreviousTab(browser_,
425 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40426 break;
[email protected]5d98294912012-06-27 22:57:40427 case IDC_MOVE_TAB_NEXT:
428 MoveTabNext(browser_);
429 break;
430 case IDC_MOVE_TAB_PREVIOUS:
431 MoveTabPrevious(browser_);
432 break;
433 case IDC_SELECT_TAB_0:
434 case IDC_SELECT_TAB_1:
435 case IDC_SELECT_TAB_2:
436 case IDC_SELECT_TAB_3:
437 case IDC_SELECT_TAB_4:
438 case IDC_SELECT_TAB_5:
439 case IDC_SELECT_TAB_6:
440 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37441 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37442 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0,
443 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40444 break;
445 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37446 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37447 SelectLastTab(browser_,
448 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40449 break;
450 case IDC_DUPLICATE_TAB:
451 DuplicateTab(browser_);
452 break;
453 case IDC_RESTORE_TAB:
454 RestoreTab(browser_);
Collin Baker9bbe1d82019-03-08 01:16:27455 browser_->window()->OnTabRestored(IDC_RESTORE_TAB);
[email protected]5d98294912012-06-27 22:57:40456 break;
[email protected]5d98294912012-06-27 22:57:40457 case IDC_SHOW_AS_TAB:
458 ConvertPopupToTabbedBrowser(browser_);
459 break;
460 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28461 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40462 break;
Alan Cutter09965802018-03-27 07:25:29463 case IDC_OPEN_IN_PWA_WINDOW:
464 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
Eric Willigerse2ca235a2019-08-17 01:01:06465 web_app::ReparentWebAppForSecureActiveTab(browser_);
Alan Cutter09965802018-03-27 07:25:29466 break;
Leonard Greyf13493b2019-12-19 18:12:57467 case IDC_MOVE_TAB_TO_NEW_WINDOW:
468 MoveTabToNewWindow(browser_);
469 break;
[email protected]770c6d82012-09-06 22:21:32470
[email protected]d12cc5e2013-10-19 18:25:06471#if defined(OS_CHROMEOS)
472 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47473 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35474 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47475 break;
[email protected]d12cc5e2013-10-19 18:25:06476#endif
477
[email protected]893124a22014-04-15 00:45:28478#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15479 case IDC_MINIMIZE_WINDOW:
480 browser_->window()->Minimize();
481 break;
482 case IDC_MAXIMIZE_WINDOW:
483 browser_->window()->Maximize();
484 break;
485 case IDC_RESTORE_WINDOW:
486 browser_->window()->Restore();
487 break;
[email protected]af97be4c62014-02-13 14:43:34488 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35489 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34490 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
491 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
492 break;
493 }
494#endif
495
[email protected]5d98294912012-06-27 22:57:40496#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21497 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
498 chrome::ToggleFullscreenToolbar(browser_);
499 break;
spqchan2c5d541e2017-10-25 07:07:11500 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
Robert Sesek03282612018-10-31 15:48:06501 chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_);
spqchan2c5d541e2017-10-25 07:07:11502 break;
503 }
[email protected]5d98294912012-06-27 22:57:40504#endif
505 case IDC_EXIT:
506 Exit();
507 break;
508
509 // Page-related commands
510 case IDC_SAVE_PAGE:
511 SavePage(browser_);
512 break;
Peter Kasting32bb2602019-08-22 19:01:43513 case IDC_BOOKMARK_THIS_TAB:
Collin Baker4ab8ad82019-06-06 17:02:54514#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14515 feature_engagement::BookmarkTrackerFactory::GetInstance()
516 ->GetForProfile(profile())
517 ->OnBookmarkAdded();
518#endif
Peter Kasting32bb2602019-08-22 19:01:43519 BookmarkCurrentTabAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40520 break;
[email protected]5d98294912012-06-27 22:57:40521 case IDC_BOOKMARK_ALL_TABS:
Collin Baker4ab8ad82019-06-06 17:02:54522#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14523 feature_engagement::BookmarkTrackerFactory::GetInstance()
524 ->GetForProfile(profile())
525 ->OnBookmarkAdded();
526#endif
[email protected]5d98294912012-06-27 22:57:40527 BookmarkAllTabs(browser_);
528 break;
529 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06530 browser_->tab_strip_model()
531 ->GetActiveWebContents()
532 ->GetMainFrame()
533 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40534 break;
535 case IDC_EMAIL_PAGE_LOCATION:
536 EmailPageLocation(browser_);
537 break;
538 case IDC_PRINT:
539 Print(browser_);
540 break;
bondd052b5f82015-10-28 22:39:32541
Lei Zhang48a4a5262018-04-17 20:18:44542#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55543 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37544 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55545 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40546 break;
Lei Zhang48a4a5262018-04-17 20:18:44547#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32548
bondd052b5f82015-10-28 22:39:32549 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
550 SaveCreditCard(browser_);
551 break;
siyua3e599eaa2018-07-13 00:23:06552 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
553 MigrateLocalCards(browser_);
554 break;
siyuac6e018d2019-10-18 01:19:30555 case IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE:
556 MaybeShowSaveLocalCardSignInPromo(browser_);
557 break;
558 case IDC_CLOSE_SIGN_IN_PROMO:
559 CloseSaveLocalCardSignInPromo(browser_);
560 break;
[email protected]e625b7602013-10-28 09:24:56561 case IDC_TRANSLATE_PAGE:
562 Translate(browser_);
563 break;
[email protected]4bee4432014-05-05 13:11:41564 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
565 ManagePasswordsForPage(browser_);
566 break;
Tina Wang4c324702019-04-25 18:35:15567 case IDC_SEND_TAB_TO_SELF:
Tina Wang0e7e6e92019-05-14 21:03:03568 SendTabToSelfFromPageAction(browser_);
Tina Wang4c324702019-04-25 18:35:15569 break;
[email protected]4bee4432014-05-05 13:11:41570
[email protected]5d98294912012-06-27 22:57:40571 // Clipboard commands
572 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40573 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40574 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12575 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40576 break;
577
578 // Find-in-page
579 case IDC_FIND:
580 Find(browser_);
581 break;
582 case IDC_FIND_NEXT:
583 FindNext(browser_);
584 break;
585 case IDC_FIND_PREVIOUS:
586 FindPrevious(browser_);
587 break;
Jeff Fisher6cc1ce7b2019-06-28 23:02:38588 case IDC_CLOSE_FIND_OR_STOP:
589 if (CanCloseFind(browser_))
590 CloseFind(browser_);
591 else if (IsCommandEnabled(IDC_STOP))
592 ExecuteCommand(IDC_STOP);
593 break;
[email protected]5d98294912012-06-27 22:57:40594
595 // Zoom
596 case IDC_ZOOM_PLUS:
597 Zoom(browser_, content::PAGE_ZOOM_IN);
598 break;
599 case IDC_ZOOM_NORMAL:
600 Zoom(browser_, content::PAGE_ZOOM_RESET);
601 break;
602 case IDC_ZOOM_MINUS:
603 Zoom(browser_, content::PAGE_ZOOM_OUT);
604 break;
605
606 // Focus various bits of UI
607 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37608 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40609 FocusToolbar(browser_);
610 break;
611 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37612 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40613 FocusLocationBar(browser_);
614 break;
615 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37616 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40617 FocusSearch(browser_);
618 break;
619 case IDC_FOCUS_MENU_BAR:
620 FocusAppMenu(browser_);
621 break;
622 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37623 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40624 FocusBookmarksToolbar(browser_);
625 break;
David Tsengc0b1b642018-01-24 07:12:27626 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
627 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15628 break;
[email protected]5d98294912012-06-27 22:57:40629 case IDC_FOCUS_NEXT_PANE:
630 FocusNextPane(browser_);
631 break;
632 case IDC_FOCUS_PREVIOUS_PANE:
633 FocusPreviousPane(browser_);
634 break;
635
636 // Show various bits of UI
637 case IDC_OPEN_FILE:
638 browser_->OpenFile();
639 break;
Alan Cutter81ac726682018-09-25 00:18:36640 case IDC_CREATE_SHORTCUT:
Alan Cutter98844a9fa2019-06-19 21:11:40641 base::RecordAction(base::UserMetricsAction("CreateShortcut"));
Alan Cutter81ac726682018-09-25 00:18:36642 CreateBookmarkAppFromCurrentWebContents(browser_,
643 true /* force_shortcut_app */);
644 break;
645 case IDC_INSTALL_PWA:
Alan Cutter98844a9fa2019-06-19 21:11:40646 base::RecordAction(base::UserMetricsAction("InstallWebAppFromMenu"));
Alan Cutter81ac726682018-09-25 00:18:36647 CreateBookmarkAppFromCurrentWebContents(browser_,
648 false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14649 break;
[email protected]5d98294912012-06-27 22:57:40650 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01651 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40652 break;
653 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52654 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40655 break;
[email protected]2056c3192013-10-21 22:40:51656 case IDC_DEV_TOOLS_DEVICES:
657 InspectUI::InspectDevices(browser_);
658 break;
[email protected]5d98294912012-06-27 22:57:40659 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01660 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40661 break;
[email protected]d16657c2012-09-03 14:25:10662 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01663 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10664 break;
[email protected]5d98294912012-06-27 22:57:40665 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38666 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40667 break;
caelyn4e4e08a2015-02-04 21:27:49668#if defined(OS_CHROMEOS)
669 case IDC_TAKE_SCREENSHOT:
670 TakeScreenshot();
671 break;
672#endif
Nico Weber0cc71122019-07-29 17:30:40673#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
[email protected]5d98294912012-06-27 22:57:40674 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04675 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40676 break;
[email protected]236ad3022013-09-04 03:27:43677#endif
[email protected]5d98294912012-06-27 22:57:40678 case IDC_SHOW_BOOKMARK_BAR:
679 ToggleBookmarkBar(browser_);
680 break;
681 case IDC_PROFILING_ENABLED:
Bryce Thomas96b07772018-11-07 03:04:15682 content::Profiling::Toggle();
[email protected]5d98294912012-06-27 22:57:40683 break;
684
685 case IDC_SHOW_BOOKMARK_MANAGER:
686 ShowBookmarkManager(browser_);
687 break;
688 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37689 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40690 ShowAppMenu(browser_);
691 break;
692 case IDC_SHOW_AVATAR_MENU:
693 ShowAvatarMenu(browser_);
694 break;
695 case IDC_SHOW_HISTORY:
696 ShowHistory(browser_);
697 break;
698 case IDC_SHOW_DOWNLOADS:
699 ShowDownloads(browser_);
700 break;
701 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08702 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40703 break;
704 case IDC_OPTIONS:
705 ShowSettings(browser_);
706 break;
707 case IDC_EDIT_SEARCH_ENGINES:
708 ShowSearchEngineSettings(browser_);
709 break;
710 case IDC_VIEW_PASSWORDS:
711 ShowPasswordManager(browser_);
712 break;
713 case IDC_CLEAR_BROWSING_DATA:
714 ShowClearBrowsingDataDialog(browser_);
715 break;
716 case IDC_IMPORT_SETTINGS:
717 ShowImportDialog(browser_);
718 break;
[email protected]9b7ab882012-09-10 23:46:36719 case IDC_TOGGLE_REQUEST_TABLET_SITE:
720 ToggleRequestTabletSite(browser_);
721 break;
[email protected]5d98294912012-06-27 22:57:40722 case IDC_ABOUT:
723 ShowAboutChrome(browser_);
724 break;
725 case IDC_UPGRADE_DIALOG:
726 OpenUpdateChromeDialog(browser_);
727 break;
[email protected]5d98294912012-06-27 22:57:40728 case IDC_HELP_PAGE_VIA_KEYBOARD:
729 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
730 break;
731 case IDC_HELP_PAGE_VIA_MENU:
732 ShowHelp(browser_, HELP_SOURCE_MENU);
733 break;
Bret Sepulveda2d018662017-05-18 21:31:48734 case IDC_SHOW_BETA_FORUM:
735 ShowBetaForum(browser_);
736 break;
David Roger7e25dff2019-02-07 09:03:17737#if !defined(OS_CHROMEOS)
estade8c0780f2015-08-21 23:36:41738 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37739 ShowBrowserSigninOrSettings(
740 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41741 break;
David Roger7e25dff2019-02-07 09:03:17742#endif
[email protected]6bd370b2014-05-28 14:19:47743 case IDC_DISTILL_PAGE:
Aran Gilman6586e8f2019-06-03 18:50:56744 ToggleDistilledView(browser_);
[email protected]6bd370b2014-05-28 14:19:47745 break;
apacible45cbfc92015-09-28 22:45:41746 case IDC_ROUTE_MEDIA:
Takumi Fujimotoa8bc3c92019-12-26 20:12:10747 RouteMediaInvokedFromAppMenu(browser_);
apacible45cbfc92015-09-28 22:45:41748 break;
Tommy Steimelc4477982017-11-29 18:07:18749 case IDC_WINDOW_MUTE_SITE:
750 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26751 break;
752 case IDC_WINDOW_PIN_TAB:
753 PinTab(browser_);
754 break;
Elly Fong-Jones2d0443cb2019-11-14 15:04:20755 case IDC_WINDOW_CLOSE_TABS_TO_RIGHT:
756 CloseTabsToRight(browser_);
757 break;
758 case IDC_WINDOW_CLOSE_OTHER_TABS:
759 CloseOtherTabs(browser_);
760 break;
Yann Dagocd13225a2019-03-07 18:39:05761 case IDC_SHOW_MANAGEMENT_PAGE: {
Yann Dagoc1d1c4af2019-04-17 13:40:51762 ShowSingletonTab(browser_, GURL(kChromeUIManagementURL));
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:27763 break;
Yann Dagocd13225a2019-03-07 18:39:05764 }
Elly Fong-Jones5e6baaf2019-10-10 23:17:14765 case IDC_MUTE_TARGET_SITE:
766 MuteSiteForKeyboardFocusedTab(browser_);
767 break;
768 case IDC_PIN_TARGET_TAB:
769 PinKeyboardFocusedTab(browser_);
770 break;
771 case IDC_DUPLICATE_TARGET_TAB:
772 DuplicateKeyboardFocusedTab(browser_);
773 break;
Christopher Lam0dbac2b2017-11-14 07:12:10774 // Hosted App commands
775 case IDC_COPY_URL:
776 CopyURL(browser_);
777 break;
778 case IDC_OPEN_IN_CHROME:
779 OpenInChrome(browser_);
780 break;
781 case IDC_SITE_SETTINGS:
782 ShowSiteSettings(
783 browser_,
784 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
785 break;
Alan Cuttera99d1522019-09-12 02:09:22786 case IDC_WEB_APP_MENU_APP_INFO: {
Dana Fried08b774a2019-05-10 18:21:48787 content::WebContents* const web_contents =
788 browser_->tab_strip_model()->GetActiveWebContents();
789 if (web_contents) {
790 ShowPageInfoDialog(web_contents,
791 base::BindOnce(&AppInfoDialogClosedCallback,
792 base::Unretained(web_contents)),
793 bubble_anchor_util::kAppMenuButton);
794 }
Christopher Lam86b52712017-12-04 01:58:33795 break;
Dana Fried08b774a2019-05-10 18:21:48796 }
[email protected]5d98294912012-06-27 22:57:40797 default:
798 LOG(WARNING) << "Received Unimplemented Command: " << id;
799 break;
800 }
Ivan Sandrk9669d0e2017-12-15 23:50:20801
802 return true;
803}
804
805void BrowserCommandController::AddCommandObserver(int id,
806 CommandObserver* observer) {
807 command_updater_.AddCommandObserver(id, observer);
808}
809
810void BrowserCommandController::RemoveCommandObserver(
Aran Gilmand217b5b2019-04-11 17:45:43811 int id,
812 CommandObserver* observer) {
Ivan Sandrk9669d0e2017-12-15 23:50:20813 command_updater_.RemoveCommandObserver(id, observer);
814}
815
816void BrowserCommandController::RemoveCommandObserver(
817 CommandObserver* observer) {
818 command_updater_.RemoveCommandObserver(observer);
819}
820
821bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
822 if (is_locked_fullscreen_)
823 return false;
824
825 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40826}
827
Mihai Sardarescuf87ccc12018-09-26 10:37:45828////////////////////////////////////////////////////////////////////////////////
829// BrowserCommandController, SigninPrefObserver implementation:
830
831void BrowserCommandController::OnSigninAllowedPrefChange() {
832 // For unit tests, we don't have a window.
833 if (!window())
834 return;
835 UpdateShowSyncState(IsShowingMainUI());
836}
837
[email protected]5d98294912012-06-27 22:57:40838// BrowserCommandController, TabStripModelObserver implementation:
839
sangwoo.ko1ae265f12018-10-18 08:30:28840void BrowserCommandController::OnTabStripModelChanged(
841 TabStripModel* tab_strip_model,
842 const TabStripModelChange& change,
843 const TabStripSelectionChange& selection) {
Dana Frieda391e6ce2019-05-08 00:00:20844 std::vector<content::WebContents*> new_contents;
845 std::vector<content::WebContents*> old_contents;
[email protected]5d98294912012-06-27 22:57:40846
Dana Frieda391e6ce2019-05-08 00:00:20847 switch (change.type()) {
848 case TabStripModelChange::kInserted:
849 for (const auto& contents : change.GetInsert()->contents)
850 new_contents.push_back(contents.contents);
851 break;
852 case TabStripModelChange::kReplaced: {
853 auto* replace = change.GetReplace();
854 new_contents.push_back(replace->new_contents);
855 old_contents.push_back(replace->old_contents);
856 break;
sangwoo.ko1ae265f12018-10-18 08:30:28857 }
Dana Frieda391e6ce2019-05-08 00:00:20858 case TabStripModelChange::kRemoved:
859 for (const auto& contents : change.GetRemove()->contents)
860 old_contents.push_back(contents.contents);
861 break;
862 default:
863 break;
sangwoo.ko1ae265f12018-10-18 08:30:28864 }
Dana Frieda391e6ce2019-05-08 00:00:20865
866 for (auto* contents : old_contents)
867 RemoveInterstitialObservers(contents);
868 for (auto* contents : new_contents)
869 AddInterstitialObservers(contents);
[email protected]5d98294912012-06-27 22:57:40870}
871
[email protected]3cac87232012-11-20 01:48:27872void BrowserCommandController::TabBlockedStateChanged(
873 content::WebContents* contents,
874 int index) {
875 PrintingStateChanged();
876 FullscreenStateChanged();
877 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41878 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27879}
880
[email protected]5d98294912012-06-27 22:57:40881////////////////////////////////////////////////////////////////////////////////
882// BrowserCommandController, TabRestoreServiceObserver implementation:
883
884void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25885 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53886 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40887}
888
889void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25890 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40891 service->RemoveObserver(this);
892}
893
[email protected]2e9369e2014-08-15 09:12:53894void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25895 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53896 UpdateTabRestoreCommandState();
897}
898
[email protected]5d98294912012-06-27 22:57:40899////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40900// BrowserCommandController, private:
901
[email protected]20ca0382013-02-28 19:50:07902class BrowserCommandController::InterstitialObserver
903 : public content::WebContentsObserver {
904 public:
905 InterstitialObserver(BrowserCommandController* controller,
906 content::WebContents* web_contents)
Aran Gilmand217b5b2019-04-11 17:45:43907 : WebContentsObserver(web_contents), controller_(controller) {}
[email protected]20ca0382013-02-28 19:50:07908
dcheng5dd5ff62014-10-21 12:42:38909 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07910 controller_->UpdateCommandsForTabState();
911 }
912
dcheng5dd5ff62014-10-21 12:42:38913 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07914 controller_->UpdateCommandsForTabState();
915 }
916
917 private:
918 BrowserCommandController* controller_;
919
920 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
921};
922
[email protected]6a414ff2013-02-27 08:22:54923bool BrowserCommandController::IsShowingMainUI() {
manukf1a116392018-10-25 16:28:24924 return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
925}
926
927bool BrowserCommandController::IsShowingLocationBar() {
928 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
[email protected]5d98294912012-06-27 22:57:40929}
930
931void BrowserCommandController::InitCommandState() {
932 // All browser commands whose state isn't set automagically some other way
933 // (like Back & Forward with initial page load) must have their state
934 // initialized here, otherwise they will be forever disabled.
935
Ivan Sandrk9669d0e2017-12-15 23:50:20936 if (is_locked_fullscreen_)
937 return;
938
[email protected]5d98294912012-06-27 22:57:40939 // Navigation commands
940 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05941 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57942 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40943
944 // Window management commands
945 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
946 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
947 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
948 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53949 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55950 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40951 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06952#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58953 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06954 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
955 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
956#endif
[email protected]893124a22014-04-15 00:45:28957#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15958 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
959 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
960 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15961 bool use_system_title_bar = true;
962#if defined(USE_OZONE)
963 use_system_title_bar = ui::OzonePlatform::GetInstance()
964 ->GetPlatformProperties()
965 .use_system_title_bar;
966#endif
967 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
968 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34969#endif
Alan Cutter09965802018-03-27 07:25:29970 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40971
972 // Page-related commands
973 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41974 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40975
976 // Zoom
977 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
978 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53979 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40980 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
981
982 // Show various bits of UI
Aran Gilmand217b5b2019-04-11 17:45:43983 const bool guest_session =
984 profile()->IsGuestSession() || profile()->IsSystemProfile();
mlerman7831f57d2015-05-25 11:40:15985 DCHECK(!profile()->IsSystemProfile())
986 << "Ought to never have browser for the system profile.";
Joel Hockey2687ab52019-08-14 23:59:46987 const bool normal_window = browser_->is_type_normal();
[email protected]05454532013-01-22 21:09:08988 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40989 UpdateCommandsForDevTools();
990 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06991 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40992 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56993 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40994 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
995 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48996 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06997 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
Aran Gilmand217b5b2019-04-11 17:45:43998 command_updater_.UpdateCommandEnabled(
999 IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord());
Rohit Agarwal2a2230b2019-08-21 15:53:411000 command_updater_.UpdateCommandEnabled(
1001 IDC_CLEAR_BROWSING_DATA,
1002 !guest_session && !profile()->IsIncognitoProfile());
[email protected]39d47592014-01-10 21:42:451003#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:491004 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
Ramin Halavatif362b7a2019-04-17 05:24:501005 // Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu
1006 // is only required in incognito mode.
Ramin Halavati2394dc452019-05-21 16:21:581007 if (profile()->IsIncognitoProfile())
[email protected]338416c02014-05-13 16:47:061008 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
Ramin Halavatif362b7a2019-04-17 05:24:501009#else
1010 if (normal_window)
1011 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
[email protected]39d47592014-01-10 21:42:451012#endif
siyuac6e018d2019-10-18 01:19:301013 command_updater_.UpdateCommandEnabled(
1014 IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE, true);
1015 command_updater_.UpdateCommandEnabled(IDC_CLOSE_SIGN_IN_PROMO, true);
[email protected]5d98294912012-06-27 22:57:401016
Mihai Sardarescu2ec5205682018-09-26 09:20:051017 UpdateShowSyncState(true);
1018
[email protected]5d98294912012-06-27 22:57:401019 // Navigation commands
Joel Hockey2687ab52019-08-14 23:59:461020 command_updater_.UpdateCommandEnabled(
1021 IDC_HOME, normal_window || browser_->deprecated_is_app());
[email protected]5d98294912012-06-27 22:57:401022
Alan Cutterd0bd51902019-05-22 04:15:231023 const bool is_web_app =
1024 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Christopher Lam0dbac2b2017-11-14 07:12:101025 // Hosted app browser commands.
Alan Cutterd0bd51902019-05-22 04:15:231026 command_updater_.UpdateCommandEnabled(IDC_COPY_URL, is_web_app);
1027 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME, is_web_app);
1028 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS, is_web_app);
Alan Cuttera99d1522019-09-12 02:09:221029 command_updater_.UpdateCommandEnabled(IDC_WEB_APP_MENU_APP_INFO, is_web_app);
Christopher Lam0dbac2b2017-11-14 07:12:101030
[email protected]5d98294912012-06-27 22:57:401031 // Window management commands
[email protected]5d98294912012-06-27 22:57:401032 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
Aran Gilmand217b5b2019-04-11 17:45:431033 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:401034 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
1035 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
1036 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
1037 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
1038 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
1039 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
1040 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
1041 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
1042 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
1043 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
1044 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:401045
[email protected]338416c02014-05-13 16:47:061046 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:401047 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:401048
[email protected]6bd370b2014-05-28 14:19:471049 // Distill current page.
Aran Gilman7b6ccf5d2019-09-05 19:16:021050 command_updater_.UpdateCommandEnabled(IDC_DISTILL_PAGE,
1051 dom_distiller::IsDomDistillerEnabled());
[email protected]6bd370b2014-05-28 14:19:471052
Tommy Steimelc4477982017-11-29 18:07:181053 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:261054 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
Elly Fong-Jones2d0443cb2019-11-14 15:04:201055 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1056 normal_window);
1057 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1058 normal_window);
ellyjones0101ba02017-05-19 15:50:261059
[email protected]338416c02014-05-13 16:47:061060 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:251061 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:401062 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:401063 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:401064 UpdateCommandsForIncognitoAvailability();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141065 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]5d98294912012-06-27 22:57:401066}
1067
[email protected]05454532013-01-22 21:09:081068// static
1069void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1070 CommandUpdater* command_updater,
1071 Profile* profile) {
mlermane01e6de2014-09-29 19:26:471072 const bool guest_session = profile->IsGuestSession();
1073 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:401074 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:081075 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
1076 command_updater->UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431077 IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:081078 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401079 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:471080 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:401081
[email protected]57b25292014-05-01 16:31:061082 const bool forced_incognito =
1083 incognito_availability == IncognitoModePrefs::FORCED ||
1084 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:081085 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401086 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:061087 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:161088 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:551089 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:061090 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401091 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401092
[email protected]57b25292014-05-01 16:31:061093 // Bookmark manager and settings page/subpages are forced to open in normal
1094 // mode. For this reason we disable these commands when incognito is forced.
1095 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1096 enable_extensions && !forced_incognito);
1097
1098 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1099 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1100 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411101 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081102}
1103
1104void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201105 if (is_locked_fullscreen_)
1106 return;
1107
[email protected]05454532013-01-22 21:09:081108 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1109
[email protected]6a414ff2013-02-27 08:22:541110 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081111 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1112 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1113 }
[email protected]5d98294912012-06-27 22:57:401114}
1115
1116void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201117 if (is_locked_fullscreen_)
1118 return;
1119
[email protected]617ee962013-01-29 20:49:121120 WebContents* current_web_contents =
1121 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571122 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401123 return;
[email protected]5d98294912012-06-27 22:57:401124
1125 // Navigation commands
1126 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1127 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1128 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051129 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401130 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571131 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1132 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401133
1134 // Window management commands
Aran Gilmand217b5b2019-04-11 17:45:431135 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461136 IDC_DUPLICATE_TAB,
1137 !browser_->deprecated_is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181138 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
Joel Hockey2687ab52019-08-14 23:59:461139 !browser_->deprecated_is_app());
ellyjones0101ba02017-05-19 15:50:261140 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
Joel Hockey2687ab52019-08-14 23:59:461141 !browser_->deprecated_is_app());
Elly Fong-Jones2d0443cb2019-11-14 15:04:201142 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1143 CanCloseTabsToRight(browser_));
1144 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1145 CanCloseOtherTabs(browser_));
Leonard Greyf13493b2019-12-19 18:12:571146 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_TO_NEW_WINDOW,
1147 CanMoveTabToNewWindow(browser_));
[email protected]5d98294912012-06-27 22:57:401148
1149 // Page-related commands
1150 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571151 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161152 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401153 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1154 CanViewSource(browser_));
1155 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1156 CanEmailPageLocation(browser_));
Joel Hockey2687ab52019-08-14 23:59:461157 if (browser_->is_type_devtools())
[email protected]5d98294912012-06-27 22:57:401158 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1159
Alan Cutter81ac726682018-09-25 00:18:361160 bool can_create_bookmark_app = CanCreateBookmarkApp(browser_);
1161 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA,
1162 can_create_bookmark_app);
1163 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
1164 can_create_bookmark_app);
Alan Cutter403cebb2018-05-17 05:22:451165 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Alan Cutter81ac726682018-09-25 00:18:361166 can_create_bookmark_app);
[email protected]5d98294912012-06-27 22:57:401167
[email protected]9b7ab882012-09-10 23:46:361168 command_updater_.UpdateCommandEnabled(
1169 IDC_TOGGLE_REQUEST_TABLET_SITE,
1170 CanRequestTabletSite(current_web_contents));
1171
[email protected]5d98294912012-06-27 22:57:401172 UpdateCommandsForContentRestrictionState();
1173 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271174 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411175 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531176 // Update the zoom commands when an active tab is selected.
1177 UpdateCommandsForZoomState();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141178 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]d93dbd12014-08-04 23:42:531179}
1180
1181void BrowserCommandController::UpdateCommandsForZoomState() {
Aran Gilmand217b5b2019-04-11 17:45:431182 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
[email protected]d93dbd12014-08-04 23:42:531183 if (!contents)
1184 return;
Aran Gilmand217b5b2019-04-11 17:45:431185 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
a.sarkar.arundaadc712015-02-26 05:39:081186 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241187 CanResetZoom(contents));
Aran Gilmand217b5b2019-04-11 17:45:431188 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401189}
1190
1191void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1192 int restrictions = GetContentRestrictions(browser_);
1193
1194 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011195 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401196 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011197 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401198 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011199 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401200 UpdateSaveAsState();
1201 UpdatePrintingState();
1202}
1203
1204void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201205 if (is_locked_fullscreen_)
1206 return;
1207
Pavol Marko56df0272018-07-04 17:55:041208 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1209 profile(), browser_->tab_strip_model()->GetActiveWebContents());
Aran Gilmand217b5b2019-04-11 17:45:431210 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401211 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1212 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511213 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1214 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401215 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1216 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101217 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1218 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111219#if defined(OS_MACOSX)
1220 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1221 dev_tools_enabled);
1222#endif
[email protected]5d98294912012-06-27 22:57:401223}
1224
1225void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201226 if (is_locked_fullscreen_)
1227 return;
1228
Peter Kasting32bb2602019-08-22 19:01:431229 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_THIS_TAB,
1230 CanBookmarkCurrentTab(browser_));
[email protected]5d98294912012-06-27 22:57:401231 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1232 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291233#if defined(OS_WIN)
1234 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1235#endif
[email protected]5d98294912012-06-27 22:57:401236}
1237
1238void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201239 if (is_locked_fullscreen_)
1240 return;
1241
tfarina3bddbe112014-08-28 05:29:321242 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431243 IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled &&
1244 !profile()->IsGuestSession() &&
1245 !profile()->IsSystemProfile() &&
1246 !profile()->GetPrefs()->IsManagedPreference(
1247 bookmarks::prefs::kShowBookmarkBar) &&
1248 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401249}
1250
[email protected]9ec3ea5b2012-12-03 18:14:301251void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201252 if (is_locked_fullscreen_)
1253 return;
1254
[email protected]9ec3ea5b2012-12-03 18:14:301255 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081256 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301257}
1258
[email protected]32dfede2013-08-25 15:48:251259void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201260 if (is_locked_fullscreen_)
1261 return;
1262
zijiehe3c7af992017-02-12 20:59:401263 const bool is_fullscreen = window() && window()->IsFullscreen();
1264 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241265 const bool show_location_bar = IsShowingLocationBar();
1266
zijiehe3c7af992017-02-12 20:59:401267 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401268
1269 // Navigation commands
1270 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1271
1272 // Window management commands
1273 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461274 IDC_SHOW_AS_TAB, !browser_->is_type_normal() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401275
1276 // Focus various bits of UI
1277 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241278 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401279 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
Aran Gilmand217b5b2019-04-11 17:45:431280 command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR,
1281 main_not_fullscreen);
1282 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE,
1283 main_not_fullscreen);
1284 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE,
1285 main_not_fullscreen);
1286 command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS,
1287 main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151288 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271289 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401290
1291 // Show various bits of UI
1292 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
Nico Weber0cc71122019-07-29 17:30:401293#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
Fabio Rocha19bf4262019-04-04 01:05:181294 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461295 IDC_FEEDBACK, show_main_ui || browser_->is_type_devtools());
[email protected]236ad3022013-09-04 03:27:431296#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051297 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401298
[email protected]5d98294912012-06-27 22:57:401299 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1300 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1301 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1302 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Tina Wangf09681ac2019-03-27 20:52:101303 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui);
Tina Wangfa016992019-05-31 00:01:151304 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF_SINGLE_TARGET,
1305 show_main_ui);
Yann Dago70ca3dd2019-02-27 01:12:351306 command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true);
primianod3a81ab2016-01-25 22:21:151307
1308 if (base::debug::IsProfilingSupported())
1309 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401310
[email protected]aeafc3852014-04-29 16:51:291311#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401312 // Disable toggling into fullscreen mode if disallowed by pref.
Aran Gilmand217b5b2019-04-11 17:45:431313 const bool fullscreen_enabled =
1314 is_fullscreen ||
zijiehe3c7af992017-02-12 20:59:401315 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1316#else
1317 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511318#endif
1319
1320 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211321 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1322 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401323
1324 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411325 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001326 UpdateCommandsForHostedAppAvailability();
1327}
1328
1329void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1330 bool has_toolbar =
Joel Hockey2687ab52019-08-14 23:59:461331 browser_->is_type_normal() ||
Alan Cutterd0bd51902019-05-22 04:15:231332 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Alan Cutter167dfe82018-04-11 09:06:001333 if (window() && window()->ShouldHideUIForFullscreen())
1334 has_toolbar = false;
1335 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1336 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1337 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1338 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401339}
1340
Ivan Sandrk9669d0e2017-12-15 23:50:201341#if defined(OS_CHROMEOS)
1342namespace {
1343
1344#if DCHECK_IS_ON()
1345// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1346// otherwise. Compiled only in debug mode.
1347void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
Ivan Sandrk6ac9c9a2018-12-14 14:15:071348 constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201349
1350 // Go through all the command ids, skip the whitelisted ones.
1351 for (int id : command_updater->GetAllIds()) {
Jan Wilken Dörriea8cb56302019-06-06 18:59:361352 if (base::Contains(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201353 continue;
1354 }
1355 DCHECK(!command_updater->IsCommandEnabled(id));
1356 }
1357}
1358#endif
1359
1360} // namespace
1361
1362void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrke0e92452019-03-21 09:32:481363 bool is_locked_fullscreen =
1364 platform_util::IsBrowserLockedFullscreen(browser_);
Ivan Sandrk9669d0e2017-12-15 23:50:201365 // Sanity check to make sure this function is called only on state change.
1366 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1367 if (is_locked_fullscreen == is_locked_fullscreen_)
1368 return;
1369 is_locked_fullscreen_ = is_locked_fullscreen;
1370
1371 if (is_locked_fullscreen_) {
1372 command_updater_.DisableAllCommands();
1373 // Update the state of whitelisted commands:
1374 // IDC_CUT/IDC_COPY/IDC_PASTE,
1375 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071376 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201377 // All other commands will be disabled (there is an early return in their
1378 // corresponding UpdateCommandsFor* functions).
1379#if DCHECK_IS_ON()
1380 NonWhitelistedCommandsAreDisabled(&command_updater_);
1381#endif
1382 } else {
1383 // Do an init call to re-initialize command state after the
1384 // DisableAllCommands.
1385 InitCommandState();
1386 }
1387}
1388#endif
1389
[email protected]5d98294912012-06-27 22:57:401390void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201391 if (is_locked_fullscreen_)
1392 return;
1393
[email protected]d53e4032012-06-29 18:58:341394 bool print_enabled = CanPrint(browser_);
1395 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441396#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551397 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1398 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441399#endif
[email protected]5d98294912012-06-27 22:57:401400}
1401
1402void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201403 if (is_locked_fullscreen_)
1404 return;
1405
[email protected]5d98294912012-06-27 22:57:401406 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1407}
1408
Mihai Sardarescu2ec5205682018-09-26 09:20:051409void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1410 if (is_locked_fullscreen_)
1411 return;
1412
Mihai Sardarescuf87ccc12018-09-26 10:37:451413 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141414 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051415}
1416
[email protected]05454532013-01-22 21:09:081417// static
1418void BrowserCommandController::UpdateOpenFileState(
1419 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401420 bool enabled = true;
1421 PrefService* local_state = g_browser_process->local_state();
1422 if (local_state)
1423 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1424
[email protected]05454532013-01-22 21:09:081425 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401426}
1427
1428void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1429 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201430 if (is_locked_fullscreen_)
1431 return;
1432
[email protected]5d98294912012-06-27 22:57:401433 window()->UpdateReloadStopState(is_loading, force);
1434 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
Jeff Fisher6cc1ce7b2019-06-28 23:02:381435 UpdateCloseFindOrStop();
[email protected]5d98294912012-06-27 22:57:401436}
1437
[email protected]2e9369e2014-08-15 09:12:531438void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201439 if (is_locked_fullscreen_)
1440 return;
1441
blundell74001adc2015-09-18 11:04:251442 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531443 TabRestoreServiceFactory::GetForProfile(profile());
1444 // The command is enabled if the service hasn't loaded yet to trigger loading.
1445 // The command is updated once the load completes.
1446 command_updater_.UpdateCommandEnabled(
1447 IDC_RESTORE_TAB,
Peter Kasting32bb2602019-08-22 19:01:431448 tab_restore_service && (!tab_restore_service->IsLoaded() ||
1449 !tab_restore_service->entries().empty()));
[email protected]2e9369e2014-08-15 09:12:531450}
1451
[email protected]3cac87232012-11-20 01:48:271452void BrowserCommandController::UpdateCommandsForFind() {
1453 TabStripModel* model = browser_->tab_strip_model();
Joel Hockey2687ab52019-08-14 23:59:461454 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1455 !browser_->is_type_devtools();
[email protected]3cac87232012-11-20 01:48:271456
1457 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1458 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1459 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1460}
1461
Jeff Fisher6cc1ce7b2019-06-28 23:02:381462void BrowserCommandController::UpdateCloseFindOrStop() {
1463 bool enabled = CanCloseFind(browser_) || IsCommandEnabled(IDC_STOP);
1464 command_updater_.UpdateCommandEnabled(IDC_CLOSE_FIND_OR_STOP, enabled);
1465}
1466
apacible45cbfc92015-09-28 22:45:411467void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201468 if (is_locked_fullscreen_)
1469 return;
1470
apacible45cbfc92015-09-28 22:45:411471 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1472 CanRouteMedia(browser_));
1473}
1474
Elly Fong-Jones5e6baaf2019-10-10 23:17:141475void BrowserCommandController::UpdateCommandsForTabKeyboardFocus(
1476 base::Optional<int> target_index) {
1477 command_updater_.UpdateCommandEnabled(
1478 IDC_DUPLICATE_TARGET_TAB, !browser_->deprecated_is_app() &&
1479 target_index.has_value() &&
1480 CanDuplicateTabAt(browser_, *target_index));
1481 const bool normal_window = browser_->is_type_normal();
1482 command_updater_.UpdateCommandEnabled(
1483 IDC_MUTE_TARGET_SITE, normal_window && target_index.has_value());
1484 command_updater_.UpdateCommandEnabled(
1485 IDC_PIN_TARGET_TAB, normal_window && target_index.has_value());
1486}
1487
[email protected]409ea2972012-11-10 19:54:431488void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071489 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401490}
1491
1492void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241493 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071494 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1495 if (interstitial_observers_[i]->web_contents() != contents)
1496 continue;
1497
1498 delete interstitial_observers_[i];
1499 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1500 return;
1501 }
[email protected]5d98294912012-06-27 22:57:401502}
1503
1504BrowserWindow* BrowserCommandController::window() {
1505 return browser_->window();
1506}
1507
1508Profile* BrowserCommandController::profile() {
1509 return browser_->profile();
1510}
1511
[email protected]5d98294912012-06-27 22:57:401512} // namespace chrome