| 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.h" | 5 #include "components/mus/ws/window_tree.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
| 12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 13 #include "components/mus/ws/default_access_policy.h" | 15 #include "components/mus/ws/default_access_policy.h" |
| 14 #include "components/mus/ws/display.h" | 16 #include "components/mus/ws/display.h" |
| 15 #include "components/mus/ws/display_manager.h" | 17 #include "components/mus/ws/display_manager.h" |
| 16 #include "components/mus/ws/focus_controller.h" | 18 #include "components/mus/ws/focus_controller.h" |
| 17 #include "components/mus/ws/operation.h" | 19 #include "components/mus/ws/operation.h" |
| 18 #include "components/mus/ws/platform_display.h" | 20 #include "components/mus/ws/platform_display.h" |
| 19 #include "components/mus/ws/server_window.h" | 21 #include "components/mus/ws/server_window.h" |
| 20 #include "components/mus/ws/server_window_observer.h" | 22 #include "components/mus/ws/server_window_observer.h" |
| 21 #include "components/mus/ws/window_manager_state.h" | 23 #include "components/mus/ws/window_manager_state.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 TargetedEvent(ServerWindow* target, const ui::Event& event) | 43 TargetedEvent(ServerWindow* target, const ui::Event& event) |
| 42 : target_(target), event_(ui::Event::Clone(event)) { | 44 : target_(target), event_(ui::Event::Clone(event)) { |
| 43 target_->AddObserver(this); | 45 target_->AddObserver(this); |
| 44 } | 46 } |
| 45 ~TargetedEvent() override { | 47 ~TargetedEvent() override { |
| 46 if (target_) | 48 if (target_) |
| 47 target_->RemoveObserver(this); | 49 target_->RemoveObserver(this); |
| 48 } | 50 } |
| 49 | 51 |
| 50 ServerWindow* target() { return target_; } | 52 ServerWindow* target() { return target_; } |
| 51 scoped_ptr<ui::Event> TakeEvent() { return std::move(event_); } | 53 std::unique_ptr<ui::Event> TakeEvent() { return std::move(event_); } |
| 52 | 54 |
| 53 private: | 55 private: |
| 54 // ServerWindowObserver: | 56 // ServerWindowObserver: |
| 55 void OnWindowDestroyed(ServerWindow* window) override { | 57 void OnWindowDestroyed(ServerWindow* window) override { |
| 56 DCHECK_EQ(target_, window); | 58 DCHECK_EQ(target_, window); |
| 57 target_->RemoveObserver(this); | 59 target_->RemoveObserver(this); |
| 58 target_ = nullptr; | 60 target_ = nullptr; |
| 59 } | 61 } |
| 60 | 62 |
| 61 ServerWindow* target_; | 63 ServerWindow* target_; |
| 62 scoped_ptr<ui::Event> event_; | 64 std::unique_ptr<ui::Event> event_; |
| 63 | 65 |
| 64 DISALLOW_COPY_AND_ASSIGN(TargetedEvent); | 66 DISALLOW_COPY_AND_ASSIGN(TargetedEvent); |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 WindowTree::WindowTree(WindowServer* window_server, | 69 WindowTree::WindowTree(WindowServer* window_server, |
| 68 const UserId& user_id, | 70 const UserId& user_id, |
| 69 ServerWindow* root, | 71 ServerWindow* root, |
| 70 scoped_ptr<AccessPolicy> access_policy) | 72 std::unique_ptr<AccessPolicy> access_policy) |
| 71 : window_server_(window_server), | 73 : window_server_(window_server), |
| 72 user_id_(user_id), | 74 user_id_(user_id), |
| 73 id_(window_server_->GetAndAdvanceNextConnectionId()), | 75 id_(window_server_->GetAndAdvanceNextConnectionId()), |
| 74 next_window_id_(1), | 76 next_window_id_(1), |
| 75 access_policy_(std::move(access_policy)), | 77 access_policy_(std::move(access_policy)), |
| 76 event_ack_id_(0), | 78 event_ack_id_(0), |
| 77 window_manager_internal_(nullptr) { | 79 window_manager_internal_(nullptr) { |
| 78 if (root) | 80 if (root) |
| 79 roots_.insert(root); | 81 roots_.insert(root); |
| 80 access_policy_->Init(id_, this); | 82 access_policy_->Init(id_, this); |
| 81 } | 83 } |
| 82 | 84 |
| 83 WindowTree::~WindowTree() { | 85 WindowTree::~WindowTree() { |
| 84 DestroyWindows(); | 86 DestroyWindows(); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void WindowTree::Init(scoped_ptr<WindowTreeBinding> binding, | 89 void WindowTree::Init(std::unique_ptr<WindowTreeBinding> binding, |
| 88 mojom::WindowTreePtr tree) { | 90 mojom::WindowTreePtr tree) { |
| 89 DCHECK(!binding_); | 91 DCHECK(!binding_); |
| 90 binding_ = std::move(binding); | 92 binding_ = std::move(binding); |
| 91 | 93 |
| 92 if (roots_.empty()) | 94 if (roots_.empty()) |
| 93 return; | 95 return; |
| 94 | 96 |
| 95 std::vector<const ServerWindow*> to_send; | 97 std::vector<const ServerWindow*> to_send; |
| 96 CHECK_EQ(1u, roots_.size()); | 98 CHECK_EQ(1u, roots_.size()); |
| 97 const ServerWindow* root = *roots_.begin(); | 99 const ServerWindow* root = *roots_.begin(); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 302 |
| 301 bool WindowTree::Embed(const ClientWindowId& window_id, | 303 bool WindowTree::Embed(const ClientWindowId& window_id, |
| 302 mojom::WindowTreeClientPtr client) { | 304 mojom::WindowTreeClientPtr client) { |
| 303 if (!client || !CanEmbed(window_id)) | 305 if (!client || !CanEmbed(window_id)) |
| 304 return false; | 306 return false; |
| 305 ServerWindow* window = GetWindowByClientId(window_id); | 307 ServerWindow* window = GetWindowByClientId(window_id); |
| 306 PrepareForEmbed(window); | 308 PrepareForEmbed(window); |
| 307 // When embedding we don't know the user id of where the TreeClient came | 309 // When embedding we don't know the user id of where the TreeClient came |
| 308 // from. Use an invalid id, which limits what the client is able to do. | 310 // from. Use an invalid id, which limits what the client is able to do. |
| 309 window_server_->EmbedAtWindow(window, InvalidUserId(), std::move(client), | 311 window_server_->EmbedAtWindow(window, InvalidUserId(), std::move(client), |
| 310 make_scoped_ptr(new DefaultAccessPolicy)); | 312 base::WrapUnique(new DefaultAccessPolicy)); |
| 311 return true; | 313 return true; |
| 312 } | 314 } |
| 313 | 315 |
| 314 void WindowTree::DispatchInputEvent(ServerWindow* target, | 316 void WindowTree::DispatchInputEvent(ServerWindow* target, |
| 315 const ui::Event& event) { | 317 const ui::Event& event) { |
| 316 if (event_ack_id_) { | 318 if (event_ack_id_) { |
| 317 // This is currently waiting for an event ack. Add it to the queue. | 319 // This is currently waiting for an event ack. Add it to the queue. |
| 318 event_queue_.push(make_scoped_ptr(new TargetedEvent(target, event))); | 320 event_queue_.push(base::WrapUnique(new TargetedEvent(target, event))); |
| 319 // TODO(sad): If the |event_queue_| grows too large, then this should notify | 321 // TODO(sad): If the |event_queue_| grows too large, then this should notify |
| 320 // Display, so that it can stop sending events. | 322 // Display, so that it can stop sending events. |
| 321 return; | 323 return; |
| 322 } | 324 } |
| 323 | 325 |
| 324 // If there are events in the queue, then store this new event in the queue, | 326 // If there are events in the queue, then store this new event in the queue, |
| 325 // and dispatch the latest event from the queue instead that still has a live | 327 // and dispatch the latest event from the queue instead that still has a live |
| 326 // target. | 328 // target. |
| 327 if (!event_queue_.empty()) { | 329 if (!event_queue_.empty()) { |
| 328 event_queue_.push(make_scoped_ptr(new TargetedEvent(target, event))); | 330 event_queue_.push(base::WrapUnique(new TargetedEvent(target, event))); |
| 329 return; | 331 return; |
| 330 } | 332 } |
| 331 | 333 |
| 332 DispatchInputEventImpl(target, event); | 334 DispatchInputEventImpl(target, event); |
| 333 } | 335 } |
| 334 | 336 |
| 335 bool WindowTree::IsWaitingForNewTopLevelWindow(uint32_t wm_change_id) { | 337 bool WindowTree::IsWaitingForNewTopLevelWindow(uint32_t wm_change_id) { |
| 336 return waiting_for_top_level_window_info_ && | 338 return waiting_for_top_level_window_info_ && |
| 337 waiting_for_top_level_window_info_->wm_change_id == wm_change_id; | 339 waiting_for_top_level_window_info_->wm_change_id == wm_change_id; |
| 338 } | 340 } |
| 339 | 341 |
| 340 void WindowTree::OnWindowManagerCreatedTopLevelWindow( | 342 void WindowTree::OnWindowManagerCreatedTopLevelWindow( |
| 341 uint32_t wm_change_id, | 343 uint32_t wm_change_id, |
| 342 uint32_t client_change_id, | 344 uint32_t client_change_id, |
| 343 const ServerWindow* window) { | 345 const ServerWindow* window) { |
| 344 DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id)); | 346 DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id)); |
| 345 scoped_ptr<WaitingForTopLevelWindowInfo> waiting_for_top_level_window_info( | 347 std::unique_ptr<WaitingForTopLevelWindowInfo> |
| 346 std::move(waiting_for_top_level_window_info_)); | 348 waiting_for_top_level_window_info( |
| 349 std::move(waiting_for_top_level_window_info_)); |
| 347 binding_->SetIncomingMethodCallProcessingPaused(false); | 350 binding_->SetIncomingMethodCallProcessingPaused(false); |
| 348 // We were paused, so the id should still be valid. | 351 // We were paused, so the id should still be valid. |
| 349 DCHECK(IsValidIdForNewWindow( | 352 DCHECK(IsValidIdForNewWindow( |
| 350 waiting_for_top_level_window_info->client_window_id)); | 353 waiting_for_top_level_window_info->client_window_id)); |
| 351 client_id_to_window_id_map_[waiting_for_top_level_window_info | 354 client_id_to_window_id_map_[waiting_for_top_level_window_info |
| 352 ->client_window_id] = window->id(); | 355 ->client_window_id] = window->id(); |
| 353 window_id_to_client_id_map_[window->id()] = | 356 window_id_to_client_id_map_[window->id()] = |
| 354 waiting_for_top_level_window_info->client_window_id; | 357 waiting_for_top_level_window_info->client_window_id; |
| 355 roots_.insert(window); | 358 roots_.insert(window); |
| 356 const bool drawn = window->parent() && window->parent()->IsDrawn(); | 359 const bool drawn = window->parent() && window->parent()->IsDrawn(); |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 event_ack_id_ = 0; | 1231 event_ack_id_ = 0; |
| 1229 | 1232 |
| 1230 WindowManagerState* event_source_wms = event_source_wms_; | 1233 WindowManagerState* event_source_wms = event_source_wms_; |
| 1231 event_source_wms_ = nullptr; | 1234 event_source_wms_ = nullptr; |
| 1232 if (event_source_wms) | 1235 if (event_source_wms) |
| 1233 event_source_wms->OnEventAck(this, result); | 1236 event_source_wms->OnEventAck(this, result); |
| 1234 | 1237 |
| 1235 if (!event_queue_.empty()) { | 1238 if (!event_queue_.empty()) { |
| 1236 DCHECK(!event_ack_id_); | 1239 DCHECK(!event_ack_id_); |
| 1237 ServerWindow* target = nullptr; | 1240 ServerWindow* target = nullptr; |
| 1238 scoped_ptr<ui::Event> event; | 1241 std::unique_ptr<ui::Event> event; |
| 1239 do { | 1242 do { |
| 1240 scoped_ptr<TargetedEvent> targeted_event = | 1243 std::unique_ptr<TargetedEvent> targeted_event = |
| 1241 std::move(event_queue_.front()); | 1244 std::move(event_queue_.front()); |
| 1242 event_queue_.pop(); | 1245 event_queue_.pop(); |
| 1243 target = targeted_event->target(); | 1246 target = targeted_event->target(); |
| 1244 event = targeted_event->TakeEvent(); | 1247 event = targeted_event->TakeEvent(); |
| 1245 } while (!event_queue_.empty() && !GetDisplay(target)); | 1248 } while (!event_queue_.empty() && !GetDisplay(target)); |
| 1246 if (target) | 1249 if (target) |
| 1247 DispatchInputEventImpl(target, *event); | 1250 DispatchInputEventImpl(target, *event); |
| 1248 } | 1251 } |
| 1249 } | 1252 } |
| 1250 | 1253 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 } | 1412 } |
| 1410 | 1413 |
| 1411 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1414 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
| 1412 const ServerWindow* window) const { | 1415 const ServerWindow* window) const { |
| 1413 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1416 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
| 1414 return tree && tree != this; | 1417 return tree && tree != this; |
| 1415 } | 1418 } |
| 1416 | 1419 |
| 1417 } // namespace ws | 1420 } // namespace ws |
| 1418 } // namespace mus | 1421 } // namespace mus |
| OLD | NEW |