No longer register app window placement preference keys on
[chromium-blink-merge.git] / chrome / browser / ui / ash / chrome_shell_delegate.cc
blobdf4870af9cc019dca7799156f54fb334a2d3a0e2
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_service.h"
16 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
17 #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
18 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
20 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/grit/chromium_strings.h"
23 #include "components/signin/core/common/profile_management_switches.h"
24 #include "ui/base/l10n/l10n_util.h"
26 #if defined(OS_CHROMEOS)
27 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
28 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
29 #include "components/user_manager/user_manager.h"
30 #endif
32 // static
33 ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL;
35 ChromeShellDelegate::ChromeShellDelegate()
36 : shelf_delegate_(NULL) {
37 instance_ = this;
38 PlatformInit();
41 ChromeShellDelegate::~ChromeShellDelegate() {
42 if (instance_ == this)
43 instance_ = NULL;
46 bool ChromeShellDelegate::IsMultiProfilesEnabled() const {
47 if (!profiles::IsMultipleProfilesEnabled())
48 return false;
49 #if defined(OS_CHROMEOS)
50 // If there is a user manager, we need to see that we can at least have 2
51 // simultaneous users to allow this feature.
52 if (!user_manager::UserManager::IsInitialized())
53 return false;
54 size_t admitted_users_to_be_added = user_manager::UserManager::Get()
55 ->GetUsersAdmittedForMultiProfile()
56 .size();
57 size_t logged_in_users =
58 user_manager::UserManager::Get()->GetLoggedInUsers().size();
59 if (!logged_in_users) {
60 // The shelf gets created on the login screen and as such we have to create
61 // all multi profile items of the the system tray menu before the user logs
62 // in. For special cases like Kiosk mode and / or guest mode this isn't a
63 // problem since either the browser gets restarted and / or the flag is not
64 // allowed, but for an "ephermal" user (see crbug.com/312324) it is not
65 // decided yet if he could add other users to his session or not.
66 // TODO(skuhne): As soon as the issue above needs to be resolved, this logic
67 // should change.
68 logged_in_users = 1;
70 if (admitted_users_to_be_added + logged_in_users <= 1)
71 return false;
72 #endif
73 return true;
76 bool ChromeShellDelegate::IsIncognitoAllowed() const {
77 #if defined(OS_CHROMEOS)
78 return chromeos::AccessibilityManager::Get()->IsIncognitoAllowed();
79 #endif
80 return true;
83 bool ChromeShellDelegate::IsRunningInForcedAppMode() const {
84 return chrome::IsRunningInForcedAppMode();
87 bool ChromeShellDelegate::IsMultiAccountEnabled() const {
88 #if defined(OS_CHROMEOS)
89 return switches::IsEnableAccountConsistency();
90 #endif
91 return false;
94 void ChromeShellDelegate::Exit() {
95 chrome::AttemptUserExit();
98 content::BrowserContext* ChromeShellDelegate::GetActiveBrowserContext() {
99 #if defined(OS_CHROMEOS)
100 DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size());
101 #endif
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
109 // the controller.
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 if (!shelf_delegate_) {
119 shelf_delegate_ = ChromeLauncherController::CreateInstance(NULL, model);
120 shelf_delegate_->Init();
122 return shelf_delegate_;
125 ui::MenuModel* ChromeShellDelegate::CreateContextMenu(
126 aura::Window* root,
127 ash::ShelfItemDelegate* item_delegate,
128 ash::ShelfItem* item) {
129 DCHECK(shelf_delegate_);
130 // Don't show context menu for exclusive app runtime mode.
131 if (chrome::IsRunningInAppMode())
132 return NULL;
134 if (item_delegate && item)
135 return new LauncherContextMenu(shelf_delegate_, item_delegate, item, root);
137 return new LauncherContextMenu(shelf_delegate_, root);
140 ash::GPUSupport* ChromeShellDelegate::CreateGPUSupport() {
141 // Chrome uses real GPU support.
142 return new ash::GPUSupportImpl;
145 base::string16 ChromeShellDelegate::GetProductName() const {
146 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
149 keyboard::KeyboardControllerProxy*
150 ChromeShellDelegate::CreateKeyboardControllerProxy() {
151 return new AshKeyboardControllerProxy();
154 void ChromeShellDelegate::VirtualKeyboardActivated(bool activated) {
155 FOR_EACH_OBSERVER(ash::VirtualKeyboardStateObserver,
156 keyboard_state_observer_list_,
157 OnVirtualKeyboardStateChanged(activated));
160 void ChromeShellDelegate::AddVirtualKeyboardStateObserver(
161 ash::VirtualKeyboardStateObserver* observer) {
162 keyboard_state_observer_list_.AddObserver(observer);
165 void ChromeShellDelegate::RemoveVirtualKeyboardStateObserver(
166 ash::VirtualKeyboardStateObserver* observer) {
167 keyboard_state_observer_list_.RemoveObserver(observer);