blob: 3372c998965779b5282209e7a536a4d6fd06de82 [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"
David Rogera6c88122017-10-25 13:02:4647#include "components/signin/core/browser/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"
Lukasz Anforowicze1b954d92017-10-30 21:28:0651#include "content/public/browser/render_frame_host.h"
[email protected]5d98294912012-06-27 22:57:4052#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0753#include "content/public/browser/web_contents_observer.h"
bend32292b2016-10-07 00:21:5854#include "content/public/common/service_manager_connection.h"
[email protected]5d98294912012-06-27 22:57:4055#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5556#include "extensions/browser/extension_system.h"
riajiangc4a5b6b2016-09-02 23:47:1157#include "mash/public/interfaces/launchable.mojom.h"
Brett Wilson65f951c2016-11-03 22:06:1258#include "printing/features/features.h"
rockot734fb662016-10-15 16:41:3059#include "services/service_manager/public/cpp/connector.h"
[email protected]7e9acd082013-09-17 23:31:1660#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4061
[email protected]9c4d68332013-01-30 13:34:4162#if defined(OS_MACOSX)
63#include "chrome/browser/ui/browser_commands_mac.h"
64#endif
65
[email protected]5d98294912012-06-27 22:57:4066#if defined(OS_WIN)
[email protected]a43ed002013-02-05 19:47:5467#include "base/win/windows_version.h"
[email protected]2d0f80f2013-11-01 22:47:1868#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4069#endif
70
[email protected]d12cc5e2013-10-19 18:25:0671#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:5872#include "ash/accelerators/accelerator_commands_classic.h" // mash-ok
73#include "chrome/browser/ui/ash/ash_util.h"
[email protected]0c930812014-01-30 18:01:4774#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
[email protected]5226f1e2013-11-09 04:12:1075#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
caelyn4e4e08a2015-02-04 21:27:4976#include "chrome/browser/ui/browser_commands_chromeos.h"
[email protected]d12cc5e2013-10-19 18:25:0677#endif
78
[email protected]d5bedb6d2014-04-08 10:49:3279#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
karandeepbe6200332016-06-21 12:26:1080#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3481#endif
82
Bettina Deaf3dac202017-09-16 20:53:2283#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:1484#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker.h"
85#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker_factory.h"
Catherine Chungbeb884222017-08-01 15:47:5586#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker.h"
87#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker_factory.h"
88#endif
89
[email protected]5d98294912012-06-27 22:57:4090using content::NavigationEntry;
91using content::NavigationController;
92using content::WebContents;
93
[email protected]5d98294912012-06-27 22:57:4094namespace chrome {
95
96///////////////////////////////////////////////////////////////////////////////
97// BrowserCommandController, public:
98
[email protected]338416c02014-05-13 16:47:0699BrowserCommandController::BrowserCommandController(Browser* browser)
[email protected]5d98294912012-06-27 22:57:40100 : browser_(browser),
Zijie Hedd69ee7d2017-08-21 21:12:52101 command_updater_(this) {
[email protected]5d98294912012-06-27 22:57:40102 browser_->tab_strip_model()->AddObserver(this);
103 PrefService* local_state = g_browser_process->local_state();
104 if (local_state) {
105 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30106 local_pref_registrar_.Add(
107 prefs::kAllowFileSelectionDialogs,
108 base::Bind(
109 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
110 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40111 }
112
113 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30114 profile_pref_registrar_.Add(
115 prefs::kDevToolsDisabled,
116 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
117 base::Unretained(this)));
118 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32119 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30120 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
121 base::Unretained(this)));
122 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32123 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30124 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
125 base::Unretained(this)));
126 profile_pref_registrar_.Add(
127 prefs::kIncognitoModeAvailability,
128 base::Bind(
129 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
130 base::Unretained(this)));
131 profile_pref_registrar_.Add(
132 prefs::kPrintingEnabled,
133 base::Bind(&BrowserCommandController::UpdatePrintingState,
134 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25135#if !defined(OS_MACOSX)
136 profile_pref_registrar_.Add(
137 prefs::kFullscreenAllowed,
138 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
139 base::Unretained(this)));
140#endif
estade8c0780f2015-08-21 23:36:41141 pref_signin_allowed_.Init(
142 prefs::kSigninAllowed,
143 profile()->GetOriginalProfile()->GetPrefs(),
144 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
145 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40146
147 InitCommandState();
148
blundell74001adc2015-09-18 11:04:25149 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40150 TabRestoreServiceFactory::GetForProfile(profile());
151 if (tab_restore_service) {
152 tab_restore_service->AddObserver(this);
153 TabRestoreServiceChanged(tab_restore_service);
154 }
[email protected]5d98294912012-06-27 22:57:40155}
156
157BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36158 // TabRestoreService may have been shutdown by the time we get here. Don't
159 // trigger creating it.
blundell74001adc2015-09-18 11:04:25160 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36161 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40162 if (tab_restore_service)
163 tab_restore_service->RemoveObserver(this);
164 profile_pref_registrar_.RemoveAll();
165 local_pref_registrar_.RemoveAll();
166 browser_->tab_strip_model()->RemoveObserver(this);
[email protected]5d98294912012-06-27 22:57:40167}
168
169bool BrowserCommandController::IsReservedCommandOrKey(
170 int command_id,
171 const content::NativeWebKeyboardEvent& event) {
172 // In Apps mode, no keys are reserved.
173 if (browser_->is_app())
174 return false;
175
176#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19177 // On Chrome OS, the top row of keys are mapped to browser actions like
178 // back/forward or refresh. We don't want web pages to be able to change the
179 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
180 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40181 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54182 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19183 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
184 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
185 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40186 return true;
187 }
188#endif
189
zijiehe68cd3dc22017-04-07 18:50:29190 if (window()->IsFullscreen()) {
191 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
192 // be delivered to the web page. The intent to implement and ship can be
193 // found in http://crbug.com/680809.
194 const bool is_exit_fullscreen =
195 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
196#if defined(OS_MACOSX)
197 // This behavior is different on Mac OS, which has a unique user-initiated
198 // full-screen mode. According to the discussion in http://crbug.com/702251,
199 // the commands should be reserved for browser-side handling if the browser
200 // window's toolbar is visible.
201 if (window()->IsToolbarShowing()) {
202 if (command_id == IDC_FULLSCREEN)
203 return true;
204 } else {
205 return is_exit_fullscreen;
206 }
207#else
208 return is_exit_fullscreen;
209#endif
210 }
[email protected]1e2172f2014-04-01 17:32:34211
[email protected]893124a22014-04-15 00:45:28212#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34213 // If this key was registered by the user as a content editing hotkey, then
214 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32215 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34216 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42217 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34218 return false;
219#endif
220
zijiehe13207802017-02-16 08:06:10221 return command_id == IDC_CLOSE_TAB ||
222 command_id == IDC_CLOSE_WINDOW ||
223 command_id == IDC_NEW_INCOGNITO_WINDOW ||
224 command_id == IDC_NEW_TAB ||
225 command_id == IDC_NEW_WINDOW ||
226 command_id == IDC_RESTORE_TAB ||
227 command_id == IDC_SELECT_NEXT_TAB ||
228 command_id == IDC_SELECT_PREVIOUS_TAB ||
229 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40230}
231
[email protected]5d98294912012-06-27 22:57:40232void BrowserCommandController::TabStateChanged() {
233 UpdateCommandsForTabState();
234}
235
[email protected]d93dbd12014-08-04 23:42:53236void BrowserCommandController::ZoomStateChanged() {
237 UpdateCommandsForZoomState();
238}
239
[email protected]5d98294912012-06-27 22:57:40240void BrowserCommandController::ContentRestrictionsChanged() {
241 UpdateCommandsForContentRestrictionState();
242}
243
244void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25245 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40246}
247
248void BrowserCommandController::PrintingStateChanged() {
249 UpdatePrintingState();
250}
251
252void BrowserCommandController::LoadingStateChanged(bool is_loading,
253 bool force) {
254 UpdateReloadStopState(is_loading, force);
255}
256
wittman76df71db32014-12-18 23:26:58257void BrowserCommandController::ExtensionStateChanged() {
258 // Extensions may disable the bookmark editing commands.
259 UpdateCommandsForBookmarkEditing();
260}
261
[email protected]5d98294912012-06-27 22:57:40262////////////////////////////////////////////////////////////////////////////////
[email protected]de0d0f42012-12-06 21:27:11263// BrowserCommandController, CommandUpdaterDelegate implementation:
[email protected]5d98294912012-06-27 22:57:40264
265void BrowserCommandController::ExecuteCommandWithDisposition(
[email protected]de0d0f42012-12-06 21:27:11266 int id,
267 WindowOpenDisposition disposition) {
[email protected]5d98294912012-06-27 22:57:40268 // No commands are enabled if there is not yet any selected tab.
269 // TODO(pkasting): It seems like we should not need this, because either
270 // most/all commands should not have been enabled yet anyway or the ones that
271 // are enabled should be global, or safe themselves against having no selected
272 // tab. However, Ben says he tried removing this before and got lots of
273 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
274 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26275 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
[email protected]5d98294912012-06-27 22:57:40276 return;
277
278 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
279 << id;
280
[email protected]5d98294912012-06-27 22:57:40281 // The order of commands in this switch statement must match the function
282 // declaration order in browser.h!
283 switch (id) {
284 // Navigation commands
ojanc7e48992016-05-20 19:50:18285 case IDC_BACKSPACE_BACK:
ojan0fe15052017-05-30 20:01:04286 window()->MaybeShowNewBackShortcutBubble(false);
pkasting36aa72942016-06-10 05:49:08287 break;
[email protected]5d98294912012-06-27 22:57:40288 case IDC_BACK:
zijiehe4dde8072017-02-13 20:38:35289 window()->HideNewBackShortcutBubble();
[email protected]5d98294912012-06-27 22:57:40290 GoBack(browser_, disposition);
291 break;
ojanc7e48992016-05-20 19:50:18292 case IDC_BACKSPACE_FORWARD:
ojan0fe15052017-05-30 20:01:04293 window()->MaybeShowNewBackShortcutBubble(true);
pkasting36aa72942016-06-10 05:49:08294 break;
[email protected]5d98294912012-06-27 22:57:40295 case IDC_FORWARD:
zijiehe4dde8072017-02-13 20:38:35296 window()->HideNewBackShortcutBubble();
[email protected]5d98294912012-06-27 22:57:40297 GoForward(browser_, disposition);
298 break;
299 case IDC_RELOAD:
300 Reload(browser_, disposition);
301 break;
[email protected]58e29032012-08-06 20:19:57302 case IDC_RELOAD_CLEARING_CACHE:
303 ClearCache(browser_);
304 // FALL THROUGH
toyoshim7dad4b1182016-04-01 14:28:05305 case IDC_RELOAD_BYPASSING_CACHE:
306 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40307 break;
308 case IDC_HOME:
309 Home(browser_, disposition);
310 break;
311 case IDC_OPEN_CURRENT_URL:
312 OpenCurrentURL(browser_);
313 break;
314 case IDC_STOP:
315 Stop(browser_);
316 break;
317
318 // Window management commands
319 case IDC_NEW_WINDOW:
320 NewWindow(browser_);
321 break;
322 case IDC_NEW_INCOGNITO_WINDOW:
323 NewIncognitoWindow(browser_);
324 break;
325 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37326 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09327 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40328 break;
Bettina Dea0a4505922017-09-28 00:53:32329 case IDC_NEW_TAB: {
330 NewTab(browser_);
331#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55332 // This is not in NewTab() to avoid tracking programmatic creation of new
333 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32334 auto* new_tab_tracker =
335 feature_engagement::NewTabTrackerFactory::GetInstance()
336 ->GetForProfile(profile());
337
338 new_tab_tracker->OnNewTabOpened();
339 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55340#endif
[email protected]5d98294912012-06-27 22:57:40341 break;
Bettina Dea0a4505922017-09-28 00:53:32342 }
[email protected]5d98294912012-06-27 22:57:40343 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37344 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09345 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40346 break;
347 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37348 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
[email protected]5d98294912012-06-27 22:57:40349 SelectNextTab(browser_);
350 break;
351 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37352 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
[email protected]5d98294912012-06-27 22:57:40353 SelectPreviousTab(browser_);
354 break;
[email protected]5d98294912012-06-27 22:57:40355 case IDC_MOVE_TAB_NEXT:
356 MoveTabNext(browser_);
357 break;
358 case IDC_MOVE_TAB_PREVIOUS:
359 MoveTabPrevious(browser_);
360 break;
361 case IDC_SELECT_TAB_0:
362 case IDC_SELECT_TAB_1:
363 case IDC_SELECT_TAB_2:
364 case IDC_SELECT_TAB_3:
365 case IDC_SELECT_TAB_4:
366 case IDC_SELECT_TAB_5:
367 case IDC_SELECT_TAB_6:
368 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37369 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40370 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
371 break;
372 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37373 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40374 SelectLastTab(browser_);
375 break;
376 case IDC_DUPLICATE_TAB:
377 DuplicateTab(browser_);
378 break;
379 case IDC_RESTORE_TAB:
380 RestoreTab(browser_);
381 break;
[email protected]5d98294912012-06-27 22:57:40382 case IDC_SHOW_AS_TAB:
383 ConvertPopupToTabbedBrowser(browser_);
384 break;
385 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28386 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40387 break;
[email protected]770c6d82012-09-06 22:21:32388
[email protected]d12cc5e2013-10-19 18:25:06389#if defined(OS_CHROMEOS)
390 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47391 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35392 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47393 break;
[email protected]d12cc5e2013-10-19 18:25:06394#endif
395
[email protected]893124a22014-04-15 00:45:28396#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]af97be4c62014-02-13 14:43:34397 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35398 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34399 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
400 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
401 break;
402 }
403#endif
404
[email protected]5d98294912012-06-27 22:57:40405#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21406 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
407 chrome::ToggleFullscreenToolbar(browser_);
408 break;
spqchan2c5d541e2017-10-25 07:07:11409 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
410 PrefService* prefs = profile()->GetPrefs();
411 prefs->SetBoolean(prefs::kAllowJavascriptAppleEvents,
412 !prefs->GetBoolean(prefs::kAllowJavascriptAppleEvents));
413 break;
414 }
[email protected]5d98294912012-06-27 22:57:40415#endif
416 case IDC_EXIT:
417 Exit();
418 break;
419
420 // Page-related commands
421 case IDC_SAVE_PAGE:
422 SavePage(browser_);
423 break;
424 case IDC_BOOKMARK_PAGE:
Bettina Dea48125dc2017-09-06 03:23:14425#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
426 feature_engagement::BookmarkTrackerFactory::GetInstance()
427 ->GetForProfile(profile())
428 ->OnBookmarkAdded();
429#endif
deepak.m154a7f392014-12-15 04:41:43430 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40431 break;
[email protected]5d98294912012-06-27 22:57:40432 case IDC_BOOKMARK_ALL_TABS:
Bettina Dea48125dc2017-09-06 03:23:14433#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
434 feature_engagement::BookmarkTrackerFactory::GetInstance()
435 ->GetForProfile(profile())
436 ->OnBookmarkAdded();
437#endif
[email protected]5d98294912012-06-27 22:57:40438 BookmarkAllTabs(browser_);
439 break;
440 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06441 browser_->tab_strip_model()
442 ->GetActiveWebContents()
443 ->GetMainFrame()
444 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40445 break;
446 case IDC_EMAIL_PAGE_LOCATION:
447 EmailPageLocation(browser_);
448 break;
449 case IDC_PRINT:
450 Print(browser_);
451 break;
bondd052b5f82015-10-28 22:39:32452
Brett Wilson65f951c2016-11-03 22:06:12453#if BUILDFLAG(ENABLE_BASIC_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55454 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37455 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55456 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40457 break;
vitalybukae29991c2014-11-05 21:15:12458#endif // ENABLE_BASIC_PRINTING
bondd052b5f82015-10-28 22:39:32459
bondd052b5f82015-10-28 22:39:32460 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
461 SaveCreditCard(browser_);
462 break;
[email protected]e625b7602013-10-28 09:24:56463 case IDC_TRANSLATE_PAGE:
464 Translate(browser_);
465 break;
[email protected]4bee4432014-05-05 13:11:41466 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
467 ManagePasswordsForPage(browser_);
468 break;
469
[email protected]5d98294912012-06-27 22:57:40470 // Clipboard commands
471 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40472 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40473 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12474 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40475 break;
476
477 // Find-in-page
478 case IDC_FIND:
479 Find(browser_);
480 break;
481 case IDC_FIND_NEXT:
482 FindNext(browser_);
483 break;
484 case IDC_FIND_PREVIOUS:
485 FindPrevious(browser_);
486 break;
487
488 // Zoom
489 case IDC_ZOOM_PLUS:
490 Zoom(browser_, content::PAGE_ZOOM_IN);
491 break;
492 case IDC_ZOOM_NORMAL:
493 Zoom(browser_, content::PAGE_ZOOM_RESET);
494 break;
495 case IDC_ZOOM_MINUS:
496 Zoom(browser_, content::PAGE_ZOOM_OUT);
497 break;
498
499 // Focus various bits of UI
500 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37501 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40502 FocusToolbar(browser_);
503 break;
504 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37505 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40506 FocusLocationBar(browser_);
507 break;
508 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37509 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40510 FocusSearch(browser_);
511 break;
512 case IDC_FOCUS_MENU_BAR:
513 FocusAppMenu(browser_);
514 break;
515 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37516 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40517 FocusBookmarksToolbar(browser_);
518 break;
[email protected]822ca8c62013-04-19 00:49:15519 case IDC_FOCUS_INFOBARS:
520 FocusInfobars(browser_);
521 break;
[email protected]5d98294912012-06-27 22:57:40522 case IDC_FOCUS_NEXT_PANE:
523 FocusNextPane(browser_);
524 break;
525 case IDC_FOCUS_PREVIOUS_PANE:
526 FocusPreviousPane(browser_);
527 break;
528
529 // Show various bits of UI
530 case IDC_OPEN_FILE:
531 browser_->OpenFile();
532 break;
[email protected]488e3952013-11-18 05:29:14533 case IDC_CREATE_HOSTED_APP:
[email protected]92086542014-04-08 08:45:29534 CreateBookmarkAppFromCurrentWebContents(browser_);
[email protected]488e3952013-11-18 05:29:14535 break;
[email protected]5d98294912012-06-27 22:57:40536 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01537 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40538 break;
539 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52540 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40541 break;
[email protected]2056c3192013-10-21 22:40:51542 case IDC_DEV_TOOLS_DEVICES:
543 InspectUI::InspectDevices(browser_);
544 break;
[email protected]5d98294912012-06-27 22:57:40545 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01546 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40547 break;
[email protected]d16657c2012-09-03 14:25:10548 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01549 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10550 break;
[email protected]5d98294912012-06-27 22:57:40551 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38552 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40553 break;
caelyn4e4e08a2015-02-04 21:27:49554#if defined(OS_CHROMEOS)
555 case IDC_TAKE_SCREENSHOT:
556 TakeScreenshot();
557 break;
558#endif
[email protected]236ad3022013-09-04 03:27:43559#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40560 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04561 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40562 break;
[email protected]236ad3022013-09-04 03:27:43563#endif
[email protected]5d98294912012-06-27 22:57:40564 case IDC_SHOW_BOOKMARK_BAR:
565 ToggleBookmarkBar(browser_);
566 break;
567 case IDC_PROFILING_ENABLED:
568 Profiling::Toggle();
569 break;
570
571 case IDC_SHOW_BOOKMARK_MANAGER:
572 ShowBookmarkManager(browser_);
573 break;
574 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37575 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40576 ShowAppMenu(browser_);
577 break;
578 case IDC_SHOW_AVATAR_MENU:
579 ShowAvatarMenu(browser_);
580 break;
[email protected]5d98294912012-06-27 22:57:40581 case IDC_SHOW_HISTORY:
582 ShowHistory(browser_);
583 break;
584 case IDC_SHOW_DOWNLOADS:
585 ShowDownloads(browser_);
586 break;
587 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08588 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40589 break;
590 case IDC_OPTIONS:
591 ShowSettings(browser_);
592 break;
593 case IDC_EDIT_SEARCH_ENGINES:
594 ShowSearchEngineSettings(browser_);
595 break;
596 case IDC_VIEW_PASSWORDS:
597 ShowPasswordManager(browser_);
598 break;
599 case IDC_CLEAR_BROWSING_DATA:
600 ShowClearBrowsingDataDialog(browser_);
601 break;
602 case IDC_IMPORT_SETTINGS:
603 ShowImportDialog(browser_);
604 break;
[email protected]9b7ab882012-09-10 23:46:36605 case IDC_TOGGLE_REQUEST_TABLET_SITE:
606 ToggleRequestTabletSite(browser_);
607 break;
[email protected]5d98294912012-06-27 22:57:40608 case IDC_ABOUT:
609 ShowAboutChrome(browser_);
610 break;
611 case IDC_UPGRADE_DIALOG:
612 OpenUpdateChromeDialog(browser_);
613 break;
614 case IDC_VIEW_INCOMPATIBILITIES:
615 ShowConflicts(browser_);
616 break;
617 case IDC_HELP_PAGE_VIA_KEYBOARD:
618 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
619 break;
620 case IDC_HELP_PAGE_VIA_MENU:
621 ShowHelp(browser_, HELP_SOURCE_MENU);
622 break;
Bret Sepulveda2d018662017-05-18 21:31:48623 case IDC_SHOW_BETA_FORUM:
624 ShowBetaForum(browser_);
625 break;
estade8c0780f2015-08-21 23:36:41626 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37627 ShowBrowserSigninOrSettings(
628 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41629 break;
[email protected]6bd370b2014-05-28 14:19:47630 case IDC_DISTILL_PAGE:
631 DistillCurrentPage(browser_);
632 break;
kpschoedelf8e9274e2014-10-07 18:32:41633#if defined(OS_CHROMEOS)
634 case IDC_TOUCH_HUD_PROJECTION_TOGGLE:
fwang052ae582017-03-01 06:29:36635 if (ash_util::IsRunningInMash()) {
rockot400ea35b2016-10-15 19:15:32636 service_manager::Connector* connector =
bend32292b2016-10-07 00:21:58637 content::ServiceManagerConnection::GetForProcess()->GetConnector();
riajiangc4a5b6b2016-09-02 23:47:11638 mash::mojom::LaunchablePtr launchable;
benbd3c2482017-01-07 05:48:21639 connector->BindInterface("touch_hud", &launchable);
riajiangc4a5b6b2016-09-02 23:47:11640 launchable->Launch(mash::mojom::kWindow,
641 mash::mojom::LaunchMode::DEFAULT);
642 } else {
643 ash::accelerators::ToggleTouchHudProjection();
644 }
kpschoedelf8e9274e2014-10-07 18:32:41645 break;
646#endif
apacible45cbfc92015-09-28 22:45:41647 case IDC_ROUTE_MEDIA:
648 RouteMedia(browser_);
649 break;
ellyjones0101ba02017-05-19 15:50:26650 case IDC_WINDOW_MUTE_TAB:
651 MuteTab(browser_);
652 break;
653 case IDC_WINDOW_PIN_TAB:
654 PinTab(browser_);
655 break;
[email protected]5d98294912012-06-27 22:57:40656
657 default:
658 LOG(WARNING) << "Received Unimplemented Command: " << id;
659 break;
660 }
661}
662
estade8c0780f2015-08-21 23:36:41663////////////////////////////////////////////////////////////////////////////////
664// BrowserCommandController, SigninPrefObserver implementation:
665
666void BrowserCommandController::OnSigninAllowedPrefChange() {
667 // For unit tests, we don't have a window.
668 if (!window())
669 return;
670 UpdateShowSyncState(IsShowingMainUI());
671}
672
[email protected]5d98294912012-06-27 22:57:40673// BrowserCommandController, TabStripModelObserver implementation:
674
pmonette9119e492016-09-20 22:14:55675void BrowserCommandController::TabInsertedAt(TabStripModel* tab_strip_model,
676 WebContents* contents,
[email protected]5d98294912012-06-27 22:57:40677 int index,
678 bool foreground) {
679 AddInterstitialObservers(contents);
680}
681
[email protected]e89cfcb2012-11-11 14:47:24682void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
[email protected]5d98294912012-06-27 22:57:40683 RemoveInterstitialObservers(contents);
684}
685
686void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13687 WebContents* old_contents,
688 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40689 int index) {
[email protected]b624ddc2012-11-15 18:04:13690 RemoveInterstitialObservers(old_contents);
691 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40692}
693
[email protected]3cac87232012-11-20 01:48:27694void BrowserCommandController::TabBlockedStateChanged(
695 content::WebContents* contents,
696 int index) {
697 PrintingStateChanged();
698 FullscreenStateChanged();
699 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41700 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27701}
702
[email protected]5d98294912012-06-27 22:57:40703////////////////////////////////////////////////////////////////////////////////
704// BrowserCommandController, TabRestoreServiceObserver implementation:
705
706void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25707 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53708 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40709}
710
711void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25712 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40713 service->RemoveObserver(this);
714}
715
[email protected]2e9369e2014-08-15 09:12:53716void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25717 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53718 UpdateTabRestoreCommandState();
719}
720
[email protected]5d98294912012-06-27 22:57:40721////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40722// BrowserCommandController, private:
723
[email protected]20ca0382013-02-28 19:50:07724class BrowserCommandController::InterstitialObserver
725 : public content::WebContentsObserver {
726 public:
727 InterstitialObserver(BrowserCommandController* controller,
728 content::WebContents* web_contents)
729 : WebContentsObserver(web_contents),
730 controller_(controller) {
731 }
732
dcheng5dd5ff62014-10-21 12:42:38733 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07734 controller_->UpdateCommandsForTabState();
735 }
736
dcheng5dd5ff62014-10-21 12:42:38737 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07738 controller_->UpdateCommandsForTabState();
739 }
740
741 private:
742 BrowserCommandController* controller_;
743
744 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
745};
746
[email protected]6a414ff2013-02-27 08:22:54747bool BrowserCommandController::IsShowingMainUI() {
748 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
749 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40750}
751
752void BrowserCommandController::InitCommandState() {
753 // All browser commands whose state isn't set automagically some other way
754 // (like Back & Forward with initial page load) must have their state
755 // initialized here, otherwise they will be forever disabled.
756
757 // Navigation commands
758 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05759 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57760 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40761
762 // Window management commands
763 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
764 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
765 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
766 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53767 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55768 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40769 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06770#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58771 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06772 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
773 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
774#endif
[email protected]893124a22014-04-15 00:45:28775#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]af97be4c62014-02-13 14:43:34776 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true);
777#endif
[email protected]5d98294912012-06-27 22:57:40778
779 // Page-related commands
780 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41781 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40782
783 // Zoom
784 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
785 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53786 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40787 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
788
789 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15790 const bool guest_session = profile()->IsGuestSession() ||
791 profile()->IsSystemProfile();
792 DCHECK(!profile()->IsSystemProfile())
793 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06794 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08795 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40796 UpdateCommandsForDevTools();
797 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06798 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40799 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56800 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40801 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
802 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48803 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06804 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51805 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06806 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51807 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33808 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
809 !guest_session);
[email protected]39d47592014-01-10 21:42:45810#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49811 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
kpschoedelf8e9274e2014-10-07 18:32:41812 command_updater_.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE, true);
[email protected]338416c02014-05-13 16:47:06813#else
814 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19815 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06816 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19817 }
[email protected]39d47592014-01-10 21:42:45818#endif
[email protected]5d98294912012-06-27 22:57:40819
estade8c0780f2015-08-21 23:36:41820 UpdateShowSyncState(true);
821
[email protected]5d98294912012-06-27 22:57:40822 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24823 command_updater_.UpdateCommandEnabled(
824 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06825 normal_window ||
826 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40827
828 // Window management commands
[email protected]5d98294912012-06-27 22:57:40829 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
830 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
831 normal_window);
832 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
833 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
834 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
835 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
836 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
837 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
838 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
839 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
840 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
841 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
842 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40843
[email protected]338416c02014-05-13 16:47:06844 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40845 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
846 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
847
[email protected]6bd370b2014-05-28 14:19:47848 // Distill current page.
849 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43850 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
851 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47852
ellyjones0101ba02017-05-19 15:50:26853 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_TAB, normal_window);
854 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
855
[email protected]338416c02014-05-13 16:47:06856 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25857 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40858 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40859 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40860 UpdateCommandsForIncognitoAvailability();
861}
862
[email protected]05454532013-01-22 21:09:08863// static
864void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
865 CommandUpdater* command_updater,
866 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47867 const bool guest_session = profile->IsGuestSession();
868 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40869 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08870 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
871 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40872 IDC_NEW_WINDOW,
873 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08874 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40875 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47876 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40877
[email protected]57b25292014-05-01 16:31:06878 const bool forced_incognito =
879 incognito_availability == IncognitoModePrefs::FORCED ||
880 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08881 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40882 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06883 browser_defaults::bookmarks_enabled && !forced_incognito);
[email protected]03d25812014-06-22 19:41:55884 ExtensionService* extension_service =
885 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06886 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40887 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40888
[email protected]57b25292014-05-01 16:31:06889 // Bookmark manager and settings page/subpages are forced to open in normal
890 // mode. For this reason we disable these commands when incognito is forced.
891 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
892 enable_extensions && !forced_incognito);
893
894 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
895 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
896 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:41897 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:08898}
899
900void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
901 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
902
[email protected]6a414ff2013-02-27 08:22:54903 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:08904 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
905 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
906 }
[email protected]5d98294912012-06-27 22:57:40907}
908
909void BrowserCommandController::UpdateCommandsForTabState() {
[email protected]617ee962013-01-29 20:49:12910 WebContents* current_web_contents =
911 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:57912 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:40913 return;
[email protected]5d98294912012-06-27 22:57:40914
915 // Navigation commands
ojanc7e48992016-05-20 19:50:18916 command_updater_.UpdateCommandEnabled(IDC_BACKSPACE_BACK,
917 CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:40918 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
ojanc7e48992016-05-20 19:50:18919 command_updater_.UpdateCommandEnabled(IDC_BACKSPACE_FORWARD,
920 CanGoForward(browser_));
[email protected]5d98294912012-06-27 22:57:40921 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
922 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:05923 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:40924 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:57925 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
926 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:40927
928 // Window management commands
929 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
930 !browser_->is_app() && CanDuplicateTab(browser_));
ellyjones0101ba02017-05-19 15:50:26931 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_TAB,
932 !browser_->is_app());
933 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
934 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:40935
936 // Page-related commands
937 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:57938 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:16939 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:40940 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
941 CanViewSource(browser_));
942 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
943 CanEmailPageLocation(browser_));
944 if (browser_->is_devtools())
945 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
946
[email protected]92086542014-04-08 08:45:29947 command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP,
948 CanCreateBookmarkApp(browser_));
[email protected]5d98294912012-06-27 22:57:40949
[email protected]9b7ab882012-09-10 23:46:36950 command_updater_.UpdateCommandEnabled(
951 IDC_TOGGLE_REQUEST_TABLET_SITE,
952 CanRequestTabletSite(current_web_contents));
953
[email protected]5d98294912012-06-27 22:57:40954 UpdateCommandsForContentRestrictionState();
955 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:27956 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41957 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:53958 // Update the zoom commands when an active tab is selected.
959 UpdateCommandsForZoomState();
960}
961
962void BrowserCommandController::UpdateCommandsForZoomState() {
963 WebContents* contents =
964 browser_->tab_strip_model()->GetActiveWebContents();
965 if (!contents)
966 return;
a.sarkar.arundaadc712015-02-26 05:39:08967 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
968 CanZoomIn(contents));
969 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:24970 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:08971 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
972 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:40973}
974
975void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
976 int restrictions = GetContentRestrictions(browser_);
977
978 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:01979 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:40980 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:01981 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:40982 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:01983 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:40984 UpdateSaveAsState();
985 UpdatePrintingState();
986}
987
988void BrowserCommandController::UpdateCommandsForDevTools() {
989 bool dev_tools_enabled =
990 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
991 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
992 dev_tools_enabled);
993 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
994 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:51995 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
996 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:40997 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
998 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:10999 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1000 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111001#if defined(OS_MACOSX)
1002 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1003 dev_tools_enabled);
1004#endif
[email protected]5d98294912012-06-27 22:57:401005}
1006
1007void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
1008 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1009 CanBookmarkCurrentPage(browser_));
1010 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1011 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291012#if defined(OS_WIN)
1013 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1014#endif
[email protected]5d98294912012-06-27 22:57:401015}
1016
1017void BrowserCommandController::UpdateCommandsForBookmarkBar() {
tfarina3bddbe112014-08-28 05:29:321018 command_updater_.UpdateCommandEnabled(
1019 IDC_SHOW_BOOKMARK_BAR,
1020 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151021 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321022 !profile()->GetPrefs()->IsManagedPreference(
1023 bookmarks::prefs::kShowBookmarkBar) &&
1024 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401025}
1026
[email protected]9ec3ea5b2012-12-03 18:14:301027void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1028 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081029 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301030}
1031
[email protected]32dfede2013-08-25 15:48:251032void BrowserCommandController::UpdateCommandsForFullscreenMode() {
zijiehe3c7af992017-02-12 20:59:401033 const bool is_fullscreen = window() && window()->IsFullscreen();
1034 const bool show_main_ui = IsShowingMainUI();
1035 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401036
1037 // Navigation commands
1038 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1039
1040 // Window management commands
1041 command_updater_.UpdateCommandEnabled(
1042 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401043 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401044
1045 // Focus various bits of UI
1046 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1047 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1048 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1049 command_updater_.UpdateCommandEnabled(
1050 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1051 command_updater_.UpdateCommandEnabled(
1052 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1053 command_updater_.UpdateCommandEnabled(
1054 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1055 command_updater_.UpdateCommandEnabled(
1056 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151057 command_updater_.UpdateCommandEnabled(
1058 IDC_FOCUS_INFOBARS, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401059
1060 // Show various bits of UI
1061 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431062#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401063 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431064#endif
estade8c0780f2015-08-21 23:36:411065 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401066
[email protected]5d98294912012-06-27 22:57:401067 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1068 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1069 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1070 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151071
1072 if (base::debug::IsProfilingSupported())
1073 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401074
[email protected]aeafc3852014-04-29 16:51:291075#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401076 // Disable toggling into fullscreen mode if disallowed by pref.
1077 const bool fullscreen_enabled = is_fullscreen ||
1078 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1079#else
1080 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511081#endif
1082
1083 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211084 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1085 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401086
1087 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411088 UpdateCommandsForIncognitoAvailability();
[email protected]5d98294912012-06-27 22:57:401089}
1090
1091void BrowserCommandController::UpdatePrintingState() {
[email protected]d53e4032012-06-29 18:58:341092 bool print_enabled = CanPrint(browser_);
1093 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Brett Wilson65f951c2016-11-03 22:06:121094#if BUILDFLAG(ENABLE_BASIC_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551095 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1096 CanBasicPrint(browser_));
vitalybukae29991c2014-11-05 21:15:121097#endif // ENABLE_BASIC_PRINTING
[email protected]5d98294912012-06-27 22:57:401098}
1099
1100void BrowserCommandController::UpdateSaveAsState() {
1101 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1102}
1103
estade8c0780f2015-08-21 23:36:411104void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1105 command_updater_.UpdateCommandEnabled(
1106 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
1107}
1108
[email protected]05454532013-01-22 21:09:081109// static
1110void BrowserCommandController::UpdateOpenFileState(
1111 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401112 bool enabled = true;
1113 PrefService* local_state = g_browser_process->local_state();
1114 if (local_state)
1115 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1116
[email protected]05454532013-01-22 21:09:081117 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401118}
1119
1120void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1121 bool force) {
1122 window()->UpdateReloadStopState(is_loading, force);
1123 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1124}
1125
[email protected]2e9369e2014-08-15 09:12:531126void BrowserCommandController::UpdateTabRestoreCommandState() {
blundell74001adc2015-09-18 11:04:251127 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531128 TabRestoreServiceFactory::GetForProfile(profile());
1129 // The command is enabled if the service hasn't loaded yet to trigger loading.
1130 // The command is updated once the load completes.
1131 command_updater_.UpdateCommandEnabled(
1132 IDC_RESTORE_TAB,
1133 tab_restore_service &&
1134 (!tab_restore_service->IsLoaded() ||
1135 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1136}
1137
[email protected]3cac87232012-11-20 01:48:271138void BrowserCommandController::UpdateCommandsForFind() {
1139 TabStripModel* model = browser_->tab_strip_model();
1140 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1141 !browser_->is_devtools();
1142
1143 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1144 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1145 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1146}
1147
apacible45cbfc92015-09-28 22:45:411148void BrowserCommandController::UpdateCommandsForMediaRouter() {
1149 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1150 CanRouteMedia(browser_));
1151}
1152
[email protected]409ea2972012-11-10 19:54:431153void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071154 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401155}
1156
1157void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241158 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071159 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1160 if (interstitial_observers_[i]->web_contents() != contents)
1161 continue;
1162
1163 delete interstitial_observers_[i];
1164 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1165 return;
1166 }
[email protected]5d98294912012-06-27 22:57:401167}
1168
1169BrowserWindow* BrowserCommandController::window() {
1170 return browser_->window();
1171}
1172
1173Profile* BrowserCommandController::profile() {
1174 return browser_->profile();
1175}
1176
[email protected]5d98294912012-06-27 22:57:401177} // namespace chrome