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/content_support/inject.h"
10 #include "ash/high_contrast/high_contrast_controller.h"
11 #include "ash/magnifier/magnification_controller.h"
12 #include "ash/magnifier/partial_magnification_controller.h"
13 #include "ash/shell.h"
14 #include "ash/wm/event_rewriter_event_filter.h"
15 #include "base/command_line.h"
16 #include "chrome/browser/browser_shutdown.h"
17 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
18 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
19 #include "chrome/browser/lifetime/application_lifetime.h"
20 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
21 #include "chrome/browser/ui/ash/event_rewriter.h"
22 #include "chrome/browser/ui/ash/screenshot_taker.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "ui/aura/env.h"
25 #include "ui/aura/root_window.h"
27 #if defined(OS_CHROMEOS)
28 #include "base/sys_info.h"
29 #include "chrome/browser/ui/ash/ime_controller_chromeos.h"
30 #include "chrome/browser/ui/ash/volume_controller_chromeos.h"
31 #include "chromeos/chromeos_switches.h"
32 #include "chromeos/login/login_state.h"
33 #include "ui/base/x/x11_util.h"
38 bool ShouldOpenAshOnStartup() {
39 #if defined(OS_CHROMEOS)
42 // TODO(scottmg): http://crbug.com/133312, will need this for Win8 too.
43 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kOpenAsh
);
47 #if defined(OS_CHROMEOS)
48 if (base::SysInfo::IsRunningOnChromeOS()) {
49 // Hides the cursor outside of the Aura root window. The cursor will be
50 // drawn within the Aura root window, and it'll remain hidden after the
51 // Aura window is closed.
55 // Hide the mouse cursor completely at boot.
56 if (!chromeos::LoginState::Get()->IsUserLoggedIn())
57 ash::Shell::set_initially_hide_cursor(true);
60 // Shell takes ownership of ChromeShellDelegate.
61 ash::Shell
* shell
= ash::Shell::CreateInstance(new ChromeShellDelegate
);
62 ash::InitContentSupport();
63 shell
->event_rewriter_filter()->SetEventRewriterDelegate(
64 scoped_ptr
<ash::EventRewriterDelegate
>(new EventRewriter
).Pass());
65 shell
->accelerator_controller()->SetScreenshotDelegate(
66 scoped_ptr
<ash::ScreenshotDelegate
>(new ScreenshotTaker
).Pass());
67 #if defined(OS_CHROMEOS)
68 shell
->accelerator_controller()->SetImeControlDelegate(
69 scoped_ptr
<ash::ImeControlDelegate
>(new ImeController
).Pass());
70 ash::Shell::GetInstance()->high_contrast_controller()->SetEnabled(
71 chromeos::AccessibilityManager::Get()->IsHighContrastEnabled());
73 DCHECK(chromeos::MagnificationManager::Get());
74 bool magnifier_enabled
=
75 chromeos::MagnificationManager::Get()->IsMagnifierEnabled();
76 ash::MagnifierType magnifier_type
=
77 chromeos::MagnificationManager::Get()->GetMagnifierType();
78 ash::Shell::GetInstance()->magnification_controller()->
79 SetEnabled(magnifier_enabled
&& magnifier_type
== ash::MAGNIFIER_FULL
);
80 ash::Shell::GetInstance()->partial_magnification_controller()->
81 SetEnabled(magnifier_enabled
&& magnifier_type
== ash::MAGNIFIER_PARTIAL
);
83 if (!CommandLine::ForCurrentProcess()->HasSwitch(
84 switches::kDisableZeroBrowsersOpenForTests
)) {
85 chrome::StartKeepAlive();
88 ash::Shell::GetPrimaryRootWindow()->GetDispatcher()->host()->Show();
92 // If shutdown is initiated by |BrowserX11IOErrorHandler|, don't
93 // try to cleanup resources.
94 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers() &&
95 ash::Shell::HasInstance()) {
96 ash::Shell::DeleteInstance();
100 } // namespace chrome