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 "components/view_manager/default_access_policy.h" | |
6 | |
7 #include "components/view_manager/access_policy_delegate.h" | |
8 #include "components/view_manager/server_view.h" | |
9 | |
10 namespace view_manager { | |
11 | |
12 DefaultAccessPolicy::DefaultAccessPolicy( | |
13 mojo::ConnectionSpecificId connection_id, | |
14 AccessPolicyDelegate* delegate) | |
15 : connection_id_(connection_id), delegate_(delegate) { | |
16 } | |
17 | |
18 DefaultAccessPolicy::~DefaultAccessPolicy() { | |
19 } | |
20 | |
21 bool DefaultAccessPolicy::CanRemoveViewFromParent( | |
22 const ServerView* view) const { | |
23 if (!WasCreatedByThisConnection(view)) | |
24 return false; // Can only unparent views we created. | |
25 | |
26 return delegate_->IsRootForAccessPolicy(view->parent()->id()) || | |
27 WasCreatedByThisConnection(view->parent()); | |
28 } | |
29 | |
30 bool DefaultAccessPolicy::CanAddView(const ServerView* parent, | |
31 const ServerView* child) const { | |
32 return WasCreatedByThisConnection(child) && | |
33 (delegate_->IsRootForAccessPolicy(parent->id()) || | |
34 (WasCreatedByThisConnection(parent) && | |
35 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(parent))); | |
36 } | |
37 | |
38 bool DefaultAccessPolicy::CanReorderView(const ServerView* view, | |
39 const ServerView* relative_view, | |
40 mojo::OrderDirection direction) const { | |
41 return WasCreatedByThisConnection(view) && | |
42 WasCreatedByThisConnection(relative_view); | |
43 } | |
44 | |
45 bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const { | |
46 return WasCreatedByThisConnection(view); | |
47 } | |
48 | |
49 bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const { | |
50 return WasCreatedByThisConnection(view) || | |
51 delegate_->IsRootForAccessPolicy(view->id()) || | |
52 IsDescendantOfEmbedRoot(view); | |
53 } | |
54 | |
55 bool DefaultAccessPolicy::CanDescendIntoViewForViewTree( | |
56 const ServerView* view) const { | |
57 return (WasCreatedByThisConnection(view) && | |
58 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view)) || | |
59 delegate_->IsRootForAccessPolicy(view->id()) || | |
60 delegate_->IsDescendantOfEmbedRoot(view); | |
61 } | |
62 | |
63 bool DefaultAccessPolicy::CanEmbed(const ServerView* view) const { | |
64 return WasCreatedByThisConnection(view) || | |
65 (delegate_->IsViewKnownForAccessPolicy(view) && | |
66 IsDescendantOfEmbedRoot(view) && | |
67 !delegate_->IsRootForAccessPolicy(view->id())); | |
68 } | |
69 | |
70 bool DefaultAccessPolicy::CanChangeViewVisibility( | |
71 const ServerView* view) const { | |
72 return WasCreatedByThisConnection(view) || | |
73 delegate_->IsRootForAccessPolicy(view->id()); | |
74 } | |
75 | |
76 bool DefaultAccessPolicy::CanSetViewSurfaceId(const ServerView* view) const { | |
77 // Once a view embeds another app, the embedder app is no longer able to | |
78 // call SetViewSurfaceId() - this ability is transferred to the embedded app. | |
79 if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view)) | |
80 return false; | |
81 return WasCreatedByThisConnection(view) || | |
82 delegate_->IsRootForAccessPolicy(view->id()); | |
83 } | |
84 | |
85 bool DefaultAccessPolicy::CanSetViewBounds(const ServerView* view) const { | |
86 return WasCreatedByThisConnection(view); | |
87 } | |
88 | |
89 bool DefaultAccessPolicy::CanSetViewProperties(const ServerView* view) const { | |
90 return WasCreatedByThisConnection(view); | |
91 } | |
92 | |
93 bool DefaultAccessPolicy::CanSetViewTextInputState( | |
94 const ServerView* view) const { | |
95 return WasCreatedByThisConnection(view) || | |
96 delegate_->IsRootForAccessPolicy(view->id()); | |
97 } | |
98 | |
99 bool DefaultAccessPolicy::CanSetFocus(const ServerView* view) const { | |
100 return WasCreatedByThisConnection(view) || | |
101 delegate_->IsRootForAccessPolicy(view->id()); | |
102 } | |
103 | |
104 bool DefaultAccessPolicy::CanSetAccessPolicy(const ServerView* view) const { | |
105 return false; | |
106 } | |
107 | |
108 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange( | |
109 const ServerView* view, | |
110 const ServerView** new_parent, | |
111 const ServerView** old_parent) const { | |
112 if (!WasCreatedByThisConnection(view) && !IsDescendantOfEmbedRoot(view) && | |
113 (!*new_parent || !IsDescendantOfEmbedRoot(*new_parent)) && | |
114 (!*old_parent || !IsDescendantOfEmbedRoot(*old_parent))) { | |
115 return false; | |
116 } | |
117 | |
118 if (*new_parent && !WasCreatedByThisConnection(*new_parent) && | |
119 !delegate_->IsRootForAccessPolicy((*new_parent)->id()) && | |
120 !delegate_->IsDescendantOfEmbedRoot(*new_parent)) { | |
121 *new_parent = nullptr; | |
122 } | |
123 | |
124 if (*old_parent && !WasCreatedByThisConnection(*old_parent) && | |
125 !delegate_->IsRootForAccessPolicy((*old_parent)->id()) && | |
126 !delegate_->IsDescendantOfEmbedRoot(*new_parent)) { | |
127 *old_parent = nullptr; | |
128 } | |
129 return true; | |
130 } | |
131 | |
132 const ServerView* DefaultAccessPolicy::GetViewForFocusChange( | |
133 const ServerView* focused) { | |
134 if (WasCreatedByThisConnection(focused) || | |
135 delegate_->IsRootForAccessPolicy(focused->id())) | |
136 return focused; | |
137 return nullptr; | |
138 } | |
139 | |
140 bool DefaultAccessPolicy::WasCreatedByThisConnection( | |
141 const ServerView* view) const { | |
142 return view->id().connection_id == connection_id_; | |
143 } | |
144 | |
145 bool DefaultAccessPolicy::IsDescendantOfEmbedRoot( | |
146 const ServerView* view) const { | |
147 return delegate_->IsDescendantOfEmbedRoot(view); | |
148 } | |
149 | |
150 } // namespace view_manager | |
OLD | NEW |