Update V8 to version 4.6.52.
[chromium-blink-merge.git] / components / view_manager / window_manager_access_policy.cc
bloba04e7396a8b8e736bbe7733990685c4748cbf4cc
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/view_manager/window_manager_access_policy.h"
7 #include "components/view_manager/access_policy_delegate.h"
8 #include "components/view_manager/server_view.h"
10 namespace view_manager {
12 // TODO(sky): document why this differs from default for each case. Maybe want
13 // to subclass DefaultAccessPolicy.
15 WindowManagerAccessPolicy::WindowManagerAccessPolicy(
16 mojo::ConnectionSpecificId connection_id,
17 AccessPolicyDelegate* delegate)
18 : connection_id_(connection_id), delegate_(delegate) {
21 WindowManagerAccessPolicy::~WindowManagerAccessPolicy() {
24 bool WindowManagerAccessPolicy::CanRemoveViewFromParent(
25 const ServerView* view) const {
26 return true;
29 bool WindowManagerAccessPolicy::CanAddView(const ServerView* parent,
30 const ServerView* child) const {
31 return true;
34 bool WindowManagerAccessPolicy::CanReorderView(
35 const ServerView* view,
36 const ServerView* relative_view,
37 mojo::OrderDirection direction) const {
38 return true;
41 bool WindowManagerAccessPolicy::CanDeleteView(const ServerView* view) const {
42 return view->id().connection_id == connection_id_;
45 bool WindowManagerAccessPolicy::CanGetViewTree(const ServerView* view) const {
46 return view->id() != ClonedViewId();
49 bool WindowManagerAccessPolicy::CanDescendIntoViewForViewTree(
50 const ServerView* view) const {
51 return view->id() != ClonedViewId();
54 bool WindowManagerAccessPolicy::CanEmbed(const ServerView* view) const {
55 return view->id().connection_id == connection_id_ ||
56 (view->allows_reembed() &&
57 delegate_->IsViewKnownForAccessPolicy(view));
60 bool WindowManagerAccessPolicy::CanChangeViewVisibility(
61 const ServerView* view) const {
62 // The WindowManager can change the visibility of the root too.
63 return view->id().connection_id == connection_id_ ||
64 (view->GetRoot() == view);
67 bool WindowManagerAccessPolicy::CanSetViewSurfaceId(
68 const ServerView* view) const {
69 if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view))
70 return false;
71 return view->id().connection_id == connection_id_ ||
72 (delegate_->IsRootForAccessPolicy(view->id()));
75 bool WindowManagerAccessPolicy::CanSetViewBounds(const ServerView* view) const {
76 return view->id().connection_id == connection_id_;
79 bool WindowManagerAccessPolicy::CanSetViewProperties(
80 const ServerView* view) const {
81 return view->id().connection_id == connection_id_;
84 bool WindowManagerAccessPolicy::CanSetViewTextInputState(
85 const ServerView* view) const {
86 return view->id().connection_id == connection_id_;
89 bool WindowManagerAccessPolicy::CanSetFocus(const ServerView* view) const {
90 return true;
93 bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
94 const ServerView* view,
95 const ServerView** new_parent,
96 const ServerView** old_parent) const {
97 if (view->id() == ClonedViewId())
98 return false;
100 // Notify if we've already told the window manager about the view, or if we've
101 // already told the window manager about the parent. The later handles the
102 // case of a view that wasn't parented to the root getting added to the root.
103 return IsViewKnown(view) || (*new_parent && IsViewKnown(*new_parent));
106 const ServerView* WindowManagerAccessPolicy::GetViewForFocusChange(
107 const ServerView* focused) {
108 return focused;
111 bool WindowManagerAccessPolicy::IsViewKnown(const ServerView* view) const {
112 return delegate_->IsViewKnownForAccessPolicy(view);
115 } // namespace view_manager