Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / ash / shell / shell_delegate_impl.cc
blob289d769c9c26a658e3ff9ce2f4245db520f2a242
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/session/user_info.h"
15 #include "ash/shell/context_menu.h"
16 #include "ash/shell/example_factory.h"
17 #include "ash/shell/keyboard_controller_proxy_stub.h"
18 #include "ash/shell/shelf_delegate_impl.h"
19 #include "ash/shell/toplevel_window.h"
20 #include "ash/shell_window_ids.h"
21 #include "ash/system/tray/default_system_tray_delegate.h"
22 #include "ash/wm/window_state.h"
23 #include "base/message_loop/message_loop.h"
24 #include "base/strings/utf_string_conversions.h"
25 #include "ui/aura/window.h"
26 #include "ui/wm/core/input_method_event_filter.h"
28 namespace ash {
29 namespace shell {
30 namespace {
32 class NewWindowDelegateImpl : public NewWindowDelegate {
33 public:
34 NewWindowDelegateImpl() {}
35 virtual ~NewWindowDelegateImpl() {}
37 // NewWindowDelegate:
38 virtual void NewTab() OVERRIDE {}
39 virtual void NewWindow(bool incognito) OVERRIDE {
40 ash::shell::ToplevelWindow::CreateParams create_params;
41 create_params.can_resize = true;
42 create_params.can_maximize = true;
43 ash::shell::ToplevelWindow::CreateToplevelWindow(create_params);
45 virtual void OpenFileManager() OVERRIDE {}
46 virtual void OpenCrosh() OVERRIDE {}
47 virtual void RestoreTab() OVERRIDE {}
48 virtual void ShowKeyboardOverlay() OVERRIDE {}
49 virtual void ShowTaskManager() OVERRIDE {}
50 virtual void OpenFeedbackPage() OVERRIDE {}
52 private:
53 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
56 class MediaDelegateImpl : public MediaDelegate {
57 public:
58 MediaDelegateImpl() {}
59 virtual ~MediaDelegateImpl() {}
61 // MediaDelegate:
62 virtual void HandleMediaNextTrack() OVERRIDE {}
63 virtual void HandleMediaPlayPause() OVERRIDE {}
64 virtual void HandleMediaPrevTrack() OVERRIDE {}
65 virtual MediaCaptureState GetMediaCaptureState(
66 content::BrowserContext* context) OVERRIDE {
67 return MEDIA_CAPTURE_VIDEO;
70 private:
71 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
74 class UserInfoImpl : public UserInfo {
75 public:
76 UserInfoImpl() {}
77 virtual ~UserInfoImpl() {}
79 // UserInfo:
80 virtual base::string16 GetDisplayName() const OVERRIDE {
81 return base::UTF8ToUTF16("stub-user");
83 virtual base::string16 GetGivenName() const OVERRIDE {
84 return base::UTF8ToUTF16("Stub");
86 virtual std::string GetEmail() const OVERRIDE {
87 return "stub-user@domain.com";
89 virtual std::string GetUserID() const OVERRIDE { return GetEmail(); }
90 virtual const gfx::ImageSkia& GetImage() const OVERRIDE {
91 return user_image_;
94 private:
95 gfx::ImageSkia user_image_;
97 DISALLOW_COPY_AND_ASSIGN(UserInfoImpl);
100 class SessionStateDelegateImpl : public SessionStateDelegate {
101 public:
102 SessionStateDelegateImpl()
103 : screen_locked_(false), user_info_(new UserInfoImpl()) {}
105 virtual ~SessionStateDelegateImpl() {}
107 // SessionStateDelegate:
108 virtual content::BrowserContext* GetBrowserContextByIndex(
109 MultiProfileIndex index) OVERRIDE {
110 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
112 virtual content::BrowserContext* GetBrowserContextForWindow(
113 aura::Window* window) OVERRIDE {
114 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
116 virtual int GetMaximumNumberOfLoggedInUsers() const OVERRIDE { return 3; }
117 virtual int NumberOfLoggedInUsers() const OVERRIDE {
118 // ash_shell has 2 users.
119 return 2;
121 virtual bool IsActiveUserSessionStarted() const OVERRIDE { return true; }
122 virtual bool CanLockScreen() const OVERRIDE { return true; }
123 virtual bool IsScreenLocked() const OVERRIDE { return screen_locked_; }
124 virtual bool ShouldLockScreenBeforeSuspending() const OVERRIDE {
125 return false;
127 virtual void LockScreen() OVERRIDE {
128 shell::CreateLockScreen();
129 screen_locked_ = true;
130 Shell::GetInstance()->UpdateShelfVisibility();
132 virtual void UnlockScreen() OVERRIDE {
133 screen_locked_ = false;
134 Shell::GetInstance()->UpdateShelfVisibility();
136 virtual bool IsUserSessionBlocked() const OVERRIDE {
137 return !IsActiveUserSessionStarted() || IsScreenLocked();
139 virtual SessionState GetSessionState() const OVERRIDE {
140 // Assume that if session is not active we're at login.
141 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
142 : SESSION_STATE_LOGIN_PRIMARY;
144 virtual const UserInfo* GetUserInfo(MultiProfileIndex index) const OVERRIDE {
145 return user_info_.get();
147 virtual const UserInfo* GetUserInfo(
148 content::BrowserContext* context) const OVERRIDE {
149 return user_info_.get();
151 virtual bool ShouldShowAvatar(aura::Window* window) const OVERRIDE {
152 return !user_info_->GetImage().isNull();
154 virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE {}
155 virtual void CycleActiveUser(CycleUser cycle_user) OVERRIDE {}
156 virtual void AddSessionStateObserver(
157 ash::SessionStateObserver* observer) OVERRIDE {}
158 virtual void RemoveSessionStateObserver(
159 ash::SessionStateObserver* observer) OVERRIDE {}
161 private:
162 bool screen_locked_;
164 // A pseudo user info.
165 scoped_ptr<UserInfo> user_info_;
167 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
170 } // namespace
172 ShellDelegateImpl::ShellDelegateImpl()
173 : watcher_(NULL),
174 shelf_delegate_(NULL),
175 browser_context_(NULL) {
178 ShellDelegateImpl::~ShellDelegateImpl() {
181 void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
182 watcher_ = watcher;
183 if (shelf_delegate_)
184 shelf_delegate_->set_watcher(watcher);
187 bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
188 return false;
191 bool ShellDelegateImpl::IsIncognitoAllowed() const {
192 return true;
195 bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
196 return false;
199 bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
200 return false;
203 bool ShellDelegateImpl::IsMultiAccountEnabled() const {
204 return false;
207 void ShellDelegateImpl::PreInit() {
210 void ShellDelegateImpl::PreShutdown() {
213 void ShellDelegateImpl::Exit() {
214 base::MessageLoopForUI::current()->Quit();
217 keyboard::KeyboardControllerProxy*
218 ShellDelegateImpl::CreateKeyboardControllerProxy() {
219 return new KeyboardControllerProxyStub();
222 void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
225 void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
226 VirtualKeyboardStateObserver* observer) {
229 void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
230 VirtualKeyboardStateObserver* observer) {
233 content::BrowserContext* ShellDelegateImpl::GetActiveBrowserContext() {
234 return browser_context_;
237 app_list::AppListViewDelegate* ShellDelegateImpl::CreateAppListViewDelegate() {
238 return ash::shell::CreateAppListViewDelegate();
241 ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
242 shelf_delegate_ = new ShelfDelegateImpl(watcher_);
243 return shelf_delegate_;
246 ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
247 return new DefaultSystemTrayDelegate;
250 ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
251 return new DefaultUserWallpaperDelegate();
254 ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
255 return new SessionStateDelegateImpl;
258 ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
259 return new DefaultAccessibilityDelegate;
262 ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
263 return new NewWindowDelegateImpl;
266 ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
267 return new MediaDelegateImpl;
270 ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
271 aura::Window* root,
272 ash::ShelfItemDelegate* item_delegate,
273 ash::ShelfItem* item) {
274 return new ContextMenu(root);
277 GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
278 // Real GPU support depends on src/content, so just use a stub.
279 return new GPUSupportStub;
282 base::string16 ShellDelegateImpl::GetProductName() const {
283 return base::string16();
286 } // namespace shell
287 } // namespace ash