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 #include "components/mus/ws/window_tree_impl.h" | 5 #include "components/mus/ws/window_tree_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 mojom::EventPtr event_; | 60 mojom::EventPtr event_; |
61 | 61 |
62 DISALLOW_COPY_AND_ASSIGN(TargetedEvent); | 62 DISALLOW_COPY_AND_ASSIGN(TargetedEvent); |
63 }; | 63 }; |
64 | 64 |
65 WindowTreeImpl::WindowTreeImpl(ConnectionManager* connection_manager, | 65 WindowTreeImpl::WindowTreeImpl(ConnectionManager* connection_manager, |
66 ServerWindow* root, | 66 ServerWindow* root, |
67 uint32_t policy_bitmask) | 67 uint32_t policy_bitmask) |
68 : connection_manager_(connection_manager), | 68 : connection_manager_(connection_manager), |
69 id_(connection_manager_->GetAndAdvanceNextConnectionId()), | 69 id_(connection_manager_->GetAndAdvanceNextConnectionId()), |
| 70 next_window_id_(1), |
70 client_(nullptr), | 71 client_(nullptr), |
71 event_ack_id_(0), | 72 event_ack_id_(0), |
72 event_source_host_(nullptr), | 73 event_source_host_(nullptr), |
73 is_embed_root_(false), | 74 is_embed_root_(false), |
74 window_manager_internal_(nullptr) { | 75 window_manager_internal_(nullptr) { |
75 CHECK(root); | 76 CHECK(root); |
76 roots_.insert(root); | 77 roots_.insert(root); |
77 if (root->GetRoot() == root) { | 78 if (root->GetRoot() == root) { |
78 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); | 79 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); |
79 is_embed_root_ = true; | 80 is_embed_root_ = true; |
(...skipping 13 matching lines...) Expand all Loading... |
93 client_ = client; | 94 client_ = client; |
94 std::vector<const ServerWindow*> to_send; | 95 std::vector<const ServerWindow*> to_send; |
95 CHECK_EQ(1u, roots_.size()); | 96 CHECK_EQ(1u, roots_.size()); |
96 GetUnknownWindowsFrom(*roots_.begin(), &to_send); | 97 GetUnknownWindowsFrom(*roots_.begin(), &to_send); |
97 | 98 |
98 WindowTreeHostImpl* host = GetHost(*roots_.begin()); | 99 WindowTreeHostImpl* host = GetHost(*roots_.begin()); |
99 const ServerWindow* focused_window = | 100 const ServerWindow* focused_window = |
100 host ? host->GetFocusedWindow() : nullptr; | 101 host ? host->GetFocusedWindow() : nullptr; |
101 if (focused_window) | 102 if (focused_window) |
102 focused_window = access_policy_->GetWindowForFocusChange(focused_window); | 103 focused_window = access_policy_->GetWindowForFocusChange(focused_window); |
103 const Id focused_window_transport_id(MapWindowIdToClient(focused_window)); | 104 ClientWindowId focused_window_id; |
| 105 if (focused_window) |
| 106 IsWindowKnown(focused_window, &focused_window_id); |
104 | 107 |
105 client->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree), | 108 client->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree), |
106 focused_window_transport_id, | 109 focused_window_id.id, |
107 is_embed_root_ ? WindowTree::kAccessPolicyEmbedRoot | 110 is_embed_root_ ? WindowTree::kAccessPolicyEmbedRoot |
108 : WindowTree::kAccessPolicyDefault); | 111 : WindowTree::kAccessPolicyDefault); |
109 } | 112 } |
110 | 113 |
111 const ServerWindow* WindowTreeImpl::GetWindow(const WindowId& id) const { | 114 const ServerWindow* WindowTreeImpl::GetWindow(const WindowId& id) const { |
112 if (id_ == id.connection_id) { | 115 if (id_ == id.connection_id) { |
113 WindowMap::const_iterator i = window_map_.find(id.window_id); | 116 auto iter = created_window_map_.find(id); |
114 return i == window_map_.end() ? NULL : i->second; | 117 return iter == created_window_map_.end() ? nullptr : iter->second; |
115 } | 118 } |
116 return connection_manager_->GetWindow(id); | 119 return connection_manager_->GetWindow(id); |
117 } | 120 } |
118 | 121 |
| 122 bool WindowTreeImpl::IsWindowKnown(const ServerWindow* window, |
| 123 ClientWindowId* id) const { |
| 124 if (!window) |
| 125 return false; |
| 126 auto iter = window_id_to_client_id_map_.find(window->id()); |
| 127 if (iter == window_id_to_client_id_map_.end()) |
| 128 return false; |
| 129 if (id) |
| 130 *id = iter->second; |
| 131 return true; |
| 132 } |
| 133 |
119 bool WindowTreeImpl::HasRoot(const ServerWindow* window) const { | 134 bool WindowTreeImpl::HasRoot(const ServerWindow* window) const { |
120 return roots_.count(window) > 0; | 135 return roots_.count(window) > 0; |
121 } | 136 } |
122 | 137 |
| 138 const ServerWindow* WindowTreeImpl::GetWindowByClientId( |
| 139 const ClientWindowId& id) const { |
| 140 auto iter = client_id_to_window_id_map_.find(id); |
| 141 return iter == client_id_to_window_id_map_.end() ? nullptr |
| 142 : GetWindow(iter->second); |
| 143 } |
| 144 |
123 const WindowTreeHostImpl* WindowTreeImpl::GetHost( | 145 const WindowTreeHostImpl* WindowTreeImpl::GetHost( |
124 const ServerWindow* window) const { | 146 const ServerWindow* window) const { |
125 return window ? connection_manager_->GetWindowTreeHostByWindow(window) | 147 return window ? connection_manager_->GetWindowTreeHostByWindow(window) |
126 : nullptr; | 148 : nullptr; |
127 } | 149 } |
128 | 150 |
129 void WindowTreeImpl::OnWindowDestroyingTreeImpl(WindowTreeImpl* connection) { | 151 void WindowTreeImpl::OnWindowDestroyingTreeImpl(WindowTreeImpl* connection) { |
130 // Notify our client if |connection| was embedded in any of our views. | 152 // Notify our client if |connection| was embedded in any of our views. |
131 for (const auto* connection_root : connection->roots_) { | 153 for (const auto* connection_root : connection->roots_) { |
132 const bool owns_connection_root = | 154 const bool owns_connection_root = |
133 connection_root->id().connection_id == id_; | 155 connection_root->id().connection_id == id_; |
134 const bool knows_about_connection_root = | 156 if (owns_connection_root || |
135 window_map_.count(connection_root->id().window_id) > 0; | |
136 if ((owns_connection_root && knows_about_connection_root) || | |
137 (is_embed_root_ && IsWindowKnown(connection_root))) { | 157 (is_embed_root_ && IsWindowKnown(connection_root))) { |
138 client_->OnEmbeddedAppDisconnected(MapWindowIdToClient(connection_root)); | 158 client_->OnEmbeddedAppDisconnected( |
| 159 ClientWindowIdForWindow(connection_root).id); |
139 } | 160 } |
140 } | 161 } |
141 } | 162 } |
142 | 163 |
143 void WindowTreeImpl::OnWillDestroyWindowTreeHost( | 164 void WindowTreeImpl::OnWillDestroyWindowTreeHost( |
144 WindowTreeHostImpl* tree_host) { | 165 WindowTreeHostImpl* tree_host) { |
145 if (event_source_host_ == tree_host) | 166 if (event_source_host_ == tree_host) |
146 event_source_host_ = nullptr; | 167 event_source_host_ = nullptr; |
147 } | 168 } |
148 | 169 |
149 void WindowTreeImpl::NotifyChangeCompleted( | 170 void WindowTreeImpl::NotifyChangeCompleted( |
150 uint32_t change_id, | 171 uint32_t change_id, |
151 mojom::WindowManagerErrorCode error_code) { | 172 mojom::WindowManagerErrorCode error_code) { |
152 client_->OnChangeCompleted( | 173 client_->OnChangeCompleted( |
153 change_id, error_code == mojom::WindowManagerErrorCode::SUCCESS); | 174 change_id, error_code == mojom::WindowManagerErrorCode::SUCCESS); |
154 } | 175 } |
155 | 176 |
156 bool WindowTreeImpl::NewWindow( | 177 bool WindowTreeImpl::NewWindow( |
157 const WindowId& window_id, | 178 const ClientWindowId& client_window_id, |
158 const std::map<std::string, std::vector<uint8_t>>& properties) { | 179 const std::map<std::string, std::vector<uint8_t>>& properties) { |
159 if (!IsValidIdForNewWindow(window_id)) | 180 if (!IsValidIdForNewWindow(client_window_id)) |
160 return false; | 181 return false; |
161 window_map_[window_id.window_id] = | 182 const WindowId window_id = GenerateNewWindowId(); |
| 183 DCHECK(!GetWindow(window_id)); |
| 184 ServerWindow* window = |
162 connection_manager_->CreateServerWindow(window_id, properties); | 185 connection_manager_->CreateServerWindow(window_id, properties); |
163 known_windows_.insert(WindowIdToTransportId(window_id)); | 186 created_window_map_[window_id] = window; |
| 187 client_id_to_window_id_map_[client_window_id] = window_id; |
| 188 window_id_to_client_id_map_[window_id] = client_window_id; |
164 return true; | 189 return true; |
165 } | 190 } |
166 | 191 |
167 bool WindowTreeImpl::AddWindow(const WindowId& parent_id, | 192 bool WindowTreeImpl::AddWindow(const ClientWindowId& parent_id, |
168 const WindowId& child_id) { | 193 const ClientWindowId& child_id) { |
169 ServerWindow* parent = GetWindow(MapWindowIdFromClient(parent_id)); | 194 ServerWindow* parent = GetWindowByClientId(parent_id); |
170 ServerWindow* child = GetWindow(MapWindowIdFromClient(child_id)); | 195 ServerWindow* child = GetWindowByClientId(child_id); |
171 if (parent && child && child->parent() != parent && | 196 if (parent && child && child->parent() != parent && |
172 !child->Contains(parent) && access_policy_->CanAddWindow(parent, child)) { | 197 !child->Contains(parent) && access_policy_->CanAddWindow(parent, child)) { |
173 Operation op(this, connection_manager_, OperationType::ADD_WINDOW); | 198 Operation op(this, connection_manager_, OperationType::ADD_WINDOW); |
174 parent->Add(child); | 199 parent->Add(child); |
175 return true; | 200 return true; |
176 } | 201 } |
177 return false; | 202 return false; |
178 } | 203 } |
179 | 204 |
180 bool WindowTreeImpl::AddTransientWindow(const WindowId& window_id, | 205 bool WindowTreeImpl::AddTransientWindow( |
181 const WindowId& transient_window_id) { | 206 const ClientWindowId& window_id, |
182 ServerWindow* window = GetWindow(MapWindowIdFromClient(window_id)); | 207 const ClientWindowId& transient_window_id) { |
183 ServerWindow* transient_window = | 208 ServerWindow* window = GetWindowByClientId(window_id); |
184 GetWindow(MapWindowIdFromClient(transient_window_id)); | 209 ServerWindow* transient_window = GetWindowByClientId(transient_window_id); |
185 if (window && transient_window && !transient_window->Contains(window) && | 210 if (window && transient_window && !transient_window->Contains(window) && |
186 access_policy_->CanAddTransientWindow(window, transient_window)) { | 211 access_policy_->CanAddTransientWindow(window, transient_window)) { |
187 Operation op(this, connection_manager_, | 212 Operation op(this, connection_manager_, |
188 OperationType::ADD_TRANSIENT_WINDOW); | 213 OperationType::ADD_TRANSIENT_WINDOW); |
189 window->AddTransientWindow(transient_window); | 214 window->AddTransientWindow(transient_window); |
190 return true; | 215 return true; |
191 } | 216 } |
192 return false; | 217 return false; |
193 } | 218 } |
194 | 219 |
195 std::vector<const ServerWindow*> WindowTreeImpl::GetWindowTree( | 220 std::vector<const ServerWindow*> WindowTreeImpl::GetWindowTree( |
196 const WindowId& window_id) const { | 221 const ClientWindowId& window_id) const { |
197 const ServerWindow* window = GetWindow(window_id); | 222 const ServerWindow* window = GetWindowByClientId(window_id); |
198 std::vector<const ServerWindow*> windows; | 223 std::vector<const ServerWindow*> windows; |
199 if (window) | 224 if (window) |
200 GetWindowTreeImpl(window, &windows); | 225 GetWindowTreeImpl(window, &windows); |
201 return windows; | 226 return windows; |
202 } | 227 } |
203 | 228 |
204 bool WindowTreeImpl::SetWindowVisibility(const WindowId& window_id, | 229 bool WindowTreeImpl::SetWindowVisibility(const ClientWindowId& window_id, |
205 bool visible) { | 230 bool visible) { |
206 ServerWindow* window = GetWindow(MapWindowIdFromClient(window_id)); | 231 ServerWindow* window = GetWindowByClientId(window_id); |
207 if (!window || window->visible() == visible || | 232 if (!window || window->visible() == visible || |
208 !access_policy_->CanChangeWindowVisibility(window)) { | 233 !access_policy_->CanChangeWindowVisibility(window)) { |
209 return false; | 234 return false; |
210 } | 235 } |
211 Operation op(this, connection_manager_, OperationType::SET_WINDOW_VISIBILITY); | 236 Operation op(this, connection_manager_, OperationType::SET_WINDOW_VISIBILITY); |
212 window->SetVisible(visible); | 237 window->SetVisible(visible); |
213 return true; | 238 return true; |
214 } | 239 } |
215 | 240 |
216 bool WindowTreeImpl::Embed(const WindowId& window_id, | 241 bool WindowTreeImpl::Embed(const ClientWindowId& window_id, |
217 mojom::WindowTreeClientPtr client, | 242 mojom::WindowTreeClientPtr client, |
218 uint32_t policy_bitmask, | 243 uint32_t policy_bitmask, |
219 ConnectionSpecificId* connection_id) { | 244 ConnectionSpecificId* connection_id) { |
220 *connection_id = kInvalidConnectionId; | 245 *connection_id = kInvalidConnectionId; |
221 if (!client || !CanEmbed(window_id, policy_bitmask)) | 246 if (!client || !CanEmbed(window_id, policy_bitmask)) |
222 return false; | 247 return false; |
223 PrepareForEmbed(window_id); | 248 ServerWindow* window = GetWindowByClientId(window_id); |
| 249 PrepareForEmbed(window); |
224 WindowTreeImpl* new_connection = connection_manager_->EmbedAtWindow( | 250 WindowTreeImpl* new_connection = connection_manager_->EmbedAtWindow( |
225 GetWindow(window_id), policy_bitmask, std::move(client)); | 251 window, policy_bitmask, std::move(client)); |
226 if (is_embed_root_) | 252 if (is_embed_root_) |
227 *connection_id = new_connection->id(); | 253 *connection_id = new_connection->id(); |
228 return true; | 254 return true; |
229 } | 255 } |
230 | 256 |
231 void WindowTreeImpl::DispatchInputEvent(ServerWindow* target, | 257 void WindowTreeImpl::DispatchInputEvent(ServerWindow* target, |
232 mojom::EventPtr event) { | 258 mojom::EventPtr event) { |
233 if (event_ack_id_) { | 259 if (event_ack_id_) { |
234 // This is currently waiting for an event ack. Add it to the queue. | 260 // This is currently waiting for an event ack. Add it to the queue. |
235 event_queue_.push( | 261 event_queue_.push( |
(...skipping 16 matching lines...) Expand all Loading... |
252 } | 278 } |
253 | 279 |
254 bool WindowTreeImpl::IsWaitingForNewTopLevelWindow(uint32_t wm_change_id) { | 280 bool WindowTreeImpl::IsWaitingForNewTopLevelWindow(uint32_t wm_change_id) { |
255 return waiting_for_top_level_window_info_ && | 281 return waiting_for_top_level_window_info_ && |
256 waiting_for_top_level_window_info_->wm_change_id == wm_change_id; | 282 waiting_for_top_level_window_info_->wm_change_id == wm_change_id; |
257 } | 283 } |
258 | 284 |
259 void WindowTreeImpl::OnWindowManagerCreatedTopLevelWindow( | 285 void WindowTreeImpl::OnWindowManagerCreatedTopLevelWindow( |
260 uint32_t wm_change_id, | 286 uint32_t wm_change_id, |
261 uint32_t client_change_id, | 287 uint32_t client_change_id, |
262 const WindowId& window_id) { | 288 const ServerWindow* window) { |
263 DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id)); | 289 DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id)); |
264 scoped_ptr<WaitingForTopLevelWindowInfo> waiting_for_top_level_window_info( | 290 scoped_ptr<WaitingForTopLevelWindowInfo> waiting_for_top_level_window_info( |
265 std::move(waiting_for_top_level_window_info_)); | 291 std::move(waiting_for_top_level_window_info_)); |
266 connection_manager_->GetClientConnection(this) | 292 connection_manager_->GetClientConnection(this) |
267 ->SetIncomingMethodCallProcessingPaused(false); | 293 ->SetIncomingMethodCallProcessingPaused(false); |
268 embed_to_real_id_map_[waiting_for_top_level_window_info->window_id] = | 294 // We were paused, so the id should still be valid. |
269 window_id; | 295 DCHECK(IsValidIdForNewWindow( |
270 std::vector<const ServerWindow*> unused; | 296 waiting_for_top_level_window_info->client_window_id)); |
271 const ServerWindow* window = GetWindow(window_id); | 297 client_id_to_window_id_map_[waiting_for_top_level_window_info |
| 298 ->client_window_id] = window->id(); |
| 299 window_id_to_client_id_map_[window->id()] = |
| 300 waiting_for_top_level_window_info->client_window_id; |
272 roots_.insert(window); | 301 roots_.insert(window); |
273 GetUnknownWindowsFrom(window, &unused); | |
274 client_->OnTopLevelCreated(client_change_id, WindowToWindowData(window)); | 302 client_->OnTopLevelCreated(client_change_id, WindowToWindowData(window)); |
275 } | 303 } |
276 | 304 |
277 WindowId WindowTreeImpl::MapWindowIdFromClient(const WindowId& id) const { | |
278 auto iter = embed_to_real_id_map_.find(id); | |
279 return iter == embed_to_real_id_map_.end() ? id : iter->second; | |
280 } | |
281 | |
282 Id WindowTreeImpl::MapWindowIdToClient(const ServerWindow* window) const { | |
283 return MapWindowIdToClient(window ? window->id() : WindowId()); | |
284 } | |
285 | |
286 Id WindowTreeImpl::MapWindowIdToClient(const WindowId& id) const { | |
287 // Clients typically don't have many embed windows, so we don't maintain an | |
288 // inverse mapping. | |
289 for (const auto& pair : embed_to_real_id_map_) { | |
290 if (pair.second == id) | |
291 return WindowIdToTransportId(pair.first); | |
292 } | |
293 return WindowIdToTransportId(id); | |
294 } | |
295 | |
296 void WindowTreeImpl::OnChangeCompleted(uint32_t change_id, bool success) { | 305 void WindowTreeImpl::OnChangeCompleted(uint32_t change_id, bool success) { |
297 client_->OnChangeCompleted(change_id, success); | 306 client_->OnChangeCompleted(change_id, success); |
298 } | 307 } |
299 | 308 |
300 void WindowTreeImpl::ProcessWindowBoundsChanged(const ServerWindow* window, | 309 void WindowTreeImpl::ProcessWindowBoundsChanged(const ServerWindow* window, |
301 const gfx::Rect& old_bounds, | 310 const gfx::Rect& old_bounds, |
302 const gfx::Rect& new_bounds, | 311 const gfx::Rect& new_bounds, |
303 bool originated_change) { | 312 bool originated_change) { |
304 if (originated_change || !IsWindowKnown(window)) | 313 ClientWindowId client_window_id; |
| 314 if (originated_change || !IsWindowKnown(window, &client_window_id)) |
305 return; | 315 return; |
306 client_->OnWindowBoundsChanged(MapWindowIdToClient(window), | 316 client_->OnWindowBoundsChanged(client_window_id.id, Rect::From(old_bounds), |
307 Rect::From(old_bounds), | |
308 Rect::From(new_bounds)); | 317 Rect::From(new_bounds)); |
309 } | 318 } |
310 | 319 |
311 void WindowTreeImpl::ProcessClientAreaChanged( | 320 void WindowTreeImpl::ProcessClientAreaChanged( |
312 const ServerWindow* window, | 321 const ServerWindow* window, |
313 const gfx::Insets& new_client_area, | 322 const gfx::Insets& new_client_area, |
314 const std::vector<gfx::Rect>& new_additional_client_areas, | 323 const std::vector<gfx::Rect>& new_additional_client_areas, |
315 bool originated_change) { | 324 bool originated_change) { |
316 if (originated_change || !IsWindowKnown(window)) | 325 ClientWindowId client_window_id; |
| 326 if (originated_change || !IsWindowKnown(window, &client_window_id)) |
317 return; | 327 return; |
318 client_->OnClientAreaChanged( | 328 client_->OnClientAreaChanged( |
319 MapWindowIdToClient(window), mojo::Insets::From(new_client_area), | 329 client_window_id.id, mojo::Insets::From(new_client_area), |
320 mojo::Array<mojo::RectPtr>::From(new_additional_client_areas)); | 330 mojo::Array<mojo::RectPtr>::From(new_additional_client_areas)); |
321 } | 331 } |
322 | 332 |
323 void WindowTreeImpl::ProcessViewportMetricsChanged( | 333 void WindowTreeImpl::ProcessViewportMetricsChanged( |
324 WindowTreeHostImpl* host, | 334 WindowTreeHostImpl* host, |
325 const mojom::ViewportMetrics& old_metrics, | 335 const mojom::ViewportMetrics& old_metrics, |
326 const mojom::ViewportMetrics& new_metrics, | 336 const mojom::ViewportMetrics& new_metrics, |
327 bool originated_change) { | 337 bool originated_change) { |
328 mojo::Array<Id> window_ids; | 338 mojo::Array<Id> window_ids; |
329 for (const ServerWindow* root : roots_) { | 339 for (const ServerWindow* root : roots_) { |
330 if (GetHost(root) == host) | 340 if (GetHost(root) == host) { |
331 window_ids.push_back(MapWindowIdToClient(root->id())); | 341 ClientWindowId client_window_id; |
| 342 const bool known = IsWindowKnown(root, &client_window_id); |
| 343 DCHECK(known); |
| 344 window_ids.push_back(client_window_id.id); |
| 345 } |
332 } | 346 } |
333 if (window_ids.size() == 0u) | 347 if (window_ids.size() == 0u) |
334 return; | 348 return; |
335 | 349 |
336 client_->OnWindowViewportMetricsChanged( | 350 client_->OnWindowViewportMetricsChanged( |
337 std::move(window_ids), old_metrics.Clone(), new_metrics.Clone()); | 351 std::move(window_ids), old_metrics.Clone(), new_metrics.Clone()); |
338 } | 352 } |
339 | 353 |
340 void WindowTreeImpl::ProcessWillChangeWindowHierarchy( | 354 void WindowTreeImpl::ProcessWillChangeWindowHierarchy( |
341 const ServerWindow* window, | 355 const ServerWindow* window, |
(...skipping 13 matching lines...) Expand all Loading... |
355 } | 369 } |
356 | 370 |
357 void WindowTreeImpl::ProcessWindowPropertyChanged( | 371 void WindowTreeImpl::ProcessWindowPropertyChanged( |
358 const ServerWindow* window, | 372 const ServerWindow* window, |
359 const std::string& name, | 373 const std::string& name, |
360 const std::vector<uint8_t>* new_data, | 374 const std::vector<uint8_t>* new_data, |
361 bool originated_change) { | 375 bool originated_change) { |
362 if (originated_change) | 376 if (originated_change) |
363 return; | 377 return; |
364 | 378 |
| 379 ClientWindowId client_window_id; |
| 380 if (!IsWindowKnown(window, &client_window_id)) |
| 381 return; |
| 382 |
365 Array<uint8_t> data; | 383 Array<uint8_t> data; |
366 if (new_data) | 384 if (new_data) |
367 data = Array<uint8_t>::From(*new_data); | 385 data = Array<uint8_t>::From(*new_data); |
368 | 386 |
369 client_->OnWindowSharedPropertyChanged(MapWindowIdToClient(window), | 387 client_->OnWindowSharedPropertyChanged(client_window_id.id, String(name), |
370 String(name), std::move(data)); | 388 std::move(data)); |
371 } | 389 } |
372 | 390 |
373 void WindowTreeImpl::ProcessWindowHierarchyChanged( | 391 void WindowTreeImpl::ProcessWindowHierarchyChanged( |
374 const ServerWindow* window, | 392 const ServerWindow* window, |
375 const ServerWindow* new_parent, | 393 const ServerWindow* new_parent, |
376 const ServerWindow* old_parent, | 394 const ServerWindow* old_parent, |
377 bool originated_change) { | 395 bool originated_change) { |
378 if (originated_change && !IsWindowKnown(window) && new_parent && | 396 if (originated_change && !IsWindowKnown(window) && new_parent && |
379 IsWindowKnown(new_parent)) { | 397 IsWindowKnown(new_parent)) { |
380 std::vector<const ServerWindow*> unused; | 398 std::vector<const ServerWindow*> unused; |
381 GetUnknownWindowsFrom(window, &unused); | 399 GetUnknownWindowsFrom(window, &unused); |
382 } | 400 } |
383 if (originated_change || (connection_manager_->current_operation_type() == | 401 if (originated_change || (connection_manager_->current_operation_type() == |
384 OperationType::DELETE_WINDOW) || | 402 OperationType::DELETE_WINDOW) || |
385 (connection_manager_->current_operation_type() == OperationType::EMBED) || | 403 (connection_manager_->current_operation_type() == OperationType::EMBED) || |
386 connection_manager_->DidConnectionMessageClient(id_)) { | 404 connection_manager_->DidConnectionMessageClient(id_)) { |
387 return; | 405 return; |
388 } | 406 } |
389 | 407 |
390 if (!access_policy_->ShouldNotifyOnHierarchyChange(window, &new_parent, | 408 if (!access_policy_->ShouldNotifyOnHierarchyChange(window, &new_parent, |
391 &old_parent)) { | 409 &old_parent)) { |
392 return; | 410 return; |
393 } | 411 } |
394 // Inform the client of any new windows and update the set of windows we know | 412 // Inform the client of any new windows and update the set of windows we know |
395 // about. | 413 // about. |
396 std::vector<const ServerWindow*> to_send; | 414 std::vector<const ServerWindow*> to_send; |
397 if (!IsWindowKnown(window)) | 415 if (!IsWindowKnown(window)) |
398 GetUnknownWindowsFrom(window, &to_send); | 416 GetUnknownWindowsFrom(window, &to_send); |
399 const WindowId new_parent_id(new_parent ? new_parent->id() : WindowId()); | 417 const ClientWindowId new_parent_client_window_id = |
400 const WindowId old_parent_id(old_parent ? old_parent->id() : WindowId()); | 418 new_parent ? ClientWindowIdForWindow(new_parent) : ClientWindowId(); |
| 419 const ClientWindowId old_parent_client_window_id = |
| 420 old_parent ? ClientWindowIdForWindow(old_parent) : ClientWindowId(); |
| 421 const ClientWindowId client_window_id = |
| 422 window ? ClientWindowIdForWindow(window) : ClientWindowId(); |
401 client_->OnWindowHierarchyChanged( | 423 client_->OnWindowHierarchyChanged( |
402 MapWindowIdToClient(window), MapWindowIdToClient(new_parent_id), | 424 client_window_id.id, new_parent_client_window_id.id, |
403 MapWindowIdToClient(old_parent_id), WindowsToWindowDatas(to_send)); | 425 old_parent_client_window_id.id, WindowsToWindowDatas(to_send)); |
404 connection_manager_->OnConnectionMessagedClient(id_); | 426 connection_manager_->OnConnectionMessagedClient(id_); |
405 } | 427 } |
406 | 428 |
407 void WindowTreeImpl::ProcessWindowReorder(const ServerWindow* window, | 429 void WindowTreeImpl::ProcessWindowReorder(const ServerWindow* window, |
408 const ServerWindow* relative_window, | 430 const ServerWindow* relative_window, |
409 mojom::OrderDirection direction, | 431 mojom::OrderDirection direction, |
410 bool originated_change) { | 432 bool originated_change) { |
411 DCHECK_EQ(window->parent(), relative_window->parent()); | 433 DCHECK_EQ(window->parent(), relative_window->parent()); |
412 if (originated_change || !IsWindowKnown(window) || | 434 ClientWindowId client_window_id, relative_client_window_id; |
413 !IsWindowKnown(relative_window) || | 435 if (originated_change || !IsWindowKnown(window, &client_window_id) || |
| 436 !IsWindowKnown(relative_window, &relative_client_window_id) || |
414 connection_manager_->DidConnectionMessageClient(id_)) | 437 connection_manager_->DidConnectionMessageClient(id_)) |
415 return; | 438 return; |
416 | 439 |
417 // Do not notify ordering changes of the root windows, since the client | 440 // Do not notify ordering changes of the root windows, since the client |
418 // doesn't know about the ancestors of the roots, and so can't do anything | 441 // doesn't know about the ancestors of the roots, and so can't do anything |
419 // about this ordering change of the root. | 442 // about this ordering change of the root. |
420 if (HasRoot(window) || HasRoot(relative_window)) | 443 if (HasRoot(window) || HasRoot(relative_window)) |
421 return; | 444 return; |
422 | 445 |
423 client_->OnWindowReordered(MapWindowIdToClient(window), | 446 client_->OnWindowReordered(client_window_id.id, relative_client_window_id.id, |
424 MapWindowIdToClient(relative_window), direction); | 447 direction); |
425 connection_manager_->OnConnectionMessagedClient(id_); | 448 connection_manager_->OnConnectionMessagedClient(id_); |
426 } | 449 } |
427 | 450 |
428 void WindowTreeImpl::ProcessWindowDeleted(const ServerWindow* window, | 451 void WindowTreeImpl::ProcessWindowDeleted(const ServerWindow* window, |
429 bool originated_change) { | 452 bool originated_change) { |
430 if (window->id().connection_id == id_) | 453 if (window->id().connection_id == id_) |
431 window_map_.erase(window->id().window_id); | 454 created_window_map_.erase(window->id()); |
432 | 455 |
433 const Id transport_id = MapWindowIdToClient(window); | 456 ClientWindowId client_window_id; |
434 | 457 if (!IsWindowKnown(window, &client_window_id)) |
435 const bool in_known = | 458 return; |
436 known_windows_.erase(WindowIdToTransportId(window->id())) > 0; | |
437 | 459 |
438 if (HasRoot(window)) | 460 if (HasRoot(window)) |
439 RemoveRoot(window, RemoveRootReason::DELETED); | 461 RemoveRoot(window, RemoveRootReason::DELETED); |
| 462 else |
| 463 RemoveFromMaps(window); |
440 | 464 |
441 if (originated_change) | 465 if (originated_change) |
442 return; | 466 return; |
443 | 467 |
444 if (in_known) { | 468 client_->OnWindowDeleted(client_window_id.id); |
445 client_->OnWindowDeleted(transport_id); | 469 connection_manager_->OnConnectionMessagedClient(id_); |
446 connection_manager_->OnConnectionMessagedClient(id_); | |
447 } | |
448 } | 470 } |
449 | 471 |
450 void WindowTreeImpl::ProcessWillChangeWindowVisibility( | 472 void WindowTreeImpl::ProcessWillChangeWindowVisibility( |
451 const ServerWindow* window, | 473 const ServerWindow* window, |
452 bool originated_change) { | 474 bool originated_change) { |
453 if (originated_change) | 475 if (originated_change) |
454 return; | 476 return; |
455 | 477 |
456 if (IsWindowKnown(window)) { | 478 ClientWindowId client_window_id; |
457 client_->OnWindowVisibilityChanged(MapWindowIdToClient(window), | 479 if (IsWindowKnown(window, &client_window_id)) { |
458 !window->visible()); | 480 client_->OnWindowVisibilityChanged(client_window_id.id, !window->visible()); |
459 return; | 481 return; |
460 } | 482 } |
461 | 483 |
462 bool window_target_drawn_state; | 484 bool window_target_drawn_state; |
463 if (window->visible()) { | 485 if (window->visible()) { |
464 // Window is being hidden, won't be drawn. | 486 // Window is being hidden, won't be drawn. |
465 window_target_drawn_state = false; | 487 window_target_drawn_state = false; |
466 } else { | 488 } else { |
467 // Window is being shown. Window will be drawn if its parent is drawn. | 489 // Window is being shown. Window will be drawn if its parent is drawn. |
468 window_target_drawn_state = window->parent() && window->parent()->IsDrawn(); | 490 window_target_drawn_state = window->parent() && window->parent()->IsDrawn(); |
469 } | 491 } |
470 | 492 |
471 NotifyDrawnStateChanged(window, window_target_drawn_state); | 493 NotifyDrawnStateChanged(window, window_target_drawn_state); |
472 } | 494 } |
473 | 495 |
474 void WindowTreeImpl::ProcessCursorChanged(const ServerWindow* window, | 496 void WindowTreeImpl::ProcessCursorChanged(const ServerWindow* window, |
475 int32_t cursor_id, | 497 int32_t cursor_id, |
476 bool originated_change) { | 498 bool originated_change) { |
477 if (originated_change) | 499 if (originated_change) |
478 return; | 500 return; |
479 client_->OnWindowPredefinedCursorChanged(MapWindowIdToClient(window), | 501 ClientWindowId client_window_id; |
| 502 if (!IsWindowKnown(window, &client_window_id)) |
| 503 return; |
| 504 |
| 505 client_->OnWindowPredefinedCursorChanged(client_window_id.id, |
480 mojom::Cursor(cursor_id)); | 506 mojom::Cursor(cursor_id)); |
481 } | 507 } |
482 | 508 |
483 void WindowTreeImpl::ProcessFocusChanged( | 509 void WindowTreeImpl::ProcessFocusChanged( |
484 const ServerWindow* old_focused_window, | 510 const ServerWindow* old_focused_window, |
485 const ServerWindow* new_focused_window) { | 511 const ServerWindow* new_focused_window) { |
486 const ServerWindow* window = | 512 const ServerWindow* window = |
487 new_focused_window | 513 new_focused_window |
488 ? access_policy_->GetWindowForFocusChange(new_focused_window) | 514 ? access_policy_->GetWindowForFocusChange(new_focused_window) |
489 : nullptr; | 515 : nullptr; |
490 client_->OnWindowFocused(window ? MapWindowIdToClient(window) | 516 ClientWindowId client_window_id; |
491 : MapWindowIdToClient(WindowId())); | 517 // If the window isn't known we'll supply null, which is ok. |
| 518 IsWindowKnown(window, &client_window_id); |
| 519 // TODO(sky): this should only notify if this results in a change of focus |
| 520 // for the client. |
| 521 client_->OnWindowFocused(client_window_id.id); |
492 } | 522 } |
493 | 523 |
494 void WindowTreeImpl::ProcessTransientWindowAdded( | 524 void WindowTreeImpl::ProcessTransientWindowAdded( |
495 const ServerWindow* window, | 525 const ServerWindow* window, |
496 const ServerWindow* transient_window, | 526 const ServerWindow* transient_window, |
497 bool originated_change) { | 527 bool originated_change) { |
498 if (originated_change) | 528 if (originated_change) |
499 return; | 529 return; |
500 client_->OnTransientWindowAdded(MapWindowIdToClient(window), | 530 |
501 MapWindowIdToClient(transient_window)); | 531 ClientWindowId client_window_id, transient_client_window_id; |
| 532 if (!IsWindowKnown(window, &client_window_id) || |
| 533 !IsWindowKnown(transient_window, &transient_client_window_id)) { |
| 534 return; |
| 535 } |
| 536 client_->OnTransientWindowAdded(client_window_id.id, |
| 537 transient_client_window_id.id); |
502 } | 538 } |
503 | 539 |
504 void WindowTreeImpl::ProcessTransientWindowRemoved( | 540 void WindowTreeImpl::ProcessTransientWindowRemoved( |
505 const ServerWindow* window, | 541 const ServerWindow* window, |
506 const ServerWindow* transient_window, | 542 const ServerWindow* transient_window, |
507 bool originated_change) { | 543 bool originated_change) { |
508 if (originated_change) | 544 if (originated_change) |
509 return; | 545 return; |
510 client_->OnTransientWindowRemoved(MapWindowIdToClient(window), | 546 ClientWindowId client_window_id, transient_client_window_id; |
511 MapWindowIdToClient(transient_window)); | 547 if (!IsWindowKnown(window, &client_window_id) || |
| 548 !IsWindowKnown(transient_window, &transient_client_window_id)) { |
| 549 return; |
| 550 } |
| 551 client_->OnTransientWindowRemoved(client_window_id.id, |
| 552 transient_client_window_id.id); |
512 } | 553 } |
513 | 554 |
514 WindowTreeHostImpl* WindowTreeImpl::GetHostForWindowManager() { | 555 WindowTreeHostImpl* WindowTreeImpl::GetHostForWindowManager() { |
515 // The WindowTreeImpl for the wm has one and only one root. | 556 // The WindowTreeImpl for the wm has one and only one root. |
516 CHECK_EQ(1u, roots_.size()); | 557 CHECK_EQ(1u, roots_.size()); |
517 | 558 |
518 // Indicates this connection is for the wm. | 559 // Indicates this connection is for the wm. |
519 DCHECK(window_manager_internal_); | 560 DCHECK(window_manager_internal_); |
520 | 561 |
521 WindowTreeHostImpl* host = GetHost(*roots_.begin()); | 562 WindowTreeHostImpl* host = GetHost(*roots_.begin()); |
(...skipping 20 matching lines...) Expand all Loading... |
542 if (!host || !host->GetWindowTree() || | 583 if (!host || !host->GetWindowTree() || |
543 !host->GetWindowTree()->window_manager_internal_) { | 584 !host->GetWindowTree()->window_manager_internal_) { |
544 return false; | 585 return false; |
545 } | 586 } |
546 | 587 |
547 // Requests coming from the WM should not be routed through the WM again. | 588 // Requests coming from the WM should not be routed through the WM again. |
548 const bool is_wm = host->GetWindowTree() == this; | 589 const bool is_wm = host->GetWindowTree() == this; |
549 return is_wm ? false : true; | 590 return is_wm ? false : true; |
550 } | 591 } |
551 | 592 |
552 bool WindowTreeImpl::IsWindowKnown(const ServerWindow* window) const { | 593 ClientWindowId WindowTreeImpl::ClientWindowIdForWindow( |
553 return known_windows_.count(WindowIdToTransportId(window->id())) > 0; | 594 const ServerWindow* window) const { |
| 595 auto iter = window_id_to_client_id_map_.find(window->id()); |
| 596 DCHECK(iter != window_id_to_client_id_map_.end()); |
| 597 return iter->second; |
554 } | 598 } |
555 | 599 |
556 bool WindowTreeImpl::IsValidIdForNewWindow(const WindowId& id) const { | 600 bool WindowTreeImpl::IsValidIdForNewWindow(const ClientWindowId& id) const { |
557 return id.connection_id == id_ && embed_to_real_id_map_.count(id) == 0 && | 601 if (is_embed_root_ && WindowIdFromTransportId(id.id).connection_id != id_) { |
558 window_map_.count(id.window_id) == 0; | 602 // Embed roots see windows created from other connections. If they don't |
| 603 // use the connection id when creating windows the client could end up with |
| 604 // two windows with the same id. Because of this we restrict the ids such |
| 605 // connections can create. |
| 606 return false; |
| 607 } |
| 608 return client_id_to_window_id_map_.count(id) == 0u; |
| 609 } |
| 610 |
| 611 WindowId WindowTreeImpl::GenerateNewWindowId() { |
| 612 // TODO(sky): deal with wrapping and uniqueness. |
| 613 return WindowId(id_, next_window_id_++); |
559 } | 614 } |
560 | 615 |
561 bool WindowTreeImpl::CanReorderWindow(const ServerWindow* window, | 616 bool WindowTreeImpl::CanReorderWindow(const ServerWindow* window, |
562 const ServerWindow* relative_window, | 617 const ServerWindow* relative_window, |
563 mojom::OrderDirection direction) const { | 618 mojom::OrderDirection direction) const { |
564 if (!window || !relative_window) | 619 if (!window || !relative_window) |
565 return false; | 620 return false; |
566 | 621 |
567 if (!window->parent() || window->parent() != relative_window->parent()) | 622 if (!window->parent() || window->parent() != relative_window->parent()) |
568 return false; | 623 return false; |
(...skipping 23 matching lines...) Expand all Loading... |
592 delete window; | 647 delete window; |
593 return true; | 648 return true; |
594 } | 649 } |
595 | 650 |
596 void WindowTreeImpl::GetUnknownWindowsFrom( | 651 void WindowTreeImpl::GetUnknownWindowsFrom( |
597 const ServerWindow* window, | 652 const ServerWindow* window, |
598 std::vector<const ServerWindow*>* windows) { | 653 std::vector<const ServerWindow*>* windows) { |
599 if (IsWindowKnown(window) || !access_policy_->CanGetWindowTree(window)) | 654 if (IsWindowKnown(window) || !access_policy_->CanGetWindowTree(window)) |
600 return; | 655 return; |
601 windows->push_back(window); | 656 windows->push_back(window); |
602 known_windows_.insert(WindowIdToTransportId(window->id())); | 657 // There are two cases where this gets hit: |
| 658 // . During init, in which case using the window id as the client id is |
| 659 // fine. |
| 660 // . When a window is moved to a parent of a window we know about. This is |
| 661 // only encountered for the WM or embed roots. We assume such clients want |
| 662 // to see the real id of the window and are only created ClientWindowIds |
| 663 // with the connection_id. |
| 664 const ClientWindowId client_window_id(WindowIdToTransportId(window->id())); |
| 665 DCHECK_EQ(0u, client_id_to_window_id_map_.count(client_window_id)); |
| 666 client_id_to_window_id_map_[client_window_id] = window->id(); |
| 667 window_id_to_client_id_map_[window->id()] = client_window_id; |
603 if (!access_policy_->CanDescendIntoWindowForWindowTree(window)) | 668 if (!access_policy_->CanDescendIntoWindowForWindowTree(window)) |
604 return; | 669 return; |
605 std::vector<const ServerWindow*> children(window->GetChildren()); | 670 std::vector<const ServerWindow*> children(window->GetChildren()); |
606 for (size_t i = 0; i < children.size(); ++i) | 671 for (size_t i = 0; i < children.size(); ++i) |
607 GetUnknownWindowsFrom(children[i], windows); | 672 GetUnknownWindowsFrom(children[i], windows); |
608 } | 673 } |
609 | 674 |
| 675 bool WindowTreeImpl::RemoveFromMaps(const ServerWindow* window) { |
| 676 auto iter = window_id_to_client_id_map_.find(window->id()); |
| 677 if (iter == window_id_to_client_id_map_.end()) |
| 678 return false; |
| 679 |
| 680 client_id_to_window_id_map_.erase(iter->second); |
| 681 window_id_to_client_id_map_.erase(iter); |
| 682 return true; |
| 683 } |
| 684 |
610 void WindowTreeImpl::RemoveFromKnown( | 685 void WindowTreeImpl::RemoveFromKnown( |
611 const ServerWindow* window, | 686 const ServerWindow* window, |
612 std::vector<ServerWindow*>* local_windows) { | 687 std::vector<ServerWindow*>* local_windows) { |
613 if (window->id().connection_id == id_) { | 688 if (window->id().connection_id == id_) { |
614 if (local_windows) | 689 if (local_windows) |
615 local_windows->push_back(GetWindow(window->id())); | 690 local_windows->push_back(GetWindow(window->id())); |
616 return; | 691 return; |
617 } | 692 } |
618 known_windows_.erase(WindowIdToTransportId(window->id())); | 693 |
| 694 RemoveFromMaps(window); |
| 695 |
619 std::vector<const ServerWindow*> children = window->GetChildren(); | 696 std::vector<const ServerWindow*> children = window->GetChildren(); |
620 for (size_t i = 0; i < children.size(); ++i) | 697 for (size_t i = 0; i < children.size(); ++i) |
621 RemoveFromKnown(children[i], local_windows); | 698 RemoveFromKnown(children[i], local_windows); |
622 } | 699 } |
623 | 700 |
624 void WindowTreeImpl::RemoveRoot(const ServerWindow* window, | 701 void WindowTreeImpl::RemoveRoot(const ServerWindow* window, |
625 RemoveRootReason reason) { | 702 RemoveRootReason reason) { |
626 DCHECK(roots_.count(window) > 0); | 703 DCHECK(roots_.count(window) > 0); |
627 roots_.erase(window); | 704 roots_.erase(window); |
628 const Id transport_id = MapWindowIdToClient(window); | |
629 | 705 |
630 for (auto& pair : embed_to_real_id_map_) { | 706 const ClientWindowId client_window_id(ClientWindowIdForWindow(window)); |
631 if (pair.second == window->id()) { | |
632 embed_to_real_id_map_.erase(pair.first); | |
633 break; | |
634 } | |
635 } | |
636 | 707 |
637 // No need to do anything if we created the window. | 708 // No need to do anything if we created the window. |
638 if (window->id().connection_id == id_) | 709 if (window->id().connection_id == id_) |
639 return; | 710 return; |
640 | 711 |
641 if (reason == RemoveRootReason::EMBED) { | 712 if (reason == RemoveRootReason::EMBED) { |
642 client_->OnUnembed(transport_id); | 713 client_->OnUnembed(client_window_id.id); |
643 client_->OnWindowDeleted(transport_id); | 714 client_->OnWindowDeleted(client_window_id.id); |
644 connection_manager_->OnConnectionMessagedClient(id_); | 715 connection_manager_->OnConnectionMessagedClient(id_); |
645 } | 716 } |
646 | 717 |
647 // This connection no longer knows about the window. Unparent any windows that | 718 // This connection no longer knows about the window. Unparent any windows that |
648 // were parented to windows in the root. | 719 // were parented to windows in the root. |
649 std::vector<ServerWindow*> local_windows; | 720 std::vector<ServerWindow*> local_windows; |
650 RemoveFromKnown(window, &local_windows); | 721 RemoveFromKnown(window, &local_windows); |
651 for (size_t i = 0; i < local_windows.size(); ++i) | 722 for (size_t i = 0; i < local_windows.size(); ++i) |
652 local_windows[i]->parent()->Remove(local_windows[i]); | 723 local_windows[i]->parent()->Remove(local_windows[i]); |
653 } | 724 } |
654 | 725 |
655 Array<mojom::WindowDataPtr> WindowTreeImpl::WindowsToWindowDatas( | 726 Array<mojom::WindowDataPtr> WindowTreeImpl::WindowsToWindowDatas( |
656 const std::vector<const ServerWindow*>& windows) { | 727 const std::vector<const ServerWindow*>& windows) { |
657 Array<mojom::WindowDataPtr> array(windows.size()); | 728 Array<mojom::WindowDataPtr> array(windows.size()); |
658 for (size_t i = 0; i < windows.size(); ++i) | 729 for (size_t i = 0; i < windows.size(); ++i) |
659 array[i] = WindowToWindowData(windows[i]); | 730 array[i] = WindowToWindowData(windows[i]); |
660 return array; | 731 return array; |
661 } | 732 } |
662 | 733 |
663 mojom::WindowDataPtr WindowTreeImpl::WindowToWindowData( | 734 mojom::WindowDataPtr WindowTreeImpl::WindowToWindowData( |
664 const ServerWindow* window) { | 735 const ServerWindow* window) { |
665 DCHECK(IsWindowKnown(window)); | 736 DCHECK(IsWindowKnown(window)); |
666 const ServerWindow* parent = window->parent(); | 737 const ServerWindow* parent = window->parent(); |
667 // If the parent isn't known, it means the parent is not visible to us (not | 738 // If the parent isn't known, it means the parent is not visible to us (not |
668 // in roots), and should not be sent over. | 739 // in roots), and should not be sent over. |
669 if (parent && !IsWindowKnown(parent)) | 740 if (parent && !IsWindowKnown(parent)) |
670 parent = NULL; | 741 parent = nullptr; |
671 mojom::WindowDataPtr window_data(mojom::WindowData::New()); | 742 mojom::WindowDataPtr window_data(mojom::WindowData::New()); |
672 window_data->parent_id = MapWindowIdToClient(parent); | 743 window_data->parent_id = |
673 window_data->window_id = MapWindowIdToClient(window); | 744 parent ? ClientWindowIdForWindow(parent).id : ClientWindowId().id; |
| 745 window_data->window_id = |
| 746 window ? ClientWindowIdForWindow(window).id : ClientWindowId().id; |
674 window_data->bounds = Rect::From(window->bounds()); | 747 window_data->bounds = Rect::From(window->bounds()); |
675 window_data->properties = | 748 window_data->properties = |
676 mojo::Map<String, Array<uint8_t>>::From(window->properties()); | 749 mojo::Map<String, Array<uint8_t>>::From(window->properties()); |
677 window_data->visible = window->visible(); | 750 window_data->visible = window->visible(); |
678 window_data->drawn = window->IsDrawn(); | 751 window_data->drawn = window->IsDrawn(); |
679 window_data->viewport_metrics = | 752 window_data->viewport_metrics = |
680 connection_manager_->GetViewportMetricsForWindow(window); | 753 connection_manager_->GetViewportMetricsForWindow(window); |
681 return window_data; | 754 return window_data; |
682 } | 755 } |
683 | 756 |
(...skipping 17 matching lines...) Expand all Loading... |
701 | 774 |
702 void WindowTreeImpl::NotifyDrawnStateChanged(const ServerWindow* window, | 775 void WindowTreeImpl::NotifyDrawnStateChanged(const ServerWindow* window, |
703 bool new_drawn_value) { | 776 bool new_drawn_value) { |
704 // Even though we don't know about window, it may be an ancestor of our root, | 777 // Even though we don't know about window, it may be an ancestor of our root, |
705 // in which case the change may effect our roots drawn state. | 778 // in which case the change may effect our roots drawn state. |
706 if (roots_.empty()) | 779 if (roots_.empty()) |
707 return; | 780 return; |
708 | 781 |
709 for (auto* root : roots_) { | 782 for (auto* root : roots_) { |
710 if (window->Contains(root) && (new_drawn_value != root->IsDrawn())) { | 783 if (window->Contains(root) && (new_drawn_value != root->IsDrawn())) { |
711 client_->OnWindowDrawnStateChanged(MapWindowIdToClient(root), | 784 client_->OnWindowDrawnStateChanged(ClientWindowIdForWindow(root).id, |
712 new_drawn_value); | 785 new_drawn_value); |
713 } | 786 } |
714 } | 787 } |
715 } | 788 } |
716 | 789 |
717 void WindowTreeImpl::DestroyWindows() { | 790 void WindowTreeImpl::DestroyWindows() { |
718 if (window_map_.empty()) | 791 if (created_window_map_.empty()) |
719 return; | 792 return; |
720 | 793 |
721 Operation op(this, connection_manager_, OperationType::DELETE_WINDOW); | 794 Operation op(this, connection_manager_, OperationType::DELETE_WINDOW); |
722 // If we get here from the destructor we're not going to get | 795 // If we get here from the destructor we're not going to get |
723 // ProcessWindowDeleted(). Copy the map and delete from the copy so that we | 796 // ProcessWindowDeleted(). Copy the map and delete from the copy so that we |
724 // don't have to worry about whether |window_map_| changes or not. | 797 // don't have to worry about whether |created_window_map_| changes or not. |
725 WindowMap window_map_copy; | 798 base::hash_map<WindowId, ServerWindow*> created_window_map_copy; |
726 window_map_.swap(window_map_copy); | 799 created_window_map_.swap(created_window_map_copy); |
727 // A sibling can be a transient parent of another window so we detach windows | 800 // A sibling can be a transient parent of another window so we detach windows |
728 // from their transient parents to avoid double deletes. | 801 // from their transient parents to avoid double deletes. |
729 for (auto& pair : window_map_copy) { | 802 for (auto& pair : created_window_map_copy) { |
730 ServerWindow* transient_parent = pair.second->transient_parent(); | 803 ServerWindow* transient_parent = pair.second->transient_parent(); |
731 if (transient_parent) | 804 if (transient_parent) |
732 transient_parent->RemoveTransientWindow(pair.second); | 805 transient_parent->RemoveTransientWindow(pair.second); |
733 } | 806 } |
734 STLDeleteValues(&window_map_copy); | 807 STLDeleteValues(&created_window_map_copy); |
735 } | 808 } |
736 | 809 |
737 bool WindowTreeImpl::CanEmbed(const WindowId& window_id, | 810 bool WindowTreeImpl::CanEmbed(const ClientWindowId& window_id, |
738 uint32_t policy_bitmask) const { | 811 uint32_t policy_bitmask) const { |
739 const ServerWindow* window = GetWindow(window_id); | 812 const ServerWindow* window = GetWindowByClientId(window_id); |
740 return window && access_policy_->CanEmbed(window, policy_bitmask); | 813 return window && access_policy_->CanEmbed(window, policy_bitmask); |
741 } | 814 } |
742 | 815 |
743 void WindowTreeImpl::PrepareForEmbed(const WindowId& window_id) { | 816 void WindowTreeImpl::PrepareForEmbed(ServerWindow* window) { |
744 const ServerWindow* window = GetWindow(window_id); | |
745 DCHECK(window); | 817 DCHECK(window); |
746 | 818 |
747 // Only allow a node to be the root for one connection. | 819 // Only allow a node to be the root for one connection. |
748 WindowTreeImpl* existing_owner = | 820 WindowTreeImpl* existing_owner = |
749 connection_manager_->GetConnectionWithRoot(window); | 821 connection_manager_->GetConnectionWithRoot(window); |
750 | 822 |
751 Operation op(this, connection_manager_, OperationType::EMBED); | 823 Operation op(this, connection_manager_, OperationType::EMBED); |
752 RemoveChildrenAsPartOfEmbed(window_id); | 824 RemoveChildrenAsPartOfEmbed(window); |
753 if (existing_owner) { | 825 if (existing_owner) { |
754 // Never message the originating connection. | 826 // Never message the originating connection. |
755 connection_manager_->OnConnectionMessagedClient(id_); | 827 connection_manager_->OnConnectionMessagedClient(id_); |
756 existing_owner->RemoveRoot(window, RemoveRootReason::EMBED); | 828 existing_owner->RemoveRoot(window, RemoveRootReason::EMBED); |
757 } | 829 } |
758 } | 830 } |
759 | 831 |
760 void WindowTreeImpl::RemoveChildrenAsPartOfEmbed(const WindowId& window_id) { | 832 void WindowTreeImpl::RemoveChildrenAsPartOfEmbed(ServerWindow* window) { |
761 ServerWindow* window = GetWindow(window_id); | |
762 CHECK(window); | 833 CHECK(window); |
763 CHECK(window->id().connection_id == window_id.connection_id); | |
764 std::vector<ServerWindow*> children = window->GetChildren(); | 834 std::vector<ServerWindow*> children = window->GetChildren(); |
765 for (size_t i = 0; i < children.size(); ++i) | 835 for (size_t i = 0; i < children.size(); ++i) |
766 window->Remove(children[i]); | 836 window->Remove(children[i]); |
767 } | 837 } |
768 | 838 |
769 void WindowTreeImpl::DispatchInputEventImpl(ServerWindow* target, | 839 void WindowTreeImpl::DispatchInputEventImpl(ServerWindow* target, |
770 mojom::EventPtr event) { | 840 mojom::EventPtr event) { |
771 DCHECK(!event_ack_id_); | 841 DCHECK(!event_ack_id_); |
772 // We do not want to create a sequential id for each event, because that can | 842 // We do not want to create a sequential id for each event, because that can |
773 // leak some information to the client. So instead, manufacture the id from | 843 // leak some information to the client. So instead, manufacture the id from |
774 // the event pointer. | 844 // the event pointer. |
775 event_ack_id_ = | 845 event_ack_id_ = |
776 0x1000000 | (reinterpret_cast<uintptr_t>(event.get()) & 0xffffff); | 846 0x1000000 | (reinterpret_cast<uintptr_t>(event.get()) & 0xffffff); |
777 event_source_host_ = GetHost(target); | 847 event_source_host_ = GetHost(target); |
778 // Should only get events from windows attached to a host. | 848 // Should only get events from windows attached to a host. |
779 DCHECK(event_source_host_); | 849 DCHECK(event_source_host_); |
780 client_->OnWindowInputEvent(event_ack_id_, MapWindowIdToClient(target), | 850 client_->OnWindowInputEvent(event_ack_id_, ClientWindowIdForWindow(target).id, |
781 std::move(event)); | 851 std::move(event)); |
782 } | 852 } |
783 | 853 |
784 void WindowTreeImpl::NewWindow( | 854 void WindowTreeImpl::NewWindow( |
785 uint32_t change_id, | 855 uint32_t change_id, |
786 Id transport_window_id, | 856 Id transport_window_id, |
787 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 857 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
788 std::map<std::string, std::vector<uint8_t>> properties; | 858 std::map<std::string, std::vector<uint8_t>> properties; |
789 if (!transport_properties.is_null()) { | 859 if (!transport_properties.is_null()) { |
790 properties = | 860 properties = |
791 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 861 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
792 } | 862 } |
793 client_->OnChangeCompleted( | 863 client_->OnChangeCompleted( |
794 change_id, | 864 change_id, NewWindow(ClientWindowId(transport_window_id), properties)); |
795 NewWindow(MapWindowIdFromClient(transport_window_id), properties)); | |
796 } | 865 } |
797 | 866 |
798 void WindowTreeImpl::NewTopLevelWindow( | 867 void WindowTreeImpl::NewTopLevelWindow( |
799 uint32_t change_id, | 868 uint32_t change_id, |
800 Id transport_window_id, | 869 Id transport_window_id, |
801 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 870 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
802 DCHECK(!waiting_for_top_level_window_info_); | 871 DCHECK(!waiting_for_top_level_window_info_); |
803 const WindowId window_id(MapWindowIdFromClient(transport_window_id)); | 872 const ClientWindowId client_window_id(transport_window_id); |
804 // TODO(sky): need a way for client to provide context. | 873 // TODO(sky): need a way for client to provide context. |
805 WindowTreeHostImpl* tree_host = | 874 WindowTreeHostImpl* tree_host = |
806 connection_manager_->GetActiveWindowTreeHost(); | 875 connection_manager_->GetActiveWindowTreeHost(); |
807 if (!tree_host || tree_host->GetWindowTree() == this || | 876 if (!tree_host || tree_host->GetWindowTree() == this || |
808 !IsValidIdForNewWindow(window_id)) { | 877 !IsValidIdForNewWindow(client_window_id)) { |
809 client_->OnChangeCompleted(change_id, false); | 878 client_->OnChangeCompleted(change_id, false); |
810 return; | 879 return; |
811 } | 880 } |
812 | 881 |
813 // The server creates the real window. Any further messages from the client | 882 // The server creates the real window. Any further messages from the client |
814 // may try to alter the window. Pause incoming messages so that we know we | 883 // may try to alter the window. Pause incoming messages so that we know we |
815 // can't get a message for a window before the window is created. Once the | 884 // can't get a message for a window before the window is created. Once the |
816 // window is created we'll resume processing. | 885 // window is created we'll resume processing. |
817 connection_manager_->GetClientConnection(this) | 886 connection_manager_->GetClientConnection(this) |
818 ->SetIncomingMethodCallProcessingPaused(true); | 887 ->SetIncomingMethodCallProcessingPaused(true); |
819 | 888 |
820 const uint32_t wm_change_id = | 889 const uint32_t wm_change_id = |
821 connection_manager_->GenerateWindowManagerChangeId(this, change_id); | 890 connection_manager_->GenerateWindowManagerChangeId(this, change_id); |
822 | 891 |
823 waiting_for_top_level_window_info_.reset( | 892 waiting_for_top_level_window_info_.reset( |
824 new WaitingForTopLevelWindowInfo(window_id, wm_change_id)); | 893 new WaitingForTopLevelWindowInfo(client_window_id, wm_change_id)); |
825 | 894 |
826 tree_host->GetWindowTree()->window_manager_internal_->WmCreateTopLevelWindow( | 895 tree_host->GetWindowTree()->window_manager_internal_->WmCreateTopLevelWindow( |
827 wm_change_id, std::move(transport_properties)); | 896 wm_change_id, std::move(transport_properties)); |
828 } | 897 } |
829 | 898 |
830 void WindowTreeImpl::DeleteWindow(uint32_t change_id, Id transport_window_id) { | 899 void WindowTreeImpl::DeleteWindow(uint32_t change_id, Id transport_window_id) { |
831 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 900 ServerWindow* window = |
| 901 GetWindowByClientId(ClientWindowId(transport_window_id)); |
832 bool success = false; | 902 bool success = false; |
833 bool should_close = window && (access_policy_->CanDeleteWindow(window) || | 903 bool should_close = window && (access_policy_->CanDeleteWindow(window) || |
834 ShouldRouteToWindowManager(window)); | 904 ShouldRouteToWindowManager(window)); |
835 if (should_close) { | 905 if (should_close) { |
836 WindowTreeImpl* connection = | 906 WindowTreeImpl* connection = |
837 connection_manager_->GetConnection(window->id().connection_id); | 907 connection_manager_->GetConnection(window->id().connection_id); |
838 success = connection && connection->DeleteWindowImpl(this, window); | 908 success = connection && connection->DeleteWindowImpl(this, window); |
839 } | 909 } |
840 client_->OnChangeCompleted(change_id, success); | 910 client_->OnChangeCompleted(change_id, success); |
841 } | 911 } |
842 | 912 |
843 void WindowTreeImpl::AddWindow(uint32_t change_id, Id parent_id, Id child_id) { | 913 void WindowTreeImpl::AddWindow(uint32_t change_id, Id parent_id, Id child_id) { |
844 client_->OnChangeCompleted(change_id, | 914 client_->OnChangeCompleted(change_id, AddWindow(ClientWindowId(parent_id), |
845 AddWindow(MapWindowIdFromClient(parent_id), | 915 ClientWindowId(child_id))); |
846 MapWindowIdFromClient(child_id))); | |
847 } | 916 } |
848 | 917 |
849 void WindowTreeImpl::RemoveWindowFromParent(uint32_t change_id, Id window_id) { | 918 void WindowTreeImpl::RemoveWindowFromParent(uint32_t change_id, Id window_id) { |
850 bool success = false; | 919 bool success = false; |
851 ServerWindow* window = GetWindow(MapWindowIdFromClient(window_id)); | 920 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
852 if (window && window->parent() && | 921 if (window && window->parent() && |
853 access_policy_->CanRemoveWindowFromParent(window)) { | 922 access_policy_->CanRemoveWindowFromParent(window)) { |
854 success = true; | 923 success = true; |
855 Operation op(this, connection_manager_, | 924 Operation op(this, connection_manager_, |
856 OperationType::REMOVE_WINDOW_FROM_PARENT); | 925 OperationType::REMOVE_WINDOW_FROM_PARENT); |
857 window->parent()->Remove(window); | 926 window->parent()->Remove(window); |
858 } | 927 } |
859 client_->OnChangeCompleted(change_id, success); | 928 client_->OnChangeCompleted(change_id, success); |
860 } | 929 } |
861 | 930 |
862 void WindowTreeImpl::AddTransientWindow(uint32_t change_id, | 931 void WindowTreeImpl::AddTransientWindow(uint32_t change_id, |
863 Id window, | 932 Id window, |
864 Id transient_window) { | 933 Id transient_window) { |
865 client_->OnChangeCompleted( | 934 client_->OnChangeCompleted( |
866 change_id, AddTransientWindow(MapWindowIdFromClient(window), | 935 change_id, AddTransientWindow(ClientWindowId(window), |
867 MapWindowIdFromClient(transient_window))); | 936 ClientWindowId(transient_window))); |
868 } | 937 } |
869 | 938 |
870 void WindowTreeImpl::RemoveTransientWindowFromParent(uint32_t change_id, | 939 void WindowTreeImpl::RemoveTransientWindowFromParent(uint32_t change_id, |
871 Id transient_window_id) { | 940 Id transient_window_id) { |
872 bool success = false; | 941 bool success = false; |
873 ServerWindow* transient_window = | 942 ServerWindow* transient_window = |
874 GetWindow(MapWindowIdFromClient(transient_window_id)); | 943 GetWindowByClientId(ClientWindowId(transient_window_id)); |
875 if (transient_window->transient_parent() && | 944 if (transient_window && transient_window->transient_parent() && |
876 access_policy_->CanRemoveTransientWindowFromParent(transient_window)) { | 945 access_policy_->CanRemoveTransientWindowFromParent(transient_window)) { |
877 success = true; | 946 success = true; |
878 Operation op(this, connection_manager_, | 947 Operation op(this, connection_manager_, |
879 OperationType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT); | 948 OperationType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT); |
880 transient_window->transient_parent()->RemoveTransientWindow( | 949 transient_window->transient_parent()->RemoveTransientWindow( |
881 transient_window); | 950 transient_window); |
882 } | 951 } |
883 client_->OnChangeCompleted(change_id, success); | 952 client_->OnChangeCompleted(change_id, success); |
884 } | 953 } |
885 | 954 |
886 void WindowTreeImpl::ReorderWindow(uint32_t change_id, | 955 void WindowTreeImpl::ReorderWindow(uint32_t change_id, |
887 Id window_id, | 956 Id window_id, |
888 Id relative_window_id, | 957 Id relative_window_id, |
889 mojom::OrderDirection direction) { | 958 mojom::OrderDirection direction) { |
890 bool success = false; | 959 bool success = false; |
891 ServerWindow* window = GetWindow(MapWindowIdFromClient(window_id)); | 960 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
892 ServerWindow* relative_window = | 961 ServerWindow* relative_window = |
893 GetWindow(MapWindowIdFromClient(relative_window_id)); | 962 GetWindowByClientId(ClientWindowId(relative_window_id)); |
894 if (CanReorderWindow(window, relative_window, direction)) { | 963 if (CanReorderWindow(window, relative_window, direction)) { |
895 success = true; | 964 success = true; |
896 Operation op(this, connection_manager_, OperationType::REORDER_WINDOW); | 965 Operation op(this, connection_manager_, OperationType::REORDER_WINDOW); |
897 window->Reorder(relative_window, direction); | 966 window->Reorder(relative_window, direction); |
898 connection_manager_->ProcessWindowReorder(window, relative_window, | 967 connection_manager_->ProcessWindowReorder(window, relative_window, |
899 direction); | 968 direction); |
900 } | 969 } |
901 client_->OnChangeCompleted(change_id, success); | 970 client_->OnChangeCompleted(change_id, success); |
902 } | 971 } |
903 | 972 |
904 void WindowTreeImpl::GetWindowTree( | 973 void WindowTreeImpl::GetWindowTree( |
905 Id window_id, | 974 Id window_id, |
906 const Callback<void(Array<mojom::WindowDataPtr>)>& callback) { | 975 const Callback<void(Array<mojom::WindowDataPtr>)>& callback) { |
907 std::vector<const ServerWindow*> windows( | 976 std::vector<const ServerWindow*> windows( |
908 GetWindowTree(MapWindowIdFromClient(window_id))); | 977 GetWindowTree(ClientWindowId(window_id))); |
909 callback.Run(WindowsToWindowDatas(windows)); | 978 callback.Run(WindowsToWindowDatas(windows)); |
910 } | 979 } |
911 | 980 |
912 void WindowTreeImpl::SetWindowBounds(uint32_t change_id, | 981 void WindowTreeImpl::SetWindowBounds(uint32_t change_id, |
913 Id window_id, | 982 Id window_id, |
914 mojo::RectPtr bounds) { | 983 mojo::RectPtr bounds) { |
915 ServerWindow* window = GetWindow(MapWindowIdFromClient(window_id)); | 984 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
916 if (window && ShouldRouteToWindowManager(window)) { | 985 if (window && ShouldRouteToWindowManager(window)) { |
917 const uint32_t wm_change_id = | 986 const uint32_t wm_change_id = |
918 connection_manager_->GenerateWindowManagerChangeId(this, change_id); | 987 connection_manager_->GenerateWindowManagerChangeId(this, change_id); |
919 // |window_id| may be a client id, use the id from the window to ensure | 988 // |window_id| may be a client id, use the id from the window to ensure |
920 // the windowmanager doesn't get an id it doesn't know about. | 989 // the windowmanager doesn't get an id it doesn't know about. |
921 GetHost(window)->GetWindowTree()->window_manager_internal_->WmSetBounds( | 990 WindowTreeImpl* wm_window_tree = GetHost(window)->GetWindowTree(); |
922 wm_change_id, WindowIdToTransportId(window->id()), std::move(bounds)); | 991 wm_window_tree->window_manager_internal_->WmSetBounds( |
| 992 wm_change_id, wm_window_tree->ClientWindowIdForWindow(window).id, |
| 993 std::move(bounds)); |
923 return; | 994 return; |
924 } | 995 } |
925 | 996 |
926 // Only the owner of the window can change the bounds. | 997 // Only the owner of the window can change the bounds. |
927 bool success = window && access_policy_->CanSetWindowBounds(window); | 998 bool success = window && access_policy_->CanSetWindowBounds(window); |
928 if (success) { | 999 if (success) { |
929 Operation op(this, connection_manager_, OperationType::SET_WINDOW_BOUNDS); | 1000 Operation op(this, connection_manager_, OperationType::SET_WINDOW_BOUNDS); |
930 window->SetBounds(bounds.To<gfx::Rect>()); | 1001 window->SetBounds(bounds.To<gfx::Rect>()); |
931 } | 1002 } |
932 client_->OnChangeCompleted(change_id, success); | 1003 client_->OnChangeCompleted(change_id, success); |
933 } | 1004 } |
934 | 1005 |
935 void WindowTreeImpl::SetWindowVisibility(uint32_t change_id, | 1006 void WindowTreeImpl::SetWindowVisibility(uint32_t change_id, |
936 Id transport_window_id, | 1007 Id transport_window_id, |
937 bool visible) { | 1008 bool visible) { |
938 client_->OnChangeCompleted( | 1009 client_->OnChangeCompleted( |
939 change_id, | 1010 change_id, |
940 SetWindowVisibility(MapWindowIdFromClient(transport_window_id), visible)); | 1011 SetWindowVisibility(ClientWindowId(transport_window_id), visible)); |
941 } | 1012 } |
942 | 1013 |
943 void WindowTreeImpl::SetWindowProperty(uint32_t change_id, | 1014 void WindowTreeImpl::SetWindowProperty(uint32_t change_id, |
944 Id transport_window_id, | 1015 Id transport_window_id, |
945 const mojo::String& name, | 1016 const mojo::String& name, |
946 mojo::Array<uint8_t> value) { | 1017 mojo::Array<uint8_t> value) { |
947 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1018 ServerWindow* window = |
| 1019 GetWindowByClientId(ClientWindowId(transport_window_id)); |
948 if (window && ShouldRouteToWindowManager(window)) { | 1020 if (window && ShouldRouteToWindowManager(window)) { |
949 const uint32_t wm_change_id = | 1021 const uint32_t wm_change_id = |
950 connection_manager_->GenerateWindowManagerChangeId(this, change_id); | 1022 connection_manager_->GenerateWindowManagerChangeId(this, change_id); |
951 GetHost(window)->GetWindowTree()->window_manager_internal_->WmSetProperty( | 1023 WindowTreeImpl* wm_window_tree = GetHost(window)->GetWindowTree(); |
952 wm_change_id, WindowIdToTransportId(window->id()), name, | 1024 wm_window_tree->window_manager_internal_->WmSetProperty( |
| 1025 wm_change_id, wm_window_tree->ClientWindowIdForWindow(window).id, name, |
953 std::move(value)); | 1026 std::move(value)); |
954 return; | 1027 return; |
955 } | 1028 } |
956 const bool success = window && access_policy_->CanSetWindowProperties(window); | 1029 const bool success = window && access_policy_->CanSetWindowProperties(window); |
957 if (success) { | 1030 if (success) { |
958 Operation op(this, connection_manager_, OperationType::SET_WINDOW_PROPERTY); | 1031 Operation op(this, connection_manager_, OperationType::SET_WINDOW_PROPERTY); |
959 if (value.is_null()) { | 1032 if (value.is_null()) { |
960 window->SetProperty(name, nullptr); | 1033 window->SetProperty(name, nullptr); |
961 } else { | 1034 } else { |
962 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); | 1035 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); |
963 window->SetProperty(name, &data); | 1036 window->SetProperty(name, &data); |
964 } | 1037 } |
965 } | 1038 } |
966 client_->OnChangeCompleted(change_id, success); | 1039 client_->OnChangeCompleted(change_id, success); |
967 } | 1040 } |
968 | 1041 |
969 void WindowTreeImpl::AttachSurface( | 1042 void WindowTreeImpl::AttachSurface( |
970 Id transport_window_id, | 1043 Id transport_window_id, |
971 mojom::SurfaceType type, | 1044 mojom::SurfaceType type, |
972 mojo::InterfaceRequest<mojom::Surface> surface, | 1045 mojo::InterfaceRequest<mojom::Surface> surface, |
973 mojom::SurfaceClientPtr client) { | 1046 mojom::SurfaceClientPtr client) { |
974 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1047 ServerWindow* window = |
| 1048 GetWindowByClientId(ClientWindowId(transport_window_id)); |
975 const bool success = | 1049 const bool success = |
976 window && access_policy_->CanSetWindowSurface(window, type); | 1050 window && access_policy_->CanSetWindowSurface(window, type); |
977 if (!success) | 1051 if (!success) |
978 return; | 1052 return; |
979 window->CreateSurface(type, std::move(surface), std::move(client)); | 1053 window->CreateSurface(type, std::move(surface), std::move(client)); |
980 } | 1054 } |
981 | 1055 |
982 void WindowTreeImpl::SetWindowTextInputState(Id transport_window_id, | 1056 void WindowTreeImpl::SetWindowTextInputState(Id transport_window_id, |
983 mojo::TextInputStatePtr state) { | 1057 mojo::TextInputStatePtr state) { |
984 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1058 ServerWindow* window = |
| 1059 GetWindowByClientId(ClientWindowId(transport_window_id)); |
985 bool success = window && access_policy_->CanSetWindowTextInputState(window); | 1060 bool success = window && access_policy_->CanSetWindowTextInputState(window); |
986 if (success) | 1061 if (success) |
987 window->SetTextInputState(state.To<ui::TextInputState>()); | 1062 window->SetTextInputState(state.To<ui::TextInputState>()); |
988 } | 1063 } |
989 | 1064 |
990 void WindowTreeImpl::SetImeVisibility(Id transport_window_id, | 1065 void WindowTreeImpl::SetImeVisibility(Id transport_window_id, |
991 bool visible, | 1066 bool visible, |
992 mojo::TextInputStatePtr state) { | 1067 mojo::TextInputStatePtr state) { |
993 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1068 ServerWindow* window = |
| 1069 GetWindowByClientId(ClientWindowId(transport_window_id)); |
994 bool success = window && access_policy_->CanSetWindowTextInputState(window); | 1070 bool success = window && access_policy_->CanSetWindowTextInputState(window); |
995 if (success) { | 1071 if (success) { |
996 if (!state.is_null()) | 1072 if (!state.is_null()) |
997 window->SetTextInputState(state.To<ui::TextInputState>()); | 1073 window->SetTextInputState(state.To<ui::TextInputState>()); |
998 | 1074 |
999 WindowTreeHostImpl* host = GetHost(window); | 1075 WindowTreeHostImpl* host = GetHost(window); |
1000 if (host) | 1076 if (host) |
1001 host->SetImeVisibility(window, visible); | 1077 host->SetImeVisibility(window, visible); |
1002 } | 1078 } |
1003 } | 1079 } |
(...skipping 23 matching lines...) Expand all Loading... |
1027 } while (!event_queue_.empty() && !GetHost(target)); | 1103 } while (!event_queue_.empty() && !GetHost(target)); |
1028 if (target) | 1104 if (target) |
1029 DispatchInputEventImpl(target, std::move(event)); | 1105 DispatchInputEventImpl(target, std::move(event)); |
1030 } | 1106 } |
1031 } | 1107 } |
1032 | 1108 |
1033 void WindowTreeImpl::SetClientArea( | 1109 void WindowTreeImpl::SetClientArea( |
1034 Id transport_window_id, | 1110 Id transport_window_id, |
1035 mojo::InsetsPtr insets, | 1111 mojo::InsetsPtr insets, |
1036 mojo::Array<mojo::RectPtr> transport_additional_client_areas) { | 1112 mojo::Array<mojo::RectPtr> transport_additional_client_areas) { |
1037 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1113 ServerWindow* window = |
| 1114 GetWindowByClientId(ClientWindowId(transport_window_id)); |
1038 if (!window || !access_policy_->CanSetClientArea(window)) | 1115 if (!window || !access_policy_->CanSetClientArea(window)) |
1039 return; | 1116 return; |
1040 | 1117 |
1041 std::vector<gfx::Rect> additional_client_areas = | 1118 std::vector<gfx::Rect> additional_client_areas = |
1042 transport_additional_client_areas.To<std::vector<gfx::Rect>>(); | 1119 transport_additional_client_areas.To<std::vector<gfx::Rect>>(); |
1043 window->SetClientArea(insets.To<gfx::Insets>(), additional_client_areas); | 1120 window->SetClientArea(insets.To<gfx::Insets>(), additional_client_areas); |
1044 } | 1121 } |
1045 | 1122 |
1046 void WindowTreeImpl::Embed(Id transport_window_id, | 1123 void WindowTreeImpl::Embed(Id transport_window_id, |
1047 mojom::WindowTreeClientPtr client, | 1124 mojom::WindowTreeClientPtr client, |
1048 uint32_t policy_bitmask, | 1125 uint32_t policy_bitmask, |
1049 const EmbedCallback& callback) { | 1126 const EmbedCallback& callback) { |
1050 ConnectionSpecificId connection_id = kInvalidConnectionId; | 1127 ConnectionSpecificId connection_id = kInvalidConnectionId; |
1051 const bool result = Embed(MapWindowIdFromClient(transport_window_id), | 1128 const bool result = Embed(ClientWindowId(transport_window_id), |
1052 std::move(client), policy_bitmask, &connection_id); | 1129 std::move(client), policy_bitmask, &connection_id); |
1053 callback.Run(result, connection_id); | 1130 callback.Run(result, connection_id); |
1054 } | 1131 } |
1055 | 1132 |
1056 void WindowTreeImpl::SetFocus(uint32_t change_id, Id transport_window_id) { | 1133 void WindowTreeImpl::SetFocus(uint32_t change_id, Id transport_window_id) { |
1057 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1134 ServerWindow* window = |
| 1135 GetWindowByClientId(ClientWindowId(transport_window_id)); |
1058 // TODO(beng): consider shifting non-policy drawn check logic to VTH's | 1136 // TODO(beng): consider shifting non-policy drawn check logic to VTH's |
1059 // FocusController. | 1137 // FocusController. |
1060 // TODO(sky): this doesn't work to clear focus. That is because if window is | 1138 // TODO(sky): this doesn't work to clear focus. That is because if window is |
1061 // null, then |host| is null and we fail. | 1139 // null, then |host| is null and we fail. |
1062 WindowTreeHostImpl* host = GetHost(window); | 1140 WindowTreeHostImpl* host = GetHost(window); |
1063 const bool success = window && window->IsDrawn() && window->can_focus() && | 1141 const bool success = window && window->IsDrawn() && window->can_focus() && |
1064 access_policy_->CanSetFocus(window) && host; | 1142 access_policy_->CanSetFocus(window) && host; |
1065 if (success) { | 1143 if (success) { |
1066 Operation op(this, connection_manager_, OperationType::SET_FOCUS); | 1144 Operation op(this, connection_manager_, OperationType::SET_FOCUS); |
1067 host->SetFocusedWindow(window); | 1145 host->SetFocusedWindow(window); |
1068 } | 1146 } |
1069 client_->OnChangeCompleted(change_id, success); | 1147 client_->OnChangeCompleted(change_id, success); |
1070 } | 1148 } |
1071 | 1149 |
1072 void WindowTreeImpl::SetCanFocus(Id transport_window_id, bool can_focus) { | 1150 void WindowTreeImpl::SetCanFocus(Id transport_window_id, bool can_focus) { |
1073 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1151 ServerWindow* window = |
| 1152 GetWindowByClientId(ClientWindowId(transport_window_id)); |
1074 // TODO(sky): there should be an else case (it shouldn't route to wm and | 1153 // TODO(sky): there should be an else case (it shouldn't route to wm and |
1075 // policy allows, then set_can_focus). | 1154 // policy allows, then set_can_focus). |
1076 if (window && ShouldRouteToWindowManager(window)) | 1155 if (window && ShouldRouteToWindowManager(window)) |
1077 window->set_can_focus(can_focus); | 1156 window->set_can_focus(can_focus); |
1078 } | 1157 } |
1079 | 1158 |
1080 void WindowTreeImpl::SetPredefinedCursor(uint32_t change_id, | 1159 void WindowTreeImpl::SetPredefinedCursor(uint32_t change_id, |
1081 Id transport_window_id, | 1160 Id transport_window_id, |
1082 mus::mojom::Cursor cursor_id) { | 1161 mus::mojom::Cursor cursor_id) { |
1083 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1162 ServerWindow* window = |
| 1163 GetWindowByClientId(ClientWindowId(transport_window_id)); |
1084 | 1164 |
1085 // Only the owner of the window can change the bounds. | 1165 // Only the owner of the window can change the bounds. |
1086 bool success = window && access_policy_->CanSetCursorProperties(window); | 1166 bool success = window && access_policy_->CanSetCursorProperties(window); |
1087 if (success) { | 1167 if (success) { |
1088 Operation op(this, connection_manager_, | 1168 Operation op(this, connection_manager_, |
1089 OperationType::SET_WINDOW_PREDEFINED_CURSOR); | 1169 OperationType::SET_WINDOW_PREDEFINED_CURSOR); |
1090 window->SetPredefinedCursor(cursor_id); | 1170 window->SetPredefinedCursor(cursor_id); |
1091 } | 1171 } |
1092 client_->OnChangeCompleted(change_id, success); | 1172 client_->OnChangeCompleted(change_id, success); |
1093 } | 1173 } |
(...skipping 17 matching lines...) Expand all Loading... |
1111 if (GetHostForWindowManager()) | 1191 if (GetHostForWindowManager()) |
1112 connection_manager_->WindowManagerChangeCompleted(change_id, response); | 1192 connection_manager_->WindowManagerChangeCompleted(change_id, response); |
1113 } | 1193 } |
1114 | 1194 |
1115 void WindowTreeImpl::WmRequestClose(Id transport_window_id) { | 1195 void WindowTreeImpl::WmRequestClose(Id transport_window_id) { |
1116 // Only the WindowManager should be using this. | 1196 // Only the WindowManager should be using this. |
1117 WindowTreeHostImpl* host = GetHostForWindowManager(); | 1197 WindowTreeHostImpl* host = GetHostForWindowManager(); |
1118 if (!host) | 1198 if (!host) |
1119 return; | 1199 return; |
1120 | 1200 |
1121 ServerWindow* window = GetWindow(MapWindowIdFromClient(transport_window_id)); | 1201 ServerWindow* window = |
| 1202 GetWindowByClientId(ClientWindowId(transport_window_id)); |
1122 WindowTreeImpl* connection = | 1203 WindowTreeImpl* connection = |
1123 connection_manager_->GetConnectionWithRoot(window); | 1204 connection_manager_->GetConnectionWithRoot(window); |
1124 if (connection && connection != host->GetWindowTree()) | 1205 if (connection && connection != host->GetWindowTree()) |
1125 connection->client_->RequestClose(connection->MapWindowIdToClient(window)); | 1206 connection->client_->RequestClose( |
| 1207 connection->ClientWindowIdForWindow(window).id); |
1126 // TODO(sky): think about what else case means. | 1208 // TODO(sky): think about what else case means. |
1127 } | 1209 } |
1128 | 1210 |
1129 void WindowTreeImpl::WmSetFrameDecorationValues( | 1211 void WindowTreeImpl::WmSetFrameDecorationValues( |
1130 mojom::FrameDecorationValuesPtr values) { | 1212 mojom::FrameDecorationValuesPtr values) { |
1131 if (GetHostForWindowManager()) | 1213 if (GetHostForWindowManager()) |
1132 GetHostForWindowManager()->SetFrameDecorationValues(std::move(values)); | 1214 GetHostForWindowManager()->SetFrameDecorationValues(std::move(values)); |
1133 } | 1215 } |
1134 | 1216 |
1135 void WindowTreeImpl::OnWmCreatedTopLevelWindow(uint32_t change_id, | 1217 void WindowTreeImpl::OnWmCreatedTopLevelWindow(uint32_t change_id, |
1136 Id transport_window_id) { | 1218 Id transport_window_id) { |
1137 if (GetHostForWindowManager()) { | 1219 if (GetHostForWindowManager()) { |
1138 connection_manager_->WindowManagerCreatedTopLevelWindow( | 1220 ServerWindow* window = |
1139 this, change_id, transport_window_id); | 1221 GetWindowByClientId(ClientWindowId(transport_window_id)); |
| 1222 if (window && window->id().connection_id != id_) { |
| 1223 connection_manager_->WindowManagerSentBogusMessage(); |
| 1224 window = nullptr; |
| 1225 } |
| 1226 connection_manager_->WindowManagerCreatedTopLevelWindow(this, change_id, |
| 1227 window); |
1140 } | 1228 } |
1141 // TODO(sky): think about what else case means. | 1229 // TODO(sky): think about what else case means. |
1142 } | 1230 } |
1143 | 1231 |
1144 bool WindowTreeImpl::HasRootForAccessPolicy(const ServerWindow* window) const { | 1232 bool WindowTreeImpl::HasRootForAccessPolicy(const ServerWindow* window) const { |
1145 return HasRoot(window); | 1233 return HasRoot(window); |
1146 } | 1234 } |
1147 | 1235 |
1148 bool WindowTreeImpl::IsWindowKnownForAccessPolicy( | 1236 bool WindowTreeImpl::IsWindowKnownForAccessPolicy( |
1149 const ServerWindow* window) const { | 1237 const ServerWindow* window) const { |
(...skipping 13 matching lines...) Expand all Loading... |
1163 | 1251 |
1164 for (const auto* root : roots_) { | 1252 for (const auto* root : roots_) { |
1165 if (root->Contains(window)) | 1253 if (root->Contains(window)) |
1166 return true; | 1254 return true; |
1167 } | 1255 } |
1168 return false; | 1256 return false; |
1169 } | 1257 } |
1170 | 1258 |
1171 } // namespace ws | 1259 } // namespace ws |
1172 } // namespace mus | 1260 } // namespace mus |
OLD | NEW |