OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views_content_client/views_content_client_main_parts.h" | 5 #include "ui/views_content_client/views_content_client_main_parts_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "content/public/browser/context_factory.h" | 14 #include "content/public/browser/context_factory.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "content/shell/browser/shell_browser_context.h" | 16 #include "content/shell/browser/shell_browser_context.h" |
17 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
18 #include "ui/base/ime/input_method_initializer.h" | 18 #include "ui/base/ime/input_method_initializer.h" |
19 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
20 #include "ui/views/test/desktop_test_views_delegate.h" | 20 #include "ui/views/test/desktop_test_views_delegate.h" |
21 #include "ui/views/widget/native_widget_aura.h" | 21 #include "ui/views/widget/native_widget_aura.h" |
22 #include "ui/views_content_client/views_content_client.h" | 22 #include "ui/views_content_client/views_content_client.h" |
23 #include "ui/wm/core/wm_state.h" | 23 #include "ui/wm/core/wm_state.h" |
24 | 24 |
25 #if defined(OS_CHROMEOS) | |
26 #include "ui/aura/test/test_screen.h" | 25 #include "ui/aura/test/test_screen.h" |
27 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
28 #include "ui/aura/window_event_dispatcher.h" | 27 #include "ui/aura/window_event_dispatcher.h" |
29 #include "ui/wm/test/wm_test_helper.h" | 28 #include "ui/wm/test/wm_test_helper.h" |
30 #else // !defined(OS_CHROMEOS) | |
31 #include "ui/views/widget/desktop_aura/desktop_screen.h" | |
32 #endif | |
33 | 29 |
34 namespace ui { | 30 namespace ui { |
35 | 31 |
36 ViewsContentClientMainParts::ViewsContentClientMainParts( | 32 namespace { |
| 33 |
| 34 class ViewsContentClientMainPartsChromeOS |
| 35 : public ViewsContentClientMainPartsAura { |
| 36 public: |
| 37 ViewsContentClientMainPartsChromeOS( |
| 38 const content::MainFunctionParams& content_params, |
| 39 ViewsContentClient* views_content_client); |
| 40 virtual ~ViewsContentClientMainPartsChromeOS() {} |
| 41 |
| 42 // content::BrowserMainParts: |
| 43 virtual void PreMainMessageLoopRun() OVERRIDE; |
| 44 virtual void PostMainMessageLoopRun() OVERRIDE; |
| 45 |
| 46 private: |
| 47 // Enable a minimal set of views::corewm to be initialized. |
| 48 scoped_ptr<wm::WMTestHelper> wm_test_helper_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsAura); |
| 51 }; |
| 52 |
| 53 ViewsContentClientMainPartsChromeOS::ViewsContentClientMainPartsChromeOS( |
37 const content::MainFunctionParams& content_params, | 54 const content::MainFunctionParams& content_params, |
38 ViewsContentClient* views_content_client) | 55 ViewsContentClient* views_content_client) |
39 : views_content_client_(views_content_client) { | 56 : ViewsContentClientMainPartsAura(content_params, views_content_client) { |
40 } | 57 } |
41 | 58 |
42 ViewsContentClientMainParts::~ViewsContentClientMainParts() { | 59 void ViewsContentClientMainPartsChromeOS::PreMainMessageLoopRun() { |
43 } | 60 ViewsContentClientMainPartsAura::PreMainMessageLoopRun(); |
44 | 61 |
45 void ViewsContentClientMainParts::ToolkitInitialized() { | |
46 wm_state_.reset(new ::wm::WMState); | |
47 } | |
48 | |
49 void ViewsContentClientMainParts::PreMainMessageLoopRun() { | |
50 ui::InitializeInputMethodForTesting(); | |
51 browser_context_.reset(new content::ShellBrowserContext(false, NULL)); | |
52 | |
53 gfx::NativeView window_context = NULL; | |
54 #if defined(OS_CHROMEOS) | |
55 gfx::Screen::SetScreenInstance( | 62 gfx::Screen::SetScreenInstance( |
56 gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create()); | 63 gfx::SCREEN_TYPE_NATIVE, aura::TestScreen::Create()); |
57 // Set up basic pieces of views::corewm. | 64 // Set up basic pieces of views::corewm. |
58 wm_test_helper_.reset(new ::wm::WMTestHelper(gfx::Size(800, 600), | 65 wm_test_helper_.reset(new ::wm::WMTestHelper(gfx::Size(800, 600), |
59 content::GetContextFactory())); | 66 content::GetContextFactory())); |
60 // Ensure the X window gets mapped. | 67 // Ensure the X window gets mapped. |
61 wm_test_helper_->host()->Show(); | 68 wm_test_helper_->host()->Show(); |
| 69 |
62 // Ensure Aura knows where to open new windows. | 70 // Ensure Aura knows where to open new windows. |
63 window_context = wm_test_helper_->host()->window(); | 71 views_content_client()->task().Run(browser_context(), |
64 #else | 72 wm_test_helper_->host()->window()); |
65 aura::Env::CreateInstance(true); | |
66 gfx::Screen::SetScreenInstance( | |
67 gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); | |
68 #endif | |
69 views_delegate_.reset(new views::DesktopTestViewsDelegate); | |
70 | |
71 views_content_client_->task().Run(browser_context_.get(), window_context); | |
72 } | 73 } |
73 | 74 |
74 void ViewsContentClientMainParts::PostMainMessageLoopRun() { | 75 void ViewsContentClientMainParts::PostMainMessageLoopRun() { |
75 browser_context_.reset(); | |
76 #if defined(OS_CHROMEOS) | |
77 wm_test_helper_.reset(); | 76 wm_test_helper_.reset(); |
78 #endif | |
79 views_delegate_.reset(); | |
80 aura::Env::DeleteInstance(); | |
81 } | 77 } |
82 | 78 |
83 bool ViewsContentClientMainParts::MainMessageLoopRun(int* result_code) { | 79 } // namespace |
84 base::RunLoop run_loop; | |
85 run_loop.Run(); | |
86 return true; | |
87 } | |
88 | 80 |
89 } // namespace ui | 81 } // namespace ui |
OLD | NEW |