Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: services/ui/ws/window_tree.cc

Issue 2183163002: mus: Change PointerWatcher to observe all pointer events, with moves optional. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renames, PointerEvent, tests etc Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ||
1003 event.type() == ui::ET_POINTER_ENTERED ||
1004 event.type() == ui::ET_POINTER_EXITED))
1005 return false;
1006 return true;
1007 }
1008
1009 void WindowTree::SendToPointerWatcher(const ui::Event& event) {
1010 if (EventMatchesPointerWatcher(event))
1011 client()->OnPointerWatcherEvent(ui::Event::Clone(event),
1012 pointer_watcher_id_);
1000 } 1013 }
1001 1014
1002 void WindowTree::NewWindow( 1015 void WindowTree::NewWindow(
1003 uint32_t change_id, 1016 uint32_t change_id,
1004 Id transport_window_id, 1017 Id transport_window_id,
1005 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 1018 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
1006 std::map<std::string, std::vector<uint8_t>> properties; 1019 std::map<std::string, std::vector<uint8_t>> properties;
1007 if (!transport_properties.is_null()) { 1020 if (!transport_properties.is_null()) {
1008 properties = 1021 properties =
1009 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 1022 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 access_policy_->CanSetCapture(current_capture_window)) && 1168 access_policy_->CanSetCapture(current_capture_window)) &&
1156 window == current_capture_window; 1169 window == current_capture_window;
1157 if (success) { 1170 if (success) {
1158 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); 1171 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE);
1159 success = display_root->window_manager_state()->SetCapture( 1172 success = display_root->window_manager_state()->SetCapture(
1160 nullptr, kInvalidClientId); 1173 nullptr, kInvalidClientId);
1161 } 1174 }
1162 client()->OnChangeCompleted(change_id, success); 1175 client()->OnChangeCompleted(change_id, success);
1163 } 1176 }
1164 1177
1165 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher, 1178 void WindowTree::StartPointerWatcher(bool want_moves,
1166 uint32_t observer_id) { 1179 uint32_t pointer_watcher_id) {
1167 if (matcher.is_null() || observer_id == 0) { 1180 if (pointer_watcher_id == 0) {
1168 // Clear any existing event observer. 1181 StopPointerWatcher();
1169 event_observer_matcher_.reset();
1170 event_observer_id_ = 0;
1171 return; 1182 return;
1172 } 1183 }
1184 has_pointer_watcher_ = true;
1185 pointer_watcher_want_moves_ = want_moves;
1186 pointer_watcher_id_ = pointer_watcher_id;
1187 }
1173 1188
1174 // Do not allow key events to be observed, as a compromised app could register 1189 void WindowTree::StopPointerWatcher() {
1175 // itself as an event observer and spy on keystrokes to another app. 1190 has_pointer_watcher_ = false;
1176 if (!matcher->type_matcher && !matcher->pointer_kind_matcher) { 1191 pointer_watcher_want_moves_ = false;
1177 DVLOG(1) << "SetEventObserver must specify an event type."; 1192 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 } 1193 }
1210 1194
1211 void WindowTree::SetWindowBounds(uint32_t change_id, 1195 void WindowTree::SetWindowBounds(uint32_t change_id,
1212 Id window_id, 1196 Id window_id,
1213 const gfx::Rect& bounds) { 1197 const gfx::Rect& bounds) {
1214 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1198 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1215 if (window && ShouldRouteToWindowManager(window)) { 1199 if (window && ShouldRouteToWindowManager(window)) {
1216 const uint32_t wm_change_id = 1200 const uint32_t wm_change_id =
1217 window_server_->GenerateWindowManagerChangeId(this, change_id); 1201 window_server_->GenerateWindowManagerChangeId(this, change_id);
1218 // |window_id| may be a client id, use the id from the window to ensure 1202 // |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
1669 } 1653 }
1670 1654
1671 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( 1655 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy(
1672 const ServerWindow* window) const { 1656 const ServerWindow* window) const {
1673 WindowTree* tree = window_server_->GetTreeWithRoot(window); 1657 WindowTree* tree = window_server_->GetTreeWithRoot(window);
1674 return tree && tree != this; 1658 return tree && tree != this;
1675 } 1659 }
1676 1660
1677 } // namespace ws 1661 } // namespace ws
1678 } // namespace ui 1662 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698