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

Side by Side Diff: mojo/services/view_manager/view_manager_service_impl.h

Issue 421693002: Adds an AccessPolicy that is queried to determine what a connection can do (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 5 months 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 | Annotate | Revision Log
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 #ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_ 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_ 6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
15 #include "base/memory/scoped_ptr.h"
15 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" 16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
17 #include "mojo/services/view_manager/access_policy_delegate.h"
16 #include "mojo/services/view_manager/ids.h" 18 #include "mojo/services/view_manager/ids.h"
17 #include "mojo/services/view_manager/view_manager_export.h" 19 #include "mojo/services/view_manager/view_manager_export.h"
18 20
19 namespace gfx { 21 namespace gfx {
20 class Rect; 22 class Rect;
21 } 23 }
22 24
23 namespace mojo { 25 namespace mojo {
24 namespace service { 26 namespace service {
25 27
28 class AccessPolicy;
26 class Node; 29 class Node;
27 class RootNodeManager; 30 class RootNodeManager;
28 class View; 31 class View;
29 32
30 #if defined(OS_WIN) 33 #if defined(OS_WIN)
31 // Equivalent of NON_EXPORTED_BASE which does not work with the template snafu 34 // Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
32 // below. 35 // below.
33 #pragma warning(push) 36 #pragma warning(push)
34 #pragma warning(disable : 4275) 37 #pragma warning(disable : 4275)
35 #endif 38 #endif
36 39
37 // Manages a connection from the client. 40 // Manages a connection from the client.
38 class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl 41 class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl
39 : public InterfaceImpl<ViewManagerService> { 42 : public InterfaceImpl<ViewManagerService>,
43 public AccessPolicyDelegate {
40 public: 44 public:
41 ViewManagerServiceImpl(RootNodeManager* root_node_manager, 45 ViewManagerServiceImpl(RootNodeManager* root_node_manager,
42 ConnectionSpecificId creator_id, 46 ConnectionSpecificId creator_id,
43 const std::string& creator_url, 47 const std::string& creator_url,
44 const std::string& url, 48 const std::string& url,
45 const NodeId& root_id); 49 const NodeId& root_id);
46 virtual ~ViewManagerServiceImpl(); 50 virtual ~ViewManagerServiceImpl();
47 51
48 // Used to mark this connection as originating from a call to 52 // Used to mark this connection as originating from a call to
49 // ViewManagerService::Connect(). When set OnConnectionError() deletes |this|. 53 // ViewManagerService::Connect(). When set OnConnectionError() deletes |this|.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // TODO(sky): move this to private section (currently can't because of 105 // TODO(sky): move this to private section (currently can't because of
102 // bindings). 106 // bindings).
103 // InterfaceImp overrides: 107 // InterfaceImp overrides:
104 virtual void OnConnectionError() MOJO_OVERRIDE; 108 virtual void OnConnectionError() MOJO_OVERRIDE;
105 109
106 private: 110 private:
107 typedef std::map<ConnectionSpecificId, Node*> NodeMap; 111 typedef std::map<ConnectionSpecificId, Node*> NodeMap;
108 typedef std::map<ConnectionSpecificId, View*> ViewMap; 112 typedef std::map<ConnectionSpecificId, View*> ViewMap;
109 typedef base::hash_set<Id> NodeIdSet; 113 typedef base::hash_set<Id> NodeIdSet;
110 114
115 bool IsNodeKnown(const Node* node) const;
116
111 // These functions return true if the corresponding mojom function is allowed 117 // These functions return true if the corresponding mojom function is allowed
112 // for this connection. 118 // for this connection.
113 bool CanRemoveNodeFromParent(const Node* node) const;
114 bool CanAddNode(const Node* parent, const Node* child) const;
115 bool CanReorderNode(const Node* node, 119 bool CanReorderNode(const Node* node,
116 const Node* relative_node, 120 const Node* relative_node,
117 OrderDirection direction) const; 121 OrderDirection direction) const;
118 bool CanDeleteNode(const NodeId& node_id) const;
119 bool CanDeleteView(const ViewId& view_id) const;
120 bool CanSetView(const Node* node, const ViewId& view_id) const;
121 bool CanSetFocus(const Node* node) const;
122 bool CanGetNodeTree(const Node* node) const;
123 bool CanEmbed(Id transport_node_id) const;
124 bool CanSetNodeVisibility(const Node* node, bool visible) const;
125 // Used during GetNodeTreeImpl() to decide if we should descend into |node|
126 // when building the results of GetNodeTree().
127 bool CanDescendIntoNodeForNodeTree(const Node* node) const;
128 122
129 // Deletes a node owned by this connection. Returns true on success. |source| 123 // Deletes a node owned by this connection. Returns true on success. |source|
130 // is the connection that originated the change. 124 // is the connection that originated the change.
131 bool DeleteNodeImpl(ViewManagerServiceImpl* source, const NodeId& node_id); 125 bool DeleteNodeImpl(ViewManagerServiceImpl* source, Node* node);
132 126
133 // Deletes a view owned by this connection. Returns true on success. |source| 127 // Deletes a view owned by this connection. Returns true on success. |source|
134 // is the connection that originated the change. 128 // is the connection that originated the change.
135 bool DeleteViewImpl(ViewManagerServiceImpl* source, const ViewId& view_id); 129 bool DeleteViewImpl(ViewManagerServiceImpl* source, View* view);
136 130
137 // Sets the view associated with a node. 131 // Sets the view associated with a node.
138 bool SetViewImpl(Node* node, const ViewId& view_id); 132 bool SetViewImpl(Node* node, View* view);
139 133
140 // If |node| is known (in |known_nodes_|) does nothing. Otherwise adds |node| 134 // If |node| is known (in |known_nodes_|) does nothing. Otherwise adds |node|
141 // to |nodes|, marks |node| as known and recurses. 135 // to |nodes|, marks |node| as known and recurses.
142 void GetUnknownNodesFrom(const Node* node, std::vector<const Node*>* nodes); 136 void GetUnknownNodesFrom(const Node* node, std::vector<const Node*>* nodes);
143 137
144 // Returns true if node (or one of its ancestors) is embedded in another
145 // connection.
146 bool IsNodeEmbeddedInAnotherConnection(const Node* node) const;
147
148 // Removes |node| and all its descendants from |known_nodes_|. This does not 138 // Removes |node| and all its descendants from |known_nodes_|. This does not
149 // recurse through nodes that were created by this connection. All nodes owned 139 // recurse through nodes that were created by this connection. All nodes owned
150 // by this connection are added to |local_nodes|. 140 // by this connection are added to |local_nodes|.
151 void RemoveFromKnown(const Node* node, std::vector<Node*>* local_nodes); 141 void RemoveFromKnown(const Node* node, std::vector<Node*>* local_nodes);
152 142
153 // Adds |node_id| to the set of roots this connection knows about. The caller 143 // Adds |node_id| to the set of roots this connection knows about. The caller
154 // should have verified |node_id| is not among the roots of this connection. 144 // should have verified |node_id| is not among the roots of this connection.
155 void AddRoot(const NodeId& node_id); 145 void AddRoot(const NodeId& node_id);
156 146
157 // Removes |node_id| from the set of roots this connection knows about. 147 // Removes |node_id| from the set of roots this connection knows about.
158 void RemoveRoot(const NodeId& node_id); 148 void RemoveRoot(const NodeId& node_id);
159 149
160 void RemoveChildrenAsPartOfEmbed(const NodeId& node_id); 150 void RemoveChildrenAsPartOfEmbed(const NodeId& node_id);
161 151
162 // Returns true if |node| is a non-null and a descendant of |roots_| (or
163 // |roots_| is empty).
164 bool IsNodeDescendantOfRoots(const Node* node) const;
165
166 // Returns true if notification should be sent of a hierarchy change. If true
167 // is returned, any nodes that need to be sent to the client are added to
168 // |to_send|.
169 bool ShouldNotifyOnHierarchyChange(const Node* node,
170 const Node** new_parent,
171 const Node** old_parent,
172 std::vector<const Node*>* to_send);
173
174 // Converts an array of Nodes to NodeDatas. This assumes all the nodes are 152 // Converts an array of Nodes to NodeDatas. This assumes all the nodes are
175 // valid for the client. The parent of nodes the client is not allowed to see 153 // valid for the client. The parent of nodes the client is not allowed to see
176 // are set to NULL (in the returned NodeDatas). 154 // are set to NULL (in the returned NodeDatas).
177 Array<NodeDataPtr> NodesToNodeDatas(const std::vector<const Node*>& nodes); 155 Array<NodeDataPtr> NodesToNodeDatas(const std::vector<const Node*>& nodes);
178 156
179 // Implementation of GetNodeTree(). Adds |node| to |nodes| and recurses if 157 // Implementation of GetNodeTree(). Adds |node| to |nodes| and recurses if
180 // CanDescendIntoNodeForNodeTree() returns true. 158 // CanDescendIntoNodeForNodeTree() returns true.
181 void GetNodeTreeImpl(const Node* node, std::vector<const Node*>* nodes) const; 159 void GetNodeTreeImpl(const Node* node, std::vector<const Node*>* nodes) const;
182 160
183 // ViewManagerService: 161 // ViewManagerService:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 const Callback<void(bool)>& callback) OVERRIDE; 194 const Callback<void(bool)>& callback) OVERRIDE;
217 virtual void SetNodeVisibility(Id transport_node_id, 195 virtual void SetNodeVisibility(Id transport_node_id,
218 bool visible, 196 bool visible,
219 const Callback<void(bool)>& callback) OVERRIDE; 197 const Callback<void(bool)>& callback) OVERRIDE;
220 virtual void Embed(const String& url, 198 virtual void Embed(const String& url,
221 Id transport_node_id, 199 Id transport_node_id,
222 const Callback<void(bool)>& callback) OVERRIDE; 200 const Callback<void(bool)>& callback) OVERRIDE;
223 virtual void DispatchOnViewInputEvent(Id transport_view_id, 201 virtual void DispatchOnViewInputEvent(Id transport_view_id,
224 EventPtr event) OVERRIDE; 202 EventPtr event) OVERRIDE;
225 203
226 // InterfaceImp overrides: 204 // InterfaceImp:
Ben Goodger (Google) 2014/07/25 20:51:46 InterfaceImpl
sky 2014/07/25 21:10:46 Done.
227 virtual void OnConnectionEstablished() MOJO_OVERRIDE; 205 virtual void OnConnectionEstablished() MOJO_OVERRIDE;
228 206
207 // AccessPolicyDelegate:
208 virtual const base::hash_set<Id>& GetRootsForAccessPolicy() const OVERRIDE;
209 virtual bool IsNodeKnownForAccessPolicy(const Node* node) const OVERRIDE;
210 virtual bool IsNodeEmbeddedInAnotherConnectionForAccessPolicy(
211 const Node* node) const OVERRIDE;
212
229 RootNodeManager* root_node_manager_; 213 RootNodeManager* root_node_manager_;
230 214
231 // Id of this connection as assigned by RootNodeManager. 215 // Id of this connection as assigned by RootNodeManager.
232 const ConnectionSpecificId id_; 216 const ConnectionSpecificId id_;
233 217
234 // URL this connection was created for. 218 // URL this connection was created for.
235 const std::string url_; 219 const std::string url_;
236 220
237 // ID of the connection that created us. If 0 it indicates either we were 221 // ID of the connection that created us. If 0 it indicates either we were
238 // created by the root, or the connection that created us has been destroyed. 222 // created by the root, or the connection that created us has been destroyed.
239 ConnectionSpecificId creator_id_; 223 ConnectionSpecificId creator_id_;
240 224
241 // The URL of the app that embedded the app this connection was created for. 225 // The URL of the app that embedded the app this connection was created for.
242 const std::string creator_url_; 226 const std::string creator_url_;
243 227
228 scoped_ptr<AccessPolicy> access_policy_;
229
244 // The nodes and views created by this connection. This connection owns these 230 // The nodes and views created by this connection. This connection owns these
245 // objects. 231 // objects.
246 NodeMap node_map_; 232 NodeMap node_map_;
247 ViewMap view_map_; 233 ViewMap view_map_;
248 234
249 // The set of nodes that has been communicated to the client. 235 // The set of nodes that has been communicated to the client.
250 NodeIdSet known_nodes_; 236 NodeIdSet known_nodes_;
251 237
252 // This is the set of nodes the connection can parent nodes to (in addition to 238 // This is the set of nodes the connection can parent nodes to (in addition to
253 // any nodes created by this connection). If empty the connection can 239 // any nodes created by this connection). If empty the connection can
(...skipping 10 matching lines...) Expand all
264 }; 250 };
265 251
266 #if defined(OS_WIN) 252 #if defined(OS_WIN)
267 #pragma warning(pop) 253 #pragma warning(pop)
268 #endif 254 #endif
269 255
270 } // namespace service 256 } // namespace service
271 } // namespace mojo 257 } // namespace mojo
272 258
273 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_ 259 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698