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 "mojo/services/view_manager/window_manager_access_policy.h"
7 #include "mojo/services/view_manager/access_policy_delegate.h"
8 #include "mojo/services/view_manager/node.h"
13 // TODO(sky): document why this differs from default for each case. Maybe want
14 // to subclass DefaultAccessPolicy.
16 WindowManagerAccessPolicy::WindowManagerAccessPolicy(
17 ConnectionSpecificId connection_id
,
18 AccessPolicyDelegate
* delegate
)
19 : connection_id_(connection_id
),
23 WindowManagerAccessPolicy::~WindowManagerAccessPolicy() {
26 bool WindowManagerAccessPolicy::CanRemoveNodeFromParent(
27 const Node
* node
) const {
31 bool WindowManagerAccessPolicy::CanAddNode(const Node
* parent
,
32 const Node
* child
) const {
36 bool WindowManagerAccessPolicy::CanReorderNode(const Node
* node
,
37 const Node
* relative_node
,
38 OrderDirection direction
) const {
42 bool WindowManagerAccessPolicy::CanDeleteNode(const Node
* node
) const {
43 return node
->id().connection_id
== connection_id_
;
46 bool WindowManagerAccessPolicy::CanGetNodeTree(const Node
* node
) const {
50 bool WindowManagerAccessPolicy::CanDescendIntoNodeForNodeTree(
51 const Node
* node
) const {
55 bool WindowManagerAccessPolicy::CanEmbed(const Node
* node
) const {
56 return node
->id().connection_id
== connection_id_
;
59 bool WindowManagerAccessPolicy::CanChangeNodeVisibility(
60 const Node
* node
) const {
61 return node
->id().connection_id
== connection_id_
;
64 bool WindowManagerAccessPolicy::CanSetNodeContents(const Node
* node
) const {
65 if (delegate_
->IsNodeRootOfAnotherConnectionForAccessPolicy(node
))
67 return node
->id().connection_id
== connection_id_
||
68 (delegate_
->GetRootsForAccessPolicy().count(
69 NodeIdToTransportId(node
->id())) > 0);
72 bool WindowManagerAccessPolicy::CanSetNodeBounds(const Node
* node
) const {
73 return node
->id().connection_id
== connection_id_
;
76 bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
78 const Node
** new_parent
,
79 const Node
** old_parent
) const {
80 // Notify if we've already told the window manager about the node, or if we've
81 // already told the window manager about the parent. The later handles the
82 // case of a node that wasn't parented to the root getting added to the root.
83 return IsNodeKnown(node
) || (*new_parent
&& IsNodeKnown(*new_parent
));
86 bool WindowManagerAccessPolicy::ShouldSendViewDeleted(
87 const ViewId
& view_id
) const {
91 bool WindowManagerAccessPolicy::IsNodeKnown(const Node
* node
) const {
92 return delegate_
->IsNodeKnownForAccessPolicy(node
);
95 } // namespace service