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/app_list/app_list_view_delegate.h"
26 #include "ui/aura/window.h"
27 #include "ui/gfx/image/image.h"
33 class NewWindowDelegateImpl
: public NewWindowDelegate
{
35 NewWindowDelegateImpl() {}
36 ~NewWindowDelegateImpl() override
{}
39 void NewTab() override
{}
40 void NewWindow(bool incognito
) override
{
41 ash::shell::ToplevelWindow::CreateParams create_params
;
42 create_params
.can_resize
= true;
43 create_params
.can_maximize
= true;
44 ash::shell::ToplevelWindow::CreateToplevelWindow(create_params
);
46 void OpenFileManager() override
{}
47 void OpenCrosh() override
{}
48 void OpenGetHelp() override
{}
49 void RestoreTab() override
{}
50 void ShowKeyboardOverlay() override
{}
51 void ShowTaskManager() override
{}
52 void OpenFeedbackPage() override
{}
55 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl
);
58 class MediaDelegateImpl
: public MediaDelegate
{
60 MediaDelegateImpl() {}
61 ~MediaDelegateImpl() override
{}
64 void HandleMediaNextTrack() override
{}
65 void HandleMediaPlayPause() override
{}
66 void HandleMediaPrevTrack() override
{}
67 MediaCaptureState
GetMediaCaptureState(
68 content::BrowserContext
* context
) override
{
69 return MEDIA_CAPTURE_VIDEO
;
73 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl
);
76 class SessionStateDelegateImpl
: public SessionStateDelegate
{
78 SessionStateDelegateImpl()
79 : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
81 ~SessionStateDelegateImpl() override
{}
83 // SessionStateDelegate:
84 content::BrowserContext
* GetBrowserContextByIndex(
85 MultiProfileIndex index
) override
{
86 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
88 content::BrowserContext
* GetBrowserContextForWindow(
89 aura::Window
* window
) override
{
90 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
92 content::BrowserContext
* GetUserPresentingBrowserContextForWindow(
93 aura::Window
* window
) override
{
96 int GetMaximumNumberOfLoggedInUsers() const override
{ return 3; }
97 int NumberOfLoggedInUsers() const override
{
98 // ash_shell has 2 users.
101 bool IsActiveUserSessionStarted() const override
{ return true; }
102 bool CanLockScreen() const override
{ return true; }
103 bool IsScreenLocked() const override
{ return screen_locked_
; }
104 bool ShouldLockScreenBeforeSuspending() const override
{ return false; }
105 void LockScreen() override
{
106 shell::CreateLockScreen();
107 screen_locked_
= true;
108 Shell::GetInstance()->UpdateShelfVisibility();
110 void UnlockScreen() override
{
111 screen_locked_
= false;
112 Shell::GetInstance()->UpdateShelfVisibility();
114 bool IsUserSessionBlocked() const override
{
115 return !IsActiveUserSessionStarted() || IsScreenLocked();
117 SessionState
GetSessionState() const override
{
118 // Assume that if session is not active we're at login.
119 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
120 : SESSION_STATE_LOGIN_PRIMARY
;
122 const user_manager::UserInfo
* GetUserInfo(
123 MultiProfileIndex index
) const override
{
124 return user_info_
.get();
126 const user_manager::UserInfo
* GetUserInfo(
127 content::BrowserContext
* context
) const override
{
128 return user_info_
.get();
130 bool ShouldShowAvatar(aura::Window
* window
) const override
{
131 return !user_info_
->GetImage().isNull();
133 void SwitchActiveUser(const std::string
& user_id
) override
{}
134 void CycleActiveUser(CycleUser cycle_user
) override
{}
135 bool IsMultiProfileAllowedByPrimaryUserPolicy() const override
{
138 void AddSessionStateObserver(ash::SessionStateObserver
* observer
) override
{}
139 void RemoveSessionStateObserver(
140 ash::SessionStateObserver
* observer
) override
{}
145 // A pseudo user info.
146 scoped_ptr
<user_manager::UserInfo
> user_info_
;
148 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl
);
153 ShellDelegateImpl::ShellDelegateImpl()
155 shelf_delegate_(NULL
),
156 browser_context_(NULL
) {
159 ShellDelegateImpl::~ShellDelegateImpl() {
162 void ShellDelegateImpl::SetWatcher(WindowWatcher
* watcher
) {
165 shelf_delegate_
->set_watcher(watcher
);
168 bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
172 bool ShellDelegateImpl::IsIncognitoAllowed() const {
176 bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
180 bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
184 bool ShellDelegateImpl::IsMultiAccountEnabled() const {
188 bool ShellDelegateImpl::IsForceMaximizeOnFirstRun() const {
192 void ShellDelegateImpl::PreInit() {
195 void ShellDelegateImpl::PreShutdown() {
198 void ShellDelegateImpl::Exit() {
199 base::MessageLoopForUI::current()->Quit();
202 keyboard::KeyboardControllerProxy
*
203 ShellDelegateImpl::CreateKeyboardControllerProxy() {
204 return new KeyboardControllerProxyStub();
207 void ShellDelegateImpl::VirtualKeyboardActivated(bool activated
) {
210 void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
211 VirtualKeyboardStateObserver
* observer
) {
214 void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
215 VirtualKeyboardStateObserver
* observer
) {
218 content::BrowserContext
* ShellDelegateImpl::GetActiveBrowserContext() {
219 return browser_context_
;
222 app_list::AppListViewDelegate
* ShellDelegateImpl::GetAppListViewDelegate() {
223 if (!app_list_view_delegate_
)
224 app_list_view_delegate_
.reset(ash::shell::CreateAppListViewDelegate());
225 return app_list_view_delegate_
.get();
228 ShelfDelegate
* ShellDelegateImpl::CreateShelfDelegate(ShelfModel
* model
) {
229 shelf_delegate_
= new ShelfDelegateImpl(watcher_
);
230 return shelf_delegate_
;
233 ash::SystemTrayDelegate
* ShellDelegateImpl::CreateSystemTrayDelegate() {
234 return new DefaultSystemTrayDelegate
;
237 ash::UserWallpaperDelegate
* ShellDelegateImpl::CreateUserWallpaperDelegate() {
238 return new DefaultUserWallpaperDelegate();
241 ash::SessionStateDelegate
* ShellDelegateImpl::CreateSessionStateDelegate() {
242 return new SessionStateDelegateImpl
;
245 ash::AccessibilityDelegate
* ShellDelegateImpl::CreateAccessibilityDelegate() {
246 return new DefaultAccessibilityDelegate
;
249 ash::NewWindowDelegate
* ShellDelegateImpl::CreateNewWindowDelegate() {
250 return new NewWindowDelegateImpl
;
253 ash::MediaDelegate
* ShellDelegateImpl::CreateMediaDelegate() {
254 return new MediaDelegateImpl
;
257 ui::MenuModel
* ShellDelegateImpl::CreateContextMenu(
259 ash::ShelfItemDelegate
* item_delegate
,
260 ash::ShelfItem
* item
) {
261 return new ContextMenu(root
);
264 GPUSupport
* ShellDelegateImpl::CreateGPUSupport() {
265 // Real GPU support depends on src/content, so just use a stub.
266 return new GPUSupportStub
;
269 base::string16
ShellDelegateImpl::GetProductName() const {
270 return base::string16();
273 gfx::Image
ShellDelegateImpl::GetDeprecatedAcceleratorImage() const {