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 | |
39 ui::GestureProviderConfigType TouchEmulationConfigurationToType( | 26 ui::GestureProviderConfigType TouchEmulationConfigurationToType( |
40 const std::string& protocol_value) { | 27 const std::string& protocol_value) { |
41 ui::GestureProviderConfigType result = | 28 ui::GestureProviderConfigType result = |
42 ui::GestureProviderConfigType::CURRENT_PLATFORM; | 29 ui::GestureProviderConfigType::CURRENT_PLATFORM; |
43 if (protocol_value == | 30 if (protocol_value == |
44 set_touch_emulation_enabled::kConfigurationMobile) { | 31 set_touch_emulation_enabled::kConfigurationMobile) { |
45 result = ui::GestureProviderConfigType::GENERIC_MOBILE; | 32 result = ui::GestureProviderConfigType::GENERIC_MOBILE; |
46 } | 33 } |
47 if (protocol_value == | 34 if (protocol_value == |
48 set_touch_emulation_enabled::kConfigurationDesktop) { | 35 set_touch_emulation_enabled::kConfigurationDesktop) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 int height, | 125 int height, |
139 double device_scale_factor, | 126 double device_scale_factor, |
140 bool mobile, | 127 bool mobile, |
141 bool fit_window, | 128 bool fit_window, |
142 const double* optional_scale, | 129 const double* optional_scale, |
143 const double* optional_offset_x, | 130 const double* optional_offset_x, |
144 const double* optional_offset_y, | 131 const double* optional_offset_y, |
145 const int* screen_width, | 132 const int* screen_width, |
146 const int* screen_height, | 133 const int* screen_height, |
147 const int* position_x, | 134 const int* position_x, |
148 const int* position_y, | 135 const int* position_y) { |
149 const scoped_ptr<base::DictionaryValue>& screen_orientation) { | |
150 const static int max_size = 10000000; | 136 const static int max_size = 10000000; |
151 const static double max_scale = 10; | 137 const static double max_scale = 10; |
152 const static int max_orientation_angle = 360; | |
153 | 138 |
154 if (!host_) | 139 if (!host_) |
155 return Response::InternalError("Could not connect to view"); | 140 return Response::InternalError("Could not connect to view"); |
156 | 141 |
157 if (screen_width && screen_height && | 142 if (screen_width && screen_height && |
158 (*screen_width < 0 || *screen_height < 0 || | 143 (*screen_width < 0 || *screen_height < 0 || |
159 *screen_width > max_size || *screen_height > max_size)) { | 144 *screen_width > max_size || *screen_height > max_size)) { |
160 return Response::InvalidParams( | 145 return Response::InvalidParams( |
161 "Screen width and height values must be positive, not greater than " + | 146 "Screen width and height values must be positive, not greater than " + |
162 base::IntToString(max_size)); | 147 base::IntToString(max_size)); |
(...skipping 13 matching lines...) Expand all Loading... |
176 | 161 |
177 if (device_scale_factor < 0) | 162 if (device_scale_factor < 0) |
178 return Response::InvalidParams("deviceScaleFactor must be non-negative"); | 163 return Response::InvalidParams("deviceScaleFactor must be non-negative"); |
179 | 164 |
180 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) { | 165 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) { |
181 return Response::InvalidParams( | 166 return Response::InvalidParams( |
182 "scale must be positive, not greater than " + | 167 "scale must be positive, not greater than " + |
183 base::DoubleToString(max_scale)); | 168 base::DoubleToString(max_scale)); |
184 } | 169 } |
185 | 170 |
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 | |
210 blink::WebDeviceEmulationParams params; | 171 blink::WebDeviceEmulationParams params; |
211 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : | 172 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : |
212 blink::WebDeviceEmulationParams::Desktop; | 173 blink::WebDeviceEmulationParams::Desktop; |
213 if (screen_width && screen_height) | 174 if (screen_width && screen_height) |
214 params.screenSize = blink::WebSize(*screen_width, *screen_height); | 175 params.screenSize = blink::WebSize(*screen_width, *screen_height); |
215 if (position_x && position_y) | 176 if (position_x && position_y) |
216 params.viewPosition = blink::WebPoint(*position_x, *position_y); | 177 params.viewPosition = blink::WebPoint(*position_x, *position_y); |
217 params.deviceScaleFactor = device_scale_factor; | 178 params.deviceScaleFactor = device_scale_factor; |
218 params.viewSize = blink::WebSize(width, height); | 179 params.viewSize = blink::WebSize(width, height); |
219 params.fitToView = fit_window; | 180 params.fitToView = fit_window; |
220 params.scale = optional_scale ? *optional_scale : 1; | 181 params.scale = optional_scale ? *optional_scale : 1; |
221 params.offset = blink::WebFloatPoint( | 182 params.offset = blink::WebFloatPoint( |
222 optional_offset_x ? *optional_offset_x : 0.f, | 183 optional_offset_x ? *optional_offset_x : 0.f, |
223 optional_offset_y ? *optional_offset_y : 0.f); | 184 optional_offset_y ? *optional_offset_y : 0.f); |
224 params.screenOrientationType = orientationType; | |
225 params.screenOrientationAngle = orientationAngle; | |
226 | 185 |
227 if (device_emulation_enabled_ && params == device_emulation_params_) | 186 if (device_emulation_enabled_ && params == device_emulation_params_) |
228 return Response::OK(); | 187 return Response::OK(); |
229 | 188 |
230 device_emulation_enabled_ = true; | 189 device_emulation_enabled_ = true; |
231 device_emulation_params_ = params; | 190 device_emulation_params_ = params; |
232 UpdateDeviceEmulationState(); | 191 UpdateDeviceEmulationState(); |
233 return Response::OK(); | 192 return Response::OK(); |
234 } | 193 } |
235 | 194 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 widget_host->GetRoutingID(), device_emulation_params_)); | 230 widget_host->GetRoutingID(), device_emulation_params_)); |
272 } else { | 231 } else { |
273 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 232 widget_host->Send(new ViewMsg_DisableDeviceEmulation( |
274 widget_host->GetRoutingID())); | 233 widget_host->GetRoutingID())); |
275 } | 234 } |
276 } | 235 } |
277 | 236 |
278 } // namespace emulation | 237 } // namespace emulation |
279 } // namespace devtools | 238 } // namespace devtools |
280 } // namespace content | 239 } // namespace content |
OLD | NEW |