blob: 0671bf6127a44c63770e1637c717ac388ef29887 [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"
mfomitchev493ed602016-04-09 00:48:398#include "ash/app_list/app_list_shower_delegate_factory.h"
9#include "ash/app_list/app_list_view_delegate_factory.h"
[email protected]f3ab6eff52013-10-24 03:29:3810#include "ash/default_accessibility_delegate.h"
[email protected]a7611df2013-09-26 07:57:1011#include "ash/default_user_wallpaper_delegate.h"
[email protected]99edff3e2014-01-31 18:20:3612#include "ash/gpu_support_stub.h"
[email protected]efc897f72013-11-01 11:43:0713#include "ash/media_delegate.h"
[email protected]47686c42013-10-25 01:49:1714#include "ash/new_window_delegate.h"
[email protected]fdf74bf2014-04-30 21:24:0215#include "ash/session/session_state_delegate.h"
[email protected]565f32fc02013-03-05 18:51:4816#include "ash/shell/context_menu.h"
[email protected]262f8bd2012-03-23 19:30:2717#include "ash/shell/example_factory.h"
[email protected]8b57e942013-12-09 19:39:2018#include "ash/shell/shelf_delegate_impl.h"
[email protected]b77236f72012-03-25 03:07:1919#include "ash/shell/toplevel_window.h"
[email protected]262f8bd2012-03-23 19:30:2720#include "ash/shell_window_ids.h"
[email protected]9f19d5c2013-09-13 17:01:4821#include "ash/system/tray/default_system_tray_delegate.h"
ben974286a2015-10-10 00:45:1222#include "ash/test/test_keyboard_ui.h"
[email protected]a41b4e12013-09-20 04:36:3423#include "ash/wm/window_state.h"
mfomitchev493ed602016-04-09 00:48:3924#include "base/memory/ptr_util.h"
[email protected]9e3e6352013-07-17 04:07:5125#include "base/message_loop/message_loop.h"
[email protected]7009d9b2014-05-03 21:38:3626#include "base/strings/utf_string_conversions.h"
[email protected]d66eac42014-07-14 23:48:3027#include "components/user_manager/user_info_impl.h"
tapted537b88b12014-09-19 02:48:5228#include "ui/app_list/app_list_view_delegate.h"
mfomitchev493ed602016-04-09 00:48:3929#include "ui/app_list/shower/app_list_shower_impl.h"
[email protected]262f8bd2012-03-23 19:30:2730#include "ui/aura/window.h"
afakhrycd2bb98d2015-09-09 09:03:4231#include "ui/gfx/image/image.h"
ben93072442015-10-05 19:14:3232#include "ui/gfx/image/image_skia.h"
[email protected]262f8bd2012-03-23 19:30:2733
34namespace ash {
35namespace shell {
[email protected]47686c42013-10-25 01:49:1736namespace {
37
38class NewWindowDelegateImpl : public NewWindowDelegate {
39 public:
40 NewWindowDelegateImpl() {}
dchengf5963512014-10-28 01:14:1341 ~NewWindowDelegateImpl() override {}
[email protected]47686c42013-10-25 01:49:1742
[email protected]7009d9b2014-05-03 21:38:3643 // NewWindowDelegate:
dchengf5963512014-10-28 01:14:1344 void NewTab() override {}
45 void NewWindow(bool incognito) override {
[email protected]47686c42013-10-25 01:49:1746 ash::shell::ToplevelWindow::CreateParams create_params;
47 create_params.can_resize = true;
48 create_params.can_maximize = true;
49 ash::shell::ToplevelWindow::CreateToplevelWindow(create_params);
50 }
dchengf5963512014-10-28 01:14:1351 void OpenFileManager() override {}
52 void OpenCrosh() override {}
cyleeb6ce38f2015-01-08 12:25:3153 void OpenGetHelp() override {}
dchengf5963512014-10-28 01:14:1354 void RestoreTab() override {}
55 void ShowKeyboardOverlay() override {}
56 void ShowTaskManager() override {}
57 void OpenFeedbackPage() override {}
[email protected]47686c42013-10-25 01:49:1758
59 private:
60 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
61};
62
[email protected]efc897f72013-11-01 11:43:0763class MediaDelegateImpl : public MediaDelegate {
64 public:
65 MediaDelegateImpl() {}
dchengf5963512014-10-28 01:14:1366 ~MediaDelegateImpl() override {}
[email protected]efc897f72013-11-01 11:43:0767
[email protected]7009d9b2014-05-03 21:38:3668 // MediaDelegate:
dchengf5963512014-10-28 01:14:1369 void HandleMediaNextTrack() override {}
70 void HandleMediaPlayPause() override {}
71 void HandleMediaPrevTrack() override {}
ben93072442015-10-05 19:14:3272 MediaCaptureState GetMediaCaptureState(UserIndex index) override {
[email protected]7009d9b2014-05-03 21:38:3673 return MEDIA_CAPTURE_VIDEO;
74 }
[email protected]efc897f72013-11-01 11:43:0775
76 private:
77 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
78};
79
[email protected]7009d9b2014-05-03 21:38:3680class SessionStateDelegateImpl : public SessionStateDelegate {
81 public:
82 SessionStateDelegateImpl()
[email protected]d66eac42014-07-14 23:48:3083 : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
[email protected]7009d9b2014-05-03 21:38:3684
dchengf5963512014-10-28 01:14:1385 ~SessionStateDelegateImpl() override {}
[email protected]7009d9b2014-05-03 21:38:3686
87 // SessionStateDelegate:
dchengf5963512014-10-28 01:14:1388 int GetMaximumNumberOfLoggedInUsers() const override { return 3; }
89 int NumberOfLoggedInUsers() const override {
[email protected]7009d9b2014-05-03 21:38:3690 // ash_shell has 2 users.
91 return 2;
92 }
dchengf5963512014-10-28 01:14:1393 bool IsActiveUserSessionStarted() const override { return true; }
94 bool CanLockScreen() const override { return true; }
95 bool IsScreenLocked() const override { return screen_locked_; }
96 bool ShouldLockScreenBeforeSuspending() const override { return false; }
97 void LockScreen() override {
[email protected]7009d9b2014-05-03 21:38:3698 shell::CreateLockScreen();
99 screen_locked_ = true;
100 Shell::GetInstance()->UpdateShelfVisibility();
101 }
dchengf5963512014-10-28 01:14:13102 void UnlockScreen() override {
[email protected]7009d9b2014-05-03 21:38:36103 screen_locked_ = false;
104 Shell::GetInstance()->UpdateShelfVisibility();
105 }
dchengf5963512014-10-28 01:14:13106 bool IsUserSessionBlocked() const override {
[email protected]7009d9b2014-05-03 21:38:36107 return !IsActiveUserSessionStarted() || IsScreenLocked();
108 }
dchengf5963512014-10-28 01:14:13109 SessionState GetSessionState() const override {
[email protected]7009d9b2014-05-03 21:38:36110 // Assume that if session is not active we're at login.
111 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
112 : SESSION_STATE_LOGIN_PRIMARY;
113 }
ben93072442015-10-05 19:14:32114 const user_manager::UserInfo* GetUserInfo(UserIndex index) const override {
[email protected]7009d9b2014-05-03 21:38:36115 return user_info_.get();
116 }
dchengf5963512014-10-28 01:14:13117 bool ShouldShowAvatar(aura::Window* window) const override {
[email protected]7009d9b2014-05-03 21:38:36118 return !user_info_->GetImage().isNull();
119 }
ben93072442015-10-05 19:14:32120 gfx::ImageSkia GetAvatarImageForWindow(aura::Window* window) const override {
121 return gfx::ImageSkia();
122 }
alematecdf46dd2015-11-12 03:15:16123 void SwitchActiveUser(const AccountId& account_id) override {}
dchengf5963512014-10-28 01:14:13124 void CycleActiveUser(CycleUser cycle_user) override {}
125 bool IsMultiProfileAllowedByPrimaryUserPolicy() const override {
[email protected]815dfac92014-08-13 16:04:04126 return true;
127 }
dchengf5963512014-10-28 01:14:13128 void AddSessionStateObserver(ash::SessionStateObserver* observer) override {}
129 void RemoveSessionStateObserver(
mostynb10d6b382014-10-03 16:23:45130 ash::SessionStateObserver* observer) override {}
[email protected]7009d9b2014-05-03 21:38:36131
132 private:
133 bool screen_locked_;
134
135 // A pseudo user info.
dchenga94547472016-04-08 08:41:11136 std::unique_ptr<user_manager::UserInfo> user_info_;
[email protected]7009d9b2014-05-03 21:38:36137
138 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
139};
140
mfomitchev493ed602016-04-09 00:48:39141class AppListViewDelegateFactoryImpl : public ash::AppListViewDelegateFactory {
142 public:
143 AppListViewDelegateFactoryImpl() {}
144 ~AppListViewDelegateFactoryImpl() override {}
145
146 // app_list::AppListViewDelegateFactory:
147 app_list::AppListViewDelegate* GetDelegate() override {
148 if (!app_list_view_delegate_.get())
149 app_list_view_delegate_.reset(CreateAppListViewDelegate());
150 return app_list_view_delegate_.get();
151 }
152
153 private:
154 std::unique_ptr<app_list::AppListViewDelegate> app_list_view_delegate_;
155
156 DISALLOW_COPY_AND_ASSIGN(AppListViewDelegateFactoryImpl);
157};
158
[email protected]47686c42013-10-25 01:49:17159} // namespace
[email protected]262f8bd2012-03-23 19:30:27160
mfomitchev493ed602016-04-09 00:48:39161ShellDelegateImpl::ShellDelegateImpl()
162 : shelf_delegate_(nullptr),
163 app_list_shower_delegate_factory_(new AppListShowerDelegateFactory(
164 base::WrapUnique(new AppListViewDelegateFactoryImpl))) {}
[email protected]262f8bd2012-03-23 19:30:27165
mswc3cf79d2016-01-05 20:52:06166ShellDelegateImpl::~ShellDelegateImpl() {}
[email protected]262f8bd2012-03-23 19:30:27167
[email protected]5c85d5d2012-12-03 14:22:56168bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
[email protected]697f04c2012-10-03 01:15:10169 return false;
170}
171
[email protected]5ecf6122013-10-31 12:24:09172bool ShellDelegateImpl::IsIncognitoAllowed() const {
173 return true;
174}
175
[email protected]e718e6f2013-04-15 16:01:59176bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
177 return false;
178}
179
[email protected]565f32fc02013-03-05 18:51:48180bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
181 return false;
182}
183
ben894584d2015-09-30 23:56:53184bool ShellDelegateImpl::CanShowWindowForUser(aura::Window* window) const {
185 return true;
186}
187
peletskyida0bbb12015-04-08 17:11:04188bool ShellDelegateImpl::IsForceMaximizeOnFirstRun() const {
189 return false;
190}
191
[email protected]dcc990722013-03-24 16:35:20192void ShellDelegateImpl::PreInit() {
193}
194
[email protected]050e77182014-03-25 15:29:16195void ShellDelegateImpl::PreShutdown() {
[email protected]3528b7d2012-04-18 10:46:36196}
197
[email protected]262f8bd2012-03-23 19:30:27198void ShellDelegateImpl::Exit() {
sadruld3af96a2016-01-28 16:16:24199 base::MessageLoop::current()->QuitWhenIdle();
[email protected]262f8bd2012-03-23 19:30:27200}
201
ben974286a2015-10-10 00:45:12202keyboard::KeyboardUI* ShellDelegateImpl::CreateKeyboardUI() {
203 return new TestKeyboardUI;
[email protected]86459e2c2013-04-10 13:39:24204}
205
[email protected]40db36e2014-04-04 14:08:18206void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
207}
208
209void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
210 VirtualKeyboardStateObserver* observer) {
211}
212
213void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
214 VirtualKeyboardStateObserver* observer) {
215}
216
yusukes0b08bdbb2016-03-30 21:39:54217void ShellDelegateImpl::OpenUrl(const GURL& url) {}
218
mfomitchev493ed602016-04-09 00:48:39219app_list::AppListShower* ShellDelegateImpl::GetAppListShower() {
220 if (!app_list_shower_) {
221 app_list_shower_.reset(new app_list::AppListShowerImpl(
222 app_list_shower_delegate_factory_.get()));
223 }
224 return app_list_shower_.get();
[email protected]262f8bd2012-03-23 19:30:27225}
226
[email protected]8b57e942013-12-09 19:39:20227ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
mswc3cf79d2016-01-05 20:52:06228 shelf_delegate_ = new ShelfDelegateImpl();
[email protected]8b57e942013-12-09 19:39:20229 return shelf_delegate_;
[email protected]262f8bd2012-03-23 19:30:27230}
231
[email protected]51ed5992012-11-07 10:14:39232ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
[email protected]9f19d5c2013-09-13 17:01:48233 return new DefaultSystemTrayDelegate;
[email protected]262f8bd2012-03-23 19:30:27234}
235
236ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
[email protected]a7611df2013-09-26 07:57:10237 return new DefaultUserWallpaperDelegate();
[email protected]262f8bd2012-03-23 19:30:27238}
[email protected]4d7ce4352012-07-13 06:56:06239
[email protected]fcb123d2013-04-17 15:58:49240ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
[email protected]7009d9b2014-05-03 21:38:36241 return new SessionStateDelegateImpl;
[email protected]fcb123d2013-04-17 15:58:49242}
243
[email protected]f3ab6eff52013-10-24 03:29:38244ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
[email protected]093b8d642014-04-03 20:59:28245 return new DefaultAccessibilityDelegate;
[email protected]f3ab6eff52013-10-24 03:29:38246}
247
[email protected]47686c42013-10-25 01:49:17248ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
249 return new NewWindowDelegateImpl;
[email protected]c28853612012-05-31 22:43:44250}
[email protected]262f8bd2012-03-23 19:30:27251
[email protected]efc897f72013-11-01 11:43:07252ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
253 return new MediaDelegateImpl;
254}
255
[email protected]e0cfc7f2014-01-09 20:25:42256ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
msw953caf1f2016-03-18 00:33:29257 ash::Shelf* shelf,
msw141c6b22016-03-04 00:55:30258 const ash::ShelfItem* item) {
msw953caf1f2016-03-18 00:33:29259 return new ContextMenu(shelf);
[email protected]431552c2012-10-23 00:38:33260}
261
[email protected]99edff3e2014-01-31 18:20:36262GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
263 // Real GPU support depends on src/content, so just use a stub.
264 return new GPUSupportStub;
265}
266
[email protected]ed95e022013-04-11 04:03:32267base::string16 ShellDelegateImpl::GetProductName() const {
268 return base::string16();
[email protected]5673bf52013-02-01 06:14:24269}
270
afakhrycd2bb98d2015-09-09 09:03:42271gfx::Image ShellDelegateImpl::GetDeprecatedAcceleratorImage() const {
272 return gfx::Image();
273}
274
[email protected]262f8bd2012-03-23 19:30:27275} // namespace shell
276} // namespace ash