Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: content/browser/devtools/protocol/emulation_handler.cc

Issue 2237433004: Adds DevTools commands for forced viewport override. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove offset/scale params, rename commands, clip by backing size. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 bool fit_window, 144 bool fit_window,
145 const double* optional_scale, 145 const double* optional_scale,
146 const double* optional_offset_x, 146 const double* optional_offset_x,
147 const double* optional_offset_y, 147 const double* optional_offset_y,
148 const int* screen_width, 148 const int* screen_width,
149 const int* screen_height, 149 const int* screen_height,
150 const int* position_x, 150 const int* position_x,
151 const int* position_y, 151 const int* position_y,
152 const std::unique_ptr<base::DictionaryValue>& screen_orientation) { 152 const std::unique_ptr<base::DictionaryValue>& screen_orientation) {
153 const static int max_size = 10000000; 153 const static int max_size = 10000000;
154 const static double max_scale = 10;
155 const static int max_orientation_angle = 360; 154 const static int max_orientation_angle = 360;
156 155
157 if (!host_) 156 if (!host_)
158 return Response::InternalError("Could not connect to view"); 157 return Response::InternalError("Could not connect to view");
159 158
160 if (screen_width && screen_height && 159 if (screen_width && screen_height &&
161 (*screen_width < 0 || *screen_height < 0 || 160 (*screen_width < 0 || *screen_height < 0 ||
162 *screen_width > max_size || *screen_height > max_size)) { 161 *screen_width > max_size || *screen_height > max_size)) {
163 return Response::InvalidParams( 162 return Response::InvalidParams(
164 "Screen width and height values must be positive, not greater than " + 163 "Screen width and height values must be positive, not greater than " +
165 base::IntToString(max_size)); 164 base::IntToString(max_size));
166 } 165 }
167 166
168 if (screen_width && screen_height && position_x && position_y && 167 if (screen_width && screen_height && position_x && position_y &&
169 (*position_x < 0 || *position_y < 0 || 168 (*position_x < 0 || *position_y < 0 ||
170 *position_x > *screen_width || *position_y > *screen_height)) { 169 *position_x > *screen_width || *position_y > *screen_height)) {
171 return Response::InvalidParams("View position should be on the screen"); 170 return Response::InvalidParams("View position should be on the screen");
172 } 171 }
173 172
174 if (width < 0 || height < 0 || width > max_size || height > max_size) { 173 if (width < 0 || height < 0 || width > max_size || height > max_size) {
175 return Response::InvalidParams( 174 return Response::InvalidParams(
176 "Width and height values must be positive, not greater than " + 175 "Width and height values must be positive, not greater than " +
177 base::IntToString(max_size)); 176 base::IntToString(max_size));
178 } 177 }
179 178
180 if (device_scale_factor < 0) 179 if (device_scale_factor < 0)
181 return Response::InvalidParams("deviceScaleFactor must be non-negative"); 180 return Response::InvalidParams("deviceScaleFactor must be non-negative");
182 181
183 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) {
184 return Response::InvalidParams(
185 "scale must be positive, not greater than " +
186 base::DoubleToString(max_scale));
187 }
188
189 blink::WebScreenOrientationType orientationType = 182 blink::WebScreenOrientationType orientationType =
190 blink::WebScreenOrientationUndefined; 183 blink::WebScreenOrientationUndefined;
191 int orientationAngle = 0; 184 int orientationAngle = 0;
192 if (screen_orientation) { 185 if (screen_orientation) {
193 std::string orientationTypeString; 186 std::string orientationTypeString;
194 if (!screen_orientation->GetString("type", &orientationTypeString)) { 187 if (!screen_orientation->GetString("type", &orientationTypeString)) {
195 return Response::InvalidParams( 188 return Response::InvalidParams(
196 "Screen orientation type must be a string"); 189 "Screen orientation type must be a string");
197 } 190 }
198 orientationType = WebScreenOrientationTypeFromString(orientationTypeString); 191 orientationType = WebScreenOrientationTypeFromString(orientationTypeString);
(...skipping 14 matching lines...) Expand all
213 blink::WebDeviceEmulationParams params; 206 blink::WebDeviceEmulationParams params;
214 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : 207 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile :
215 blink::WebDeviceEmulationParams::Desktop; 208 blink::WebDeviceEmulationParams::Desktop;
216 if (screen_width && screen_height) 209 if (screen_width && screen_height)
217 params.screenSize = blink::WebSize(*screen_width, *screen_height); 210 params.screenSize = blink::WebSize(*screen_width, *screen_height);
218 if (position_x && position_y) 211 if (position_x && position_y)
219 params.viewPosition = blink::WebPoint(*position_x, *position_y); 212 params.viewPosition = blink::WebPoint(*position_x, *position_y);
220 params.deviceScaleFactor = device_scale_factor; 213 params.deviceScaleFactor = device_scale_factor;
221 params.viewSize = blink::WebSize(width, height); 214 params.viewSize = blink::WebSize(width, height);
222 params.fitToView = fit_window; 215 params.fitToView = fit_window;
223 params.scale = optional_scale ? *optional_scale : 1;
224 params.offset = blink::WebFloatPoint(
225 optional_offset_x ? *optional_offset_x : 0.f,
226 optional_offset_y ? *optional_offset_y : 0.f);
227 params.screenOrientationType = orientationType; 216 params.screenOrientationType = orientationType;
228 params.screenOrientationAngle = orientationAngle; 217 params.screenOrientationAngle = orientationAngle;
229 218
230 if (device_emulation_enabled_ && params == device_emulation_params_) 219 if (device_emulation_enabled_ && params == device_emulation_params_)
231 return Response::OK(); 220 return Response::OK();
232 221
233 device_emulation_enabled_ = true; 222 device_emulation_enabled_ = true;
234 device_emulation_params_ = params; 223 device_emulation_params_ = params;
235 UpdateDeviceEmulationState(); 224 UpdateDeviceEmulationState();
236 return Response::OK(); 225 return Response::OK();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 widget_host->GetRoutingID(), device_emulation_params_)); 263 widget_host->GetRoutingID(), device_emulation_params_));
275 } else { 264 } else {
276 widget_host->Send(new ViewMsg_DisableDeviceEmulation( 265 widget_host->Send(new ViewMsg_DisableDeviceEmulation(
277 widget_host->GetRoutingID())); 266 widget_host->GetRoutingID()));
278 } 267 }
279 } 268 }
280 269
281 } // namespace emulation 270 } // namespace emulation
282 } // namespace devtools 271 } // namespace devtools
283 } // namespace content 272 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698