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) { |
150 const static int max_size = 10000000; | 157 const static int max_size = 10000000; |
151 const static double max_scale = 10; | 158 const static double max_scale = 10; |
152 const static int max_orientation_angle = 360; | 159 const static int max_orientation_angle = 360; |
153 | 160 |
154 if (!host_) | 161 if (!host_) |
155 return Response::InternalError("Could not connect to view"); | 162 return Response::InternalError("Could not connect to view"); |
156 | 163 |
157 if (screen_width && screen_height && | 164 if (screen_width && screen_height && |
158 (*screen_width < 0 || *screen_height < 0 || | 165 (*screen_width < 0 || *screen_height < 0 || |
159 *screen_width > max_size || *screen_height > max_size)) { | 166 *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( | 207 return Response::InvalidParams( |
201 "Screen orientation angle must be a number"); | 208 "Screen orientation angle must be a number"); |
202 } | 209 } |
203 if (orientationAngle < 0 || orientationAngle >= max_orientation_angle) { | 210 if (orientationAngle < 0 || orientationAngle >= max_orientation_angle) { |
204 return Response::InvalidParams( | 211 return Response::InvalidParams( |
205 "Screen orientation angle must be non-negative, less than " + | 212 "Screen orientation angle must be non-negative, less than " + |
206 base::IntToString(max_orientation_angle)); | 213 base::IntToString(max_orientation_angle)); |
207 } | 214 } |
208 } | 215 } |
209 | 216 |
| 217 if ((scroll_position_x && |
| 218 (*scroll_position_x < 0 || *scroll_position_x > max_size)) || |
| 219 (scroll_position_y && |
| 220 (*scroll_position_y < 0 || *scroll_position_y > max_size))) { |
| 221 return Response::InvalidParams( |
| 222 "Scroll position coordinates must be non-negative, not greater than " + |
| 223 base::IntToString(max_size)); |
| 224 } |
| 225 |
| 226 if ((visual_viewport_width && |
| 227 (*visual_viewport_width < 0 || *visual_viewport_width > max_size)) || |
| 228 (visual_viewport_height && |
| 229 (*visual_viewport_height < 0 || *visual_viewport_height > max_size))) { |
| 230 return Response::InvalidParams( |
| 231 "Visible_width and visible_height values must be positive, not greater " |
| 232 "than " + |
| 233 base::IntToString(max_size)); |
| 234 } |
| 235 |
| 236 if ((visual_viewport_position_x && |
| 237 (*visual_viewport_position_x < 0 || |
| 238 *visual_viewport_position_x > max_size)) || |
| 239 (visual_viewport_position_y && |
| 240 (*visual_viewport_position_y < 0 || |
| 241 *visual_viewport_position_y > max_size))) { |
| 242 return Response::InvalidParams( |
| 243 "Visual viewport position coordinates must be non-negative, not " |
| 244 "greater than " + |
| 245 base::IntToString(max_size)); |
| 246 } |
| 247 |
| 248 if (visual_viewport_scale && |
| 249 (*visual_viewport_scale <= 0 || *visual_viewport_scale > max_scale)) { |
| 250 return Response::InvalidParams( |
| 251 "Scale must be positive and not greater than " + |
| 252 base::DoubleToString(max_scale)); |
| 253 } |
| 254 |
210 blink::WebDeviceEmulationParams params; | 255 blink::WebDeviceEmulationParams params; |
211 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : | 256 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : |
212 blink::WebDeviceEmulationParams::Desktop; | 257 blink::WebDeviceEmulationParams::Desktop; |
213 if (screen_width && screen_height) | 258 if (screen_width && screen_height) |
214 params.screenSize = blink::WebSize(*screen_width, *screen_height); | 259 params.screenSize = blink::WebSize(*screen_width, *screen_height); |
215 if (position_x && position_y) | 260 if (position_x && position_y) |
216 params.viewPosition = blink::WebPoint(*position_x, *position_y); | 261 params.viewPosition = blink::WebPoint(*position_x, *position_y); |
217 params.deviceScaleFactor = device_scale_factor; | 262 params.deviceScaleFactor = device_scale_factor; |
218 params.viewSize = blink::WebSize(width, height); | 263 params.viewSize = blink::WebSize(width, height); |
219 params.fitToView = fit_window; | 264 params.fitToView = fit_window; |
220 params.scale = optional_scale ? *optional_scale : 1; | 265 params.scale = optional_scale ? *optional_scale : 1; |
221 params.offset = blink::WebFloatPoint( | 266 params.offset = blink::WebFloatPoint( |
222 optional_offset_x ? *optional_offset_x : 0.f, | 267 optional_offset_x ? *optional_offset_x : 0.f, |
223 optional_offset_y ? *optional_offset_y : 0.f); | 268 optional_offset_y ? *optional_offset_y : 0.f); |
224 params.screenOrientationType = orientationType; | 269 params.screenOrientationType = orientationType; |
225 params.screenOrientationAngle = orientationAngle; | 270 params.screenOrientationAngle = orientationAngle; |
| 271 params.scrollPosition = |
| 272 blink::WebPoint(scroll_position_x ? *scroll_position_x : -1, |
| 273 scroll_position_y ? *scroll_position_y : -1); |
| 274 params.visualViewportSize = |
| 275 blink::WebSize(visual_viewport_width ? *visual_viewport_width : 0, |
| 276 visual_viewport_height ? *visual_viewport_height : 0); |
| 277 params.visualViewportPosition = blink::WebFloatPoint( |
| 278 visual_viewport_position_x ? *visual_viewport_position_x : -1, |
| 279 visual_viewport_position_y ? *visual_viewport_position_y : -1); |
| 280 params.visualViewportScale = |
| 281 visual_viewport_scale ? *visual_viewport_scale : 0; |
226 | 282 |
227 if (device_emulation_enabled_ && params == device_emulation_params_) | 283 if (device_emulation_enabled_ && params == device_emulation_params_) |
228 return Response::OK(); | 284 return Response::OK(); |
229 | 285 |
230 device_emulation_enabled_ = true; | 286 device_emulation_enabled_ = true; |
231 device_emulation_params_ = params; | 287 device_emulation_params_ = params; |
232 UpdateDeviceEmulationState(); | 288 UpdateDeviceEmulationState(); |
233 return Response::OK(); | 289 return Response::OK(); |
234 } | 290 } |
235 | 291 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 widget_host->GetRoutingID(), device_emulation_params_)); | 327 widget_host->GetRoutingID(), device_emulation_params_)); |
272 } else { | 328 } else { |
273 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 329 widget_host->Send(new ViewMsg_DisableDeviceEmulation( |
274 widget_host->GetRoutingID())); | 330 widget_host->GetRoutingID())); |
275 } | 331 } |
276 } | 332 } |
277 | 333 |
278 } // namespace emulation | 334 } // namespace emulation |
279 } // namespace devtools | 335 } // namespace devtools |
280 } // namespace content | 336 } // namespace content |
OLD | NEW |