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

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: pointer enter/exit; has_pointer_watcher 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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 return; 693 return;
694 ClientWindowId client_window_id, transient_client_window_id; 694 ClientWindowId client_window_id, transient_client_window_id;
695 if (!IsWindowKnown(window, &client_window_id) || 695 if (!IsWindowKnown(window, &client_window_id) ||
696 !IsWindowKnown(transient_window, &transient_client_window_id)) { 696 !IsWindowKnown(transient_window, &transient_client_window_id)) {
697 return; 697 return;
698 } 698 }
699 client()->OnTransientWindowRemoved(client_window_id.id, 699 client()->OnTransientWindowRemoved(client_window_id.id,
700 transient_client_window_id.id); 700 transient_client_window_id.id);
701 } 701 }
702 702
703 void WindowTree::SendToPointerWatcher(const ui::Event& event) {
704 if (EventMatchesPointerWatcher(event))
705 client()->OnPointerEventObserved(ui::Event::Clone(event),
706 pointer_watcher_id_);
707 }
708
703 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const { 709 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const {
704 if (window_manager_state_) 710 if (window_manager_state_)
705 return false; // We are the window manager, don't route to ourself. 711 return false; // We are the window manager, don't route to ourself.
706 712
707 // If the client created this window, then do not route it through the WM. 713 // If the client created this window, then do not route it through the WM.
708 if (window->id().client_id == id_) 714 if (window->id().client_id == id_)
709 return false; 715 return false;
710 716
711 // If the client did not create the window, then it must be the root of the 717 // If the client did not create the window, then it must be the root of the
712 // client. If not, that means the client should not know about this window, 718 // 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
980 } 986 }
981 987
982 void WindowTree::DispatchInputEventImpl(ServerWindow* target, 988 void WindowTree::DispatchInputEventImpl(ServerWindow* target,
983 const ui::Event& event) { 989 const ui::Event& event) {
984 GenerateEventAckId(); 990 GenerateEventAckId();
985 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target); 991 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target);
986 DCHECK(display_root); 992 DCHECK(display_root);
987 event_source_wms_ = display_root->window_manager_state(); 993 event_source_wms_ = display_root->window_manager_state();
988 // Should only get events from windows attached to a host. 994 // Should only get events from windows attached to a host.
989 DCHECK(event_source_wms_); 995 DCHECK(event_source_wms_);
990 bool matched_observer = 996 bool matched_pointer_watcher = EventMatchesPointerWatcher(event);
991 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event);
992 client()->OnWindowInputEvent( 997 client()->OnWindowInputEvent(
993 event_ack_id_, ClientWindowIdForWindow(target).id, 998 event_ack_id_, ClientWindowIdForWindow(target).id,
994 ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0); 999 ui::Event::Clone(event),
1000 matched_pointer_watcher ? pointer_watcher_id_ : 0);
995 } 1001 }
996 1002
997 void WindowTree::SendToEventObserver(const ui::Event& event) { 1003 bool WindowTree::EventMatchesPointerWatcher(const ui::Event& event) const {
998 if (event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event)) 1004 if (pointer_watcher_id_ == 0)
999 client()->OnEventObserved(ui::Event::Clone(event), event_observer_id_); 1005 return false;
1006 if (!event.IsPointerEvent())
1007 return false;
1008 if (pointer_watcher_want_moves_ && event.type() == ui::ET_POINTER_MOVED)
1009 return true;
1010 return !pointer_watcher_want_moves_ && (event.type() == ui::ET_POINTER_DOWN ||
sky 2016/08/05 18:06:51 Why do you have the !pointer_watcher_wants_moves_
riajiang 2016/08/05 19:23:59 Oh right! Removed.
1011 event.type() == ui::ET_POINTER_UP);
1000 } 1012 }
1001 1013
1002 void WindowTree::NewWindow( 1014 void WindowTree::NewWindow(
1003 uint32_t change_id, 1015 uint32_t change_id,
1004 Id transport_window_id, 1016 Id transport_window_id,
1005 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 1017 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
1006 std::map<std::string, std::vector<uint8_t>> properties; 1018 std::map<std::string, std::vector<uint8_t>> properties;
1007 if (!transport_properties.is_null()) { 1019 if (!transport_properties.is_null()) {
1008 properties = 1020 properties =
1009 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 1021 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)) && 1167 access_policy_->CanSetCapture(current_capture_window)) &&
1156 window == current_capture_window; 1168 window == current_capture_window;
1157 if (success) { 1169 if (success) {
1158 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); 1170 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE);
1159 success = display_root->window_manager_state()->SetCapture( 1171 success = display_root->window_manager_state()->SetCapture(
1160 nullptr, kInvalidClientId); 1172 nullptr, kInvalidClientId);
1161 } 1173 }
1162 client()->OnChangeCompleted(change_id, success); 1174 client()->OnChangeCompleted(change_id, success);
1163 } 1175 }
1164 1176
1165 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher, 1177 void WindowTree::StartPointerWatcher(bool want_moves,
1166 uint32_t observer_id) { 1178 uint32_t pointer_watcher_id) {
1167 if (matcher.is_null() || observer_id == 0) { 1179 if (pointer_watcher_id == 0) {
1168 // Clear any existing event observer. 1180 StopPointerWatcher();
sky 2016/08/05 18:06:51 Please also log here as the client shouldn't reall
riajiang 2016/08/05 19:23:59 Done.
1169 event_observer_matcher_.reset();
1170 event_observer_id_ = 0;
1171 return; 1181 return;
1172 } 1182 }
1183 pointer_watcher_want_moves_ = want_moves;
1184 pointer_watcher_id_ = pointer_watcher_id;
1185 }
1173 1186
1174 // Do not allow key events to be observed, as a compromised app could register 1187 void WindowTree::StopPointerWatcher() {
1175 // itself as an event observer and spy on keystrokes to another app. 1188 pointer_watcher_want_moves_ = false;
1176 if (!matcher->type_matcher && !matcher->pointer_kind_matcher) { 1189 pointer_watcher_id_ = 0;
1177 DVLOG(1) << "SetEventObserver must specify an event type.";
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698