[Android] Add tests for toolbar of Chrome Custom Tabs
[chromium-blink-merge.git] / components / view_manager / default_access_policy.cc
blobb307c558ef6fac10db5f1f4f5db912f144771383
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/default_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 DefaultAccessPolicy::DefaultAccessPolicy(
13 mojo::ConnectionSpecificId connection_id,
14 AccessPolicyDelegate* delegate)
15 : connection_id_(connection_id), delegate_(delegate) {
18 DefaultAccessPolicy::~DefaultAccessPolicy() {
21 bool DefaultAccessPolicy::CanRemoveViewFromParent(
22 const ServerView* view) const {
23 if (!WasCreatedByThisConnection(view))
24 return false; // Can only unparent views we created.
26 return delegate_->IsRootForAccessPolicy(view->parent()->id()) ||
27 WasCreatedByThisConnection(view->parent());
30 bool DefaultAccessPolicy::CanAddView(const ServerView* parent,
31 const ServerView* child) const {
32 return WasCreatedByThisConnection(child) &&
33 (delegate_->IsRootForAccessPolicy(parent->id()) ||
34 (WasCreatedByThisConnection(parent) &&
35 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(parent)));
38 bool DefaultAccessPolicy::CanReorderView(const ServerView* view,
39 const ServerView* relative_view,
40 mojo::OrderDirection direction) const {
41 return WasCreatedByThisConnection(view) &&
42 WasCreatedByThisConnection(relative_view);
45 bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const {
46 return WasCreatedByThisConnection(view);
49 bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const {
50 return WasCreatedByThisConnection(view) ||
51 delegate_->IsRootForAccessPolicy(view->id());
54 bool DefaultAccessPolicy::CanDescendIntoViewForViewTree(
55 const ServerView* view) const {
56 return (WasCreatedByThisConnection(view) &&
57 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view)) ||
58 delegate_->IsRootForAccessPolicy(view->id()) ||
59 delegate_->IsEmbedRootForAccessPolicy();
62 bool DefaultAccessPolicy::CanEmbed(const ServerView* view) const {
63 return WasCreatedByThisConnection(view) ||
64 (view->allows_reembed() &&
65 delegate_->IsViewKnownForAccessPolicy(view));
68 bool DefaultAccessPolicy::CanChangeViewVisibility(
69 const ServerView* view) const {
70 return WasCreatedByThisConnection(view) ||
71 delegate_->IsRootForAccessPolicy(view->id());
74 bool DefaultAccessPolicy::CanSetViewSurfaceId(const ServerView* view) const {
75 // Once a view embeds another app, the embedder app is no longer able to
76 // call SetViewSurfaceId() - this ability is transferred to the embedded app.
77 if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view))
78 return false;
79 return WasCreatedByThisConnection(view) ||
80 delegate_->IsRootForAccessPolicy(view->id());
83 bool DefaultAccessPolicy::CanSetViewBounds(const ServerView* view) const {
84 return WasCreatedByThisConnection(view);
87 bool DefaultAccessPolicy::CanSetViewProperties(const ServerView* view) const {
88 return WasCreatedByThisConnection(view);
91 bool DefaultAccessPolicy::CanSetFocus(const ServerView* view) const {
92 return WasCreatedByThisConnection(view) ||
93 delegate_->IsRootForAccessPolicy(view->id());
96 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange(
97 const ServerView* view,
98 const ServerView** new_parent,
99 const ServerView** old_parent) const {
100 if (!WasCreatedByThisConnection(view))
101 return false;
103 if (*new_parent && !WasCreatedByThisConnection(*new_parent) &&
104 !delegate_->IsRootForAccessPolicy((*new_parent)->id())) {
105 *new_parent = NULL;
108 if (*old_parent && !WasCreatedByThisConnection(*old_parent) &&
109 !delegate_->IsRootForAccessPolicy((*old_parent)->id())) {
110 *old_parent = NULL;
112 return true;
115 const ServerView* DefaultAccessPolicy::GetViewForFocusChange(
116 const ServerView* focused) {
117 if (WasCreatedByThisConnection(focused) ||
118 delegate_->IsRootForAccessPolicy(focused->id()))
119 return focused;
120 return nullptr;
123 bool DefaultAccessPolicy::WasCreatedByThisConnection(
124 const ServerView* view) const {
125 return view->id().connection_id == connection_id_;
128 } // namespace view_manager