Roll ANGLE cc54ab3..c5b2ba5
[chromium-blink-merge.git] / components / mus / default_access_policy.cc
blobf5ffd78dbdb46c510e7077e7d6e31b77ea7a9361
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 mus {
12 DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id,
13 AccessPolicyDelegate* delegate)
14 : connection_id_(connection_id), delegate_(delegate) {}
16 DefaultAccessPolicy::~DefaultAccessPolicy() {}
18 bool DefaultAccessPolicy::CanRemoveViewFromParent(
19 const ServerView* view) const {
20 if (!WasCreatedByThisConnection(view))
21 return false; // Can only unparent views we created.
23 return delegate_->IsRootForAccessPolicy(view->parent()->id()) ||
24 WasCreatedByThisConnection(view->parent());
27 bool DefaultAccessPolicy::CanAddView(const ServerView* parent,
28 const ServerView* child) const {
29 return WasCreatedByThisConnection(child) &&
30 (delegate_->IsRootForAccessPolicy(parent->id()) ||
31 (WasCreatedByThisConnection(parent) &&
32 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(parent)));
35 bool DefaultAccessPolicy::CanReorderView(const ServerView* view,
36 const ServerView* relative_view,
37 mojo::OrderDirection direction) const {
38 return WasCreatedByThisConnection(view) &&
39 WasCreatedByThisConnection(relative_view);
42 bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const {
43 return WasCreatedByThisConnection(view);
46 bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const {
47 return WasCreatedByThisConnection(view) ||
48 delegate_->IsRootForAccessPolicy(view->id()) ||
49 IsDescendantOfEmbedRoot(view);
52 bool DefaultAccessPolicy::CanDescendIntoViewForViewTree(
53 const ServerView* view) const {
54 return (WasCreatedByThisConnection(view) &&
55 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view)) ||
56 delegate_->IsRootForAccessPolicy(view->id()) ||
57 delegate_->IsDescendantOfEmbedRoot(view);
60 bool DefaultAccessPolicy::CanEmbed(const ServerView* view,
61 uint32_t policy_bitmask) const {
62 if (policy_bitmask != mojo::ViewTree::ACCESS_POLICY_DEFAULT)
63 return false;
64 return WasCreatedByThisConnection(view) ||
65 (delegate_->IsViewKnownForAccessPolicy(view) &&
66 IsDescendantOfEmbedRoot(view) &&
67 !delegate_->IsRootForAccessPolicy(view->id()));
70 bool DefaultAccessPolicy::CanChangeViewVisibility(
71 const ServerView* view) const {
72 return WasCreatedByThisConnection(view) ||
73 delegate_->IsRootForAccessPolicy(view->id());
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());
85 bool DefaultAccessPolicy::CanSetViewBounds(const ServerView* view) const {
86 return WasCreatedByThisConnection(view);
89 bool DefaultAccessPolicy::CanSetViewProperties(const ServerView* view) const {
90 return WasCreatedByThisConnection(view);
93 bool DefaultAccessPolicy::CanSetViewTextInputState(
94 const ServerView* view) const {
95 return WasCreatedByThisConnection(view) ||
96 delegate_->IsRootForAccessPolicy(view->id());
99 bool DefaultAccessPolicy::CanSetFocus(const ServerView* view) const {
100 return WasCreatedByThisConnection(view) ||
101 delegate_->IsRootForAccessPolicy(view->id());
104 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange(
105 const ServerView* view,
106 const ServerView** new_parent,
107 const ServerView** old_parent) const {
108 if (!WasCreatedByThisConnection(view) && !IsDescendantOfEmbedRoot(view) &&
109 (!*new_parent || !IsDescendantOfEmbedRoot(*new_parent)) &&
110 (!*old_parent || !IsDescendantOfEmbedRoot(*old_parent))) {
111 return false;
114 if (*new_parent && !WasCreatedByThisConnection(*new_parent) &&
115 !delegate_->IsRootForAccessPolicy((*new_parent)->id()) &&
116 !delegate_->IsDescendantOfEmbedRoot(*new_parent)) {
117 *new_parent = nullptr;
120 if (*old_parent && !WasCreatedByThisConnection(*old_parent) &&
121 !delegate_->IsRootForAccessPolicy((*old_parent)->id()) &&
122 !delegate_->IsDescendantOfEmbedRoot(*new_parent)) {
123 *old_parent = nullptr;
125 return true;
128 const ServerView* DefaultAccessPolicy::GetViewForFocusChange(
129 const ServerView* focused) {
130 if (WasCreatedByThisConnection(focused) ||
131 delegate_->IsRootForAccessPolicy(focused->id()))
132 return focused;
133 return nullptr;
136 bool DefaultAccessPolicy::WasCreatedByThisConnection(
137 const ServerView* view) const {
138 return view->id().connection_id == connection_id_;
141 bool DefaultAccessPolicy::IsDescendantOfEmbedRoot(
142 const ServerView* view) const {
143 return delegate_->IsDescendantOfEmbedRoot(view);
146 } // namespace mus