OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/launcher/launch_instance.h" | 5 #include "services/ui/launcher/launch_instance.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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
11 #include "mojo/application/application_runner_chromium.h" | 11 #include "mojo/application/application_runner_chromium.h" |
12 #include "mojo/public/c/system/main.h" | 12 #include "mojo/public/c/system/main.h" |
13 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
14 #include "mojo/public/cpp/application/connect.h" | 14 #include "mojo/public/cpp/application/connect.h" |
15 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" | |
16 #include "services/ui/launcher/launcher_view_tree.h" | 15 #include "services/ui/launcher/launcher_view_tree.h" |
17 | 16 |
18 namespace launcher { | 17 namespace launcher { |
19 | 18 |
20 LaunchInstance::LaunchInstance(mojo::ApplicationImpl* app_impl, | 19 LaunchInstance::LaunchInstance(mojo::ApplicationImpl* app_impl, |
21 const std::string& app_url, | 20 mojo::NativeViewportPtr viewport, |
| 21 mojo::ui::ViewProviderPtr view_provider, |
22 mojo::gfx::composition::Compositor* compositor, | 22 mojo::gfx::composition::Compositor* compositor, |
23 mojo::ui::ViewManager* view_manager, | 23 mojo::ui::ViewManager* view_manager, |
24 const base::Closure& shutdown_callback) | 24 const base::Closure& shutdown_callback) |
25 : app_impl_(app_impl), | 25 : app_impl_(app_impl), |
26 app_url_(app_url), | 26 viewport_(viewport.Pass()), |
| 27 view_provider_(view_provider.Pass()), |
27 compositor_(compositor), | 28 compositor_(compositor), |
28 view_manager_(view_manager), | 29 view_manager_(view_manager), |
29 shutdown_callback_(shutdown_callback), | 30 shutdown_callback_(shutdown_callback), |
30 viewport_event_dispatcher_binding_(this) {} | 31 viewport_event_dispatcher_binding_(this) {} |
31 | 32 |
32 LaunchInstance::~LaunchInstance() {} | 33 LaunchInstance::~LaunchInstance() {} |
33 | 34 |
34 void LaunchInstance::Launch() { | 35 void LaunchInstance::Launch() { |
35 DVLOG(1) << "Launching " << app_url_; | |
36 TRACE_EVENT0("launcher", __func__); | 36 TRACE_EVENT0("launcher", __func__); |
37 | 37 |
38 InitViewport(); | 38 InitViewport(); |
39 | 39 |
40 mojo::ui::ViewProviderPtr client_view_provider; | 40 view_provider_->CreateView(GetProxy(&client_view_owner_), nullptr); |
41 mojo::ConnectToService(app_impl_->shell(), app_url_, | 41 view_provider_.reset(); |
42 GetProxy(&client_view_provider)); | |
43 | |
44 client_view_provider->CreateView(GetProxy(&client_view_owner_), nullptr); | |
45 } | 42 } |
46 | 43 |
47 void LaunchInstance::InitViewport() { | 44 void LaunchInstance::InitViewport() { |
48 mojo::ConnectToService(app_impl_->shell(), "mojo:native_viewport_service", | 45 if (!viewport_) { |
49 GetProxy(&viewport_)); | 46 mojo::ConnectToService(app_impl_->shell(), "mojo:native_viewport_service", |
| 47 GetProxy(&viewport_)); |
| 48 } |
50 viewport_.set_connection_error_handler(base::Bind( | 49 viewport_.set_connection_error_handler(base::Bind( |
51 &LaunchInstance::OnViewportConnectionError, base::Unretained(this))); | 50 &LaunchInstance::OnViewportConnectionError, base::Unretained(this))); |
52 | 51 |
53 mojo::NativeViewportEventDispatcherPtr dispatcher; | 52 mojo::NativeViewportEventDispatcherPtr dispatcher; |
54 viewport_event_dispatcher_binding_.Bind(GetProxy(&dispatcher)); | 53 viewport_event_dispatcher_binding_.Bind(GetProxy(&dispatcher)); |
55 viewport_->SetEventDispatcher(dispatcher.Pass()); | 54 viewport_->SetEventDispatcher(dispatcher.Pass()); |
56 | 55 |
57 // Match the Nexus 5 aspect ratio initially. | 56 // Match the Nexus 5 aspect ratio initially. |
58 auto size = mojo::Size::New(); | 57 auto size = mojo::Size::New(); |
59 size->width = 320; | 58 size->width = 320; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 97 } |
99 | 98 |
100 void LaunchInstance::OnEvent(mojo::EventPtr event, | 99 void LaunchInstance::OnEvent(mojo::EventPtr event, |
101 const mojo::Callback<void()>& callback) { | 100 const mojo::Callback<void()>& callback) { |
102 if (view_tree_) | 101 if (view_tree_) |
103 view_tree_->DispatchEvent(event.Pass()); | 102 view_tree_->DispatchEvent(event.Pass()); |
104 callback.Run(); | 103 callback.Run(); |
105 } | 104 } |
106 | 105 |
107 } // namespace launcher | 106 } // namespace launcher |
OLD | NEW |