blob: 361a38a0cdfd8592f83381fb632f06bf6152d08b [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
[email protected]488e3952013-11-18 05:29:1411#include "base/command_line.h"
brettwfb87ed22015-12-05 00:44:1512#include "base/debug/debugging_flags.h"
primianod3a81ab2016-01-25 22:21:1513#include "base/debug/profiler.h"
avi655876a2015-12-25 07:18:1514#include "base/macros.h"
bratell0a7406f2017-03-28 07:46:3715#include "base/metrics/user_metrics.h"
avi655876a2015-12-25 07:18:1516#include "build/build_config.h"
[email protected]5d98294912012-06-27 22:57:4017#include "chrome/app/chrome_command_ids.h"
18#include "chrome/browser/browser_process.h"
[email protected]dcc8fbc2013-07-12 00:54:0919#include "chrome/browser/chrome_notification_types.h"
[email protected]5d98294912012-06-27 22:57:4020#include "chrome/browser/defaults.h"
21#include "chrome/browser/extensions/extension_service.h"
benwells39f23ae2014-08-27 08:01:5222#include "chrome/browser/extensions/extension_util.h"
[email protected]2e9d79f2013-08-16 05:45:5623#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4024#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4025#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4726#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4027#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0328#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1629#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4030#include "chrome/browser/sync/profile_sync_service_factory.h"
[email protected]5d98294912012-06-27 22:57:4031#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
32#include "chrome/browser/ui/browser.h"
33#include "chrome/browser/ui/browser_commands.h"
34#include "chrome/browser/ui/browser_window.h"
35#include "chrome/browser/ui/chrome_pages.h"
[email protected]5d98294912012-06-27 22:57:4036#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]2056c3192013-10-21 22:40:5137#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0138#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4039#include "chrome/common/pref_names.h"
40#include "chrome/common/profiling.h"
brettwe1f0af8b2015-10-09 21:30:4641#include "components/bookmarks/common/bookmark_pref_names.h"
maxbogue26f40222016-09-16 20:22:1842#include "components/browser_sync/profile_sync_service.h"
sdefresne0f2ef352015-07-27 19:18:0043#include "components/dom_distiller/core/dom_distiller_switches.h"
Bettina Deaf3dac202017-09-16 20:53:2244#include "components/feature_engagement/features.h"
brettwb1fc1b82016-02-02 00:19:0845#include "components/prefs/pref_service.h"
blundella08c5dd2015-09-18 06:14:1646#include "components/sessions/core/tab_restore_service.h"
brettwe1f0af8b2015-10-09 21:30:4647#include "components/signin/core/common/signin_pref_names.h"
[email protected]5d98294912012-06-27 22:57:4048#include "content/public/browser/native_web_keyboard_event.h"
49#include "content/public/browser/navigation_controller.h"
50#include "content/public/browser/navigation_entry.h"
[email protected]5d98294912012-06-27 22:57:4051#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0752#include "content/public/browser/web_contents_observer.h"
bend32292b2016-10-07 00:21:5853#include "content/public/common/service_manager_connection.h"
[email protected]5d98294912012-06-27 22:57:4054#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5555#include "extensions/browser/extension_system.h"
riajiangc4a5b6b2016-09-02 23:47:1156#include "mash/public/interfaces/launchable.mojom.h"
Brett Wilson65f951c2016-11-03 22:06:1257#include "printing/features/features.h"
rockot734fb662016-10-15 16:41:3058#include "services/service_manager/public/cpp/connector.h"
[email protected]7e9acd082013-09-17 23:31:1659#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4060
[email protected]9c4d68332013-01-30 13:34:4161#if defined(OS_MACOSX)
62#include "chrome/browser/ui/browser_commands_mac.h"
63#endif
64
[email protected]5d98294912012-06-27 22:57:4065#if defined(OS_WIN)
[email protected]a43ed002013-02-05 19:47:5466#include "base/win/windows_version.h"
[email protected]2d0f80f2013-11-01 22:47:1867#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4068#endif
69
[email protected]d12cc5e2013-10-19 18:25:0670#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:5871#include "ash/accelerators/accelerator_commands_classic.h" // mash-ok
72#include "chrome/browser/ui/ash/ash_util.h"
[email protected]0c930812014-01-30 18:01:4773#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
[email protected]5226f1e2013-11-09 04:12:1074#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
caelyn4e4e08a2015-02-04 21:27:4975#include "chrome/browser/ui/browser_commands_chromeos.h"
[email protected]d12cc5e2013-10-19 18:25:0676#endif
77
[email protected]d5bedb6d2014-04-08 10:49:3278#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
karandeepbe6200332016-06-21 12:26:1079#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3480#endif
81
Bettina Deaf3dac202017-09-16 20:53:2282#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:1483#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker.h"
84#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker_factory.h"
Catherine Chungbeb884222017-08-01 15:47:5585#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker.h"
86#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker_factory.h"
87#endif
88
[email protected]5d98294912012-06-27 22:57:4089using content::NavigationEntry;
90using content::NavigationController;
91using content::WebContents;
92
[email protected]5d98294912012-06-27 22:57:4093namespace chrome {
94
95///////////////////////////////////////////////////////////////////////////////
96// BrowserCommandController, public:
97
[email protected]338416c02014-05-13 16:47:0698BrowserCommandController::BrowserCommandController(Browser* browser)
[email protected]5d98294912012-06-27 22:57:4099 : browser_(browser),
Zijie Hedd69ee7d2017-08-21 21:12:52100 command_updater_(this) {
[email protected]5d98294912012-06-27 22:57:40101 browser_->tab_strip_model()->AddObserver(this);
102 PrefService* local_state = g_browser_process->local_state();
103 if (local_state) {
104 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30105 local_pref_registrar_.Add(
106 prefs::kAllowFileSelectionDialogs,
107 base::Bind(
108 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
109 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40110 }
111
112 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30113 profile_pref_registrar_.Add(
114 prefs::kDevToolsDisabled,
115 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
116 base::Unretained(this)));
117 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32118 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30119 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
120 base::Unretained(this)));
121 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32122 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30123 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
124 base::Unretained(this)));
125 profile_pref_registrar_.Add(
126 prefs::kIncognitoModeAvailability,
127 base::Bind(
128 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
129 base::Unretained(this)));
130 profile_pref_registrar_.Add(
131 prefs::kPrintingEnabled,
132 base::Bind(&BrowserCommandController::UpdatePrintingState,
133 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25134#if !defined(OS_MACOSX)
135 profile_pref_registrar_.Add(
136 prefs::kFullscreenAllowed,
137 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
138 base::Unretained(this)));
139#endif
estade8c0780f2015-08-21 23:36:41140 pref_signin_allowed_.Init(
141 prefs::kSigninAllowed,
142 profile()->GetOriginalProfile()->GetPrefs(),
143 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
144 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40145
146 InitCommandState();
147
blundell74001adc2015-09-18 11:04:25148 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40149 TabRestoreServiceFactory::GetForProfile(profile());
150 if (tab_restore_service) {
151 tab_restore_service->AddObserver(this);
152 TabRestoreServiceChanged(tab_restore_service);
153 }
[email protected]5d98294912012-06-27 22:57:40154}
155
156BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36157 // TabRestoreService may have been shutdown by the time we get here. Don't
158 // trigger creating it.
blundell74001adc2015-09-18 11:04:25159 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36160 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40161 if (tab_restore_service)
162 tab_restore_service->RemoveObserver(this);
163 profile_pref_registrar_.RemoveAll();
164 local_pref_registrar_.RemoveAll();
165 browser_->tab_strip_model()->RemoveObserver(this);
[email protected]5d98294912012-06-27 22:57:40166}
167
168bool BrowserCommandController::IsReservedCommandOrKey(
169 int command_id,
170 const content::NativeWebKeyboardEvent& event) {
171 // In Apps mode, no keys are reserved.
172 if (browser_->is_app())
173 return false;
174
175#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19176 // On Chrome OS, the top row of keys are mapped to browser actions like
177 // back/forward or refresh. We don't want web pages to be able to change the
178 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
179 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40180 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54181 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19182 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
183 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
184 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40185 return true;
186 }
187#endif
188
zijiehe68cd3dc22017-04-07 18:50:29189 if (window()->IsFullscreen()) {
190 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
191 // be delivered to the web page. The intent to implement and ship can be
192 // found in http://crbug.com/680809.
193 const bool is_exit_fullscreen =
194 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
195#if defined(OS_MACOSX)
196 // This behavior is different on Mac OS, which has a unique user-initiated
197 // full-screen mode. According to the discussion in http://crbug.com/702251,
198 // the commands should be reserved for browser-side handling if the browser
199 // window's toolbar is visible.
200 if (window()->IsToolbarShowing()) {
201 if (command_id == IDC_FULLSCREEN)
202 return true;
203 } else {
204 return is_exit_fullscreen;
205 }
206#else
207 return is_exit_fullscreen;
208#endif
209 }
[email protected]1e2172f2014-04-01 17:32:34210
[email protected]893124a22014-04-15 00:45:28211#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34212 // If this key was registered by the user as a content editing hotkey, then
213 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32214 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34215 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42216 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34217 return false;
218#endif
219
zijiehe13207802017-02-16 08:06:10220 return command_id == IDC_CLOSE_TAB ||
221 command_id == IDC_CLOSE_WINDOW ||
222 command_id == IDC_NEW_INCOGNITO_WINDOW ||
223 command_id == IDC_NEW_TAB ||
224 command_id == IDC_NEW_WINDOW ||
225 command_id == IDC_RESTORE_TAB ||
226 command_id == IDC_SELECT_NEXT_TAB ||
227 command_id == IDC_SELECT_PREVIOUS_TAB ||
228 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40229}
230
[email protected]5d98294912012-06-27 22:57:40231void BrowserCommandController::TabStateChanged() {
232 UpdateCommandsForTabState();
233}
234
[email protected]d93dbd12014-08-04 23:42:53235void BrowserCommandController::ZoomStateChanged() {
236 UpdateCommandsForZoomState();
237}
238
[email protected]5d98294912012-06-27 22:57:40239void BrowserCommandController::ContentRestrictionsChanged() {
240 UpdateCommandsForContentRestrictionState();
241}
242
243void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25244 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40245}
246
247void BrowserCommandController::PrintingStateChanged() {
248 UpdatePrintingState();
249}
250
251void BrowserCommandController::LoadingStateChanged(bool is_loading,
252 bool force) {
253 UpdateReloadStopState(is_loading, force);
254}
255
wittman76df71db32014-12-18 23:26:58256void BrowserCommandController::ExtensionStateChanged() {
257 // Extensions may disable the bookmark editing commands.
258 UpdateCommandsForBookmarkEditing();
259}
260
[email protected]5d98294912012-06-27 22:57:40261////////////////////////////////////////////////////////////////////////////////
[email protected]de0d0f42012-12-06 21:27:11262// BrowserCommandController, CommandUpdaterDelegate implementation:
[email protected]5d98294912012-06-27 22:57:40263
264void BrowserCommandController::ExecuteCommandWithDisposition(
[email protected]de0d0f42012-12-06 21:27:11265 int id,
266 WindowOpenDisposition disposition) {
[email protected]5d98294912012-06-27 22:57:40267 // No commands are enabled if there is not yet any selected tab.
268 // TODO(pkasting): It seems like we should not need this, because either
269 // most/all commands should not have been enabled yet anyway or the ones that
270 // are enabled should be global, or safe themselves against having no selected
271 // tab. However, Ben says he tried removing this before and got lots of
272 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
273 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26274 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
[email protected]5d98294912012-06-27 22:57:40275 return;
276
277 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
278 << id;
279
[email protected]5d98294912012-06-27 22:57:40280 // The order of commands in this switch statement must match the function
281 // declaration order in browser.h!
282 switch (id) {
283 // Navigation commands
ojanc7e48992016-05-20 19:50:18284 case IDC_BACKSPACE_BACK:
ojan0fe15052017-05-30 20:01:04285 window()->MaybeShowNewBackShortcutBubble(false);
pkasting36aa72942016-06-10 05:49:08286 break;
[email protected]5d98294912012-06-27 22:57:40287 case IDC_BACK:
zijiehe4dde8072017-02-13 20:38:35288 window()->HideNewBackShortcutBubble();
[email protected]5d98294912012-06-27 22:57:40289 GoBack(browser_, disposition);
290 break;
ojanc7e48992016-05-20 19:50:18291 case IDC_BACKSPACE_FORWARD:
ojan0fe15052017-05-30 20:01:04292 window()->MaybeShowNewBackShortcutBubble(true);
pkasting36aa72942016-06-10 05:49:08293 break;
[email protected]5d98294912012-06-27 22:57:40294 case IDC_FORWARD:
zijiehe4dde8072017-02-13 20:38:35295 window()->HideNewBackShortcutBubble();
[email protected]5d98294912012-06-27 22:57:40296 GoForward(browser_, disposition);
297 break;
298 case IDC_RELOAD:
299 Reload(browser_, disposition);
300 break;
[email protected]58e29032012-08-06 20:19:57301 case IDC_RELOAD_CLEARING_CACHE:
302 ClearCache(browser_);
303 // FALL THROUGH
toyoshim7dad4b1182016-04-01 14:28:05304 case IDC_RELOAD_BYPASSING_CACHE:
305 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40306 break;
307 case IDC_HOME:
308 Home(browser_, disposition);
309 break;
310 case IDC_OPEN_CURRENT_URL:
311 OpenCurrentURL(browser_);
312 break;
313 case IDC_STOP:
314 Stop(browser_);
315 break;
316
317 // Window management commands
318 case IDC_NEW_WINDOW:
319 NewWindow(browser_);
320 break;
321 case IDC_NEW_INCOGNITO_WINDOW:
322 NewIncognitoWindow(browser_);
323 break;
324 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37325 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09326 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40327 break;
Bettina Dea0a4505922017-09-28 00:53:32328 case IDC_NEW_TAB: {
329 NewTab(browser_);
330#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55331 // This is not in NewTab() to avoid tracking programmatic creation of new
332 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32333 auto* new_tab_tracker =
334 feature_engagement::NewTabTrackerFactory::GetInstance()
335 ->GetForProfile(profile());
336
337 new_tab_tracker->OnNewTabOpened();
338 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55339#endif
[email protected]5d98294912012-06-27 22:57:40340 break;
Bettina Dea0a4505922017-09-28 00:53:32341 }
[email protected]5d98294912012-06-27 22:57:40342 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37343 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09344 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40345 break;
346 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37347 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
[email protected]5d98294912012-06-27 22:57:40348 SelectNextTab(browser_);
349 break;
350 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37351 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
[email protected]5d98294912012-06-27 22:57:40352 SelectPreviousTab(browser_);
353 break;
[email protected]5d98294912012-06-27 22:57:40354 case IDC_MOVE_TAB_NEXT:
355 MoveTabNext(browser_);
356 break;
357 case IDC_MOVE_TAB_PREVIOUS:
358 MoveTabPrevious(browser_);
359 break;
360 case IDC_SELECT_TAB_0:
361 case IDC_SELECT_TAB_1:
362 case IDC_SELECT_TAB_2:
363 case IDC_SELECT_TAB_3:
364 case IDC_SELECT_TAB_4:
365 case IDC_SELECT_TAB_5:
366 case IDC_SELECT_TAB_6:
367 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37368 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40369 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
370 break;
371 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37372 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40373 SelectLastTab(browser_);
374 break;
375 case IDC_DUPLICATE_TAB:
376 DuplicateTab(browser_);
377 break;
378 case IDC_RESTORE_TAB:
379 RestoreTab(browser_);
380 break;
[email protected]5d98294912012-06-27 22:57:40381 case IDC_SHOW_AS_TAB:
382 ConvertPopupToTabbedBrowser(browser_);
383 break;
384 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28385 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40386 break;
[email protected]770c6d82012-09-06 22:21:32387
[email protected]d12cc5e2013-10-19 18:25:06388#if defined(OS_CHROMEOS)
389 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47390 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35391 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47392 break;
[email protected]d12cc5e2013-10-19 18:25:06393#endif
394
[email protected]893124a22014-04-15 00:45:28395#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]af97be4c62014-02-13 14:43:34396 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35397 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34398 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
399 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
400 break;
401 }
402#endif
403
[email protected]5d98294912012-06-27 22:57:40404#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21405 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
406 chrome::ToggleFullscreenToolbar(browser_);
407 break;
spqchan2c5d541e2017-10-25 07:07:11408 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
409 PrefService* prefs = profile()->GetPrefs();
410 prefs->SetBoolean(prefs::kAllowJavascriptAppleEvents,
411 !prefs->GetBoolean(prefs::kAllowJavascriptAppleEvents));
412 break;
413 }
[email protected]5d98294912012-06-27 22:57:40414#endif
415 case IDC_EXIT:
416 Exit();
417 break;
418
419 // Page-related commands
420 case IDC_SAVE_PAGE:
421 SavePage(browser_);
422 break;
423 case IDC_BOOKMARK_PAGE:
Bettina Dea48125dc2017-09-06 03:23:14424#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
425 feature_engagement::BookmarkTrackerFactory::GetInstance()
426 ->GetForProfile(profile())
427 ->OnBookmarkAdded();
428#endif
deepak.m154a7f392014-12-15 04:41:43429 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40430 break;
[email protected]5d98294912012-06-27 22:57:40431 case IDC_BOOKMARK_ALL_TABS:
Bettina Dea48125dc2017-09-06 03:23:14432#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
433 feature_engagement::BookmarkTrackerFactory::GetInstance()
434 ->GetForProfile(profile())
435 ->OnBookmarkAdded();
436#endif
[email protected]5d98294912012-06-27 22:57:40437 BookmarkAllTabs(browser_);
438 break;
439 case IDC_VIEW_SOURCE:
440 ViewSelectedSource(browser_);
441 break;
442 case IDC_EMAIL_PAGE_LOCATION:
443 EmailPageLocation(browser_);
444 break;
445 case IDC_PRINT:
446 Print(browser_);
447 break;
bondd052b5f82015-10-28 22:39:32448
Brett Wilson65f951c2016-11-03 22:06:12449#if BUILDFLAG(ENABLE_BASIC_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55450 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37451 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55452 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40453 break;
vitalybukae29991c2014-11-05 21:15:12454#endif // ENABLE_BASIC_PRINTING
bondd052b5f82015-10-28 22:39:32455
bondd052b5f82015-10-28 22:39:32456 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
457 SaveCreditCard(browser_);
458 break;
[email protected]e625b7602013-10-28 09:24:56459 case IDC_TRANSLATE_PAGE:
460 Translate(browser_);
461 break;
[email protected]4bee4432014-05-05 13:11:41462 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
463 ManagePasswordsForPage(browser_);
464 break;
465
[email protected]5d98294912012-06-27 22:57:40466 // Clipboard commands
467 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40468 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40469 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12470 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40471 break;
472
473 // Find-in-page
474 case IDC_FIND:
475 Find(browser_);
476 break;
477 case IDC_FIND_NEXT:
478 FindNext(browser_);
479 break;
480 case IDC_FIND_PREVIOUS:
481 FindPrevious(browser_);
482 break;
483
484 // Zoom
485 case IDC_ZOOM_PLUS:
486 Zoom(browser_, content::PAGE_ZOOM_IN);
487 break;
488 case IDC_ZOOM_NORMAL:
489 Zoom(browser_, content::PAGE_ZOOM_RESET);
490 break;
491 case IDC_ZOOM_MINUS:
492 Zoom(browser_, content::PAGE_ZOOM_OUT);
493 break;
494
495 // Focus various bits of UI
496 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37497 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40498 FocusToolbar(browser_);
499 break;
500 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37501 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40502 FocusLocationBar(browser_);
503 break;
504 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37505 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40506 FocusSearch(browser_);
507 break;
508 case IDC_FOCUS_MENU_BAR:
509 FocusAppMenu(browser_);
510 break;
511 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37512 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40513 FocusBookmarksToolbar(browser_);
514 break;
[email protected]822ca8c62013-04-19 00:49:15515 case IDC_FOCUS_INFOBARS:
516 FocusInfobars(browser_);
517 break;
[email protected]5d98294912012-06-27 22:57:40518 case IDC_FOCUS_NEXT_PANE:
519 FocusNextPane(browser_);
520 break;
521 case IDC_FOCUS_PREVIOUS_PANE:
522 FocusPreviousPane(browser_);
523 break;
524
525 // Show various bits of UI
526 case IDC_OPEN_FILE:
527 browser_->OpenFile();
528 break;
[email protected]488e3952013-11-18 05:29:14529 case IDC_CREATE_HOSTED_APP:
[email protected]92086542014-04-08 08:45:29530 CreateBookmarkAppFromCurrentWebContents(browser_);
[email protected]488e3952013-11-18 05:29:14531 break;
[email protected]5d98294912012-06-27 22:57:40532 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01533 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40534 break;
535 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52536 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40537 break;
[email protected]2056c3192013-10-21 22:40:51538 case IDC_DEV_TOOLS_DEVICES:
539 InspectUI::InspectDevices(browser_);
540 break;
[email protected]5d98294912012-06-27 22:57:40541 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01542 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40543 break;
[email protected]d16657c2012-09-03 14:25:10544 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01545 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10546 break;
[email protected]5d98294912012-06-27 22:57:40547 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38548 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40549 break;
caelyn4e4e08a2015-02-04 21:27:49550#if defined(OS_CHROMEOS)
551 case IDC_TAKE_SCREENSHOT:
552 TakeScreenshot();
553 break;
554#endif
[email protected]236ad3022013-09-04 03:27:43555#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40556 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04557 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40558 break;
[email protected]236ad3022013-09-04 03:27:43559#endif
[email protected]5d98294912012-06-27 22:57:40560 case IDC_SHOW_BOOKMARK_BAR:
561 ToggleBookmarkBar(browser_);
562 break;
563 case IDC_PROFILING_ENABLED:
564 Profiling::Toggle();
565 break;
566
567 case IDC_SHOW_BOOKMARK_MANAGER:
568 ShowBookmarkManager(browser_);
569 break;
570 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37571 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40572 ShowAppMenu(browser_);
573 break;
574 case IDC_SHOW_AVATAR_MENU:
575 ShowAvatarMenu(browser_);
576 break;
[email protected]5d98294912012-06-27 22:57:40577 case IDC_SHOW_HISTORY:
578 ShowHistory(browser_);
579 break;
580 case IDC_SHOW_DOWNLOADS:
581 ShowDownloads(browser_);
582 break;
583 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08584 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40585 break;
586 case IDC_OPTIONS:
587 ShowSettings(browser_);
588 break;
589 case IDC_EDIT_SEARCH_ENGINES:
590 ShowSearchEngineSettings(browser_);
591 break;
592 case IDC_VIEW_PASSWORDS:
593 ShowPasswordManager(browser_);
594 break;
595 case IDC_CLEAR_BROWSING_DATA:
596 ShowClearBrowsingDataDialog(browser_);
597 break;
598 case IDC_IMPORT_SETTINGS:
599 ShowImportDialog(browser_);
600 break;
[email protected]9b7ab882012-09-10 23:46:36601 case IDC_TOGGLE_REQUEST_TABLET_SITE:
602 ToggleRequestTabletSite(browser_);
603 break;
[email protected]5d98294912012-06-27 22:57:40604 case IDC_ABOUT:
605 ShowAboutChrome(browser_);
606 break;
607 case IDC_UPGRADE_DIALOG:
608 OpenUpdateChromeDialog(browser_);
609 break;
610 case IDC_VIEW_INCOMPATIBILITIES:
611 ShowConflicts(browser_);
612 break;
613 case IDC_HELP_PAGE_VIA_KEYBOARD:
614 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
615 break;
616 case IDC_HELP_PAGE_VIA_MENU:
617 ShowHelp(browser_, HELP_SOURCE_MENU);
618 break;
Bret Sepulveda2d018662017-05-18 21:31:48619 case IDC_SHOW_BETA_FORUM:
620 ShowBetaForum(browser_);
621 break;
estade8c0780f2015-08-21 23:36:41622 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37623 ShowBrowserSigninOrSettings(
624 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41625 break;
[email protected]6bd370b2014-05-28 14:19:47626 case IDC_DISTILL_PAGE:
627 DistillCurrentPage(browser_);
628 break;
kpschoedelf8e9274e2014-10-07 18:32:41629#if defined(OS_CHROMEOS)
630 case IDC_TOUCH_HUD_PROJECTION_TOGGLE:
fwang052ae582017-03-01 06:29:36631 if (ash_util::IsRunningInMash()) {
rockot400ea35b2016-10-15 19:15:32632 service_manager::Connector* connector =
bend32292b2016-10-07 00:21:58633 content::ServiceManagerConnection::GetForProcess()->GetConnector();
riajiangc4a5b6b2016-09-02 23:47:11634 mash::mojom::LaunchablePtr launchable;
benbd3c2482017-01-07 05:48:21635 connector->BindInterface("touch_hud", &launchable);
riajiangc4a5b6b2016-09-02 23:47:11636 launchable->Launch(mash::mojom::kWindow,
637 mash::mojom::LaunchMode::DEFAULT);
638 } else {
639 ash::accelerators::ToggleTouchHudProjection();
640 }
kpschoedelf8e9274e2014-10-07 18:32:41641 break;
642#endif
apacible45cbfc92015-09-28 22:45:41643 case IDC_ROUTE_MEDIA:
644 RouteMedia(browser_);
645 break;
ellyjones0101ba02017-05-19 15:50:26646 case IDC_WINDOW_MUTE_TAB:
647 MuteTab(browser_);
648 break;
649 case IDC_WINDOW_PIN_TAB:
650 PinTab(browser_);
651 break;
[email protected]5d98294912012-06-27 22:57:40652
653 default:
654 LOG(WARNING) << "Received Unimplemented Command: " << id;
655 break;
656 }
657}
658
estade8c0780f2015-08-21 23:36:41659////////////////////////////////////////////////////////////////////////////////
660// BrowserCommandController, SigninPrefObserver implementation:
661
662void BrowserCommandController::OnSigninAllowedPrefChange() {
663 // For unit tests, we don't have a window.
664 if (!window())
665 return;
666 UpdateShowSyncState(IsShowingMainUI());
667}
668
[email protected]5d98294912012-06-27 22:57:40669// BrowserCommandController, TabStripModelObserver implementation:
670
pmonette9119e492016-09-20 22:14:55671void BrowserCommandController::TabInsertedAt(TabStripModel* tab_strip_model,
672 WebContents* contents,
[email protected]5d98294912012-06-27 22:57:40673 int index,
674 bool foreground) {
675 AddInterstitialObservers(contents);
676}
677
[email protected]e89cfcb2012-11-11 14:47:24678void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
[email protected]5d98294912012-06-27 22:57:40679 RemoveInterstitialObservers(contents);
680}
681
682void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13683 WebContents* old_contents,
684 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40685 int index) {
[email protected]b624ddc2012-11-15 18:04:13686 RemoveInterstitialObservers(old_contents);
687 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40688}
689
[email protected]3cac87232012-11-20 01:48:27690void BrowserCommandController::TabBlockedStateChanged(
691 content::WebContents* contents,
692 int index) {
693 PrintingStateChanged();
694 FullscreenStateChanged();
695 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41696 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27697}
698
[email protected]5d98294912012-06-27 22:57:40699////////////////////////////////////////////////////////////////////////////////
700// BrowserCommandController, TabRestoreServiceObserver implementation:
701
702void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25703 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53704 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40705}
706
707void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25708 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40709 service->RemoveObserver(this);
710}
711
[email protected]2e9369e2014-08-15 09:12:53712void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25713 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53714 UpdateTabRestoreCommandState();
715}
716
[email protected]5d98294912012-06-27 22:57:40717////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40718// BrowserCommandController, private:
719
[email protected]20ca0382013-02-28 19:50:07720class BrowserCommandController::InterstitialObserver
721 : public content::WebContentsObserver {
722 public:
723 InterstitialObserver(BrowserCommandController* controller,
724 content::WebContents* web_contents)
725 : WebContentsObserver(web_contents),
726 controller_(controller) {
727 }
728
dcheng5dd5ff62014-10-21 12:42:38729 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07730 controller_->UpdateCommandsForTabState();
731 }
732
dcheng5dd5ff62014-10-21 12:42:38733 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07734 controller_->UpdateCommandsForTabState();
735 }
736
737 private:
738 BrowserCommandController* controller_;
739
740 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
741};
742
[email protected]6a414ff2013-02-27 08:22:54743bool BrowserCommandController::IsShowingMainUI() {
744 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
745 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40746}
747
748void BrowserCommandController::InitCommandState() {
749 // All browser commands whose state isn't set automagically some other way
750 // (like Back & Forward with initial page load) must have their state
751 // initialized here, otherwise they will be forever disabled.
752
753 // Navigation commands
754 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05755 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57756 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40757
758 // Window management commands
759 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
760 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
761 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
762 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53763 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55764 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40765 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06766#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58767 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06768 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
769 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
770#endif
[email protected]893124a22014-04-15 00:45:28771#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]af97be4c62014-02-13 14:43:34772 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true);
773#endif
[email protected]5d98294912012-06-27 22:57:40774
775 // Page-related commands
776 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41777 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40778
779 // Zoom
780 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
781 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53782 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40783 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
784
785 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15786 const bool guest_session = profile()->IsGuestSession() ||
787 profile()->IsSystemProfile();
788 DCHECK(!profile()->IsSystemProfile())
789 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06790 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08791 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40792 UpdateCommandsForDevTools();
793 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06794 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40795 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56796 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40797 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
798 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48799 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06800 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51801 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06802 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51803 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33804 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
805 !guest_session);
[email protected]39d47592014-01-10 21:42:45806#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49807 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
kpschoedelf8e9274e2014-10-07 18:32:41808 command_updater_.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE, true);
[email protected]338416c02014-05-13 16:47:06809#else
810 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19811 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06812 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19813 }
[email protected]39d47592014-01-10 21:42:45814#endif
[email protected]5d98294912012-06-27 22:57:40815
estade8c0780f2015-08-21 23:36:41816 UpdateShowSyncState(true);
817
[email protected]5d98294912012-06-27 22:57:40818 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24819 command_updater_.UpdateCommandEnabled(
820 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06821 normal_window ||
822 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40823
824 // Window management commands
[email protected]5d98294912012-06-27 22:57:40825 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
826 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
827 normal_window);
828 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
829 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
830 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
831 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
832 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
833 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
834 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
835 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
836 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
837 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
838 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40839
[email protected]338416c02014-05-13 16:47:06840 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40841 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
842 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
843
[email protected]6bd370b2014-05-28 14:19:47844 // Distill current page.
845 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43846 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
847 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47848
ellyjones0101ba02017-05-19 15:50:26849 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_TAB, normal_window);
850 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
851
[email protected]338416c02014-05-13 16:47:06852 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25853 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40854 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40855 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40856 UpdateCommandsForIncognitoAvailability();
857}
858
[email protected]05454532013-01-22 21:09:08859// static
860void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
861 CommandUpdater* command_updater,
862 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47863 const bool guest_session = profile->IsGuestSession();
864 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40865 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08866 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
867 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40868 IDC_NEW_WINDOW,
869 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08870 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40871 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47872 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40873
[email protected]57b25292014-05-01 16:31:06874 const bool forced_incognito =
875 incognito_availability == IncognitoModePrefs::FORCED ||
876 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08877 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40878 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06879 browser_defaults::bookmarks_enabled && !forced_incognito);
[email protected]03d25812014-06-22 19:41:55880 ExtensionService* extension_service =
881 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06882 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40883 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40884
[email protected]57b25292014-05-01 16:31:06885 // Bookmark manager and settings page/subpages are forced to open in normal
886 // mode. For this reason we disable these commands when incognito is forced.
887 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
888 enable_extensions && !forced_incognito);
889
890 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
891 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
892 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:41893 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:08894}
895
896void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
897 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
898
[email protected]6a414ff2013-02-27 08:22:54899 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:08900 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
901 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
902 }
[email protected]5d98294912012-06-27 22:57:40903}
904
905void BrowserCommandController::UpdateCommandsForTabState() {
[email protected]617ee962013-01-29 20:49:12906 WebContents* current_web_contents =
907 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:57908 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:40909 return;
[email protected]5d98294912012-06-27 22:57:40910
911 // Navigation commands
ojanc7e48992016-05-20 19:50:18912 command_updater_.UpdateCommandEnabled(IDC_BACKSPACE_BACK,
913 CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:40914 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
ojanc7e48992016-05-20 19:50:18915 command_updater_.UpdateCommandEnabled(IDC_BACKSPACE_FORWARD,
916 CanGoForward(browser_));
[email protected]5d98294912012-06-27 22:57:40917 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
918 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:05919 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:40920 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:57921 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
922 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:40923
924 // Window management commands
925 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
926 !browser_->is_app() && CanDuplicateTab(browser_));
ellyjones0101ba02017-05-19 15:50:26927 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_TAB,
928 !browser_->is_app());
929 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
930 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:40931
932 // Page-related commands
933 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:57934 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:16935 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:40936 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
937 CanViewSource(browser_));
938 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
939 CanEmailPageLocation(browser_));
940 if (browser_->is_devtools())
941 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
942
[email protected]92086542014-04-08 08:45:29943 command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP,
944 CanCreateBookmarkApp(browser_));
[email protected]5d98294912012-06-27 22:57:40945
[email protected]9b7ab882012-09-10 23:46:36946 command_updater_.UpdateCommandEnabled(
947 IDC_TOGGLE_REQUEST_TABLET_SITE,
948 CanRequestTabletSite(current_web_contents));
949
[email protected]5d98294912012-06-27 22:57:40950 UpdateCommandsForContentRestrictionState();
951 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:27952 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41953 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:53954 // Update the zoom commands when an active tab is selected.
955 UpdateCommandsForZoomState();
956}
957
958void BrowserCommandController::UpdateCommandsForZoomState() {
959 WebContents* contents =
960 browser_->tab_strip_model()->GetActiveWebContents();
961 if (!contents)
962 return;
a.sarkar.arundaadc712015-02-26 05:39:08963 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
964 CanZoomIn(contents));
965 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:24966 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:08967 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
968 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:40969}
970
971void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
972 int restrictions = GetContentRestrictions(browser_);
973
974 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:01975 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:40976 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:01977 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:40978 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:01979 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:40980 UpdateSaveAsState();
981 UpdatePrintingState();
982}
983
984void BrowserCommandController::UpdateCommandsForDevTools() {
985 bool dev_tools_enabled =
986 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
987 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
988 dev_tools_enabled);
989 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
990 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:51991 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
992 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:40993 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
994 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:10995 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
996 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:11997#if defined(OS_MACOSX)
998 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
999 dev_tools_enabled);
1000#endif
[email protected]5d98294912012-06-27 22:57:401001}
1002
1003void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
1004 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1005 CanBookmarkCurrentPage(browser_));
1006 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1007 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291008#if defined(OS_WIN)
1009 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1010#endif
[email protected]5d98294912012-06-27 22:57:401011}
1012
1013void BrowserCommandController::UpdateCommandsForBookmarkBar() {
tfarina3bddbe112014-08-28 05:29:321014 command_updater_.UpdateCommandEnabled(
1015 IDC_SHOW_BOOKMARK_BAR,
1016 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151017 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321018 !profile()->GetPrefs()->IsManagedPreference(
1019 bookmarks::prefs::kShowBookmarkBar) &&
1020 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401021}
1022
[email protected]9ec3ea5b2012-12-03 18:14:301023void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1024 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081025 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301026}
1027
[email protected]32dfede2013-08-25 15:48:251028void BrowserCommandController::UpdateCommandsForFullscreenMode() {
zijiehe3c7af992017-02-12 20:59:401029 const bool is_fullscreen = window() && window()->IsFullscreen();
1030 const bool show_main_ui = IsShowingMainUI();
1031 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401032
1033 // Navigation commands
1034 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1035
1036 // Window management commands
1037 command_updater_.UpdateCommandEnabled(
1038 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401039 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401040
1041 // Focus various bits of UI
1042 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1043 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1044 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1045 command_updater_.UpdateCommandEnabled(
1046 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1047 command_updater_.UpdateCommandEnabled(
1048 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1049 command_updater_.UpdateCommandEnabled(
1050 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1051 command_updater_.UpdateCommandEnabled(
1052 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151053 command_updater_.UpdateCommandEnabled(
1054 IDC_FOCUS_INFOBARS, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401055
1056 // Show various bits of UI
1057 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431058#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401059 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431060#endif
estade8c0780f2015-08-21 23:36:411061 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401062
[email protected]5d98294912012-06-27 22:57:401063 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1064 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1065 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1066 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151067
1068 if (base::debug::IsProfilingSupported())
1069 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401070
[email protected]aeafc3852014-04-29 16:51:291071#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401072 // Disable toggling into fullscreen mode if disallowed by pref.
1073 const bool fullscreen_enabled = is_fullscreen ||
1074 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1075#else
1076 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511077#endif
1078
1079 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211080 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1081 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401082
1083 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411084 UpdateCommandsForIncognitoAvailability();
[email protected]5d98294912012-06-27 22:57:401085}
1086
1087void BrowserCommandController::UpdatePrintingState() {
[email protected]d53e4032012-06-29 18:58:341088 bool print_enabled = CanPrint(browser_);
1089 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Brett Wilson65f951c2016-11-03 22:06:121090#if BUILDFLAG(ENABLE_BASIC_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551091 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1092 CanBasicPrint(browser_));
vitalybukae29991c2014-11-05 21:15:121093#endif // ENABLE_BASIC_PRINTING
[email protected]5d98294912012-06-27 22:57:401094}
1095
1096void BrowserCommandController::UpdateSaveAsState() {
1097 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1098}
1099
estade8c0780f2015-08-21 23:36:411100void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1101 command_updater_.UpdateCommandEnabled(
1102 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
1103}
1104
[email protected]05454532013-01-22 21:09:081105// static
1106void BrowserCommandController::UpdateOpenFileState(
1107 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401108 bool enabled = true;
1109 PrefService* local_state = g_browser_process->local_state();
1110 if (local_state)
1111 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1112
[email protected]05454532013-01-22 21:09:081113 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401114}
1115
1116void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1117 bool force) {
1118 window()->UpdateReloadStopState(is_loading, force);
1119 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1120}
1121
[email protected]2e9369e2014-08-15 09:12:531122void BrowserCommandController::UpdateTabRestoreCommandState() {
blundell74001adc2015-09-18 11:04:251123 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531124 TabRestoreServiceFactory::GetForProfile(profile());
1125 // The command is enabled if the service hasn't loaded yet to trigger loading.
1126 // The command is updated once the load completes.
1127 command_updater_.UpdateCommandEnabled(
1128 IDC_RESTORE_TAB,
1129 tab_restore_service &&
1130 (!tab_restore_service->IsLoaded() ||
1131 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1132}
1133
[email protected]3cac87232012-11-20 01:48:271134void BrowserCommandController::UpdateCommandsForFind() {
1135 TabStripModel* model = browser_->tab_strip_model();
1136 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1137 !browser_->is_devtools();
1138
1139 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1140 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1141 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1142}
1143
apacible45cbfc92015-09-28 22:45:411144void BrowserCommandController::UpdateCommandsForMediaRouter() {
1145 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1146 CanRouteMedia(browser_));
1147}
1148
[email protected]409ea2972012-11-10 19:54:431149void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071150 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401151}
1152
1153void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241154 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071155 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1156 if (interstitial_observers_[i]->web_contents() != contents)
1157 continue;
1158
1159 delete interstitial_observers_[i];
1160 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1161 return;
1162 }
[email protected]5d98294912012-06-27 22:57:401163}
1164
1165BrowserWindow* BrowserCommandController::window() {
1166 return browser_->window();
1167}
1168
1169Profile* BrowserCommandController::profile() {
1170 return browser_->profile();
1171}
1172
[email protected]5d98294912012-06-27 22:57:401173} // namespace chrome