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

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

Issue 1764483003: Changes ownership of ClientConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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_impl.h ('k') | components/mus/ws/window_tree_unittest.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 #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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 DISALLOW_COPY_AND_ASSIGN(TargetedEvent); 64 DISALLOW_COPY_AND_ASSIGN(TargetedEvent);
65 }; 65 };
66 66
67 WindowTreeImpl::WindowTreeImpl(ConnectionManager* connection_manager, 67 WindowTreeImpl::WindowTreeImpl(ConnectionManager* connection_manager,
68 ServerWindow* root, 68 ServerWindow* root,
69 uint32_t policy_bitmask) 69 uint32_t policy_bitmask)
70 : connection_manager_(connection_manager), 70 : connection_manager_(connection_manager),
71 id_(connection_manager_->GetAndAdvanceNextConnectionId()), 71 id_(connection_manager_->GetAndAdvanceNextConnectionId()),
72 next_window_id_(1), 72 next_window_id_(1),
73 client_(nullptr),
74 event_ack_id_(0), 73 event_ack_id_(0),
75 event_source_host_(nullptr), 74 event_source_host_(nullptr),
76 is_embed_root_(false), 75 is_embed_root_(false),
77 window_manager_internal_(nullptr) { 76 window_manager_internal_(nullptr) {
78 if (root) 77 if (root)
79 roots_.insert(root); 78 roots_.insert(root);
80 // TODO(sky): pass in type rather than inferring it. 79 // TODO(sky): pass in type rather than inferring it.
81 if (root && root->id().connection_id == kInvalidConnectionId) { 80 if (root && root->id().connection_id == kInvalidConnectionId) {
82 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); 81 access_policy_.reset(new WindowManagerAccessPolicy(id_, this));
83 is_embed_root_ = true; 82 is_embed_root_ = true;
84 } else { 83 } else {
85 access_policy_.reset(new DefaultAccessPolicy(id_, this)); 84 access_policy_.reset(new DefaultAccessPolicy(id_, this));
86 is_embed_root_ = (policy_bitmask & WindowTree::kAccessPolicyEmbedRoot) != 0; 85 is_embed_root_ = (policy_bitmask & WindowTree::kAccessPolicyEmbedRoot) != 0;
87 } 86 }
88 } 87 }
89 88
90 WindowTreeImpl::~WindowTreeImpl() { 89 WindowTreeImpl::~WindowTreeImpl() {
91 DestroyWindows(); 90 DestroyWindows();
92 } 91 }
93 92
94 void WindowTreeImpl::Init(mojom::WindowTreeClient* client, 93 void WindowTreeImpl::Init(scoped_ptr<ClientConnection> client_connection,
95 mojom::WindowTreePtr tree) { 94 mojom::WindowTreePtr tree) {
96 DCHECK(!client_); 95 DCHECK(!client_connection_);
97 client_ = client; 96 client_connection_ = std::move(client_connection);
98 97
99 if (roots_.empty()) 98 if (roots_.empty())
100 return; 99 return;
101 100
102 std::vector<const ServerWindow*> to_send; 101 std::vector<const ServerWindow*> to_send;
103 CHECK_EQ(1u, roots_.size()); 102 CHECK_EQ(1u, roots_.size());
104 GetUnknownWindowsFrom(*roots_.begin(), &to_send); 103 GetUnknownWindowsFrom(*roots_.begin(), &to_send);
105 104
106 WindowTreeHostImpl* host = GetHost(*roots_.begin()); 105 WindowTreeHostImpl* host = GetHost(*roots_.begin());
107 const ServerWindow* focused_window = 106 const ServerWindow* focused_window =
108 host ? host->GetFocusedWindow() : nullptr; 107 host ? host->GetFocusedWindow() : nullptr;
109 if (focused_window) 108 if (focused_window)
110 focused_window = access_policy_->GetWindowForFocusChange(focused_window); 109 focused_window = access_policy_->GetWindowForFocusChange(focused_window);
111 ClientWindowId focused_window_id; 110 ClientWindowId focused_window_id;
112 if (focused_window) 111 if (focused_window)
113 IsWindowKnown(focused_window, &focused_window_id); 112 IsWindowKnown(focused_window, &focused_window_id);
114 113
115 client->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree), 114 client()->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree),
116 focused_window_id.id, 115 focused_window_id.id,
117 is_embed_root_ ? WindowTree::kAccessPolicyEmbedRoot 116 is_embed_root_ ? WindowTree::kAccessPolicyEmbedRoot
118 : WindowTree::kAccessPolicyDefault); 117 : WindowTree::kAccessPolicyDefault);
119 } 118 }
120 119
121 void WindowTreeImpl::ConfigureWindowManager() { 120 void WindowTreeImpl::ConfigureWindowManager() {
122 DCHECK(!window_manager_internal_); 121 DCHECK(!window_manager_internal_);
123 window_manager_internal_ = 122 window_manager_internal_ = client_connection_->GetWindowManager();
124 connection_manager_->GetClientConnection(this)->GetWindowManager();
125 } 123 }
126 124
127 const ServerWindow* WindowTreeImpl::GetWindow(const WindowId& id) const { 125 const ServerWindow* WindowTreeImpl::GetWindow(const WindowId& id) const {
128 if (id_ == id.connection_id) { 126 if (id_ == id.connection_id) {
129 auto iter = created_window_map_.find(id); 127 auto iter = created_window_map_.find(id);
130 return iter == created_window_map_.end() ? nullptr : iter->second; 128 return iter == created_window_map_.end() ? nullptr : iter->second;
131 } 129 }
132 return connection_manager_->GetWindow(id); 130 return connection_manager_->GetWindow(id);
133 } 131 }
134 132
(...skipping 26 matching lines...) Expand all
161 : nullptr; 159 : nullptr;
162 } 160 }
163 161
164 void WindowTreeImpl::OnWindowDestroyingTreeImpl(WindowTreeImpl* connection) { 162 void WindowTreeImpl::OnWindowDestroyingTreeImpl(WindowTreeImpl* connection) {
165 // Notify our client if |connection| was embedded in any of our views. 163 // Notify our client if |connection| was embedded in any of our views.
166 for (const auto* connection_root : connection->roots_) { 164 for (const auto* connection_root : connection->roots_) {
167 const bool owns_connection_root = 165 const bool owns_connection_root =
168 connection_root->id().connection_id == id_; 166 connection_root->id().connection_id == id_;
169 if (owns_connection_root || 167 if (owns_connection_root ||
170 (is_embed_root_ && IsWindowKnown(connection_root))) { 168 (is_embed_root_ && IsWindowKnown(connection_root))) {
171 client_->OnEmbeddedAppDisconnected( 169 client()->OnEmbeddedAppDisconnected(
172 ClientWindowIdForWindow(connection_root).id); 170 ClientWindowIdForWindow(connection_root).id);
173 } 171 }
174 } 172 }
175 } 173 }
176 174
177 void WindowTreeImpl::OnWillDestroyWindowTreeHost( 175 void WindowTreeImpl::OnWillDestroyWindowTreeHost(
178 WindowTreeHostImpl* tree_host) { 176 WindowTreeHostImpl* tree_host) {
179 if (event_source_host_ == tree_host) 177 if (event_source_host_ == tree_host)
180 event_source_host_ = nullptr; 178 event_source_host_ = nullptr;
181 } 179 }
182 180
183 void WindowTreeImpl::NotifyChangeCompleted( 181 void WindowTreeImpl::NotifyChangeCompleted(
184 uint32_t change_id, 182 uint32_t change_id,
185 mojom::WindowManagerErrorCode error_code) { 183 mojom::WindowManagerErrorCode error_code) {
186 client_->OnChangeCompleted( 184 client()->OnChangeCompleted(
187 change_id, error_code == mojom::WindowManagerErrorCode::SUCCESS); 185 change_id, error_code == mojom::WindowManagerErrorCode::SUCCESS);
188 } 186 }
189 187
190 bool WindowTreeImpl::NewWindow( 188 bool WindowTreeImpl::NewWindow(
191 const ClientWindowId& client_window_id, 189 const ClientWindowId& client_window_id,
192 const std::map<std::string, std::vector<uint8_t>>& properties) { 190 const std::map<std::string, std::vector<uint8_t>>& properties) {
193 if (!IsValidIdForNewWindow(client_window_id)) 191 if (!IsValidIdForNewWindow(client_window_id))
194 return false; 192 return false;
195 const WindowId window_id = GenerateNewWindowId(); 193 const WindowId window_id = GenerateNewWindowId();
196 DCHECK(!GetWindow(window_id)); 194 DCHECK(!GetWindow(window_id));
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 waiting_for_top_level_window_info_->wm_change_id == wm_change_id; 293 waiting_for_top_level_window_info_->wm_change_id == wm_change_id;
296 } 294 }
297 295
298 void WindowTreeImpl::OnWindowManagerCreatedTopLevelWindow( 296 void WindowTreeImpl::OnWindowManagerCreatedTopLevelWindow(
299 uint32_t wm_change_id, 297 uint32_t wm_change_id,
300 uint32_t client_change_id, 298 uint32_t client_change_id,
301 const ServerWindow* window) { 299 const ServerWindow* window) {
302 DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id)); 300 DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id));
303 scoped_ptr<WaitingForTopLevelWindowInfo> waiting_for_top_level_window_info( 301 scoped_ptr<WaitingForTopLevelWindowInfo> waiting_for_top_level_window_info(
304 std::move(waiting_for_top_level_window_info_)); 302 std::move(waiting_for_top_level_window_info_));
305 connection_manager_->GetClientConnection(this) 303 client_connection_->SetIncomingMethodCallProcessingPaused(false);
306 ->SetIncomingMethodCallProcessingPaused(false);
307 // We were paused, so the id should still be valid. 304 // We were paused, so the id should still be valid.
308 DCHECK(IsValidIdForNewWindow( 305 DCHECK(IsValidIdForNewWindow(
309 waiting_for_top_level_window_info->client_window_id)); 306 waiting_for_top_level_window_info->client_window_id));
310 client_id_to_window_id_map_[waiting_for_top_level_window_info 307 client_id_to_window_id_map_[waiting_for_top_level_window_info
311 ->client_window_id] = window->id(); 308 ->client_window_id] = window->id();
312 window_id_to_client_id_map_[window->id()] = 309 window_id_to_client_id_map_[window->id()] =
313 waiting_for_top_level_window_info->client_window_id; 310 waiting_for_top_level_window_info->client_window_id;
314 roots_.insert(window); 311 roots_.insert(window);
315 client_->OnTopLevelCreated(client_change_id, WindowToWindowData(window)); 312 client()->OnTopLevelCreated(client_change_id, WindowToWindowData(window));
316 } 313 }
317 314
318 void WindowTreeImpl::OnChangeCompleted(uint32_t change_id, bool success) { 315 void WindowTreeImpl::OnChangeCompleted(uint32_t change_id, bool success) {
319 client_->OnChangeCompleted(change_id, success); 316 client()->OnChangeCompleted(change_id, success);
320 } 317 }
321 318
322 void WindowTreeImpl::OnAccelerator(uint32_t accelerator_id, 319 void WindowTreeImpl::OnAccelerator(uint32_t accelerator_id,
323 mojom::EventPtr event) { 320 mojom::EventPtr event) {
324 DCHECK(window_manager_internal_); 321 DCHECK(window_manager_internal_);
325 window_manager_internal_->OnAccelerator(accelerator_id, std::move(event)); 322 window_manager_internal_->OnAccelerator(accelerator_id, std::move(event));
326 } 323 }
327 324
328 void WindowTreeImpl::ProcessWindowBoundsChanged(const ServerWindow* window, 325 void WindowTreeImpl::ProcessWindowBoundsChanged(const ServerWindow* window,
329 const gfx::Rect& old_bounds, 326 const gfx::Rect& old_bounds,
330 const gfx::Rect& new_bounds, 327 const gfx::Rect& new_bounds,
331 bool originated_change) { 328 bool originated_change) {
332 ClientWindowId client_window_id; 329 ClientWindowId client_window_id;
333 if (originated_change || !IsWindowKnown(window, &client_window_id)) 330 if (originated_change || !IsWindowKnown(window, &client_window_id))
334 return; 331 return;
335 client_->OnWindowBoundsChanged(client_window_id.id, Rect::From(old_bounds), 332 client()->OnWindowBoundsChanged(client_window_id.id, Rect::From(old_bounds),
336 Rect::From(new_bounds)); 333 Rect::From(new_bounds));
337 } 334 }
338 335
339 void WindowTreeImpl::ProcessClientAreaChanged( 336 void WindowTreeImpl::ProcessClientAreaChanged(
340 const ServerWindow* window, 337 const ServerWindow* window,
341 const gfx::Insets& new_client_area, 338 const gfx::Insets& new_client_area,
342 const std::vector<gfx::Rect>& new_additional_client_areas, 339 const std::vector<gfx::Rect>& new_additional_client_areas,
343 bool originated_change) { 340 bool originated_change) {
344 ClientWindowId client_window_id; 341 ClientWindowId client_window_id;
345 if (originated_change || !IsWindowKnown(window, &client_window_id)) 342 if (originated_change || !IsWindowKnown(window, &client_window_id))
346 return; 343 return;
347 client_->OnClientAreaChanged( 344 client()->OnClientAreaChanged(
348 client_window_id.id, mojo::Insets::From(new_client_area), 345 client_window_id.id, mojo::Insets::From(new_client_area),
349 mojo::Array<mojo::RectPtr>::From(new_additional_client_areas)); 346 mojo::Array<mojo::RectPtr>::From(new_additional_client_areas));
350 } 347 }
351 348
352 void WindowTreeImpl::ProcessViewportMetricsChanged( 349 void WindowTreeImpl::ProcessViewportMetricsChanged(
353 WindowTreeHostImpl* host, 350 WindowTreeHostImpl* host,
354 const mojom::ViewportMetrics& old_metrics, 351 const mojom::ViewportMetrics& old_metrics,
355 const mojom::ViewportMetrics& new_metrics, 352 const mojom::ViewportMetrics& new_metrics,
356 bool originated_change) { 353 bool originated_change) {
357 mojo::Array<Id> window_ids; 354 mojo::Array<Id> window_ids;
358 for (const ServerWindow* root : roots_) { 355 for (const ServerWindow* root : roots_) {
359 if (GetHost(root) == host) { 356 if (GetHost(root) == host) {
360 ClientWindowId client_window_id; 357 ClientWindowId client_window_id;
361 const bool known = IsWindowKnown(root, &client_window_id); 358 const bool known = IsWindowKnown(root, &client_window_id);
362 DCHECK(known); 359 DCHECK(known);
363 window_ids.push_back(client_window_id.id); 360 window_ids.push_back(client_window_id.id);
364 } 361 }
365 } 362 }
366 if (window_ids.size() == 0u) 363 if (window_ids.size() == 0u)
367 return; 364 return;
368 365
369 client_->OnWindowViewportMetricsChanged( 366 client()->OnWindowViewportMetricsChanged(
370 std::move(window_ids), old_metrics.Clone(), new_metrics.Clone()); 367 std::move(window_ids), old_metrics.Clone(), new_metrics.Clone());
371 } 368 }
372 369
373 void WindowTreeImpl::ProcessWillChangeWindowHierarchy( 370 void WindowTreeImpl::ProcessWillChangeWindowHierarchy(
374 const ServerWindow* window, 371 const ServerWindow* window,
375 const ServerWindow* new_parent, 372 const ServerWindow* new_parent,
376 const ServerWindow* old_parent, 373 const ServerWindow* old_parent,
377 bool originated_change) { 374 bool originated_change) {
378 if (originated_change) 375 if (originated_change)
379 return; 376 return;
(...skipping 16 matching lines...) Expand all
396 return; 393 return;
397 394
398 ClientWindowId client_window_id; 395 ClientWindowId client_window_id;
399 if (!IsWindowKnown(window, &client_window_id)) 396 if (!IsWindowKnown(window, &client_window_id))
400 return; 397 return;
401 398
402 Array<uint8_t> data(nullptr); 399 Array<uint8_t> data(nullptr);
403 if (new_data) 400 if (new_data)
404 data = Array<uint8_t>::From(*new_data); 401 data = Array<uint8_t>::From(*new_data);
405 402
406 client_->OnWindowSharedPropertyChanged(client_window_id.id, String(name), 403 client()->OnWindowSharedPropertyChanged(client_window_id.id, String(name),
407 std::move(data)); 404 std::move(data));
408 } 405 }
409 406
410 void WindowTreeImpl::ProcessWindowHierarchyChanged( 407 void WindowTreeImpl::ProcessWindowHierarchyChanged(
411 const ServerWindow* window, 408 const ServerWindow* window,
412 const ServerWindow* new_parent, 409 const ServerWindow* new_parent,
413 const ServerWindow* old_parent, 410 const ServerWindow* old_parent,
414 bool originated_change) { 411 bool originated_change) {
415 const bool knows_new = new_parent && IsWindowKnown(new_parent); 412 const bool knows_new = new_parent && IsWindowKnown(new_parent);
416 if (originated_change && !IsWindowKnown(window) && knows_new) { 413 if (originated_change && !IsWindowKnown(window) && knows_new) {
417 std::vector<const ServerWindow*> unused; 414 std::vector<const ServerWindow*> unused;
(...skipping 18 matching lines...) Expand all
436 const bool knows_old = old_parent && IsWindowKnown(old_parent); 433 const bool knows_old = old_parent && IsWindowKnown(old_parent);
437 if (!knows_old && !knows_new) 434 if (!knows_old && !knows_new)
438 return; 435 return;
439 436
440 const ClientWindowId new_parent_client_window_id = 437 const ClientWindowId new_parent_client_window_id =
441 knows_new ? ClientWindowIdForWindow(new_parent) : ClientWindowId(); 438 knows_new ? ClientWindowIdForWindow(new_parent) : ClientWindowId();
442 const ClientWindowId old_parent_client_window_id = 439 const ClientWindowId old_parent_client_window_id =
443 knows_old ? ClientWindowIdForWindow(old_parent) : ClientWindowId(); 440 knows_old ? ClientWindowIdForWindow(old_parent) : ClientWindowId();
444 const ClientWindowId client_window_id = 441 const ClientWindowId client_window_id =
445 window ? ClientWindowIdForWindow(window) : ClientWindowId(); 442 window ? ClientWindowIdForWindow(window) : ClientWindowId();
446 client_->OnWindowHierarchyChanged( 443 client()->OnWindowHierarchyChanged(
447 client_window_id.id, new_parent_client_window_id.id, 444 client_window_id.id, new_parent_client_window_id.id,
448 old_parent_client_window_id.id, WindowsToWindowDatas(to_send)); 445 old_parent_client_window_id.id, WindowsToWindowDatas(to_send));
449 connection_manager_->OnConnectionMessagedClient(id_); 446 connection_manager_->OnConnectionMessagedClient(id_);
450 } 447 }
451 448
452 void WindowTreeImpl::ProcessWindowReorder(const ServerWindow* window, 449 void WindowTreeImpl::ProcessWindowReorder(const ServerWindow* window,
453 const ServerWindow* relative_window, 450 const ServerWindow* relative_window,
454 mojom::OrderDirection direction, 451 mojom::OrderDirection direction,
455 bool originated_change) { 452 bool originated_change) {
456 DCHECK_EQ(window->parent(), relative_window->parent()); 453 DCHECK_EQ(window->parent(), relative_window->parent());
457 ClientWindowId client_window_id, relative_client_window_id; 454 ClientWindowId client_window_id, relative_client_window_id;
458 if (originated_change || !IsWindowKnown(window, &client_window_id) || 455 if (originated_change || !IsWindowKnown(window, &client_window_id) ||
459 !IsWindowKnown(relative_window, &relative_client_window_id) || 456 !IsWindowKnown(relative_window, &relative_client_window_id) ||
460 connection_manager_->DidConnectionMessageClient(id_)) 457 connection_manager_->DidConnectionMessageClient(id_))
461 return; 458 return;
462 459
463 // Do not notify ordering changes of the root windows, since the client 460 // Do not notify ordering changes of the root windows, since the client
464 // doesn't know about the ancestors of the roots, and so can't do anything 461 // doesn't know about the ancestors of the roots, and so can't do anything
465 // about this ordering change of the root. 462 // about this ordering change of the root.
466 if (HasRoot(window) || HasRoot(relative_window)) 463 if (HasRoot(window) || HasRoot(relative_window))
467 return; 464 return;
468 465
469 client_->OnWindowReordered(client_window_id.id, relative_client_window_id.id, 466 client()->OnWindowReordered(client_window_id.id, relative_client_window_id.id,
470 direction); 467 direction);
471 connection_manager_->OnConnectionMessagedClient(id_); 468 connection_manager_->OnConnectionMessagedClient(id_);
472 } 469 }
473 470
474 void WindowTreeImpl::ProcessWindowDeleted(const ServerWindow* window, 471 void WindowTreeImpl::ProcessWindowDeleted(const ServerWindow* window,
475 bool originated_change) { 472 bool originated_change) {
476 if (window->id().connection_id == id_) 473 if (window->id().connection_id == id_)
477 created_window_map_.erase(window->id()); 474 created_window_map_.erase(window->id());
478 475
479 ClientWindowId client_window_id; 476 ClientWindowId client_window_id;
480 if (!IsWindowKnown(window, &client_window_id)) 477 if (!IsWindowKnown(window, &client_window_id))
481 return; 478 return;
482 479
483 if (HasRoot(window)) 480 if (HasRoot(window))
484 RemoveRoot(window, RemoveRootReason::DELETED); 481 RemoveRoot(window, RemoveRootReason::DELETED);
485 else 482 else
486 RemoveFromMaps(window); 483 RemoveFromMaps(window);
487 484
488 if (originated_change) 485 if (originated_change)
489 return; 486 return;
490 487
491 client_->OnWindowDeleted(client_window_id.id); 488 client()->OnWindowDeleted(client_window_id.id);
492 connection_manager_->OnConnectionMessagedClient(id_); 489 connection_manager_->OnConnectionMessagedClient(id_);
493 } 490 }
494 491
495 void WindowTreeImpl::ProcessWillChangeWindowVisibility( 492 void WindowTreeImpl::ProcessWillChangeWindowVisibility(
496 const ServerWindow* window, 493 const ServerWindow* window,
497 bool originated_change) { 494 bool originated_change) {
498 if (originated_change) 495 if (originated_change)
499 return; 496 return;
500 497
501 ClientWindowId client_window_id; 498 ClientWindowId client_window_id;
502 if (IsWindowKnown(window, &client_window_id)) { 499 if (IsWindowKnown(window, &client_window_id)) {
503 client_->OnWindowVisibilityChanged(client_window_id.id, !window->visible()); 500 client()->OnWindowVisibilityChanged(client_window_id.id,
501 !window->visible());
504 return; 502 return;
505 } 503 }
506 504
507 bool window_target_drawn_state; 505 bool window_target_drawn_state;
508 if (window->visible()) { 506 if (window->visible()) {
509 // Window is being hidden, won't be drawn. 507 // Window is being hidden, won't be drawn.
510 window_target_drawn_state = false; 508 window_target_drawn_state = false;
511 } else { 509 } else {
512 // Window is being shown. Window will be drawn if its parent is drawn. 510 // Window is being shown. Window will be drawn if its parent is drawn.
513 window_target_drawn_state = window->parent() && window->parent()->IsDrawn(); 511 window_target_drawn_state = window->parent() && window->parent()->IsDrawn();
514 } 512 }
515 513
516 NotifyDrawnStateChanged(window, window_target_drawn_state); 514 NotifyDrawnStateChanged(window, window_target_drawn_state);
517 } 515 }
518 516
519 void WindowTreeImpl::ProcessCursorChanged(const ServerWindow* window, 517 void WindowTreeImpl::ProcessCursorChanged(const ServerWindow* window,
520 int32_t cursor_id, 518 int32_t cursor_id,
521 bool originated_change) { 519 bool originated_change) {
522 if (originated_change) 520 if (originated_change)
523 return; 521 return;
524 ClientWindowId client_window_id; 522 ClientWindowId client_window_id;
525 if (!IsWindowKnown(window, &client_window_id)) 523 if (!IsWindowKnown(window, &client_window_id))
526 return; 524 return;
527 525
528 client_->OnWindowPredefinedCursorChanged(client_window_id.id, 526 client()->OnWindowPredefinedCursorChanged(client_window_id.id,
529 mojom::Cursor(cursor_id)); 527 mojom::Cursor(cursor_id));
530 } 528 }
531 529
532 void WindowTreeImpl::ProcessFocusChanged( 530 void WindowTreeImpl::ProcessFocusChanged(
533 const ServerWindow* old_focused_window, 531 const ServerWindow* old_focused_window,
534 const ServerWindow* new_focused_window) { 532 const ServerWindow* new_focused_window) {
535 const ServerWindow* window = 533 const ServerWindow* window =
536 new_focused_window 534 new_focused_window
537 ? access_policy_->GetWindowForFocusChange(new_focused_window) 535 ? access_policy_->GetWindowForFocusChange(new_focused_window)
538 : nullptr; 536 : nullptr;
539 ClientWindowId client_window_id; 537 ClientWindowId client_window_id;
540 // If the window isn't known we'll supply null, which is ok. 538 // If the window isn't known we'll supply null, which is ok.
541 IsWindowKnown(window, &client_window_id); 539 IsWindowKnown(window, &client_window_id);
542 // TODO(sky): this should only notify if this results in a change of focus 540 // TODO(sky): this should only notify if this results in a change of focus
543 // for the client. 541 // for the client.
544 client_->OnWindowFocused(client_window_id.id); 542 client()->OnWindowFocused(client_window_id.id);
545 } 543 }
546 544
547 void WindowTreeImpl::ProcessTransientWindowAdded( 545 void WindowTreeImpl::ProcessTransientWindowAdded(
548 const ServerWindow* window, 546 const ServerWindow* window,
549 const ServerWindow* transient_window, 547 const ServerWindow* transient_window,
550 bool originated_change) { 548 bool originated_change) {
551 if (originated_change) 549 if (originated_change)
552 return; 550 return;
553 551
554 ClientWindowId client_window_id, transient_client_window_id; 552 ClientWindowId client_window_id, transient_client_window_id;
555 if (!IsWindowKnown(window, &client_window_id) || 553 if (!IsWindowKnown(window, &client_window_id) ||
556 !IsWindowKnown(transient_window, &transient_client_window_id)) { 554 !IsWindowKnown(transient_window, &transient_client_window_id)) {
557 return; 555 return;
558 } 556 }
559 client_->OnTransientWindowAdded(client_window_id.id, 557 client()->OnTransientWindowAdded(client_window_id.id,
560 transient_client_window_id.id); 558 transient_client_window_id.id);
561 } 559 }
562 560
563 void WindowTreeImpl::ProcessTransientWindowRemoved( 561 void WindowTreeImpl::ProcessTransientWindowRemoved(
564 const ServerWindow* window, 562 const ServerWindow* window,
565 const ServerWindow* transient_window, 563 const ServerWindow* transient_window,
566 bool originated_change) { 564 bool originated_change) {
567 if (originated_change) 565 if (originated_change)
568 return; 566 return;
569 ClientWindowId client_window_id, transient_client_window_id; 567 ClientWindowId client_window_id, transient_client_window_id;
570 if (!IsWindowKnown(window, &client_window_id) || 568 if (!IsWindowKnown(window, &client_window_id) ||
571 !IsWindowKnown(transient_window, &transient_client_window_id)) { 569 !IsWindowKnown(transient_window, &transient_client_window_id)) {
572 return; 570 return;
573 } 571 }
574 client_->OnTransientWindowRemoved(client_window_id.id, 572 client()->OnTransientWindowRemoved(client_window_id.id,
575 transient_client_window_id.id); 573 transient_client_window_id.id);
576 } 574 }
577 575
578 WindowTreeHostImpl* WindowTreeImpl::GetHostForWindowManager() { 576 WindowTreeHostImpl* WindowTreeImpl::GetHostForWindowManager() {
579 // The WindowTreeImpl for the wm has one and only one root. 577 // The WindowTreeImpl for the wm has one and only one root.
580 CHECK_EQ(1u, roots_.size()); 578 CHECK_EQ(1u, roots_.size());
581 579
582 // Indicates this connection is for the wm. 580 // Indicates this connection is for the wm.
583 DCHECK(window_manager_internal_); 581 DCHECK(window_manager_internal_);
584 582
585 WindowTreeHostImpl* host = GetHost(*roots_.begin()); 583 WindowTreeHostImpl* host = GetHost(*roots_.begin());
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 DCHECK(roots_.count(window) > 0); 737 DCHECK(roots_.count(window) > 0);
740 roots_.erase(window); 738 roots_.erase(window);
741 739
742 const ClientWindowId client_window_id(ClientWindowIdForWindow(window)); 740 const ClientWindowId client_window_id(ClientWindowIdForWindow(window));
743 741
744 // No need to do anything if we created the window. 742 // No need to do anything if we created the window.
745 if (window->id().connection_id == id_) 743 if (window->id().connection_id == id_)
746 return; 744 return;
747 745
748 if (reason == RemoveRootReason::EMBED) { 746 if (reason == RemoveRootReason::EMBED) {
749 client_->OnUnembed(client_window_id.id); 747 client()->OnUnembed(client_window_id.id);
750 client_->OnWindowDeleted(client_window_id.id); 748 client()->OnWindowDeleted(client_window_id.id);
751 connection_manager_->OnConnectionMessagedClient(id_); 749 connection_manager_->OnConnectionMessagedClient(id_);
752 } 750 }
753 751
754 // This connection no longer knows about the window. Unparent any windows that 752 // This connection no longer knows about the window. Unparent any windows that
755 // were parented to windows in the root. 753 // were parented to windows in the root.
756 std::vector<ServerWindow*> local_windows; 754 std::vector<ServerWindow*> local_windows;
757 RemoveFromKnown(window, &local_windows); 755 RemoveFromKnown(window, &local_windows);
758 for (size_t i = 0; i < local_windows.size(); ++i) 756 for (size_t i = 0; i < local_windows.size(); ++i)
759 local_windows[i]->parent()->Remove(local_windows[i]); 757 local_windows[i]->parent()->Remove(local_windows[i]);
760 } 758 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 808
811 void WindowTreeImpl::NotifyDrawnStateChanged(const ServerWindow* window, 809 void WindowTreeImpl::NotifyDrawnStateChanged(const ServerWindow* window,
812 bool new_drawn_value) { 810 bool new_drawn_value) {
813 // Even though we don't know about window, it may be an ancestor of our root, 811 // Even though we don't know about window, it may be an ancestor of our root,
814 // in which case the change may effect our roots drawn state. 812 // in which case the change may effect our roots drawn state.
815 if (roots_.empty()) 813 if (roots_.empty())
816 return; 814 return;
817 815
818 for (auto* root : roots_) { 816 for (auto* root : roots_) {
819 if (window->Contains(root) && (new_drawn_value != root->IsDrawn())) { 817 if (window->Contains(root) && (new_drawn_value != root->IsDrawn())) {
820 client_->OnWindowDrawnStateChanged(ClientWindowIdForWindow(root).id, 818 client()->OnWindowDrawnStateChanged(ClientWindowIdForWindow(root).id,
821 new_drawn_value); 819 new_drawn_value);
822 } 820 }
823 } 821 }
824 } 822 }
825 823
826 void WindowTreeImpl::DestroyWindows() { 824 void WindowTreeImpl::DestroyWindows() {
827 if (created_window_map_.empty()) 825 if (created_window_map_.empty())
828 return; 826 return;
829 827
830 Operation op(this, connection_manager_, OperationType::DELETE_WINDOW); 828 Operation op(this, connection_manager_, OperationType::DELETE_WINDOW);
831 // If we get here from the destructor we're not going to get 829 // If we get here from the destructor we're not going to get
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 mojom::EventPtr event) { 874 mojom::EventPtr event) {
877 DCHECK(!event_ack_id_); 875 DCHECK(!event_ack_id_);
878 // We do not want to create a sequential id for each event, because that can 876 // We do not want to create a sequential id for each event, because that can
879 // leak some information to the client. So instead, manufacture the id from 877 // leak some information to the client. So instead, manufacture the id from
880 // the event pointer. 878 // the event pointer.
881 event_ack_id_ = 879 event_ack_id_ =
882 0x1000000 | (reinterpret_cast<uintptr_t>(event.get()) & 0xffffff); 880 0x1000000 | (reinterpret_cast<uintptr_t>(event.get()) & 0xffffff);
883 event_source_host_ = GetHost(target); 881 event_source_host_ = GetHost(target);
884 // Should only get events from windows attached to a host. 882 // Should only get events from windows attached to a host.
885 DCHECK(event_source_host_); 883 DCHECK(event_source_host_);
886 client_->OnWindowInputEvent(event_ack_id_, ClientWindowIdForWindow(target).id, 884 client()->OnWindowInputEvent(
887 std::move(event)); 885 event_ack_id_, ClientWindowIdForWindow(target).id, std::move(event));
888 } 886 }
889 887
890 void WindowTreeImpl::NewWindow( 888 void WindowTreeImpl::NewWindow(
891 uint32_t change_id, 889 uint32_t change_id,
892 Id transport_window_id, 890 Id transport_window_id,
893 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 891 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
894 std::map<std::string, std::vector<uint8_t>> properties; 892 std::map<std::string, std::vector<uint8_t>> properties;
895 if (!transport_properties.is_null()) { 893 if (!transport_properties.is_null()) {
896 properties = 894 properties =
897 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 895 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
898 } 896 }
899 client_->OnChangeCompleted( 897 client()->OnChangeCompleted(
900 change_id, NewWindow(ClientWindowId(transport_window_id), properties)); 898 change_id, NewWindow(ClientWindowId(transport_window_id), properties));
901 } 899 }
902 900
903 void WindowTreeImpl::NewTopLevelWindow( 901 void WindowTreeImpl::NewTopLevelWindow(
904 uint32_t change_id, 902 uint32_t change_id,
905 Id transport_window_id, 903 Id transport_window_id,
906 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 904 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
907 DCHECK(!waiting_for_top_level_window_info_); 905 DCHECK(!waiting_for_top_level_window_info_);
908 const ClientWindowId client_window_id(transport_window_id); 906 const ClientWindowId client_window_id(transport_window_id);
909 WindowTreeHostImpl* tree_host = 907 WindowTreeHostImpl* tree_host =
910 connection_manager_->GetActiveWindowTreeHost(); 908 connection_manager_->GetActiveWindowTreeHost();
911 // TODO(sky): need a way for client to provide context. 909 // TODO(sky): need a way for client to provide context.
912 WindowManagerState* wms = 910 WindowManagerState* wms =
913 tree_host ? tree_host->GetFirstWindowManagerState() : nullptr; 911 tree_host ? tree_host->GetFirstWindowManagerState() : nullptr;
914 if (!wms || wms->tree() == this || !IsValidIdForNewWindow(client_window_id)) { 912 if (!wms || wms->tree() == this || !IsValidIdForNewWindow(client_window_id)) {
915 client_->OnChangeCompleted(change_id, false); 913 client()->OnChangeCompleted(change_id, false);
916 return; 914 return;
917 } 915 }
918 916
919 // The server creates the real window. Any further messages from the client 917 // The server creates the real window. Any further messages from the client
920 // may try to alter the window. Pause incoming messages so that we know we 918 // may try to alter the window. Pause incoming messages so that we know we
921 // can't get a message for a window before the window is created. Once the 919 // can't get a message for a window before the window is created. Once the
922 // window is created we'll resume processing. 920 // window is created we'll resume processing.
923 connection_manager_->GetClientConnection(this) 921 client_connection_->SetIncomingMethodCallProcessingPaused(true);
924 ->SetIncomingMethodCallProcessingPaused(true);
925 922
926 const uint32_t wm_change_id = 923 const uint32_t wm_change_id =
927 connection_manager_->GenerateWindowManagerChangeId(this, change_id); 924 connection_manager_->GenerateWindowManagerChangeId(this, change_id);
928 925
929 waiting_for_top_level_window_info_.reset( 926 waiting_for_top_level_window_info_.reset(
930 new WaitingForTopLevelWindowInfo(client_window_id, wm_change_id)); 927 new WaitingForTopLevelWindowInfo(client_window_id, wm_change_id));
931 928
932 wms->tree()->window_manager_internal_->WmCreateTopLevelWindow( 929 wms->tree()->window_manager_internal_->WmCreateTopLevelWindow(
933 wm_change_id, std::move(transport_properties)); 930 wm_change_id, std::move(transport_properties));
934 } 931 }
935 932
936 void WindowTreeImpl::DeleteWindow(uint32_t change_id, Id transport_window_id) { 933 void WindowTreeImpl::DeleteWindow(uint32_t change_id, Id transport_window_id) {
937 ServerWindow* window = 934 ServerWindow* window =
938 GetWindowByClientId(ClientWindowId(transport_window_id)); 935 GetWindowByClientId(ClientWindowId(transport_window_id));
939 bool success = false; 936 bool success = false;
940 bool should_close = window && (access_policy_->CanDeleteWindow(window) || 937 bool should_close = window && (access_policy_->CanDeleteWindow(window) ||
941 ShouldRouteToWindowManager(window)); 938 ShouldRouteToWindowManager(window));
942 if (should_close) { 939 if (should_close) {
943 WindowTreeImpl* connection = 940 WindowTreeImpl* connection =
944 connection_manager_->GetConnection(window->id().connection_id); 941 connection_manager_->GetConnection(window->id().connection_id);
945 success = connection && connection->DeleteWindowImpl(this, window); 942 success = connection && connection->DeleteWindowImpl(this, window);
946 } 943 }
947 client_->OnChangeCompleted(change_id, success); 944 client()->OnChangeCompleted(change_id, success);
948 } 945 }
949 946
950 void WindowTreeImpl::AddWindow(uint32_t change_id, Id parent_id, Id child_id) { 947 void WindowTreeImpl::AddWindow(uint32_t change_id, Id parent_id, Id child_id) {
951 client_->OnChangeCompleted(change_id, AddWindow(ClientWindowId(parent_id), 948 client()->OnChangeCompleted(change_id, AddWindow(ClientWindowId(parent_id),
952 ClientWindowId(child_id))); 949 ClientWindowId(child_id)));
953 } 950 }
954 951
955 void WindowTreeImpl::RemoveWindowFromParent(uint32_t change_id, Id window_id) { 952 void WindowTreeImpl::RemoveWindowFromParent(uint32_t change_id, Id window_id) {
956 bool success = false; 953 bool success = false;
957 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 954 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
958 if (window && window->parent() && 955 if (window && window->parent() &&
959 access_policy_->CanRemoveWindowFromParent(window)) { 956 access_policy_->CanRemoveWindowFromParent(window)) {
960 success = true; 957 success = true;
961 Operation op(this, connection_manager_, 958 Operation op(this, connection_manager_,
962 OperationType::REMOVE_WINDOW_FROM_PARENT); 959 OperationType::REMOVE_WINDOW_FROM_PARENT);
963 window->parent()->Remove(window); 960 window->parent()->Remove(window);
964 } 961 }
965 client_->OnChangeCompleted(change_id, success); 962 client()->OnChangeCompleted(change_id, success);
966 } 963 }
967 964
968 void WindowTreeImpl::AddTransientWindow(uint32_t change_id, 965 void WindowTreeImpl::AddTransientWindow(uint32_t change_id,
969 Id window, 966 Id window,
970 Id transient_window) { 967 Id transient_window) {
971 client_->OnChangeCompleted( 968 client()->OnChangeCompleted(
972 change_id, AddTransientWindow(ClientWindowId(window), 969 change_id, AddTransientWindow(ClientWindowId(window),
973 ClientWindowId(transient_window))); 970 ClientWindowId(transient_window)));
974 } 971 }
975 972
976 void WindowTreeImpl::RemoveTransientWindowFromParent(uint32_t change_id, 973 void WindowTreeImpl::RemoveTransientWindowFromParent(uint32_t change_id,
977 Id transient_window_id) { 974 Id transient_window_id) {
978 bool success = false; 975 bool success = false;
979 ServerWindow* transient_window = 976 ServerWindow* transient_window =
980 GetWindowByClientId(ClientWindowId(transient_window_id)); 977 GetWindowByClientId(ClientWindowId(transient_window_id));
981 if (transient_window && transient_window->transient_parent() && 978 if (transient_window && transient_window->transient_parent() &&
982 access_policy_->CanRemoveTransientWindowFromParent(transient_window)) { 979 access_policy_->CanRemoveTransientWindowFromParent(transient_window)) {
983 success = true; 980 success = true;
984 Operation op(this, connection_manager_, 981 Operation op(this, connection_manager_,
985 OperationType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT); 982 OperationType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT);
986 transient_window->transient_parent()->RemoveTransientWindow( 983 transient_window->transient_parent()->RemoveTransientWindow(
987 transient_window); 984 transient_window);
988 } 985 }
989 client_->OnChangeCompleted(change_id, success); 986 client()->OnChangeCompleted(change_id, success);
990 } 987 }
991 988
992 void WindowTreeImpl::ReorderWindow(uint32_t change_id, 989 void WindowTreeImpl::ReorderWindow(uint32_t change_id,
993 Id window_id, 990 Id window_id,
994 Id relative_window_id, 991 Id relative_window_id,
995 mojom::OrderDirection direction) { 992 mojom::OrderDirection direction) {
996 bool success = false; 993 bool success = false;
997 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 994 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
998 ServerWindow* relative_window = 995 ServerWindow* relative_window =
999 GetWindowByClientId(ClientWindowId(relative_window_id)); 996 GetWindowByClientId(ClientWindowId(relative_window_id));
1000 if (CanReorderWindow(window, relative_window, direction)) { 997 if (CanReorderWindow(window, relative_window, direction)) {
1001 success = true; 998 success = true;
1002 Operation op(this, connection_manager_, OperationType::REORDER_WINDOW); 999 Operation op(this, connection_manager_, OperationType::REORDER_WINDOW);
1003 window->Reorder(relative_window, direction); 1000 window->Reorder(relative_window, direction);
1004 connection_manager_->ProcessWindowReorder(window, relative_window, 1001 connection_manager_->ProcessWindowReorder(window, relative_window,
1005 direction); 1002 direction);
1006 } 1003 }
1007 client_->OnChangeCompleted(change_id, success); 1004 client()->OnChangeCompleted(change_id, success);
1008 } 1005 }
1009 1006
1010 void WindowTreeImpl::GetWindowTree( 1007 void WindowTreeImpl::GetWindowTree(
1011 Id window_id, 1008 Id window_id,
1012 const Callback<void(Array<mojom::WindowDataPtr>)>& callback) { 1009 const Callback<void(Array<mojom::WindowDataPtr>)>& callback) {
1013 std::vector<const ServerWindow*> windows( 1010 std::vector<const ServerWindow*> windows(
1014 GetWindowTree(ClientWindowId(window_id))); 1011 GetWindowTree(ClientWindowId(window_id)));
1015 callback.Run(WindowsToWindowDatas(windows)); 1012 callback.Run(WindowsToWindowDatas(windows));
1016 } 1013 }
1017 1014
1018 void WindowTreeImpl::SetCapture(uint32_t change_id, Id window_id) { 1015 void WindowTreeImpl::SetCapture(uint32_t change_id, Id window_id) {
1019 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1016 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1020 WindowTreeHostImpl* host = GetHost(window); 1017 WindowTreeHostImpl* host = GetHost(window);
1021 ServerWindow* current_capture_window = 1018 ServerWindow* current_capture_window =
1022 host ? host->GetCaptureWindow() : nullptr; 1019 host ? host->GetCaptureWindow() : nullptr;
1023 bool success = window && access_policy_->CanSetCapture(window) && host && 1020 bool success = window && access_policy_->CanSetCapture(window) && host &&
1024 (!current_capture_window || 1021 (!current_capture_window ||
1025 access_policy_->CanSetCapture(current_capture_window)) && 1022 access_policy_->CanSetCapture(current_capture_window)) &&
1026 event_ack_id_; 1023 event_ack_id_;
1027 if (success) { 1024 if (success) {
1028 Operation op(this, connection_manager_, OperationType::SET_CAPTURE); 1025 Operation op(this, connection_manager_, OperationType::SET_CAPTURE);
1029 host->SetCapture(window, !HasRoot(window)); 1026 host->SetCapture(window, !HasRoot(window));
1030 } 1027 }
1031 client_->OnChangeCompleted(change_id, success); 1028 client()->OnChangeCompleted(change_id, success);
1032 } 1029 }
1033 1030
1034 void WindowTreeImpl::ReleaseCapture(uint32_t change_id, Id window_id) { 1031 void WindowTreeImpl::ReleaseCapture(uint32_t change_id, Id window_id) {
1035 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1032 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1036 WindowTreeHostImpl* host = GetHost(window); 1033 WindowTreeHostImpl* host = GetHost(window);
1037 ServerWindow* current_capture_window = 1034 ServerWindow* current_capture_window =
1038 host ? host->GetCaptureWindow() : nullptr; 1035 host ? host->GetCaptureWindow() : nullptr;
1039 bool success = window && host && 1036 bool success = window && host &&
1040 (!current_capture_window || 1037 (!current_capture_window ||
1041 access_policy_->CanSetCapture(current_capture_window)) && 1038 access_policy_->CanSetCapture(current_capture_window)) &&
1042 window == current_capture_window; 1039 window == current_capture_window;
1043 if (success) { 1040 if (success) {
1044 Operation op(this, connection_manager_, OperationType::RELEASE_CAPTURE); 1041 Operation op(this, connection_manager_, OperationType::RELEASE_CAPTURE);
1045 host->SetCapture(nullptr, false); 1042 host->SetCapture(nullptr, false);
1046 } 1043 }
1047 client_->OnChangeCompleted(change_id, success); 1044 client()->OnChangeCompleted(change_id, success);
1048 } 1045 }
1049 1046
1050 void WindowTreeImpl::SetWindowBounds(uint32_t change_id, 1047 void WindowTreeImpl::SetWindowBounds(uint32_t change_id,
1051 Id window_id, 1048 Id window_id,
1052 mojo::RectPtr bounds) { 1049 mojo::RectPtr bounds) {
1053 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1050 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1054 if (window && ShouldRouteToWindowManager(window)) { 1051 if (window && ShouldRouteToWindowManager(window)) {
1055 const uint32_t wm_change_id = 1052 const uint32_t wm_change_id =
1056 connection_manager_->GenerateWindowManagerChangeId(this, change_id); 1053 connection_manager_->GenerateWindowManagerChangeId(this, change_id);
1057 // |window_id| may be a client id, use the id from the window to ensure 1054 // |window_id| may be a client id, use the id from the window to ensure
1058 // the windowmanager doesn't get an id it doesn't know about. 1055 // the windowmanager doesn't get an id it doesn't know about.
1059 WindowManagerState* wms = 1056 WindowManagerState* wms =
1060 connection_manager_->GetWindowManagerAndHost(window) 1057 connection_manager_->GetWindowManagerAndHost(window)
1061 .window_manager_state; 1058 .window_manager_state;
1062 wms->tree()->window_manager_internal_->WmSetBounds( 1059 wms->tree()->window_manager_internal_->WmSetBounds(
1063 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id, 1060 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id,
1064 std::move(bounds)); 1061 std::move(bounds));
1065 return; 1062 return;
1066 } 1063 }
1067 1064
1068 // Only the owner of the window can change the bounds. 1065 // Only the owner of the window can change the bounds.
1069 bool success = window && access_policy_->CanSetWindowBounds(window); 1066 bool success = window && access_policy_->CanSetWindowBounds(window);
1070 if (success) { 1067 if (success) {
1071 Operation op(this, connection_manager_, OperationType::SET_WINDOW_BOUNDS); 1068 Operation op(this, connection_manager_, OperationType::SET_WINDOW_BOUNDS);
1072 window->SetBounds(bounds.To<gfx::Rect>()); 1069 window->SetBounds(bounds.To<gfx::Rect>());
1073 } 1070 }
1074 client_->OnChangeCompleted(change_id, success); 1071 client()->OnChangeCompleted(change_id, success);
1075 } 1072 }
1076 1073
1077 void WindowTreeImpl::SetWindowVisibility(uint32_t change_id, 1074 void WindowTreeImpl::SetWindowVisibility(uint32_t change_id,
1078 Id transport_window_id, 1075 Id transport_window_id,
1079 bool visible) { 1076 bool visible) {
1080 client_->OnChangeCompleted( 1077 client()->OnChangeCompleted(
1081 change_id, 1078 change_id,
1082 SetWindowVisibility(ClientWindowId(transport_window_id), visible)); 1079 SetWindowVisibility(ClientWindowId(transport_window_id), visible));
1083 } 1080 }
1084 1081
1085 void WindowTreeImpl::SetWindowProperty(uint32_t change_id, 1082 void WindowTreeImpl::SetWindowProperty(uint32_t change_id,
1086 Id transport_window_id, 1083 Id transport_window_id,
1087 const mojo::String& name, 1084 const mojo::String& name,
1088 mojo::Array<uint8_t> value) { 1085 mojo::Array<uint8_t> value) {
1089 ServerWindow* window = 1086 ServerWindow* window =
1090 GetWindowByClientId(ClientWindowId(transport_window_id)); 1087 GetWindowByClientId(ClientWindowId(transport_window_id));
(...skipping 11 matching lines...) Expand all
1102 const bool success = window && access_policy_->CanSetWindowProperties(window); 1099 const bool success = window && access_policy_->CanSetWindowProperties(window);
1103 if (success) { 1100 if (success) {
1104 Operation op(this, connection_manager_, OperationType::SET_WINDOW_PROPERTY); 1101 Operation op(this, connection_manager_, OperationType::SET_WINDOW_PROPERTY);
1105 if (value.is_null()) { 1102 if (value.is_null()) {
1106 window->SetProperty(name, nullptr); 1103 window->SetProperty(name, nullptr);
1107 } else { 1104 } else {
1108 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); 1105 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>();
1109 window->SetProperty(name, &data); 1106 window->SetProperty(name, &data);
1110 } 1107 }
1111 } 1108 }
1112 client_->OnChangeCompleted(change_id, success); 1109 client()->OnChangeCompleted(change_id, success);
1113 } 1110 }
1114 1111
1115 void WindowTreeImpl::AttachSurface( 1112 void WindowTreeImpl::AttachSurface(
1116 Id transport_window_id, 1113 Id transport_window_id,
1117 mojom::SurfaceType type, 1114 mojom::SurfaceType type,
1118 mojo::InterfaceRequest<mojom::Surface> surface, 1115 mojo::InterfaceRequest<mojom::Surface> surface,
1119 mojom::SurfaceClientPtr client) { 1116 mojom::SurfaceClientPtr client) {
1120 ServerWindow* window = 1117 ServerWindow* window =
1121 GetWindowByClientId(ClientWindowId(transport_window_id)); 1118 GetWindowByClientId(ClientWindowId(transport_window_id));
1122 const bool success = 1119 const bool success =
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 // FocusController. 1207 // FocusController.
1211 // TODO(sky): this doesn't work to clear focus. That is because if window is 1208 // TODO(sky): this doesn't work to clear focus. That is because if window is
1212 // null, then |host| is null and we fail. 1209 // null, then |host| is null and we fail.
1213 WindowTreeHostImpl* host = GetHost(window); 1210 WindowTreeHostImpl* host = GetHost(window);
1214 const bool success = window && window->IsDrawn() && window->can_focus() && 1211 const bool success = window && window->IsDrawn() && window->can_focus() &&
1215 access_policy_->CanSetFocus(window) && host; 1212 access_policy_->CanSetFocus(window) && host;
1216 if (success) { 1213 if (success) {
1217 Operation op(this, connection_manager_, OperationType::SET_FOCUS); 1214 Operation op(this, connection_manager_, OperationType::SET_FOCUS);
1218 host->SetFocusedWindow(window); 1215 host->SetFocusedWindow(window);
1219 } 1216 }
1220 client_->OnChangeCompleted(change_id, success); 1217 client()->OnChangeCompleted(change_id, success);
1221 } 1218 }
1222 1219
1223 void WindowTreeImpl::SetCanFocus(Id transport_window_id, bool can_focus) { 1220 void WindowTreeImpl::SetCanFocus(Id transport_window_id, bool can_focus) {
1224 ServerWindow* window = 1221 ServerWindow* window =
1225 GetWindowByClientId(ClientWindowId(transport_window_id)); 1222 GetWindowByClientId(ClientWindowId(transport_window_id));
1226 // TODO(sky): there should be an else case (it shouldn't route to wm and 1223 // TODO(sky): there should be an else case (it shouldn't route to wm and
1227 // policy allows, then set_can_focus). 1224 // policy allows, then set_can_focus).
1228 if (window && ShouldRouteToWindowManager(window)) 1225 if (window && ShouldRouteToWindowManager(window))
1229 window->set_can_focus(can_focus); 1226 window->set_can_focus(can_focus);
1230 } 1227 }
1231 1228
1232 void WindowTreeImpl::SetPredefinedCursor(uint32_t change_id, 1229 void WindowTreeImpl::SetPredefinedCursor(uint32_t change_id,
1233 Id transport_window_id, 1230 Id transport_window_id,
1234 mus::mojom::Cursor cursor_id) { 1231 mus::mojom::Cursor cursor_id) {
1235 ServerWindow* window = 1232 ServerWindow* window =
1236 GetWindowByClientId(ClientWindowId(transport_window_id)); 1233 GetWindowByClientId(ClientWindowId(transport_window_id));
1237 1234
1238 // Only the owner of the window can change the bounds. 1235 // Only the owner of the window can change the bounds.
1239 bool success = window && access_policy_->CanSetCursorProperties(window); 1236 bool success = window && access_policy_->CanSetCursorProperties(window);
1240 if (success) { 1237 if (success) {
1241 Operation op(this, connection_manager_, 1238 Operation op(this, connection_manager_,
1242 OperationType::SET_WINDOW_PREDEFINED_CURSOR); 1239 OperationType::SET_WINDOW_PREDEFINED_CURSOR);
1243 window->SetPredefinedCursor(cursor_id); 1240 window->SetPredefinedCursor(cursor_id);
1244 } 1241 }
1245 client_->OnChangeCompleted(change_id, success); 1242 client()->OnChangeCompleted(change_id, success);
1246 } 1243 }
1247 1244
1248 void WindowTreeImpl::GetWindowManagerClient( 1245 void WindowTreeImpl::GetWindowManagerClient(
1249 mojo::AssociatedInterfaceRequest<mojom::WindowManagerClient> internal) { 1246 mojo::AssociatedInterfaceRequest<mojom::WindowManagerClient> internal) {
1250 if (!access_policy_->CanSetWindowManager() || !window_manager_internal_ || 1247 if (!access_policy_->CanSetWindowManager() || !window_manager_internal_ ||
1251 window_manager_internal_client_binding_) { 1248 window_manager_internal_client_binding_) {
1252 return; 1249 return;
1253 } 1250 }
1254 window_manager_internal_client_binding_.reset( 1251 window_manager_internal_client_binding_.reset(
1255 new mojo::AssociatedBinding<mojom::WindowManagerClient>( 1252 new mojo::AssociatedBinding<mojom::WindowManagerClient>(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 // Only the WindowManager should be using this. 1320 // Only the WindowManager should be using this.
1324 WindowTreeHostImpl* host = GetHostForWindowManager(); 1321 WindowTreeHostImpl* host = GetHostForWindowManager();
1325 if (!host) 1322 if (!host)
1326 return; 1323 return;
1327 1324
1328 ServerWindow* window = 1325 ServerWindow* window =
1329 GetWindowByClientId(ClientWindowId(transport_window_id)); 1326 GetWindowByClientId(ClientWindowId(transport_window_id));
1330 WindowTreeImpl* connection = 1327 WindowTreeImpl* connection =
1331 connection_manager_->GetConnectionWithRoot(window); 1328 connection_manager_->GetConnectionWithRoot(window);
1332 if (connection && connection != this) { 1329 if (connection && connection != this) {
1333 connection->client_->RequestClose( 1330 connection->client()->RequestClose(
1334 connection->ClientWindowIdForWindow(window).id); 1331 connection->ClientWindowIdForWindow(window).id);
1335 } 1332 }
1336 // TODO(sky): think about what else case means. 1333 // TODO(sky): think about what else case means.
1337 } 1334 }
1338 1335
1339 void WindowTreeImpl::WmSetFrameDecorationValues( 1336 void WindowTreeImpl::WmSetFrameDecorationValues(
1340 mojom::FrameDecorationValuesPtr values) { 1337 mojom::FrameDecorationValuesPtr values) {
1341 if (GetHostForWindowManager()) 1338 if (GetHostForWindowManager())
1342 GetHostForWindowManager()->SetFrameDecorationValues(std::move(values)); 1339 GetHostForWindowManager()->SetFrameDecorationValues(std::move(values));
1343 } 1340 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 1376
1380 for (const auto* root : roots_) { 1377 for (const auto* root : roots_) {
1381 if (root->Contains(window)) 1378 if (root->Contains(window))
1382 return true; 1379 return true;
1383 } 1380 }
1384 return false; 1381 return false;
1385 } 1382 }
1386 1383
1387 } // namespace ws 1384 } // namespace ws
1388 } // namespace mus 1385 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_tree_impl.h ('k') | components/mus/ws/window_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698