blob: 9a161914485d8c7b6cf110d7f0d3ad6625220b15 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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"
Ben Murdochca12bfa2013-07-23 11:17:05 +01009#include "base/message_loop/message_loop.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000010#include "base/run_loop.h"
Torne (Richard Coles)5e3f23d2013-06-11 16:24:11 +010011#include "base/strings/string_number_conversions.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000012#include "base/threading/thread.h"
13#include "base/threading/thread_restrictions.h"
14#include "content/public/common/content_switches.h"
Torne (Richard Coles)3551c9c2013-08-23 16:39:15 +010015#include "content/shell/browser/shell_browser_context.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000016#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"
Ben Murdocheb525c52013-07-10 11:40:50 +010019#include "url/gurl.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000020
21#if defined(USE_AURA)
Torne (Richard Coles)58218062012-11-14 11:43:16 +000022#include "ui/aura/env.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000023#include "ui/gfx/screen.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000024#include "ui/views/widget/desktop_aura/desktop_screen.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000025#include "ui/views/widget/native_widget_aura.h"
26#endif
27
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010028#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"
32#endif
33
Torne (Richard Coles)58218062012-11-14 11:43:16 +000034namespace views {
35namespace examples {
36
37ExamplesBrowserMainParts::ExamplesBrowserMainParts(
38 const content::MainFunctionParams& parameters) {
39}
40
41ExamplesBrowserMainParts::~ExamplesBrowserMainParts() {
42}
43
44void ExamplesBrowserMainParts::PreMainMessageLoopRun() {
Ben Murdocheb525c52013-07-10 11:40:50 +010045 browser_context_.reset(new content::ShellBrowserContext(false, NULL));
Torne (Richard Coles)58218062012-11-14 11:43:16 +000046
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010047 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)
Torne (Richard Coles)58218062012-11-14 11:43:16 +000058 gfx::Screen::SetScreenInstance(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000059 gfx::SCREEN_TYPE_NATIVE, CreateDesktopScreen());
Torne (Richard Coles)58218062012-11-14 11:43:16 +000060#endif
61 views_delegate_.reset(new DesktopTestViewsDelegate);
62
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010063 ShowExamplesWindowWithContent(
64 QUIT_ON_CLOSE, browser_context_.get(), window_context);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000065}
66
67void ExamplesBrowserMainParts::PostMainMessageLoopRun() {
68 browser_context_.reset();
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010069#if defined(OS_CHROMEOS)
70 minimal_shell_.reset();
71#endif
Torne (Richard Coles)58218062012-11-14 11:43:16 +000072 views_delegate_.reset();
73#if defined(USE_AURA)
Torne (Richard Coles)58218062012-11-14 11:43:16 +000074 aura::Env::DeleteInstance();
75#endif
76}
77
78bool 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);
83#else
84 base::RunLoop run_loop;
85#endif
86 run_loop.Run();
87 return true;
88}
89
90} // namespace examples
91} // namespace views