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" |
11 #include "mojo/services/view_manager/node.h" | 11 #include "mojo/services/view_manager/node.h" |
12 #include "mojo/services/view_manager/root_node_manager.h" | 12 #include "mojo/services/view_manager/root_node_manager.h" |
13 #include "mojo/services/view_manager/view.h" | 13 #include "mojo/services/view_manager/view.h" |
14 #include "mojo/services/view_manager/window_manager_access_policy.h" | 14 #include "mojo/services/view_manager/window_manager_access_policy.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/gfx/codec/png_codec.h" | 17 #include "ui/gfx/codec/png_codec.h" |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 namespace service { | 20 namespace service { |
21 | 21 |
22 ViewManagerServiceImpl::ViewManagerServiceImpl( | 22 ViewManagerServiceImpl::ViewManagerServiceImpl( |
23 RootNodeManager* root_node_manager, | 23 RootNodeManager* root_node_manager, |
24 ConnectionSpecificId creator_id, | 24 ConnectionSpecificId creator_id, |
25 const std::string& creator_url, | 25 const std::string& creator_url, |
26 const std::string& url, | 26 const std::string& url, |
27 const NodeId& root_id) | 27 const NodeId& root_id, |
| 28 InterfaceRequest<ServiceProvider> service_provider) |
28 : root_node_manager_(root_node_manager), | 29 : root_node_manager_(root_node_manager), |
29 id_(root_node_manager_->GetAndAdvanceNextConnectionId()), | 30 id_(root_node_manager_->GetAndAdvanceNextConnectionId()), |
30 url_(url), | 31 url_(url), |
31 creator_id_(creator_id), | 32 creator_id_(creator_id), |
32 creator_url_(creator_url), | 33 creator_url_(creator_url), |
33 delete_on_connection_error_(false) { | 34 delete_on_connection_error_(false), |
| 35 service_provider_(service_provider.Pass()) { |
34 CHECK(GetNode(root_id)); | 36 CHECK(GetNode(root_id)); |
35 roots_.insert(NodeIdToTransportId(root_id)); | 37 roots_.insert(NodeIdToTransportId(root_id)); |
36 if (root_id == RootNodeId()) | 38 if (root_id == RootNodeId()) |
37 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); | 39 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); |
38 else | 40 else |
39 access_policy_.reset(new DefaultAccessPolicy(id_, this)); | 41 access_policy_.reset(new DefaultAccessPolicy(id_, this)); |
40 } | 42 } |
41 | 43 |
42 ViewManagerServiceImpl::~ViewManagerServiceImpl() { | 44 ViewManagerServiceImpl::~ViewManagerServiceImpl() { |
43 // Delete any views we created. | 45 // Delete any views we created. |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 if (local_nodes) | 284 if (local_nodes) |
283 local_nodes->push_back(GetNode(node->id())); | 285 local_nodes->push_back(GetNode(node->id())); |
284 return; | 286 return; |
285 } | 287 } |
286 known_nodes_.erase(NodeIdToTransportId(node->id())); | 288 known_nodes_.erase(NodeIdToTransportId(node->id())); |
287 std::vector<const Node*> children = node->GetChildren(); | 289 std::vector<const Node*> children = node->GetChildren(); |
288 for (size_t i = 0; i < children.size(); ++i) | 290 for (size_t i = 0; i < children.size(); ++i) |
289 RemoveFromKnown(children[i], local_nodes); | 291 RemoveFromKnown(children[i], local_nodes); |
290 } | 292 } |
291 | 293 |
292 void ViewManagerServiceImpl::AddRoot(const NodeId& node_id) { | 294 void ViewManagerServiceImpl::AddRoot( |
| 295 const NodeId& node_id, |
| 296 InterfaceRequest<ServiceProvider> service_provider) { |
293 const Id transport_node_id(NodeIdToTransportId(node_id)); | 297 const Id transport_node_id(NodeIdToTransportId(node_id)); |
294 CHECK(roots_.count(transport_node_id) == 0); | 298 CHECK(roots_.count(transport_node_id) == 0); |
295 | 299 |
296 CHECK_EQ(creator_id_, node_id.connection_id); | 300 CHECK_EQ(creator_id_, node_id.connection_id); |
297 roots_.insert(transport_node_id); | 301 roots_.insert(transport_node_id); |
298 const Node* node = GetNode(node_id); | 302 const Node* node = GetNode(node_id); |
299 CHECK(node); | 303 CHECK(node); |
300 std::vector<const Node*> to_send; | 304 std::vector<const Node*> to_send; |
301 if (!IsNodeKnown(node)) { | 305 if (!IsNodeKnown(node)) { |
302 GetUnknownNodesFrom(node, &to_send); | 306 GetUnknownNodesFrom(node, &to_send); |
303 } else { | 307 } else { |
304 // Even though the connection knows about the new root we need to tell it | 308 // Even though the connection knows about the new root we need to tell it |
305 // |node| is now a root. | 309 // |node| is now a root. |
306 to_send.push_back(node); | 310 to_send.push_back(node); |
307 } | 311 } |
308 | 312 |
309 client()->OnEmbed(id_, creator_url_, NodeToNodeData(to_send.front())); | 313 client()->OnEmbed(id_, creator_url_, NodeToNodeData(to_send.front()), |
| 314 service_provider.Pass()); |
310 root_node_manager_->OnConnectionMessagedClient(id_); | 315 root_node_manager_->OnConnectionMessagedClient(id_); |
311 } | 316 } |
312 | 317 |
313 void ViewManagerServiceImpl::RemoveRoot(const NodeId& node_id) { | 318 void ViewManagerServiceImpl::RemoveRoot(const NodeId& node_id) { |
314 const Id transport_node_id(NodeIdToTransportId(node_id)); | 319 const Id transport_node_id(NodeIdToTransportId(node_id)); |
315 CHECK(roots_.count(transport_node_id) > 0); | 320 CHECK(roots_.count(transport_node_id) > 0); |
316 | 321 |
317 roots_.erase(transport_node_id); | 322 roots_.erase(transport_node_id); |
318 | 323 |
319 // No need to do anything if we created the node. | 324 // No need to do anything if we created the node. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 const bool success = node && node->IsVisible() != visible && | 569 const bool success = node && node->IsVisible() != visible && |
565 access_policy_->CanChangeNodeVisibility(node); | 570 access_policy_->CanChangeNodeVisibility(node); |
566 if (success) { | 571 if (success) { |
567 DCHECK(node); | 572 DCHECK(node); |
568 node->SetVisible(visible); | 573 node->SetVisible(visible); |
569 } | 574 } |
570 // TODO(sky): need to notify of visibility changes. | 575 // TODO(sky): need to notify of visibility changes. |
571 callback.Run(success); | 576 callback.Run(success); |
572 } | 577 } |
573 | 578 |
574 void ViewManagerServiceImpl::Embed(const String& url, | 579 void ViewManagerServiceImpl::Embed( |
575 Id transport_node_id, | 580 const String& url, |
576 const Callback<void(bool)>& callback) { | 581 Id transport_node_id, |
| 582 ServiceProviderPtr service_provider, |
| 583 const Callback<void(bool)>& callback) { |
| 584 InterfaceRequest<ServiceProvider> spir; |
| 585 spir.Bind(service_provider.PassMessagePipe()); |
| 586 |
577 if (NodeIdFromTransportId(transport_node_id) == InvalidNodeId()) { | 587 if (NodeIdFromTransportId(transport_node_id) == InvalidNodeId()) { |
578 root_node_manager_->EmbedRoot(url); | 588 root_node_manager_->EmbedRoot(url, spir.Pass()); |
579 callback.Run(true); | 589 callback.Run(true); |
580 return; | 590 return; |
581 } | 591 } |
582 const Node* node = GetNode(NodeIdFromTransportId(transport_node_id)); | 592 const Node* node = GetNode(NodeIdFromTransportId(transport_node_id)); |
583 bool success = node && access_policy_->CanEmbed(node); | 593 bool success = node && access_policy_->CanEmbed(node); |
584 if (success) { | 594 if (success) { |
585 // Only allow a node to be the root for one connection. | 595 // Only allow a node to be the root for one connection. |
586 const NodeId node_id(NodeIdFromTransportId(transport_node_id)); | 596 const NodeId node_id(NodeIdFromTransportId(transport_node_id)); |
587 ViewManagerServiceImpl* connection_by_url = | 597 ViewManagerServiceImpl* connection_by_url = |
588 root_node_manager_->GetConnectionByCreator(id_, url.To<std::string>()); | 598 root_node_manager_->GetConnectionByCreator(id_, url.To<std::string>()); |
589 ViewManagerServiceImpl* connection_with_node_as_root = | 599 ViewManagerServiceImpl* connection_with_node_as_root = |
590 root_node_manager_->GetConnectionWithRoot(node_id); | 600 root_node_manager_->GetConnectionWithRoot(node_id); |
591 if ((connection_by_url != connection_with_node_as_root || | 601 if ((connection_by_url != connection_with_node_as_root || |
592 (!connection_by_url && !connection_with_node_as_root)) && | 602 (!connection_by_url && !connection_with_node_as_root)) && |
593 (!connection_by_url || !connection_by_url->HasRoot(node_id))) { | 603 (!connection_by_url || !connection_by_url->HasRoot(node_id))) { |
594 RootNodeManager::ScopedChange change(this, root_node_manager_, true); | 604 RootNodeManager::ScopedChange change(this, root_node_manager_, true); |
595 RemoveChildrenAsPartOfEmbed(node_id); | 605 RemoveChildrenAsPartOfEmbed(node_id); |
596 // Never message the originating connection. | 606 // Never message the originating connection. |
597 root_node_manager_->OnConnectionMessagedClient(id_); | 607 root_node_manager_->OnConnectionMessagedClient(id_); |
598 if (connection_with_node_as_root) | 608 if (connection_with_node_as_root) |
599 connection_with_node_as_root->RemoveRoot(node_id); | 609 connection_with_node_as_root->RemoveRoot(node_id); |
600 if (connection_by_url) | 610 if (connection_by_url) { |
601 connection_by_url->AddRoot(node_id); | 611 connection_by_url->AddRoot(node_id, spir.Pass()); |
602 else | 612 } else { |
603 root_node_manager_->Embed(id_, url, transport_node_id); | 613 root_node_manager_->Embed(id_, url, transport_node_id, |
| 614 spir.Pass()); |
| 615 } |
604 } else { | 616 } else { |
605 success = false; | 617 success = false; |
606 } | 618 } |
607 } | 619 } |
608 callback.Run(success); | 620 callback.Run(success); |
609 } | 621 } |
610 | 622 |
611 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, | 623 void ViewManagerServiceImpl::DispatchOnViewInputEvent(Id transport_view_id, |
612 EventPtr event) { | 624 EventPtr event) { |
613 // We only allow the WM to dispatch events. At some point this function will | 625 // We only allow the WM to dispatch events. At some point this function will |
(...skipping 12 matching lines...) Expand all Loading... |
626 } | 638 } |
627 } | 639 } |
628 | 640 |
629 void ViewManagerServiceImpl::OnConnectionEstablished() { | 641 void ViewManagerServiceImpl::OnConnectionEstablished() { |
630 root_node_manager_->AddConnection(this); | 642 root_node_manager_->AddConnection(this); |
631 | 643 |
632 std::vector<const Node*> to_send; | 644 std::vector<const Node*> to_send; |
633 for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) | 645 for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) |
634 GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send); | 646 GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send); |
635 | 647 |
636 client()->OnEmbed(id_, creator_url_, NodeToNodeData(to_send.front())); | 648 client()->OnEmbed(id_, creator_url_, NodeToNodeData(to_send.front()), |
| 649 service_provider_.Pass()); |
637 } | 650 } |
638 | 651 |
639 const base::hash_set<Id>& | 652 const base::hash_set<Id>& |
640 ViewManagerServiceImpl::GetRootsForAccessPolicy() const { | 653 ViewManagerServiceImpl::GetRootsForAccessPolicy() const { |
641 return roots_; | 654 return roots_; |
642 } | 655 } |
643 | 656 |
644 bool ViewManagerServiceImpl::IsNodeKnownForAccessPolicy( | 657 bool ViewManagerServiceImpl::IsNodeKnownForAccessPolicy( |
645 const Node* node) const { | 658 const Node* node) const { |
646 return IsNodeKnown(node); | 659 return IsNodeKnown(node); |
647 } | 660 } |
648 | 661 |
649 bool ViewManagerServiceImpl::IsNodeRootOfAnotherConnectionForAccessPolicy( | 662 bool ViewManagerServiceImpl::IsNodeRootOfAnotherConnectionForAccessPolicy( |
650 const Node* node) const { | 663 const Node* node) const { |
651 ViewManagerServiceImpl* connection = | 664 ViewManagerServiceImpl* connection = |
652 root_node_manager_->GetConnectionWithRoot(node->id()); | 665 root_node_manager_->GetConnectionWithRoot(node->id()); |
653 return connection && connection != this; | 666 return connection && connection != this; |
654 } | 667 } |
655 | 668 |
656 } // namespace service | 669 } // namespace service |
657 } // namespace mojo | 670 } // namespace mojo |
OLD | NEW |