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.
5 #include "ui/views/examples/content_client/examples_browser_main_parts.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/views/examples/examples_window_with_content.h"
17 #include "ui/views/focus/accelerator_handler.h"
18 #include "ui/views/test/desktop_test_views_delegate.h"
22 #include "ui/aura/env.h"
23 #include "ui/gfx/screen.h"
24 #include "ui/views/widget/desktop_aura/desktop_screen.h"
25 #include "ui/views/widget/native_widget_aura.h"
28 #if defined(OS_CHROMEOS)
29 #include "ui/aura/root_window.h"
30 #include "ui/aura/test/test_screen.h"
31 #include "ui/shell/minimal_shell.h"
37 ExamplesBrowserMainParts::ExamplesBrowserMainParts(
38 const content::MainFunctionParams& parameters) {
41 ExamplesBrowserMainParts::~ExamplesBrowserMainParts() {
44 void ExamplesBrowserMainParts::PreMainMessageLoopRun() {
45 browser_context_.reset(new content::ShellBrowserContext(false, NULL));
47 gfx::NativeView window_context = NULL;
48 #if defined(OS_CHROMEOS)
49 gfx::Screen::SetScreenInstance(
50 gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create());
51 // Set up basic pieces of views::corewm.
52 minimal_shell_.reset(new shell::MinimalShell(gfx::Size(800, 600)));
53 // Ensure the X window gets mapped.
54 minimal_shell_->root_window()->ShowRootWindow();
55 // Ensure Aura knows where to open new windows.
56 window_context = minimal_shell_->root_window();
57 #elif defined(USE_AURA)
58 gfx::Screen::SetScreenInstance(
59 gfx::SCREEN_TYPE_NATIVE, CreateDesktopScreen());
61 views_delegate_.reset(new DesktopTestViewsDelegate);
63 ShowExamplesWindowWithContent(
64 QUIT_ON_CLOSE, browser_context_.get(), window_context);
67 void ExamplesBrowserMainParts::PostMainMessageLoopRun() {
68 browser_context_.reset();
69 #if defined(OS_CHROMEOS)
70 minimal_shell_.reset();
72 views_delegate_.reset();
74 aura::Env::DeleteInstance();
78 bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) {
79 // xxx: Hax here because this kills event handling.
80 #if !defined(USE_AURA)
81 AcceleratorHandler accelerator_handler;
82 base::RunLoop run_loop(&accelerator_handler);
84 base::RunLoop run_loop;
90 } // namespace examples