Chromium Code Reviews| 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 "Visible_width and visible_height values must be positive, not greater " | |
| 
 
dgozman
2016/07/21 20:54:08
Visual viewport dimensions must be positive, not g
 
Eric Seckler
2016/07/22 14:44:48
Done.
 
 | |
| 218 "than " + | |
| 219 base::IntToString(max_size)); | |
| 220 } | |
| 221 | |
| 210 blink::WebDeviceEmulationParams params; | 222 blink::WebDeviceEmulationParams params; | 
| 211 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : | 223 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : | 
| 212 blink::WebDeviceEmulationParams::Desktop; | 224 blink::WebDeviceEmulationParams::Desktop; | 
| 213 if (screen_width && screen_height) | 225 if (screen_width && screen_height) | 
| 214 params.screenSize = blink::WebSize(*screen_width, *screen_height); | 226 params.screenSize = blink::WebSize(*screen_width, *screen_height); | 
| 215 if (position_x && position_y) | 227 if (position_x && position_y) | 
| 216 params.viewPosition = blink::WebPoint(*position_x, *position_y); | 228 params.viewPosition = blink::WebPoint(*position_x, *position_y); | 
| 217 params.deviceScaleFactor = device_scale_factor; | 229 params.deviceScaleFactor = device_scale_factor; | 
| 218 params.viewSize = blink::WebSize(width, height); | 230 params.viewSize = blink::WebSize(width, height); | 
| 219 params.fitToView = fit_window; | 231 params.fitToView = fit_window; | 
| 220 params.scale = optional_scale ? *optional_scale : 1; | 232 params.scale = optional_scale ? *optional_scale : 1; | 
| 221 params.offset = blink::WebFloatPoint( | 233 params.offset = blink::WebFloatPoint( | 
| 222 optional_offset_x ? *optional_offset_x : 0.f, | 234 optional_offset_x ? *optional_offset_x : 0.f, | 
| 223 optional_offset_y ? *optional_offset_y : 0.f); | 235 optional_offset_y ? *optional_offset_y : 0.f); | 
| 224 params.screenOrientationType = orientationType; | 236 params.screenOrientationType = orientationType; | 
| 225 params.screenOrientationAngle = orientationAngle; | 237 params.screenOrientationAngle = orientationAngle; | 
| 238 params.visualViewportSize = | |
| 239 blink::WebSize(visual_viewport_width ? *visual_viewport_width : 0, | |
| 240 visual_viewport_height ? *visual_viewport_height : 0); | |
| 226 | 241 | 
| 227 if (device_emulation_enabled_ && params == device_emulation_params_) | 242 if (device_emulation_enabled_ && params == device_emulation_params_) | 
| 228 return Response::OK(); | 243 return Response::OK(); | 
| 229 | 244 | 
| 230 device_emulation_enabled_ = true; | 245 device_emulation_enabled_ = true; | 
| 231 device_emulation_params_ = params; | 246 device_emulation_params_ = params; | 
| 232 UpdateDeviceEmulationState(); | 247 UpdateDeviceEmulationState(); | 
| 233 return Response::OK(); | 248 return Response::OK(); | 
| 234 } | 249 } | 
| 235 | 250 | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 widget_host->GetRoutingID(), device_emulation_params_)); | 286 widget_host->GetRoutingID(), device_emulation_params_)); | 
| 272 } else { | 287 } else { | 
| 273 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 288 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 
| 274 widget_host->GetRoutingID())); | 289 widget_host->GetRoutingID())); | 
| 275 } | 290 } | 
| 276 } | 291 } | 
| 277 | 292 | 
| 278 } // namespace emulation | 293 } // namespace emulation | 
| 279 } // namespace devtools | 294 } // namespace devtools | 
| 280 } // namespace content | 295 } // namespace content | 
| OLD | NEW |