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 } | 995 } |
996 | 996 |
997 void WindowTree::SendToEventObserver(const ui::Event& event) { | 997 bool WindowTree::EventMatchesPointerWatcher(const ui::Event& event) { |
998 if (event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event)) | 998 if (!has_pointer_watcher_) |
999 client()->OnEventObserved(ui::Event::Clone(event), event_observer_id_); | 999 return false; |
1000 if (!event.IsPointerEvent()) | |
1001 return false; | |
1002 if (!pointer_watcher_want_moves_ && (event.type() == ui::ET_POINTER_MOVED || | |
James Cook
2016/08/02 21:19:51
I think you can skip this if() now. The statement
riajiang
2016/08/02 22:01:41
True, done.
| |
1003 event.type() == ui::ET_POINTER_ENTERED || | |
1004 event.type() == ui::ET_POINTER_EXITED)) | |
1005 return false; | |
1006 return pointer_watcher_want_moves_ || (event.type() == ui::ET_POINTER_DOWN || | |
1007 event.type() == ui::ET_POINTER_UP); | |
1008 } | |
1009 | |
1010 void WindowTree::SendToPointerWatcher(const ui::Event& event) { | |
1011 if (EventMatchesPointerWatcher(event)) | |
1012 client()->OnPointerEventObserved(ui::Event::Clone(event), | |
1013 pointer_watcher_id_); | |
1000 } | 1014 } |
1001 | 1015 |
1002 void WindowTree::NewWindow( | 1016 void WindowTree::NewWindow( |
1003 uint32_t change_id, | 1017 uint32_t change_id, |
1004 Id transport_window_id, | 1018 Id transport_window_id, |
1005 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 1019 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
1006 std::map<std::string, std::vector<uint8_t>> properties; | 1020 std::map<std::string, std::vector<uint8_t>> properties; |
1007 if (!transport_properties.is_null()) { | 1021 if (!transport_properties.is_null()) { |
1008 properties = | 1022 properties = |
1009 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1023 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 access_policy_->CanSetCapture(current_capture_window)) && | 1169 access_policy_->CanSetCapture(current_capture_window)) && |
1156 window == current_capture_window; | 1170 window == current_capture_window; |
1157 if (success) { | 1171 if (success) { |
1158 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); | 1172 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); |
1159 success = display_root->window_manager_state()->SetCapture( | 1173 success = display_root->window_manager_state()->SetCapture( |
1160 nullptr, kInvalidClientId); | 1174 nullptr, kInvalidClientId); |
1161 } | 1175 } |
1162 client()->OnChangeCompleted(change_id, success); | 1176 client()->OnChangeCompleted(change_id, success); |
1163 } | 1177 } |
1164 | 1178 |
1165 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher, | 1179 void WindowTree::StartPointerWatcher(bool want_moves, |
1166 uint32_t observer_id) { | 1180 uint32_t pointer_watcher_id) { |
1167 if (matcher.is_null() || observer_id == 0) { | 1181 if (pointer_watcher_id == 0) { |
1168 // Clear any existing event observer. | 1182 StopPointerWatcher(); |
1169 event_observer_matcher_.reset(); | |
1170 event_observer_id_ = 0; | |
1171 return; | 1183 return; |
1172 } | 1184 } |
1185 has_pointer_watcher_ = true; | |
1186 pointer_watcher_want_moves_ = want_moves; | |
1187 pointer_watcher_id_ = pointer_watcher_id; | |
1188 } | |
1173 | 1189 |
1174 // Do not allow key events to be observed, as a compromised app could register | 1190 void WindowTree::StopPointerWatcher() { |
1175 // itself as an event observer and spy on keystrokes to another app. | 1191 has_pointer_watcher_ = false; |
1176 if (!matcher->type_matcher && !matcher->pointer_kind_matcher) { | 1192 pointer_watcher_want_moves_ = false; |
1177 DVLOG(1) << "SetEventObserver must specify an event type."; | 1193 pointer_watcher_id_ = 0; |
1178 return; | |
1179 } | |
1180 | |
1181 const ui::mojom::EventType event_type_whitelist[] = { | |
1182 ui::mojom::EventType::POINTER_CANCEL, ui::mojom::EventType::POINTER_DOWN, | |
1183 ui::mojom::EventType::POINTER_MOVE, ui::mojom::EventType::POINTER_UP, | |
1184 ui::mojom::EventType::MOUSE_EXIT, ui::mojom::EventType::WHEEL, | |
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 } | 1194 } |
1210 | 1195 |
1211 void WindowTree::SetWindowBounds(uint32_t change_id, | 1196 void WindowTree::SetWindowBounds(uint32_t change_id, |
1212 Id window_id, | 1197 Id window_id, |
1213 const gfx::Rect& bounds) { | 1198 const gfx::Rect& bounds) { |
1214 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | 1199 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
1215 if (window && ShouldRouteToWindowManager(window)) { | 1200 if (window && ShouldRouteToWindowManager(window)) { |
1216 const uint32_t wm_change_id = | 1201 const uint32_t wm_change_id = |
1217 window_server_->GenerateWindowManagerChangeId(this, change_id); | 1202 window_server_->GenerateWindowManagerChangeId(this, change_id); |
1218 // |window_id| may be a client id, use the id from the window to ensure | 1203 // |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... | |
1670 } | 1655 } |
1671 | 1656 |
1672 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1657 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
1673 const ServerWindow* window) const { | 1658 const ServerWindow* window) const { |
1674 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1659 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
1675 return tree && tree != this; | 1660 return tree && tree != this; |
1676 } | 1661 } |
1677 | 1662 |
1678 } // namespace ws | 1663 } // namespace ws |
1679 } // namespace ui | 1664 } // namespace ui |
OLD | NEW |