NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / ash / ash_init.cc
blob4ba14256fe5c0bbe4296a3844ec437882f9c52ca
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/ash_init.h"
7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/ash_switches.h"
9 #include "ash/high_contrast/high_contrast_controller.h"
10 #include "ash/magnifier/magnification_controller.h"
11 #include "ash/magnifier/partial_magnification_controller.h"
12 #include "ash/shell.h"
13 #include "base/command_line.h"
14 #include "chrome/browser/browser_shutdown.h"
15 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
16 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
17 #include "chrome/browser/lifetime/application_lifetime.h"
18 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
19 #include "chrome/browser/ui/ash/screenshot_taker.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "ui/aura/env.h"
22 #include "ui/aura/root_window.h"
24 #if defined(OS_CHROMEOS)
25 #include "base/sys_info.h"
26 #include "chrome/browser/ui/ash/ime_controller_chromeos.h"
27 #include "chrome/browser/ui/ash/volume_controller_chromeos.h"
28 #include "chromeos/chromeos_switches.h"
29 #include "chromeos/login/login_state.h"
30 #include "ui/base/x/x11_util.h"
31 #endif
33 namespace chrome {
35 bool ShouldOpenAshOnStartup() {
36 #if defined(OS_CHROMEOS)
37 return true;
38 #endif
39 // TODO(scottmg): http://crbug.com/133312, will need this for Win8 too.
40 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kOpenAsh);
43 void OpenAsh() {
44 #if defined(OS_CHROMEOS)
45 if (base::SysInfo::IsRunningOnChromeOS()) {
46 // Hides the cursor outside of the Aura root window. The cursor will be
47 // drawn within the Aura root window, and it'll remain hidden after the
48 // Aura window is closed.
49 ui::HideHostCursor();
52 // Hide the mouse cursor completely at boot.
53 if (!chromeos::LoginState::Get()->IsUserLoggedIn())
54 ash::Shell::set_initially_hide_cursor(true);
55 #endif
57 // Shell takes ownership of ChromeShellDelegate.
58 ash::Shell* shell = ash::Shell::CreateInstance(new ChromeShellDelegate);
59 shell->accelerator_controller()->SetScreenshotDelegate(
60 scoped_ptr<ash::ScreenshotDelegate>(new ScreenshotTaker).Pass());
61 #if defined(OS_CHROMEOS)
62 shell->accelerator_controller()->SetImeControlDelegate(
63 scoped_ptr<ash::ImeControlDelegate>(new ImeController).Pass());
64 shell->high_contrast_controller()->SetEnabled(
65 chromeos::AccessibilityManager::Get()->IsHighContrastEnabled());
67 DCHECK(chromeos::MagnificationManager::Get());
68 bool magnifier_enabled =
69 chromeos::MagnificationManager::Get()->IsMagnifierEnabled();
70 ash::MagnifierType magnifier_type =
71 chromeos::MagnificationManager::Get()->GetMagnifierType();
72 shell->magnification_controller()->
73 SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_FULL);
74 shell->partial_magnification_controller()->
75 SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_PARTIAL);
77 if (!CommandLine::ForCurrentProcess()->HasSwitch(
78 switches::kDisableZeroBrowsersOpenForTests)) {
79 chrome::StartKeepAlive();
81 #endif
82 ash::Shell::GetPrimaryRootWindow()->GetDispatcher()->host()->Show();
85 void CloseAsh() {
86 // If shutdown is initiated by |BrowserX11IOErrorHandler|, don't
87 // try to cleanup resources.
88 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers() &&
89 ash::Shell::HasInstance()) {
90 ash::Shell::DeleteInstance();
94 } // namespace chrome