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 (!IsNodeFromThisConnection(node)) | |
25 return false; // Can only unparent nodes we created. | |
26 | |
27 const Node* parent = node->GetParent(); | |
28 return IsNodeInRoots(parent) || IsNodeFromThisConnection(parent); | |
29 } | |
30 | |
31 bool DefaultAccessPolicy::CanAddNode(const Node* parent, | |
32 const Node* child) const { | |
33 return IsNodeFromThisConnection(child) && | |
34 (IsNodeInRoots(parent) || | |
35 (IsNodeFromThisConnection(parent) && | |
36 !delegate_->IsNodeEmbeddedInAnotherConnectionForAccessPolicy(parent))); | |
37 } | |
38 | |
39 bool DefaultAccessPolicy::CanReorderNode(const Node* node, | |
40 const Node* relative_node, | |
41 OrderDirection direction) const { | |
42 return IsNodeFromThisConnection(node) && | |
43 IsNodeFromThisConnection(relative_node); | |
44 } | |
45 | |
46 bool DefaultAccessPolicy::CanDeleteNode(const Node* node) const { | |
47 return IsNodeFromThisConnection(node); | |
48 } | |
49 | |
50 bool DefaultAccessPolicy::CanDeleteView(const View* view) const { | |
51 return view->id().connection_id == connection_id_; | |
Ben Goodger (Google)
2014/07/25 20:51:46
I would distill this pattern to an "IdOwnedByThisC
sky
2014/07/25 21:10:46
I went with a template (ick!) so that I can keep t
| |
52 } | |
53 | |
54 bool DefaultAccessPolicy::CanSetView(const Node* node, const View* view) const { | |
55 if (view && view->id().connection_id != connection_id_) | |
56 return false; | |
57 | |
58 return IsNodeFromThisConnection(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 IsNodeFromThisConnection(node) || IsNodeInRoots(node); | |
68 } | |
69 | |
70 bool DefaultAccessPolicy::CanDescendIntoNodeForNodeTree( | |
71 const Node* node) const { | |
72 return IsNodeFromThisConnection(node) && | |
73 !delegate_->IsNodeEmbeddedInAnotherConnectionForAccessPolicy(node); | |
74 } | |
75 | |
76 bool DefaultAccessPolicy::CanEmbed(const Node* node) const { | |
77 return IsNodeFromThisConnection(node); | |
78 } | |
79 | |
80 bool DefaultAccessPolicy::CanChangeNodeVisibility(const Node* node) const { | |
81 return IsNodeFromThisConnection(node) || IsNodeInRoots(node); | |
82 } | |
83 | |
84 bool DefaultAccessPolicy::CanSetViewContents(const View* view) const { | |
85 return view->id().connection_id == connection_id_; | |
86 } | |
87 | |
88 bool DefaultAccessPolicy::CanSetNodeBounds(const Node* node) const { | |
89 return IsNodeFromThisConnection(node); | |
90 } | |
91 | |
92 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange( | |
93 const Node* node, | |
94 const Node** new_parent, | |
95 const Node** old_parent) const { | |
96 if (!IsNodeFromThisConnection(node)) | |
97 return false; | |
98 | |
99 if (*new_parent && !IsNodeFromThisConnection(*new_parent) && | |
100 !IsNodeInRoots(*new_parent)) { | |
101 *new_parent = NULL; | |
102 } | |
103 | |
104 if (*old_parent && !IsNodeFromThisConnection(*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 bool DefaultAccessPolicy::IsNodeFromThisConnection(const Node* node) const { | |
127 return node->id().connection_id == connection_id_; | |
128 } | |
129 | |
130 } // namespace service | |
131 } // namespace mojo | |
OLD | NEW |