chrome_browser_main_extra_parts_ash.cc revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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/session_state_delegate.h"
8#include "ash/shell.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"
22
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"
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_CHROMEOS)
34class ScreenTypeDelegateWin : public gfx::ScreenTypeDelegate {
35 public:
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;
42  }
43 private:
44  DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin);
45};
46
47class ShellDialogsDelegateWin : public ui::ShellDialogsDelegate {
48 public:
49  ShellDialogsDelegateWin() {}
50  virtual bool IsWindowInMetro(gfx::NativeWindow window) OVERRIDE {
51    return chrome::IsNativeViewInAsh(window);
52  }
53 private:
54  DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin);
55};
56
57base::LazyInstance<ShellDialogsDelegateWin> g_shell_dialogs_delegate;
58
59#endif
60
61ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() {
62}
63
64ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() {
65}
66
67void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
68  if (chrome::ShouldOpenAshOnStartup()) {
69    chrome::OpenAsh();
70  } else {
71#if !defined(OS_CHROMEOS)
72    gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin);
73    ui::SelectFileDialog::SetShellDialogsDelegate(
74        &g_shell_dialogs_delegate.Get());
75#endif
76  }
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
80  // screen.
81  if (keyboard::IsKeyboardEnabled())
82    keyboard::InitializeKeyboard();
83#endif
84
85#if defined(FILE_MANAGER_EXTENSION)
86  ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory);
87#endif
88}
89
90void 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();
96  }
97}
98
99void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {
100  chrome::CloseAsh();
101}
102