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 "mojo/services/view_manager/view_manager_service_impl.h" | 5 #include "mojo/services/view_manager/view_manager_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 9 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
10 #include "mojo/services/view_manager/connection_manager.h" | 10 #include "mojo/services/view_manager/connection_manager.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (local_views) | 207 if (local_views) |
208 local_views->push_back(GetView(view->id())); | 208 local_views->push_back(GetView(view->id())); |
209 return; | 209 return; |
210 } | 210 } |
211 known_views_.erase(ViewIdToTransportId(view->id())); | 211 known_views_.erase(ViewIdToTransportId(view->id())); |
212 std::vector<const ServerView*> children = view->GetChildren(); | 212 std::vector<const ServerView*> children = view->GetChildren(); |
213 for (size_t i = 0; i < children.size(); ++i) | 213 for (size_t i = 0; i < children.size(); ++i) |
214 RemoveFromKnown(children[i], local_views); | 214 RemoveFromKnown(children[i], local_views); |
215 } | 215 } |
216 | 216 |
217 void ViewManagerServiceImpl::AddRoot( | |
218 const ViewId& view_id, | |
219 InterfaceRequest<ServiceProvider> service_provider) { | |
220 const Id transport_view_id(ViewIdToTransportId(view_id)); | |
221 CHECK(roots_.count(transport_view_id) == 0); | |
222 | |
223 CHECK_EQ(creator_id_, view_id.connection_id); | |
224 roots_.insert(transport_view_id); | |
225 const ServerView* view = GetView(view_id); | |
226 CHECK(view); | |
227 std::vector<const ServerView*> to_send; | |
228 if (!IsViewKnown(view)) { | |
229 GetUnknownViewsFrom(view, &to_send); | |
230 } else { | |
231 // Even though the connection knows about the new root we need to tell it | |
232 // |view| is now a root. | |
233 to_send.push_back(view); | |
234 } | |
235 | |
236 client()->OnEmbed(id_, | |
237 creator_url_, | |
238 ViewToViewData(to_send.front()), | |
239 service_provider.Pass()); | |
240 connection_manager_->OnConnectionMessagedClient(id_); | |
241 } | |
242 | |
243 void ViewManagerServiceImpl::RemoveRoot(const ViewId& view_id) { | 217 void ViewManagerServiceImpl::RemoveRoot(const ViewId& view_id) { |
244 const Id transport_view_id(ViewIdToTransportId(view_id)); | 218 const Id transport_view_id(ViewIdToTransportId(view_id)); |
245 CHECK(roots_.count(transport_view_id) > 0); | 219 CHECK(roots_.count(transport_view_id) > 0); |
246 | 220 |
247 roots_.erase(transport_view_id); | 221 roots_.erase(transport_view_id); |
248 | 222 |
249 // No need to do anything if we created the view. | 223 // No need to do anything if we created the view. |
250 if (view_id.connection_id == id_) | 224 if (view_id.connection_id == id_) |
251 return; | 225 return; |
252 | 226 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 const Callback<void(bool)>& callback) { | 431 const Callback<void(bool)>& callback) { |
458 InterfaceRequest<ServiceProvider> spir; | 432 InterfaceRequest<ServiceProvider> spir; |
459 spir.Bind(service_provider.PassMessagePipe()); | 433 spir.Bind(service_provider.PassMessagePipe()); |
460 | 434 |
461 if (ViewIdFromTransportId(transport_view_id) == InvalidViewId()) { | 435 if (ViewIdFromTransportId(transport_view_id) == InvalidViewId()) { |
462 connection_manager_->EmbedRoot(url, spir.Pass()); | 436 connection_manager_->EmbedRoot(url, spir.Pass()); |
463 callback.Run(true); | 437 callback.Run(true); |
464 return; | 438 return; |
465 } | 439 } |
466 const ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); | 440 const ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); |
467 bool success = view && access_policy_->CanEmbed(view); | 441 if (!view || !access_policy_->CanEmbed(view)) { |
468 if (success) { | 442 callback.Run(false); |
469 // Only allow a view to be the root for one connection. | 443 return; |
470 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | |
471 ViewManagerServiceImpl* connection_by_url = | |
472 connection_manager_->GetConnectionByCreator(id_, url.To<std::string>()); | |
473 ViewManagerServiceImpl* connection_with_view_as_root = | |
474 connection_manager_->GetConnectionWithRoot(view_id); | |
475 if ((connection_by_url != connection_with_view_as_root || | |
476 (!connection_by_url && !connection_with_view_as_root)) && | |
477 (!connection_by_url || !connection_by_url->HasRoot(view_id))) { | |
478 ConnectionManager::ScopedChange change(this, connection_manager_, true); | |
479 RemoveChildrenAsPartOfEmbed(view_id); | |
480 // Never message the originating connection. | |
481 connection_manager_->OnConnectionMessagedClient(id_); | |
482 if (connection_with_view_as_root) | |
483 connection_with_view_as_root->RemoveRoot(view_id); | |
484 if (connection_by_url) { | |
485 connection_by_url->AddRoot(view_id, spir.Pass()); | |
486 } else { | |
487 connection_manager_->Embed(id_, url, transport_view_id, spir.Pass()); | |
488 } | |
489 } else { | |
490 success = false; | |
491 } | |
492 } | 444 } |
493 callback.Run(success); | 445 |
| 446 // Only allow a node to be the root for one connection. |
| 447 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
| 448 ViewManagerServiceImpl* existing_owner = |
| 449 connection_manager_->GetConnectionWithRoot(view_id); |
| 450 |
| 451 ConnectionManager::ScopedChange change(this, connection_manager_, true); |
| 452 RemoveChildrenAsPartOfEmbed(view_id); |
| 453 if (existing_owner) { |
| 454 // Never message the originating connection. |
| 455 connection_manager_->OnConnectionMessagedClient(id_); |
| 456 existing_owner->RemoveRoot(view_id); |
| 457 } |
| 458 connection_manager_->Embed(id_, url, transport_view_id, spir.Pass()); |
| 459 callback.Run(true); |
494 } | 460 } |
495 | 461 |
496 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, | 462 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, |
497 EventPtr event) { | 463 EventPtr event) { |
498 // We only allow the WM to dispatch events. At some point this function will | 464 // We only allow the WM to dispatch events. At some point this function will |
499 // move to a separate interface and the check can go away. | 465 // move to a separate interface and the check can go away. |
500 if (id_ != kWindowManagerConnection) | 466 if (id_ != kWindowManagerConnection) |
501 return; | 467 return; |
502 | 468 |
503 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); | 469 const ViewId view_id(ViewIdFromTransportId(transport_view_id)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 507 |
542 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( | 508 bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy( |
543 const ServerView* view) const { | 509 const ServerView* view) const { |
544 ViewManagerServiceImpl* connection = | 510 ViewManagerServiceImpl* connection = |
545 connection_manager_->GetConnectionWithRoot(view->id()); | 511 connection_manager_->GetConnectionWithRoot(view->id()); |
546 return connection && connection != this; | 512 return connection && connection != this; |
547 } | 513 } |
548 | 514 |
549 } // namespace service | 515 } // namespace service |
550 } // namespace mojo | 516 } // namespace mojo |
OLD | NEW |