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

Side by Side Diff: components/mus/ws/window_tree_impl.h

Issue 1639223003: Makes it so each windowtreeclient can use whatever ids it wants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 11 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
« no previous file with comments | « components/mus/ws/window_tree_host_impl.cc ('k') | components/mus/ws/window_tree_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 COMPONENTS_MUS_WS_WINDOW_TREE_IMPL_H_ 5 #ifndef COMPONENTS_MUS_WS_WINDOW_TREE_IMPL_H_
6 #define COMPONENTS_MUS_WS_WINDOW_TREE_IMPL_H_ 6 #define COMPONENTS_MUS_WS_WINDOW_TREE_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 mojom::WindowTreeClient* client() { return client_; } 58 mojom::WindowTreeClient* client() { return client_; }
59 59
60 // Returns the Window with the specified id. 60 // Returns the Window with the specified id.
61 ServerWindow* GetWindow(const WindowId& id) { 61 ServerWindow* GetWindow(const WindowId& id) {
62 return const_cast<ServerWindow*>( 62 return const_cast<ServerWindow*>(
63 const_cast<const WindowTreeImpl*>(this)->GetWindow(id)); 63 const_cast<const WindowTreeImpl*>(this)->GetWindow(id));
64 } 64 }
65 const ServerWindow* GetWindow(const WindowId& id) const; 65 const ServerWindow* GetWindow(const WindowId& id) const;
66 66
67 // Returns the Window with the specified client id *only* if known to this
68 // client, returns null if not known.
69 ServerWindow* GetWindowByClientId(const ClientWindowId& id) {
70 return const_cast<ServerWindow*>(
71 const_cast<const WindowTreeImpl*>(this)->GetWindowByClientId(id));
72 }
73 const ServerWindow* GetWindowByClientId(const ClientWindowId& id) const;
74
75 bool IsWindowKnown(const ServerWindow* window) const {
76 return IsWindowKnown(window, nullptr);
77 }
78 // Returns whether |window| is known to this connection. If |window| is
79 // known and |client_window_id| is non-null |client_window_id| is set to
80 // the ClientWindowId of the window.
81 bool IsWindowKnown(const ServerWindow* window,
82 ClientWindowId* client_window_id) const;
83
67 // Returns true if |window| is one of this connections roots. 84 // Returns true if |window| is one of this connections roots.
68 bool HasRoot(const ServerWindow* window) const; 85 bool HasRoot(const ServerWindow* window) const;
69 86
70 std::set<const ServerWindow*> roots() { return roots_; } 87 std::set<const ServerWindow*> roots() { return roots_; }
71 88
72 bool is_embed_root() const { return is_embed_root_; } 89 bool is_embed_root() const { return is_embed_root_; }
73 90
74 const WindowTreeHostImpl* GetHost(const ServerWindow* window) const; 91 const WindowTreeHostImpl* GetHost(const ServerWindow* window) const;
75 WindowTreeHostImpl* GetHost(const ServerWindow* window) { 92 WindowTreeHostImpl* GetHost(const ServerWindow* window) {
76 return const_cast<WindowTreeHostImpl*>( 93 return const_cast<WindowTreeHostImpl*>(
77 const_cast<const WindowTreeImpl*>(this)->GetHost(window)); 94 const_cast<const WindowTreeImpl*>(this)->GetHost(window));
78 } 95 }
79 96
80 // Invoked when a connection is about to be destroyed. 97 // Invoked when a connection is about to be destroyed.
81 void OnWindowDestroyingTreeImpl(WindowTreeImpl* connection); 98 void OnWindowDestroyingTreeImpl(WindowTreeImpl* connection);
82 99
83 void OnWillDestroyWindowTreeHost(WindowTreeHostImpl* tree_host); 100 void OnWillDestroyWindowTreeHost(WindowTreeHostImpl* tree_host);
84 101
85 // These functions are synchronous variants of those defined in the mojom. The 102 // These functions are synchronous variants of those defined in the mojom. The
86 // WindowTree implementations all call into these. See the mojom for details. 103 // WindowTree implementations all call into these. See the mojom for details.
87 bool NewWindow(const WindowId& window_id, 104 bool NewWindow(const ClientWindowId& client_window_id,
88 const std::map<std::string, std::vector<uint8_t>>& properties); 105 const std::map<std::string, std::vector<uint8_t>>& properties);
89 bool AddWindow(const WindowId& parent_id, const WindowId& child_id); 106 bool AddWindow(const ClientWindowId& parent_id,
90 bool AddTransientWindow(const WindowId& window_id, 107 const ClientWindowId& child_id);
91 const WindowId& transient_window_id); 108 bool AddTransientWindow(const ClientWindowId& window_id,
109 const ClientWindowId& transient_window_id);
92 std::vector<const ServerWindow*> GetWindowTree( 110 std::vector<const ServerWindow*> GetWindowTree(
93 const WindowId& window_id) const; 111 const ClientWindowId& window_id) const;
94 bool SetWindowVisibility(const WindowId& window_id, bool visible); 112 bool SetWindowVisibility(const ClientWindowId& window_id, bool visible);
95 bool Embed(const WindowId& window_id, 113 bool Embed(const ClientWindowId& window_id,
96 mojom::WindowTreeClientPtr client, 114 mojom::WindowTreeClientPtr client,
97 uint32_t policy_bitmask, 115 uint32_t policy_bitmask,
98 ConnectionSpecificId* connection_id); 116 ConnectionSpecificId* connection_id);
99 void DispatchInputEvent(ServerWindow* target, mojom::EventPtr event); 117 void DispatchInputEvent(ServerWindow* target, mojom::EventPtr event);
100 118
101 bool IsWaitingForNewTopLevelWindow(uint32_t wm_change_id); 119 bool IsWaitingForNewTopLevelWindow(uint32_t wm_change_id);
102 void OnWindowManagerCreatedTopLevelWindow(uint32_t wm_change_id, 120 void OnWindowManagerCreatedTopLevelWindow(uint32_t wm_change_id,
103 uint32_t client_change_id, 121 uint32_t client_change_id,
104 const WindowId& window_id); 122 const ServerWindow* window);
105
106 // Maps the window id from the client to the server. Normally the ids are the
107 // same, but there may be a different id at the embed point.
108 WindowId MapWindowIdFromClient(Id transport_window_id) const {
109 return MapWindowIdFromClient(WindowIdFromTransportId(transport_window_id));
110 }
111 WindowId MapWindowIdFromClient(const WindowId& id) const;
112
113 // Maps the window id to the client.
114 Id MapWindowIdToClient(const ServerWindow* window) const;
115 Id MapWindowIdToClient(const WindowId& id) const;
116 123
117 // Calls through to the client. 124 // Calls through to the client.
118 void OnChangeCompleted(uint32_t change_id, bool success); 125 void OnChangeCompleted(uint32_t change_id, bool success);
119 126
120 // The following methods are invoked after the corresponding change has been 127 // The following methods are invoked after the corresponding change has been
121 // processed. They do the appropriate bookkeeping and update the client as 128 // processed. They do the appropriate bookkeeping and update the client as
122 // necessary. 129 // necessary.
123 void ProcessWindowBoundsChanged(const ServerWindow* window, 130 void ProcessWindowBoundsChanged(const ServerWindow* window,
124 const gfx::Rect& old_bounds, 131 const gfx::Rect& old_bounds,
125 const gfx::Rect& new_bounds, 132 const gfx::Rect& new_bounds,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void ProcessFocusChanged(const ServerWindow* old_focused_window, 165 void ProcessFocusChanged(const ServerWindow* old_focused_window,
159 const ServerWindow* new_focused_window); 166 const ServerWindow* new_focused_window);
160 void ProcessTransientWindowAdded(const ServerWindow* window, 167 void ProcessTransientWindowAdded(const ServerWindow* window,
161 const ServerWindow* transient_window, 168 const ServerWindow* transient_window,
162 bool originated_change); 169 bool originated_change);
163 void ProcessTransientWindowRemoved(const ServerWindow* window, 170 void ProcessTransientWindowRemoved(const ServerWindow* window,
164 const ServerWindow* transient_window, 171 const ServerWindow* transient_window,
165 bool originated_change); 172 bool originated_change);
166 173
167 private: 174 private:
168 using WindowIdSet = base::hash_set<Id>;
169 using WindowMap = std::map<ConnectionSpecificId, ServerWindow*>;
170 friend class WindowTreeTest; 175 friend class WindowTreeTest;
171 176
172 struct WaitingForTopLevelWindowInfo { 177 struct WaitingForTopLevelWindowInfo {
173 WaitingForTopLevelWindowInfo(WindowId window_id, uint32_t wm_change_id) 178 WaitingForTopLevelWindowInfo(const ClientWindowId& client_window_id,
174 : window_id(window_id), wm_change_id(wm_change_id) {} 179 uint32_t wm_change_id)
180 : client_window_id(client_window_id), wm_change_id(wm_change_id) {}
175 ~WaitingForTopLevelWindowInfo() {} 181 ~WaitingForTopLevelWindowInfo() {}
176 182
177 // Id supplied from the client. 183 // Id supplied from the client.
178 WindowId window_id; 184 ClientWindowId client_window_id;
179 185
180 // Change id we created for the window manager. 186 // Change id we created for the window manager.
181 uint32_t wm_change_id; 187 uint32_t wm_change_id;
182 }; 188 };
183 189
184 enum class RemoveRootReason { 190 enum class RemoveRootReason {
185 // The window is being removed. 191 // The window is being removed.
186 DELETED, 192 DELETED,
187 193
188 // Another connection is being embedded in the window. 194 // Another connection is being embedded in the window.
189 EMBED, 195 EMBED,
190 }; 196 };
191 197
192 // Used when this connection is associated with the window manager. 198 // Used when this connection is associated with the window manager.
193 WindowTreeHostImpl* GetHostForWindowManager(); 199 WindowTreeHostImpl* GetHostForWindowManager();
194 200
195 bool ShouldRouteToWindowManager(const ServerWindow* window) const; 201 bool ShouldRouteToWindowManager(const ServerWindow* window) const;
196 202
197 bool IsWindowKnown(const ServerWindow* window) const; 203 ClientWindowId ClientWindowIdForWindow(const ServerWindow* window) const;
198 204
199 // Returns true if |id| is a valid WindowId for a new window. 205 // Returns true if |id| is a valid WindowId for a new window.
200 bool IsValidIdForNewWindow(const WindowId& id) const; 206 bool IsValidIdForNewWindow(const ClientWindowId& id) const;
207
208 WindowId GenerateNewWindowId();
201 209
202 // These functions return true if the corresponding mojom function is allowed 210 // These functions return true if the corresponding mojom function is allowed
203 // for this connection. 211 // for this connection.
204 bool CanReorderWindow(const ServerWindow* window, 212 bool CanReorderWindow(const ServerWindow* window,
205 const ServerWindow* relative_window, 213 const ServerWindow* relative_window,
206 mojom::OrderDirection direction) const; 214 mojom::OrderDirection direction) const;
207 215
208 // Deletes a window owned by this connection. Returns true on success. 216 // Deletes a window owned by this connection. Returns true on success.
209 // |source| is the connection that originated the change. 217 // |source| is the connection that originated the change.
210 bool DeleteWindowImpl(WindowTreeImpl* source, ServerWindow* window); 218 bool DeleteWindowImpl(WindowTreeImpl* source, ServerWindow* window);
211 219
212 // If |window| is known (in |known_windows_|) does nothing. Otherwise adds 220 // If |window| is known does nothing. Otherwise adds |window| to |windows|,
213 // |window| to |windows|, marks |window| as known and recurses. 221 // marks |window| as known and recurses.
214 void GetUnknownWindowsFrom(const ServerWindow* window, 222 void GetUnknownWindowsFrom(const ServerWindow* window,
215 std::vector<const ServerWindow*>* windows); 223 std::vector<const ServerWindow*>* windows);
216 224
217 // Removes |window| and all its descendants from |known_windows_|. This does 225 // Removes |window| from the appropriate maps. If |window| is known to this
218 // not recurse through windows that were created by this connection. All 226 // client true is returned.
227 bool RemoveFromMaps(const ServerWindow* window);
228
229 // Removes |window| and all its descendants from the necessary maps. This
230 // does not recurse through windows that were created by this connection. All
219 // windows owned by this connection are added to |local_windows|. 231 // windows owned by this connection are added to |local_windows|.
220 void RemoveFromKnown(const ServerWindow* window, 232 void RemoveFromKnown(const ServerWindow* window,
221 std::vector<ServerWindow*>* local_windows); 233 std::vector<ServerWindow*>* local_windows);
222 234
223 // Resets the root of this connection. 235 // Resets the root of this connection.
224 void RemoveRoot(const ServerWindow* window, RemoveRootReason reason); 236 void RemoveRoot(const ServerWindow* window, RemoveRootReason reason);
225 237
226 // Converts Window(s) to WindowData(s) for transport. This assumes all the 238 // Converts Window(s) to WindowData(s) for transport. This assumes all the
227 // windows are valid for the client. The parent of windows the client is not 239 // windows are valid for the client. The parent of windows the client is not
228 // allowed to see are set to NULL (in the returned WindowData(s)). 240 // allowed to see are set to NULL (in the returned WindowData(s)).
229 mojo::Array<mojom::WindowDataPtr> WindowsToWindowDatas( 241 mojo::Array<mojom::WindowDataPtr> WindowsToWindowDatas(
230 const std::vector<const ServerWindow*>& windows); 242 const std::vector<const ServerWindow*>& windows);
231 mojom::WindowDataPtr WindowToWindowData(const ServerWindow* window); 243 mojom::WindowDataPtr WindowToWindowData(const ServerWindow* window);
232 244
233 // Implementation of GetWindowTree(). Adds |window| to |windows| and recurses 245 // Implementation of GetWindowTree(). Adds |window| to |windows| and recurses
234 // if CanDescendIntoWindowForWindowTree() returns true. 246 // if CanDescendIntoWindowForWindowTree() returns true.
235 void GetWindowTreeImpl(const ServerWindow* window, 247 void GetWindowTreeImpl(const ServerWindow* window,
236 std::vector<const ServerWindow*>* windows) const; 248 std::vector<const ServerWindow*>* windows) const;
237 249
238 // Notify the client if the drawn state of any of the roots changes. 250 // Notify the client if the drawn state of any of the roots changes.
239 // |window| is the window that is changing to the drawn state 251 // |window| is the window that is changing to the drawn state
240 // |new_drawn_value|. 252 // |new_drawn_value|.
241 void NotifyDrawnStateChanged(const ServerWindow* window, 253 void NotifyDrawnStateChanged(const ServerWindow* window,
242 bool new_drawn_value); 254 bool new_drawn_value);
243 255
244 // Deletes all Windows we own. 256 // Deletes all Windows we own.
245 void DestroyWindows(); 257 void DestroyWindows();
246 258
247 bool CanEmbed(const WindowId& window_id, uint32_t policy_bitmask) const; 259 bool CanEmbed(const ClientWindowId& window_id, uint32_t policy_bitmask) const;
248 void PrepareForEmbed(const WindowId& window_id); 260 void PrepareForEmbed(ServerWindow* window);
249 void RemoveChildrenAsPartOfEmbed(const WindowId& window_id); 261 void RemoveChildrenAsPartOfEmbed(ServerWindow* window);
250 262
251 void DispatchInputEventImpl(ServerWindow* target, mojom::EventPtr event); 263 void DispatchInputEventImpl(ServerWindow* target, mojom::EventPtr event);
252 264
253 // Calls OnChangeCompleted() on the client. 265 // Calls OnChangeCompleted() on the client.
254 void NotifyChangeCompleted(uint32_t change_id, 266 void NotifyChangeCompleted(uint32_t change_id,
255 mojom::WindowManagerErrorCode error_code); 267 mojom::WindowManagerErrorCode error_code);
256 268
257 // WindowTree: 269 // WindowTree:
258 void NewWindow(uint32_t change_id, 270 void NewWindow(uint32_t change_id,
259 Id transport_window_id, 271 Id transport_window_id,
260 mojo::Map<mojo::String, mojo::Array<uint8_t>> 272 mojo::Map<mojo::String, mojo::Array<uint8_t>>
261 transport_properties) override; 273 transport_properties) override;
262 void NewTopLevelWindow(uint32_t change_id, 274 void NewTopLevelWindow(uint32_t change_id,
263 Id transport_window_id, 275 Id transport_window_id,
264 mojo::Map<mojo::String, mojo::Array<uint8_t>> 276 mojo::Map<mojo::String, mojo::Array<uint8_t>>
265 transport_properties) override; 277 transport_properties) override;
266 void DeleteWindow(uint32_t change_id, Id transport_window_id) override; 278 void DeleteWindow(uint32_t change_id, Id transport_window_id) override;
267 void AddWindow(uint32_t change_id, Id parent_id, Id child_id) override; 279 void AddWindow(uint32_t change_id, Id parent_id, Id child_id) override;
268 void RemoveWindowFromParent(uint32_t change_id, Id window_id) override; 280 void RemoveWindowFromParent(uint32_t change_id, Id window_id) override;
269 void AddTransientWindow(uint32_t change_id, 281 void AddTransientWindow(uint32_t change_id,
270 Id window_id, 282 Id window,
271 Id transient_window_id) override; 283 Id transient_window) override;
272 void RemoveTransientWindowFromParent(uint32_t change_id, 284 void RemoveTransientWindowFromParent(uint32_t change_id,
273 Id transient_window_id) override; 285 Id transient_window_id) override;
274 void ReorderWindow(uint32_t change_Id, 286 void ReorderWindow(uint32_t change_Id,
275 Id window_id, 287 Id window_id,
276 Id relative_window_id, 288 Id relative_window_id,
277 mojom::OrderDirection direction) override; 289 mojom::OrderDirection direction) override;
278 void GetWindowTree( 290 void GetWindowTree(
279 Id window_id, 291 Id window_id,
280 const mojo::Callback<void(mojo::Array<mojom::WindowDataPtr>)>& callback) 292 const mojo::Callback<void(mojo::Array<mojom::WindowDataPtr>)>& callback)
281 override; 293 override;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 bool IsWindowKnownForAccessPolicy(const ServerWindow* window) const override; 341 bool IsWindowKnownForAccessPolicy(const ServerWindow* window) const override;
330 bool IsWindowRootOfAnotherConnectionForAccessPolicy( 342 bool IsWindowRootOfAnotherConnectionForAccessPolicy(
331 const ServerWindow* window) const override; 343 const ServerWindow* window) const override;
332 bool IsDescendantOfEmbedRoot(const ServerWindow* window) override; 344 bool IsDescendantOfEmbedRoot(const ServerWindow* window) override;
333 345
334 ConnectionManager* connection_manager_; 346 ConnectionManager* connection_manager_;
335 347
336 // Id of this connection as assigned by ConnectionManager. 348 // Id of this connection as assigned by ConnectionManager.
337 const ConnectionSpecificId id_; 349 const ConnectionSpecificId id_;
338 350
351 ConnectionSpecificId next_window_id_;
352
339 mojom::WindowTreeClient* client_; 353 mojom::WindowTreeClient* client_;
340 354
341 scoped_ptr<mus::ws::AccessPolicy> access_policy_; 355 scoped_ptr<mus::ws::AccessPolicy> access_policy_;
342 356
343 // The windows created by this connection. This connection owns these objects.
344 WindowMap window_map_;
345
346 // The set of windows that has been communicated to the client.
347 WindowIdSet known_windows_;
348
349 // The roots, or embed points, of this connection. A WindowTreeImpl may have 357 // The roots, or embed points, of this connection. A WindowTreeImpl may have
350 // any number of roots, including 0. 358 // any number of roots, including 0.
351 std::set<const ServerWindow*> roots_; 359 std::set<const ServerWindow*> roots_;
352 360
361 // The windows created by this connection. This connection owns these objects.
362 base::hash_map<WindowId, ServerWindow*> created_window_map_;
363
364 // The client is allowed to assign ids. These two maps providing the mapping
365 // from the ids native to the server (WindowId) to those understood by the
366 // client (ClientWindowId).
367 base::hash_map<ClientWindowId, WindowId> client_id_to_window_id_map_;
368 base::hash_map<WindowId, ClientWindowId> window_id_to_client_id_map_;
369
353 uint32_t event_ack_id_; 370 uint32_t event_ack_id_;
354 371
355 // WindowTreeHostImpl the current event came from. 372 // WindowTreeHostImpl the current event came from.
356 WindowTreeHostImpl* event_source_host_; 373 WindowTreeHostImpl* event_source_host_;
357 374
358 bool is_embed_root_; 375 bool is_embed_root_;
359 376
360 std::queue<scoped_ptr<TargetedEvent>> event_queue_; 377 std::queue<scoped_ptr<TargetedEvent>> event_queue_;
361 378
362 scoped_ptr<mojo::AssociatedBinding<mojom::WindowManagerInternalClient>> 379 scoped_ptr<mojo::AssociatedBinding<mojom::WindowManagerInternalClient>>
363 window_manager_internal_client_binding_; 380 window_manager_internal_client_binding_;
364 mojom::WindowManagerInternal* window_manager_internal_; 381 mojom::WindowManagerInternal* window_manager_internal_;
365 382
366 std::map<WindowId, WindowId> embed_to_real_id_map_;
367
368 scoped_ptr<WaitingForTopLevelWindowInfo> waiting_for_top_level_window_info_; 383 scoped_ptr<WaitingForTopLevelWindowInfo> waiting_for_top_level_window_info_;
369 384
370 DISALLOW_COPY_AND_ASSIGN(WindowTreeImpl); 385 DISALLOW_COPY_AND_ASSIGN(WindowTreeImpl);
371 }; 386 };
372 387
373 } // namespace ws 388 } // namespace ws
374 } // namespace mus 389 } // namespace mus
375 390
376 #endif // COMPONENTS_MUS_WS_WINDOW_TREE_IMPL_H_ 391 #endif // COMPONENTS_MUS_WS_WINDOW_TREE_IMPL_H_
OLDNEW
« no previous file with comments | « components/mus/ws/window_tree_host_impl.cc ('k') | components/mus/ws/window_tree_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698