chrome_browser_main_extra_parts_ash.cc revision effb81e5f8246d0db0270817048dc992db66e9fb
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/views/ash/chrome_browser_main_extra_parts_ash.h" 6 7#include "ash/root_window_controller.h" 8#include "ash/session_state_delegate.h" 9#include "ash/shell.h" 10#include "base/command_line.h" 11#include "base/lazy_instance.h" 12#include "chrome/browser/chrome_browser_main.h" 13#include "chrome/browser/ui/ash/ash_init.h" 14#include "chrome/browser/ui/ash/ash_util.h" 15#include "chrome/browser/ui/views/ash/tab_scrubber.h" 16#include "chrome/common/chrome_switches.h" 17#include "ui/aura/env.h" 18#include "ui/gfx/screen.h" 19#include "ui/gfx/screen_type_delegate.h" 20#include "ui/keyboard/keyboard.h" 21#include "ui/keyboard/keyboard_util.h" 22 23#if defined(OS_CHROMEOS) 24#include "chrome/browser/ui/views/select_file_dialog_extension.h" 25#include "chrome/browser/ui/views/select_file_dialog_extension_factory.h" 26#endif 27 28#if !defined(OS_CHROMEOS) 29#include "ui/shell_dialogs/select_file_dialog.h" 30#include "ui/shell_dialogs/shell_dialogs_delegate.h" 31#endif 32 33#if !defined(OS_CHROMEOS) 34class ScreenTypeDelegateWin : public gfx::ScreenTypeDelegate { 35 public: 36 ScreenTypeDelegateWin() {} 37 virtual gfx::ScreenType GetScreenTypeForNativeView( 38 gfx::NativeView view) OVERRIDE { 39 return chrome::IsNativeViewInAsh(view) ? 40 gfx::SCREEN_TYPE_ALTERNATE : 41 gfx::SCREEN_TYPE_NATIVE; 42 } 43 private: 44 DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin); 45}; 46 47class ShellDialogsDelegateWin : public ui::ShellDialogsDelegate { 48 public: 49 ShellDialogsDelegateWin() {} 50 virtual bool IsWindowInMetro(gfx::NativeWindow window) OVERRIDE { 51 return chrome::IsNativeViewInAsh(window); 52 } 53 private: 54 DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin); 55}; 56 57base::LazyInstance<ShellDialogsDelegateWin> g_shell_dialogs_delegate; 58 59#endif 60 61ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() { 62} 63 64ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() { 65} 66 67void ChromeBrowserMainExtraPartsAsh::PreProfileInit() { 68 if (chrome::ShouldOpenAshOnStartup()) { 69 chrome::OpenAsh(); 70 } else { 71#if !defined(OS_CHROMEOS) 72 gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin); 73 ui::SelectFileDialog::SetShellDialogsDelegate( 74 g_shell_dialogs_delegate.Pointer()); 75#endif 76 } 77#if defined(OS_CHROMEOS) 78 // For OS_CHROMEOS, virtual keyboard needs to be initialized before profile 79 // initialized. Otherwise, virtual keyboard extension will not load at login 80 // screen. 81 keyboard::InitializeKeyboard(); 82#endif 83 84#if defined(OS_CHROMEOS) 85 ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory); 86#endif 87} 88 89void ChromeBrowserMainExtraPartsAsh::PostProfileInit() { 90 if (!ash::Shell::HasInstance()) 91 return; 92 93 // Initialize TabScrubber after the Ash Shell has been initialized. 94 TabScrubber::GetInstance(); 95 // Activate virtual keyboard after profile is initialized. It depends on the 96 // default profile. If keyboard usability experiment flag is set, defer the 97 // activation to UpdateWindow() in virtual_keyboard_window_controller.cc. 98 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) { 99 ash::Shell::GetPrimaryRootWindowController()->ActivateKeyboard( 100 ash::Shell::GetInstance()->keyboard_controller()); 101 } 102} 103 104void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() { 105 chrome::CloseAsh(); 106} 107