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

Side by Side Diff: content/common/input/touch_event_stream_validator.cc

Issue 537733003: [Android] Enable input event stream validation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review and fix tests Created 6 years, 3 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 "content/common/input/touch_event_stream_validator.h" 5 #include "content/common/input/touch_event_stream_validator.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/input/web_touch_event_traits.h" 8 #include "content/common/input/web_touch_event_traits.h"
9 9
10 using blink::WebInputEvent; 10 using blink::WebInputEvent;
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 32
33 bool TouchEventStreamValidator::Validate(const WebTouchEvent& event, 33 bool TouchEventStreamValidator::Validate(const WebTouchEvent& event,
34 std::string* error_msg) { 34 std::string* error_msg) {
35 DCHECK(error_msg); 35 DCHECK(error_msg);
36 error_msg->clear(); 36 error_msg->clear();
37 37
38 WebTouchEvent previous_event = previous_event_; 38 WebTouchEvent previous_event = previous_event_;
39 previous_event_ = event; 39 previous_event_ = event;
40 40
41 if (!event.touchesLength) {
42 error_msg->append("Touch event is empty.\n");
43 return false;
44 }
45
46 if (!WebInputEvent::isTouchEventType(event.type))
47 error_msg->append("Touch event has invalid type.\n");
48
41 // Allow "hard" restarting of touch stream validation. This is necessary 49 // Allow "hard" restarting of touch stream validation. This is necessary
42 // in cases where touch event forwarding ceases in response to the event ack 50 // in cases where touch event forwarding ceases in response to the event ack
43 // or removal of touch handlers. 51 // or removal of touch handlers.
44 if (WebTouchEventTraits::IsTouchSequenceStart(event)) 52 if (WebTouchEventTraits::IsTouchSequenceStart(event))
45 previous_event = WebTouchEvent(); 53 previous_event = WebTouchEvent();
46 54
47 // Unreleased points from the previous event should exist in the latest event. 55 // Unreleased points from the previous event should exist in the latest event.
48 for (unsigned i = 0; i < previous_event.touchesLength; ++i) { 56 for (unsigned i = 0; i < previous_event.touchesLength; ++i) {
49 const WebTouchPoint& previous_point = previous_event.touches[i]; 57 const WebTouchPoint& previous_point = previous_event.touches[i];
50 if (previous_point.state == WebTouchPoint::StateCancelled || 58 if (previous_point.state == WebTouchPoint::StateCancelled ||
51 previous_point.state == WebTouchPoint::StateReleased) 59 previous_point.state == WebTouchPoint::StateReleased)
52 continue; 60 continue;
53 61
54 const WebTouchPoint* point = FindTouchPoint(event, previous_point.id); 62 const WebTouchPoint* point = FindTouchPoint(event, previous_point.id);
55 if (!point) 63 if (!point)
56 error_msg->append("Previously active touch point not in new event.\n"); 64 error_msg->append("Previously active touch point not in new event.\n");
57 } 65 }
58 66
67 bool found_valid_state_for_type = false;
59 for (unsigned i = 0; i < event.touchesLength; ++i) { 68 for (unsigned i = 0; i < event.touchesLength; ++i) {
60 const WebTouchPoint& point = event.touches[i]; 69 const WebTouchPoint& point = event.touches[i];
61 const WebTouchPoint* previous_point = 70 const WebTouchPoint* previous_point =
62 FindTouchPoint(previous_event, point.id); 71 FindTouchPoint(previous_event, point.id);
63 72
64 // The point should exist in the previous event if it is not a new point. 73 // The point should exist in the previous event if it is not a new point.
65 if (!previous_point) { 74 if (!previous_point) {
66 if (point.state != WebTouchPoint::StatePressed) 75 if (point.state != WebTouchPoint::StatePressed)
67 error_msg->append("Active touch point not found in previous event.\n"); 76 error_msg->append("Active touch point not found in previous event.\n");
68 } else { 77 } else {
69 if (point.state == WebTouchPoint::StatePressed && 78 if (point.state == WebTouchPoint::StatePressed &&
70 previous_point->state != WebTouchPoint::StateCancelled && 79 previous_point->state != WebTouchPoint::StateCancelled &&
71 previous_point->state != WebTouchPoint::StateReleased) { 80 previous_point->state != WebTouchPoint::StateReleased) {
72 error_msg->append("Pressed touch point id already exists.\n"); 81 error_msg->append("Pressed touch point id already exists.\n");
73 } 82 }
74 } 83 }
75 84
76 switch (point.state) { 85 switch (point.state) {
77 case WebTouchPoint::StateUndefined: 86 case WebTouchPoint::StateUndefined:
78 error_msg->append("Undefined WebTouchPoint state.\n"); 87 error_msg->append("Undefined WebTouchPoint state.\n");
79 break; 88 break;
80 89
81 case WebTouchPoint::StateReleased: 90 case WebTouchPoint::StateReleased:
82 if (event.type != WebInputEvent::TouchEnd) 91 if (event.type != WebInputEvent::TouchEnd)
83 error_msg->append("Released touch point outside touchend.\n"); 92 error_msg->append("Released touch point outside touchend.\n");
93 else
94 found_valid_state_for_type = true;
84 break; 95 break;
85 96
86 case WebTouchPoint::StatePressed: 97 case WebTouchPoint::StatePressed:
87 if (event.type != WebInputEvent::TouchStart) 98 if (event.type != WebInputEvent::TouchStart)
88 error_msg->append("Pressed touch point outside touchstart.\n"); 99 error_msg->append("Pressed touch point outside touchstart.\n");
100 else
101 found_valid_state_for_type = true;
89 break; 102 break;
90 103
91 case WebTouchPoint::StateMoved: 104 case WebTouchPoint::StateMoved:
92 if (event.type != WebInputEvent::TouchMove) 105 if (event.type != WebInputEvent::TouchMove)
93 error_msg->append("Moved touch point outside touchmove.\n"); 106 error_msg->append("Moved touch point outside touchmove.\n");
107 else
108 found_valid_state_for_type = true;
94 break; 109 break;
95 110
96 case WebTouchPoint::StateStationary: 111 case WebTouchPoint::StateStationary:
97 break; 112 break;
98 113
99 case WebTouchPoint::StateCancelled: 114 case WebTouchPoint::StateCancelled:
100 if (event.type != WebInputEvent::TouchCancel) 115 if (event.type != WebInputEvent::TouchCancel)
101 error_msg->append("Cancelled touch point outside touchcancel.\n"); 116 error_msg->append("Cancelled touch point outside touchcancel.\n");
117 else
118 found_valid_state_for_type = true;
102 break; 119 break;
103 } 120 }
104 } 121 }
122
123 if (!found_valid_state_for_type)
124 error_msg->append("No valid touch point corresponding to event type.");
125
105 return error_msg->empty(); 126 return error_msg->empty();
106 } 127 }
107 128
108 } // namespace content 129 } // namespace content
OLDNEW
« no previous file with comments | « content/common/input/touch_event_stream_validator.h ('k') | content/common/input/touch_event_stream_validator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698