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. 4 5 #include "content/common/input/input_event_stream_validator.h" 6 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" 11 12 using blink::WebInputEvent; 13 using blink::WebGestureEvent; 14 using blink::WebTouchEvent; 15 16 namespace content { 17 18 InputEventStreamValidator::InputEventStreamValidator() 19 : enabled_(CommandLine::ForCurrentProcess()->HasSwitch( 20 switches::kValidateInputEventStream)) { 21 } 22 23 InputEventStreamValidator::~InputEventStreamValidator() { 24 } 25 26 void InputEventStreamValidator::Validate(const WebInputEvent& event) { 27 if (!enabled_) 28 return; 29 30 DCHECK(ValidateImpl(event, &error_msg_)) << error_msg_; 31 } 32 33 bool InputEventStreamValidator::ValidateImpl(const blink::WebInputEvent& event, 34 std::string* error_msg) { 35 DCHECK(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); 44 } 45 return true; 46 } 47 48 } // namespace content 49