- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / ash / chrome_browser_main_extra_parts_ash.cc
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 #include "ui/views/widget/desktop_aura/desktop_screen.h"
23
24 #if defined(FILE_MANAGER_EXTENSION)
25 #include "chrome/browser/ui/views/select_file_dialog_extension.h"
26 #include "chrome/browser/ui/views/select_file_dialog_extension_factory.h"
27 #endif
28
29 #if !defined(OS_CHROMEOS)
30 #include "ui/shell_dialogs/select_file_dialog.h"
31 #include "ui/shell_dialogs/shell_dialogs_delegate.h"
32 #endif
33
34 #if !defined(OS_CHROMEOS)
35 class ScreenTypeDelegateWin : public gfx::ScreenTypeDelegate {
36  public:
37   ScreenTypeDelegateWin() {}
38   virtual gfx::ScreenType GetScreenTypeForNativeView(
39       gfx::NativeView view) OVERRIDE {
40     return chrome::IsNativeViewInAsh(view) ?
41         gfx::SCREEN_TYPE_ALTERNATE :
42         gfx::SCREEN_TYPE_NATIVE;
43   }
44  private:
45   DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin);
46 };
47
48 class ShellDialogsDelegateWin : public ui::ShellDialogsDelegate {
49  public:
50   ShellDialogsDelegateWin() {}
51   virtual bool IsWindowInMetro(gfx::NativeWindow window) OVERRIDE {
52     return chrome::IsNativeViewInAsh(window);
53   }
54  private:
55   DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin);
56 };
57
58 base::LazyInstance<ShellDialogsDelegateWin> g_shell_dialogs_delegate;
59
60 #endif
61
62 ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() {
63 }
64
65 ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() {
66 }
67
68 void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
69   if (chrome::ShouldOpenAshOnStartup()) {
70     chrome::OpenAsh();
71   } else {
72 #if !defined(OS_CHROMEOS)
73     gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin);
74     ui::SelectFileDialog::SetShellDialogsDelegate(
75         &g_shell_dialogs_delegate.Get());
76 #endif
77   }
78 #if defined(OS_CHROMEOS)
79   // For OS_CHROMEOS, virtual keyboard needs to be initialized before profile
80   // initialized. Otherwise, virtual keyboard extension will not load at login
81   // screen.
82   if (keyboard::IsKeyboardEnabled())
83     keyboard::InitializeKeyboard();
84 #endif
85
86 #if defined(FILE_MANAGER_EXTENSION)
87   ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory);
88 #endif
89 }
90
91 void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
92   if (!ash::Shell::HasInstance())
93     return;
94
95   // Initialize TabScrubber after the Ash Shell has been initialized.
96   TabScrubber::GetInstance();
97   // Activate virtual keyboard after profile is initialized. It depends on the
98   // default profile.
99   ash::Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
100       ash::Shell::GetInstance()->keyboard_controller());
101 }
102
103 void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {
104   chrome::CloseAsh();
105 }