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/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" 25 26 #if defined(OS_CHROMEOS) 27 #include "base/chromeos/chromeos_version.h" 28 #include "chrome/browser/ui/ash/brightness_controller_chromeos.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" 34 #endif 35 36 namespace chrome { 37 38 bool ShouldOpenAshOnStartup() { 39 #if defined(OS_CHROMEOS) 40 return true; 41 #endif 42 // TODO(scottmg): http://crbug.com/133312, will need this for Win8 too. 43 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kOpenAsh); 44 } 45 46 void OpenAsh() { 47 #if defined(OS_CHROMEOS) 48 if (base::chromeos::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 55 // Hide the mouse cursor completely at boot. 56 if (!chromeos::LoginState::Get()->IsUserLoggedIn()) 57 ash::Shell::set_initially_hide_cursor(true); 58 #endif 59 60 // Shell takes ownership of ChromeShellDelegate. 61 ash::Shell* shell = ash::Shell::CreateInstance(new ChromeShellDelegate); 62 shell->event_rewriter_filter()->SetEventRewriterDelegate( 63 scoped_ptr<ash::EventRewriterDelegate>(new EventRewriter).Pass()); 64 shell->accelerator_controller()->SetScreenshotDelegate( 65 scoped_ptr<ash::ScreenshotDelegate>(new ScreenshotTaker).Pass()); 66 #if defined(OS_CHROMEOS) 67 shell->accelerator_controller()->SetBrightnessControlDelegate( 68 scoped_ptr<ash::BrightnessControlDelegate>( 69 new BrightnessController).Pass()); 70 shell->accelerator_controller()->SetImeControlDelegate( 71 scoped_ptr<ash::ImeControlDelegate>(new ImeController).Pass()); 72 ash::Shell::GetInstance()->high_contrast_controller()->SetEnabled( 73 chromeos::AccessibilityManager::Get()->IsHighContrastEnabled()); 74 75 DCHECK(chromeos::MagnificationManager::Get()); 76 bool magnifier_enabled = 77 chromeos::MagnificationManager::Get()->IsMagnifierEnabled(); 78 ash::MagnifierType magnifier_type = 79 chromeos::MagnificationManager::Get()->GetMagnifierType(); 80 ash::Shell::GetInstance()->magnification_controller()-> 81 SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_FULL); 82 ash::Shell::GetInstance()->partial_magnification_controller()-> 83 SetEnabled(magnifier_enabled && magnifier_type == ash::MAGNIFIER_PARTIAL); 84 85 if (!CommandLine::ForCurrentProcess()->HasSwitch( 86 switches::kDisableZeroBrowsersOpenForTests)) { 87 chrome::StartKeepAlive(); 88 } 89 #endif 90 ash::Shell::GetPrimaryRootWindow()->ShowRootWindow(); 91 } 92 93 void CloseAsh() { 94 // If shutdown is initiated by |BrowserX11IOErrorHandler|, don't 95 // try to cleanup resources. 96 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers() && 97 ash::Shell::HasInstance()) { 98 ash::Shell::DeleteInstance(); 99 } 100 } 101 102 } // namespace chrome 103