[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" |
[email protected] | f3ab6eff5 | 2013-10-24 03:29:38 | [diff] [blame] | 8 | #include "ash/default_accessibility_delegate.h" |
[email protected] | a7611df | 2013-09-26 07:57:10 | [diff] [blame] | 9 | #include "ash/default_user_wallpaper_delegate.h" |
[email protected] | 99edff3e | 2014-01-31 18:20:36 | [diff] [blame] | 10 | #include "ash/gpu_support_stub.h" |
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 11 | #include "ash/media_delegate.h" |
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 12 | #include "ash/new_window_delegate.h" |
[email protected] | fdf74bf | 2014-04-30 21:24:02 | [diff] [blame] | 13 | #include "ash/session/session_state_delegate.h" |
[email protected] | 565f32fc0 | 2013-03-05 18:51:48 | [diff] [blame] | 14 | #include "ash/shell/context_menu.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 15 | #include "ash/shell/example_factory.h" |
[email protected] | 51f43811 | 2013-11-18 19:32:50 | [diff] [blame] | 16 | #include "ash/shell/keyboard_controller_proxy_stub.h" |
[email protected] | 8b57e94 | 2013-12-09 19:39:20 | [diff] [blame] | 17 | #include "ash/shell/shelf_delegate_impl.h" |
[email protected] | b77236f7 | 2012-03-25 03:07:19 | [diff] [blame] | 18 | #include "ash/shell/toplevel_window.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 19 | #include "ash/shell_window_ids.h" |
[email protected] | 9f19d5c | 2013-09-13 17:01:48 | [diff] [blame] | 20 | #include "ash/system/tray/default_system_tray_delegate.h" |
[email protected] | a41b4e1 | 2013-09-20 04:36:34 | [diff] [blame] | 21 | #include "ash/wm/window_state.h" |
[email protected] | 9e3e635 | 2013-07-17 04:07:51 | [diff] [blame] | 22 | #include "base/message_loop/message_loop.h" |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 23 | #include "base/strings/utf_string_conversions.h" |
[email protected] | d66eac4 | 2014-07-14 23:48:30 | [diff] [blame] | 24 | #include "components/user_manager/user_info_impl.h" |
tapted | 537b88b1 | 2014-09-19 02:48:52 | [diff] [blame] | 25 | #include "ui/app_list/app_list_view_delegate.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 26 | #include "ui/aura/window.h" |
[email protected] | ee3ed1077 | 2014-03-11 22:02:01 | [diff] [blame] | 27 | #include "ui/wm/core/input_method_event_filter.h" |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 28 | |
29 | namespace ash { | ||||
30 | namespace shell { | ||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 31 | namespace { |
32 | |||||
33 | class NewWindowDelegateImpl : public NewWindowDelegate { | ||||
34 | public: | ||||
35 | NewWindowDelegateImpl() {} | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 36 | ~NewWindowDelegateImpl() override {} |
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 37 | |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 38 | // NewWindowDelegate: |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 39 | void NewTab() override {} |
40 | void NewWindow(bool incognito) override { | ||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 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); | ||||
45 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 46 | void OpenFileManager() override {} |
47 | void OpenCrosh() override {} | ||||
cylee | b6ce38f | 2015-01-08 12:25:31 | [diff] [blame] | 48 | void OpenGetHelp() override {} |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 49 | void RestoreTab() override {} |
50 | void ShowKeyboardOverlay() override {} | ||||
51 | void ShowTaskManager() override {} | ||||
52 | void OpenFeedbackPage() override {} | ||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 53 | |
54 | private: | ||||
55 | DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl); | ||||
56 | }; | ||||
57 | |||||
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 58 | class MediaDelegateImpl : public MediaDelegate { |
59 | public: | ||||
60 | MediaDelegateImpl() {} | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 61 | ~MediaDelegateImpl() override {} |
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 62 | |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 63 | // MediaDelegate: |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 64 | void HandleMediaNextTrack() override {} |
65 | void HandleMediaPlayPause() override {} | ||||
66 | void HandleMediaPrevTrack() override {} | ||||
67 | MediaCaptureState GetMediaCaptureState( | ||||
mostynb | 10d6b38 | 2014-10-03 16:23:45 | [diff] [blame] | 68 | content::BrowserContext* context) override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 69 | return MEDIA_CAPTURE_VIDEO; |
70 | } | ||||
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 71 | |
72 | private: | ||||
73 | DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl); | ||||
74 | }; | ||||
75 | |||||
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 76 | class SessionStateDelegateImpl : public SessionStateDelegate { |
77 | public: | ||||
78 | SessionStateDelegateImpl() | ||||
[email protected] | d66eac4 | 2014-07-14 23:48:30 | [diff] [blame] | 79 | : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {} |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 80 | |
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 81 | ~SessionStateDelegateImpl() override {} |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 82 | |
83 | // SessionStateDelegate: | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 84 | content::BrowserContext* GetBrowserContextByIndex( |
mostynb | 10d6b38 | 2014-10-03 16:23:45 | [diff] [blame] | 85 | MultiProfileIndex index) override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 86 | return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); |
87 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 88 | content::BrowserContext* GetBrowserContextForWindow( |
mostynb | 10d6b38 | 2014-10-03 16:23:45 | [diff] [blame] | 89 | aura::Window* window) override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 90 | return Shell::GetInstance()->delegate()->GetActiveBrowserContext(); |
91 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 92 | int GetMaximumNumberOfLoggedInUsers() const override { return 3; } |
93 | int NumberOfLoggedInUsers() const override { | ||||
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 94 | // ash_shell has 2 users. |
95 | return 2; | ||||
96 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 97 | bool IsActiveUserSessionStarted() const override { return true; } |
98 | bool CanLockScreen() const override { return true; } | ||||
99 | bool IsScreenLocked() const override { return screen_locked_; } | ||||
100 | bool ShouldLockScreenBeforeSuspending() const override { return false; } | ||||
101 | void LockScreen() override { | ||||
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 102 | shell::CreateLockScreen(); |
103 | screen_locked_ = true; | ||||
104 | Shell::GetInstance()->UpdateShelfVisibility(); | ||||
105 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 106 | void UnlockScreen() override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 107 | screen_locked_ = false; |
108 | Shell::GetInstance()->UpdateShelfVisibility(); | ||||
109 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 110 | bool IsUserSessionBlocked() const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 111 | return !IsActiveUserSessionStarted() || IsScreenLocked(); |
112 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 113 | SessionState GetSessionState() const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 114 | // Assume that if session is not active we're at login. |
115 | return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE | ||||
116 | : SESSION_STATE_LOGIN_PRIMARY; | ||||
117 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 118 | const user_manager::UserInfo* GetUserInfo( |
mostynb | 10d6b38 | 2014-10-03 16:23:45 | [diff] [blame] | 119 | MultiProfileIndex index) const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 120 | return user_info_.get(); |
121 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 122 | const user_manager::UserInfo* GetUserInfo( |
mostynb | 10d6b38 | 2014-10-03 16:23:45 | [diff] [blame] | 123 | content::BrowserContext* context) const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 124 | return user_info_.get(); |
125 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 126 | bool ShouldShowAvatar(aura::Window* window) const override { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 127 | return !user_info_->GetImage().isNull(); |
128 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 129 | void SwitchActiveUser(const std::string& user_id) override {} |
130 | void CycleActiveUser(CycleUser cycle_user) override {} | ||||
131 | bool IsMultiProfileAllowedByPrimaryUserPolicy() const override { | ||||
[email protected] | 815dfac9 | 2014-08-13 16:04:04 | [diff] [blame] | 132 | return true; |
133 | } | ||||
dcheng | f596351 | 2014-10-28 01:14:13 | [diff] [blame] | 134 | void AddSessionStateObserver(ash::SessionStateObserver* observer) override {} |
135 | void RemoveSessionStateObserver( | ||||
mostynb | 10d6b38 | 2014-10-03 16:23:45 | [diff] [blame] | 136 | ash::SessionStateObserver* observer) override {} |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 137 | |
138 | private: | ||||
139 | bool screen_locked_; | ||||
140 | |||||
141 | // A pseudo user info. | ||||
[email protected] | d66eac4 | 2014-07-14 23:48:30 | [diff] [blame] | 142 | scoped_ptr<user_manager::UserInfo> user_info_; |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 143 | |
144 | DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl); | ||||
145 | }; | ||||
146 | |||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 147 | } // namespace |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 148 | |
149 | ShellDelegateImpl::ShellDelegateImpl() | ||||
150 | : watcher_(NULL), | ||||
[email protected] | 8b57e94 | 2013-12-09 19:39:20 | [diff] [blame] | 151 | shelf_delegate_(NULL), |
[email protected] | 17155b8 | 2013-11-08 22:57:32 | [diff] [blame] | 152 | browser_context_(NULL) { |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 153 | } |
154 | |||||
155 | ShellDelegateImpl::~ShellDelegateImpl() { | ||||
156 | } | ||||
157 | |||||
158 | void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) { | ||||
159 | watcher_ = watcher; | ||||
[email protected] | 8b57e94 | 2013-12-09 19:39:20 | [diff] [blame] | 160 | if (shelf_delegate_) |
161 | shelf_delegate_->set_watcher(watcher); | ||||
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 162 | } |
163 | |||||
[email protected] | 5c85d5d | 2012-12-03 14:22:56 | [diff] [blame] | 164 | bool ShellDelegateImpl::IsFirstRunAfterBoot() const { |
[email protected] | 697f04c | 2012-10-03 01:15:10 | [diff] [blame] | 165 | return false; |
166 | } | ||||
167 | |||||
[email protected] | 5ecf612 | 2013-10-31 12:24:09 | [diff] [blame] | 168 | bool ShellDelegateImpl::IsIncognitoAllowed() const { |
169 | return true; | ||||
170 | } | ||||
171 | |||||
[email protected] | e718e6f | 2013-04-15 16:01:59 | [diff] [blame] | 172 | bool ShellDelegateImpl::IsMultiProfilesEnabled() const { |
173 | return false; | ||||
174 | } | ||||
175 | |||||
[email protected] | 565f32fc0 | 2013-03-05 18:51:48 | [diff] [blame] | 176 | bool ShellDelegateImpl::IsRunningInForcedAppMode() const { |
177 | return false; | ||||
178 | } | ||||
179 | |||||
[email protected] | d7ffac7 | 2014-04-10 13:17:17 | [diff] [blame] | 180 | bool ShellDelegateImpl::IsMultiAccountEnabled() const { |
181 | return false; | ||||
182 | } | ||||
183 | |||||
peletskyi | da0bbb1 | 2015-04-08 17:11:04 | [diff] [blame^] | 184 | bool ShellDelegateImpl::IsForceMaximizeOnFirstRun() const { |
185 | return false; | ||||
186 | } | ||||
187 | |||||
[email protected] | dcc99072 | 2013-03-24 16:35:20 | [diff] [blame] | 188 | void ShellDelegateImpl::PreInit() { |
189 | } | ||||
190 | |||||
[email protected] | 050e7718 | 2014-03-25 15:29:16 | [diff] [blame] | 191 | void ShellDelegateImpl::PreShutdown() { |
[email protected] | 3528b7d | 2012-04-18 10:46:36 | [diff] [blame] | 192 | } |
193 | |||||
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 194 | void ShellDelegateImpl::Exit() { |
[email protected] | bd9a7f3 | 2013-04-30 20:25:42 | [diff] [blame] | 195 | base::MessageLoopForUI::current()->Quit(); |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 196 | } |
197 | |||||
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 198 | keyboard::KeyboardControllerProxy* |
199 | ShellDelegateImpl::CreateKeyboardControllerProxy() { | ||||
[email protected] | eff4c7f | 2013-08-13 01:45:50 | [diff] [blame] | 200 | return new KeyboardControllerProxyStub(); |
[email protected] | 86459e2c | 2013-04-10 13:39:24 | [diff] [blame] | 201 | } |
202 | |||||
[email protected] | 40db36e | 2014-04-04 14:08:18 | [diff] [blame] | 203 | void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) { |
204 | } | ||||
205 | |||||
206 | void ShellDelegateImpl::AddVirtualKeyboardStateObserver( | ||||
207 | VirtualKeyboardStateObserver* observer) { | ||||
208 | } | ||||
209 | |||||
210 | void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver( | ||||
211 | VirtualKeyboardStateObserver* observer) { | ||||
212 | } | ||||
213 | |||||
[email protected] | 97eb75a | 2013-12-12 23:43:50 | [diff] [blame] | 214 | content::BrowserContext* ShellDelegateImpl::GetActiveBrowserContext() { |
[email protected] | 17155b8 | 2013-11-08 22:57:32 | [diff] [blame] | 215 | return browser_context_; |
[email protected] | 24af497 | 2012-05-04 19:42:18 | [diff] [blame] | 216 | } |
217 | |||||
tapted | 537b88b1 | 2014-09-19 02:48:52 | [diff] [blame] | 218 | app_list::AppListViewDelegate* ShellDelegateImpl::GetAppListViewDelegate() { |
219 | if (!app_list_view_delegate_) | ||||
220 | app_list_view_delegate_.reset(ash::shell::CreateAppListViewDelegate()); | ||||
221 | return app_list_view_delegate_.get(); | ||||
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 222 | } |
223 | |||||
[email protected] | 8b57e94 | 2013-12-09 19:39:20 | [diff] [blame] | 224 | ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) { |
225 | shelf_delegate_ = new ShelfDelegateImpl(watcher_); | ||||
226 | return shelf_delegate_; | ||||
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 227 | } |
228 | |||||
[email protected] | 51ed599 | 2012-11-07 10:14:39 | [diff] [blame] | 229 | ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() { |
[email protected] | 9f19d5c | 2013-09-13 17:01:48 | [diff] [blame] | 230 | return new DefaultSystemTrayDelegate; |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 231 | } |
232 | |||||
233 | ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() { | ||||
[email protected] | a7611df | 2013-09-26 07:57:10 | [diff] [blame] | 234 | return new DefaultUserWallpaperDelegate(); |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 235 | } |
[email protected] | 4d7ce435 | 2012-07-13 06:56:06 | [diff] [blame] | 236 | |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 237 | ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() { |
[email protected] | 7009d9b | 2014-05-03 21:38:36 | [diff] [blame] | 238 | return new SessionStateDelegateImpl; |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 239 | } |
240 | |||||
[email protected] | f3ab6eff5 | 2013-10-24 03:29:38 | [diff] [blame] | 241 | ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() { |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 242 | return new DefaultAccessibilityDelegate; |
[email protected] | f3ab6eff5 | 2013-10-24 03:29:38 | [diff] [blame] | 243 | } |
244 | |||||
[email protected] | 47686c4 | 2013-10-25 01:49:17 | [diff] [blame] | 245 | ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() { |
246 | return new NewWindowDelegateImpl; | ||||
[email protected] | c2885361 | 2012-05-31 22:43:44 | [diff] [blame] | 247 | } |
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 248 | |
[email protected] | efc897f7 | 2013-11-01 11:43:07 | [diff] [blame] | 249 | ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() { |
250 | return new MediaDelegateImpl; | ||||
251 | } | ||||
252 | |||||
[email protected] | e0cfc7f | 2014-01-09 20:25:42 | [diff] [blame] | 253 | ui::MenuModel* ShellDelegateImpl::CreateContextMenu( |
254 | aura::Window* root, | ||||
255 | ash::ShelfItemDelegate* item_delegate, | ||||
[email protected] | eec097142 | 2014-02-03 23:51:27 | [diff] [blame] | 256 | ash::ShelfItem* item) { |
[email protected] | 431552c | 2012-10-23 00:38:33 | [diff] [blame] | 257 | return new ContextMenu(root); |
258 | } | ||||
259 | |||||
[email protected] | 99edff3e | 2014-01-31 18:20:36 | [diff] [blame] | 260 | GPUSupport* ShellDelegateImpl::CreateGPUSupport() { |
261 | // Real GPU support depends on src/content, so just use a stub. | ||||
262 | return new GPUSupportStub; | ||||
263 | } | ||||
264 | |||||
[email protected] | ed95e02 | 2013-04-11 04:03:32 | [diff] [blame] | 265 | base::string16 ShellDelegateImpl::GetProductName() const { |
266 | return base::string16(); | ||||
[email protected] | 5673bf5 | 2013-02-01 06:14:24 | [diff] [blame] | 267 | } |
268 | |||||
[email protected] | 262f8bd | 2012-03-23 19:30:27 | [diff] [blame] | 269 | } // namespace shell |
270 | } // namespace ash |