| 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/mus/default_access_policy.h" | |
| 6 | |
| 7 #include "components/mus/access_policy_delegate.h" | |
| 8 #include "components/mus/server_view.h" | |
| 9 | |
| 10 namespace mus { | |
| 11 | |
| 12 DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id, | |
| 13 AccessPolicyDelegate* delegate) | |
| 14 : connection_id_(connection_id), delegate_(delegate) {} | |
| 15 | |
| 16 DefaultAccessPolicy::~DefaultAccessPolicy() {} | |
| 17 | |
| 18 bool DefaultAccessPolicy::CanRemoveViewFromParent( | |
| 19 const ServerView* view) const { | |
| 20 if (!WasCreatedByThisConnection(view)) | |
| 21 return false; // Can only unparent views we created. | |
| 22 | |
| 23 return delegate_->IsRootForAccessPolicy(view->parent()->id()) || | |
| 24 WasCreatedByThisConnection(view->parent()); | |
| 25 } | |
| 26 | |
| 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))); | |
| 33 } | |
| 34 | |
| 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); | |
| 40 } | |
| 41 | |
| 42 bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const { | |
| 43 return WasCreatedByThisConnection(view); | |
| 44 } | |
| 45 | |
| 46 bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const { | |
| 47 return WasCreatedByThisConnection(view) || | |
| 48 delegate_->IsRootForAccessPolicy(view->id()) || | |
| 49 IsDescendantOfEmbedRoot(view); | |
| 50 } | |
| 51 | |
| 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); | |
| 58 } | |
| 59 | |
| 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())); | |
| 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::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; | |
| 112 } | |
| 113 | |
| 114 if (*new_parent && !WasCreatedByThisConnection(*new_parent) && | |
| 115 !delegate_->IsRootForAccessPolicy((*new_parent)->id()) && | |
| 116 !delegate_->IsDescendantOfEmbedRoot(*new_parent)) { | |
| 117 *new_parent = nullptr; | |
| 118 } | |
| 119 | |
| 120 if (*old_parent && !WasCreatedByThisConnection(*old_parent) && | |
| 121 !delegate_->IsRootForAccessPolicy((*old_parent)->id()) && | |
| 122 !delegate_->IsDescendantOfEmbedRoot(*new_parent)) { | |
| 123 *old_parent = nullptr; | |
| 124 } | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 const ServerView* DefaultAccessPolicy::GetViewForFocusChange( | |
| 129 const ServerView* focused) { | |
| 130 if (WasCreatedByThisConnection(focused) || | |
| 131 delegate_->IsRootForAccessPolicy(focused->id())) | |
| 132 return focused; | |
| 133 return nullptr; | |
| 134 } | |
| 135 | |
| 136 bool DefaultAccessPolicy::WasCreatedByThisConnection( | |
| 137 const ServerView* view) const { | |
| 138 return view->id().connection_id == connection_id_; | |
| 139 } | |
| 140 | |
| 141 bool DefaultAccessPolicy::IsDescendantOfEmbedRoot( | |
| 142 const ServerView* view) const { | |
| 143 return delegate_->IsDescendantOfEmbedRoot(view); | |
| 144 } | |
| 145 | |
| 146 } // namespace mus | |
| OLD | NEW |