Chromium Code Reviews| Index: content/browser/devtools/protocol/emulation_handler.cc |
| diff --git a/content/browser/devtools/protocol/emulation_handler.cc b/content/browser/devtools/protocol/emulation_handler.cc |
| index 12c377a4fc84eab5396d2d195ded5158134a463f..875bd246dbed1181531fc92c8d03ec8f5b02d12d 100644 |
| --- a/content/browser/devtools/protocol/emulation_handler.cc |
| +++ b/content/browser/devtools/protocol/emulation_handler.cc |
| @@ -146,7 +146,15 @@ Response EmulationHandler::SetDeviceMetricsOverride( |
| const int* screen_height, |
| const int* position_x, |
| const int* position_y, |
| - const std::unique_ptr<base::DictionaryValue>& screen_orientation) { |
| + const std::unique_ptr<base::DictionaryValue>& screen_orientation, |
| + const int* scroll_position_x, |
| + const int* scroll_position_y, |
| + const int* visual_viewport_width, |
| + const int* visual_viewport_height, |
| + const double* visual_viewport_position_x, |
| + const double* visual_viewport_position_y, |
| + const double* visual_viewport_scale, |
| + const bool* resize_window) { |
| const static int max_size = 10000000; |
| const static double max_scale = 10; |
| const static int max_orientation_angle = 360; |
| @@ -207,6 +215,44 @@ Response EmulationHandler::SetDeviceMetricsOverride( |
| } |
| } |
| + if ((scroll_position_x && |
| + (*scroll_position_x < 0 || *scroll_position_x > max_size)) || |
| + (scroll_position_y && |
| + (*scroll_position_y < 0 || *scroll_position_y > max_size))) { |
| + return Response::InvalidParams( |
| + "Scroll position coordinates must be non-negative, not greater than" + |
|
Sami
2016/06/23 17:34:03
nit: missing space at the end.
Eric Seckler
2016/06/27 17:32:58
Done, also below.
|
| + base::IntToString(max_size)); |
| + } |
| + |
| + if ((visual_viewport_width && |
| + (*visual_viewport_width < 0 || *visual_viewport_width > max_size)) || |
| + (visual_viewport_height && |
| + (*visual_viewport_height < 0 || *visual_viewport_height > max_size))) { |
| + return Response::InvalidParams( |
| + "Visible_width and visible_height values must be positive, not greater " |
| + "than " + |
| + base::IntToString(max_size)); |
| + } |
| + |
| + if ((visual_viewport_position_x && |
| + (*visual_viewport_position_x < 0 || |
| + *visual_viewport_position_x > max_size)) || |
| + (visual_viewport_position_y && |
| + (*visual_viewport_position_y < 0 || |
| + *visual_viewport_position_y > max_size))) { |
| + return Response::InvalidParams( |
| + "Visual viewport position coordinates must be non-negative, not " |
| + "greater than" + |
| + base::IntToString(max_size)); |
| + } |
| + |
| + if (visual_viewport_scale && |
| + (*visual_viewport_scale <= 0 || *visual_viewport_scale > max_scale)) { |
| + return Response::InvalidParams( |
| + "Scale must be positive and not greater than " + |
| + base::DoubleToString(max_scale)); |
| + } |
| + |
| blink::WebDeviceEmulationParams params; |
| params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : |
| blink::WebDeviceEmulationParams::Desktop; |
| @@ -223,6 +269,18 @@ Response EmulationHandler::SetDeviceMetricsOverride( |
| optional_offset_y ? *optional_offset_y : 0.f); |
| params.screenOrientationType = orientationType; |
| params.screenOrientationAngle = orientationAngle; |
| + params.scrollPosition = |
| + blink::WebPoint(scroll_position_x ? *scroll_position_x : -1, |
| + scroll_position_y ? *scroll_position_y : -1); |
| + params.visualViewportSize = |
| + blink::WebSize(visual_viewport_width ? *visual_viewport_width : 0, |
| + visual_viewport_height ? *visual_viewport_height : 0); |
| + params.visualViewportPosition = blink::WebFloatPoint( |
| + visual_viewport_position_x ? *visual_viewport_position_x : -1, |
| + visual_viewport_position_y ? *visual_viewport_position_y : -1); |
| + params.visualViewportScale = |
| + visual_viewport_scale ? *visual_viewport_scale : 0; |
| + params.resizeWindow = resize_window ? *resize_window : false; |
| if (device_emulation_enabled_ && params == device_emulation_params_) |
| return Response::OK(); |
| @@ -266,6 +324,9 @@ void EmulationHandler::UpdateDeviceEmulationState() { |
| host_ ? host_->GetRenderWidgetHost() : nullptr; |
| if (!widget_host) |
| return; |
| + |
| + // TODO(eseckler) handle |resize_window| |
| + |
| if (device_emulation_enabled_) { |
| widget_host->Send(new ViewMsg_EnableDeviceEmulation( |
| widget_host->GetRoutingID(), device_emulation_params_)); |