OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/devtools/protocol/emulation_handler.h" | 5 #include "content/browser/devtools/protocol/emulation_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 double device_scale_factor, | 139 double device_scale_factor, |
140 bool mobile, | 140 bool mobile, |
141 bool fit_window, | 141 bool fit_window, |
142 const double* optional_scale, | 142 const double* optional_scale, |
143 const double* optional_offset_x, | 143 const double* optional_offset_x, |
144 const double* optional_offset_y, | 144 const double* optional_offset_y, |
145 const int* screen_width, | 145 const int* screen_width, |
146 const int* screen_height, | 146 const int* screen_height, |
147 const int* position_x, | 147 const int* position_x, |
148 const int* position_y, | 148 const int* position_y, |
149 const std::unique_ptr<base::DictionaryValue>& screen_orientation) { | 149 const std::unique_ptr<base::DictionaryValue>& screen_orientation, |
150 const int* scroll_position_x, | |
151 const int* scroll_position_y, | |
152 const int* visual_viewport_width, | |
153 const int* visual_viewport_height, | |
154 const double* visual_viewport_position_x, | |
155 const double* visual_viewport_position_y, | |
156 const double* visual_viewport_scale, | |
157 const bool* resize_window) { | |
150 const static int max_size = 10000000; | 158 const static int max_size = 10000000; |
151 const static double max_scale = 10; | 159 const static double max_scale = 10; |
152 const static int max_orientation_angle = 360; | 160 const static int max_orientation_angle = 360; |
153 | 161 |
154 if (!host_) | 162 if (!host_) |
155 return Response::InternalError("Could not connect to view"); | 163 return Response::InternalError("Could not connect to view"); |
156 | 164 |
157 if (screen_width && screen_height && | 165 if (screen_width && screen_height && |
158 (*screen_width < 0 || *screen_height < 0 || | 166 (*screen_width < 0 || *screen_height < 0 || |
159 *screen_width > max_size || *screen_height > max_size)) { | 167 *screen_width > max_size || *screen_height > max_size)) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 return Response::InvalidParams( | 208 return Response::InvalidParams( |
201 "Screen orientation angle must be a number"); | 209 "Screen orientation angle must be a number"); |
202 } | 210 } |
203 if (orientationAngle < 0 || orientationAngle >= max_orientation_angle) { | 211 if (orientationAngle < 0 || orientationAngle >= max_orientation_angle) { |
204 return Response::InvalidParams( | 212 return Response::InvalidParams( |
205 "Screen orientation angle must be non-negative, less than " + | 213 "Screen orientation angle must be non-negative, less than " + |
206 base::IntToString(max_orientation_angle)); | 214 base::IntToString(max_orientation_angle)); |
207 } | 215 } |
208 } | 216 } |
209 | 217 |
218 if ((scroll_position_x && | |
219 (*scroll_position_x < 0 || *scroll_position_x > max_size)) || | |
220 (scroll_position_y && | |
221 (*scroll_position_y < 0 || *scroll_position_y > max_size))) { | |
222 return Response::InvalidParams( | |
223 "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.
| |
224 base::IntToString(max_size)); | |
225 } | |
226 | |
227 if ((visual_viewport_width && | |
228 (*visual_viewport_width < 0 || *visual_viewport_width > max_size)) || | |
229 (visual_viewport_height && | |
230 (*visual_viewport_height < 0 || *visual_viewport_height > max_size))) { | |
231 return Response::InvalidParams( | |
232 "Visible_width and visible_height values must be positive, not greater " | |
233 "than " + | |
234 base::IntToString(max_size)); | |
235 } | |
236 | |
237 if ((visual_viewport_position_x && | |
238 (*visual_viewport_position_x < 0 || | |
239 *visual_viewport_position_x > max_size)) || | |
240 (visual_viewport_position_y && | |
241 (*visual_viewport_position_y < 0 || | |
242 *visual_viewport_position_y > max_size))) { | |
243 return Response::InvalidParams( | |
244 "Visual viewport position coordinates must be non-negative, not " | |
245 "greater than" + | |
246 base::IntToString(max_size)); | |
247 } | |
248 | |
249 if (visual_viewport_scale && | |
250 (*visual_viewport_scale <= 0 || *visual_viewport_scale > max_scale)) { | |
251 return Response::InvalidParams( | |
252 "Scale must be positive and not greater than " + | |
253 base::DoubleToString(max_scale)); | |
254 } | |
255 | |
210 blink::WebDeviceEmulationParams params; | 256 blink::WebDeviceEmulationParams params; |
211 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : | 257 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : |
212 blink::WebDeviceEmulationParams::Desktop; | 258 blink::WebDeviceEmulationParams::Desktop; |
213 if (screen_width && screen_height) | 259 if (screen_width && screen_height) |
214 params.screenSize = blink::WebSize(*screen_width, *screen_height); | 260 params.screenSize = blink::WebSize(*screen_width, *screen_height); |
215 if (position_x && position_y) | 261 if (position_x && position_y) |
216 params.viewPosition = blink::WebPoint(*position_x, *position_y); | 262 params.viewPosition = blink::WebPoint(*position_x, *position_y); |
217 params.deviceScaleFactor = device_scale_factor; | 263 params.deviceScaleFactor = device_scale_factor; |
218 params.viewSize = blink::WebSize(width, height); | 264 params.viewSize = blink::WebSize(width, height); |
219 params.fitToView = fit_window; | 265 params.fitToView = fit_window; |
220 params.scale = optional_scale ? *optional_scale : 1; | 266 params.scale = optional_scale ? *optional_scale : 1; |
221 params.offset = blink::WebFloatPoint( | 267 params.offset = blink::WebFloatPoint( |
222 optional_offset_x ? *optional_offset_x : 0.f, | 268 optional_offset_x ? *optional_offset_x : 0.f, |
223 optional_offset_y ? *optional_offset_y : 0.f); | 269 optional_offset_y ? *optional_offset_y : 0.f); |
224 params.screenOrientationType = orientationType; | 270 params.screenOrientationType = orientationType; |
225 params.screenOrientationAngle = orientationAngle; | 271 params.screenOrientationAngle = orientationAngle; |
272 params.scrollPosition = | |
273 blink::WebPoint(scroll_position_x ? *scroll_position_x : -1, | |
274 scroll_position_y ? *scroll_position_y : -1); | |
275 params.visualViewportSize = | |
276 blink::WebSize(visual_viewport_width ? *visual_viewport_width : 0, | |
277 visual_viewport_height ? *visual_viewport_height : 0); | |
278 params.visualViewportPosition = blink::WebFloatPoint( | |
279 visual_viewport_position_x ? *visual_viewport_position_x : -1, | |
280 visual_viewport_position_y ? *visual_viewport_position_y : -1); | |
281 params.visualViewportScale = | |
282 visual_viewport_scale ? *visual_viewport_scale : 0; | |
283 params.resizeWindow = resize_window ? *resize_window : false; | |
226 | 284 |
227 if (device_emulation_enabled_ && params == device_emulation_params_) | 285 if (device_emulation_enabled_ && params == device_emulation_params_) |
228 return Response::OK(); | 286 return Response::OK(); |
229 | 287 |
230 device_emulation_enabled_ = true; | 288 device_emulation_enabled_ = true; |
231 device_emulation_params_ = params; | 289 device_emulation_params_ = params; |
232 UpdateDeviceEmulationState(); | 290 UpdateDeviceEmulationState(); |
233 return Response::OK(); | 291 return Response::OK(); |
234 } | 292 } |
235 | 293 |
(...skipping 23 matching lines...) Expand all Loading... | |
259 widget_host->SetTouchEventEmulationEnabled(enabled, config_type); | 317 widget_host->SetTouchEventEmulationEnabled(enabled, config_type); |
260 if (GetWebContents()) | 318 if (GetWebContents()) |
261 GetWebContents()->SetForceDisableOverscrollContent(enabled); | 319 GetWebContents()->SetForceDisableOverscrollContent(enabled); |
262 } | 320 } |
263 | 321 |
264 void EmulationHandler::UpdateDeviceEmulationState() { | 322 void EmulationHandler::UpdateDeviceEmulationState() { |
265 RenderWidgetHostImpl* widget_host = | 323 RenderWidgetHostImpl* widget_host = |
266 host_ ? host_->GetRenderWidgetHost() : nullptr; | 324 host_ ? host_->GetRenderWidgetHost() : nullptr; |
267 if (!widget_host) | 325 if (!widget_host) |
268 return; | 326 return; |
327 | |
328 // TODO(eseckler) handle |resize_window| | |
329 | |
269 if (device_emulation_enabled_) { | 330 if (device_emulation_enabled_) { |
270 widget_host->Send(new ViewMsg_EnableDeviceEmulation( | 331 widget_host->Send(new ViewMsg_EnableDeviceEmulation( |
271 widget_host->GetRoutingID(), device_emulation_params_)); | 332 widget_host->GetRoutingID(), device_emulation_params_)); |
272 } else { | 333 } else { |
273 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 334 widget_host->Send(new ViewMsg_DisableDeviceEmulation( |
274 widget_host->GetRoutingID())); | 335 widget_host->GetRoutingID())); |
275 } | 336 } |
276 } | 337 } |
277 | 338 |
278 } // namespace emulation | 339 } // namespace emulation |
279 } // namespace devtools | 340 } // namespace devtools |
280 } // namespace content | 341 } // namespace content |
OLD | NEW |