| OLD | NEW |
| 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_CONNECTION_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
| 6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #pragma warning(push) | 35 #pragma warning(push) |
| 36 #pragma warning(disable : 4275) | 36 #pragma warning(disable : 4275) |
| 37 #endif | 37 #endif |
| 38 | 38 |
| 39 // Manages a connection from the client. | 39 // Manages a connection from the client. |
| 40 class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection | 40 class MOJO_VIEW_MANAGER_EXPORT ViewManagerConnection |
| 41 : public InterfaceImpl<IViewManager>, | 41 : public InterfaceImpl<IViewManager>, |
| 42 public NodeDelegate { | 42 public NodeDelegate { |
| 43 public: | 43 public: |
| 44 ViewManagerConnection(RootNodeManager* root_node_manager, | 44 ViewManagerConnection(RootNodeManager* root_node_manager, |
| 45 TransportConnectionId creator_id, | 45 ConnectionSpecificId creator_id, |
| 46 const std::string& url); | 46 const std::string& url); |
| 47 virtual ~ViewManagerConnection(); | 47 virtual ~ViewManagerConnection(); |
| 48 | 48 |
| 49 // Used to mark this connection as originating from a call to | 49 // Used to mark this connection as originating from a call to |
| 50 // IViewManager::Connect(). When set OnConnectionError() deletes |this|. | 50 // IViewManager::Connect(). When set OnConnectionError() deletes |this|. |
| 51 void set_delete_on_connection_error() { delete_on_connection_error_ = true; } | 51 void set_delete_on_connection_error() { delete_on_connection_error_ = true; } |
| 52 | 52 |
| 53 TransportConnectionId id() const { return id_; } | 53 ConnectionSpecificId id() const { return id_; } |
| 54 TransportConnectionId creator_id() const { return creator_id_; } | 54 ConnectionSpecificId creator_id() const { return creator_id_; } |
| 55 const std::string& url() const { return url_; } | 55 const std::string& url() const { return url_; } |
| 56 | 56 |
| 57 // Returns the Node with the specified id. | 57 // Returns the Node with the specified id. |
| 58 Node* GetNode(const NodeId& id) { | 58 Node* GetNode(const NodeId& id) { |
| 59 return const_cast<Node*>( | 59 return const_cast<Node*>( |
| 60 const_cast<const ViewManagerConnection*>(this)->GetNode(id)); | 60 const_cast<const ViewManagerConnection*>(this)->GetNode(id)); |
| 61 } | 61 } |
| 62 const Node* GetNode(const NodeId& id) const; | 62 const Node* GetNode(const NodeId& id) const; |
| 63 | 63 |
| 64 // Returns the View with the specified id. | 64 // Returns the View with the specified id. |
| 65 View* GetView(const ViewId& id) { | 65 View* GetView(const ViewId& id) { |
| 66 return const_cast<View*>( | 66 return const_cast<View*>( |
| 67 const_cast<const ViewManagerConnection*>(this)->GetView(id)); | 67 const_cast<const ViewManagerConnection*>(this)->GetView(id)); |
| 68 } | 68 } |
| 69 const View* GetView(const ViewId& id) const; | 69 const View* GetView(const ViewId& id) const; |
| 70 | 70 |
| 71 void SetRoots(const Array<TransportNodeId>& node_ids); | 71 void SetRoots(const Array<Id>& node_ids); |
| 72 | 72 |
| 73 // Invoked when a connection is destroyed. | 73 // Invoked when a connection is destroyed. |
| 74 void OnViewManagerConnectionDestroyed(TransportConnectionId id); | 74 void OnViewManagerConnectionDestroyed(ConnectionSpecificId id); |
| 75 | 75 |
| 76 // The following methods are invoked after the corresponding change has been | 76 // The following methods are invoked after the corresponding change has been |
| 77 // processed. They do the appropriate bookkeeping and update the client as | 77 // processed. They do the appropriate bookkeeping and update the client as |
| 78 // necessary. | 78 // necessary. |
| 79 void ProcessNodeBoundsChanged(const Node* node, | 79 void ProcessNodeBoundsChanged(const Node* node, |
| 80 const gfx::Rect& old_bounds, | 80 const gfx::Rect& old_bounds, |
| 81 const gfx::Rect& new_bounds, | 81 const gfx::Rect& new_bounds, |
| 82 bool originated_change); | 82 bool originated_change); |
| 83 void ProcessNodeHierarchyChanged(const Node* node, | 83 void ProcessNodeHierarchyChanged(const Node* node, |
| 84 const Node* new_parent, | 84 const Node* new_parent, |
| 85 const Node* old_parent, | 85 const Node* old_parent, |
| 86 TransportChangeId server_change_id, | 86 Id server_change_id, |
| 87 bool originated_change); | 87 bool originated_change); |
| 88 void ProcessNodeViewReplaced(const Node* node, | 88 void ProcessNodeViewReplaced(const Node* node, |
| 89 const View* new_view, | 89 const View* new_view, |
| 90 const View* old_view, | 90 const View* old_view, |
| 91 bool originated_change); | 91 bool originated_change); |
| 92 void ProcessNodeDeleted(const NodeId& node, | 92 void ProcessNodeDeleted(const NodeId& node, |
| 93 TransportChangeId server_change_id, | 93 Id server_change_id, |
| 94 bool originated_change); | 94 bool originated_change); |
| 95 void ProcessViewDeleted(const ViewId& view, bool originated_change); | 95 void ProcessViewDeleted(const ViewId& view, bool originated_change); |
| 96 void ProcessViewInputEvent(const View* view, const ui::Event* event); | 96 void ProcessViewInputEvent(const View* view, const ui::Event* event); |
| 97 | 97 |
| 98 // TODO(sky): move this to private section (currently can't because of | 98 // TODO(sky): move this to private section (currently can't because of |
| 99 // bindings). | 99 // bindings). |
| 100 // InterfaceImp overrides: | 100 // InterfaceImp overrides: |
| 101 virtual void OnConnectionError() MOJO_OVERRIDE; | 101 virtual void OnConnectionError() MOJO_OVERRIDE; |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 typedef std::map<TransportConnectionSpecificNodeId, Node*> NodeMap; | 104 typedef std::map<ConnectionSpecificId, Node*> NodeMap; |
| 105 typedef std::map<TransportConnectionSpecificViewId, View*> ViewMap; | 105 typedef std::map<ConnectionSpecificId, View*> ViewMap; |
| 106 typedef base::hash_set<TransportNodeId> NodeIdSet; | 106 typedef base::hash_set<Id> NodeIdSet; |
| 107 | 107 |
| 108 // These functions return true if the corresponding mojom function is allowed | 108 // These functions return true if the corresponding mojom function is allowed |
| 109 // for this connection. | 109 // for this connection. |
| 110 bool CanRemoveNodeFromParent(const Node* node) const; | 110 bool CanRemoveNodeFromParent(const Node* node) const; |
| 111 bool CanAddNode(const Node* parent, const Node* child) const; | 111 bool CanAddNode(const Node* parent, const Node* child) const; |
| 112 bool CanDeleteNode(const NodeId& node_id) const; | 112 bool CanDeleteNode(const NodeId& node_id) const; |
| 113 bool CanDeleteView(const ViewId& view_id) const; | 113 bool CanDeleteView(const ViewId& view_id) const; |
| 114 bool CanSetView(const Node* node, const ViewId& view_id) const; | 114 bool CanSetView(const Node* node, const ViewId& view_id) const; |
| 115 bool CanGetNodeTree(const Node* node) const; | 115 bool CanGetNodeTree(const Node* node) const; |
| 116 bool CanConnect(const mojo::Array<uint32_t>& node_ids) const; | 116 bool CanConnect(const mojo::Array<uint32_t>& node_ids) const; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 130 // to |nodes|, marks |node| as known and recurses. | 130 // to |nodes|, marks |node| as known and recurses. |
| 131 void GetUnknownNodesFrom(const Node* node, std::vector<const Node*>* nodes); | 131 void GetUnknownNodesFrom(const Node* node, std::vector<const Node*>* nodes); |
| 132 | 132 |
| 133 // Removes |node| and all its descendants from |known_nodes_|. This does not | 133 // Removes |node| and all its descendants from |known_nodes_|. This does not |
| 134 // recurse through nodes that were created by this connection. | 134 // recurse through nodes that were created by this connection. |
| 135 void RemoveFromKnown(const Node* node); | 135 void RemoveFromKnown(const Node* node); |
| 136 | 136 |
| 137 // Adds |node_ids| to roots, returning true if at least one of the nodes was | 137 // Adds |node_ids| to roots, returning true if at least one of the nodes was |
| 138 // not already a root. If at least one of the nodes was not already a root | 138 // not already a root. If at least one of the nodes was not already a root |
| 139 // the client is told of the new roots. | 139 // the client is told of the new roots. |
| 140 bool AddRoots(const std::vector<TransportNodeId>& node_ids); | 140 bool AddRoots(const std::vector<Id>& node_ids); |
| 141 | 141 |
| 142 // Returns true if |node| is a non-null and a descendant of |roots_| (or | 142 // Returns true if |node| is a non-null and a descendant of |roots_| (or |
| 143 // |roots_| is empty). | 143 // |roots_| is empty). |
| 144 bool IsNodeDescendantOfRoots(const Node* node) const; | 144 bool IsNodeDescendantOfRoots(const Node* node) const; |
| 145 | 145 |
| 146 // Returns true if notification should be sent of a hierarchy change. If true | 146 // Returns true if notification should be sent of a hierarchy change. If true |
| 147 // is returned, any nodes that need to be sent to the client are added to | 147 // is returned, any nodes that need to be sent to the client are added to |
| 148 // |to_send|. | 148 // |to_send|. |
| 149 bool ShouldNotifyOnHierarchyChange(const Node* node, | 149 bool ShouldNotifyOnHierarchyChange(const Node* node, |
| 150 const Node** new_parent, | 150 const Node** new_parent, |
| 151 const Node** old_parent, | 151 const Node** old_parent, |
| 152 std::vector<const Node*>* to_send); | 152 std::vector<const Node*>* to_send); |
| 153 | 153 |
| 154 // Converts an array of Nodes to INodes. This assumes all the nodes are valid | 154 // Converts an array of Nodes to INodes. This assumes all the nodes are valid |
| 155 // for the client. The parent of nodes the client is not allowed to see are | 155 // for the client. The parent of nodes the client is not allowed to see are |
| 156 // set to NULL (in the returned INodes). | 156 // set to NULL (in the returned INodes). |
| 157 Array<INodePtr> NodesToINodes(const std::vector<const Node*>& nodes); | 157 Array<INodePtr> NodesToINodes(const std::vector<const Node*>& nodes); |
| 158 | 158 |
| 159 // Overridden from IViewManager: | 159 // Overridden from IViewManager: |
| 160 virtual void CreateNode(TransportNodeId transport_node_id, | 160 virtual void CreateNode(Id transport_node_id, |
| 161 const Callback<void(bool)>& callback) OVERRIDE; | 161 const Callback<void(bool)>& callback) OVERRIDE; |
| 162 virtual void DeleteNode(TransportNodeId transport_node_id, | 162 virtual void DeleteNode(Id transport_node_id, |
| 163 const Callback<void(bool)>& callback) OVERRIDE; | 163 const Callback<void(bool)>& callback) OVERRIDE; |
| 164 virtual void AddNode(TransportNodeId parent_id, | 164 virtual void AddNode(Id parent_id, |
| 165 TransportNodeId child_id, | 165 Id child_id, |
| 166 TransportChangeId server_change_id, | 166 Id server_change_id, |
| 167 const Callback<void(bool)>& callback) OVERRIDE; | 167 const Callback<void(bool)>& callback) OVERRIDE; |
| 168 virtual void RemoveNodeFromParent( | 168 virtual void RemoveNodeFromParent( |
| 169 TransportNodeId node_id, | 169 Id node_id, |
| 170 TransportChangeId server_change_id, | 170 Id server_change_id, |
| 171 const Callback<void(bool)>& callback) OVERRIDE; | 171 const Callback<void(bool)>& callback) OVERRIDE; |
| 172 virtual void GetNodeTree( | 172 virtual void GetNodeTree( |
| 173 TransportNodeId node_id, | 173 Id node_id, |
| 174 const Callback<void(Array<INodePtr>)>& callback) OVERRIDE; | 174 const Callback<void(Array<INodePtr>)>& callback) OVERRIDE; |
| 175 virtual void CreateView(TransportViewId transport_view_id, | 175 virtual void CreateView(Id transport_view_id, |
| 176 const Callback<void(bool)>& callback) OVERRIDE; | 176 const Callback<void(bool)>& callback) OVERRIDE; |
| 177 virtual void DeleteView(TransportViewId transport_view_id, | 177 virtual void DeleteView(Id transport_view_id, |
| 178 const Callback<void(bool)>& callback) OVERRIDE; | 178 const Callback<void(bool)>& callback) OVERRIDE; |
| 179 virtual void SetView(TransportNodeId transport_node_id, | 179 virtual void SetView(Id transport_node_id, |
| 180 TransportViewId transport_view_id, | 180 Id transport_view_id, |
| 181 const Callback<void(bool)>& callback) OVERRIDE; | 181 const Callback<void(bool)>& callback) OVERRIDE; |
| 182 virtual void SetViewContents(TransportViewId view_id, | 182 virtual void SetViewContents(Id view_id, |
| 183 ScopedSharedBufferHandle buffer, | 183 ScopedSharedBufferHandle buffer, |
| 184 uint32_t buffer_size, | 184 uint32_t buffer_size, |
| 185 const Callback<void(bool)>& callback) OVERRIDE; | 185 const Callback<void(bool)>& callback) OVERRIDE; |
| 186 virtual void SetNodeBounds(TransportNodeId node_id, | 186 virtual void SetNodeBounds(Id node_id, |
| 187 RectPtr bounds, | 187 RectPtr bounds, |
| 188 const Callback<void(bool)>& callback) OVERRIDE; | 188 const Callback<void(bool)>& callback) OVERRIDE; |
| 189 virtual void Connect(const mojo::String& url, | 189 virtual void Connect(const mojo::String& url, |
| 190 mojo::Array<uint32_t> node_ids, | 190 mojo::Array<uint32_t> node_ids, |
| 191 const mojo::Callback<void(bool)>& callback) OVERRIDE; | 191 const mojo::Callback<void(bool)>& callback) OVERRIDE; |
| 192 | 192 |
| 193 // Overridden from NodeDelegate: | 193 // Overridden from NodeDelegate: |
| 194 virtual void OnNodeHierarchyChanged(const Node* node, | 194 virtual void OnNodeHierarchyChanged(const Node* node, |
| 195 const Node* new_parent, | 195 const Node* new_parent, |
| 196 const Node* old_parent) OVERRIDE; | 196 const Node* old_parent) OVERRIDE; |
| 197 virtual void OnNodeViewReplaced(const Node* node, | 197 virtual void OnNodeViewReplaced(const Node* node, |
| 198 const View* new_view, | 198 const View* new_view, |
| 199 const View* old_view) OVERRIDE; | 199 const View* old_view) OVERRIDE; |
| 200 virtual void OnViewInputEvent(const View* view, | 200 virtual void OnViewInputEvent(const View* view, |
| 201 const ui::Event* event) OVERRIDE; | 201 const ui::Event* event) OVERRIDE; |
| 202 | 202 |
| 203 // InterfaceImp overrides: | 203 // InterfaceImp overrides: |
| 204 virtual void OnConnectionEstablished() MOJO_OVERRIDE; | 204 virtual void OnConnectionEstablished() MOJO_OVERRIDE; |
| 205 | 205 |
| 206 RootNodeManager* root_node_manager_; | 206 RootNodeManager* root_node_manager_; |
| 207 | 207 |
| 208 // Id of this connection as assigned by RootNodeManager. | 208 // Id of this connection as assigned by RootNodeManager. |
| 209 const TransportConnectionId id_; | 209 const ConnectionSpecificId id_; |
| 210 | 210 |
| 211 // URL this connection was created for. | 211 // URL this connection was created for. |
| 212 const std::string url_; | 212 const std::string url_; |
| 213 | 213 |
| 214 // ID of the connection that created us. If 0 it indicates either we were | 214 // ID of the connection that created us. If 0 it indicates either we were |
| 215 // created by the root, or the connection that created us has been destroyed. | 215 // created by the root, or the connection that created us has been destroyed. |
| 216 TransportConnectionId creator_id_; | 216 ConnectionSpecificId creator_id_; |
| 217 | 217 |
| 218 NodeMap node_map_; | 218 NodeMap node_map_; |
| 219 | 219 |
| 220 ViewMap view_map_; | 220 ViewMap view_map_; |
| 221 | 221 |
| 222 // The set of nodes that has been communicated to the client. | 222 // The set of nodes that has been communicated to the client. |
| 223 NodeIdSet known_nodes_; | 223 NodeIdSet known_nodes_; |
| 224 | 224 |
| 225 // This is the set of nodes the connection can parent nodes to (in addition to | 225 // This is the set of nodes the connection can parent nodes to (in addition to |
| 226 // any nodes created by this connection). If empty the connection can | 226 // any nodes created by this connection). If empty the connection can |
| (...skipping 11 matching lines...) Expand all Loading... |
| 238 | 238 |
| 239 #if defined(OS_WIN) | 239 #if defined(OS_WIN) |
| 240 #pragma warning(pop) | 240 #pragma warning(pop) |
| 241 #endif | 241 #endif |
| 242 | 242 |
| 243 } // namespace service | 243 } // namespace service |
| 244 } // namespace view_manager | 244 } // namespace view_manager |
| 245 } // namespace mojo | 245 } // namespace mojo |
| 246 | 246 |
| 247 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ | 247 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
| OLD | NEW |