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
3 // found in the LICENSE file.
5 #include "content/common/input/input_event_stream_validator.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "content/public/common/content_switches.h"
10 #include "third_party/WebKit/public/web/WebInputEvent.h"
12 using blink::WebInputEvent
;
13 using blink::WebGestureEvent
;
14 using blink::WebTouchEvent
;
18 InputEventStreamValidator::InputEventStreamValidator()
19 : enabled_(CommandLine::ForCurrentProcess()->HasSwitch(
20 switches::kValidateInputEventStream
)) {
23 InputEventStreamValidator::~InputEventStreamValidator() {
26 void InputEventStreamValidator::Validate(const WebInputEvent
& event
) {
30 DCHECK(ValidateImpl(event
, &error_msg_
)) << error_msg_
;
33 bool InputEventStreamValidator::ValidateImpl(const blink::WebInputEvent
& event
,
34 std::string
* error_msg
) {
36 if (WebInputEvent::isGestureEventType(event
.type
)) {
37 const WebGestureEvent
& gesture
= static_cast<const WebGestureEvent
&>(event
);
38 // TODO(jdduke): Validate touchpad gesture streams.
39 if (gesture
.sourceDevice
== blink::WebGestureDeviceTouchscreen
)
40 return gesture_validator_
.Validate(gesture
, error_msg
);
41 } else if (WebInputEvent::isTouchEventType(event
.type
)) {
42 const WebTouchEvent
& touch
= static_cast<const WebTouchEvent
&>(event
);
43 return touch_validator_
.Validate(touch
, error_msg
);
48 } // namespace content