| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/launcher_app.h" | 5 #include "services/ui/launcher/launcher_app.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
| 11 #include "mojo/common/tracing_impl.h" | 11 #include "mojo/common/tracing_impl.h" |
| 12 #include "mojo/public/c/system/main.h" | 12 #include "mojo/public/c/system/main.h" |
| 13 #include "mojo/public/cpp/application/application_connection.h" | 13 #include "mojo/public/cpp/application/application_connection.h" |
| 14 #include "mojo/public/cpp/application/application_impl.h" | 14 #include "mojo/public/cpp/application/application_impl.h" |
| 15 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" |
| 15 #include "services/ui/launcher/launcher_view_tree.h" | 16 #include "services/ui/launcher/launcher_view_tree.h" |
| 16 | 17 |
| 17 namespace launcher { | 18 namespace launcher { |
| 18 | 19 |
| 19 LauncherApp::LauncherApp() | 20 LauncherApp::LauncherApp() |
| 20 : app_impl_(nullptr), viewport_event_dispatcher_binding_(this) {} | 21 : app_impl_(nullptr), viewport_event_dispatcher_binding_(this) {} |
| 21 | 22 |
| 22 LauncherApp::~LauncherApp() {} | 23 LauncherApp::~LauncherApp() {} |
| 23 | 24 |
| 24 void LauncherApp::Initialize(mojo::ApplicationImpl* app_impl) { | 25 void LauncherApp::Initialize(mojo::ApplicationImpl* app_impl) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 void LauncherApp::OnViewportCreated(mojo::ViewportMetricsPtr metrics) { | 91 void LauncherApp::OnViewportCreated(mojo::ViewportMetricsPtr metrics) { |
| 91 viewport_->Show(); | 92 viewport_->Show(); |
| 92 | 93 |
| 93 mojo::ContextProviderPtr context_provider; | 94 mojo::ContextProviderPtr context_provider; |
| 94 viewport_->GetContextProvider(GetProxy(&context_provider)); | 95 viewport_->GetContextProvider(GetProxy(&context_provider)); |
| 95 | 96 |
| 96 view_tree_.reset(new LauncherViewTree( | 97 view_tree_.reset(new LauncherViewTree( |
| 97 compositor_.get(), view_manager_.get(), context_provider.Pass(), | 98 compositor_.get(), view_manager_.get(), context_provider.Pass(), |
| 98 metrics.Pass(), | 99 metrics.Pass(), |
| 99 base::Bind(&LauncherApp::Shutdown, base::Unretained(this)))); | 100 base::Bind(&LauncherApp::Shutdown, base::Unretained(this)))); |
| 100 UpdateClientView(); | 101 view_tree_->SetRoot(client_view_owner_.Pass()); |
| 102 |
| 101 RequestUpdatedViewportMetrics(); | 103 RequestUpdatedViewportMetrics(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void LauncherApp::OnViewportMetricsChanged(mojo::ViewportMetricsPtr metrics) { | 106 void LauncherApp::OnViewportMetricsChanged(mojo::ViewportMetricsPtr metrics) { |
| 105 if (view_tree_) { | 107 if (view_tree_) { |
| 106 view_tree_->SetViewportMetrics(metrics.Pass()); | 108 view_tree_->SetViewportMetrics(metrics.Pass()); |
| 107 RequestUpdatedViewportMetrics(); | 109 RequestUpdatedViewportMetrics(); |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 | 112 |
| 111 void LauncherApp::RequestUpdatedViewportMetrics() { | 113 void LauncherApp::RequestUpdatedViewportMetrics() { |
| 112 viewport_->RequestMetrics(base::Bind(&LauncherApp::OnViewportMetricsChanged, | 114 viewport_->RequestMetrics(base::Bind(&LauncherApp::OnViewportMetricsChanged, |
| 113 base::Unretained(this))); | 115 base::Unretained(this))); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void LauncherApp::OnEvent(mojo::EventPtr event, | 118 void LauncherApp::OnEvent(mojo::EventPtr event, |
| 117 const mojo::Callback<void()>& callback) { | 119 const mojo::Callback<void()>& callback) { |
| 118 if (view_tree_) | 120 if (view_tree_) |
| 119 view_tree_->DispatchEvent(event.Pass()); | 121 view_tree_->DispatchEvent(event.Pass()); |
| 120 callback.Run(); | 122 callback.Run(); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void LauncherApp::LaunchClient(std::string app_url) { | 125 void LauncherApp::LaunchClient(std::string app_url) { |
| 124 DVLOG(1) << "Launching " << app_url; | 126 DVLOG(1) << "Launching " << app_url; |
| 125 | 127 |
| 126 app_impl_->ConnectToService(app_url, &client_view_provider_); | 128 mojo::ui::ViewProviderPtr client_view_provider; |
| 127 client_view_provider_.set_connection_error_handler(base::Bind( | 129 app_impl_->ConnectToService(app_url, &client_view_provider); |
| 128 &LauncherApp::OnClientConnectionError, base::Unretained(this))); | |
| 129 | 130 |
| 130 client_view_provider_->CreateView( | 131 client_view_provider->CreateView(mojo::GetProxy(&client_view_owner_), nullptr, |
| 131 nullptr, nullptr, | 132 nullptr); |
| 132 base::Bind(&LauncherApp::OnClientViewCreated, base::Unretained(this))); | |
| 133 } | |
| 134 | |
| 135 void LauncherApp::OnClientConnectionError() { | |
| 136 LOG(ERROR) << "Exiting due to client application connection error."; | |
| 137 Shutdown(); | |
| 138 } | |
| 139 | |
| 140 void LauncherApp::OnClientViewCreated(mojo::ui::ViewTokenPtr view_token) { | |
| 141 client_view_token_ = view_token.Pass(); | |
| 142 UpdateClientView(); | |
| 143 } | |
| 144 | |
| 145 void LauncherApp::UpdateClientView() { | |
| 146 if (view_tree_) | |
| 147 view_tree_->SetRoot(client_view_token_.Clone()); | |
| 148 } | 133 } |
| 149 | 134 |
| 150 void LauncherApp::Shutdown() { | 135 void LauncherApp::Shutdown() { |
| 151 app_impl_->Terminate(); | 136 app_impl_->Terminate(); |
| 152 } | 137 } |
| 153 | 138 |
| 154 } // namespace launcher | 139 } // namespace launcher |
| OLD | NEW |