blob: db062e0994e4163cc9dfaf9d2c0feb8115c9b5df [file] [log] [blame]
[email protected]262f8bd2012-03-23 19:30:271// 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
[email protected]f3ab6eff52013-10-24 03:29:387#include "ash/accessibility_delegate.h"
[email protected]f3ab6eff52013-10-24 03:29:388#include "ash/default_accessibility_delegate.h"
[email protected]a7611df2013-09-26 07:57:109#include "ash/default_user_wallpaper_delegate.h"
[email protected]99edff3e2014-01-31 18:20:3610#include "ash/gpu_support_stub.h"
[email protected]efc897f72013-11-01 11:43:0711#include "ash/media_delegate.h"
[email protected]47686c42013-10-25 01:49:1712#include "ash/new_window_delegate.h"
[email protected]fdf74bf2014-04-30 21:24:0213#include "ash/session/session_state_delegate.h"
benb91330f2015-10-03 22:20:1814#include "ash/shell/content/shell_content_state_impl.h"
[email protected]565f32fc02013-03-05 18:51:4815#include "ash/shell/context_menu.h"
[email protected]262f8bd2012-03-23 19:30:2716#include "ash/shell/example_factory.h"
[email protected]8b57e942013-12-09 19:39:2017#include "ash/shell/shelf_delegate_impl.h"
[email protected]b77236f72012-03-25 03:07:1918#include "ash/shell/toplevel_window.h"
[email protected]262f8bd2012-03-23 19:30:2719#include "ash/shell_window_ids.h"
[email protected]9f19d5c2013-09-13 17:01:4820#include "ash/system/tray/default_system_tray_delegate.h"
benb91330f2015-10-03 22:20:1821#include "ash/test/content/keyboard_controller_proxy_stub.h"
[email protected]a41b4e12013-09-20 04:36:3422#include "ash/wm/window_state.h"
[email protected]9e3e6352013-07-17 04:07:5123#include "base/message_loop/message_loop.h"
[email protected]7009d9b2014-05-03 21:38:3624#include "base/strings/utf_string_conversions.h"
[email protected]d66eac42014-07-14 23:48:3025#include "components/user_manager/user_info_impl.h"
tapted537b88b12014-09-19 02:48:5226#include "ui/app_list/app_list_view_delegate.h"
[email protected]262f8bd2012-03-23 19:30:2727#include "ui/aura/window.h"
afakhrycd2bb98d2015-09-09 09:03:4228#include "ui/gfx/image/image.h"
ben93072442015-10-05 19:14:3229#include "ui/gfx/image/image_skia.h"
[email protected]262f8bd2012-03-23 19:30:2730
31namespace ash {
32namespace shell {
[email protected]47686c42013-10-25 01:49:1733namespace {
34
35class NewWindowDelegateImpl : public NewWindowDelegate {
36 public:
37 NewWindowDelegateImpl() {}
dchengf5963512014-10-28 01:14:1338 ~NewWindowDelegateImpl() override {}
[email protected]47686c42013-10-25 01:49:1739
[email protected]7009d9b2014-05-03 21:38:3640 // NewWindowDelegate:
dchengf5963512014-10-28 01:14:1341 void NewTab() override {}
42 void NewWindow(bool incognito) override {
[email protected]47686c42013-10-25 01:49:1743 ash::shell::ToplevelWindow::CreateParams create_params;
44 create_params.can_resize = true;
45 create_params.can_maximize = true;
46 ash::shell::ToplevelWindow::CreateToplevelWindow(create_params);
47 }
dchengf5963512014-10-28 01:14:1348 void OpenFileManager() override {}
49 void OpenCrosh() override {}
cyleeb6ce38f2015-01-08 12:25:3150 void OpenGetHelp() override {}
dchengf5963512014-10-28 01:14:1351 void RestoreTab() override {}
52 void ShowKeyboardOverlay() override {}
53 void ShowTaskManager() override {}
54 void OpenFeedbackPage() override {}
[email protected]47686c42013-10-25 01:49:1755
56 private:
57 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
58};
59
[email protected]efc897f72013-11-01 11:43:0760class MediaDelegateImpl : public MediaDelegate {
61 public:
62 MediaDelegateImpl() {}
dchengf5963512014-10-28 01:14:1363 ~MediaDelegateImpl() override {}
[email protected]efc897f72013-11-01 11:43:0764
[email protected]7009d9b2014-05-03 21:38:3665 // MediaDelegate:
dchengf5963512014-10-28 01:14:1366 void HandleMediaNextTrack() override {}
67 void HandleMediaPlayPause() override {}
68 void HandleMediaPrevTrack() override {}
ben93072442015-10-05 19:14:3269 MediaCaptureState GetMediaCaptureState(UserIndex index) override {
[email protected]7009d9b2014-05-03 21:38:3670 return MEDIA_CAPTURE_VIDEO;
71 }
[email protected]efc897f72013-11-01 11:43:0772
73 private:
74 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
75};
76
[email protected]7009d9b2014-05-03 21:38:3677class SessionStateDelegateImpl : public SessionStateDelegate {
78 public:
79 SessionStateDelegateImpl()
[email protected]d66eac42014-07-14 23:48:3080 : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
[email protected]7009d9b2014-05-03 21:38:3681
dchengf5963512014-10-28 01:14:1382 ~SessionStateDelegateImpl() override {}
[email protected]7009d9b2014-05-03 21:38:3683
84 // SessionStateDelegate:
dchengf5963512014-10-28 01:14:1385 int GetMaximumNumberOfLoggedInUsers() const override { return 3; }
86 int NumberOfLoggedInUsers() const override {
[email protected]7009d9b2014-05-03 21:38:3687 // ash_shell has 2 users.
88 return 2;
89 }
dchengf5963512014-10-28 01:14:1390 bool IsActiveUserSessionStarted() const override { return true; }
91 bool CanLockScreen() const override { return true; }
92 bool IsScreenLocked() const override { return screen_locked_; }
93 bool ShouldLockScreenBeforeSuspending() const override { return false; }
94 void LockScreen() override {
[email protected]7009d9b2014-05-03 21:38:3695 shell::CreateLockScreen();
96 screen_locked_ = true;
97 Shell::GetInstance()->UpdateShelfVisibility();
98 }
dchengf5963512014-10-28 01:14:1399 void UnlockScreen() override {
[email protected]7009d9b2014-05-03 21:38:36100 screen_locked_ = false;
101 Shell::GetInstance()->UpdateShelfVisibility();
102 }
dchengf5963512014-10-28 01:14:13103 bool IsUserSessionBlocked() const override {
[email protected]7009d9b2014-05-03 21:38:36104 return !IsActiveUserSessionStarted() || IsScreenLocked();
105 }
dchengf5963512014-10-28 01:14:13106 SessionState GetSessionState() const override {
[email protected]7009d9b2014-05-03 21:38:36107 // Assume that if session is not active we're at login.
108 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
109 : SESSION_STATE_LOGIN_PRIMARY;
110 }
ben93072442015-10-05 19:14:32111 const user_manager::UserInfo* GetUserInfo(UserIndex index) const override {
[email protected]7009d9b2014-05-03 21:38:36112 return user_info_.get();
113 }
dchengf5963512014-10-28 01:14:13114 bool ShouldShowAvatar(aura::Window* window) const override {
[email protected]7009d9b2014-05-03 21:38:36115 return !user_info_->GetImage().isNull();
116 }
ben93072442015-10-05 19:14:32117 gfx::ImageSkia GetAvatarImageForWindow(aura::Window* window) const override {
118 return gfx::ImageSkia();
119 }
dchengf5963512014-10-28 01:14:13120 void SwitchActiveUser(const std::string& user_id) override {}
121 void CycleActiveUser(CycleUser cycle_user) override {}
122 bool IsMultiProfileAllowedByPrimaryUserPolicy() const override {
[email protected]815dfac92014-08-13 16:04:04123 return true;
124 }
dchengf5963512014-10-28 01:14:13125 void AddSessionStateObserver(ash::SessionStateObserver* observer) override {}
126 void RemoveSessionStateObserver(
mostynb10d6b382014-10-03 16:23:45127 ash::SessionStateObserver* observer) override {}
[email protected]7009d9b2014-05-03 21:38:36128
129 private:
130 bool screen_locked_;
131
132 // A pseudo user info.
[email protected]d66eac42014-07-14 23:48:30133 scoped_ptr<user_manager::UserInfo> user_info_;
[email protected]7009d9b2014-05-03 21:38:36134
135 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
136};
137
[email protected]47686c42013-10-25 01:49:17138} // namespace
[email protected]262f8bd2012-03-23 19:30:27139
140ShellDelegateImpl::ShellDelegateImpl()
benb91330f2015-10-03 22:20:18141 : watcher_(NULL), shelf_delegate_(NULL) {}
[email protected]262f8bd2012-03-23 19:30:27142
143ShellDelegateImpl::~ShellDelegateImpl() {
144}
145
146void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
147 watcher_ = watcher;
[email protected]8b57e942013-12-09 19:39:20148 if (shelf_delegate_)
149 shelf_delegate_->set_watcher(watcher);
[email protected]262f8bd2012-03-23 19:30:27150}
151
[email protected]5c85d5d2012-12-03 14:22:56152bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
[email protected]697f04c2012-10-03 01:15:10153 return false;
154}
155
[email protected]5ecf6122013-10-31 12:24:09156bool ShellDelegateImpl::IsIncognitoAllowed() const {
157 return true;
158}
159
[email protected]e718e6f2013-04-15 16:01:59160bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
161 return false;
162}
163
[email protected]565f32fc02013-03-05 18:51:48164bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
165 return false;
166}
167
[email protected]d7ffac72014-04-10 13:17:17168bool ShellDelegateImpl::IsMultiAccountEnabled() const {
169 return false;
170}
171
ben894584d2015-09-30 23:56:53172bool ShellDelegateImpl::CanShowWindowForUser(aura::Window* window) const {
173 return true;
174}
175
peletskyida0bbb12015-04-08 17:11:04176bool ShellDelegateImpl::IsForceMaximizeOnFirstRun() const {
177 return false;
178}
179
[email protected]dcc990722013-03-24 16:35:20180void ShellDelegateImpl::PreInit() {
181}
182
[email protected]050e77182014-03-25 15:29:16183void ShellDelegateImpl::PreShutdown() {
[email protected]3528b7d2012-04-18 10:46:36184}
185
[email protected]262f8bd2012-03-23 19:30:27186void ShellDelegateImpl::Exit() {
[email protected]bd9a7f32013-04-30 20:25:42187 base::MessageLoopForUI::current()->Quit();
[email protected]262f8bd2012-03-23 19:30:27188}
189
[email protected]86459e2c2013-04-10 13:39:24190keyboard::KeyboardControllerProxy*
191 ShellDelegateImpl::CreateKeyboardControllerProxy() {
[email protected]eff4c7f2013-08-13 01:45:50192 return new KeyboardControllerProxyStub();
[email protected]86459e2c2013-04-10 13:39:24193}
194
[email protected]40db36e2014-04-04 14:08:18195void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
196}
197
198void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
199 VirtualKeyboardStateObserver* observer) {
200}
201
202void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
203 VirtualKeyboardStateObserver* observer) {
204}
205
tapted537b88b12014-09-19 02:48:52206app_list::AppListViewDelegate* ShellDelegateImpl::GetAppListViewDelegate() {
207 if (!app_list_view_delegate_)
208 app_list_view_delegate_.reset(ash::shell::CreateAppListViewDelegate());
209 return app_list_view_delegate_.get();
[email protected]262f8bd2012-03-23 19:30:27210}
211
[email protected]8b57e942013-12-09 19:39:20212ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
213 shelf_delegate_ = new ShelfDelegateImpl(watcher_);
214 return shelf_delegate_;
[email protected]262f8bd2012-03-23 19:30:27215}
216
[email protected]51ed5992012-11-07 10:14:39217ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
[email protected]9f19d5c2013-09-13 17:01:48218 return new DefaultSystemTrayDelegate;
[email protected]262f8bd2012-03-23 19:30:27219}
220
221ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
[email protected]a7611df2013-09-26 07:57:10222 return new DefaultUserWallpaperDelegate();
[email protected]262f8bd2012-03-23 19:30:27223}
[email protected]4d7ce4352012-07-13 06:56:06224
[email protected]fcb123d2013-04-17 15:58:49225ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
[email protected]7009d9b2014-05-03 21:38:36226 return new SessionStateDelegateImpl;
[email protected]fcb123d2013-04-17 15:58:49227}
228
[email protected]f3ab6eff52013-10-24 03:29:38229ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
[email protected]093b8d642014-04-03 20:59:28230 return new DefaultAccessibilityDelegate;
[email protected]f3ab6eff52013-10-24 03:29:38231}
232
[email protected]47686c42013-10-25 01:49:17233ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
234 return new NewWindowDelegateImpl;
[email protected]c28853612012-05-31 22:43:44235}
[email protected]262f8bd2012-03-23 19:30:27236
[email protected]efc897f72013-11-01 11:43:07237ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
238 return new MediaDelegateImpl;
239}
240
[email protected]e0cfc7f2014-01-09 20:25:42241ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
242 aura::Window* root,
243 ash::ShelfItemDelegate* item_delegate,
[email protected]eec0971422014-02-03 23:51:27244 ash::ShelfItem* item) {
[email protected]431552c2012-10-23 00:38:33245 return new ContextMenu(root);
246}
247
[email protected]99edff3e2014-01-31 18:20:36248GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
249 // Real GPU support depends on src/content, so just use a stub.
250 return new GPUSupportStub;
251}
252
[email protected]ed95e022013-04-11 04:03:32253base::string16 ShellDelegateImpl::GetProductName() const {
254 return base::string16();
[email protected]5673bf52013-02-01 06:14:24255}
256
afakhrycd2bb98d2015-09-09 09:03:42257gfx::Image ShellDelegateImpl::GetDeprecatedAcceleratorImage() const {
258 return gfx::Image();
259}
260
[email protected]262f8bd2012-03-23 19:30:27261} // namespace shell
262} // namespace ash