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

Unified Diff: content/browser/devtools/protocol/input_handler.cc

Issue 2868943004: Validate input from devtools channel to ensure that position is valid. (Closed)
Patch Set: Add param name Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/devtools/protocol/input_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/devtools/protocol/input_handler.cc
diff --git a/content/browser/devtools/protocol/input_handler.cc b/content/browser/devtools/protocol/input_handler.cc
index cadff830717077c5d4a4ca6d0716f6fec6032d4e..967dd2cd21e0a91ca65631cfd8d26ecea4d3a5ba 100644
--- a/content/browser/devtools/protocol/input_handler.cc
+++ b/content/browser/devtools/protocol/input_handler.cc
@@ -475,6 +475,11 @@ void InputHandler::SynthesizePinchGesture(
gesture_params.scale_factor = scale_factor;
gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_);
+ if (!PointIsWithinContents(gesture_params.anchor)) {
+ callback->sendFailure(Response::InvalidParams("Position out of bounds"));
+ return;
+ }
+
gesture_params.relative_pointer_speed_in_pixels_s =
relative_speed.fromMaybe(kDefaultRelativeSpeed);
@@ -516,11 +521,16 @@ void InputHandler::SynthesizeScrollGesture(
const int kDefaultSpeed = 800;
gesture_params.anchor = CssPixelsToPointF(x, y, page_scale_factor_);
+ if (!PointIsWithinContents(gesture_params.anchor)) {
+ callback->sendFailure(Response::InvalidParams("Position out of bounds"));
+ return;
+ }
+
gesture_params.prevent_fling =
prevent_fling.fromMaybe(kDefaultPreventFling);
gesture_params.speed_in_pixels_s = speed.fromMaybe(kDefaultSpeed);
- if (x_distance.fromJust() || y_distance.fromJust()) {
+ if (x_distance.isJust() || y_distance.isJust()) {
gesture_params.distances.push_back(
CssPixelsToVector2dF(x_distance.fromMaybe(0),
y_distance.fromMaybe(0), page_scale_factor_));
@@ -610,6 +620,11 @@ void InputHandler::SynthesizeTapGesture(
const int kDefaultTapCount = 1;
gesture_params.position = CssPixelsToPointF(x, y, page_scale_factor_);
+ if (!PointIsWithinContents(gesture_params.position)) {
+ callback->sendFailure(Response::InvalidParams("Position out of bounds"));
+ return;
+ }
+
gesture_params.duration_ms = duration.fromMaybe(kDefaultDuration);
if (!StringToGestureSourceType(
@@ -645,5 +660,11 @@ void InputHandler::ClearPendingKeyAndMouseCallbacks() {
pending_mouse_callbacks_.clear();
}
+bool InputHandler::PointIsWithinContents(gfx::PointF point) const {
+ gfx::Rect bounds = host_->GetView()->GetViewBounds();
+ bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0).
+ return bounds.Contains(point.x(), point.y());
+}
+
} // namespace protocol
} // namespace content
« no previous file with comments | « content/browser/devtools/protocol/input_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698