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/views/ash/chrome_browser_main_extra_parts_ash.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/session/session_state_delegate.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_controller.h"
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"
28 #if !defined(OS_CHROMEOS)
29 #include "ui/shell_dialogs/select_file_dialog.h"
30 #include "ui/shell_dialogs/shell_dialogs_delegate.h"
34 #include "base/win/windows_version.h"
37 #if !defined(OS_CHROMEOS)
38 class ScreenTypeDelegateWin : public gfx::ScreenTypeDelegate {
40 ScreenTypeDelegateWin() {}
41 virtual gfx::ScreenType GetScreenTypeForNativeView(
42 gfx::NativeView view) OVERRIDE {
43 return chrome::IsNativeViewInAsh(view) ?
44 gfx::SCREEN_TYPE_ALTERNATE :
45 gfx::SCREEN_TYPE_NATIVE;
48 DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin);
51 class ShellDialogsDelegateWin : public ui::ShellDialogsDelegate {
53 ShellDialogsDelegateWin() {}
54 virtual bool IsWindowInMetro(gfx::NativeWindow window) OVERRIDE {
56 if (base::win::GetVersion() < base::win::VERSION_WIN8)
59 return chrome::IsNativeViewInAsh(window);
62 DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin);
65 base::LazyInstance<ShellDialogsDelegateWin> g_shell_dialogs_delegate;
69 ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() {
72 ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() {
75 void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
76 if (chrome::ShouldOpenAshOnStartup()) {
77 chrome::OpenAsh(gfx::kNullAcceleratedWidget);
79 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
80 ash::Shell::GetInstance()->CreateShelf();
81 ash::Shell::GetInstance()->ShowShelf();
84 #if !defined(OS_CHROMEOS)
85 gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin);
86 ui::SelectFileDialog::SetShellDialogsDelegate(
87 g_shell_dialogs_delegate.Pointer());
90 #if defined(OS_CHROMEOS)
91 // For OS_CHROMEOS, virtual keyboard needs to be initialized before profile
92 // initialized. Otherwise, virtual keyboard extension will not load at login
94 keyboard::InitializeKeyboard();
97 #if defined(OS_CHROMEOS)
98 ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory);
102 void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
103 if (!ash::Shell::HasInstance())
106 // Initialize TabScrubber after the Ash Shell has been initialized.
107 TabScrubber::GetInstance();
108 // Activate virtual keyboard after profile is initialized. It depends on the
110 ash::Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
111 keyboard::KeyboardController::GetInstance());
114 void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {