Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / ash_init.cc
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/ash_init.h"
6
7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/accelerometer/accelerometer_controller.h"
9 #include "ash/ash_switches.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 "base/command_line.h"
15 #include "chrome/browser/browser_shutdown.h"
16 #include "chrome/browser/lifetime/application_lifetime.h"
17 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
18 #include "chrome/browser/ui/ash/screenshot_taker.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "ui/aura/env.h"
22 #include "ui/aura/window_tree_host.h"
23
24 #if defined(OS_CHROMEOS)
25 #include "base/sys_info.h"
26 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
27 #include "chrome/browser/chromeos/accessibility/magnification_manager.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"
33 #endif
34
35 namespace chrome {
36
37 bool ShouldOpenAshOnStartup() {
38 #if defined(OS_CHROMEOS)
39   return true;
40 #endif
41   // TODO(scottmg): http://crbug.com/133312, will need this for Win8 too.
42   return CommandLine::ForCurrentProcess()->HasSwitch(switches::kOpenAsh);
43 }
44
45 void OpenAsh() {
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.
51     ui::HideHostCursor();
52   }
53
54   // Hide the mouse cursor completely at boot.
55   if (!chromeos::LoginState::Get()->IsUserLoggedIn())
56     ash::Shell::set_initially_hide_cursor(true);
57 #endif
58
59   // Shell takes ownership of ChromeShellDelegate.
60   ash::Shell* shell = ash::Shell::CreateInstance(new ChromeShellDelegate);
61   shell->accelerator_controller()->SetScreenshotDelegate(
62       scoped_ptr<ash::ScreenshotDelegate>(new ScreenshotTaker).Pass());
63   // TODO(flackr): Investigate exposing a blocking pool task runner to chromeos.
64   shell->accelerometer_controller()->Initialize(
65       content::BrowserThread::GetBlockingPool()->
66           GetTaskRunnerWithShutdownBehavior(
67               base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
68 #if defined(OS_CHROMEOS)
69   shell->accelerator_controller()->SetImeControlDelegate(
70       scoped_ptr<ash::ImeControlDelegate>(new ImeController).Pass());
71   shell->high_contrast_controller()->SetEnabled(
72       chromeos::AccessibilityManager::Get()->IsHighContrastEnabled());
73
74   DCHECK(chromeos::MagnificationManager::Get());
75   bool magnifier_enabled =
76       chromeos::MagnificationManager::Get()->IsMagnifierEnabled();
77   ash::MagnifierType magnifier_type =
78       chromeos::MagnificationManager::Get()->GetMagnifierType();
79   shell->magnification_controller()->
80       SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_FULL);
81   shell->partial_magnification_controller()->
82       SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_PARTIAL);
83
84   if (!CommandLine::ForCurrentProcess()->HasSwitch(
85       switches::kDisableZeroBrowsersOpenForTests)) {
86     chrome::IncrementKeepAliveCount();
87   }
88 #endif
89   ash::Shell::GetPrimaryRootWindow()->GetHost()->Show();
90 }
91
92 void CloseAsh() {
93   if (ash::Shell::HasInstance())
94     ash::Shell::DeleteInstance();
95 }
96
97 }  // namespace chrome