blob: 1d0d4f60f5c6eb85ae427f1898a2a9a478aeb7f6 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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/ash/chrome_shell_delegate.h"
6
Ben Murdoch2385ea32013-08-06 11:01:04 +01007#include "apps/native_app_window.h"
Ben Murdocheb525c52013-07-10 11:40:50 +01008#include "apps/shell_window.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00009#include "ash/ash_switches.h"
10#include "ash/host/root_window_host_factory.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000011#include "ash/launcher/launcher_types.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000012#include "ash/magnifier/magnifier_constants.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010013#include "ash/session_state_delegate.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014#include "ash/shelf/shelf_widget.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000015#include "ash/system/tray/system_tray_delegate.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000016#include "ash/wm/window_properties.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017#include "ash/wm/window_util.h"
18#include "base/bind.h"
19#include "base/command_line.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000020#include "base/prefs/pref_service.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010021#include "base/strings/utf_string_conversions.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000022#include "chrome/browser/app_mode/app_mode_utils.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010023#include "chrome/browser/chrome_notification_types.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010024#include "chrome/browser/extensions/shell_window_registry.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000025#include "chrome/browser/lifetime/application_lifetime.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000026#include "chrome/browser/profiles/profile_manager.h"
27#include "chrome/browser/sessions/tab_restore_service.h"
28#include "chrome/browser/sessions/tab_restore_service_factory.h"
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +010029#include "chrome/browser/sessions/tab_restore_service_observer.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000030#include "chrome/browser/ui/app_list/app_list_view_delegate.h"
31#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010032#include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000033#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
34#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
35#include "chrome/browser/ui/ash/user_action_handler.h"
36#include "chrome/browser/ui/ash/window_positioner.h"
37#include "chrome/browser/ui/browser.h"
38#include "chrome/browser/ui/browser_commands.h"
39#include "chrome/browser/ui/browser_finder.h"
40#include "chrome/browser/ui/browser_window.h"
41#include "chrome/browser/ui/host_desktop.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010042#include "chrome/browser/ui/immersive_fullscreen_configuration.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000043#include "chrome/common/chrome_switches.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000044#include "content/public/browser/notification_service.h"
45#include "content/public/browser/user_metrics.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000046#include "grit/chromium_strings.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000047#include "grit/generated_resources.h"
48#include "ui/aura/client/user_action_client.h"
49#include "ui/aura/window.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000050#include "ui/base/l10n/l10n_util.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000051
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010052#if defined(OS_CHROMEOS)
53#include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
54#endif
55
Torne (Richard Coles)58218062012-11-14 11:43:16 +000056// static
57ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL;
58
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +010059namespace {
60
61void RestoreTabUsingProfile(Profile* profile) {
62 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile);
63 service->RestoreMostRecentEntry(NULL, chrome::HOST_DESKTOP_TYPE_ASH);
64}
65
66} // namespace
67
68// TabRestoreHelper is used to restore a tab. In particular when the user
69// attempts to a restore a tab if the TabRestoreService hasn't finished loading
70// this waits for it. Once the TabRestoreService finishes loading the tab is
71// restored.
72class ChromeShellDelegate::TabRestoreHelper : public TabRestoreServiceObserver {
73 public:
74 TabRestoreHelper(ChromeShellDelegate* delegate,
75 Profile* profile,
76 TabRestoreService* service)
77 : delegate_(delegate),
78 profile_(profile),
79 tab_restore_service_(service) {
80 tab_restore_service_->AddObserver(this);
81 }
82
83 virtual ~TabRestoreHelper() {
84 tab_restore_service_->RemoveObserver(this);
85 }
86
87 TabRestoreService* tab_restore_service() { return tab_restore_service_; }
88
89 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE {
90 }
91 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE {
92 // This destroys us.
93 delegate_->tab_restore_helper_.reset();
94 }
95
96 virtual void TabRestoreServiceLoaded(TabRestoreService* service) OVERRIDE {
97 RestoreTabUsingProfile(profile_);
98 // This destroys us.
99 delegate_->tab_restore_helper_.reset();
100 }
101
102 private:
103 ChromeShellDelegate* delegate_;
104 Profile* profile_;
105 TabRestoreService* tab_restore_service_;
106
107 DISALLOW_COPY_AND_ASSIGN(TabRestoreHelper);
108};
109
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000110ChromeShellDelegate::ChromeShellDelegate()
111 : window_positioner_(new ash::WindowPositioner()),
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100112 weak_factory_(this),
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000113 launcher_delegate_(NULL) {
114 instance_ = this;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000115 PlatformInit();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000116}
117
118ChromeShellDelegate::~ChromeShellDelegate() {
119 if (instance_ == this)
120 instance_ = NULL;
121}
122
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100123bool ChromeShellDelegate::IsMultiProfilesEnabled() const {
124 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000125}
126
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000127bool ChromeShellDelegate::IsRunningInForcedAppMode() const {
128 return chrome::IsRunningInForcedAppMode();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000129}
130
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000131void ChromeShellDelegate::Exit() {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000132 chrome::AttemptUserExit();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000133}
134
135void ChromeShellDelegate::NewTab() {
136 Browser* browser = GetTargetBrowser();
137 // If the browser was not active, we call BrowserWindow::Show to make it
138 // visible. Otherwise, we let Browser::NewTab handle the active window change.
139 const bool was_active = browser->window()->IsActive();
140 chrome::NewTab(browser);
141 if (!was_active)
142 browser->window()->Show();
143}
144
145void ChromeShellDelegate::NewWindow(bool is_incognito) {
146 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
147 chrome::NewEmptyWindow(
148 is_incognito ? profile->GetOffTheRecordProfile() : profile,
149 chrome::HOST_DESKTOP_TYPE_ASH);
150}
151
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100152void ChromeShellDelegate::ToggleFullscreen() {
153 // Only toggle if the user has a window open.
154 aura::Window* window = ash::wm::GetActiveWindow();
155 if (!window)
156 return;
157
158 bool is_fullscreen = ash::wm::IsWindowFullscreen(window);
159
160 // Windows which cannot be maximized should not be fullscreened.
Ben Murdocheb525c52013-07-10 11:40:50 +0100161 if (!is_fullscreen && !ash::wm::CanMaximizeWindow(window))
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100162 return;
163
164 Browser* browser = chrome::FindBrowserWithWindow(window);
165 if (browser) {
Ben Murdocheb525c52013-07-10 11:40:50 +0100166 // If a window is fullscreen, exit fullscreen.
167 if (is_fullscreen) {
168 chrome::ToggleFullscreenMode(browser);
169 return;
170 }
171
172 // AppNonClientFrameViewAsh shows only the window controls and no other
173 // window decorations which is pretty close to fullscreen. Put v1 apps
174 // into maximized mode instead of fullscreen to avoid showing the ugly
175 // fullscreen exit bubble.
176#if defined(OS_WIN)
177 if (browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) {
178 chrome::ToggleFullscreenMode(browser);
179 return;
180 }
181#endif // OS_WIN
182 if (browser->is_app() && browser->app_type() != Browser::APP_TYPE_CHILD)
183 ash::wm::ToggleMaximizedWindow(window);
184 else
185 chrome::ToggleFullscreenMode(browser);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100186 return;
187 }
188
189 // |window| may belong to a shell window.
Ben Murdocheb525c52013-07-10 11:40:50 +0100190 apps::ShellWindow* shell_window = extensions::ShellWindowRegistry::
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100191 GetShellWindowForNativeWindowAnyProfile(window);
192 if (shell_window) {
193 if (is_fullscreen)
194 shell_window->Restore();
195 else
196 shell_window->Fullscreen();
197 }
198}
199
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000200void ChromeShellDelegate::ToggleMaximized() {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000201 // Only toggle if the user has a window open.
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000202 aura::Window* window = ash::wm::GetActiveWindow();
203 if (!window)
204 return;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000205
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000206 // Get out of fullscreen when in fullscreen mode.
207 if (ash::wm::IsWindowFullscreen(window)) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100208 ToggleFullscreen();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000209 return;
210 }
211 ash::wm::ToggleMaximizedWindow(window);
212}
213
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000214void ChromeShellDelegate::RestoreTab() {
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100215 if (tab_restore_helper_.get()) {
216 DCHECK(!tab_restore_helper_->tab_restore_service()->IsLoaded());
217 return;
218 }
219
220 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
221 Profile* profile = browser ? browser->profile() : NULL;
222 if (!profile)
223 profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
224 if (profile->IsOffTheRecord())
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000225 return;
226 TabRestoreService* service =
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100227 TabRestoreServiceFactory::GetForProfile(profile);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000228 if (!service)
229 return;
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100230
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000231 if (service->IsLoaded()) {
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100232 RestoreTabUsingProfile(profile);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000233 } else {
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100234 tab_restore_helper_.reset(new TabRestoreHelper(this, profile, service));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000235 service->LoadTabsFromLastSession();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000236 }
237}
238
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000239void ChromeShellDelegate::ShowTaskManager() {
Ben Murdocheb525c52013-07-10 11:40:50 +0100240 chrome::OpenTaskManager(NULL);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000241}
242
243content::BrowserContext* ChromeShellDelegate::GetCurrentBrowserContext() {
244 return ProfileManager::GetDefaultProfile();
245}
246
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000247app_list::AppListViewDelegate*
248 ChromeShellDelegate::CreateAppListViewDelegate() {
249 DCHECK(ash::Shell::HasInstance());
250 // Shell will own the created delegate, and the delegate will own
251 // the controller.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000252 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
253 return new AppListViewDelegate(new AppListControllerDelegateAsh(), profile);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000254}
255
256ash::LauncherDelegate* ChromeShellDelegate::CreateLauncherDelegate(
257 ash::LauncherModel* model) {
Ben Murdocheb525c52013-07-10 11:40:50 +0100258 DCHECK(ProfileManager::IsGetDefaultProfileAllowed());
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000259 // TODO(oshima): This is currently broken with multiple launchers.
260 // Refactor so that there is just one launcher delegate in the
261 // shell.
262 if (!launcher_delegate_) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000263 launcher_delegate_ = ChromeLauncherController::CreateInstance(NULL, model);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000264 launcher_delegate_->Init();
265 }
266 return launcher_delegate_;
267}
268
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000269aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() {
270 return new UserActionHandler;
271}
272
273void ChromeShellDelegate::OpenFeedbackPage() {
274 chrome::OpenFeedbackDialog(GetTargetBrowser());
275}
276
277void ChromeShellDelegate::RecordUserMetricsAction(
278 ash::UserMetricsAction action) {
279 switch (action) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000280 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6:
281 content::RecordAction(
282 content::UserMetricsAction("Accel_KeyboardBrightnessDown_F6"));
283 break;
284 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7:
285 content::RecordAction(
286 content::UserMetricsAction("Accel_KeyboardBrightnessUp_F7"));
287 break;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000288 case ash::UMA_ACCEL_LOCK_SCREEN_L:
289 content::RecordAction(
290 content::UserMetricsAction("Accel_LockScreen_L"));
291 break;
292 case ash::UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON:
293 content::RecordAction(
294 content::UserMetricsAction("Accel_LockScreen_LockButton"));
295 break;
296 case ash::UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON:
297 content::RecordAction(
298 content::UserMetricsAction("Accel_LockScreen_PowerButton"));
299 break;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100300 case ash::UMA_ACCEL_FULLSCREEN_F4:
301 content::RecordAction(content::UserMetricsAction("Accel_Fullscreen_F4"));
302 break;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000303 case ash::UMA_ACCEL_MAXIMIZE_RESTORE_F4:
304 content::RecordAction(
305 content::UserMetricsAction("Accel_Maximize_Restore_F4"));
306 break;
307 case ash::UMA_ACCEL_NEWTAB_T:
308 content::RecordAction(content::UserMetricsAction("Accel_NewTab_T"));
309 break;
310 case ash::UMA_ACCEL_NEXTWINDOW_F5:
311 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_F5"));
312 break;
313 case ash::UMA_ACCEL_NEXTWINDOW_TAB:
314 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_Tab"));
315 break;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100316 case ash::UMA_ACCEL_OVERVIEW_F5:
317 content::RecordAction(content::UserMetricsAction("Accel_Overview_F5"));
318 break;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000319 case ash::UMA_ACCEL_PREVWINDOW_F5:
320 content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_F5"));
321 break;
322 case ash::UMA_ACCEL_PREVWINDOW_TAB:
323 content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_Tab"));
324 break;
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100325 case ash::UMA_ACCEL_EXIT_FIRST_Q:
326 content::RecordAction(content::UserMetricsAction("Accel_Exit_First_Q"));
327 break;
328 case ash::UMA_ACCEL_EXIT_SECOND_Q:
329 content::RecordAction(content::UserMetricsAction("Accel_Exit_Second_Q"));
330 break;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000331 case ash::UMA_ACCEL_SEARCH_LWIN:
332 content::RecordAction(content::UserMetricsAction("Accel_Search_LWin"));
333 break;
334 case ash::UMA_ACCEL_SHUT_DOWN_POWER_BUTTON:
335 content::RecordAction(
336 content::UserMetricsAction("Accel_ShutDown_PowerButton"));
337 break;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100338 case ash::UMA_CLOSE_THROUGH_CONTEXT_MENU:
339 content::RecordAction(content::UserMetricsAction("CloseFromContextMenu"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000340 break;
341 case ash::UMA_LAUNCHER_CLICK_ON_APP:
342 content::RecordAction(content::UserMetricsAction("Launcher_ClickOnApp"));
343 break;
344 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON:
345 content::RecordAction(
346 content::UserMetricsAction("Launcher_ClickOnApplistButton"));
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100347#if defined(OS_CHROMEOS)
348 chromeos::default_pinned_apps_field_trial::RecordShelfClick(
349 chromeos::default_pinned_apps_field_trial::APP_LAUNCHER);
350#endif
351 break;
352 case ash::UMA_MINIMIZE_PER_KEY:
353 content::RecordAction(content::UserMetricsAction("Minimize_UsingKey"));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000354 break;
355 case ash::UMA_MOUSE_DOWN:
356 content::RecordAction(content::UserMetricsAction("Mouse_Down"));
357 break;
358 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK:
359 content::RecordAction(
360 content::UserMetricsAction("Caption_ClickTogglesMaximize"));
361 break;
362 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE:
363 content::RecordAction(
364 content::UserMetricsAction("Caption_GestureTogglesMaximize"));
365 break;
366 case ash::UMA_TOUCHSCREEN_TAP_DOWN:
367 content::RecordAction(content::UserMetricsAction("Touchscreen_Down"));
368 break;
369 case ash::UMA_TRAY_HELP:
370 content::RecordAction(content::UserMetricsAction("Tray_Help"));
371 break;
372 case ash::UMA_TRAY_LOCK_SCREEN:
373 content::RecordAction(content::UserMetricsAction("Tray_LockScreen"));
374 break;
375 case ash::UMA_TRAY_SHUT_DOWN:
376 content::RecordAction(content::UserMetricsAction("Tray_ShutDown"));
377 break;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100378 case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK:
379 content::RecordAction(content::UserMetricsAction("AppCloseButton_Clk"));
380 break;
381 case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK:
382 content::RecordAction(content::UserMetricsAction("CloseButton_Clk"));
383 break;
384 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN:
385 content::RecordAction(content::UserMetricsAction("MaxButton_Clk_ExitFS"));
386 break;
387 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE:
388 content::RecordAction(
389 content::UserMetricsAction("MaxButton_Clk_Restore"));
390 break;
391 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE:
392 content::RecordAction(
393 content::UserMetricsAction("MaxButton_Clk_Maximize"));
394 break;
395 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE:
396 content::RecordAction(content::UserMetricsAction("MinButton_Clk"));
397 break;
398 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE:
399 content::RecordAction(content::UserMetricsAction("MaxButton_Maximize"));
400 break;
401 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT:
402 content::RecordAction(content::UserMetricsAction("MaxButton_MaxLeft"));
403 break;
404 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT:
405 content::RecordAction(content::UserMetricsAction("MaxButton_MaxRight"));
406 break;
407 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE:
408 content::RecordAction(content::UserMetricsAction("MaxButton_Minimize"));
409 break;
410 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE:
411 content::RecordAction(content::UserMetricsAction("MaxButton_Restore"));
412 break;
413 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_SHOW_BUBBLE:
414 content::RecordAction(content::UserMetricsAction("MaxButton_ShowBubble"));
415 break;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000416 }
417}
418
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000419ui::MenuModel* ChromeShellDelegate::CreateContextMenu(aura::RootWindow* root) {
420 DCHECK(launcher_delegate_);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000421 // Don't show context menu for exclusive app runtime mode.
422 if (chrome::IsRunningInAppMode())
423 return NULL;
424
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000425 return new LauncherContextMenu(launcher_delegate_, root);
426}
427
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000428ash::RootWindowHostFactory* ChromeShellDelegate::CreateRootWindowHostFactory() {
429 return ash::RootWindowHostFactory::Create();
430}
431
432string16 ChromeShellDelegate::GetProductName() const {
433 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
434}
435
436Browser* ChromeShellDelegate::GetTargetBrowser() {
437 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
438 if (browser)
439 return browser;
440 return chrome::FindOrCreateTabbedBrowser(
441 ProfileManager::GetDefaultProfileOrOffTheRecord(),
442 chrome::HOST_DESKTOP_TYPE_ASH);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000443}
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100444
445keyboard::KeyboardControllerProxy*
446 ChromeShellDelegate::CreateKeyboardControllerProxy() {
447 return new AshKeyboardControllerProxy();
448}