| OLD | NEW |
| 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/input_event_stream_validator.h" | 5 #include "content/common/input/input_event_stream_validator.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/common/input/web_input_event_traits.h" | |
| 10 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 11 #include "third_party/WebKit/public/web/WebInputEvent.h" | 10 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 11 #include "ui/events/blink/web_input_event_traits.h" |
| 12 | 12 |
| 13 using blink::WebInputEvent; | 13 using blink::WebInputEvent; |
| 14 using blink::WebGestureEvent; | 14 using blink::WebGestureEvent; |
| 15 using blink::WebTouchEvent; | 15 using blink::WebTouchEvent; |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 InputEventStreamValidator::InputEventStreamValidator() | 19 InputEventStreamValidator::InputEventStreamValidator() |
| 20 : enabled_(base::CommandLine::ForCurrentProcess()->HasSwitch( | 20 : enabled_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 21 switches::kValidateInputEventStream)) { | 21 switches::kValidateInputEventStream)) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 InputEventStreamValidator::~InputEventStreamValidator() { | 24 InputEventStreamValidator::~InputEventStreamValidator() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 void InputEventStreamValidator::Validate(const WebInputEvent& event) { | 27 void InputEventStreamValidator::Validate(const WebInputEvent& event) { |
| 28 if (!enabled_) | 28 if (!enabled_) |
| 29 return; | 29 return; |
| 30 | 30 |
| 31 DCHECK(ValidateImpl(event, &error_msg_)) | 31 DCHECK(ValidateImpl(event, &error_msg_)) |
| 32 << error_msg_ | 32 << error_msg_ |
| 33 << "\nInvalid Event: " << WebInputEventTraits::ToString(event); | 33 << "\nInvalid Event: " << ui::WebInputEventTraits::ToString(event); |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool InputEventStreamValidator::ValidateImpl(const blink::WebInputEvent& event, | 36 bool InputEventStreamValidator::ValidateImpl(const blink::WebInputEvent& event, |
| 37 std::string* error_msg) { | 37 std::string* error_msg) { |
| 38 DCHECK(error_msg); | 38 DCHECK(error_msg); |
| 39 if (WebInputEvent::isGestureEventType(event.type)) { | 39 if (WebInputEvent::isGestureEventType(event.type)) { |
| 40 const WebGestureEvent& gesture = static_cast<const WebGestureEvent&>(event); | 40 const WebGestureEvent& gesture = static_cast<const WebGestureEvent&>(event); |
| 41 // TODO(jdduke): Validate touchpad gesture streams. | 41 // TODO(jdduke): Validate touchpad gesture streams. |
| 42 if (gesture.sourceDevice == blink::WebGestureDeviceTouchscreen) | 42 if (gesture.sourceDevice == blink::WebGestureDeviceTouchscreen) |
| 43 return gesture_validator_.Validate(gesture, error_msg); | 43 return gesture_validator_.Validate(gesture, error_msg); |
| 44 } else if (WebInputEvent::isTouchEventType(event.type)) { | 44 } else if (WebInputEvent::isTouchEventType(event.type)) { |
| 45 const WebTouchEvent& touch = static_cast<const WebTouchEvent&>(event); | 45 const WebTouchEvent& touch = static_cast<const WebTouchEvent&>(event); |
| 46 return touch_validator_.Validate(touch, error_msg); | 46 return touch_validator_.Validate(touch, error_msg); |
| 47 } | 47 } |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace content | 51 } // namespace content |
| OLD | NEW |