OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "view_manager/public/cpp/lib/view_manager_client_impl.h" | 5 #include "view_manager/public/cpp/lib/view_manager_client_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 const std::string& name, | 188 const std::string& name, |
189 const std::vector<uint8_t>& data) { | 189 const std::vector<uint8_t>& data) { |
190 DCHECK(connected_); | 190 DCHECK(connected_); |
191 service_->SetViewProperty(view_id, | 191 service_->SetViewProperty(view_id, |
192 String(name), | 192 String(name), |
193 Array<uint8_t>::From(data), | 193 Array<uint8_t>::From(data), |
194 ActionCompletedCallback()); | 194 ActionCompletedCallback()); |
195 } | 195 } |
196 | 196 |
197 void ViewManagerClientImpl::Embed(const String& url, Id view_id) { | 197 void ViewManagerClientImpl::Embed(const String& url, Id view_id) { |
198 MessagePipe pipe; | 198 Embed(url, view_id, nullptr, nullptr); |
199 InterfaceRequest<ServiceProvider> request; | |
200 request.Bind(pipe.handle0.Pass()); | |
201 Embed(url, view_id, request.Pass()); | |
202 } | 199 } |
203 | 200 |
204 void ViewManagerClientImpl::Embed( | 201 void ViewManagerClientImpl::Embed(const String& url, |
205 const String& url, | 202 Id view_id, |
206 Id view_id, | 203 InterfaceRequest<ServiceProvider> services, |
207 InterfaceRequest<ServiceProvider> service_provider) { | 204 ServiceProviderPtr exposed_services) { |
208 DCHECK(connected_); | 205 DCHECK(connected_); |
209 service_->Embed(url, view_id, service_provider.Pass(), | 206 service_->Embed(url, view_id, services.Pass(), exposed_services.Pass(), |
210 ActionCompletedCallback()); | 207 ActionCompletedCallback()); |
211 } | 208 } |
212 | 209 |
213 void ViewManagerClientImpl::AddView(View* view) { | 210 void ViewManagerClientImpl::AddView(View* view) { |
214 DCHECK(views_.find(view->id()) == views_.end()); | 211 DCHECK(views_.find(view->id()) == views_.end()); |
215 views_[view->id()] = view; | 212 views_[view->id()] = view; |
216 } | 213 } |
217 | 214 |
218 void ViewManagerClientImpl::RemoveView(Id view_id) { | 215 void ViewManagerClientImpl::RemoveView(Id view_id) { |
219 IdToViewMap::iterator it = views_.find(view_id); | 216 IdToViewMap::iterator it = views_.find(view_id); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 return view; | 251 return view; |
255 } | 252 } |
256 | 253 |
257 //////////////////////////////////////////////////////////////////////////////// | 254 //////////////////////////////////////////////////////////////////////////////// |
258 // ViewManagerClientImpl, ViewManagerClient implementation: | 255 // ViewManagerClientImpl, ViewManagerClient implementation: |
259 | 256 |
260 void ViewManagerClientImpl::OnEmbed( | 257 void ViewManagerClientImpl::OnEmbed( |
261 ConnectionSpecificId connection_id, | 258 ConnectionSpecificId connection_id, |
262 const String& creator_url, | 259 const String& creator_url, |
263 ViewDataPtr root_data, | 260 ViewDataPtr root_data, |
264 InterfaceRequest<ServiceProvider> parent_services, | 261 InterfaceRequest<ServiceProvider> services, |
| 262 ServiceProviderPtr exposed_services, |
265 ScopedMessagePipeHandle window_manager_pipe) { | 263 ScopedMessagePipeHandle window_manager_pipe) { |
266 DCHECK(!connected_); | 264 DCHECK(!connected_); |
267 connected_ = true; | 265 connected_ = true; |
268 connection_id_ = connection_id; | 266 connection_id_ = connection_id; |
269 creator_url_ = String::From(creator_url); | 267 creator_url_ = String::From(creator_url); |
270 | 268 |
271 DCHECK(!root_); | 269 DCHECK(!root_); |
272 root_ = AddViewToViewManager(this, nullptr, root_data); | 270 root_ = AddViewToViewManager(this, nullptr, root_data); |
273 root_->AddObserver(new RootObserver(root_)); | 271 root_->AddObserver(new RootObserver(root_)); |
274 | 272 |
275 ServiceProviderImpl* exported_services = nullptr; | |
276 scoped_ptr<ServiceProvider> remote; | |
277 | |
278 // BindToRequest() binds the lifetime of |exported_services| to the pipe. | |
279 exported_services = new ServiceProviderImpl; | |
280 BindToRequest(exported_services, &parent_services); | |
281 remote.reset(exported_services->CreateRemoteServiceProvider()); | |
282 | |
283 window_manager_.Bind(window_manager_pipe.Pass()); | 273 window_manager_.Bind(window_manager_pipe.Pass()); |
284 window_manager_.set_client(this); | 274 window_manager_.set_client(this); |
285 // base::Unretained() is safe here as |window_manager_| is bound to our | 275 // base::Unretained() is safe here as |window_manager_| is bound to our |
286 // lifetime. | 276 // lifetime. |
287 window_manager_->GetFocusedAndActiveViews( | 277 window_manager_->GetFocusedAndActiveViews( |
288 base::Bind(&ViewManagerClientImpl::OnGotFocusedAndActiveViews, | 278 base::Bind(&ViewManagerClientImpl::OnGotFocusedAndActiveViews, |
289 base::Unretained(this))); | 279 base::Unretained(this))); |
290 delegate_->OnEmbed(root_, exported_services, remote.Pass()); | 280 |
| 281 delegate_->OnEmbed(root_, services.Pass(), exposed_services.Pass()); |
291 } | 282 } |
292 | 283 |
293 void ViewManagerClientImpl::OnEmbeddedAppDisconnected(Id view_id) { | 284 void ViewManagerClientImpl::OnEmbeddedAppDisconnected(Id view_id) { |
294 View* view = GetViewById(view_id); | 285 View* view = GetViewById(view_id); |
295 if (view) { | 286 if (view) { |
296 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(), | 287 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(), |
297 OnViewEmbeddedAppDisconnected(view)); | 288 OnViewEmbeddedAppDisconnected(view)); |
298 } | 289 } |
299 } | 290 } |
300 | 291 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 uint32 active_view_id) { | 468 uint32 active_view_id) { |
478 if (GetViewById(focused_view_id) != focused_view_) | 469 if (GetViewById(focused_view_id) != focused_view_) |
479 OnFocusChanged(focused_view_ ? focused_view_->id() : 0, focused_view_id); | 470 OnFocusChanged(focused_view_ ? focused_view_->id() : 0, focused_view_id); |
480 if (GetViewById(active_view_id) != activated_view_) { | 471 if (GetViewById(active_view_id) != activated_view_) { |
481 OnActiveWindowChanged(activated_view_ ? activated_view_->id() : 0, | 472 OnActiveWindowChanged(activated_view_ ? activated_view_->id() : 0, |
482 active_view_id); | 473 active_view_id); |
483 } | 474 } |
484 } | 475 } |
485 | 476 |
486 } // namespace mojo | 477 } // namespace mojo |
OLD | NEW |