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

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

Issue 1203503002: [DevTools] Implement screen size and position in Emulation.setDeviceMetricsOverrides. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@screen-size-stub
Patch Set: Created 5 years, 6 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 "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "content/browser/frame_host/render_frame_host_impl.h" 8 #include "content/browser/frame_host/render_frame_host_impl.h"
9 #include "content/browser/geolocation/geolocation_service_context.h" 9 #include "content/browser/geolocation/geolocation_service_context.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 10 #include "content/browser/renderer_host/render_widget_host_impl.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 *result = true; 118 *result = true;
119 if (WebContentsImpl* web_contents = GetWebContents()) 119 if (WebContentsImpl* web_contents = GetWebContents())
120 *result &= !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme); 120 *result &= !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme);
121 if (host_ && host_->GetRenderWidgetHost()) 121 if (host_ && host_->GetRenderWidgetHost())
122 *result &= !host_->GetRenderWidgetHost()->auto_resize_enabled(); 122 *result &= !host_->GetRenderWidgetHost()->auto_resize_enabled();
123 #endif // defined(OS_ANDROID) 123 #endif // defined(OS_ANDROID)
124 return Response::OK(); 124 return Response::OK();
125 } 125 }
126 126
127 Response EmulationHandler::SetDeviceMetricsOverride( 127 Response EmulationHandler::SetDeviceMetricsOverride(
128 int width, int height, double device_scale_factor, bool mobile, 128 int width, int height, double device_scale_factor, bool mobile,
nasko 2015/06/23 10:44:44 nit: All parameters should be on a new line.
dgozman 2015/06/23 12:03:15 Done.
129 bool fit_window, const double* optional_scale, 129 bool fit_window, const double* optional_scale,
130 const double* optional_offset_x, const double* optional_offset_y, 130 const double* optional_offset_x, const double* optional_offset_y,
131 const int* screen_width, const int* screen_height, 131 const int* screen_width, const int* screen_height,
132 const int* position_x, const int* position_y) { 132 const int* position_x, const int* position_y) {
133 return SetDeviceMetricsOverride(width, height, device_scale_factor, mobile,
134 fit_window, optional_scale, optional_offset_x, optional_offset_y);
135 }
136
137 Response EmulationHandler::SetDeviceMetricsOverride(
138 int width, int height, double device_scale_factor, bool mobile,
139 bool fit_window, const double* optional_scale,
140 const double* optional_offset_x, const double* optional_offset_y) {
141 const static int max_size = 10000000; 133 const static int max_size = 10000000;
142 const static double max_scale = 10; 134 const static double max_scale = 10;
143 135
144 if (!host_) 136 if (!host_)
145 return Response::InternalError("Could not connect to view"); 137 return Response::InternalError("Could not connect to view");
146 138
139 if (screen_width && screen_height &&
140 (*screen_width < 0 || *screen_height < 0 ||
141 *screen_width > max_size || *screen_height > max_size)) {
142 return Response::InvalidParams(
143 "Screen width and height values must be positive, not greater than " +
144 base::IntToString(max_size));
145 }
146
147 if (screen_width && screen_height && position_x && position_y &&
148 (*position_x < 0 || *position_y < 0 ||
149 *position_x > *screen_width || *position_y > *screen_height)) {
150 return Response::InvalidParams("View position should be on the screen");
151 }
152
147 if (width < 0 || height < 0 || width > max_size || height > max_size) { 153 if (width < 0 || height < 0 || width > max_size || height > max_size) {
148 return Response::InvalidParams( 154 return Response::InvalidParams(
149 "Width and height values must be positive, not greater than " + 155 "Width and height values must be positive, not greater than " +
150 base::IntToString(max_size)); 156 base::IntToString(max_size));
151 } 157 }
152 158
153 if (device_scale_factor < 0) 159 if (device_scale_factor < 0)
154 return Response::InvalidParams("deviceScaleFactor must be non-negative"); 160 return Response::InvalidParams("deviceScaleFactor must be non-negative");
155 161
156 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) { 162 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) {
157 return Response::InvalidParams( 163 return Response::InvalidParams(
158 "scale must be positive, not greater than " + 164 "scale must be positive, not greater than " +
159 base::IntToString(max_scale)); 165 base::IntToString(max_scale));
160 } 166 }
161 167
162 blink::WebDeviceEmulationParams params; 168 blink::WebDeviceEmulationParams params;
163 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : 169 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile :
164 blink::WebDeviceEmulationParams::Desktop; 170 blink::WebDeviceEmulationParams::Desktop;
171 if (screen_width && screen_height)
172 params.screenSize = blink::WebSize(*screen_width, *screen_height);
173 if (position_x && position_y)
174 params.viewPosition = blink::WebPoint(*position_x, *position_y);
165 params.deviceScaleFactor = device_scale_factor; 175 params.deviceScaleFactor = device_scale_factor;
166 params.viewSize = blink::WebSize(width, height); 176 params.viewSize = blink::WebSize(width, height);
167 params.fitToView = fit_window; 177 params.fitToView = fit_window;
168 params.scale = optional_scale ? *optional_scale : 1; 178 params.scale = optional_scale ? *optional_scale : 1;
169 params.offset = blink::WebFloatPoint( 179 params.offset = blink::WebFloatPoint(
170 optional_offset_x ? *optional_offset_x : 0.f, 180 optional_offset_x ? *optional_offset_x : 0.f,
171 optional_offset_y ? *optional_offset_y : 0.f); 181 optional_offset_y ? *optional_offset_y : 0.f);
172 182
173 if (device_emulation_enabled_ && params == device_emulation_params_) 183 if (device_emulation_enabled_ && params == device_emulation_params_)
174 return Response::OK(); 184 return Response::OK();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 widget_host->GetRoutingID(), device_emulation_params_)); 228 widget_host->GetRoutingID(), device_emulation_params_));
219 } else { 229 } else {
220 widget_host->Send(new ViewMsg_DisableDeviceEmulation( 230 widget_host->Send(new ViewMsg_DisableDeviceEmulation(
221 widget_host->GetRoutingID())); 231 widget_host->GetRoutingID()));
222 } 232 }
223 } 233 }
224 234
225 } // namespace emulation 235 } // namespace emulation
226 } // namespace devtools 236 } // namespace devtools
227 } // namespace content 237 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698