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 return pointer_watcher_want_moves_ || (event.type() == ui::ET_POINTER_DOWN || | |
James Cook
2016/08/02 23:20:36
nit: () not needed
riajiang
2016/08/03 17:54:23
Done.
| |
1003 event.type() == ui::ET_POINTER_UP); | |
1004 } | |
1005 | |
1006 void WindowTree::SendToPointerWatcher(const ui::Event& event) { | |
1007 if (EventMatchesPointerWatcher(event)) | |
1008 client()->OnPointerEventObserved(ui::Event::Clone(event), | |
1009 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 access_policy_->CanSetCapture(current_capture_window)) && | 1165 access_policy_->CanSetCapture(current_capture_window)) && |
1156 window == current_capture_window; | 1166 window == current_capture_window; |
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::StartPointerWatcher(bool want_moves, |
1166 uint32_t observer_id) { | 1176 uint32_t pointer_watcher_id) { |
1167 if (matcher.is_null() || observer_id == 0) { | 1177 if (pointer_watcher_id == 0) { |
1168 // Clear any existing event observer. | 1178 StopPointerWatcher(); |
1169 event_observer_matcher_.reset(); | |
1170 event_observer_id_ = 0; | |
1171 return; | 1179 return; |
1172 } | 1180 } |
1181 has_pointer_watcher_ = true; | |
1182 pointer_watcher_want_moves_ = want_moves; | |
1183 pointer_watcher_id_ = pointer_watcher_id; | |
1184 } | |
1173 | 1185 |
1174 // Do not allow key events to be observed, as a compromised app could register | 1186 void WindowTree::StopPointerWatcher() { |
1175 // itself as an event observer and spy on keystrokes to another app. | 1187 has_pointer_watcher_ = false; |
1176 if (!matcher->type_matcher && !matcher->pointer_kind_matcher) { | 1188 pointer_watcher_want_moves_ = false; |
1177 DVLOG(1) << "SetEventObserver must specify an event type."; | 1189 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 } | 1190 } |
1210 | 1191 |
1211 void WindowTree::SetWindowBounds(uint32_t change_id, | 1192 void WindowTree::SetWindowBounds(uint32_t change_id, |
1212 Id window_id, | 1193 Id window_id, |
1213 const gfx::Rect& bounds) { | 1194 const gfx::Rect& bounds) { |
1214 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | 1195 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
1215 if (window && ShouldRouteToWindowManager(window)) { | 1196 if (window && ShouldRouteToWindowManager(window)) { |
1216 const uint32_t wm_change_id = | 1197 const uint32_t wm_change_id = |
1217 window_server_->GenerateWindowManagerChangeId(this, change_id); | 1198 window_server_->GenerateWindowManagerChangeId(this, change_id); |
1218 // |window_id| may be a client id, use the id from the window to ensure | 1199 // |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 } | 1651 } |
1671 | 1652 |
1672 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1653 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
1673 const ServerWindow* window) const { | 1654 const ServerWindow* window) const { |
1674 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1655 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
1675 return tree && tree != this; | 1656 return tree && tree != this; |
1676 } | 1657 } |
1677 | 1658 |
1678 } // namespace ws | 1659 } // namespace ws |
1679 } // namespace ui | 1660 } // namespace ui |
OLD | NEW |