Move PseudoTCP and channel auth out of LibjingleTransportFactory.
[chromium-blink-merge.git] / mojo / services / view_manager / default_access_policy.cc
bloba2443c3d432e7df0fc31fa34c029e11e19a11c73
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/default_access_policy.h"
7 #include "mojo/services/view_manager/access_policy_delegate.h"
8 #include "mojo/services/view_manager/server_view.h"
10 namespace mojo {
11 namespace service {
13 DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id,
14 AccessPolicyDelegate* delegate)
15 : connection_id_(connection_id),
16 delegate_(delegate) {
19 DefaultAccessPolicy::~DefaultAccessPolicy() {
22 bool DefaultAccessPolicy::CanRemoveViewFromParent(
23 const ServerView* view) const {
24 if (!WasCreatedByThisConnection(view))
25 return false; // Can only unparent views we created.
27 return IsViewInRoots(view->parent()) ||
28 WasCreatedByThisConnection(view->parent());
31 bool DefaultAccessPolicy::CanAddView(const ServerView* parent,
32 const ServerView* child) const {
33 return WasCreatedByThisConnection(child) &&
34 (IsViewInRoots(parent) ||
35 (WasCreatedByThisConnection(parent) &&
36 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(parent)));
39 bool DefaultAccessPolicy::CanReorderView(const ServerView* view,
40 const ServerView* relative_view,
41 OrderDirection direction) const {
42 return WasCreatedByThisConnection(view) &&
43 WasCreatedByThisConnection(relative_view);
46 bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const {
47 return WasCreatedByThisConnection(view);
50 bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const {
51 return WasCreatedByThisConnection(view) || IsViewInRoots(view);
54 bool DefaultAccessPolicy::CanDescendIntoViewForViewTree(
55 const ServerView* view) const {
56 return WasCreatedByThisConnection(view) &&
57 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view);
60 bool DefaultAccessPolicy::CanEmbed(const ServerView* view) const {
61 return WasCreatedByThisConnection(view);
64 bool DefaultAccessPolicy::CanChangeViewVisibility(
65 const ServerView* view) const {
66 return WasCreatedByThisConnection(view) || IsViewInRoots(view);
69 bool DefaultAccessPolicy::CanSetViewSurfaceId(const ServerView* view) const {
70 // Once a view embeds another app, the embedder app is no longer able to
71 // call SetViewSurfaceId() - this ability is transferred to the embedded app.
72 if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view))
73 return false;
74 return WasCreatedByThisConnection(view) || IsViewInRoots(view);
77 bool DefaultAccessPolicy::CanSetViewBounds(const ServerView* view) const {
78 return WasCreatedByThisConnection(view);
81 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange(
82 const ServerView* view,
83 const ServerView** new_parent,
84 const ServerView** old_parent) const {
85 if (!WasCreatedByThisConnection(view))
86 return false;
88 if (*new_parent && !WasCreatedByThisConnection(*new_parent) &&
89 !IsViewInRoots(*new_parent)) {
90 *new_parent = NULL;
93 if (*old_parent && !WasCreatedByThisConnection(*old_parent) &&
94 !IsViewInRoots(*old_parent)) {
95 *old_parent = NULL;
97 return true;
100 bool DefaultAccessPolicy::IsViewInRoots(const ServerView* view) const {
101 return delegate_->GetRootsForAccessPolicy().count(
102 ViewIdToTransportId(view->id())) > 0;
105 } // namespace service
106 } // namespace mojo