| 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 "services/ui/ws/window_tree.h" | 5 #include "services/ui/ws/window_tree.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } else { | 424 } else { |
| 425 DVLOG(1) << "AddActivationParent supplied invalid window id"; | 425 DVLOG(1) << "AddActivationParent supplied invalid window id"; |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 void WindowTree::OnChangeCompleted(uint32_t change_id, bool success) { | 429 void WindowTree::OnChangeCompleted(uint32_t change_id, bool success) { |
| 430 client()->OnChangeCompleted(change_id, success); | 430 client()->OnChangeCompleted(change_id, success); |
| 431 } | 431 } |
| 432 | 432 |
| 433 void WindowTree::OnAccelerator(uint32_t accelerator_id, | 433 void WindowTree::OnAccelerator(uint32_t accelerator_id, |
| 434 const ui::Event& event) { | 434 const ui::Event& event, |
| 435 bool needs_ack) { |
| 435 DCHECK(window_manager_internal_); | 436 DCHECK(window_manager_internal_); |
| 437 if (needs_ack) |
| 438 GenerateEventAckId(); |
| 439 else |
| 440 DCHECK_EQ(0u, event_ack_id_); |
| 436 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map | 441 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map |
| 437 // mojom::Event directly to ui::Event. | 442 // mojom::Event directly to ui::Event. |
| 438 window_manager_internal_->OnAccelerator(accelerator_id, | 443 window_manager_internal_->OnAccelerator(event_ack_id_, accelerator_id, |
| 439 ui::Event::Clone(event)); | 444 ui::Event::Clone(event)); |
| 440 } | 445 } |
| 441 | 446 |
| 442 void WindowTree::ClientJankinessChanged(WindowTree* tree) { | 447 void WindowTree::ClientJankinessChanged(WindowTree* tree) { |
| 443 tree->janky_ = !tree->janky_; | 448 tree->janky_ = !tree->janky_; |
| 444 if (window_manager_internal_) { | 449 if (window_manager_internal_) { |
| 445 window_manager_internal_->WmClientJankinessChanged( | 450 window_manager_internal_->WmClientJankinessChanged( |
| 446 tree->id(), tree->janky()); | 451 tree->id(), tree->janky()); |
| 447 } | 452 } |
| 448 } | 453 } |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 existing_owner->RemoveRoot(window, RemoveRootReason::EMBED); | 957 existing_owner->RemoveRoot(window, RemoveRootReason::EMBED); |
| 953 } | 958 } |
| 954 } | 959 } |
| 955 | 960 |
| 956 void WindowTree::RemoveChildrenAsPartOfEmbed(ServerWindow* window) { | 961 void WindowTree::RemoveChildrenAsPartOfEmbed(ServerWindow* window) { |
| 957 CHECK(window); | 962 CHECK(window); |
| 958 while (!window->children().empty()) | 963 while (!window->children().empty()) |
| 959 window->Remove(window->children().front()); | 964 window->Remove(window->children().front()); |
| 960 } | 965 } |
| 961 | 966 |
| 967 uint32_t WindowTree::GenerateEventAckId() { |
| 968 DCHECK(!event_ack_id_); |
| 969 // We do not want to create a sequential id for each event, because that can |
| 970 // leak some information to the client. So instead, manufacture the id |
| 971 // randomly. |
| 972 event_ack_id_ = 0x1000000 | (rand() & 0xffffff); |
| 973 return event_ack_id_; |
| 974 } |
| 975 |
| 962 void WindowTree::DispatchInputEventImpl(ServerWindow* target, | 976 void WindowTree::DispatchInputEventImpl(ServerWindow* target, |
| 963 const ui::Event& event) { | 977 const ui::Event& event) { |
| 964 DCHECK(!event_ack_id_); | 978 GenerateEventAckId(); |
| 965 // We do not want to create a sequential id for each event, because that can | |
| 966 // leak some information to the client. So instead, manufacture the id | |
| 967 // randomly. | |
| 968 // TODO(moshayedi): Find a faster way to generate ids. | |
| 969 event_ack_id_ = 0x1000000 | (rand() & 0xffffff); | |
| 970 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target); | 979 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target); |
| 971 DCHECK(display_root); | 980 DCHECK(display_root); |
| 972 event_source_wms_ = display_root->window_manager_state(); | 981 event_source_wms_ = display_root->window_manager_state(); |
| 973 // Should only get events from windows attached to a host. | 982 // Should only get events from windows attached to a host. |
| 974 DCHECK(event_source_wms_); | 983 DCHECK(event_source_wms_); |
| 975 bool matched_observer = | 984 bool matched_observer = |
| 976 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event); | 985 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event); |
| 977 client()->OnWindowInputEvent( | 986 client()->OnWindowInputEvent( |
| 978 event_ack_id_, ClientWindowIdForWindow(target).id, | 987 event_ack_id_, ClientWindowIdForWindow(target).id, |
| 979 ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0); | 988 ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 display->SetImeVisibility(window, visible); | 1299 display->SetImeVisibility(window, visible); |
| 1291 } | 1300 } |
| 1292 } | 1301 } |
| 1293 | 1302 |
| 1294 void WindowTree::OnWindowInputEventAck(uint32_t event_id, | 1303 void WindowTree::OnWindowInputEventAck(uint32_t event_id, |
| 1295 mojom::EventResult result) { | 1304 mojom::EventResult result) { |
| 1296 if (event_ack_id_ == 0 || event_id != event_ack_id_) { | 1305 if (event_ack_id_ == 0 || event_id != event_ack_id_) { |
| 1297 // TODO(sad): Something bad happened. Kill the client? | 1306 // TODO(sad): Something bad happened. Kill the client? |
| 1298 NOTIMPLEMENTED() << ": Wrong event acked. event_id=" << event_id | 1307 NOTIMPLEMENTED() << ": Wrong event acked. event_id=" << event_id |
| 1299 << ", event_ack_id_=" << event_ack_id_; | 1308 << ", event_ack_id_=" << event_ack_id_; |
| 1309 DVLOG(1) << "OnWindowInputEventAck supplied unexpected event_id"; |
| 1300 } | 1310 } |
| 1301 event_ack_id_ = 0; | 1311 event_ack_id_ = 0; |
| 1302 | 1312 |
| 1303 if (janky_) | 1313 if (janky_) |
| 1304 event_source_wms_->window_tree()->ClientJankinessChanged(this); | 1314 event_source_wms_->window_tree()->ClientJankinessChanged(this); |
| 1305 | 1315 |
| 1306 WindowManagerState* event_source_wms = event_source_wms_; | 1316 WindowManagerState* event_source_wms = event_source_wms_; |
| 1307 event_source_wms_ = nullptr; | 1317 event_source_wms_ = nullptr; |
| 1308 if (event_source_wms) | 1318 if (event_source_wms) |
| 1309 event_source_wms->OnEventAck(this, result); | 1319 event_source_wms->OnEventAck(this, result); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 ServerWindow* window = | 1613 ServerWindow* window = |
| 1604 GetWindowByClientId(ClientWindowId(transport_window_id)); | 1614 GetWindowByClientId(ClientWindowId(transport_window_id)); |
| 1605 if (window && window->id().client_id != id_) { | 1615 if (window && window->id().client_id != id_) { |
| 1606 DVLOG(1) << "OnWmCreatedTopLevelWindow supplied invalid window id"; | 1616 DVLOG(1) << "OnWmCreatedTopLevelWindow supplied invalid window id"; |
| 1607 window_server_->WindowManagerSentBogusMessage(); | 1617 window_server_->WindowManagerSentBogusMessage(); |
| 1608 window = nullptr; | 1618 window = nullptr; |
| 1609 } | 1619 } |
| 1610 window_server_->WindowManagerCreatedTopLevelWindow(this, change_id, window); | 1620 window_server_->WindowManagerCreatedTopLevelWindow(this, change_id, window); |
| 1611 } | 1621 } |
| 1612 | 1622 |
| 1623 void WindowTree::OnAcceleratorAck(uint32_t event_id, |
| 1624 mojom::EventResult result) { |
| 1625 if (event_ack_id_ == 0 || event_id != event_ack_id_) { |
| 1626 DVLOG(1) << "OnAcceleratorAck supplied invalid event_id"; |
| 1627 window_server_->WindowManagerSentBogusMessage(); |
| 1628 return; |
| 1629 } |
| 1630 event_ack_id_ = 0; |
| 1631 DCHECK(window_manager_state_); |
| 1632 window_manager_state_->OnAcceleratorAck(result); |
| 1633 } |
| 1634 |
| 1613 bool WindowTree::HasRootForAccessPolicy(const ServerWindow* window) const { | 1635 bool WindowTree::HasRootForAccessPolicy(const ServerWindow* window) const { |
| 1614 return HasRoot(window); | 1636 return HasRoot(window); |
| 1615 } | 1637 } |
| 1616 | 1638 |
| 1617 bool WindowTree::IsWindowKnownForAccessPolicy( | 1639 bool WindowTree::IsWindowKnownForAccessPolicy( |
| 1618 const ServerWindow* window) const { | 1640 const ServerWindow* window) const { |
| 1619 return IsWindowKnown(window); | 1641 return IsWindowKnown(window); |
| 1620 } | 1642 } |
| 1621 | 1643 |
| 1622 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1644 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
| 1623 const ServerWindow* window) const { | 1645 const ServerWindow* window) const { |
| 1624 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1646 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
| 1625 return tree && tree != this; | 1647 return tree && tree != this; |
| 1626 } | 1648 } |
| 1627 | 1649 |
| 1628 } // namespace ws | 1650 } // namespace ws |
| 1629 } // namespace ui | 1651 } // namespace ui |
| OLD | NEW |