Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / components / mus / window_manager_access_policy.cc
blob7e9e5b0d6472d570daaf4b0367ee159b3fb18233
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"
10 namespace mus {
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 {
24 return true;
27 bool WindowManagerAccessPolicy::CanAddView(const ServerView* parent,
28 const ServerView* child) const {
29 return true;
32 bool WindowManagerAccessPolicy::CanReorderView(
33 const ServerView* view,
34 const ServerView* relative_view,
35 mojo::OrderDirection direction) const {
36 return true;
39 bool WindowManagerAccessPolicy::CanDeleteView(const ServerView* view) const {
40 return view->id().connection_id == connection_id_;
43 bool WindowManagerAccessPolicy::CanGetViewTree(const ServerView* view) const {
44 return true;
47 bool WindowManagerAccessPolicy::CanDescendIntoViewForViewTree(
48 const ServerView* view) const {
49 return true;
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))
67 return false;
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 {
87 return true;
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) {
102 return focused;
105 bool WindowManagerAccessPolicy::IsViewKnown(const ServerView* view) const {
106 return delegate_->IsViewKnownForAccessPolicy(view);
109 } // namespace mus