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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 return; | 698 return; |
699 ClientWindowId client_window_id, transient_client_window_id; | 699 ClientWindowId client_window_id, transient_client_window_id; |
700 if (!IsWindowKnown(window, &client_window_id) || | 700 if (!IsWindowKnown(window, &client_window_id) || |
701 !IsWindowKnown(transient_window, &transient_client_window_id)) { | 701 !IsWindowKnown(transient_window, &transient_client_window_id)) { |
702 return; | 702 return; |
703 } | 703 } |
704 client()->OnTransientWindowRemoved(client_window_id.id, | 704 client()->OnTransientWindowRemoved(client_window_id.id, |
705 transient_client_window_id.id); | 705 transient_client_window_id.id); |
706 } | 706 } |
707 | 707 |
| 708 void WindowTree::SendToPointerWatcher(const ui::Event& event) { |
| 709 if (EventMatchesPointerWatcher(event)) |
| 710 client()->OnPointerEventObserved(ui::Event::Clone(event), |
| 711 pointer_watcher_id_); |
| 712 } |
| 713 |
708 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const { | 714 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const { |
709 if (window_manager_state_) | 715 if (window_manager_state_) |
710 return false; // We are the window manager, don't route to ourself. | 716 return false; // We are the window manager, don't route to ourself. |
711 | 717 |
712 // If the client created this window, then do not route it through the WM. | 718 // If the client created this window, then do not route it through the WM. |
713 if (window->id().client_id == id_) | 719 if (window->id().client_id == id_) |
714 return false; | 720 return false; |
715 | 721 |
716 // If the client did not create the window, then it must be the root of the | 722 // If the client did not create the window, then it must be the root of the |
717 // client. If not, that means the client should not know about this window, | 723 // client. If not, that means the client should not know about this window, |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 } | 991 } |
986 | 992 |
987 void WindowTree::DispatchInputEventImpl(ServerWindow* target, | 993 void WindowTree::DispatchInputEventImpl(ServerWindow* target, |
988 const ui::Event& event) { | 994 const ui::Event& event) { |
989 GenerateEventAckId(); | 995 GenerateEventAckId(); |
990 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target); | 996 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target); |
991 DCHECK(display_root); | 997 DCHECK(display_root); |
992 event_source_wms_ = display_root->window_manager_state(); | 998 event_source_wms_ = display_root->window_manager_state(); |
993 // Should only get events from windows attached to a host. | 999 // Should only get events from windows attached to a host. |
994 DCHECK(event_source_wms_); | 1000 DCHECK(event_source_wms_); |
995 bool matched_observer = | 1001 bool matched_pointer_watcher = EventMatchesPointerWatcher(event); |
996 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event); | |
997 client()->OnWindowInputEvent( | 1002 client()->OnWindowInputEvent( |
998 event_ack_id_, ClientWindowIdForWindow(target).id, | 1003 event_ack_id_, ClientWindowIdForWindow(target).id, |
999 ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0); | 1004 ui::Event::Clone(event), |
| 1005 matched_pointer_watcher ? pointer_watcher_id_ : 0); |
1000 } | 1006 } |
1001 | 1007 |
1002 void WindowTree::SendToEventObserver(const ui::Event& event) { | 1008 bool WindowTree::EventMatchesPointerWatcher(const ui::Event& event) const { |
1003 if (event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event)) | 1009 if (pointer_watcher_id_ == 0) |
1004 client()->OnEventObserved(ui::Event::Clone(event), event_observer_id_); | 1010 return false; |
| 1011 if (!event.IsPointerEvent()) |
| 1012 return false; |
| 1013 if (pointer_watcher_want_moves_ && event.type() == ui::ET_POINTER_MOVED) |
| 1014 return true; |
| 1015 return event.type() == ui::ET_POINTER_DOWN || |
| 1016 event.type() == ui::ET_POINTER_UP; |
1005 } | 1017 } |
1006 | 1018 |
1007 void WindowTree::NewWindow( | 1019 void WindowTree::NewWindow( |
1008 uint32_t change_id, | 1020 uint32_t change_id, |
1009 Id transport_window_id, | 1021 Id transport_window_id, |
1010 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 1022 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
1011 std::map<std::string, std::vector<uint8_t>> properties; | 1023 std::map<std::string, std::vector<uint8_t>> properties; |
1012 if (!transport_properties.is_null()) { | 1024 if (!transport_properties.is_null()) { |
1013 properties = | 1025 properties = |
1014 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1026 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 access_policy_->CanSetCapture(current_capture_window)) && | 1172 access_policy_->CanSetCapture(current_capture_window)) && |
1161 window == current_capture_window; | 1173 window == current_capture_window; |
1162 if (success) { | 1174 if (success) { |
1163 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); | 1175 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); |
1164 success = display_root->window_manager_state()->SetCapture( | 1176 success = display_root->window_manager_state()->SetCapture( |
1165 nullptr, kInvalidClientId); | 1177 nullptr, kInvalidClientId); |
1166 } | 1178 } |
1167 client()->OnChangeCompleted(change_id, success); | 1179 client()->OnChangeCompleted(change_id, success); |
1168 } | 1180 } |
1169 | 1181 |
1170 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher, | 1182 void WindowTree::StartPointerWatcher(bool want_moves, |
1171 uint32_t observer_id) { | 1183 uint32_t pointer_watcher_id) { |
1172 if (matcher.is_null() || observer_id == 0) { | 1184 if (pointer_watcher_id == 0) { |
1173 // Clear any existing event observer. | 1185 DVLOG(1) << "StartPointerWatcher called with 0."; |
1174 event_observer_matcher_.reset(); | 1186 StopPointerWatcher(); |
1175 event_observer_id_ = 0; | |
1176 return; | 1187 return; |
1177 } | 1188 } |
| 1189 pointer_watcher_want_moves_ = want_moves; |
| 1190 pointer_watcher_id_ = pointer_watcher_id; |
| 1191 } |
1178 | 1192 |
1179 // Do not allow key events to be observed, as a compromised app could register | 1193 void WindowTree::StopPointerWatcher() { |
1180 // itself as an event observer and spy on keystrokes to another app. | 1194 pointer_watcher_want_moves_ = false; |
1181 if (!matcher->type_matcher && !matcher->pointer_kind_matcher) { | 1195 pointer_watcher_id_ = 0; |
1182 DVLOG(1) << "SetEventObserver must specify an event type."; | |
1183 return; | |
1184 } | |
1185 | |
1186 const ui::mojom::EventType event_type_whitelist[] = { | |
1187 ui::mojom::EventType::POINTER_CANCEL, ui::mojom::EventType::POINTER_DOWN, | |
1188 ui::mojom::EventType::POINTER_MOVE, ui::mojom::EventType::POINTER_UP, | |
1189 ui::mojom::EventType::MOUSE_EXIT, ui::mojom::EventType::WHEEL, | |
1190 }; | |
1191 | |
1192 if (matcher->type_matcher) { | |
1193 auto* iter = | |
1194 std::find(std::begin(event_type_whitelist), | |
1195 std::end(event_type_whitelist), matcher->type_matcher->type); | |
1196 if (iter == std::end(event_type_whitelist)) { | |
1197 DVLOG(1) << "SetEventObserver event type not allowed"; | |
1198 return; | |
1199 } | |
1200 } | |
1201 if (matcher->pointer_kind_matcher) { | |
1202 ui::mojom::PointerKind pointer_kind = | |
1203 matcher->pointer_kind_matcher->pointer_kind; | |
1204 if (pointer_kind != ui::mojom::PointerKind::MOUSE && | |
1205 pointer_kind != ui::mojom::PointerKind::TOUCH && | |
1206 pointer_kind != ui::mojom::PointerKind::PEN) { | |
1207 DVLOG(1) << "SetEventObserver pointer kind not allowed"; | |
1208 return; | |
1209 } | |
1210 } | |
1211 | |
1212 event_observer_matcher_.reset(new EventMatcher(*matcher)); | |
1213 event_observer_id_ = observer_id; | |
1214 } | 1196 } |
1215 | 1197 |
1216 void WindowTree::SetWindowBounds(uint32_t change_id, | 1198 void WindowTree::SetWindowBounds(uint32_t change_id, |
1217 Id window_id, | 1199 Id window_id, |
1218 const gfx::Rect& bounds) { | 1200 const gfx::Rect& bounds) { |
1219 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | 1201 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
1220 if (window && ShouldRouteToWindowManager(window)) { | 1202 if (window && ShouldRouteToWindowManager(window)) { |
1221 const uint32_t wm_change_id = | 1203 const uint32_t wm_change_id = |
1222 window_server_->GenerateWindowManagerChangeId(this, change_id); | 1204 window_server_->GenerateWindowManagerChangeId(this, change_id); |
1223 // |window_id| may be a client id, use the id from the window to ensure | 1205 // |window_id| may be a client id, use the id from the window to ensure |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 } | 1657 } |
1676 | 1658 |
1677 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1659 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
1678 const ServerWindow* window) const { | 1660 const ServerWindow* window) const { |
1679 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1661 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
1680 return tree && tree != this; | 1662 return tree && tree != this; |
1681 } | 1663 } |
1682 | 1664 |
1683 } // namespace ws | 1665 } // namespace ws |
1684 } // namespace ui | 1666 } // namespace ui |
OLD | NEW |