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 "chrome/browser/ui/ash/chrome_shell_delegate.h"
7 #include "ash/content_support/gpu_support_impl.h"
8 #include "ash/wm/window_state.h"
9 #include "ash/wm/window_util.h"
10 #include "chrome/browser/app_mode/app_mode_utils.h"
11 #include "chrome/browser/lifetime/application_lifetime.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
15 #include "chrome/browser/ui/ash/app_list/app_list_service_ash.h"
16 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
18 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
19 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/grit/chromium_strings.h"
24 #include "components/signin/core/common/profile_management_switches.h"
25 #include "grit/theme_resources.h"
26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h"
29 #if defined(OS_CHROMEOS)
30 #include "base/prefs/pref_service.h"
31 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
32 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
33 #include "chrome/browser/chromeos/profiles/profile_helper.h"
34 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/common/pref_names.h"
36 #include "components/user_manager/user.h"
37 #include "components/user_manager/user_manager.h"
42 const char kKeyboardShortcutHelpPageUrl
[] =
43 "https://support.google.com/chromebook/answer/183101";
48 ChromeShellDelegate
* ChromeShellDelegate::instance_
= NULL
;
50 ChromeShellDelegate::ChromeShellDelegate()
51 : shelf_delegate_(NULL
) {
56 ChromeShellDelegate::~ChromeShellDelegate() {
57 if (instance_
== this)
61 bool ChromeShellDelegate::IsMultiProfilesEnabled() const {
62 if (!profiles::IsMultipleProfilesEnabled())
64 #if defined(OS_CHROMEOS)
65 // If there is a user manager, we need to see that we can at least have 2
66 // simultaneous users to allow this feature.
67 if (!user_manager::UserManager::IsInitialized())
69 size_t admitted_users_to_be_added
=
70 user_manager::UserManager::Get()->GetUsersAllowedForMultiProfile().size();
71 size_t logged_in_users
=
72 user_manager::UserManager::Get()->GetLoggedInUsers().size();
73 if (!logged_in_users
) {
74 // The shelf gets created on the login screen and as such we have to create
75 // all multi profile items of the the system tray menu before the user logs
76 // in. For special cases like Kiosk mode and / or guest mode this isn't a
77 // problem since either the browser gets restarted and / or the flag is not
78 // allowed, but for an "ephermal" user (see crbug.com/312324) it is not
79 // decided yet if he could add other users to his session or not.
80 // TODO(skuhne): As soon as the issue above needs to be resolved, this logic
84 if (admitted_users_to_be_added
+ logged_in_users
<= 1)
90 bool ChromeShellDelegate::IsIncognitoAllowed() const {
91 #if defined(OS_CHROMEOS)
92 return chromeos::AccessibilityManager::Get()->IsIncognitoAllowed();
97 bool ChromeShellDelegate::IsRunningInForcedAppMode() const {
98 return chrome::IsRunningInForcedAppMode();
101 bool ChromeShellDelegate::IsMultiAccountEnabled() const {
102 #if defined(OS_CHROMEOS)
103 return switches::IsEnableAccountConsistency();
108 bool ChromeShellDelegate::IsForceMaximizeOnFirstRun() const {
109 #if defined(OS_CHROMEOS)
110 const user_manager::User
* const user
=
111 user_manager::UserManager::Get()->GetActiveUser();
113 return chromeos::ProfileHelper::Get()
114 ->GetProfileByUser(user
)
116 ->GetBoolean(prefs::kForceMaximizeOnFirstRun
);
122 void ChromeShellDelegate::Exit() {
123 chrome::AttemptUserExit();
126 content::BrowserContext
* ChromeShellDelegate::GetActiveBrowserContext() {
127 #if defined(OS_CHROMEOS)
128 DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size());
130 return ProfileManager::GetActiveUserProfile();
133 app_list::AppListViewDelegate
* ChromeShellDelegate::GetAppListViewDelegate() {
134 DCHECK(ash::Shell::HasInstance());
135 return AppListServiceAsh::GetInstance()->GetViewDelegate(
136 Profile::FromBrowserContext(GetActiveBrowserContext()));
139 ash::ShelfDelegate
* ChromeShellDelegate::CreateShelfDelegate(
140 ash::ShelfModel
* model
) {
141 if (!shelf_delegate_
) {
142 shelf_delegate_
= ChromeLauncherController::CreateInstance(NULL
, model
);
143 shelf_delegate_
->Init();
145 return shelf_delegate_
;
148 ui::MenuModel
* ChromeShellDelegate::CreateContextMenu(
150 ash::ShelfItemDelegate
* item_delegate
,
151 ash::ShelfItem
* item
) {
152 DCHECK(shelf_delegate_
);
153 // Don't show context menu for exclusive app runtime mode.
154 if (chrome::IsRunningInAppMode())
157 if (item_delegate
&& item
)
158 return new LauncherContextMenu(shelf_delegate_
, item_delegate
, item
, root
);
160 return new LauncherContextMenu(shelf_delegate_
, root
);
163 ash::GPUSupport
* ChromeShellDelegate::CreateGPUSupport() {
164 // Chrome uses real GPU support.
165 return new ash::GPUSupportImpl
;
168 base::string16
ChromeShellDelegate::GetProductName() const {
169 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
);
172 void ChromeShellDelegate::OpenKeyboardShortcutHelpPage() const {
173 Profile
* profile
= ProfileManager::GetActiveUserProfile();
175 chrome::FindTabbedBrowser(profile
, false, chrome::HOST_DESKTOP_TYPE_ASH
);
178 browser
= new Browser(
179 Browser::CreateParams(profile
, chrome::HOST_DESKTOP_TYPE_ASH
));
180 browser
->window()->Show();
183 browser
->window()->Activate();
185 chrome::NavigateParams
params(browser
, GURL(kKeyboardShortcutHelpPageUrl
),
186 ui::PAGE_TRANSITION_AUTO_BOOKMARK
);
187 params
.disposition
= SINGLETON_TAB
;
188 chrome::Navigate(¶ms
);
191 gfx::Image
ChromeShellDelegate::GetDeprecatedAcceleratorImage() const {
192 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
193 IDR_BLUETOOTH_KEYBOARD
);
196 keyboard::KeyboardControllerProxy
*
197 ChromeShellDelegate::CreateKeyboardControllerProxy() {
198 return new AshKeyboardControllerProxy(
199 ProfileManager::GetActiveUserProfile());
202 void ChromeShellDelegate::VirtualKeyboardActivated(bool activated
) {
203 FOR_EACH_OBSERVER(ash::VirtualKeyboardStateObserver
,
204 keyboard_state_observer_list_
,
205 OnVirtualKeyboardStateChanged(activated
));
208 void ChromeShellDelegate::AddVirtualKeyboardStateObserver(
209 ash::VirtualKeyboardStateObserver
* observer
) {
210 keyboard_state_observer_list_
.AddObserver(observer
);
213 void ChromeShellDelegate::RemoveVirtualKeyboardStateObserver(
214 ash::VirtualKeyboardStateObserver
* observer
) {
215 keyboard_state_observer_list_
.RemoveObserver(observer
);