Add Search Service in Enhanced Bookmark Bridge
[chromium-blink-merge.git] / ash / shell / shell_delegate_impl.cc
blobc9de8850a283378b14731f82112bce868d13638b
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.
5 #include "ash/shell/shell_delegate_impl.h"
7 #include "ash/accessibility_delegate.h"
8 #include "ash/default_accessibility_delegate.h"
9 #include "ash/default_user_wallpaper_delegate.h"
10 #include "ash/gpu_support_stub.h"
11 #include "ash/media_delegate.h"
12 #include "ash/new_window_delegate.h"
13 #include "ash/session/session_state_delegate.h"
14 #include "ash/shell/context_menu.h"
15 #include "ash/shell/example_factory.h"
16 #include "ash/shell/keyboard_controller_proxy_stub.h"
17 #include "ash/shell/shelf_delegate_impl.h"
18 #include "ash/shell/toplevel_window.h"
19 #include "ash/shell_window_ids.h"
20 #include "ash/system/tray/default_system_tray_delegate.h"
21 #include "ash/wm/window_state.h"
22 #include "base/message_loop/message_loop.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "components/user_manager/user_info_impl.h"
25 #include "ui/app_list/app_list_view_delegate.h"
26 #include "ui/aura/window.h"
27 #include "ui/wm/core/input_method_event_filter.h"
29 namespace ash {
30 namespace shell {
31 namespace {
33 class NewWindowDelegateImpl : public NewWindowDelegate {
34 public:
35 NewWindowDelegateImpl() {}
36 ~NewWindowDelegateImpl() override {}
38 // NewWindowDelegate:
39 void NewTab() override {}
40 void NewWindow(bool incognito) override {
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);
46 void OpenFileManager() override {}
47 void OpenCrosh() override {}
48 void RestoreTab() override {}
49 void ShowKeyboardOverlay() override {}
50 void ShowTaskManager() override {}
51 void OpenFeedbackPage() override {}
53 private:
54 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
57 class MediaDelegateImpl : public MediaDelegate {
58 public:
59 MediaDelegateImpl() {}
60 ~MediaDelegateImpl() override {}
62 // MediaDelegate:
63 void HandleMediaNextTrack() override {}
64 void HandleMediaPlayPause() override {}
65 void HandleMediaPrevTrack() override {}
66 MediaCaptureState GetMediaCaptureState(
67 content::BrowserContext* context) override {
68 return MEDIA_CAPTURE_VIDEO;
71 private:
72 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
75 class SessionStateDelegateImpl : public SessionStateDelegate {
76 public:
77 SessionStateDelegateImpl()
78 : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
80 ~SessionStateDelegateImpl() override {}
82 // SessionStateDelegate:
83 content::BrowserContext* GetBrowserContextByIndex(
84 MultiProfileIndex index) override {
85 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
87 content::BrowserContext* GetBrowserContextForWindow(
88 aura::Window* window) override {
89 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
91 int GetMaximumNumberOfLoggedInUsers() const override { return 3; }
92 int NumberOfLoggedInUsers() const override {
93 // ash_shell has 2 users.
94 return 2;
96 bool IsActiveUserSessionStarted() const override { return true; }
97 bool CanLockScreen() const override { return true; }
98 bool IsScreenLocked() const override { return screen_locked_; }
99 bool ShouldLockScreenBeforeSuspending() const override { return false; }
100 void LockScreen() override {
101 shell::CreateLockScreen();
102 screen_locked_ = true;
103 Shell::GetInstance()->UpdateShelfVisibility();
105 void UnlockScreen() override {
106 screen_locked_ = false;
107 Shell::GetInstance()->UpdateShelfVisibility();
109 bool IsUserSessionBlocked() const override {
110 return !IsActiveUserSessionStarted() || IsScreenLocked();
112 SessionState GetSessionState() const override {
113 // Assume that if session is not active we're at login.
114 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
115 : SESSION_STATE_LOGIN_PRIMARY;
117 const user_manager::UserInfo* GetUserInfo(
118 MultiProfileIndex index) const override {
119 return user_info_.get();
121 const user_manager::UserInfo* GetUserInfo(
122 content::BrowserContext* context) const override {
123 return user_info_.get();
125 bool ShouldShowAvatar(aura::Window* window) const override {
126 return !user_info_->GetImage().isNull();
128 void SwitchActiveUser(const std::string& user_id) override {}
129 void CycleActiveUser(CycleUser cycle_user) override {}
130 bool IsMultiProfileAllowedByPrimaryUserPolicy() const override {
131 return true;
133 void AddSessionStateObserver(ash::SessionStateObserver* observer) override {}
134 void RemoveSessionStateObserver(
135 ash::SessionStateObserver* observer) override {}
137 private:
138 bool screen_locked_;
140 // A pseudo user info.
141 scoped_ptr<user_manager::UserInfo> user_info_;
143 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
146 } // namespace
148 ShellDelegateImpl::ShellDelegateImpl()
149 : watcher_(NULL),
150 shelf_delegate_(NULL),
151 browser_context_(NULL) {
154 ShellDelegateImpl::~ShellDelegateImpl() {
157 void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
158 watcher_ = watcher;
159 if (shelf_delegate_)
160 shelf_delegate_->set_watcher(watcher);
163 bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
164 return false;
167 bool ShellDelegateImpl::IsIncognitoAllowed() const {
168 return true;
171 bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
172 return false;
175 bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
176 return false;
179 bool ShellDelegateImpl::IsMultiAccountEnabled() const {
180 return false;
183 void ShellDelegateImpl::PreInit() {
186 void ShellDelegateImpl::PreShutdown() {
189 void ShellDelegateImpl::Exit() {
190 base::MessageLoopForUI::current()->Quit();
193 keyboard::KeyboardControllerProxy*
194 ShellDelegateImpl::CreateKeyboardControllerProxy() {
195 return new KeyboardControllerProxyStub();
198 void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
201 void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
202 VirtualKeyboardStateObserver* observer) {
205 void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
206 VirtualKeyboardStateObserver* observer) {
209 content::BrowserContext* ShellDelegateImpl::GetActiveBrowserContext() {
210 return browser_context_;
213 app_list::AppListViewDelegate* ShellDelegateImpl::GetAppListViewDelegate() {
214 if (!app_list_view_delegate_)
215 app_list_view_delegate_.reset(ash::shell::CreateAppListViewDelegate());
216 return app_list_view_delegate_.get();
219 ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
220 shelf_delegate_ = new ShelfDelegateImpl(watcher_);
221 return shelf_delegate_;
224 ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
225 return new DefaultSystemTrayDelegate;
228 ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
229 return new DefaultUserWallpaperDelegate();
232 ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
233 return new SessionStateDelegateImpl;
236 ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
237 return new DefaultAccessibilityDelegate;
240 ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
241 return new NewWindowDelegateImpl;
244 ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
245 return new MediaDelegateImpl;
248 ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
249 aura::Window* root,
250 ash::ShelfItemDelegate* item_delegate,
251 ash::ShelfItem* item) {
252 return new ContextMenu(root);
255 GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
256 // Real GPU support depends on src/content, so just use a stub.
257 return new GPUSupportStub;
260 base::string16 ShellDelegateImpl::GetProductName() const {
261 return base::string16();
264 } // namespace shell
265 } // namespace ash