Add ICU message format support
[chromium-blink-merge.git] / content / common / input / input_event_stream_validator.cc
blobf8a39994b4562fcae991069714bd67f9b42198bc
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/common/input/web_input_event_traits.h"
10 #include "content/public/common/content_switches.h"
11 #include "third_party/WebKit/public/web/WebInputEvent.h"
13 using blink::WebInputEvent;
14 using blink::WebGestureEvent;
15 using blink::WebTouchEvent;
17 namespace content {
19 InputEventStreamValidator::InputEventStreamValidator()
20 : enabled_(base::CommandLine::ForCurrentProcess()->HasSwitch(
21 switches::kValidateInputEventStream)) {
24 InputEventStreamValidator::~InputEventStreamValidator() {
27 void InputEventStreamValidator::Validate(const WebInputEvent& event) {
28 if (!enabled_)
29 return;
31 DCHECK(ValidateImpl(event, &error_msg_))
32 << error_msg_
33 << "\nInvalid Event: " << WebInputEventTraits::ToString(event);
36 bool InputEventStreamValidator::ValidateImpl(const blink::WebInputEvent& event,
37 std::string* error_msg) {
38 DCHECK(error_msg);
39 if (WebInputEvent::isGestureEventType(event.type)) {
40 const WebGestureEvent& gesture = static_cast<const WebGestureEvent&>(event);
41 // TODO(jdduke): Validate touchpad gesture streams.
42 if (gesture.sourceDevice == blink::WebGestureDeviceTouchscreen)
43 return gesture_validator_.Validate(gesture, error_msg);
44 } else if (WebInputEvent::isTouchEventType(event.type)) {
45 const WebTouchEvent& touch = static_cast<const WebTouchEvent&>(event);
46 return touch_validator_.Validate(touch, error_msg);
48 return true;
51 } // namespace content