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/magnifier/magnifier_constants.h"
9 #include "ash/wm/window_state.h"
10 #include "ash/wm/window_util.h"
11 #include "chrome/browser/app_mode/app_mode_utils.h"
12 #include "chrome/browser/lifetime/application_lifetime.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/profiles/profiles_state.h"
15 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
16 #include "chrome/browser/ui/ash/app_list/app_list_service_ash.h"
17 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
20 #include "chrome/browser/ui/browser_commands.h"
21 #include "chrome/grit/chromium_strings.h"
22 #include "components/signin/core/common/profile_management_switches.h"
23 #include "ui/base/l10n/l10n_util.h"
25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
27 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
28 #include "components/user_manager/user_manager.h"
32 ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL;
34 ChromeShellDelegate::ChromeShellDelegate()
35 : shelf_delegate_(NULL) {
40 ChromeShellDelegate::~ChromeShellDelegate() {
41 if (instance_ == this)
45 bool ChromeShellDelegate::IsMultiProfilesEnabled() const {
46 if (!profiles::IsMultipleProfilesEnabled())
48 #if defined(OS_CHROMEOS)
49 // If there is a user manager, we need to see that we can at least have 2
50 // simultaneous users to allow this feature.
51 if (!user_manager::UserManager::IsInitialized())
53 size_t admitted_users_to_be_added = user_manager::UserManager::Get()
54 ->GetUsersAdmittedForMultiProfile()
56 size_t logged_in_users =
57 user_manager::UserManager::Get()->GetLoggedInUsers().size();
58 if (!logged_in_users) {
59 // The shelf gets created on the login screen and as such we have to create
60 // all multi profile items of the the system tray menu before the user logs
61 // in. For special cases like Kiosk mode and / or guest mode this isn't a
62 // problem since either the browser gets restarted and / or the flag is not
63 // allowed, but for an "ephermal" user (see crbug.com/312324) it is not
64 // decided yet if he could add other users to his session or not.
65 // TODO(skuhne): As soon as the issue above needs to be resolved, this logic
69 if (admitted_users_to_be_added + logged_in_users <= 1)
75 bool ChromeShellDelegate::IsIncognitoAllowed() const {
76 #if defined(OS_CHROMEOS)
77 return chromeos::AccessibilityManager::Get()->IsIncognitoAllowed();
82 bool ChromeShellDelegate::IsRunningInForcedAppMode() const {
83 return chrome::IsRunningInForcedAppMode();
86 bool ChromeShellDelegate::IsMultiAccountEnabled() const {
87 #if defined(OS_CHROMEOS)
88 return switches::IsEnableAccountConsistency();
93 void ChromeShellDelegate::Exit() {
94 chrome::AttemptUserExit();
97 content::BrowserContext* ChromeShellDelegate::GetActiveBrowserContext() {
98 #if defined(OS_CHROMEOS)
99 DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size());
101 return ProfileManager::GetActiveUserProfile();
104 app_list::AppListViewDelegate* ChromeShellDelegate::GetAppListViewDelegate() {
105 DCHECK(ash::Shell::HasInstance());
106 return AppListServiceAsh::GetInstance()->GetViewDelegate(
107 Profile::FromBrowserContext(GetActiveBrowserContext()));
110 ash::ShelfDelegate* ChromeShellDelegate::CreateShelfDelegate(
111 ash::ShelfModel* model) {
112 if (!shelf_delegate_) {
113 shelf_delegate_ = ChromeLauncherController::CreateInstance(NULL, model);
114 shelf_delegate_->Init();
116 return shelf_delegate_;
119 ui::MenuModel* ChromeShellDelegate::CreateContextMenu(
121 ash::ShelfItemDelegate* item_delegate,
122 ash::ShelfItem* item) {
123 DCHECK(shelf_delegate_);
124 // Don't show context menu for exclusive app runtime mode.
125 if (chrome::IsRunningInAppMode())
128 if (item_delegate && item)
129 return new LauncherContextMenu(shelf_delegate_, item_delegate, item, root);
131 return new LauncherContextMenu(shelf_delegate_, root);
134 ash::GPUSupport* ChromeShellDelegate::CreateGPUSupport() {
135 // Chrome uses real GPU support.
136 return new ash::GPUSupportImpl;
139 base::string16 ChromeShellDelegate::GetProductName() const {
140 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
143 keyboard::KeyboardControllerProxy*
144 ChromeShellDelegate::CreateKeyboardControllerProxy() {
145 return new AshKeyboardControllerProxy();
148 void ChromeShellDelegate::VirtualKeyboardActivated(bool activated) {
149 FOR_EACH_OBSERVER(ash::VirtualKeyboardStateObserver,
150 keyboard_state_observer_list_,
151 OnVirtualKeyboardStateChanged(activated));
154 void ChromeShellDelegate::AddVirtualKeyboardStateObserver(
155 ash::VirtualKeyboardStateObserver* observer) {
156 keyboard_state_observer_list_.AddObserver(observer);
159 void ChromeShellDelegate::RemoveVirtualKeyboardStateObserver(
160 ash::VirtualKeyboardStateObserver* observer) {
161 keyboard_state_observer_list_.RemoveObserver(observer);