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/session_state_delegate.h"
9 #include "base/command_line.h"
10 #include "base/lazy_instance.h"
11 #include "chrome/browser/chrome_browser_main.h"
12 #include "chrome/browser/ui/ash/ash_init.h"
13 #include "chrome/browser/ui/ash/ash_util.h"
14 #include "chrome/browser/ui/views/ash/tab_scrubber.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "ui/aura/env.h"
17 #include "ui/gfx/screen.h"
18 #include "ui/gfx/screen_type_delegate.h"
19 #include "ui/keyboard/keyboard.h"
20 #include "ui/keyboard/keyboard_util.h"
21 #include "ui/views/widget/desktop_aura/desktop_screen.h"
23 #if defined(FILE_MANAGER_EXTENSION)
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"
33 #if !defined(OS_CHROMEOS)
34 class ScreenTypeDelegateWin
: public gfx::ScreenTypeDelegate
{
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
;
44 DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin
);
47 class ShellDialogsDelegateWin
: public ui::ShellDialogsDelegate
{
49 ShellDialogsDelegateWin() {}
50 virtual bool IsWindowInMetro(gfx::NativeWindow window
) OVERRIDE
{
51 return chrome::IsNativeViewInAsh(window
);
54 DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin
);
57 base::LazyInstance
<ShellDialogsDelegateWin
> g_shell_dialogs_delegate
;
61 ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() {
64 ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() {
67 void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
68 if (chrome::ShouldOpenAshOnStartup()) {
71 #if !defined(OS_CHROMEOS)
72 gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin
);
73 ui::SelectFileDialog::SetShellDialogsDelegate(
74 &g_shell_dialogs_delegate
.Get());
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
81 if (keyboard::IsKeyboardEnabled())
82 keyboard::InitializeKeyboard();
85 #if defined(FILE_MANAGER_EXTENSION)
86 ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory
);
90 void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
91 // Initialize TabScrubber after the Ash Shell has been initialized.
92 if (ash::Shell::HasInstance() &&
93 !CommandLine::ForCurrentProcess()->HasSwitch(
94 switches::kAshDisableTabScrubbing
)) {
95 TabScrubber::GetInstance();
99 void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {