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