Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: mojo/services/view_manager/default_access_policy.cc

Issue 699173003: Makes ViewManagerServiceImpl track a single root (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: comment Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/services/view_manager/default_access_policy.h" 5 #include "mojo/services/view_manager/default_access_policy.h"
6 6
7 #include "mojo/services/view_manager/access_policy_delegate.h" 7 #include "mojo/services/view_manager/access_policy_delegate.h"
8 #include "mojo/services/view_manager/server_view.h" 8 #include "mojo/services/view_manager/server_view.h"
9 9
10 namespace mojo { 10 namespace mojo {
11 namespace service { 11 namespace service {
12 12
13 DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id, 13 DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id,
14 AccessPolicyDelegate* delegate) 14 AccessPolicyDelegate* delegate)
15 : connection_id_(connection_id), 15 : connection_id_(connection_id),
16 delegate_(delegate) { 16 delegate_(delegate) {
17 } 17 }
18 18
19 DefaultAccessPolicy::~DefaultAccessPolicy() { 19 DefaultAccessPolicy::~DefaultAccessPolicy() {
20 } 20 }
21 21
22 bool DefaultAccessPolicy::CanRemoveViewFromParent( 22 bool DefaultAccessPolicy::CanRemoveViewFromParent(
23 const ServerView* view) const { 23 const ServerView* view) const {
24 if (!WasCreatedByThisConnection(view)) 24 if (!WasCreatedByThisConnection(view))
25 return false; // Can only unparent views we created. 25 return false; // Can only unparent views we created.
26 26
27 return IsViewInRoots(view->parent()) || 27 return delegate_->IsRootForAccessPolicy(view->parent()->id()) ||
28 WasCreatedByThisConnection(view->parent()); 28 WasCreatedByThisConnection(view->parent());
29 } 29 }
30 30
31 bool DefaultAccessPolicy::CanAddView(const ServerView* parent, 31 bool DefaultAccessPolicy::CanAddView(const ServerView* parent,
32 const ServerView* child) const { 32 const ServerView* child) const {
33 return WasCreatedByThisConnection(child) && 33 return WasCreatedByThisConnection(child) &&
34 (IsViewInRoots(parent) || 34 (delegate_->IsRootForAccessPolicy(parent->id()) ||
35 (WasCreatedByThisConnection(parent) && 35 (WasCreatedByThisConnection(parent) &&
36 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(parent))); 36 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(parent)));
37 } 37 }
38 38
39 bool DefaultAccessPolicy::CanReorderView(const ServerView* view, 39 bool DefaultAccessPolicy::CanReorderView(const ServerView* view,
40 const ServerView* relative_view, 40 const ServerView* relative_view,
41 OrderDirection direction) const { 41 OrderDirection direction) const {
42 return WasCreatedByThisConnection(view) && 42 return WasCreatedByThisConnection(view) &&
43 WasCreatedByThisConnection(relative_view); 43 WasCreatedByThisConnection(relative_view);
44 } 44 }
45 45
46 bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const { 46 bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const {
47 return WasCreatedByThisConnection(view); 47 return WasCreatedByThisConnection(view);
48 } 48 }
49 49
50 bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const { 50 bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const {
51 return WasCreatedByThisConnection(view) || IsViewInRoots(view); 51 return WasCreatedByThisConnection(view) ||
52 delegate_->IsRootForAccessPolicy(view->id());
52 } 53 }
53 54
54 bool DefaultAccessPolicy::CanDescendIntoViewForViewTree( 55 bool DefaultAccessPolicy::CanDescendIntoViewForViewTree(
55 const ServerView* view) const { 56 const ServerView* view) const {
56 return WasCreatedByThisConnection(view) && 57 return WasCreatedByThisConnection(view) &&
57 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view); 58 !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view);
58 } 59 }
59 60
60 bool DefaultAccessPolicy::CanEmbed(const ServerView* view) const { 61 bool DefaultAccessPolicy::CanEmbed(const ServerView* view) const {
61 return WasCreatedByThisConnection(view); 62 return WasCreatedByThisConnection(view);
62 } 63 }
63 64
64 bool DefaultAccessPolicy::CanChangeViewVisibility( 65 bool DefaultAccessPolicy::CanChangeViewVisibility(
65 const ServerView* view) const { 66 const ServerView* view) const {
66 return WasCreatedByThisConnection(view) || IsViewInRoots(view); 67 return WasCreatedByThisConnection(view) ||
68 delegate_->IsRootForAccessPolicy(view->id());
67 } 69 }
68 70
69 bool DefaultAccessPolicy::CanSetViewSurfaceId(const ServerView* view) const { 71 bool DefaultAccessPolicy::CanSetViewSurfaceId(const ServerView* view) const {
70 // Once a view embeds another app, the embedder app is no longer able to 72 // 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. 73 // call SetViewSurfaceId() - this ability is transferred to the embedded app.
72 if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view)) 74 if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view))
73 return false; 75 return false;
74 return WasCreatedByThisConnection(view) || IsViewInRoots(view); 76 return WasCreatedByThisConnection(view) ||
77 delegate_->IsRootForAccessPolicy(view->id());
75 } 78 }
76 79
77 bool DefaultAccessPolicy::CanSetViewBounds(const ServerView* view) const { 80 bool DefaultAccessPolicy::CanSetViewBounds(const ServerView* view) const {
78 return WasCreatedByThisConnection(view); 81 return WasCreatedByThisConnection(view);
79 } 82 }
80 83
81 bool DefaultAccessPolicy::CanSetViewProperties(const ServerView* view) const { 84 bool DefaultAccessPolicy::CanSetViewProperties(const ServerView* view) const {
82 return WasCreatedByThisConnection(view); 85 return WasCreatedByThisConnection(view);
83 } 86 }
84 87
85 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange( 88 bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange(
86 const ServerView* view, 89 const ServerView* view,
87 const ServerView** new_parent, 90 const ServerView** new_parent,
88 const ServerView** old_parent) const { 91 const ServerView** old_parent) const {
89 if (!WasCreatedByThisConnection(view)) 92 if (!WasCreatedByThisConnection(view))
90 return false; 93 return false;
91 94
92 if (*new_parent && !WasCreatedByThisConnection(*new_parent) && 95 if (*new_parent && !WasCreatedByThisConnection(*new_parent) &&
93 !IsViewInRoots(*new_parent)) { 96 !delegate_->IsRootForAccessPolicy((*new_parent)->id())) {
94 *new_parent = NULL; 97 *new_parent = NULL;
95 } 98 }
96 99
97 if (*old_parent && !WasCreatedByThisConnection(*old_parent) && 100 if (*old_parent && !WasCreatedByThisConnection(*old_parent) &&
98 !IsViewInRoots(*old_parent)) { 101 !delegate_->IsRootForAccessPolicy((*old_parent)->id())) {
99 *old_parent = NULL; 102 *old_parent = NULL;
100 } 103 }
101 return true; 104 return true;
102 } 105 }
103 106
104 bool DefaultAccessPolicy::IsViewInRoots(const ServerView* view) const {
105 return delegate_->GetRootsForAccessPolicy().count(
106 ViewIdToTransportId(view->id())) > 0;
107 }
108
109 bool DefaultAccessPolicy::WasCreatedByThisConnection( 107 bool DefaultAccessPolicy::WasCreatedByThisConnection(
110 const ServerView* view) const { 108 const ServerView* view) const {
111 return view->id().connection_id == connection_id_; 109 return view->id().connection_id == connection_id_;
112 } 110 }
113 111
114 } // namespace service 112 } // namespace service
115 } // namespace mojo 113 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/default_access_policy.h ('k') | mojo/services/view_manager/view_manager_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698