1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/shell/shell_delegate_impl.h"
7 #include "ash/accessibility_delegate.h"
8 #include "ash/default_accessibility_delegate.h"
9 #include "ash/default_user_wallpaper_delegate.h"
10 #include "ash/gpu_support_stub.h"
11 #include "ash/media_delegate.h"
12 #include "ash/new_window_delegate.h"
13 #include "ash/session/session_state_delegate.h"
14 #include "ash/shell/context_menu.h"
15 #include "ash/shell/example_factory.h"
16 #include "ash/shell/keyboard_controller_proxy_stub.h"
17 #include "ash/shell/shelf_delegate_impl.h"
18 #include "ash/shell/toplevel_window.h"
19 #include "ash/shell_window_ids.h"
20 #include "ash/system/tray/default_system_tray_delegate.h"
21 #include "ash/wm/window_state.h"
22 #include "base/message_loop/message_loop.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "components/user_manager/user_info_impl.h"
25 #include "ui/aura/window.h"
26 #include "ui/wm/core/input_method_event_filter.h"
32 class NewWindowDelegateImpl
: public NewWindowDelegate
{
34 NewWindowDelegateImpl() {}
35 virtual ~NewWindowDelegateImpl() {}
38 virtual void NewTab() OVERRIDE
{}
39 virtual void NewWindow(bool incognito
) OVERRIDE
{
40 ash::shell::ToplevelWindow::CreateParams create_params
;
41 create_params
.can_resize
= true;
42 create_params
.can_maximize
= true;
43 ash::shell::ToplevelWindow::CreateToplevelWindow(create_params
);
45 virtual void OpenFileManager() OVERRIDE
{}
46 virtual void OpenCrosh() OVERRIDE
{}
47 virtual void RestoreTab() OVERRIDE
{}
48 virtual void ShowKeyboardOverlay() OVERRIDE
{}
49 virtual void ShowTaskManager() OVERRIDE
{}
50 virtual void OpenFeedbackPage() OVERRIDE
{}
53 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl
);
56 class MediaDelegateImpl
: public MediaDelegate
{
58 MediaDelegateImpl() {}
59 virtual ~MediaDelegateImpl() {}
62 virtual void HandleMediaNextTrack() OVERRIDE
{}
63 virtual void HandleMediaPlayPause() OVERRIDE
{}
64 virtual void HandleMediaPrevTrack() OVERRIDE
{}
65 virtual MediaCaptureState
GetMediaCaptureState(
66 content::BrowserContext
* context
) OVERRIDE
{
67 return MEDIA_CAPTURE_VIDEO
;
71 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl
);
74 class SessionStateDelegateImpl
: public SessionStateDelegate
{
76 SessionStateDelegateImpl()
77 : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
79 virtual ~SessionStateDelegateImpl() {}
81 // SessionStateDelegate:
82 virtual content::BrowserContext
* GetBrowserContextByIndex(
83 MultiProfileIndex index
) OVERRIDE
{
84 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
86 virtual content::BrowserContext
* GetBrowserContextForWindow(
87 aura::Window
* window
) OVERRIDE
{
88 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
90 virtual int GetMaximumNumberOfLoggedInUsers() const OVERRIDE
{ return 3; }
91 virtual int NumberOfLoggedInUsers() const OVERRIDE
{
92 // ash_shell has 2 users.
95 virtual bool IsActiveUserSessionStarted() const OVERRIDE
{ return true; }
96 virtual bool CanLockScreen() const OVERRIDE
{ return true; }
97 virtual bool IsScreenLocked() const OVERRIDE
{ return screen_locked_
; }
98 virtual bool ShouldLockScreenBeforeSuspending() const OVERRIDE
{
101 virtual void LockScreen() OVERRIDE
{
102 shell::CreateLockScreen();
103 screen_locked_
= true;
104 Shell::GetInstance()->UpdateShelfVisibility();
106 virtual void UnlockScreen() OVERRIDE
{
107 screen_locked_
= false;
108 Shell::GetInstance()->UpdateShelfVisibility();
110 virtual bool IsUserSessionBlocked() const OVERRIDE
{
111 return !IsActiveUserSessionStarted() || IsScreenLocked();
113 virtual SessionState
GetSessionState() const OVERRIDE
{
114 // Assume that if session is not active we're at login.
115 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
116 : SESSION_STATE_LOGIN_PRIMARY
;
118 virtual const user_manager::UserInfo
* GetUserInfo(
119 MultiProfileIndex index
) const OVERRIDE
{
120 return user_info_
.get();
122 virtual const user_manager::UserInfo
* GetUserInfo(
123 content::BrowserContext
* context
) const OVERRIDE
{
124 return user_info_
.get();
126 virtual bool ShouldShowAvatar(aura::Window
* window
) const OVERRIDE
{
127 return !user_info_
->GetImage().isNull();
129 virtual void SwitchActiveUser(const std::string
& user_id
) OVERRIDE
{}
130 virtual void CycleActiveUser(CycleUser cycle_user
) OVERRIDE
{}
131 virtual bool IsMultiProfileAllowedByPrimaryUserPolicy() const OVERRIDE
{
134 virtual void AddSessionStateObserver(
135 ash::SessionStateObserver
* observer
) OVERRIDE
{}
136 virtual void RemoveSessionStateObserver(
137 ash::SessionStateObserver
* observer
) OVERRIDE
{}
142 // A pseudo user info.
143 scoped_ptr
<user_manager::UserInfo
> user_info_
;
145 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl
);
150 ShellDelegateImpl::ShellDelegateImpl()
152 shelf_delegate_(NULL
),
153 browser_context_(NULL
) {
156 ShellDelegateImpl::~ShellDelegateImpl() {
159 void ShellDelegateImpl::SetWatcher(WindowWatcher
* watcher
) {
162 shelf_delegate_
->set_watcher(watcher
);
165 bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
169 bool ShellDelegateImpl::IsIncognitoAllowed() const {
173 bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
177 bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
181 bool ShellDelegateImpl::IsMultiAccountEnabled() const {
185 void ShellDelegateImpl::PreInit() {
188 void ShellDelegateImpl::PreShutdown() {
191 void ShellDelegateImpl::Exit() {
192 base::MessageLoopForUI::current()->Quit();
195 keyboard::KeyboardControllerProxy
*
196 ShellDelegateImpl::CreateKeyboardControllerProxy() {
197 return new KeyboardControllerProxyStub();
200 void ShellDelegateImpl::VirtualKeyboardActivated(bool activated
) {
203 void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
204 VirtualKeyboardStateObserver
* observer
) {
207 void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
208 VirtualKeyboardStateObserver
* observer
) {
211 content::BrowserContext
* ShellDelegateImpl::GetActiveBrowserContext() {
212 return browser_context_
;
215 app_list::AppListViewDelegate
* ShellDelegateImpl::CreateAppListViewDelegate() {
216 return ash::shell::CreateAppListViewDelegate();
219 ShelfDelegate
* ShellDelegateImpl::CreateShelfDelegate(ShelfModel
* model
) {
220 shelf_delegate_
= new ShelfDelegateImpl(watcher_
);
221 return shelf_delegate_
;
224 ash::SystemTrayDelegate
* ShellDelegateImpl::CreateSystemTrayDelegate() {
225 return new DefaultSystemTrayDelegate
;
228 ash::UserWallpaperDelegate
* ShellDelegateImpl::CreateUserWallpaperDelegate() {
229 return new DefaultUserWallpaperDelegate();
232 ash::SessionStateDelegate
* ShellDelegateImpl::CreateSessionStateDelegate() {
233 return new SessionStateDelegateImpl
;
236 ash::AccessibilityDelegate
* ShellDelegateImpl::CreateAccessibilityDelegate() {
237 return new DefaultAccessibilityDelegate
;
240 ash::NewWindowDelegate
* ShellDelegateImpl::CreateNewWindowDelegate() {
241 return new NewWindowDelegateImpl
;
244 ash::MediaDelegate
* ShellDelegateImpl::CreateMediaDelegate() {
245 return new MediaDelegateImpl
;
248 ui::MenuModel
* ShellDelegateImpl::CreateContextMenu(
250 ash::ShelfItemDelegate
* item_delegate
,
251 ash::ShelfItem
* item
) {
252 return new ContextMenu(root
);
255 GPUSupport
* ShellDelegateImpl::CreateGPUSupport() {
256 // Real GPU support depends on src/content, so just use a stub.
257 return new GPUSupportStub
;
260 base::string16
ShellDelegateImpl::GetProductName() const {
261 return base::string16();