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

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

Issue 290473006: Add a TouchEventStreamValidator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 6 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/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/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
10 #include "third_party/WebKit/public/web/WebInputEvent.h" 10 #include "third_party/WebKit/public/web/WebInputEvent.h"
11 11
12 using blink::WebInputEvent;
13 using blink::WebGestureEvent;
14 using blink::WebTouchEvent;
15
12 namespace content { 16 namespace content {
13 17
14 using blink::WebInputEvent; 18 InputEventStreamValidator::InputEventStreamValidator()
15 using blink::WebGestureEvent; 19 : enabled_(CommandLine::ForCurrentProcess()->HasSwitch(
20 switches::kValidateInputEventStream)) {
21 }
16 22
17 InputEventStreamValidator::InputEventStreamValidator() { 23 InputEventStreamValidator::~InputEventStreamValidator() {
18 CommandLine* command_line = CommandLine::ForCurrentProcess();
19 enabled_ = command_line->HasSwitch(switches::kValidateInputEventStream);
20 } 24 }
21 InputEventStreamValidator::~InputEventStreamValidator() {}
22 25
23 void InputEventStreamValidator::OnEvent(const WebInputEvent& event) { 26 void InputEventStreamValidator::Validate(const WebInputEvent& event) {
24 if (!enabled_) 27 if (!enabled_)
25 return; 28 return;
26 const char* error_message = NULL; 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);
27 if (WebInputEvent::isGestureEventType(event.type)) { 36 if (WebInputEvent::isGestureEventType(event.type)) {
28 const WebGestureEvent& gesture_event = 37 const WebGestureEvent& gesture = static_cast<const WebGestureEvent&>(event);
29 static_cast<const WebGestureEvent&>(event); 38 // TODO(jdduke): Validate touchpad gesture streams.
30 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchscreen) { 39 if (gesture.sourceDevice == blink::WebGestureDeviceTouchscreen)
31 if (!gesture_validator_.Validate(gesture_event, &error_message)) 40 return gesture_validator_.Validate(gesture, error_msg);
32 NOTREACHED() << error_message; 41 } else if (WebInputEvent::isTouchEventType(event.type)) {
33 } 42 const WebTouchEvent& touch = static_cast<const WebTouchEvent&>(event);
43 return touch_validator_.Validate(touch, error_msg);
34 } 44 }
45 return true;
35 } 46 }
36 47
37 } // namespace content 48 } // namespace content
OLDNEW
« no previous file with comments | « content/common/input/input_event_stream_validator.h ('k') | content/common/input/touch_event_stream_validator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698