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.
4
5#include "ash/shell/shell_delegate_impl.h"
6
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/wm/core/input_method_event_filter.h"
28
29namespace ash {
30namespace shell {
31namespace {
32
33class NewWindowDelegateImpl : public NewWindowDelegate {
34 public:
35  NewWindowDelegateImpl() {}
36  virtual ~NewWindowDelegateImpl() {}
37
38  // NewWindowDelegate:
39  virtual void NewTab() OVERRIDE {}
40  virtual 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);
45  }
46  virtual void OpenFileManager() OVERRIDE {}
47  virtual void OpenCrosh() OVERRIDE {}
48  virtual void RestoreTab() OVERRIDE {}
49  virtual void ShowKeyboardOverlay() OVERRIDE {}
50  virtual void ShowTaskManager() OVERRIDE {}
51  virtual void OpenFeedbackPage() OVERRIDE {}
52
53 private:
54  DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
55};
56
57class MediaDelegateImpl : public MediaDelegate {
58 public:
59  MediaDelegateImpl() {}
60  virtual ~MediaDelegateImpl() {}
61
62  // MediaDelegate:
63  virtual void HandleMediaNextTrack() OVERRIDE {}
64  virtual void HandleMediaPlayPause() OVERRIDE {}
65  virtual void HandleMediaPrevTrack() OVERRIDE {}
66  virtual MediaCaptureState GetMediaCaptureState(
67      content::BrowserContext* context) OVERRIDE {
68    return MEDIA_CAPTURE_VIDEO;
69  }
70
71 private:
72  DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
73};
74
75class SessionStateDelegateImpl : public SessionStateDelegate {
76 public:
77  SessionStateDelegateImpl()
78      : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
79
80  virtual ~SessionStateDelegateImpl() {}
81
82  // SessionStateDelegate:
83  virtual content::BrowserContext* GetBrowserContextByIndex(
84      MultiProfileIndex index) OVERRIDE {
85    return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
86  }
87  virtual content::BrowserContext* GetBrowserContextForWindow(
88      aura::Window* window) OVERRIDE {
89    return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
90  }
91  virtual int GetMaximumNumberOfLoggedInUsers() const OVERRIDE { return 3; }
92  virtual int NumberOfLoggedInUsers() const OVERRIDE {
93    // ash_shell has 2 users.
94    return 2;
95  }
96  virtual bool IsActiveUserSessionStarted() const OVERRIDE { return true; }
97  virtual bool CanLockScreen() const OVERRIDE { return true; }
98  virtual bool IsScreenLocked() const OVERRIDE { return screen_locked_; }
99  virtual bool ShouldLockScreenBeforeSuspending() const OVERRIDE {
100    return false;
101  }
102  virtual void LockScreen() OVERRIDE {
103    shell::CreateLockScreen();
104    screen_locked_ = true;
105    Shell::GetInstance()->UpdateShelfVisibility();
106  }
107  virtual void UnlockScreen() OVERRIDE {
108    screen_locked_ = false;
109    Shell::GetInstance()->UpdateShelfVisibility();
110  }
111  virtual bool IsUserSessionBlocked() const OVERRIDE {
112    return !IsActiveUserSessionStarted() || IsScreenLocked();
113  }
114  virtual SessionState GetSessionState() const OVERRIDE {
115    // Assume that if session is not active we're at login.
116    return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
117                                        : SESSION_STATE_LOGIN_PRIMARY;
118  }
119  virtual const user_manager::UserInfo* GetUserInfo(
120      MultiProfileIndex index) const OVERRIDE {
121    return user_info_.get();
122  }
123  virtual const user_manager::UserInfo* GetUserInfo(
124      content::BrowserContext* context) const OVERRIDE {
125    return user_info_.get();
126  }
127  virtual bool ShouldShowAvatar(aura::Window* window) const OVERRIDE {
128    return !user_info_->GetImage().isNull();
129  }
130  virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE {}
131  virtual void CycleActiveUser(CycleUser cycle_user) OVERRIDE {}
132  virtual bool IsMultiProfileAllowedByPrimaryUserPolicy() const OVERRIDE {
133    return true;
134  }
135  virtual void AddSessionStateObserver(
136      ash::SessionStateObserver* observer) OVERRIDE {}
137  virtual void RemoveSessionStateObserver(
138      ash::SessionStateObserver* observer) OVERRIDE {}
139
140 private:
141  bool screen_locked_;
142
143  // A pseudo user info.
144  scoped_ptr<user_manager::UserInfo> user_info_;
145
146  DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
147};
148
149}  // namespace
150
151ShellDelegateImpl::ShellDelegateImpl()
152    : watcher_(NULL),
153      shelf_delegate_(NULL),
154      browser_context_(NULL) {
155}
156
157ShellDelegateImpl::~ShellDelegateImpl() {
158}
159
160void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
161  watcher_ = watcher;
162  if (shelf_delegate_)
163    shelf_delegate_->set_watcher(watcher);
164}
165
166bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
167  return false;
168}
169
170bool ShellDelegateImpl::IsIncognitoAllowed() const {
171  return true;
172}
173
174bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
175  return false;
176}
177
178bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
179  return false;
180}
181
182bool ShellDelegateImpl::IsMultiAccountEnabled() const {
183  return false;
184}
185
186void ShellDelegateImpl::PreInit() {
187}
188
189void ShellDelegateImpl::PreShutdown() {
190}
191
192void ShellDelegateImpl::Exit() {
193  base::MessageLoopForUI::current()->Quit();
194}
195
196keyboard::KeyboardControllerProxy*
197    ShellDelegateImpl::CreateKeyboardControllerProxy() {
198  return new KeyboardControllerProxyStub();
199}
200
201void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
202}
203
204void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
205    VirtualKeyboardStateObserver* observer) {
206}
207
208void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
209    VirtualKeyboardStateObserver* observer) {
210}
211
212content::BrowserContext* ShellDelegateImpl::GetActiveBrowserContext() {
213  return browser_context_;
214}
215
216app_list::AppListViewDelegate* ShellDelegateImpl::GetAppListViewDelegate() {
217  if (!app_list_view_delegate_)
218    app_list_view_delegate_.reset(ash::shell::CreateAppListViewDelegate());
219  return app_list_view_delegate_.get();
220}
221
222ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
223  shelf_delegate_ = new ShelfDelegateImpl(watcher_);
224  return shelf_delegate_;
225}
226
227ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
228  return new DefaultSystemTrayDelegate;
229}
230
231ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
232  return new DefaultUserWallpaperDelegate();
233}
234
235ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
236  return new SessionStateDelegateImpl;
237}
238
239ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
240  return new DefaultAccessibilityDelegate;
241}
242
243ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
244  return new NewWindowDelegateImpl;
245}
246
247ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
248  return new MediaDelegateImpl;
249}
250
251ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
252    aura::Window* root,
253    ash::ShelfItemDelegate* item_delegate,
254    ash::ShelfItem* item) {
255  return new ContextMenu(root);
256}
257
258GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
259  // Real GPU support depends on src/content, so just use a stub.
260  return new GPUSupportStub;
261}
262
263base::string16 ShellDelegateImpl::GetProductName() const {
264  return base::string16();
265}
266
267}  // namespace shell
268}  // namespace ash
269