| 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/default_access_policy.h" | 10 #include "mojo/services/view_manager/default_access_policy.h" |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 const Callback<void(bool)>& callback) { | 486 const Callback<void(bool)>& callback) { |
| 487 InterfaceRequest<ServiceProvider> spir; | 487 InterfaceRequest<ServiceProvider> spir; |
| 488 spir.Bind(service_provider.PassMessagePipe()); | 488 spir.Bind(service_provider.PassMessagePipe()); |
| 489 | 489 |
| 490 if (NodeIdFromTransportId(transport_view_id) == InvalidNodeId()) { | 490 if (NodeIdFromTransportId(transport_view_id) == InvalidNodeId()) { |
| 491 root_node_manager_->EmbedRoot(url, spir.Pass()); | 491 root_node_manager_->EmbedRoot(url, spir.Pass()); |
| 492 callback.Run(true); | 492 callback.Run(true); |
| 493 return; | 493 return; |
| 494 } | 494 } |
| 495 const Node* node = GetNode(NodeIdFromTransportId(transport_view_id)); | 495 const Node* node = GetNode(NodeIdFromTransportId(transport_view_id)); |
| 496 bool success = node && access_policy_->CanEmbed(node); | 496 if (!node && access_policy_->CanEmbed(node)) { |
| 497 if (success) { | 497 callback.Run(false); |
| 498 // Only allow a node to be the root for one connection. | 498 return; |
| 499 const NodeId node_id(NodeIdFromTransportId(transport_view_id)); | |
| 500 ViewManagerServiceImpl* connection_by_url = | |
| 501 root_node_manager_->GetConnectionByCreator(id_, url.To<std::string>()); | |
| 502 ViewManagerServiceImpl* connection_with_node_as_root = | |
| 503 root_node_manager_->GetConnectionWithRoot(node_id); | |
| 504 if ((connection_by_url != connection_with_node_as_root || | |
| 505 (!connection_by_url && !connection_with_node_as_root)) && | |
| 506 (!connection_by_url || !connection_by_url->HasRoot(node_id))) { | |
| 507 RootNodeManager::ScopedChange change(this, root_node_manager_, true); | |
| 508 RemoveChildrenAsPartOfEmbed(node_id); | |
| 509 // Never message the originating connection. | |
| 510 root_node_manager_->OnConnectionMessagedClient(id_); | |
| 511 if (connection_with_node_as_root) | |
| 512 connection_with_node_as_root->RemoveRoot(node_id); | |
| 513 if (connection_by_url) { | |
| 514 connection_by_url->AddRoot(node_id, spir.Pass()); | |
| 515 } else { | |
| 516 root_node_manager_->Embed(id_, url, transport_view_id, spir.Pass()); | |
| 517 } | |
| 518 } else { | |
| 519 success = false; | |
| 520 } | |
| 521 } | 499 } |
| 522 callback.Run(success); | 500 |
| 501 // Only allow a node to be the root for one connection. |
| 502 const NodeId node_id(NodeIdFromTransportId(transport_view_id)); |
| 503 ViewManagerServiceImpl* existing_owner = |
| 504 root_node_manager_->GetConnectionWithRoot(node_id); |
| 505 |
| 506 RootNodeManager::ScopedChange change(this, root_node_manager_, true); |
| 507 if (existing_owner) { |
| 508 RemoveChildrenAsPartOfEmbed(node_id); |
| 509 // Never message the originating connection. |
| 510 root_node_manager_->OnConnectionMessagedClient(id_); |
| 511 existing_owner->RemoveRoot(node_id); |
| 512 } |
| 513 root_node_manager_->Embed(id_, url, transport_view_id, spir.Pass()); |
| 514 callback.Run(true); |
| 523 } | 515 } |
| 524 | 516 |
| 525 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, | 517 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, |
| 526 EventPtr event) { | 518 EventPtr event) { |
| 527 // We only allow the WM to dispatch events. At some point this function will | 519 // We only allow the WM to dispatch events. At some point this function will |
| 528 // move to a separate interface and the check can go away. | 520 // move to a separate interface and the check can go away. |
| 529 if (id_ != kWindowManagerConnection) | 521 if (id_ != kWindowManagerConnection) |
| 530 return; | 522 return; |
| 531 | 523 |
| 532 const NodeId node_id(NodeIdFromTransportId(transport_view_id)); | 524 const NodeId node_id(NodeIdFromTransportId(transport_view_id)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 560 |
| 569 bool ViewManagerServiceImpl::IsNodeRootOfAnotherConnectionForAccessPolicy( | 561 bool ViewManagerServiceImpl::IsNodeRootOfAnotherConnectionForAccessPolicy( |
| 570 const Node* node) const { | 562 const Node* node) const { |
| 571 ViewManagerServiceImpl* connection = | 563 ViewManagerServiceImpl* connection = |
| 572 root_node_manager_->GetConnectionWithRoot(node->id()); | 564 root_node_manager_->GetConnectionWithRoot(node->id()); |
| 573 return connection && connection != this; | 565 return connection && connection != this; |
| 574 } | 566 } |
| 575 | 567 |
| 576 } // namespace service | 568 } // namespace service |
| 577 } // namespace mojo | 569 } // namespace mojo |
| OLD | NEW |