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 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 } | 980 } |
981 | 981 |
982 void WindowTree::DispatchInputEventImpl(ServerWindow* target, | 982 void WindowTree::DispatchInputEventImpl(ServerWindow* target, |
983 const ui::Event& event) { | 983 const ui::Event& event) { |
984 GenerateEventAckId(); | 984 GenerateEventAckId(); |
985 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target); | 985 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target); |
986 DCHECK(display_root); | 986 DCHECK(display_root); |
987 event_source_wms_ = display_root->window_manager_state(); | 987 event_source_wms_ = display_root->window_manager_state(); |
988 // Should only get events from windows attached to a host. | 988 // Should only get events from windows attached to a host. |
989 DCHECK(event_source_wms_); | 989 DCHECK(event_source_wms_); |
990 bool matched_observer = | 990 bool matched_pointer_watcher = EventMatchesPointerWatcher(event); |
991 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event); | |
992 client()->OnWindowInputEvent( | 991 client()->OnWindowInputEvent( |
993 event_ack_id_, ClientWindowIdForWindow(target).id, | 992 event_ack_id_, ClientWindowIdForWindow(target).id, |
994 ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0); | 993 ui::Event::Clone(event), |
| 994 matched_pointer_watcher ? pointer_watcher_id_ : 0); |
| 995 } |
| 996 |
| 997 bool WindowTree::EventMatchesPointerWatcher(const ui::Event& event) { |
| 998 if (!has_pointer_watcher_) |
| 999 return false; |
| 1000 if (!event.IsPointerEvent()) |
| 1001 return false; |
| 1002 if (!pointer_watcher_want_moves_ && event.type() == ui::ET_POINTER_MOVED) |
| 1003 return false; |
| 1004 return true; |
995 } | 1005 } |
996 | 1006 |
997 void WindowTree::SendToEventObserver(const ui::Event& event) { | 1007 void WindowTree::SendToEventObserver(const ui::Event& event) { |
998 if (event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event)) | 1008 if (EventMatchesPointerWatcher(event)) |
999 client()->OnEventObserved(ui::Event::Clone(event), event_observer_id_); | 1009 client()->OnEventObserved(ui::Event::Clone(event), pointer_watcher_id_); |
1000 } | 1010 } |
1001 | 1011 |
1002 void WindowTree::NewWindow( | 1012 void WindowTree::NewWindow( |
1003 uint32_t change_id, | 1013 uint32_t change_id, |
1004 Id transport_window_id, | 1014 Id transport_window_id, |
1005 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 1015 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
1006 std::map<std::string, std::vector<uint8_t>> properties; | 1016 std::map<std::string, std::vector<uint8_t>> properties; |
1007 if (!transport_properties.is_null()) { | 1017 if (!transport_properties.is_null()) { |
1008 properties = | 1018 properties = |
1009 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1019 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 if (success) { | 1167 if (success) { |
1158 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); | 1168 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); |
1159 success = display_root->window_manager_state()->SetCapture( | 1169 success = display_root->window_manager_state()->SetCapture( |
1160 nullptr, kInvalidClientId); | 1170 nullptr, kInvalidClientId); |
1161 } | 1171 } |
1162 client()->OnChangeCompleted(change_id, success); | 1172 client()->OnChangeCompleted(change_id, success); |
1163 } | 1173 } |
1164 | 1174 |
1165 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher, | 1175 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher, |
1166 uint32_t observer_id) { | 1176 uint32_t observer_id) { |
1167 if (matcher.is_null() || observer_id == 0) { | 1177 // JAMES - remove this function |
1168 // Clear any existing event observer. | 1178 } |
1169 event_observer_matcher_.reset(); | |
1170 event_observer_id_ = 0; | |
1171 return; | |
1172 } | |
1173 | 1179 |
1174 // Do not allow key events to be observed, as a compromised app could register | 1180 void WindowTree::StartPointerWatcher(bool want_moves, |
1175 // itself as an event observer and spy on keystrokes to another app. | 1181 uint32_t pointer_watcher_id) { |
1176 if (!matcher->type_matcher && !matcher->pointer_kind_matcher) { | 1182 has_pointer_watcher_ = true; |
1177 DVLOG(1) << "SetEventObserver must specify an event type."; | 1183 pointer_watcher_want_moves_ = want_moves; |
1178 return; | 1184 pointer_watcher_id_ = pointer_watcher_id; |
1179 } | 1185 } |
1180 | 1186 |
1181 const ui::mojom::EventType event_type_whitelist[] = { | 1187 void WindowTree::StopPointerWatcher() { |
1182 ui::mojom::EventType::POINTER_CANCEL, ui::mojom::EventType::POINTER_DOWN, | 1188 has_pointer_watcher_ = false; |
1183 ui::mojom::EventType::POINTER_MOVE, ui::mojom::EventType::POINTER_UP, | 1189 pointer_watcher_want_moves_ = false; |
1184 ui::mojom::EventType::MOUSE_EXIT, ui::mojom::EventType::WHEEL, | 1190 pointer_watcher_id_ = 0; |
1185 }; | |
1186 | |
1187 if (matcher->type_matcher) { | |
1188 auto iter = | |
1189 std::find(std::begin(event_type_whitelist), | |
1190 std::end(event_type_whitelist), matcher->type_matcher->type); | |
1191 if (iter == std::end(event_type_whitelist)) { | |
1192 DVLOG(1) << "SetEventObserver event type not allowed"; | |
1193 return; | |
1194 } | |
1195 } | |
1196 if (matcher->pointer_kind_matcher) { | |
1197 ui::mojom::PointerKind pointer_kind = | |
1198 matcher->pointer_kind_matcher->pointer_kind; | |
1199 if (pointer_kind != ui::mojom::PointerKind::MOUSE && | |
1200 pointer_kind != ui::mojom::PointerKind::TOUCH && | |
1201 pointer_kind != ui::mojom::PointerKind::PEN) { | |
1202 DVLOG(1) << "SetEventObserver pointer kind not allowed"; | |
1203 return; | |
1204 } | |
1205 } | |
1206 | |
1207 event_observer_matcher_.reset(new EventMatcher(*matcher)); | |
1208 event_observer_id_ = observer_id; | |
1209 } | 1191 } |
1210 | 1192 |
1211 void WindowTree::SetWindowBounds(uint32_t change_id, | 1193 void WindowTree::SetWindowBounds(uint32_t change_id, |
1212 Id window_id, | 1194 Id window_id, |
1213 const gfx::Rect& bounds) { | 1195 const gfx::Rect& bounds) { |
1214 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | 1196 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
1215 if (window && ShouldRouteToWindowManager(window)) { | 1197 if (window && ShouldRouteToWindowManager(window)) { |
1216 const uint32_t wm_change_id = | 1198 const uint32_t wm_change_id = |
1217 window_server_->GenerateWindowManagerChangeId(this, change_id); | 1199 window_server_->GenerateWindowManagerChangeId(this, change_id); |
1218 // |window_id| may be a client id, use the id from the window to ensure | 1200 // |window_id| may be a client id, use the id from the window to ensure |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 } | 1651 } |
1670 | 1652 |
1671 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1653 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
1672 const ServerWindow* window) const { | 1654 const ServerWindow* window) const { |
1673 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1655 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
1674 return tree && tree != this; | 1656 return tree && tree != this; |
1675 } | 1657 } |
1676 | 1658 |
1677 } // namespace ws | 1659 } // namespace ws |
1678 } // namespace ui | 1660 } // namespace ui |
OLD | NEW |