Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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" |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame^] | 9 | #include "base/message_loop/message_loop.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 10 | #include "base/run_loop.h" |
Torne (Richard Coles) | 5e3f23d | 2013-06-11 16:24:11 +0100 | [diff] [blame] | 11 | #include "base/strings/string_number_conversions.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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/shell_browser_context.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 19 | #include "url/gurl.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 20 | |
| 21 | #if defined(USE_AURA) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 22 | #include "ui/aura/env.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 23 | #include "ui/gfx/screen.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 24 | #include "ui/views/widget/desktop_aura/desktop_screen.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 25 | #include "ui/views/widget/native_widget_aura.h" |
| 26 | #endif |
| 27 | |
| 28 | namespace views { |
| 29 | namespace examples { |
| 30 | |
| 31 | ExamplesBrowserMainParts::ExamplesBrowserMainParts( |
| 32 | const content::MainFunctionParams& parameters) { |
| 33 | } |
| 34 | |
| 35 | ExamplesBrowserMainParts::~ExamplesBrowserMainParts() { |
| 36 | } |
| 37 | |
| 38 | void ExamplesBrowserMainParts::PreMainMessageLoopRun() { |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 39 | browser_context_.reset(new content::ShellBrowserContext(false, NULL)); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 40 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 41 | #if !defined(OS_CHROMEOS) && defined(USE_AURA) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 42 | gfx::Screen::SetScreenInstance( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 43 | gfx::SCREEN_TYPE_NATIVE, CreateDesktopScreen()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 44 | #endif |
| 45 | views_delegate_.reset(new DesktopTestViewsDelegate); |
| 46 | |
| 47 | ShowExamplesWindowWithContent(QUIT_ON_CLOSE, browser_context_.get()); |
| 48 | } |
| 49 | |
| 50 | void ExamplesBrowserMainParts::PostMainMessageLoopRun() { |
| 51 | browser_context_.reset(); |
| 52 | views_delegate_.reset(); |
| 53 | #if defined(USE_AURA) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 54 | aura::Env::DeleteInstance(); |
| 55 | #endif |
| 56 | } |
| 57 | |
| 58 | bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 59 | // xxx: Hax here because this kills event handling. |
| 60 | #if !defined(USE_AURA) |
| 61 | AcceleratorHandler accelerator_handler; |
| 62 | base::RunLoop run_loop(&accelerator_handler); |
| 63 | #else |
| 64 | base::RunLoop run_loop; |
| 65 | #endif |
| 66 | run_loop.Run(); |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | } // namespace examples |
| 71 | } // namespace views |