Mandoline: Rename components/view_manager to components/mus
[chromium-blink-merge.git] / components / mus / default_access_policy.cc
blobafa4fd2978e237ec2ef92873fd067f68ba553f77
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.
5 #include "components/mus/default_access_policy.h"
7 #include "components/mus/access_policy_delegate.h"
8 #include "components/mus/server_view.h"
10 namespace view_manager {
12 DefaultAccessPolicy::DefaultAccessPolicy(
13 mojo::ConnectionSpecificId connection_id,
14 AccessPolicyDelegate* delegate)
15 : connection_id_(connection_id), delegate_(delegate) {}
17 DefaultAccessPolicy::~DefaultAccessPolicy() {}
19 bool DefaultAccessPolicy::CanRemoveViewFromParent(
20 const ServerView* view) const {
21 if (!WasCreatedByThisConnection(view))
22 return false; // Can only unparent views we created.
24 return delegate_->IsRootForAccessPolicy(view->parent()->id()) ||
25 WasCreatedByThisConnection(view->parent());
28 bool DefaultAccessPolicy::CanAddView(const ServerView* parent,
29 const ServerView* child) const {
30 return WasCreatedByThisConnection(child) &&
31 (delegate_->IsRootForAccessPolicy(parent->id()) ||
32 (WasCreatedByThisConnection(parent) &&
33 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(parent)));
36 bool DefaultAccessPolicy::CanReorderView(const ServerView* view,
37 const ServerView* relative_view,
38 mojo::OrderDirection direction) const {
39 return WasCreatedByThisConnection(view) &&
40 WasCreatedByThisConnection(relative_view);
43 bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const {
44 return WasCreatedByThisConnection(view);
47 bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const {
48 return WasCreatedByThisConnection(view) ||
49 delegate_->IsRootForAccessPolicy(view->id()) ||
50 IsDescendantOfEmbedRoot(view);
53 bool DefaultAccessPolicy::CanDescendIntoViewForViewTree(
54 const ServerView* view) const {
55 return (WasCreatedByThisConnection(view) &&
56 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view)) ||
57 delegate_->IsRootForAccessPolicy(view->id()) ||
58 delegate_->IsDescendantOfEmbedRoot(view);
61 bool DefaultAccessPolicy::CanEmbed(const ServerView* view) const {
62 return WasCreatedByThisConnection(view) ||
63 (delegate_->IsViewKnownForAccessPolicy(view) &&
64 IsDescendantOfEmbedRoot(view) &&
65 !delegate_->IsRootForAccessPolicy(view->id()));
68 bool DefaultAccessPolicy::CanChangeViewVisibility(
69 const ServerView* view) const {
70 return WasCreatedByThisConnection(view) ||
71 delegate_->IsRootForAccessPolicy(view->id());
74 bool DefaultAccessPolicy::CanSetViewSurfaceId(const ServerView* view) const {
75 // Once a view embeds another app, the embedder app is no longer able to
76 // call SetViewSurfaceId() - this ability is transferred to the embedded app.
77 if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view))
78 return false;
79 return WasCreatedByThisConnection(view) ||
80 delegate_->IsRootForAccessPolicy(view->id());
83 bool DefaultAccessPolicy::CanSetViewBounds(const ServerView* view) const {
84 return WasCreatedByThisConnection(view);
87 bool DefaultAccessPolicy::CanSetViewProperties(const ServerView* view) const {
88 return WasCreatedByThisConnection(view);
91 bool DefaultAccessPolicy::CanSetViewTextInputState(
92 const ServerView* view) const {
93 return WasCreatedByThisConnection(view) ||
94 delegate_->IsRootForAccessPolicy(view->id());
97 bool DefaultAccessPolicy::CanSetFocus(const ServerView* view) const {
98 return WasCreatedByThisConnection(view) ||
99 delegate_->IsRootForAccessPolicy(view->id());
102 bool DefaultAccessPolicy::CanSetAccessPolicy(const ServerView* view) const {
103 return false;
106 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange(
107 const ServerView* view,
108 const ServerView** new_parent,
109 const ServerView** old_parent) const {
110 if (!WasCreatedByThisConnection(view) && !IsDescendantOfEmbedRoot(view) &&
111 (!*new_parent || !IsDescendantOfEmbedRoot(*new_parent)) &&
112 (!*old_parent || !IsDescendantOfEmbedRoot(*old_parent))) {
113 return false;
116 if (*new_parent && !WasCreatedByThisConnection(*new_parent) &&
117 !delegate_->IsRootForAccessPolicy((*new_parent)->id()) &&
118 !delegate_->IsDescendantOfEmbedRoot(*new_parent)) {
119 *new_parent = nullptr;
122 if (*old_parent && !WasCreatedByThisConnection(*old_parent) &&
123 !delegate_->IsRootForAccessPolicy((*old_parent)->id()) &&
124 !delegate_->IsDescendantOfEmbedRoot(*new_parent)) {
125 *old_parent = nullptr;
127 return true;
130 const ServerView* DefaultAccessPolicy::GetViewForFocusChange(
131 const ServerView* focused) {
132 if (WasCreatedByThisConnection(focused) ||
133 delegate_->IsRootForAccessPolicy(focused->id()))
134 return focused;
135 return nullptr;
138 bool DefaultAccessPolicy::WasCreatedByThisConnection(
139 const ServerView* view) const {
140 return view->id().connection_id == connection_id_;
143 bool DefaultAccessPolicy::IsDescendantOfEmbedRoot(
144 const ServerView* view) const {
145 return delegate_->IsDescendantOfEmbedRoot(view);
148 } // namespace view_manager