blob: 4af993a30e347c5b7a2a1fccc5d72e716b35d299 [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"
[email protected]565f32fc02013-03-05 18:51:4814#include "ash/shell/context_menu.h"
[email protected]262f8bd2012-03-23 19:30:2715#include "ash/shell/example_factory.h"
[email protected]51f438112013-11-18 19:32:5016#include "ash/shell/keyboard_controller_proxy_stub.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"
[email protected]a41b4e12013-09-20 04:36:3421#include "ash/wm/window_state.h"
[email protected]9e3e6352013-07-17 04:07:5122#include "base/message_loop/message_loop.h"
[email protected]7009d9b2014-05-03 21:38:3623#include "base/strings/utf_string_conversions.h"
[email protected]d66eac42014-07-14 23:48:3024#include "components/user_manager/user_info_impl.h"
tapted537b88b12014-09-19 02:48:5225#include "ui/app_list/app_list_view_delegate.h"
[email protected]262f8bd2012-03-23 19:30:2726#include "ui/aura/window.h"
[email protected]ee3ed10772014-03-11 22:02:0127#include "ui/wm/core/input_method_event_filter.h"
[email protected]262f8bd2012-03-23 19:30:2728
29namespace ash {
30namespace shell {
[email protected]47686c42013-10-25 01:49:1731namespace {
32
33class NewWindowDelegateImpl : public NewWindowDelegate {
34 public:
35 NewWindowDelegateImpl() {}
dchengf5963512014-10-28 01:14:1336 ~NewWindowDelegateImpl() override {}
[email protected]47686c42013-10-25 01:49:1737
[email protected]7009d9b2014-05-03 21:38:3638 // NewWindowDelegate:
dchengf5963512014-10-28 01:14:1339 void NewTab() override {}
40 void NewWindow(bool incognito) override {
[email protected]47686c42013-10-25 01:49:1741 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 }
dchengf5963512014-10-28 01:14:1346 void OpenFileManager() override {}
47 void OpenCrosh() override {}
cyleeb6ce38f2015-01-08 12:25:3148 void OpenGetHelp() override {}
dchengf5963512014-10-28 01:14:1349 void RestoreTab() override {}
50 void ShowKeyboardOverlay() override {}
51 void ShowTaskManager() override {}
52 void OpenFeedbackPage() override {}
[email protected]47686c42013-10-25 01:49:1753
54 private:
55 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
56};
57
[email protected]efc897f72013-11-01 11:43:0758class MediaDelegateImpl : public MediaDelegate {
59 public:
60 MediaDelegateImpl() {}
dchengf5963512014-10-28 01:14:1361 ~MediaDelegateImpl() override {}
[email protected]efc897f72013-11-01 11:43:0762
[email protected]7009d9b2014-05-03 21:38:3663 // MediaDelegate:
dchengf5963512014-10-28 01:14:1364 void HandleMediaNextTrack() override {}
65 void HandleMediaPlayPause() override {}
66 void HandleMediaPrevTrack() override {}
67 MediaCaptureState GetMediaCaptureState(
mostynb10d6b382014-10-03 16:23:4568 content::BrowserContext* context) override {
[email protected]7009d9b2014-05-03 21:38:3669 return MEDIA_CAPTURE_VIDEO;
70 }
[email protected]efc897f72013-11-01 11:43:0771
72 private:
73 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
74};
75
[email protected]7009d9b2014-05-03 21:38:3676class SessionStateDelegateImpl : public SessionStateDelegate {
77 public:
78 SessionStateDelegateImpl()
[email protected]d66eac42014-07-14 23:48:3079 : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
[email protected]7009d9b2014-05-03 21:38:3680
dchengf5963512014-10-28 01:14:1381 ~SessionStateDelegateImpl() override {}
[email protected]7009d9b2014-05-03 21:38:3682
83 // SessionStateDelegate:
dchengf5963512014-10-28 01:14:1384 content::BrowserContext* GetBrowserContextByIndex(
mostynb10d6b382014-10-03 16:23:4585 MultiProfileIndex index) override {
[email protected]7009d9b2014-05-03 21:38:3686 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
87 }
dchengf5963512014-10-28 01:14:1388 content::BrowserContext* GetBrowserContextForWindow(
mostynb10d6b382014-10-03 16:23:4589 aura::Window* window) override {
[email protected]7009d9b2014-05-03 21:38:3690 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
91 }
dchengf5963512014-10-28 01:14:1392 int GetMaximumNumberOfLoggedInUsers() const override { return 3; }
93 int NumberOfLoggedInUsers() const override {
[email protected]7009d9b2014-05-03 21:38:3694 // ash_shell has 2 users.
95 return 2;
96 }
dchengf5963512014-10-28 01:14:1397 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]7009d9b2014-05-03 21:38:36102 shell::CreateLockScreen();
103 screen_locked_ = true;
104 Shell::GetInstance()->UpdateShelfVisibility();
105 }
dchengf5963512014-10-28 01:14:13106 void UnlockScreen() override {
[email protected]7009d9b2014-05-03 21:38:36107 screen_locked_ = false;
108 Shell::GetInstance()->UpdateShelfVisibility();
109 }
dchengf5963512014-10-28 01:14:13110 bool IsUserSessionBlocked() const override {
[email protected]7009d9b2014-05-03 21:38:36111 return !IsActiveUserSessionStarted() || IsScreenLocked();
112 }
dchengf5963512014-10-28 01:14:13113 SessionState GetSessionState() const override {
[email protected]7009d9b2014-05-03 21:38:36114 // Assume that if session is not active we're at login.
115 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
116 : SESSION_STATE_LOGIN_PRIMARY;
117 }
dchengf5963512014-10-28 01:14:13118 const user_manager::UserInfo* GetUserInfo(
mostynb10d6b382014-10-03 16:23:45119 MultiProfileIndex index) const override {
[email protected]7009d9b2014-05-03 21:38:36120 return user_info_.get();
121 }
dchengf5963512014-10-28 01:14:13122 const user_manager::UserInfo* GetUserInfo(
mostynb10d6b382014-10-03 16:23:45123 content::BrowserContext* context) const override {
[email protected]7009d9b2014-05-03 21:38:36124 return user_info_.get();
125 }
dchengf5963512014-10-28 01:14:13126 bool ShouldShowAvatar(aura::Window* window) const override {
[email protected]7009d9b2014-05-03 21:38:36127 return !user_info_->GetImage().isNull();
128 }
dchengf5963512014-10-28 01:14:13129 void SwitchActiveUser(const std::string& user_id) override {}
130 void CycleActiveUser(CycleUser cycle_user) override {}
131 bool IsMultiProfileAllowedByPrimaryUserPolicy() const override {
[email protected]815dfac92014-08-13 16:04:04132 return true;
133 }
dchengf5963512014-10-28 01:14:13134 void AddSessionStateObserver(ash::SessionStateObserver* observer) override {}
135 void RemoveSessionStateObserver(
mostynb10d6b382014-10-03 16:23:45136 ash::SessionStateObserver* observer) override {}
[email protected]7009d9b2014-05-03 21:38:36137
138 private:
139 bool screen_locked_;
140
141 // A pseudo user info.
[email protected]d66eac42014-07-14 23:48:30142 scoped_ptr<user_manager::UserInfo> user_info_;
[email protected]7009d9b2014-05-03 21:38:36143
144 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
145};
146
[email protected]47686c42013-10-25 01:49:17147} // namespace
[email protected]262f8bd2012-03-23 19:30:27148
149ShellDelegateImpl::ShellDelegateImpl()
150 : watcher_(NULL),
[email protected]8b57e942013-12-09 19:39:20151 shelf_delegate_(NULL),
[email protected]17155b82013-11-08 22:57:32152 browser_context_(NULL) {
[email protected]262f8bd2012-03-23 19:30:27153}
154
155ShellDelegateImpl::~ShellDelegateImpl() {
156}
157
158void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
159 watcher_ = watcher;
[email protected]8b57e942013-12-09 19:39:20160 if (shelf_delegate_)
161 shelf_delegate_->set_watcher(watcher);
[email protected]262f8bd2012-03-23 19:30:27162}
163
[email protected]5c85d5d2012-12-03 14:22:56164bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
[email protected]697f04c2012-10-03 01:15:10165 return false;
166}
167
[email protected]5ecf6122013-10-31 12:24:09168bool ShellDelegateImpl::IsIncognitoAllowed() const {
169 return true;
170}
171
[email protected]e718e6f2013-04-15 16:01:59172bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
173 return false;
174}
175
[email protected]565f32fc02013-03-05 18:51:48176bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
177 return false;
178}
179
[email protected]d7ffac72014-04-10 13:17:17180bool ShellDelegateImpl::IsMultiAccountEnabled() const {
181 return false;
182}
183
peletskyida0bbb12015-04-08 17:11:04184bool ShellDelegateImpl::IsForceMaximizeOnFirstRun() const {
185 return false;
186}
187
[email protected]dcc990722013-03-24 16:35:20188void ShellDelegateImpl::PreInit() {
189}
190
[email protected]050e77182014-03-25 15:29:16191void ShellDelegateImpl::PreShutdown() {
[email protected]3528b7d2012-04-18 10:46:36192}
193
[email protected]262f8bd2012-03-23 19:30:27194void ShellDelegateImpl::Exit() {
[email protected]bd9a7f32013-04-30 20:25:42195 base::MessageLoopForUI::current()->Quit();
[email protected]262f8bd2012-03-23 19:30:27196}
197
[email protected]86459e2c2013-04-10 13:39:24198keyboard::KeyboardControllerProxy*
199 ShellDelegateImpl::CreateKeyboardControllerProxy() {
[email protected]eff4c7f2013-08-13 01:45:50200 return new KeyboardControllerProxyStub();
[email protected]86459e2c2013-04-10 13:39:24201}
202
[email protected]40db36e2014-04-04 14:08:18203void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
204}
205
206void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
207 VirtualKeyboardStateObserver* observer) {
208}
209
210void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
211 VirtualKeyboardStateObserver* observer) {
212}
213
[email protected]97eb75a2013-12-12 23:43:50214content::BrowserContext* ShellDelegateImpl::GetActiveBrowserContext() {
[email protected]17155b82013-11-08 22:57:32215 return browser_context_;
[email protected]24af4972012-05-04 19:42:18216}
217
tapted537b88b12014-09-19 02:48:52218app_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]262f8bd2012-03-23 19:30:27222}
223
[email protected]8b57e942013-12-09 19:39:20224ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
225 shelf_delegate_ = new ShelfDelegateImpl(watcher_);
226 return shelf_delegate_;
[email protected]262f8bd2012-03-23 19:30:27227}
228
[email protected]51ed5992012-11-07 10:14:39229ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
[email protected]9f19d5c2013-09-13 17:01:48230 return new DefaultSystemTrayDelegate;
[email protected]262f8bd2012-03-23 19:30:27231}
232
233ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
[email protected]a7611df2013-09-26 07:57:10234 return new DefaultUserWallpaperDelegate();
[email protected]262f8bd2012-03-23 19:30:27235}
[email protected]4d7ce4352012-07-13 06:56:06236
[email protected]fcb123d2013-04-17 15:58:49237ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
[email protected]7009d9b2014-05-03 21:38:36238 return new SessionStateDelegateImpl;
[email protected]fcb123d2013-04-17 15:58:49239}
240
[email protected]f3ab6eff52013-10-24 03:29:38241ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
[email protected]093b8d642014-04-03 20:59:28242 return new DefaultAccessibilityDelegate;
[email protected]f3ab6eff52013-10-24 03:29:38243}
244
[email protected]47686c42013-10-25 01:49:17245ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
246 return new NewWindowDelegateImpl;
[email protected]c28853612012-05-31 22:43:44247}
[email protected]262f8bd2012-03-23 19:30:27248
[email protected]efc897f72013-11-01 11:43:07249ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
250 return new MediaDelegateImpl;
251}
252
[email protected]e0cfc7f2014-01-09 20:25:42253ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
254 aura::Window* root,
255 ash::ShelfItemDelegate* item_delegate,
[email protected]eec0971422014-02-03 23:51:27256 ash::ShelfItem* item) {
[email protected]431552c2012-10-23 00:38:33257 return new ContextMenu(root);
258}
259
[email protected]99edff3e2014-01-31 18:20:36260GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
261 // Real GPU support depends on src/content, so just use a stub.
262 return new GPUSupportStub;
263}
264
[email protected]ed95e022013-04-11 04:03:32265base::string16 ShellDelegateImpl::GetProductName() const {
266 return base::string16();
[email protected]5673bf52013-02-01 06:14:24267}
268
[email protected]262f8bd2012-03-23 19:30:27269} // namespace shell
270} // namespace ash