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