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 gfx::ScreenType
GetScreenTypeForNativeView(gfx::NativeView view
) override
{
42 return chrome::IsNativeViewInAsh(view
) ?
43 gfx::SCREEN_TYPE_ALTERNATE
:
44 gfx::SCREEN_TYPE_NATIVE
;
47 DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin
);
50 class ShellDialogsDelegateWin
: public ui::ShellDialogsDelegate
{
52 ShellDialogsDelegateWin() {}
53 bool IsWindowInMetro(gfx::NativeWindow window
) override
{
55 if (base::win::GetVersion() < base::win::VERSION_WIN8
)
58 return chrome::IsNativeViewInAsh(window
);
61 DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin
);
64 base::LazyInstance
<ShellDialogsDelegateWin
> g_shell_dialogs_delegate
;
68 ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() {
71 ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() {
74 void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
75 if (chrome::ShouldOpenAshOnStartup()) {
76 chrome::OpenAsh(gfx::kNullAcceleratedWidget
);
78 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
79 ash::Shell::GetInstance()->CreateShelf();
80 ash::Shell::GetInstance()->ShowShelf();
83 #if !defined(OS_CHROMEOS)
84 gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin
);
85 ui::SelectFileDialog::SetShellDialogsDelegate(
86 g_shell_dialogs_delegate
.Pointer());
89 #if defined(OS_CHROMEOS)
90 // For OS_CHROMEOS, virtual keyboard needs to be initialized before profile
91 // initialized. Otherwise, virtual keyboard extension will not load at login
93 keyboard::InitializeKeyboard();
96 #if defined(OS_CHROMEOS)
97 ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory
);
101 void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
102 if (!ash::Shell::HasInstance())
105 // Initialize TabScrubber after the Ash Shell has been initialized.
106 TabScrubber::GetInstance();
107 // Activate virtual keyboard after profile is initialized. It depends on the
109 ash::Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
110 keyboard::KeyboardController::GetInstance());
113 void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {