chrome_shell_delegate.cc revision 0f1bc08d4cfcc34181b0b5cbf065c40f687bf740
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. 4 5#include "chrome/browser/ui/ash/chrome_shell_delegate.h" 6 7#include "apps/shell_window.h" 8#include "apps/shell_window_registry.h" 9#include "ash/host/root_window_host_factory.h" 10#include "ash/magnifier/magnifier_constants.h" 11#include "ash/wm/window_state.h" 12#include "ash/wm/window_util.h" 13#include "base/command_line.h" 14#include "chrome/browser/app_mode/app_mode_utils.h" 15#include "chrome/browser/lifetime/application_lifetime.h" 16#include "chrome/browser/profiles/profile_manager.h" 17#include "chrome/browser/ui/app_list/app_list_view_delegate.h" 18#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" 19#include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" 20#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 21#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 22#include "chrome/browser/ui/ash/user_action_handler.h" 23#include "chrome/browser/ui/browser_commands.h" 24#include "chrome/common/chrome_switches.h" 25#include "content/public/browser/user_metrics.h" 26#include "grit/chromium_strings.h" 27#include "grit/generated_resources.h" 28#include "ui/base/l10n/l10n_util.h" 29 30#if defined(OS_CHROMEOS) 31#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 32#include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" 33#include "chrome/browser/chromeos/login/user_manager.h" 34#endif 35 36// static 37ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL; 38 39ChromeShellDelegate::ChromeShellDelegate() 40 : launcher_delegate_(NULL) { 41 instance_ = this; 42 PlatformInit(); 43} 44 45ChromeShellDelegate::~ChromeShellDelegate() { 46 if (instance_ == this) 47 instance_ = NULL; 48} 49 50bool ChromeShellDelegate::IsMultiProfilesEnabled() const { 51 // TODO(skuhne): There is a function named profiles::IsMultiProfilesEnabled 52 // which does similar things - but it is not the same. We should investigate 53 // if these two could be folded together. 54 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) 55 return false; 56#if defined(OS_CHROMEOS) 57 // If there is a user manager, we need to see that we can at least have 2 58 // simultaneous users to allow this feature. 59 if (!chromeos::UserManager::IsInitialized()) 60 return false; 61 size_t admitted_users_to_be_added = 62 chromeos::UserManager::Get()->GetUsersAdmittedForMultiProfile().size(); 63 size_t logged_in_users = 64 chromeos::UserManager::Get()->GetLoggedInUsers().size(); 65 if (!logged_in_users) { 66 // The shelf gets created on the login screen and as such we have to create 67 // all multi profile items of the the system tray menu before the user logs 68 // in. For special cases like Kiosk mode and / or guest mode this isn't a 69 // problem since either the browser gets restarted and / or the flag is not 70 // allowed, but for an "ephermal" user (see crbug.com/312324) it is not 71 // decided yet if he could add other users to his session or not. 72 // TODO(skuhne): As soon as the issue above needs to be resolved, this logic 73 // should change. 74 logged_in_users = 1; 75 } 76 if (admitted_users_to_be_added + logged_in_users <= 1) 77 return false; 78#endif 79 return true; 80} 81 82bool ChromeShellDelegate::IsIncognitoAllowed() const { 83#if defined(OS_CHROMEOS) 84 return chromeos::AccessibilityManager::Get()->IsIncognitoAllowed(); 85#endif 86 return true; 87} 88 89bool ChromeShellDelegate::IsRunningInForcedAppMode() const { 90 return chrome::IsRunningInForcedAppMode(); 91} 92 93void ChromeShellDelegate::Exit() { 94 chrome::AttemptUserExit(); 95} 96 97content::BrowserContext* ChromeShellDelegate::GetCurrentBrowserContext() { 98 return ProfileManager::GetDefaultProfile(); 99} 100 101app_list::AppListViewDelegate* 102 ChromeShellDelegate::CreateAppListViewDelegate() { 103 DCHECK(ash::Shell::HasInstance()); 104 // Shell will own the created delegate, and the delegate will own 105 // the controller. 106 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); 107 return new AppListViewDelegate( 108 scoped_ptr<AppListControllerDelegate>(new AppListControllerDelegateAsh()), 109 profile); 110} 111 112ash::LauncherDelegate* ChromeShellDelegate::CreateLauncherDelegate( 113 ash::LauncherModel* model) { 114 DCHECK(ProfileManager::IsGetDefaultProfileAllowed()); 115 // TODO(oshima): This is currently broken with multiple launchers. 116 // Refactor so that there is just one launcher delegate in the 117 // shell. 118 if (!launcher_delegate_) { 119 launcher_delegate_ = ChromeLauncherController::CreateInstance(NULL, model); 120 launcher_delegate_->Init(); 121 } 122 return launcher_delegate_; 123} 124 125aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() { 126 return new UserActionHandler; 127} 128 129void ChromeShellDelegate::RecordUserMetricsAction( 130 ash::UserMetricsAction action) { 131 switch (action) { 132 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_DOWN_F6: 133 content::RecordAction( 134 content::UserMetricsAction("Accel_KeyboardBrightnessDown_F6")); 135 break; 136 case ash::UMA_ACCEL_KEYBOARD_BRIGHTNESS_UP_F7: 137 content::RecordAction( 138 content::UserMetricsAction("Accel_KeyboardBrightnessUp_F7")); 139 break; 140 case ash::UMA_ACCEL_LOCK_SCREEN_L: 141 content::RecordAction( 142 content::UserMetricsAction("Accel_LockScreen_L")); 143 break; 144 case ash::UMA_ACCEL_LOCK_SCREEN_LOCK_BUTTON: 145 content::RecordAction( 146 content::UserMetricsAction("Accel_LockScreen_LockButton")); 147 break; 148 case ash::UMA_ACCEL_LOCK_SCREEN_POWER_BUTTON: 149 content::RecordAction( 150 content::UserMetricsAction("Accel_LockScreen_PowerButton")); 151 break; 152 case ash::UMA_ACCEL_FULLSCREEN_F4: 153 content::RecordAction(content::UserMetricsAction("Accel_Fullscreen_F4")); 154 break; 155 case ash::UMA_ACCEL_MAXIMIZE_RESTORE_F4: 156 content::RecordAction( 157 content::UserMetricsAction("Accel_Maximize_Restore_F4")); 158 break; 159 case ash::UMA_ACCEL_NEWTAB_T: 160 content::RecordAction(content::UserMetricsAction("Accel_NewTab_T")); 161 break; 162 case ash::UMA_ACCEL_NEXTWINDOW_F5: 163 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_F5")); 164 break; 165 case ash::UMA_ACCEL_NEXTWINDOW_TAB: 166 content::RecordAction(content::UserMetricsAction("Accel_NextWindow_Tab")); 167 break; 168 case ash::UMA_ACCEL_OVERVIEW_F5: 169 content::RecordAction(content::UserMetricsAction("Accel_Overview_F5")); 170 break; 171 case ash::UMA_ACCEL_PREVWINDOW_F5: 172 content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_F5")); 173 break; 174 case ash::UMA_ACCEL_PREVWINDOW_TAB: 175 content::RecordAction(content::UserMetricsAction("Accel_PrevWindow_Tab")); 176 break; 177 case ash::UMA_ACCEL_EXIT_FIRST_Q: 178 content::RecordAction(content::UserMetricsAction("Accel_Exit_First_Q")); 179 break; 180 case ash::UMA_ACCEL_EXIT_SECOND_Q: 181 content::RecordAction(content::UserMetricsAction("Accel_Exit_Second_Q")); 182 break; 183 case ash::UMA_ACCEL_SEARCH_LWIN: 184 content::RecordAction(content::UserMetricsAction("Accel_Search_LWin")); 185 break; 186 case ash::UMA_ACCEL_SHUT_DOWN_POWER_BUTTON: 187 content::RecordAction( 188 content::UserMetricsAction("Accel_ShutDown_PowerButton")); 189 break; 190 case ash::UMA_CLOSE_THROUGH_CONTEXT_MENU: 191 content::RecordAction(content::UserMetricsAction("CloseFromContextMenu")); 192 break; 193 case ash::UMA_GESTURE_OVERVIEW: 194 content::RecordAction(content::UserMetricsAction("Gesture_Overview")); 195 break; 196 case ash::UMA_LAUNCHER_CLICK_ON_APP: 197 content::RecordAction(content::UserMetricsAction("Launcher_ClickOnApp")); 198 break; 199 case ash::UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON: 200 content::RecordAction( 201 content::UserMetricsAction("Launcher_ClickOnApplistButton")); 202#if defined(OS_CHROMEOS) 203 chromeos::default_pinned_apps_field_trial::RecordShelfClick( 204 chromeos::default_pinned_apps_field_trial::APP_LAUNCHER); 205#endif 206 break; 207 case ash::UMA_MINIMIZE_PER_KEY: 208 content::RecordAction(content::UserMetricsAction("Minimize_UsingKey")); 209 break; 210 case ash::UMA_MOUSE_DOWN: 211 content::RecordAction(content::UserMetricsAction("Mouse_Down")); 212 break; 213 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK: 214 content::RecordAction( 215 content::UserMetricsAction("Caption_ClickTogglesMaximize")); 216 break; 217 case ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE: 218 content::RecordAction( 219 content::UserMetricsAction("Caption_GestureTogglesMaximize")); 220 break; 221 case ash::UMA_TOUCHPAD_GESTURE_OVERVIEW: 222 content::RecordAction( 223 content::UserMetricsAction("Touchpad_Gesture_Overview")); 224 break; 225 case ash::UMA_TOUCHSCREEN_TAP_DOWN: 226 content::RecordAction(content::UserMetricsAction("Touchscreen_Down")); 227 break; 228 case ash::UMA_TRAY_HELP: 229 content::RecordAction(content::UserMetricsAction("Tray_Help")); 230 break; 231 case ash::UMA_TRAY_LOCK_SCREEN: 232 content::RecordAction(content::UserMetricsAction("Tray_LockScreen")); 233 break; 234 case ash::UMA_TRAY_SHUT_DOWN: 235 content::RecordAction(content::UserMetricsAction("Tray_ShutDown")); 236 break; 237 case ash::UMA_WINDOW_APP_CLOSE_BUTTON_CLICK: 238 content::RecordAction(content::UserMetricsAction("AppCloseButton_Clk")); 239 break; 240 case ash::UMA_WINDOW_CLOSE_BUTTON_CLICK: 241 content::RecordAction(content::UserMetricsAction("CloseButton_Clk")); 242 break; 243 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN: 244 content::RecordAction(content::UserMetricsAction("MaxButton_Clk_ExitFS")); 245 break; 246 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE: 247 content::RecordAction( 248 content::UserMetricsAction("MaxButton_Clk_Restore")); 249 break; 250 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE: 251 content::RecordAction( 252 content::UserMetricsAction("MaxButton_Clk_Maximize")); 253 break; 254 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE: 255 content::RecordAction(content::UserMetricsAction("MinButton_Clk")); 256 break; 257 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE: 258 content::RecordAction(content::UserMetricsAction("MaxButton_Maximize")); 259 break; 260 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT: 261 content::RecordAction(content::UserMetricsAction("MaxButton_MaxLeft")); 262 break; 263 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT: 264 content::RecordAction(content::UserMetricsAction("MaxButton_MaxRight")); 265 break; 266 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE: 267 content::RecordAction(content::UserMetricsAction("MaxButton_Minimize")); 268 break; 269 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE: 270 content::RecordAction(content::UserMetricsAction("MaxButton_Restore")); 271 break; 272 case ash::UMA_WINDOW_MAXIMIZE_BUTTON_SHOW_BUBBLE: 273 content::RecordAction(content::UserMetricsAction("MaxButton_ShowBubble")); 274 break; 275 case ash::UMA_WINDOW_OVERVIEW: 276 content::RecordAction( 277 content::UserMetricsAction("WindowSelector_Overview")); 278 break; 279 case ash::UMA_WINDOW_SELECTION: 280 content::RecordAction( 281 content::UserMetricsAction("WindowSelector_Selection")); 282 break; 283 } 284} 285 286ui::MenuModel* ChromeShellDelegate::CreateContextMenu(aura::Window* root) { 287 DCHECK(launcher_delegate_); 288 // Don't show context menu for exclusive app runtime mode. 289 if (chrome::IsRunningInAppMode()) 290 return NULL; 291 292 return new LauncherContextMenu(launcher_delegate_, root); 293} 294 295ash::RootWindowHostFactory* ChromeShellDelegate::CreateRootWindowHostFactory() { 296 return ash::RootWindowHostFactory::Create(); 297} 298 299string16 ChromeShellDelegate::GetProductName() const { 300 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 301} 302 303keyboard::KeyboardControllerProxy* 304 ChromeShellDelegate::CreateKeyboardControllerProxy() { 305 return new AshKeyboardControllerProxy(); 306} 307