don't pretend to support dbus on windows in dbus_export.h
[chromium-blink-merge.git] / ash / shell / shell_delegate_impl.cc
blob6261e1e98f2add161c8edfec38994d10be1c7eb6
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"
28 namespace ash {
29 namespace shell {
30 namespace {
32 class NewWindowDelegateImpl : public NewWindowDelegate {
33 public:
34 NewWindowDelegateImpl() {}
35 virtual ~NewWindowDelegateImpl() {}
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);
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 {}
52 private:
53 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
56 class MediaDelegateImpl : public MediaDelegate {
57 public:
58 MediaDelegateImpl() {}
59 virtual ~MediaDelegateImpl() {}
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;
70 private:
71 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
74 class SessionStateDelegateImpl : public SessionStateDelegate {
75 public:
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.
93 return 2;
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;
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 void AddSessionStateObserver(
132 ash::SessionStateObserver* observer) OVERRIDE {}
133 virtual void RemoveSessionStateObserver(
134 ash::SessionStateObserver* observer) OVERRIDE {}
136 private:
137 bool screen_locked_;
139 // A pseudo user info.
140 scoped_ptr<user_manager::UserInfo> user_info_;
142 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
145 } // namespace
147 ShellDelegateImpl::ShellDelegateImpl()
148 : watcher_(NULL),
149 shelf_delegate_(NULL),
150 browser_context_(NULL) {
153 ShellDelegateImpl::~ShellDelegateImpl() {
156 void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
157 watcher_ = watcher;
158 if (shelf_delegate_)
159 shelf_delegate_->set_watcher(watcher);
162 bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
163 return false;
166 bool ShellDelegateImpl::IsIncognitoAllowed() const {
167 return true;
170 bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
171 return false;
174 bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
175 return false;
178 bool ShellDelegateImpl::IsMultiAccountEnabled() const {
179 return false;
182 void ShellDelegateImpl::PreInit() {
185 void ShellDelegateImpl::PreShutdown() {
188 void ShellDelegateImpl::Exit() {
189 base::MessageLoopForUI::current()->Quit();
192 keyboard::KeyboardControllerProxy*
193 ShellDelegateImpl::CreateKeyboardControllerProxy() {
194 return new KeyboardControllerProxyStub();
197 void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
200 void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
201 VirtualKeyboardStateObserver* observer) {
204 void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
205 VirtualKeyboardStateObserver* observer) {
208 content::BrowserContext* ShellDelegateImpl::GetActiveBrowserContext() {
209 return browser_context_;
212 app_list::AppListViewDelegate* ShellDelegateImpl::CreateAppListViewDelegate() {
213 return ash::shell::CreateAppListViewDelegate();
216 ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
217 shelf_delegate_ = new ShelfDelegateImpl(watcher_);
218 return shelf_delegate_;
221 ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
222 return new DefaultSystemTrayDelegate;
225 ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
226 return new DefaultUserWallpaperDelegate();
229 ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
230 return new SessionStateDelegateImpl;
233 ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
234 return new DefaultAccessibilityDelegate;
237 ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
238 return new NewWindowDelegateImpl;
241 ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
242 return new MediaDelegateImpl;
245 ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
246 aura::Window* root,
247 ash::ShelfItemDelegate* item_delegate,
248 ash::ShelfItem* item) {
249 return new ContextMenu(root);
252 GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
253 // Real GPU support depends on src/content, so just use a stub.
254 return new GPUSupportStub;
257 base::string16 ShellDelegateImpl::GetProductName() const {
258 return base::string16();
261 } // namespace shell
262 } // namespace ash