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/server_view.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::CanRemoveViewFromParent(
27 const ServerView
* view
) const {
31 bool WindowManagerAccessPolicy::CanAddView(const ServerView
* parent
,
32 const ServerView
* child
) const {
36 bool WindowManagerAccessPolicy::CanReorderView(const ServerView
* view
,
37 const ServerView
* relative_view
,
38 OrderDirection direction
) const {
42 bool WindowManagerAccessPolicy::CanDeleteView(const ServerView
* view
) const {
43 return view
->id().connection_id
== connection_id_
;
46 bool WindowManagerAccessPolicy::CanGetViewTree(const ServerView
* view
) const {
50 bool WindowManagerAccessPolicy::CanDescendIntoViewForViewTree(
51 const ServerView
* view
) const {
55 bool WindowManagerAccessPolicy::CanEmbed(const ServerView
* view
) const {
56 return view
->id().connection_id
== connection_id_
;
59 bool WindowManagerAccessPolicy::CanChangeViewVisibility(
60 const ServerView
* view
) const {
61 return view
->id().connection_id
== connection_id_
;
64 bool WindowManagerAccessPolicy::CanSetViewContents(
65 const ServerView
* view
) const {
66 if (delegate_
->IsViewRootOfAnotherConnectionForAccessPolicy(view
))
68 return view
->id().connection_id
== connection_id_
||
69 (delegate_
->GetRootsForAccessPolicy().count(
70 ViewIdToTransportId(view
->id())) > 0);
73 bool WindowManagerAccessPolicy::CanSetViewBounds(const ServerView
* view
) const {
74 return view
->id().connection_id
== connection_id_
;
77 bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
78 const ServerView
* view
,
79 const ServerView
** new_parent
,
80 const ServerView
** old_parent
) const {
81 // Notify if we've already told the window manager about the view, or if we've
82 // already told the window manager about the parent. The later handles the
83 // case of a view that wasn't parented to the root getting added to the root.
84 return IsViewKnown(view
) || (*new_parent
&& IsViewKnown(*new_parent
));
87 bool WindowManagerAccessPolicy::IsViewKnown(const ServerView
* view
) const {
88 return delegate_
->IsViewKnownForAccessPolicy(view
);
91 } // namespace service