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* visual_viewport_width, |
| 151 const int* visual_viewport_height) { |
150 const static int max_size = 10000000; | 152 const static int max_size = 10000000; |
151 const static double max_scale = 10; | 153 const static double max_scale = 10; |
152 const static int max_orientation_angle = 360; | 154 const static int max_orientation_angle = 360; |
153 | 155 |
154 if (!host_) | 156 if (!host_) |
155 return Response::InternalError("Could not connect to view"); | 157 return Response::InternalError("Could not connect to view"); |
156 | 158 |
157 if (screen_width && screen_height && | 159 if (screen_width && screen_height && |
158 (*screen_width < 0 || *screen_height < 0 || | 160 (*screen_width < 0 || *screen_height < 0 || |
159 *screen_width > max_size || *screen_height > max_size)) { | 161 *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( | 202 return Response::InvalidParams( |
201 "Screen orientation angle must be a number"); | 203 "Screen orientation angle must be a number"); |
202 } | 204 } |
203 if (orientationAngle < 0 || orientationAngle >= max_orientation_angle) { | 205 if (orientationAngle < 0 || orientationAngle >= max_orientation_angle) { |
204 return Response::InvalidParams( | 206 return Response::InvalidParams( |
205 "Screen orientation angle must be non-negative, less than " + | 207 "Screen orientation angle must be non-negative, less than " + |
206 base::IntToString(max_orientation_angle)); | 208 base::IntToString(max_orientation_angle)); |
207 } | 209 } |
208 } | 210 } |
209 | 211 |
| 212 if ((visual_viewport_width && |
| 213 (*visual_viewport_width < 0 || *visual_viewport_width > max_size)) || |
| 214 (visual_viewport_height && |
| 215 (*visual_viewport_height < 0 || *visual_viewport_height > max_size))) { |
| 216 return Response::InvalidParams( |
| 217 "Visual viewport dimensions must be positive, not greater than " + |
| 218 base::IntToString(max_size)); |
| 219 } |
| 220 |
210 blink::WebDeviceEmulationParams params; | 221 blink::WebDeviceEmulationParams params; |
211 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : | 222 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : |
212 blink::WebDeviceEmulationParams::Desktop; | 223 blink::WebDeviceEmulationParams::Desktop; |
213 if (screen_width && screen_height) | 224 if (screen_width && screen_height) |
214 params.screenSize = blink::WebSize(*screen_width, *screen_height); | 225 params.screenSize = blink::WebSize(*screen_width, *screen_height); |
215 if (position_x && position_y) | 226 if (position_x && position_y) |
216 params.viewPosition = blink::WebPoint(*position_x, *position_y); | 227 params.viewPosition = blink::WebPoint(*position_x, *position_y); |
217 params.deviceScaleFactor = device_scale_factor; | 228 params.deviceScaleFactor = device_scale_factor; |
218 params.viewSize = blink::WebSize(width, height); | 229 params.viewSize = blink::WebSize(width, height); |
219 params.fitToView = fit_window; | 230 params.fitToView = fit_window; |
220 params.scale = optional_scale ? *optional_scale : 1; | 231 params.scale = optional_scale ? *optional_scale : 1; |
221 params.offset = blink::WebFloatPoint( | 232 params.offset = blink::WebFloatPoint( |
222 optional_offset_x ? *optional_offset_x : 0.f, | 233 optional_offset_x ? *optional_offset_x : 0.f, |
223 optional_offset_y ? *optional_offset_y : 0.f); | 234 optional_offset_y ? *optional_offset_y : 0.f); |
224 params.screenOrientationType = orientationType; | 235 params.screenOrientationType = orientationType; |
225 params.screenOrientationAngle = orientationAngle; | 236 params.screenOrientationAngle = orientationAngle; |
| 237 params.visualViewportSize = |
| 238 blink::WebSize(visual_viewport_width ? *visual_viewport_width : 0, |
| 239 visual_viewport_height ? *visual_viewport_height : 0); |
226 | 240 |
227 if (device_emulation_enabled_ && params == device_emulation_params_) | 241 if (device_emulation_enabled_ && params == device_emulation_params_) |
228 return Response::OK(); | 242 return Response::OK(); |
229 | 243 |
230 device_emulation_enabled_ = true; | 244 device_emulation_enabled_ = true; |
231 device_emulation_params_ = params; | 245 device_emulation_params_ = params; |
232 UpdateDeviceEmulationState(); | 246 UpdateDeviceEmulationState(); |
233 return Response::OK(); | 247 return Response::OK(); |
234 } | 248 } |
235 | 249 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 widget_host->GetRoutingID(), device_emulation_params_)); | 285 widget_host->GetRoutingID(), device_emulation_params_)); |
272 } else { | 286 } else { |
273 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 287 widget_host->Send(new ViewMsg_DisableDeviceEmulation( |
274 widget_host->GetRoutingID())); | 288 widget_host->GetRoutingID())); |
275 } | 289 } |
276 } | 290 } |
277 | 291 |
278 } // namespace emulation | 292 } // namespace emulation |
279 } // namespace devtools | 293 } // namespace devtools |
280 } // namespace content | 294 } // namespace content |
OLD | NEW |