[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 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 | |||||
[email protected] | f3ab6eff5 | 2013-10-24 03:29:38 | [diff] [blame] | 7 | #include "ash/accessibility_delegate.h" |
mfomitchev | 493ed60 | 2016-04-09 00:48:39 | [diff] [blame^] | 8 | #include "ash/app_list/app_list_shower_delegate_factory.h" |
9 | #include "ash/app_list/app_list_view_delegate_factory.h" | ||||
[email protected] | f3ab6eff5 | 2013-10-24 03:29:38 | [diff] [blame] | 10 | #include "ash/default_accessibility_delegate.h" |
[email protected] | a7611df | 2013-09-26 07:57:10 | [diff] [blame] | 11 | #include "ash/default_user_wallpaper_delegate.h" |
[email protected] | 99edff3e | 2014-01-31 18:20:36 | [diff] [blame] | 12 | #include "ash/gpu_support_stub.h" |
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 13 | #include "ash/media_delegate.h" |
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 14 | #include "ash/new_window_delegate.h" |
[email protected] | fdf74bf | 2014-04-30 21:24:02 | [diff] [blame] | 15 | #include "ash/session/session_state_delegate.h" |
[email protected] | 565f32fc0 | 2013-03-05 18:51:48 | [diff] [blame] | 16 | #include "ash/shell/context_menu.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 17 | #include "ash/shell/example_factory.h" |
[email protected] | 8b57e94 | 2013-12-09 19:39:20 | [diff] [blame] | 18 | #include "ash/shell/shelf_delegate_impl.h" |
[email protected] | b77236f7 | 2012-03-25 03:07:19 | [diff] [blame] | 19 | #include "ash/shell/toplevel_window.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 20 | #include "ash/shell_window_ids.h" |
[email protected] | 9f19d5c | 2013-09-13 17:01:48 | [diff] [blame] | 21 | #include "ash/system/tray/default_system_tray_delegate.h" |
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 22 | #include "ash/test/test_keyboard_ui.h" |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 23 | #include "ash/wm/window_state.h" |
mfomitchev | 493ed60 | 2016-04-09 00:48:39 | [diff] [blame^] | 24 | #include "base/memory/ptr_util.h" |
[email protected] | 9e3e635 | 2013-07-17 04:07:51 | [diff] [blame] | 25 | #include "base/message_loop/message_loop.h" |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 26 | #include "base/strings/utf_string_conversions.h" |
[email protected] | d66eac4 | 2014-07-14 23:48:30 | [diff] [blame] | 27 | #include "components/user_manager/user_info_impl.h" |
tapted | 537b88b1 | 2014-09-19 02:48:52 | [diff] [blame] | 28 | #include "ui/app_list/app_list_view_delegate.h" |
mfomitchev | 493ed60 | 2016-04-09 00:48:39 | [diff] [blame^] | 29 | #include "ui/app_list/shower/app_list_shower_impl.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 30 | #include "ui/aura/window.h" |
afakhry | cd2bb98d | 2015-09-09 09:03:42 | [diff] [blame] | 31 | #include "ui/gfx/image/image.h" |
ben | 9307244 | 2015-10-05 19:14:32 | [diff] [blame] | 32 | #include "ui/gfx/image/image_skia.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 33 | |
34 | namespace ash { | ||||
35 | namespace shell { | ||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 36 | namespace { |
37 | |||||
38 | class NewWindowDelegateImpl : public NewWindowDelegate { | ||||
39 | public: | ||||
40 | NewWindowDelegateImpl() {} | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 41 | ~NewWindowDelegateImpl() override {} |
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 42 | |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 43 | // NewWindowDelegate: |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 44 | void NewTab() override {} |
45 | void NewWindow(bool incognito) override { | ||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 46 | 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 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 51 | void OpenFileManager() override {} |
52 | void OpenCrosh() override {} | ||||
cylee | b6ce38f | 2015-01-08 12:25:31 | [diff] [blame] | 53 | void OpenGetHelp() override {} |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 54 | void RestoreTab() override {} |
55 | void ShowKeyboardOverlay() override {} | ||||
56 | void ShowTaskManager() override {} | ||||
57 | void OpenFeedbackPage() override {} | ||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 58 | |
59 | private: | ||||
60 | DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl); | ||||
61 | }; | ||||
62 | |||||
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 63 | class MediaDelegateImpl : public MediaDelegate { |
64 | public: | ||||
65 | MediaDelegateImpl() {} | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 66 | ~MediaDelegateImpl() override {} |
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 67 | |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 68 | // MediaDelegate: |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 69 | void HandleMediaNextTrack() override {} |
70 | void HandleMediaPlayPause() override {} | ||||
71 | void HandleMediaPrevTrack() override {} | ||||
ben | 9307244 | 2015-10-05 19:14:32 | [diff] [blame] | 72 | MediaCaptureState GetMediaCaptureState(UserIndex index) override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 73 | return MEDIA_CAPTURE_VIDEO; |
74 | } | ||||
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 75 | |
76 | private: | ||||
77 | DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl); | ||||
78 | }; | ||||
79 | |||||
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 80 | class SessionStateDelegateImpl : public SessionStateDelegate { |
81 | public: | ||||
82 | SessionStateDelegateImpl() | ||||
[email protected] | d66eac4 | 2014-07-14 23:48:30 | [diff] [blame] | 83 | : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {} |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 84 | |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 85 | ~SessionStateDelegateImpl() override {} |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 86 | |
87 | // SessionStateDelegate: | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 88 | int GetMaximumNumberOfLoggedInUsers() const override { return 3; } |
89 | int NumberOfLoggedInUsers() const override { | ||||
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 90 | // ash_shell has 2 users. |
91 | return 2; | ||||
92 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 93 | 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] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 98 | shell::CreateLockScreen(); |
99 | screen_locked_ = true; | ||||
100 | Shell::GetInstance()->UpdateShelfVisibility(); | ||||
101 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 102 | void UnlockScreen() override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 103 | screen_locked_ = false; |
104 | Shell::GetInstance()->UpdateShelfVisibility(); | ||||
105 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 106 | bool IsUserSessionBlocked() const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 107 | return !IsActiveUserSessionStarted() || IsScreenLocked(); |
108 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 109 | SessionState GetSessionState() const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 110 | // Assume that if session is not active we're at login. |
111 | return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE | ||||
112 | : SESSION_STATE_LOGIN_PRIMARY; | ||||
113 | } | ||||
ben | 9307244 | 2015-10-05 19:14:32 | [diff] [blame] | 114 | const user_manager::UserInfo* GetUserInfo(UserIndex index) const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 115 | return user_info_.get(); |
116 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 117 | bool ShouldShowAvatar(aura::Window* window) const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 118 | return !user_info_->GetImage().isNull(); |
119 | } | ||||
ben | 9307244 | 2015-10-05 19:14:32 | [diff] [blame] | 120 | gfx::ImageSkia GetAvatarImageForWindow(aura::Window* window) const override { |
121 | return gfx::ImageSkia(); | ||||
122 | } | ||||
alemate | cdf46dd | 2015-11-12 03:15:16 | [diff] [blame] | 123 | void SwitchActiveUser(const AccountId& account_id) override {} |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 124 | void CycleActiveUser(CycleUser cycle_user) override {} |
125 | bool IsMultiProfileAllowedByPrimaryUserPolicy() const override { | ||||
[email protected] | 815dfac9 | 2014-08-13 16:04:04 | [diff] [blame] | 126 | return true; |
127 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 128 | void AddSessionStateObserver(ash::SessionStateObserver* observer) override {} |
129 | void RemoveSessionStateObserver( | ||||
mostynb | 10d6b38 | 2014-10-03 16:23:45 | [diff] [blame] | 130 | ash::SessionStateObserver* observer) override {} |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 131 | |
132 | private: | ||||
133 | bool screen_locked_; | ||||
134 | |||||
135 | // A pseudo user info. | ||||
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 136 | std::unique_ptr<user_manager::UserInfo> user_info_; |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 137 | |
138 | DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl); | ||||
139 | }; | ||||
140 | |||||
mfomitchev | 493ed60 | 2016-04-09 00:48:39 | [diff] [blame^] | 141 | class 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] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 159 | } // namespace |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 160 | |
mfomitchev | 493ed60 | 2016-04-09 00:48:39 | [diff] [blame^] | 161 | ShellDelegateImpl::ShellDelegateImpl() |
162 | : shelf_delegate_(nullptr), | ||||
163 | app_list_shower_delegate_factory_(new AppListShowerDelegateFactory( | ||||
164 | base::WrapUnique(new AppListViewDelegateFactoryImpl))) {} | ||||
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 165 | |
msw | c3cf79d | 2016-01-05 20:52:06 | [diff] [blame] | 166 | ShellDelegateImpl::~ShellDelegateImpl() {} |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 167 | |
[email protected] | 5c85d5d | 2012-12-03 14:22:56 | [diff] [blame] | 168 | bool ShellDelegateImpl::IsFirstRunAfterBoot() const { |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 169 | return false; |
170 | } | ||||
171 | |||||
[email protected] | 5ecf612 | 2013-10-31 12:24:09 | [diff] [blame] | 172 | bool ShellDelegateImpl::IsIncognitoAllowed() const { |
173 | return true; | ||||
174 | } | ||||
175 | |||||
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 176 | bool ShellDelegateImpl::IsMultiProfilesEnabled() const { |
177 | return false; | ||||
178 | } | ||||
179 | |||||
[email protected] | 565f32fc0 | 2013-03-05 18:51:48 | [diff] [blame] | 180 | bool ShellDelegateImpl::IsRunningInForcedAppMode() const { |
181 | return false; | ||||
182 | } | ||||
183 | |||||
ben | 894584d | 2015-09-30 23:56:53 | [diff] [blame] | 184 | bool ShellDelegateImpl::CanShowWindowForUser(aura::Window* window) const { |
185 | return true; | ||||
186 | } | ||||
187 | |||||
peletskyi | da0bbb1 | 2015-04-08 17:11:04 | [diff] [blame] | 188 | bool ShellDelegateImpl::IsForceMaximizeOnFirstRun() const { |
189 | return false; | ||||
190 | } | ||||
191 | |||||
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 192 | void ShellDelegateImpl::PreInit() { |
193 | } | ||||
194 | |||||
[email protected] | 050e7718 | 2014-03-25 15:29:16 | [diff] [blame] | 195 | void ShellDelegateImpl::PreShutdown() { |
[email protected] | 3528b7d | 2012-04-18 10:46:36 | [diff] [blame] | 196 | } |
197 | |||||
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 198 | void ShellDelegateImpl::Exit() { |
sadrul | d3af96a | 2016-01-28 16:16:24 | [diff] [blame] | 199 | base::MessageLoop::current()->QuitWhenIdle(); |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 200 | } |
201 | |||||
ben | 974286a | 2015-10-10 00:45:12 | [diff] [blame] | 202 | keyboard::KeyboardUI* ShellDelegateImpl::CreateKeyboardUI() { |
203 | return new TestKeyboardUI; | ||||
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 204 | } |
205 | |||||
[email protected] | 40db36e | 2014-04-04 14:08:18 | [diff] [blame] | 206 | void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) { |
207 | } | ||||
208 | |||||
209 | void ShellDelegateImpl::AddVirtualKeyboardStateObserver( | ||||
210 | VirtualKeyboardStateObserver* observer) { | ||||
211 | } | ||||
212 | |||||
213 | void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver( | ||||
214 | VirtualKeyboardStateObserver* observer) { | ||||
215 | } | ||||
216 | |||||
yusukes | 0b08bdbb | 2016-03-30 21:39:54 | [diff] [blame] | 217 | void ShellDelegateImpl::OpenUrl(const GURL& url) {} |
218 | |||||
mfomitchev | 493ed60 | 2016-04-09 00:48:39 | [diff] [blame^] | 219 | app_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] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 225 | } |
226 | |||||
[email protected] | 8b57e94 | 2013-12-09 19:39:20 | [diff] [blame] | 227 | ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) { |
msw | c3cf79d | 2016-01-05 20:52:06 | [diff] [blame] | 228 | shelf_delegate_ = new ShelfDelegateImpl(); |
[email protected] | 8b57e94 | 2013-12-09 19:39:20 | [diff] [blame] | 229 | return shelf_delegate_; |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 230 | } |
231 | |||||
[email protected] | 51ed599 | 2012-11-07 10:14:39 | [diff] [blame] | 232 | ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() { |
[email protected] | 9f19d5c | 2013-09-13 17:01:48 | [diff] [blame] | 233 | return new DefaultSystemTrayDelegate; |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 234 | } |
235 | |||||
236 | ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() { | ||||
[email protected] | a7611df | 2013-09-26 07:57:10 | [diff] [blame] | 237 | return new DefaultUserWallpaperDelegate(); |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 238 | } |
[email protected] | 4d7ce435 | 2012-07-13 06:56:06 | [diff] [blame] | 239 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 240 | ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 241 | return new SessionStateDelegateImpl; |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 242 | } |
243 | |||||
[email protected] | f3ab6eff5 | 2013-10-24 03:29:38 | [diff] [blame] | 244 | ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 245 | return new DefaultAccessibilityDelegate; |
[email protected] | f3ab6eff5 | 2013-10-24 03:29:38 | [diff] [blame] | 246 | } |
247 | |||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 248 | ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() { |
249 | return new NewWindowDelegateImpl; | ||||
[email protected] | c2885361 | 2012-05-31 22:43:44 | [diff] [blame] | 250 | } |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 251 | |
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 252 | ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() { |
253 | return new MediaDelegateImpl; | ||||
254 | } | ||||
255 | |||||
[email protected] | e0cfc7f | 2014-01-09 20:25:42 | [diff] [blame] | 256 | ui::MenuModel* ShellDelegateImpl::CreateContextMenu( |
msw | 953caf1f | 2016-03-18 00:33:29 | [diff] [blame] | 257 | ash::Shelf* shelf, |
msw | 141c6b2 | 2016-03-04 00:55:30 | [diff] [blame] | 258 | const ash::ShelfItem* item) { |
msw | 953caf1f | 2016-03-18 00:33:29 | [diff] [blame] | 259 | return new ContextMenu(shelf); |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 260 | } |
261 | |||||
[email protected] | 99edff3e | 2014-01-31 18:20:36 | [diff] [blame] | 262 | GPUSupport* ShellDelegateImpl::CreateGPUSupport() { |
263 | // Real GPU support depends on src/content, so just use a stub. | ||||
264 | return new GPUSupportStub; | ||||
265 | } | ||||
266 | |||||
[email protected] | ed95e02 | 2013-04-11 04:03:32 | [diff] [blame] | 267 | base::string16 ShellDelegateImpl::GetProductName() const { |
268 | return base::string16(); | ||||
[email protected] | 5673bf5 | 2013-02-01 06:14:24 | [diff] [blame] | 269 | } |
270 | |||||
afakhry | cd2bb98d | 2015-09-09 09:03:42 | [diff] [blame] | 271 | gfx::Image ShellDelegateImpl::GetDeprecatedAcceleratorImage() const { |
272 | return gfx::Image(); | ||||
273 | } | ||||
274 | |||||
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 275 | } // namespace shell |
276 | } // namespace ash |