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 "ui/views/examples/content_client/examples_browser_main_parts.h" 6 7 #include "base/bind.h" 8 #include "base/command_line.h" 9 #include "base/message_loop/message_loop.h" 10 #include "base/run_loop.h" 11 #include "base/strings/string_number_conversions.h" 12 #include "base/threading/thread.h" 13 #include "base/threading/thread_restrictions.h" 14 #include "content/public/common/content_switches.h" 15 #include "content/shell/browser/shell_browser_context.h" 16 #include "ui/base/ime/input_method_initializer.h" 17 #include "ui/views/examples/examples_window_with_content.h" 18 #include "ui/views/focus/accelerator_handler.h" 19 #include "ui/views/test/desktop_test_views_delegate.h" 20 #include "url/gurl.h" 21 22 #if defined(USE_AURA) 23 #include "ui/aura/env.h" 24 #include "ui/gfx/screen.h" 25 #include "ui/views/widget/desktop_aura/desktop_screen.h" 26 #include "ui/views/widget/native_widget_aura.h" 27 #endif 28 29 #if defined(OS_CHROMEOS) 30 #include "ui/aura/root_window.h" 31 #include "ui/aura/test/test_screen.h" 32 #include "ui/aura/window.h" 33 #include "ui/wm/test/wm_test_helper.h" 34 #endif 35 36 namespace views { 37 namespace examples { 38 39 ExamplesBrowserMainParts::ExamplesBrowserMainParts( 40 const content::MainFunctionParams& parameters) { 41 } 42 43 ExamplesBrowserMainParts::~ExamplesBrowserMainParts() { 44 } 45 46 void ExamplesBrowserMainParts::PreMainMessageLoopRun() { 47 ui::InitializeInputMethodForTesting(); 48 browser_context_.reset(new content::ShellBrowserContext(false, NULL)); 49 50 gfx::NativeView window_context = NULL; 51 #if defined(OS_CHROMEOS) 52 gfx::Screen::SetScreenInstance( 53 gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create()); 54 // Set up basic pieces of views::corewm. 55 wm_test_helper_.reset(new wm::WMTestHelper(gfx::Size(800, 600))); 56 // Ensure the X window gets mapped. 57 wm_test_helper_->root_window()->host()->Show(); 58 // Ensure Aura knows where to open new windows. 59 window_context = wm_test_helper_->root_window()->window(); 60 #elif defined(USE_AURA) 61 aura::Env::CreateInstance(); 62 gfx::Screen::SetScreenInstance( 63 gfx::SCREEN_TYPE_NATIVE, CreateDesktopScreen()); 64 #endif 65 views_delegate_.reset(new DesktopTestViewsDelegate); 66 67 ShowExamplesWindowWithContent( 68 QUIT_ON_CLOSE, browser_context_.get(), window_context); 69 } 70 71 void ExamplesBrowserMainParts::PostMainMessageLoopRun() { 72 browser_context_.reset(); 73 #if defined(OS_CHROMEOS) 74 wm_test_helper_.reset(); 75 #endif 76 views_delegate_.reset(); 77 #if defined(USE_AURA) 78 aura::Env::DeleteInstance(); 79 #endif 80 } 81 82 bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) { 83 // xxx: Hax here because this kills event handling. 84 #if !defined(USE_AURA) 85 AcceleratorHandler accelerator_handler; 86 base::RunLoop run_loop(&accelerator_handler); 87 #else 88 base::RunLoop run_loop; 89 #endif 90 run_loop.Run(); 91 return true; 92 } 93 94 } // namespace examples 95 } // namespace views 96