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

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

Issue 2125663002: mus: Add watcher for all touch events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Overload copy assignment operator for Change struct. Created 4 years, 5 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "mojo/public/cpp/bindings/binding.h"
15 #include "services/ui/ws/default_access_policy.h" 16 #include "services/ui/ws/default_access_policy.h"
16 #include "services/ui/ws/display.h" 17 #include "services/ui/ws/display.h"
17 #include "services/ui/ws/display_manager.h" 18 #include "services/ui/ws/display_manager.h"
18 #include "services/ui/ws/event_matcher.h" 19 #include "services/ui/ws/event_matcher.h"
19 #include "services/ui/ws/focus_controller.h" 20 #include "services/ui/ws/focus_controller.h"
20 #include "services/ui/ws/operation.h" 21 #include "services/ui/ws/operation.h"
21 #include "services/ui/ws/platform_display.h" 22 #include "services/ui/ws/platform_display.h"
22 #include "services/ui/ws/server_window.h" 23 #include "services/ui/ws/server_window.h"
23 #include "services/ui/ws/server_window_observer.h" 24 #include "services/ui/ws/server_window_observer.h"
24 #include "services/ui/ws/user_display_manager.h" 25 #include "services/ui/ws/user_display_manager.h"
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 // We do not want to create a sequential id for each event, because that can 967 // We do not want to create a sequential id for each event, because that can
967 // leak some information to the client. So instead, manufacture the id 968 // leak some information to the client. So instead, manufacture the id
968 // randomly. 969 // randomly.
969 // TODO(moshayedi): Find a faster way to generate ids. 970 // TODO(moshayedi): Find a faster way to generate ids.
970 event_ack_id_ = 0x1000000 | (rand() & 0xffffff); 971 event_ack_id_ = 0x1000000 | (rand() & 0xffffff);
971 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target); 972 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target);
972 DCHECK(display_root); 973 DCHECK(display_root);
973 event_source_wms_ = display_root->window_manager_state(); 974 event_source_wms_ = display_root->window_manager_state();
974 // Should only get events from windows attached to a host. 975 // Should only get events from windows attached to a host.
975 DCHECK(event_source_wms_); 976 DCHECK(event_source_wms_);
976 bool matched_observer = 977 mojo::Array<uint32_t> event_observer_ids;
977 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event); 978 std::map<uint32_t, std::unique_ptr<EventMatcher>>::iterator it;
979 for (it = event_observer_matchers_.begin();
980 it != event_observer_matchers_.end(); ++it) {
981 bool matched_observer = it->second->MatchesEvent(event);
982 if (matched_observer) {
983 event_observer_ids.push_back(it->first);
984 } else {
985 event_observer_ids.push_back(0);
986 }
987 }
978 client()->OnWindowInputEvent( 988 client()->OnWindowInputEvent(
979 event_ack_id_, ClientWindowIdForWindow(target).id, 989 event_ack_id_, ClientWindowIdForWindow(target).id,
980 ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0); 990 ui::Event::Clone(event), std::move(event_observer_ids));
981 } 991 }
982 992
983 void WindowTree::SendToEventObserver(const ui::Event& event) { 993 void WindowTree::SendToEventObserver(const ui::Event& event) {
984 if (event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event)) 994 mojo::Array<uint32_t> event_observer_ids;
985 client()->OnEventObserved(ui::Event::Clone(event), event_observer_id_); 995 std::map<uint32_t, std::unique_ptr<EventMatcher>>::iterator it;
996 for (it = event_observer_matchers_.begin();
997 it != event_observer_matchers_.end(); ++it) {
998 if(it->second->MatchesEvent(event)) {
999 event_observer_ids.push_back(it->first);
1000 }
1001 }
1002 if (!event_observer_ids.empty()) {
1003 client()->OnEventObserved(ui::Event::Clone(event),
1004 std::move(event_observer_ids));
1005 }
986 } 1006 }
987 1007
988 void WindowTree::NewWindow( 1008 void WindowTree::NewWindow(
989 uint32_t change_id, 1009 uint32_t change_id,
990 Id transport_window_id, 1010 Id transport_window_id,
991 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 1011 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
992 std::map<std::string, std::vector<uint8_t>> properties; 1012 std::map<std::string, std::vector<uint8_t>> properties;
993 if (!transport_properties.is_null()) { 1013 if (!transport_properties.is_null()) {
994 properties = 1014 properties =
995 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 1015 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 access_policy_->CanSetCapture(current_capture_window)) && 1159 access_policy_->CanSetCapture(current_capture_window)) &&
1140 window == current_capture_window; 1160 window == current_capture_window;
1141 if (success) { 1161 if (success) {
1142 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); 1162 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE);
1143 success = display_root->window_manager_state()->SetCapture( 1163 success = display_root->window_manager_state()->SetCapture(
1144 nullptr, kInvalidClientId); 1164 nullptr, kInvalidClientId);
1145 } 1165 }
1146 client()->OnChangeCompleted(change_id, success); 1166 client()->OnChangeCompleted(change_id, success);
1147 } 1167 }
1148 1168
1149 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher, 1169 void WindowTree::AddEventObserver(mojom::EventMatcherPtr matcher,
1150 uint32_t observer_id) { 1170 uint32_t observer_id) {
1151 if (matcher.is_null() || observer_id == 0) { 1171 if (matcher.is_null() || observer_id == 0) {
1152 // Clear any existing event observer.
1153 event_observer_matcher_.reset();
1154 event_observer_id_ = 0;
1155 return; 1172 return;
1156 } 1173 }
1157 1174
1158 // Do not allow key events to be observed, as a compromised app could register 1175 // Do not allow key events to be observed, as a compromised app could register
1159 // itself as an event observer and spy on keystrokes to another app. 1176 // itself as an event observer and spy on keystrokes to another app.
1160 if (!matcher->type_matcher) { 1177 if (!matcher->type_matcher && !matcher->pointer_kind_matcher) {
1161 DVLOG(1) << "SetEventObserver must specify an event type."; 1178 DVLOG(1) << "SetEventObserver must specify an event type.";
1162 return; 1179 return;
1163 } 1180 }
1181
1164 const ui::mojom::EventType event_type_whitelist[] = { 1182 const ui::mojom::EventType event_type_whitelist[] = {
1165 ui::mojom::EventType::POINTER_CANCEL, ui::mojom::EventType::POINTER_DOWN, 1183 ui::mojom::EventType::POINTER_CANCEL, ui::mojom::EventType::POINTER_DOWN,
1166 ui::mojom::EventType::POINTER_MOVE, ui::mojom::EventType::POINTER_UP, 1184 ui::mojom::EventType::POINTER_MOVE, ui::mojom::EventType::POINTER_UP,
1167 ui::mojom::EventType::MOUSE_EXIT, ui::mojom::EventType::WHEEL, 1185 ui::mojom::EventType::MOUSE_EXIT, ui::mojom::EventType::WHEEL,
1168 }; 1186 };
1187 const ui::mojom::PointerKind pointer_kind_whitelist[] = {
1188 ui::mojom::PointerKind::MOUSE, ui::mojom::PointerKind::TOUCH,
1189 };
1190
1169 bool allowed = false; 1191 bool allowed = false;
1170 for (ui::mojom::EventType event_type : event_type_whitelist) { 1192 if (matcher->type_matcher) {
1171 if (matcher->type_matcher->type == event_type) { 1193 for (ui::mojom::EventType event_type : event_type_whitelist) {
1172 allowed = true; 1194 if (matcher->type_matcher->type == event_type) {
1173 break; 1195 allowed = true;
1196 break;
1197 }
1198 }
1199 }
1200 if (matcher->pointer_kind_matcher) {
1201 for (ui::mojom::PointerKind pointer : pointer_kind_whitelist) {
1202 if (matcher->pointer_kind_matcher->pointer_kind == pointer) {
1203 allowed = true;
1204 break;
1205 }
1174 } 1206 }
1175 } 1207 }
1176 if (!allowed) { 1208 if (!allowed) {
1177 DVLOG(1) << "SetEventObserver event type not allowed"; 1209 DVLOG(1) << "SetEventObserver event type not allowed";
1178 return; 1210 return;
1179 } 1211 }
1180 1212
1181 event_observer_matcher_.reset(new EventMatcher(*matcher)); 1213 std::unique_ptr<EventMatcher> event_observer_matcher;
1182 event_observer_id_ = observer_id; 1214 event_observer_matcher.reset(new EventMatcher(*matcher));
1215 event_observer_matchers_[observer_id] = std::move(event_observer_matcher);
1216 }
1217
1218 void WindowTree::RemoveEventObserver(uint32_t observer_id) {
1219 std::map<uint32_t, std::unique_ptr<EventMatcher>>::iterator it =
1220 event_observer_matchers_.find(observer_id);
1221 if (it != event_observer_matchers_.end())
1222 event_observer_matchers_.erase(it);
1183 } 1223 }
1184 1224
1185 void WindowTree::SetWindowBounds(uint32_t change_id, 1225 void WindowTree::SetWindowBounds(uint32_t change_id,
1186 Id window_id, 1226 Id window_id,
1187 const gfx::Rect& bounds) { 1227 const gfx::Rect& bounds) {
1188 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1228 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1189 if (window && ShouldRouteToWindowManager(window)) { 1229 if (window && ShouldRouteToWindowManager(window)) {
1190 const uint32_t wm_change_id = 1230 const uint32_t wm_change_id =
1191 window_server_->GenerateWindowManagerChangeId(this, change_id); 1231 window_server_->GenerateWindowManagerChangeId(this, change_id);
1192 // |window_id| may be a client id, use the id from the window to ensure 1232 // |window_id| may be a client id, use the id from the window to ensure
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 } 1661 }
1622 1662
1623 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( 1663 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy(
1624 const ServerWindow* window) const { 1664 const ServerWindow* window) const {
1625 WindowTree* tree = window_server_->GetTreeWithRoot(window); 1665 WindowTree* tree = window_server_->GetTreeWithRoot(window);
1626 return tree && tree != this; 1666 return tree && tree != this;
1627 } 1667 }
1628 1668
1629 } // namespace ws 1669 } // namespace ws
1630 } // namespace ui 1670 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698