OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/services/view_manager/default_access_policy.h" |
| 6 |
| 7 #include "mojo/services/view_manager/access_policy_delegate.h" |
| 8 #include "mojo/services/view_manager/node.h" |
| 9 #include "mojo/services/view_manager/view.h" |
| 10 |
| 11 namespace mojo { |
| 12 namespace service { |
| 13 |
| 14 DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id, |
| 15 AccessPolicyDelegate* delegate) |
| 16 : connection_id_(connection_id), |
| 17 delegate_(delegate) { |
| 18 } |
| 19 |
| 20 DefaultAccessPolicy::~DefaultAccessPolicy() { |
| 21 } |
| 22 |
| 23 bool DefaultAccessPolicy::CanRemoveNodeFromParent(const Node* node) const { |
| 24 if (!WasCreatedByThisConnection(node)) |
| 25 return false; // Can only unparent nodes we created. |
| 26 |
| 27 const Node* parent = node->GetParent(); |
| 28 return IsNodeInRoots(parent) || WasCreatedByThisConnection(parent); |
| 29 } |
| 30 |
| 31 bool DefaultAccessPolicy::CanAddNode(const Node* parent, |
| 32 const Node* child) const { |
| 33 return WasCreatedByThisConnection(child) && |
| 34 (IsNodeInRoots(parent) || |
| 35 (WasCreatedByThisConnection(parent) && |
| 36 !delegate_->IsNodeRootOfAnotherConnectionForAccessPolicy(parent))); |
| 37 } |
| 38 |
| 39 bool DefaultAccessPolicy::CanReorderNode(const Node* node, |
| 40 const Node* relative_node, |
| 41 OrderDirection direction) const { |
| 42 return WasCreatedByThisConnection(node) && |
| 43 WasCreatedByThisConnection(relative_node); |
| 44 } |
| 45 |
| 46 bool DefaultAccessPolicy::CanDeleteNode(const Node* node) const { |
| 47 return WasCreatedByThisConnection(node); |
| 48 } |
| 49 |
| 50 bool DefaultAccessPolicy::CanDeleteView(const View* view) const { |
| 51 return WasCreatedByThisConnection(view); |
| 52 } |
| 53 |
| 54 bool DefaultAccessPolicy::CanSetView(const Node* node, const View* view) const { |
| 55 if (view && !WasCreatedByThisConnection(view)) |
| 56 return false; |
| 57 |
| 58 return WasCreatedByThisConnection(node) || IsNodeInRoots(node); |
| 59 } |
| 60 |
| 61 bool DefaultAccessPolicy::CanSetFocus(const Node* node) const { |
| 62 // TODO(beng): security. |
| 63 return true; |
| 64 } |
| 65 |
| 66 bool DefaultAccessPolicy::CanGetNodeTree(const Node* node) const { |
| 67 return WasCreatedByThisConnection(node) || IsNodeInRoots(node); |
| 68 } |
| 69 |
| 70 bool DefaultAccessPolicy::CanDescendIntoNodeForNodeTree( |
| 71 const Node* node) const { |
| 72 return WasCreatedByThisConnection(node) && |
| 73 !delegate_->IsNodeRootOfAnotherConnectionForAccessPolicy(node); |
| 74 } |
| 75 |
| 76 bool DefaultAccessPolicy::CanEmbed(const Node* node) const { |
| 77 return WasCreatedByThisConnection(node); |
| 78 } |
| 79 |
| 80 bool DefaultAccessPolicy::CanChangeNodeVisibility(const Node* node) const { |
| 81 return WasCreatedByThisConnection(node) || IsNodeInRoots(node); |
| 82 } |
| 83 |
| 84 bool DefaultAccessPolicy::CanSetViewContents(const View* view) const { |
| 85 return WasCreatedByThisConnection(view); |
| 86 } |
| 87 |
| 88 bool DefaultAccessPolicy::CanSetNodeBounds(const Node* node) const { |
| 89 return WasCreatedByThisConnection(node); |
| 90 } |
| 91 |
| 92 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange( |
| 93 const Node* node, |
| 94 const Node** new_parent, |
| 95 const Node** old_parent) const { |
| 96 if (!WasCreatedByThisConnection(node)) |
| 97 return false; |
| 98 |
| 99 if (*new_parent && !WasCreatedByThisConnection(*new_parent) && |
| 100 !IsNodeInRoots(*new_parent)) { |
| 101 *new_parent = NULL; |
| 102 } |
| 103 |
| 104 if (*old_parent && !WasCreatedByThisConnection(*old_parent) && |
| 105 !IsNodeInRoots(*old_parent)) { |
| 106 *old_parent = NULL; |
| 107 } |
| 108 return true; |
| 109 } |
| 110 |
| 111 Id DefaultAccessPolicy::GetViewIdToSend(const Node* node, |
| 112 const View* view) const { |
| 113 // TODO(sky): should we send null if view is not from this connection? |
| 114 return ViewIdToTransportId(view->id()); |
| 115 } |
| 116 |
| 117 bool DefaultAccessPolicy::ShouldSendViewDeleted(const ViewId& view_id) const { |
| 118 return view_id.connection_id == connection_id_; |
| 119 } |
| 120 |
| 121 bool DefaultAccessPolicy::IsNodeInRoots(const Node* node) const { |
| 122 return delegate_->GetRootsForAccessPolicy().count( |
| 123 NodeIdToTransportId(node->id())) > 0; |
| 124 } |
| 125 |
| 126 } // namespace service |
| 127 } // namespace mojo |
OLD | NEW |