summaryrefslogtreecommitdiffstats
path: root/mojo/services/view_manager/window_manager_access_policy.cc
blob: 226630a7bab7b62357833ae09c8886fb13ae6d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/services/view_manager/window_manager_access_policy.h"

#include "mojo/services/view_manager/access_policy_delegate.h"
#include "mojo/services/view_manager/node.h"

namespace mojo {
namespace service {

// TODO(sky): document why this differs from default for each case. Maybe want
// to subclass DefaultAccessPolicy.

WindowManagerAccessPolicy::WindowManagerAccessPolicy(
    ConnectionSpecificId connection_id,
    AccessPolicyDelegate* delegate)
    : connection_id_(connection_id),
      delegate_(delegate) {
}

WindowManagerAccessPolicy::~WindowManagerAccessPolicy() {
}

bool WindowManagerAccessPolicy::CanRemoveNodeFromParent(
    const Node* node) const {
  return true;
}

bool WindowManagerAccessPolicy::CanAddNode(const Node* parent,
                                           const Node* child) const {
  return true;
}

bool WindowManagerAccessPolicy::CanReorderNode(const Node* node,
                                               const Node* relative_node,
                                               OrderDirection direction) const {
  return true;
}

bool WindowManagerAccessPolicy::CanDeleteNode(const Node* node) const {
  return node->id().connection_id == connection_id_;
}

bool WindowManagerAccessPolicy::CanGetNodeTree(const Node* node) const {
  return true;
}

bool WindowManagerAccessPolicy::CanDescendIntoNodeForNodeTree(
    const Node* node) const {
  return true;
}

bool WindowManagerAccessPolicy::CanEmbed(const Node* node) const {
  return node->id().connection_id == connection_id_;
}

bool WindowManagerAccessPolicy::CanChangeNodeVisibility(
    const Node* node) const {
  return node->id().connection_id == connection_id_;
}

bool WindowManagerAccessPolicy::CanSetNodeContents(const Node* node) const {
  if (delegate_->IsNodeRootOfAnotherConnectionForAccessPolicy(node))
    return false;
  return node->id().connection_id == connection_id_ ||
      (delegate_->GetRootsForAccessPolicy().count(
          NodeIdToTransportId(node->id())) > 0);
}

bool WindowManagerAccessPolicy::CanSetNodeBounds(const Node* node) const {
  return node->id().connection_id == connection_id_;
}

bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
    const Node* node,
    const Node** new_parent,
    const Node** old_parent) const {
  // Notify if we've already told the window manager about the node, or if we've
  // already told the window manager about the parent. The later handles the
  // case of a node that wasn't parented to the root getting added to the root.
  return IsNodeKnown(node) || (*new_parent && IsNodeKnown(*new_parent));
}

bool WindowManagerAccessPolicy::ShouldSendViewDeleted(
    const ViewId& view_id) const {
  return true;
}

bool WindowManagerAccessPolicy::IsNodeKnown(const Node* node) const {
  return delegate_->IsNodeKnownForAccessPolicy(node);
}

}  // namespace service
}  // namespace mojo