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 "components/mus/window_manager_access_policy.h"
7 #include "components/mus/access_policy_delegate.h"
8 #include "components/mus/server_view.h"
12 // TODO(sky): document why this differs from default for each case. Maybe want
13 // to subclass DefaultAccessPolicy.
15 WindowManagerAccessPolicy::WindowManagerAccessPolicy(
16 ConnectionSpecificId connection_id
,
17 AccessPolicyDelegate
* delegate
)
18 : connection_id_(connection_id
), delegate_(delegate
) {}
20 WindowManagerAccessPolicy::~WindowManagerAccessPolicy() {}
22 bool WindowManagerAccessPolicy::CanRemoveViewFromParent(
23 const ServerView
* view
) const {
27 bool WindowManagerAccessPolicy::CanAddView(const ServerView
* parent
,
28 const ServerView
* child
) const {
32 bool WindowManagerAccessPolicy::CanReorderView(
33 const ServerView
* view
,
34 const ServerView
* relative_view
,
35 mojo::OrderDirection direction
) const {
39 bool WindowManagerAccessPolicy::CanDeleteView(const ServerView
* view
) const {
40 return view
->id().connection_id
== connection_id_
;
43 bool WindowManagerAccessPolicy::CanGetViewTree(const ServerView
* view
) const {
47 bool WindowManagerAccessPolicy::CanDescendIntoViewForViewTree(
48 const ServerView
* view
) const {
52 bool WindowManagerAccessPolicy::CanEmbed(const ServerView
* view
,
53 uint32_t policy_bitmask
) const {
54 return !delegate_
->IsRootForAccessPolicy(view
->id());
57 bool WindowManagerAccessPolicy::CanChangeViewVisibility(
58 const ServerView
* view
) const {
59 // The WindowManager can change the visibility of the root too.
60 return view
->id().connection_id
== connection_id_
||
61 (view
->GetRoot() == view
);
64 bool WindowManagerAccessPolicy::CanSetViewSurfaceId(
65 const ServerView
* view
) const {
66 if (delegate_
->IsViewRootOfAnotherConnectionForAccessPolicy(view
))
68 return view
->id().connection_id
== connection_id_
||
69 (delegate_
->IsRootForAccessPolicy(view
->id()));
72 bool WindowManagerAccessPolicy::CanSetViewBounds(const ServerView
* view
) const {
73 return view
->id().connection_id
== connection_id_
;
76 bool WindowManagerAccessPolicy::CanSetViewProperties(
77 const ServerView
* view
) const {
78 return view
->id().connection_id
== connection_id_
;
81 bool WindowManagerAccessPolicy::CanSetViewTextInputState(
82 const ServerView
* view
) const {
83 return view
->id().connection_id
== connection_id_
;
86 bool WindowManagerAccessPolicy::CanSetFocus(const ServerView
* view
) const {
90 bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
91 const ServerView
* view
,
92 const ServerView
** new_parent
,
93 const ServerView
** old_parent
) const {
94 // Notify if we've already told the window manager about the view, or if we've
95 // already told the window manager about the parent. The later handles the
96 // case of a view that wasn't parented to the root getting added to the root.
97 return IsViewKnown(view
) || (*new_parent
&& IsViewKnown(*new_parent
));
100 const ServerView
* WindowManagerAccessPolicy::GetViewForFocusChange(
101 const ServerView
* focused
) {
105 bool WindowManagerAccessPolicy::IsViewKnown(const ServerView
* view
) const {
106 return delegate_
->IsViewKnownForAccessPolicy(view
);