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 "apps/app_window.h"
8 #include "apps/app_window_registry.h"
9 #include "ash/content_support/gpu_support_impl.h"
10 #include "ash/host/window_tree_host_factory.h"
11 #include "ash/magnifier/magnifier_constants.h"
12 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_util.h"
14 #include "base/command_line.h"
15 #include "chrome/browser/app_mode/app_mode_utils.h"
16 #include "chrome/browser/lifetime/application_lifetime.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/app_list/app_list_service.h"
19 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
20 #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
21 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
22 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
23 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
24 #include "chrome/browser/ui/ash/user_action_handler.h"
25 #include "chrome/browser/ui/browser_commands.h"
26 #include "chrome/common/chrome_switches.h"
27 #include "grit/chromium_strings.h"
28 #include "grit/generated_resources.h"
29 #include "ui/base/l10n/l10n_util.h"
31 #if defined(OS_CHROMEOS)
32 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
33 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
34 #include "chrome/browser/chromeos/login/user_manager.h"
38 ChromeShellDelegate
* ChromeShellDelegate::instance_
= NULL
;
40 ChromeShellDelegate::ChromeShellDelegate()
41 : shelf_delegate_(NULL
) {
46 ChromeShellDelegate::~ChromeShellDelegate() {
47 if (instance_
== this)
51 bool ChromeShellDelegate::IsMultiProfilesEnabled() const {
52 // TODO(skuhne): There is a function named profiles::IsMultiProfilesEnabled
53 // which does similar things - but it is not the same. We should investigate
54 // if these two could be folded together.
55 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles
))
57 #if defined(OS_CHROMEOS)
58 // If there is a user manager, we need to see that we can at least have 2
59 // simultaneous users to allow this feature.
60 if (!chromeos::UserManager::IsInitialized())
62 size_t admitted_users_to_be_added
=
63 chromeos::UserManager::Get()->GetUsersAdmittedForMultiProfile().size();
64 size_t logged_in_users
=
65 chromeos::UserManager::Get()->GetLoggedInUsers().size();
66 if (!logged_in_users
) {
67 // The shelf gets created on the login screen and as such we have to create
68 // all multi profile items of the the system tray menu before the user logs
69 // in. For special cases like Kiosk mode and / or guest mode this isn't a
70 // problem since either the browser gets restarted and / or the flag is not
71 // allowed, but for an "ephermal" user (see crbug.com/312324) it is not
72 // decided yet if he could add other users to his session or not.
73 // TODO(skuhne): As soon as the issue above needs to be resolved, this logic
77 if (admitted_users_to_be_added
+ logged_in_users
<= 1)
83 bool ChromeShellDelegate::IsIncognitoAllowed() const {
84 #if defined(OS_CHROMEOS)
85 return chromeos::AccessibilityManager::Get()->IsIncognitoAllowed();
90 bool ChromeShellDelegate::IsRunningInForcedAppMode() const {
91 return chrome::IsRunningInForcedAppMode();
94 void ChromeShellDelegate::Exit() {
95 chrome::AttemptUserExit();
98 content::BrowserContext
* ChromeShellDelegate::GetActiveBrowserContext() {
99 #if defined(OS_CHROMEOS)
100 DCHECK(chromeos::UserManager::Get()->GetLoggedInUsers().size());
102 return ProfileManager::GetActiveUserProfile();
105 app_list::AppListViewDelegate
*
106 ChromeShellDelegate::CreateAppListViewDelegate() {
107 DCHECK(ash::Shell::HasInstance());
108 // Shell will own the created delegate, and the delegate will own
110 return new AppListViewDelegate(
111 Profile::FromBrowserContext(GetActiveBrowserContext()),
112 AppListService::Get(chrome::HOST_DESKTOP_TYPE_ASH
)->
113 GetControllerDelegate());
116 ash::ShelfDelegate
* ChromeShellDelegate::CreateShelfDelegate(
117 ash::ShelfModel
* model
) {
118 // TODO(oshima): This is currently broken with multiple launchers.
119 // Refactor so that there is just one launcher delegate in the
121 if (!shelf_delegate_
) {
122 shelf_delegate_
= ChromeLauncherController::CreateInstance(NULL
, model
);
123 shelf_delegate_
->Init();
125 return shelf_delegate_
;
128 aura::client::UserActionClient
* ChromeShellDelegate::CreateUserActionClient() {
129 return new UserActionHandler
;
132 ui::MenuModel
* ChromeShellDelegate::CreateContextMenu(
134 ash::ShelfItemDelegate
* item_delegate
,
135 ash::ShelfItem
* item
) {
136 DCHECK(shelf_delegate_
);
137 // Don't show context menu for exclusive app runtime mode.
138 if (chrome::IsRunningInAppMode())
141 if (item_delegate
&& item
)
142 return new LauncherContextMenu(shelf_delegate_
, item_delegate
, item
, root
);
144 return new LauncherContextMenu(shelf_delegate_
, root
);
147 ash::WindowTreeHostFactory
* ChromeShellDelegate::CreateWindowTreeHostFactory() {
148 return ash::WindowTreeHostFactory::Create();
151 ash::GPUSupport
* ChromeShellDelegate::CreateGPUSupport() {
152 // Chrome uses real GPU support.
153 return new ash::GPUSupportImpl
;
156 base::string16
ChromeShellDelegate::GetProductName() const {
157 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
);
160 keyboard::KeyboardControllerProxy
*
161 ChromeShellDelegate::CreateKeyboardControllerProxy() {
162 return new AshKeyboardControllerProxy();