| 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_connection.h" | 5 #include "mojo/services/view_manager/view_manager_connection.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 9 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 10 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 10 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 bool ViewManagerConnection::CanSetView(const Node* node, | 325 bool ViewManagerConnection::CanSetView(const Node* node, |
| 326 const ViewId& view_id) const { | 326 const ViewId& view_id) const { |
| 327 if (!node || !IsNodeDescendantOfRoots(node)) | 327 if (!node || !IsNodeDescendantOfRoots(node)) |
| 328 return false; | 328 return false; |
| 329 | 329 |
| 330 const View* view = GetView(view_id); | 330 const View* view = GetView(view_id); |
| 331 return (view && view_id.connection_id == id_) || view_id == ViewId(); | 331 return (view && view_id.connection_id == id_) || view_id == ViewId(); |
| 332 } | 332 } |
| 333 | 333 |
| 334 bool ViewManagerConnection::CanSetFocus(const Node* node) const { |
| 335 // TODO(beng): security. |
| 336 return true; |
| 337 } |
| 338 |
| 334 bool ViewManagerConnection::CanGetNodeTree(const Node* node) const { | 339 bool ViewManagerConnection::CanGetNodeTree(const Node* node) const { |
| 335 return node && | 340 return node && |
| 336 (IsNodeDescendantOfRoots(node) || node->id().connection_id == id_); | 341 (IsNodeDescendantOfRoots(node) || node->id().connection_id == id_); |
| 337 } | 342 } |
| 338 | 343 |
| 339 bool ViewManagerConnection::CanEmbed( | 344 bool ViewManagerConnection::CanEmbed( |
| 340 const mojo::Array<uint32_t>& node_ids) const { | 345 const mojo::Array<uint32_t>& node_ids) const { |
| 341 for (size_t i = 0; i < node_ids.size(); ++i) { | 346 for (size_t i = 0; i < node_ids.size(); ++i) { |
| 342 const Node* node = GetNode(NodeIdFromTransportId(node_ids[i])); | 347 const Node* node = GetNode(NodeIdFromTransportId(node_ids[i])); |
| 343 if (!node || node->id().connection_id != id_) | 348 if (!node || node->id().connection_id != id_) |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 return; | 693 return; |
| 689 } | 694 } |
| 690 SkBitmap bitmap; | 695 SkBitmap bitmap; |
| 691 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(handle_data), | 696 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(handle_data), |
| 692 buffer_size, &bitmap); | 697 buffer_size, &bitmap); |
| 693 view->SetBitmap(bitmap); | 698 view->SetBitmap(bitmap); |
| 694 UnmapBuffer(handle_data); | 699 UnmapBuffer(handle_data); |
| 695 callback.Run(true); | 700 callback.Run(true); |
| 696 } | 701 } |
| 697 | 702 |
| 703 void ViewManagerConnection::SetFocus(Id node_id, |
| 704 const Callback<void(bool)> & callback) { |
| 705 bool success = false; |
| 706 Node* node = GetNode(NodeIdFromTransportId(node_id)); |
| 707 if (CanSetFocus(node)) { |
| 708 success = true; |
| 709 node->window()->Focus(); |
| 710 } |
| 711 callback.Run(success); |
| 712 } |
| 713 |
| 698 void ViewManagerConnection::SetNodeBounds( | 714 void ViewManagerConnection::SetNodeBounds( |
| 699 Id node_id, | 715 Id node_id, |
| 700 RectPtr bounds, | 716 RectPtr bounds, |
| 701 const Callback<void(bool)>& callback) { | 717 const Callback<void(bool)>& callback) { |
| 702 if (NodeIdFromTransportId(node_id).connection_id != id_) { | 718 if (NodeIdFromTransportId(node_id).connection_id != id_) { |
| 703 callback.Run(false); | 719 callback.Run(false); |
| 704 return; | 720 return; |
| 705 } | 721 } |
| 706 | 722 |
| 707 Node* node = GetNode(NodeIdFromTransportId(node_id)); | 723 Node* node = GetNode(NodeIdFromTransportId(node_id)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 client()->OnViewManagerConnectionEstablished( | 786 client()->OnViewManagerConnectionEstablished( |
| 771 id_, | 787 id_, |
| 772 creator_url_, | 788 creator_url_, |
| 773 root_node_manager_->next_server_change_id(), | 789 root_node_manager_->next_server_change_id(), |
| 774 NodesToINodes(to_send)); | 790 NodesToINodes(to_send)); |
| 775 } | 791 } |
| 776 | 792 |
| 777 } // namespace service | 793 } // namespace service |
| 778 } // namespace view_manager | 794 } // namespace view_manager |
| 779 } // namespace mojo | 795 } // namespace mojo |
| OLD | NEW |