85ba9a28206eb8d35edbe9d6980189e3ebc80ac3
[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/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_controller.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_WIN)
34 #include "base/win/windows_version.h"
35 #endif
36
37 #if !defined(OS_CHROMEOS)
38 class ScreenTypeDelegateWin : public gfx::ScreenTypeDelegate {
39  public:
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;
46   }
47  private:
48   DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin);
49 };
50
51 class ShellDialogsDelegateWin : public ui::ShellDialogsDelegate {
52  public:
53   ShellDialogsDelegateWin() {}
54   virtual bool IsWindowInMetro(gfx::NativeWindow window) OVERRIDE {
55 #if defined(OS_WIN)
56     if (base::win::GetVersion() < base::win::VERSION_WIN8)
57       return false;
58 #endif
59     return chrome::IsNativeViewInAsh(window);
60   }
61  private:
62   DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin);
63 };
64
65 base::LazyInstance<ShellDialogsDelegateWin> g_shell_dialogs_delegate;
66
67 #endif
68
69 ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() {
70 }
71
72 ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() {
73 }
74
75 void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
76   if (chrome::ShouldOpenAshOnStartup()) {
77     chrome::OpenAsh(gfx::kNullAcceleratedWidget);
78
79 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
80   ash::Shell::GetInstance()->CreateShelf();
81   ash::Shell::GetInstance()->ShowShelf();
82 #endif
83   } else {
84 #if !defined(OS_CHROMEOS)
85     gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin);
86     ui::SelectFileDialog::SetShellDialogsDelegate(
87         g_shell_dialogs_delegate.Pointer());
88 #endif
89   }
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
93   // screen.
94   keyboard::InitializeKeyboard();
95 #endif
96
97 #if defined(OS_CHROMEOS)
98   ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory);
99 #endif
100 }
101
102 void ChromeBrowserMainExtraPartsAsh::PostProfileInit() {
103   if (!ash::Shell::HasInstance())
104     return;
105
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
109   // default profile.
110   ash::Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
111       keyboard::KeyboardController::GetInstance());
112 }
113
114 void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {
115   chrome::CloseAsh();
116 }