Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / ash / chrome_shell_delegate.cc
blob612c61f8120628ddf2357f6b31686daf3da9fbd5
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/grit/chromium_strings.h"
21 #include "components/signin/core/common/profile_management_switches.h"
22 #include "ui/base/l10n/l10n_util.h"
24 #if defined(OS_CHROMEOS)
25 #include "base/prefs/pref_service.h"
26 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
27 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
28 #include "chrome/browser/chromeos/profiles/profile_helper.h"
29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/common/pref_names.h"
31 #include "components/user_manager/user.h"
32 #include "components/user_manager/user_manager.h"
33 #endif
35 // static
36 ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL;
38 ChromeShellDelegate::ChromeShellDelegate()
39 : shelf_delegate_(NULL) {
40 instance_ = this;
41 PlatformInit();
44 ChromeShellDelegate::~ChromeShellDelegate() {
45 if (instance_ == this)
46 instance_ = NULL;
49 bool ChromeShellDelegate::IsMultiProfilesEnabled() const {
50 if (!profiles::IsMultipleProfilesEnabled())
51 return false;
52 #if defined(OS_CHROMEOS)
53 // If there is a user manager, we need to see that we can at least have 2
54 // simultaneous users to allow this feature.
55 if (!user_manager::UserManager::IsInitialized())
56 return false;
57 size_t admitted_users_to_be_added =
58 user_manager::UserManager::Get()->GetUsersAllowedForMultiProfile().size();
59 size_t logged_in_users =
60 user_manager::UserManager::Get()->GetLoggedInUsers().size();
61 if (!logged_in_users) {
62 // The shelf gets created on the login screen and as such we have to create
63 // all multi profile items of the the system tray menu before the user logs
64 // in. For special cases like Kiosk mode and / or guest mode this isn't a
65 // problem since either the browser gets restarted and / or the flag is not
66 // allowed, but for an "ephermal" user (see crbug.com/312324) it is not
67 // decided yet if he could add other users to his session or not.
68 // TODO(skuhne): As soon as the issue above needs to be resolved, this logic
69 // should change.
70 logged_in_users = 1;
72 if (admitted_users_to_be_added + logged_in_users <= 1)
73 return false;
74 #endif
75 return true;
78 bool ChromeShellDelegate::IsIncognitoAllowed() const {
79 #if defined(OS_CHROMEOS)
80 return chromeos::AccessibilityManager::Get()->IsIncognitoAllowed();
81 #endif
82 return true;
85 bool ChromeShellDelegate::IsRunningInForcedAppMode() const {
86 return chrome::IsRunningInForcedAppMode();
89 bool ChromeShellDelegate::IsMultiAccountEnabled() const {
90 #if defined(OS_CHROMEOS)
91 return switches::IsEnableAccountConsistency();
92 #endif
93 return false;
96 bool ChromeShellDelegate::IsForceMaximizeOnFirstRun() const {
97 #if defined(OS_CHROMEOS)
98 const user_manager::User* const user =
99 user_manager::UserManager::Get()->GetActiveUser();
100 if (user) {
101 return chromeos::ProfileHelper::Get()
102 ->GetProfileByUser(user)
103 ->GetPrefs()
104 ->GetBoolean(prefs::kForceMaximizeOnFirstRun);
106 #endif
107 return false;
110 void ChromeShellDelegate::Exit() {
111 chrome::AttemptUserExit();
114 content::BrowserContext* ChromeShellDelegate::GetActiveBrowserContext() {
115 #if defined(OS_CHROMEOS)
116 DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size());
117 #endif
118 return ProfileManager::GetActiveUserProfile();
121 app_list::AppListViewDelegate* ChromeShellDelegate::GetAppListViewDelegate() {
122 DCHECK(ash::Shell::HasInstance());
123 return AppListServiceAsh::GetInstance()->GetViewDelegate(
124 Profile::FromBrowserContext(GetActiveBrowserContext()));
127 ash::ShelfDelegate* ChromeShellDelegate::CreateShelfDelegate(
128 ash::ShelfModel* model) {
129 if (!shelf_delegate_) {
130 shelf_delegate_ = ChromeLauncherController::CreateInstance(NULL, model);
131 shelf_delegate_->Init();
133 return shelf_delegate_;
136 ui::MenuModel* ChromeShellDelegate::CreateContextMenu(
137 aura::Window* root,
138 ash::ShelfItemDelegate* item_delegate,
139 ash::ShelfItem* item) {
140 DCHECK(shelf_delegate_);
141 // Don't show context menu for exclusive app runtime mode.
142 if (chrome::IsRunningInAppMode())
143 return NULL;
145 if (item_delegate && item)
146 return new LauncherContextMenu(shelf_delegate_, item_delegate, item, root);
148 return new LauncherContextMenu(shelf_delegate_, root);
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(
163 ProfileManager::GetActiveUserProfile());
166 void ChromeShellDelegate::VirtualKeyboardActivated(bool activated) {
167 FOR_EACH_OBSERVER(ash::VirtualKeyboardStateObserver,
168 keyboard_state_observer_list_,
169 OnVirtualKeyboardStateChanged(activated));
172 void ChromeShellDelegate::AddVirtualKeyboardStateObserver(
173 ash::VirtualKeyboardStateObserver* observer) {
174 keyboard_state_observer_list_.AddObserver(observer);
177 void ChromeShellDelegate::RemoveVirtualKeyboardStateObserver(
178 ash::VirtualKeyboardStateObserver* observer) {
179 keyboard_state_observer_list_.RemoveObserver(observer);