| 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/default_access_policy.h" | 5 #include "mojo/services/view_manager/default_access_policy.h" |
| 6 | 6 |
| 7 #include "mojo/services/view_manager/access_policy_delegate.h" | 7 #include "mojo/services/view_manager/access_policy_delegate.h" |
| 8 #include "mojo/services/view_manager/node.h" | 8 #include "mojo/services/view_manager/node.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| 11 namespace service { | 11 namespace service { |
| 12 | 12 |
| 13 DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id, | 13 DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id, |
| 14 AccessPolicyDelegate* delegate) | 14 AccessPolicyDelegate* delegate) |
| 15 : connection_id_(connection_id), | 15 : connection_id_(connection_id), |
| 16 delegate_(delegate) { | 16 delegate_(delegate) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 DefaultAccessPolicy::~DefaultAccessPolicy() { | 19 DefaultAccessPolicy::~DefaultAccessPolicy() { |
| 20 } | 20 } |
| 21 | 21 |
| 22 bool DefaultAccessPolicy::CanRemoveNodeFromParent(const Node* node) const { | 22 bool DefaultAccessPolicy::CanRemoveNodeFromParent(const Node* node) const { |
| 23 if (!WasCreatedByThisConnection(node)) | 23 if (!WasCreatedByThisConnection(node)) |
| 24 return false; // Can only unparent nodes we created. | 24 return false; // Can only unparent nodes we created. |
| 25 | 25 |
| 26 const Node* parent = node->GetParent(); | 26 return IsNodeInRoots(node->parent()) || |
| 27 return IsNodeInRoots(parent) || WasCreatedByThisConnection(parent); | 27 WasCreatedByThisConnection(node->parent()); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool DefaultAccessPolicy::CanAddNode(const Node* parent, | 30 bool DefaultAccessPolicy::CanAddNode(const Node* parent, |
| 31 const Node* child) const { | 31 const Node* child) const { |
| 32 return WasCreatedByThisConnection(child) && | 32 return WasCreatedByThisConnection(child) && |
| 33 (IsNodeInRoots(parent) || | 33 (IsNodeInRoots(parent) || |
| 34 (WasCreatedByThisConnection(parent) && | 34 (WasCreatedByThisConnection(parent) && |
| 35 !delegate_->IsNodeRootOfAnotherConnectionForAccessPolicy(parent))); | 35 !delegate_->IsNodeRootOfAnotherConnectionForAccessPolicy(parent))); |
| 36 } | 36 } |
| 37 | 37 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return view_id.connection_id == connection_id_; | 99 return view_id.connection_id == connection_id_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool DefaultAccessPolicy::IsNodeInRoots(const Node* node) const { | 102 bool DefaultAccessPolicy::IsNodeInRoots(const Node* node) const { |
| 103 return delegate_->GetRootsForAccessPolicy().count( | 103 return delegate_->GetRootsForAccessPolicy().count( |
| 104 NodeIdToTransportId(node->id())) > 0; | 104 NodeIdToTransportId(node->id())) > 0; |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace service | 107 } // namespace service |
| 108 } // namespace mojo | 108 } // namespace mojo |
| OLD | NEW |