chrome_browser_main_extra_parts_ash.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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/shell.h" 8#include "base/command_line.h" 9#include "base/lazy_instance.h" 10#include "chrome/browser/chrome_browser_main.h" 11#include "chrome/browser/toolkit_extra_parts.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/views/widget/desktop_aura/desktop_screen.h" 20 21#if defined(FILE_MANAGER_EXTENSION) 22#include "chrome/browser/ui/views/select_file_dialog_extension.h" 23#include "chrome/browser/ui/views/select_file_dialog_extension_factory.h" 24#endif 25 26#if !defined(OS_CHROMEOS) 27#include "ui/shell_dialogs/select_file_dialog.h" 28#include "ui/shell_dialogs/shell_dialogs_delegate.h" 29#endif 30 31#if !defined(OS_CHROMEOS) 32class ScreenTypeDelegateWin : public gfx::ScreenTypeDelegate { 33 public: 34 ScreenTypeDelegateWin() {} 35 virtual gfx::ScreenType GetScreenTypeForNativeView( 36 gfx::NativeView view) OVERRIDE { 37 return chrome::IsNativeViewInAsh(view) ? 38 gfx::SCREEN_TYPE_ALTERNATE : 39 gfx::SCREEN_TYPE_NATIVE; 40 } 41 private: 42 DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateWin); 43}; 44 45class ShellDialogsDelegateWin : public ui::ShellDialogsDelegate { 46 public: 47 ShellDialogsDelegateWin() {} 48 virtual bool IsWindowInMetro(gfx::NativeWindow window) OVERRIDE { 49 return chrome::IsNativeViewInAsh(window); 50 } 51 private: 52 DISALLOW_COPY_AND_ASSIGN(ShellDialogsDelegateWin); 53}; 54 55base::LazyInstance<ShellDialogsDelegateWin> g_shell_dialogs_delegate; 56 57#endif 58 59ChromeBrowserMainExtraPartsAsh::ChromeBrowserMainExtraPartsAsh() { 60} 61 62ChromeBrowserMainExtraPartsAsh::~ChromeBrowserMainExtraPartsAsh() { 63} 64 65void ChromeBrowserMainExtraPartsAsh::PreProfileInit() { 66 // For OS_CHROMEOS, initialization order needs to be carefully controlled, 67 // so OpenAsh is called from ChromeBrowserMainPartsChromeos. 68#if !defined(OS_CHROMEOS) 69 if (chrome::ShouldOpenAshOnStartup()) { 70 chrome::OpenAsh(); 71 } else { 72 gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateWin); 73 ui::SelectFileDialog::SetShellDialogsDelegate( 74 &g_shell_dialogs_delegate.Get()); 75 } 76#endif 77 78#if defined(FILE_MANAGER_EXTENSION) 79 ui::SelectFileDialog::SetFactory(new SelectFileDialogExtensionFactory); 80#endif 81} 82 83void ChromeBrowserMainExtraPartsAsh::PostProfileInit() { 84 // Initialize TabScrubber after the Ash Shell has been initialized. 85 if (ash::Shell::HasInstance() && 86 !CommandLine::ForCurrentProcess()->HasSwitch( 87 switches::kAshDisableTabScrubbing)) { 88 TabScrubber::GetInstance(); 89 } 90} 91 92void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() { 93 // For OS_CHROMEOS, CloseAsh is called from ChromeBrowserMainPartsChromeos. 94#if !defined(OS_CHROMEOS) 95 chrome::CloseAsh(); 96#endif 97} 98 99namespace chrome { 100 101void AddAshToolkitExtraParts(ChromeBrowserMainParts* main_parts) { 102 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); 103} 104 105} // namespace chrome 106