| 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 COMPONENTS_MUS_WS_VIEW_TREE_IMPL_H_ | 5 #ifndef COMPONENTS_MUS_WS_VIEW_TREE_IMPL_H_ |
| 6 #define COMPONENTS_MUS_WS_VIEW_TREE_IMPL_H_ | 6 #define COMPONENTS_MUS_WS_VIEW_TREE_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/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "components/mus/public/interfaces/surface_id.mojom.h" | 16 #include "components/mus/public/interfaces/surface_id.mojom.h" |
| 17 #include "components/mus/public/interfaces/view_tree.mojom.h" | 17 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 18 #include "components/mus/ws/access_policy_delegate.h" | 18 #include "components/mus/ws/access_policy_delegate.h" |
| 19 #include "components/mus/ws/ids.h" | 19 #include "components/mus/ws/ids.h" |
| 20 | 20 |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 class Rect; | 22 class Rect; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace mus { | 25 namespace mus { |
| 26 | 26 |
| 27 class AccessPolicy; | 27 class AccessPolicy; |
| 28 class ConnectionManager; | 28 class ConnectionManager; |
| 29 class ServerView; | 29 class ServerView; |
| 30 class ViewTreeHostImpl; | 30 class ViewTreeHostImpl; |
| 31 | 31 |
| 32 // An instance of ViewTreeImpl is created for every ViewTree request. | 32 // An instance of ViewTreeImpl is created for every ViewTree request. |
| 33 // ViewTreeImpl tracks all the state and views created by a client. ViewTreeImpl | 33 // ViewTreeImpl tracks all the state and views created by a client. ViewTreeImpl |
| 34 // coordinates with ConnectionManager to update the client (and internal state) | 34 // coordinates with ConnectionManager to update the client (and internal state) |
| 35 // as necessary. | 35 // as necessary. |
| 36 class ViewTreeImpl : public mojo::ViewTree, public AccessPolicyDelegate { | 36 class ViewTreeImpl : public mojom::WindowTree, public AccessPolicyDelegate { |
| 37 public: | 37 public: |
| 38 ViewTreeImpl(ConnectionManager* connection_manager, | 38 ViewTreeImpl(ConnectionManager* connection_manager, |
| 39 ConnectionSpecificId creator_id, | 39 ConnectionSpecificId creator_id, |
| 40 const ViewId& root_id, | 40 const ViewId& root_id, |
| 41 uint32_t policy_bitmask); | 41 uint32_t policy_bitmask); |
| 42 ~ViewTreeImpl() override; | 42 ~ViewTreeImpl() override; |
| 43 | 43 |
| 44 // |services| and |exposed_services| are the ServiceProviders to pass to the | 44 // |services| and |exposed_services| are the ServiceProviders to pass to the |
| 45 // client via OnEmbed(). | 45 // client via OnEmbed(). |
| 46 void Init(mojo::ViewTreeClient* client, mojo::ViewTreePtr tree); | 46 void Init(mojom::WindowTreeClient* client, mojom::WindowTreePtr tree); |
| 47 | 47 |
| 48 ConnectionSpecificId id() const { return id_; } | 48 ConnectionSpecificId id() const { return id_; } |
| 49 ConnectionSpecificId creator_id() const { return creator_id_; } | 49 ConnectionSpecificId creator_id() const { return creator_id_; } |
| 50 | 50 |
| 51 mojo::ViewTreeClient* client() { return client_; } | 51 mojom::WindowTreeClient* client() { return client_; } |
| 52 | 52 |
| 53 // Returns the View with the specified id. | 53 // Returns the View with the specified id. |
| 54 ServerView* GetView(const ViewId& id) { | 54 ServerView* GetView(const ViewId& id) { |
| 55 return const_cast<ServerView*>( | 55 return const_cast<ServerView*>( |
| 56 const_cast<const ViewTreeImpl*>(this)->GetView(id)); | 56 const_cast<const ViewTreeImpl*>(this)->GetView(id)); |
| 57 } | 57 } |
| 58 const ServerView* GetView(const ViewId& id) const; | 58 const ServerView* GetView(const ViewId& id) const; |
| 59 | 59 |
| 60 // Returns true if this connection's root is |id|. | 60 // Returns true if this connection's root is |id|. |
| 61 bool IsRoot(const ViewId& id) const; | 61 bool IsRoot(const ViewId& id) const; |
| 62 | 62 |
| 63 // Returns the id of the root node. This is null if the root has been | 63 // Returns the id of the root node. This is null if the root has been |
| 64 // destroyed but the connection is still valid. | 64 // destroyed but the connection is still valid. |
| 65 const ViewId* root() const { return root_.get(); } | 65 const ViewId* root() const { return root_.get(); } |
| 66 | 66 |
| 67 bool is_embed_root() const { return is_embed_root_; } | 67 bool is_embed_root() const { return is_embed_root_; } |
| 68 | 68 |
| 69 ViewTreeHostImpl* GetHost(); | 69 ViewTreeHostImpl* GetHost(); |
| 70 | 70 |
| 71 // Invoked when a connection is about to be destroyed. | 71 // Invoked when a connection is about to be destroyed. |
| 72 void OnWillDestroyViewTreeImpl(ViewTreeImpl* connection); | 72 void OnWillDestroyViewTreeImpl(ViewTreeImpl* connection); |
| 73 | 73 |
| 74 // These functions are synchronous variants of those defined in the mojom. The | 74 // These functions are synchronous variants of those defined in the mojom. The |
| 75 // ViewTree implementations all call into these. See the mojom for details. | 75 // ViewTree implementations all call into these. See the mojom for details. |
| 76 mojo::ErrorCode CreateView(const ViewId& view_id); | 76 mojom::ErrorCode NewWindow(const ViewId& window_id); |
| 77 bool AddView(const ViewId& parent_id, const ViewId& child_id); | 77 bool AddWindow(const ViewId& parent_id, const ViewId& child_id); |
| 78 std::vector<const ServerView*> GetViewTree(const ViewId& view_id) const; | 78 std::vector<const ServerView*> GetWindowTree(const ViewId& window_id) const; |
| 79 bool SetViewVisibility(const ViewId& view_id, bool visible); | 79 bool SetWindowVisibility(const ViewId& window_id, bool visible); |
| 80 bool Embed(const ViewId& view_id, | 80 bool Embed(const ViewId& window_id, |
| 81 mojo::ViewTreeClientPtr client, | 81 mojom::WindowTreeClientPtr client, |
| 82 uint32_t policy_bitmask, | 82 uint32_t policy_bitmask, |
| 83 ConnectionSpecificId* connection_id); | 83 ConnectionSpecificId* connection_id); |
| 84 void Embed(const ViewId& view_id, mojo::URLRequestPtr request); | 84 void Embed(const ViewId& window_id, mojo::URLRequestPtr request); |
| 85 | 85 |
| 86 // The following methods are invoked after the corresponding change has been | 86 // The following methods are invoked after the corresponding change has been |
| 87 // processed. They do the appropriate bookkeeping and update the client as | 87 // processed. They do the appropriate bookkeeping and update the client as |
| 88 // necessary. | 88 // necessary. |
| 89 void ProcessViewBoundsChanged(const ServerView* view, | 89 void ProcessViewBoundsChanged(const ServerView* view, |
| 90 const gfx::Rect& old_bounds, | 90 const gfx::Rect& old_bounds, |
| 91 const gfx::Rect& new_bounds, | 91 const gfx::Rect& new_bounds, |
| 92 bool originated_change); | 92 bool originated_change); |
| 93 void ProcessClientAreaChanged(const ServerView* window, | 93 void ProcessClientAreaChanged(const ServerView* window, |
| 94 const gfx::Rect& old_client_area, | 94 const gfx::Rect& old_client_area, |
| 95 const gfx::Rect& new_client_area, | 95 const gfx::Rect& new_client_area, |
| 96 bool originated_change); | 96 bool originated_change); |
| 97 void ProcessViewportMetricsChanged(const mojo::ViewportMetrics& old_metrics, | 97 void ProcessViewportMetricsChanged(const mojom::ViewportMetrics& old_metrics, |
| 98 const mojo::ViewportMetrics& new_metrics, | 98 const mojom::ViewportMetrics& new_metrics, |
| 99 bool originated_change); | 99 bool originated_change); |
| 100 void ProcessWillChangeViewHierarchy(const ServerView* view, | 100 void ProcessWillChangeViewHierarchy(const ServerView* view, |
| 101 const ServerView* new_parent, | 101 const ServerView* new_parent, |
| 102 const ServerView* old_parent, | 102 const ServerView* old_parent, |
| 103 bool originated_change); | 103 bool originated_change); |
| 104 void ProcessViewPropertyChanged(const ServerView* view, | 104 void ProcessViewPropertyChanged(const ServerView* view, |
| 105 const std::string& name, | 105 const std::string& name, |
| 106 const std::vector<uint8_t>* new_data, | 106 const std::vector<uint8_t>* new_data, |
| 107 bool originated_change); | 107 bool originated_change); |
| 108 void ProcessViewHierarchyChanged(const ServerView* view, | 108 void ProcessViewHierarchyChanged(const ServerView* view, |
| 109 const ServerView* new_parent, | 109 const ServerView* new_parent, |
| 110 const ServerView* old_parent, | 110 const ServerView* old_parent, |
| 111 bool originated_change); | 111 bool originated_change); |
| 112 void ProcessViewReorder(const ServerView* view, | 112 void ProcessViewReorder(const ServerView* view, |
| 113 const ServerView* relative_view, | 113 const ServerView* relative_view, |
| 114 mojo::OrderDirection direction, | 114 mojom::OrderDirection direction, |
| 115 bool originated_change); | 115 bool originated_change); |
| 116 void ProcessViewDeleted(const ViewId& view, bool originated_change); | 116 void ProcessViewDeleted(const ViewId& view, bool originated_change); |
| 117 void ProcessWillChangeViewVisibility(const ServerView* view, | 117 void ProcessWillChangeViewVisibility(const ServerView* view, |
| 118 bool originated_change); | 118 bool originated_change); |
| 119 void ProcessFocusChanged(const ServerView* old_focused_view, | 119 void ProcessFocusChanged(const ServerView* old_focused_view, |
| 120 const ServerView* new_focused_view); | 120 const ServerView* new_focused_view); |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 using ViewIdSet = base::hash_set<Id>; | 123 using ViewIdSet = base::hash_set<Id>; |
| 124 using ViewMap = std::map<ConnectionSpecificId, ServerView*>; | 124 using ViewMap = std::map<ConnectionSpecificId, ServerView*>; |
| 125 | 125 |
| 126 bool IsViewKnown(const ServerView* view) const; | 126 bool IsViewKnown(const ServerView* view) const; |
| 127 | 127 |
| 128 // These functions return true if the corresponding mojom function is allowed | 128 // These functions return true if the corresponding mojom function is allowed |
| 129 // for this connection. | 129 // for this connection. |
| 130 bool CanReorderView(const ServerView* view, | 130 bool CanReorderWindow(const ServerView* view, |
| 131 const ServerView* relative_view, | 131 const ServerView* relative_view, |
| 132 mojo::OrderDirection direction) const; | 132 mojom::OrderDirection direction) const; |
| 133 | 133 |
| 134 // Deletes a view owned by this connection. Returns true on success. |source| | 134 // Deletes a view owned by this connection. Returns true on success. |source| |
| 135 // is the connection that originated the change. | 135 // is the connection that originated the change. |
| 136 bool DeleteViewImpl(ViewTreeImpl* source, ServerView* view); | 136 bool DeleteWindowImpl(ViewTreeImpl* source, ServerView* view); |
| 137 | 137 |
| 138 // If |view| is known (in |known_views_|) does nothing. Otherwise adds |view| | 138 // If |view| is known (in |known_views_|) does nothing. Otherwise adds |view| |
| 139 // to |views|, marks |view| as known and recurses. | 139 // to |views|, marks |view| as known and recurses. |
| 140 void GetUnknownViewsFrom(const ServerView* view, | 140 void GetUnknownViewsFrom(const ServerView* view, |
| 141 std::vector<const ServerView*>* views); | 141 std::vector<const ServerView*>* views); |
| 142 | 142 |
| 143 // Removes |view| and all its descendants from |known_views_|. This does not | 143 // Removes |view| and all its descendants from |known_views_|. This does not |
| 144 // recurse through views that were created by this connection. All views owned | 144 // recurse through views that were created by this connection. All views owned |
| 145 // by this connection are added to |local_views|. | 145 // by this connection are added to |local_views|. |
| 146 void RemoveFromKnown(const ServerView* view, | 146 void RemoveFromKnown(const ServerView* view, |
| 147 std::vector<ServerView*>* local_views); | 147 std::vector<ServerView*>* local_views); |
| 148 | 148 |
| 149 // Resets the root of this connection. | 149 // Resets the root of this connection. |
| 150 void RemoveRoot(); | 150 void RemoveRoot(); |
| 151 | 151 |
| 152 // Converts View(s) to ViewData(s) for transport. This assumes all the views | 152 // Converts View(s) to WindowData(s) for transport. This assumes all the views |
| 153 // are valid for the client. The parent of views the client is not allowed to | 153 // are valid for the client. The parent of views the client is not allowed to |
| 154 // see are set to NULL (in the returned ViewData(s)). | 154 // see are set to NULL (in the returned WindowData(s)). |
| 155 mojo::Array<mojo::ViewDataPtr> ViewsToViewDatas( | 155 mojo::Array<mojom::WindowDataPtr> ViewsToWindowDatas( |
| 156 const std::vector<const ServerView*>& views); | 156 const std::vector<const ServerView*>& views); |
| 157 mojo::ViewDataPtr ViewToViewData(const ServerView* view); | 157 mojom::WindowDataPtr ViewToWindowData(const ServerView* view); |
| 158 | 158 |
| 159 // Implementation of GetViewTree(). Adds |view| to |views| and recurses if | 159 // Implementation of GetWindowTree(). Adds |view| to |views| and recurses if |
| 160 // CanDescendIntoViewForViewTree() returns true. | 160 // CanDescendIntoViewForViewTree() returns true. |
| 161 void GetViewTreeImpl(const ServerView* view, | 161 void GetWindowTreeImpl(const ServerView* view, |
| 162 std::vector<const ServerView*>* views) const; | 162 std::vector<const ServerView*>* views) const; |
| 163 | 163 |
| 164 // Notify the client if the drawn state of any of the roots changes. | 164 // Notify the client if the drawn state of any of the roots changes. |
| 165 // |view| is the view that is changing to the drawn state |new_drawn_value|. | 165 // |view| is the view that is changing to the drawn state |new_drawn_value|. |
| 166 void NotifyDrawnStateChanged(const ServerView* view, bool new_drawn_value); | 166 void NotifyDrawnStateChanged(const ServerView* view, bool new_drawn_value); |
| 167 | 167 |
| 168 // Deletes all Views we own. | 168 // Deletes all Views we own. |
| 169 void DestroyViews(); | 169 void DestroyViews(); |
| 170 | 170 |
| 171 bool CanEmbed(const ViewId& view_id, uint32_t policy_bitmask) const; | 171 bool CanEmbed(const ViewId& window_id, uint32_t policy_bitmask) const; |
| 172 void PrepareForEmbed(const ViewId& view_id); | 172 void PrepareForEmbed(const ViewId& window_id); |
| 173 void RemoveChildrenAsPartOfEmbed(const ViewId& view_id); | 173 void RemoveChildrenAsPartOfEmbed(const ViewId& window_id); |
| 174 | 174 |
| 175 // ViewTree: | 175 // ViewTree: |
| 176 void CreateView( | 176 void NewWindow( |
| 177 Id transport_view_id, | 177 Id transport_window_id, |
| 178 const mojo::Callback<void(mojo::ErrorCode)>& callback) override; | 178 const mojo::Callback<void(mojom::ErrorCode)>& callback) override; |
| 179 void DeleteView(Id transport_view_id, | 179 void DeleteWindow(Id transport_window_id, |
| 180 const mojo::Callback<void(bool)>& callback) override; | 180 const mojo::Callback<void(bool)>& callback) override; |
| 181 void AddView(Id parent_id, | 181 void AddWindow(Id parent_id, |
| 182 Id child_id, | 182 Id child_id, |
| 183 const mojo::Callback<void(bool)>& callback) override; | 183 const mojo::Callback<void(bool)>& callback) override; |
| 184 void RemoveViewFromParent( | 184 void RemoveWindowFromParent( |
| 185 Id view_id, | 185 Id window_id, |
| 186 const mojo::Callback<void(bool)>& callback) override; | 186 const mojo::Callback<void(bool)>& callback) override; |
| 187 void ReorderView(Id view_id, | 187 void ReorderWindow(Id window_id, |
| 188 Id relative_view_id, | 188 Id relative_window_id, |
| 189 mojo::OrderDirection direction, | 189 mojom::OrderDirection direction, |
| 190 const mojo::Callback<void(bool)>& callback) override; | |
| 191 void GetViewTree(Id view_id, | |
| 192 const mojo::Callback<void(mojo::Array<mojo::ViewDataPtr>)>& | |
| 193 callback) override; | |
| 194 void SetViewBounds(Id view_id, | |
| 195 mojo::RectPtr bounds, | |
| 196 const mojo::Callback<void(bool)>& callback) override; | 190 const mojo::Callback<void(bool)>& callback) override; |
| 197 void SetViewVisibility(Id view_id, | 191 void GetWindowTree( |
| 198 bool visible, | 192 Id window_id, |
| 193 const mojo::Callback<void(mojo::Array<mojom::WindowDataPtr>)>& callback) |
| 194 override; |
| 195 void SetWindowBounds(Id window_id, |
| 196 mojo::RectPtr bounds, |
| 197 const mojo::Callback<void(bool)>& callback) override; |
| 198 void SetWindowVisibility(Id window_id, |
| 199 bool visible, |
| 200 const mojo::Callback<void(bool)>& callback) override; |
| 201 void SetWindowProperty(Id window_id, |
| 202 const mojo::String& name, |
| 203 mojo::Array<uint8_t> value, |
| 199 const mojo::Callback<void(bool)>& callback) override; | 204 const mojo::Callback<void(bool)>& callback) override; |
| 200 void SetViewProperty(Id view_id, | 205 void RequestSurface(Id window_id, |
| 201 const mojo::String& name, | 206 mojo::InterfaceRequest<mojom::Surface> surface, |
| 202 mojo::Array<uint8_t> value, | 207 mojom::SurfaceClientPtr client) override; |
| 203 const mojo::Callback<void(bool)>& callback) override; | 208 void Embed(Id transport_window_id, |
| 204 void RequestSurface(Id view_id, | 209 mojom::WindowTreeClientPtr client, |
| 205 mojo::InterfaceRequest<mojo::Surface> surface, | |
| 206 mojo::SurfaceClientPtr client) override; | |
| 207 void Embed(Id transport_view_id, | |
| 208 mojo::ViewTreeClientPtr client, | |
| 209 uint32_t policy_bitmask, | 210 uint32_t policy_bitmask, |
| 210 const EmbedCallback& callback) override; | 211 const EmbedCallback& callback) override; |
| 211 void SetFocus(uint32_t view_id) override; | 212 void SetFocus(uint32_t window_id) override; |
| 212 void SetViewTextInputState(uint32_t view_id, | 213 void SetWindowTextInputState(uint32_t window_id, |
| 213 mojo::TextInputStatePtr state) override; | 214 mojo::TextInputStatePtr state) override; |
| 214 void SetImeVisibility(Id transport_view_id, | 215 void SetImeVisibility(Id transport_window_id, |
| 215 bool visible, | 216 bool visible, |
| 216 mojo::TextInputStatePtr state) override; | 217 mojo::TextInputStatePtr state) override; |
| 217 void SetClientArea(Id transport_window_id, mojo::RectPtr rect) override; | 218 void SetClientArea(Id transport_window_id, mojo::RectPtr rect) override; |
| 218 | 219 |
| 219 // AccessPolicyDelegate: | 220 // AccessPolicyDelegate: |
| 220 bool IsRootForAccessPolicy(const ViewId& id) const override; | 221 bool IsRootForAccessPolicy(const ViewId& id) const override; |
| 221 bool IsViewKnownForAccessPolicy(const ServerView* view) const override; | 222 bool IsViewKnownForAccessPolicy(const ServerView* view) const override; |
| 222 bool IsViewRootOfAnotherConnectionForAccessPolicy( | 223 bool IsViewRootOfAnotherConnectionForAccessPolicy( |
| 223 const ServerView* view) const override; | 224 const ServerView* view) const override; |
| 224 bool IsDescendantOfEmbedRoot(const ServerView* view) override; | 225 bool IsDescendantOfEmbedRoot(const ServerView* view) override; |
| 225 | 226 |
| 226 ConnectionManager* connection_manager_; | 227 ConnectionManager* connection_manager_; |
| 227 | 228 |
| 228 // Id of this connection as assigned by ConnectionManager. | 229 // Id of this connection as assigned by ConnectionManager. |
| 229 const ConnectionSpecificId id_; | 230 const ConnectionSpecificId id_; |
| 230 | 231 |
| 231 // ID of the connection that created us. If 0 it indicates either we were | 232 // ID of the connection that created us. If 0 it indicates either we were |
| 232 // created by the root, or the connection that created us has been destroyed. | 233 // created by the root, or the connection that created us has been destroyed. |
| 233 ConnectionSpecificId creator_id_; | 234 ConnectionSpecificId creator_id_; |
| 234 | 235 |
| 235 mojo::ViewTreeClient* client_; | 236 mojom::WindowTreeClient* client_; |
| 236 | 237 |
| 237 scoped_ptr<mus::AccessPolicy> access_policy_; | 238 scoped_ptr<mus::AccessPolicy> access_policy_; |
| 238 | 239 |
| 239 // The views created by this connection. This connection owns these objects. | 240 // The views created by this connection. This connection owns these objects. |
| 240 ViewMap view_map_; | 241 ViewMap view_map_; |
| 241 | 242 |
| 242 // The set of views that has been communicated to the client. | 243 // The set of views that has been communicated to the client. |
| 243 ViewIdSet known_views_; | 244 ViewIdSet known_views_; |
| 244 | 245 |
| 245 // The root of this connection. This is a scoped_ptr to reinforce the | 246 // The root of this connection. This is a scoped_ptr to reinforce the |
| 246 // connection may have no root. A connection has no root if either the root | 247 // connection may have no root. A connection has no root if either the root |
| 247 // is destroyed or Embed() is invoked on the root. | 248 // is destroyed or Embed() is invoked on the root. |
| 248 scoped_ptr<ViewId> root_; | 249 scoped_ptr<ViewId> root_; |
| 249 | 250 |
| 250 bool is_embed_root_; | 251 bool is_embed_root_; |
| 251 | 252 |
| 252 DISALLOW_COPY_AND_ASSIGN(ViewTreeImpl); | 253 DISALLOW_COPY_AND_ASSIGN(ViewTreeImpl); |
| 253 }; | 254 }; |
| 254 | 255 |
| 255 } // namespace mus | 256 } // namespace mus |
| 256 | 257 |
| 257 #endif // COMPONENTS_MUS_WS_VIEW_TREE_IMPL_H_ | 258 #endif // COMPONENTS_MUS_WS_VIEW_TREE_IMPL_H_ |
| OLD | NEW |