Chromecast: extracts Linux window creation code to a common place.
[chromium-blink-merge.git] / ash / shell / shell_delegate_impl.cc
blob828e01ee3befb47fed86478ad8be58cc9480f8e8
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/wm/core/input_method_event_filter.h"
29 namespace ash {
30 namespace shell {
31 namespace {
33 class NewWindowDelegateImpl : public NewWindowDelegate {
34 public:
35 NewWindowDelegateImpl() {}
36 virtual ~NewWindowDelegateImpl() {}
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);
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 {}
53 private:
54 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
57 class MediaDelegateImpl : public MediaDelegate {
58 public:
59 MediaDelegateImpl() {}
60 virtual ~MediaDelegateImpl() {}
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;
71 private:
72 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
75 class SessionStateDelegateImpl : public SessionStateDelegate {
76 public:
77 SessionStateDelegateImpl()
78 : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
80 virtual ~SessionStateDelegateImpl() {}
82 // SessionStateDelegate:
83 virtual content::BrowserContext* GetBrowserContextByIndex(
84 MultiProfileIndex index) override {
85 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
87 virtual content::BrowserContext* GetBrowserContextForWindow(
88 aura::Window* window) override {
89 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
91 virtual int GetMaximumNumberOfLoggedInUsers() const override { return 3; }
92 virtual int NumberOfLoggedInUsers() const override {
93 // ash_shell has 2 users.
94 return 2;
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;
102 virtual void LockScreen() override {
103 shell::CreateLockScreen();
104 screen_locked_ = true;
105 Shell::GetInstance()->UpdateShelfVisibility();
107 virtual void UnlockScreen() override {
108 screen_locked_ = false;
109 Shell::GetInstance()->UpdateShelfVisibility();
111 virtual bool IsUserSessionBlocked() const override {
112 return !IsActiveUserSessionStarted() || IsScreenLocked();
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;
119 virtual const user_manager::UserInfo* GetUserInfo(
120 MultiProfileIndex index) const override {
121 return user_info_.get();
123 virtual const user_manager::UserInfo* GetUserInfo(
124 content::BrowserContext* context) const override {
125 return user_info_.get();
127 virtual bool ShouldShowAvatar(aura::Window* window) const override {
128 return !user_info_->GetImage().isNull();
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;
135 virtual void AddSessionStateObserver(
136 ash::SessionStateObserver* observer) override {}
137 virtual void RemoveSessionStateObserver(
138 ash::SessionStateObserver* observer) override {}
140 private:
141 bool screen_locked_;
143 // A pseudo user info.
144 scoped_ptr<user_manager::UserInfo> user_info_;
146 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
149 } // namespace
151 ShellDelegateImpl::ShellDelegateImpl()
152 : watcher_(NULL),
153 shelf_delegate_(NULL),
154 browser_context_(NULL) {
157 ShellDelegateImpl::~ShellDelegateImpl() {
160 void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
161 watcher_ = watcher;
162 if (shelf_delegate_)
163 shelf_delegate_->set_watcher(watcher);
166 bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
167 return false;
170 bool ShellDelegateImpl::IsIncognitoAllowed() const {
171 return true;
174 bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
175 return false;
178 bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
179 return false;
182 bool ShellDelegateImpl::IsMultiAccountEnabled() const {
183 return false;
186 void ShellDelegateImpl::PreInit() {
189 void ShellDelegateImpl::PreShutdown() {
192 void ShellDelegateImpl::Exit() {
193 base::MessageLoopForUI::current()->Quit();
196 keyboard::KeyboardControllerProxy*
197 ShellDelegateImpl::CreateKeyboardControllerProxy() {
198 return new KeyboardControllerProxyStub();
201 void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
204 void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
205 VirtualKeyboardStateObserver* observer) {
208 void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
209 VirtualKeyboardStateObserver* observer) {
212 content::BrowserContext* ShellDelegateImpl::GetActiveBrowserContext() {
213 return browser_context_;
216 app_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();
222 ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
223 shelf_delegate_ = new ShelfDelegateImpl(watcher_);
224 return shelf_delegate_;
227 ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
228 return new DefaultSystemTrayDelegate;
231 ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
232 return new DefaultUserWallpaperDelegate();
235 ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
236 return new SessionStateDelegateImpl;
239 ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
240 return new DefaultAccessibilityDelegate;
243 ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
244 return new NewWindowDelegateImpl;
247 ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
248 return new MediaDelegateImpl;
251 ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
252 aura::Window* root,
253 ash::ShelfItemDelegate* item_delegate,
254 ash::ShelfItem* item) {
255 return new ContextMenu(root);
258 GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
259 // Real GPU support depends on src/content, so just use a stub.
260 return new GPUSupportStub;
263 base::string16 ShellDelegateImpl::GetProductName() const {
264 return base::string16();
267 } // namespace shell
268 } // namespace ash