| 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/ws/default_access_policy.h" | |
| 6 | |
| 7 #include "components/mus/ws/access_policy_delegate.h" | |
| 8 #include "components/mus/ws/server_window.h" | |
| 9 | |
| 10 namespace mus { | |
| 11 namespace ws { | |
| 12 | |
| 13 DefaultAccessPolicy::DefaultAccessPolicy() {} | |
| 14 | |
| 15 DefaultAccessPolicy::~DefaultAccessPolicy() {} | |
| 16 | |
| 17 void DefaultAccessPolicy::Init(ClientSpecificId client_id, | |
| 18 AccessPolicyDelegate* delegate) { | |
| 19 client_id_ = client_id; | |
| 20 delegate_ = delegate; | |
| 21 } | |
| 22 | |
| 23 bool DefaultAccessPolicy::CanRemoveWindowFromParent( | |
| 24 const ServerWindow* window) const { | |
| 25 if (!WasCreatedByThisClient(window)) | |
| 26 return false; // Can only unparent windows we created. | |
| 27 | |
| 28 return delegate_->HasRootForAccessPolicy(window->parent()) || | |
| 29 WasCreatedByThisClient(window->parent()); | |
| 30 } | |
| 31 | |
| 32 bool DefaultAccessPolicy::CanAddWindow(const ServerWindow* parent, | |
| 33 const ServerWindow* child) const { | |
| 34 return WasCreatedByThisClient(child) && | |
| 35 (delegate_->HasRootForAccessPolicy(parent) || | |
| 36 (WasCreatedByThisClient(parent) && | |
| 37 !delegate_->IsWindowRootOfAnotherTreeForAccessPolicy(parent))); | |
| 38 } | |
| 39 | |
| 40 bool DefaultAccessPolicy::CanAddTransientWindow( | |
| 41 const ServerWindow* parent, | |
| 42 const ServerWindow* child) const { | |
| 43 return (delegate_->HasRootForAccessPolicy(child) || | |
| 44 WasCreatedByThisClient(child)) && | |
| 45 (delegate_->HasRootForAccessPolicy(parent) || | |
| 46 WasCreatedByThisClient(parent)); | |
| 47 } | |
| 48 | |
| 49 bool DefaultAccessPolicy::CanRemoveTransientWindowFromParent( | |
| 50 const ServerWindow* window) const { | |
| 51 return (delegate_->HasRootForAccessPolicy(window) || | |
| 52 WasCreatedByThisClient(window)) && | |
| 53 (delegate_->HasRootForAccessPolicy(window->transient_parent()) || | |
| 54 WasCreatedByThisClient(window->transient_parent())); | |
| 55 } | |
| 56 | |
| 57 bool DefaultAccessPolicy::CanSetModal(const ServerWindow* window) const { | |
| 58 return delegate_->HasRootForAccessPolicy(window) || | |
| 59 WasCreatedByThisClient(window); | |
| 60 } | |
| 61 | |
| 62 bool DefaultAccessPolicy::CanReorderWindow( | |
| 63 const ServerWindow* window, | |
| 64 const ServerWindow* relative_window, | |
| 65 mojom::OrderDirection direction) const { | |
| 66 return WasCreatedByThisClient(window) && | |
| 67 WasCreatedByThisClient(relative_window); | |
| 68 } | |
| 69 | |
| 70 bool DefaultAccessPolicy::CanDeleteWindow(const ServerWindow* window) const { | |
| 71 return WasCreatedByThisClient(window); | |
| 72 } | |
| 73 | |
| 74 bool DefaultAccessPolicy::CanGetWindowTree(const ServerWindow* window) const { | |
| 75 return WasCreatedByThisClient(window) || | |
| 76 delegate_->HasRootForAccessPolicy(window); | |
| 77 } | |
| 78 | |
| 79 bool DefaultAccessPolicy::CanDescendIntoWindowForWindowTree( | |
| 80 const ServerWindow* window) const { | |
| 81 return (WasCreatedByThisClient(window) && | |
| 82 !delegate_->IsWindowRootOfAnotherTreeForAccessPolicy(window)) || | |
| 83 delegate_->HasRootForAccessPolicy(window); | |
| 84 } | |
| 85 | |
| 86 bool DefaultAccessPolicy::CanEmbed(const ServerWindow* window) const { | |
| 87 return WasCreatedByThisClient(window); | |
| 88 } | |
| 89 | |
| 90 bool DefaultAccessPolicy::CanChangeWindowVisibility( | |
| 91 const ServerWindow* window) const { | |
| 92 return WasCreatedByThisClient(window) || | |
| 93 delegate_->HasRootForAccessPolicy(window); | |
| 94 } | |
| 95 | |
| 96 bool DefaultAccessPolicy::CanChangeWindowOpacity( | |
| 97 const ServerWindow* window) const { | |
| 98 return WasCreatedByThisClient(window) || | |
| 99 delegate_->HasRootForAccessPolicy(window); | |
| 100 } | |
| 101 | |
| 102 bool DefaultAccessPolicy::CanSetWindowSurface( | |
| 103 const ServerWindow* window, | |
| 104 mojom::SurfaceType surface_type) const { | |
| 105 if (surface_type == mojom::SurfaceType::UNDERLAY) | |
| 106 return WasCreatedByThisClient(window); | |
| 107 | |
| 108 // Once a window embeds another app, the embedder app is no longer able to | |
| 109 // call SetWindowSurfaceId() - this ability is transferred to the embedded | |
| 110 // app. | |
| 111 if (delegate_->IsWindowRootOfAnotherTreeForAccessPolicy(window)) | |
| 112 return false; | |
| 113 return WasCreatedByThisClient(window) || | |
| 114 delegate_->HasRootForAccessPolicy(window); | |
| 115 } | |
| 116 | |
| 117 bool DefaultAccessPolicy::CanSetWindowBounds(const ServerWindow* window) const { | |
| 118 return WasCreatedByThisClient(window); | |
| 119 } | |
| 120 | |
| 121 bool DefaultAccessPolicy::CanSetWindowProperties( | |
| 122 const ServerWindow* window) const { | |
| 123 return WasCreatedByThisClient(window); | |
| 124 } | |
| 125 | |
| 126 bool DefaultAccessPolicy::CanSetWindowTextInputState( | |
| 127 const ServerWindow* window) const { | |
| 128 return WasCreatedByThisClient(window) || | |
| 129 delegate_->HasRootForAccessPolicy(window); | |
| 130 } | |
| 131 | |
| 132 bool DefaultAccessPolicy::CanSetCapture(const ServerWindow* window) const { | |
| 133 return WasCreatedByThisClient(window) || | |
| 134 delegate_->HasRootForAccessPolicy(window); | |
| 135 } | |
| 136 | |
| 137 bool DefaultAccessPolicy::CanSetFocus(const ServerWindow* window) const { | |
| 138 return !window || WasCreatedByThisClient(window) || | |
| 139 delegate_->HasRootForAccessPolicy(window); | |
| 140 } | |
| 141 | |
| 142 bool DefaultAccessPolicy::CanSetClientArea(const ServerWindow* window) const { | |
| 143 return WasCreatedByThisClient(window) || | |
| 144 delegate_->HasRootForAccessPolicy(window); | |
| 145 } | |
| 146 | |
| 147 bool DefaultAccessPolicy::CanSetHitTestMask(const ServerWindow* window) const { | |
| 148 return WasCreatedByThisClient(window) || | |
| 149 delegate_->HasRootForAccessPolicy(window); | |
| 150 } | |
| 151 | |
| 152 bool DefaultAccessPolicy::CanSetCursorProperties( | |
| 153 const ServerWindow* window) const { | |
| 154 return WasCreatedByThisClient(window) || | |
| 155 delegate_->HasRootForAccessPolicy(window); | |
| 156 } | |
| 157 | |
| 158 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange( | |
| 159 const ServerWindow* window, | |
| 160 const ServerWindow** new_parent, | |
| 161 const ServerWindow** old_parent) const { | |
| 162 if (!WasCreatedByThisClient(window)) | |
| 163 return false; | |
| 164 | |
| 165 if (*new_parent && !WasCreatedByThisClient(*new_parent) && | |
| 166 !delegate_->HasRootForAccessPolicy((*new_parent))) { | |
| 167 *new_parent = nullptr; | |
| 168 } | |
| 169 | |
| 170 if (*old_parent && !WasCreatedByThisClient(*old_parent) && | |
| 171 !delegate_->HasRootForAccessPolicy((*old_parent))) { | |
| 172 *old_parent = nullptr; | |
| 173 } | |
| 174 return true; | |
| 175 } | |
| 176 | |
| 177 const ServerWindow* DefaultAccessPolicy::GetWindowForFocusChange( | |
| 178 const ServerWindow* focused) { | |
| 179 if (WasCreatedByThisClient(focused) || | |
| 180 delegate_->HasRootForAccessPolicy(focused)) | |
| 181 return focused; | |
| 182 return nullptr; | |
| 183 } | |
| 184 | |
| 185 bool DefaultAccessPolicy::CanSetWindowManager() const { | |
| 186 return false; | |
| 187 } | |
| 188 | |
| 189 bool DefaultAccessPolicy::WasCreatedByThisClient( | |
| 190 const ServerWindow* window) const { | |
| 191 return window->id().client_id == client_id_; | |
| 192 } | |
| 193 | |
| 194 bool DefaultAccessPolicy::IsValidIdForNewWindow( | |
| 195 const ClientWindowId& id) const { | |
| 196 // Clients using DefaultAccessPolicy only see windows they have created (for | |
| 197 // the embed point they choose the id), so it's ok for clients to use whatever | |
| 198 // id they want. | |
| 199 return true; | |
| 200 } | |
| 201 | |
| 202 } // namespace ws | |
| 203 } // namespace mus | |
| OLD | NEW |