| 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" |
| 11 #include "content/browser/frame_host/render_frame_host_impl.h" | 11 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 12 #include "content/browser/geolocation/geolocation_service_context.h" | 12 #include "content/browser/geolocation/geolocation_service_context.h" |
| 13 #include "content/browser/renderer_host/render_widget_host_impl.h" | 13 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 14 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
| 15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
| 16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 namespace devtools { | 19 namespace devtools { |
| 20 namespace emulation { | 20 namespace emulation { |
| 21 | 21 |
| 22 using Response = DevToolsProtocolClient::Response; | 22 using Response = DevToolsProtocolClient::Response; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 blink::WebScreenOrientationType WebScreenOrientationTypeFromString( |
| 27 const std::string& type) { |
| 28 if (type == screen_orientation::kTypePortraitPrimary) |
| 29 return blink::WebScreenOrientationPortraitPrimary; |
| 30 if (type == screen_orientation::kTypePortraitSecondary) |
| 31 return blink::WebScreenOrientationPortraitSecondary; |
| 32 if (type == screen_orientation::kTypeLandscapePrimary) |
| 33 return blink::WebScreenOrientationLandscapePrimary; |
| 34 if (type == screen_orientation::kTypeLandscapeSecondary) |
| 35 return blink::WebScreenOrientationLandscapeSecondary; |
| 36 return blink::WebScreenOrientationUndefined; |
| 37 } |
| 38 |
| 26 ui::GestureProviderConfigType TouchEmulationConfigurationToType( | 39 ui::GestureProviderConfigType TouchEmulationConfigurationToType( |
| 27 const std::string& protocol_value) { | 40 const std::string& protocol_value) { |
| 28 ui::GestureProviderConfigType result = | 41 ui::GestureProviderConfigType result = |
| 29 ui::GestureProviderConfigType::CURRENT_PLATFORM; | 42 ui::GestureProviderConfigType::CURRENT_PLATFORM; |
| 30 if (protocol_value == | 43 if (protocol_value == |
| 31 set_touch_emulation_enabled::kConfigurationMobile) { | 44 set_touch_emulation_enabled::kConfigurationMobile) { |
| 32 result = ui::GestureProviderConfigType::GENERIC_MOBILE; | 45 result = ui::GestureProviderConfigType::GENERIC_MOBILE; |
| 33 } | 46 } |
| 34 if (protocol_value == | 47 if (protocol_value == |
| 35 set_touch_emulation_enabled::kConfigurationDesktop) { | 48 set_touch_emulation_enabled::kConfigurationDesktop) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 int height, | 138 int height, |
| 126 double device_scale_factor, | 139 double device_scale_factor, |
| 127 bool mobile, | 140 bool mobile, |
| 128 bool fit_window, | 141 bool fit_window, |
| 129 const double* optional_scale, | 142 const double* optional_scale, |
| 130 const double* optional_offset_x, | 143 const double* optional_offset_x, |
| 131 const double* optional_offset_y, | 144 const double* optional_offset_y, |
| 132 const int* screen_width, | 145 const int* screen_width, |
| 133 const int* screen_height, | 146 const int* screen_height, |
| 134 const int* position_x, | 147 const int* position_x, |
| 135 const int* position_y) { | 148 const int* position_y, |
| 149 const scoped_ptr<base::DictionaryValue>& screen_orientation) { |
| 136 const static int max_size = 10000000; | 150 const static int max_size = 10000000; |
| 137 const static double max_scale = 10; | 151 const static double max_scale = 10; |
| 152 const static int max_orientation_angle = 360; |
| 138 | 153 |
| 139 if (!host_) | 154 if (!host_) |
| 140 return Response::InternalError("Could not connect to view"); | 155 return Response::InternalError("Could not connect to view"); |
| 141 | 156 |
| 142 if (screen_width && screen_height && | 157 if (screen_width && screen_height && |
| 143 (*screen_width < 0 || *screen_height < 0 || | 158 (*screen_width < 0 || *screen_height < 0 || |
| 144 *screen_width > max_size || *screen_height > max_size)) { | 159 *screen_width > max_size || *screen_height > max_size)) { |
| 145 return Response::InvalidParams( | 160 return Response::InvalidParams( |
| 146 "Screen width and height values must be positive, not greater than " + | 161 "Screen width and height values must be positive, not greater than " + |
| 147 base::IntToString(max_size)); | 162 base::IntToString(max_size)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 161 | 176 |
| 162 if (device_scale_factor < 0) | 177 if (device_scale_factor < 0) |
| 163 return Response::InvalidParams("deviceScaleFactor must be non-negative"); | 178 return Response::InvalidParams("deviceScaleFactor must be non-negative"); |
| 164 | 179 |
| 165 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) { | 180 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) { |
| 166 return Response::InvalidParams( | 181 return Response::InvalidParams( |
| 167 "scale must be positive, not greater than " + | 182 "scale must be positive, not greater than " + |
| 168 base::DoubleToString(max_scale)); | 183 base::DoubleToString(max_scale)); |
| 169 } | 184 } |
| 170 | 185 |
| 186 blink::WebScreenOrientationType orientationType = |
| 187 blink::WebScreenOrientationUndefined; |
| 188 int orientationAngle = 0; |
| 189 if (screen_orientation) { |
| 190 std::string orientationTypeString; |
| 191 if (!screen_orientation->GetString("type", &orientationTypeString)) { |
| 192 return Response::InvalidParams( |
| 193 "Screen orientation type must be a string"); |
| 194 } |
| 195 orientationType = WebScreenOrientationTypeFromString(orientationTypeString); |
| 196 if (orientationType == blink::WebScreenOrientationUndefined) |
| 197 return Response::InvalidParams("Invalid screen orientation type value"); |
| 198 |
| 199 if (!screen_orientation->GetInteger("angle", &orientationAngle)) { |
| 200 return Response::InvalidParams( |
| 201 "Screen orientation angle must be a number"); |
| 202 } |
| 203 if (orientationAngle < 0 || orientationAngle >= max_orientation_angle) { |
| 204 return Response::InvalidParams( |
| 205 "Screen orientation angle must be non-negative, less than " + |
| 206 base::IntToString(max_orientation_angle)); |
| 207 } |
| 208 } |
| 209 |
| 171 blink::WebDeviceEmulationParams params; | 210 blink::WebDeviceEmulationParams params; |
| 172 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : | 211 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : |
| 173 blink::WebDeviceEmulationParams::Desktop; | 212 blink::WebDeviceEmulationParams::Desktop; |
| 174 if (screen_width && screen_height) | 213 if (screen_width && screen_height) |
| 175 params.screenSize = blink::WebSize(*screen_width, *screen_height); | 214 params.screenSize = blink::WebSize(*screen_width, *screen_height); |
| 176 if (position_x && position_y) | 215 if (position_x && position_y) |
| 177 params.viewPosition = blink::WebPoint(*position_x, *position_y); | 216 params.viewPosition = blink::WebPoint(*position_x, *position_y); |
| 178 params.deviceScaleFactor = device_scale_factor; | 217 params.deviceScaleFactor = device_scale_factor; |
| 179 params.viewSize = blink::WebSize(width, height); | 218 params.viewSize = blink::WebSize(width, height); |
| 180 params.fitToView = fit_window; | 219 params.fitToView = fit_window; |
| 181 params.scale = optional_scale ? *optional_scale : 1; | 220 params.scale = optional_scale ? *optional_scale : 1; |
| 182 params.offset = blink::WebFloatPoint( | 221 params.offset = blink::WebFloatPoint( |
| 183 optional_offset_x ? *optional_offset_x : 0.f, | 222 optional_offset_x ? *optional_offset_x : 0.f, |
| 184 optional_offset_y ? *optional_offset_y : 0.f); | 223 optional_offset_y ? *optional_offset_y : 0.f); |
| 224 params.screenOrientationType = orientationType; |
| 225 params.screenOrientationAngle = orientationAngle; |
| 185 | 226 |
| 186 if (device_emulation_enabled_ && params == device_emulation_params_) | 227 if (device_emulation_enabled_ && params == device_emulation_params_) |
| 187 return Response::OK(); | 228 return Response::OK(); |
| 188 | 229 |
| 189 device_emulation_enabled_ = true; | 230 device_emulation_enabled_ = true; |
| 190 device_emulation_params_ = params; | 231 device_emulation_params_ = params; |
| 191 UpdateDeviceEmulationState(); | 232 UpdateDeviceEmulationState(); |
| 192 return Response::OK(); | 233 return Response::OK(); |
| 193 } | 234 } |
| 194 | 235 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 widget_host->GetRoutingID(), device_emulation_params_)); | 271 widget_host->GetRoutingID(), device_emulation_params_)); |
| 231 } else { | 272 } else { |
| 232 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 273 widget_host->Send(new ViewMsg_DisableDeviceEmulation( |
| 233 widget_host->GetRoutingID())); | 274 widget_host->GetRoutingID())); |
| 234 } | 275 } |
| 235 } | 276 } |
| 236 | 277 |
| 237 } // namespace emulation | 278 } // namespace emulation |
| 238 } // namespace devtools | 279 } // namespace devtools |
| 239 } // namespace content | 280 } // namespace content |
| OLD | NEW |