Upstream version 7.36.149.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 defined(USE_X11)
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.
52     ui::HideHostCursor();
53   }
54 #endif
55
56   // Hide the mouse cursor completely at boot.
57   if (!chromeos::LoginState::Get()->IsUserLoggedIn())
58     ash::Shell::set_initially_hide_cursor(true);
59 #endif
60
61   // Shell takes ownership of ChromeShellDelegate.
62   ash::Shell* shell = ash::Shell::CreateInstance(new ChromeShellDelegate);
63   shell->accelerator_controller()->SetScreenshotDelegate(
64       scoped_ptr<ash::ScreenshotDelegate>(new ScreenshotTaker).Pass());
65   // TODO(flackr): Investigate exposing a blocking pool task runner to chromeos.
66   shell->accelerometer_controller()->Initialize(
67       content::BrowserThread::GetBlockingPool()->
68           GetTaskRunnerWithShutdownBehavior(
69               base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
70 #if defined(OS_CHROMEOS)
71   shell->accelerator_controller()->SetImeControlDelegate(
72       scoped_ptr<ash::ImeControlDelegate>(new ImeController).Pass());
73   shell->high_contrast_controller()->SetEnabled(
74       chromeos::AccessibilityManager::Get()->IsHighContrastEnabled());
75
76   DCHECK(chromeos::MagnificationManager::Get());
77   bool magnifier_enabled =
78       chromeos::MagnificationManager::Get()->IsMagnifierEnabled();
79   ash::MagnifierType magnifier_type =
80       chromeos::MagnificationManager::Get()->GetMagnifierType();
81   shell->magnification_controller()->
82       SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_FULL);
83   shell->partial_magnification_controller()->
84       SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_PARTIAL);
85
86   if (!CommandLine::ForCurrentProcess()->HasSwitch(
87       switches::kDisableZeroBrowsersOpenForTests)) {
88     chrome::IncrementKeepAliveCount();
89   }
90 #endif
91   ash::Shell::GetPrimaryRootWindow()->GetHost()->Show();
92 }
93
94 void CloseAsh() {
95   if (ash::Shell::HasInstance())
96     ash::Shell::DeleteInstance();
97 }
98
99 }  // namespace chrome