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 "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 Loading... | |
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, |
jochen (gone - plz use gerrit)
2015/06/23 14:59:47
wouldn't clang format put as many parameters as po
dgozman
2015/06/23 15:05:23
I've just changed to one-per-line per nasko@ comme
| |
129 bool fit_window, const double* optional_scale, | 129 int height, |
130 const double* optional_offset_x, const double* optional_offset_y, | 130 double device_scale_factor, |
131 const int* screen_width, const int* screen_height, | 131 bool mobile, |
132 const int* position_x, const int* position_y) { | 132 bool fit_window, |
133 return SetDeviceMetricsOverride(width, height, device_scale_factor, mobile, | 133 const double* optional_scale, |
134 fit_window, optional_scale, optional_offset_x, optional_offset_y); | 134 const double* optional_offset_x, |
135 } | 135 const double* optional_offset_y, |
136 | 136 const int* screen_width, |
137 Response EmulationHandler::SetDeviceMetricsOverride( | 137 const int* screen_height, |
138 int width, int height, double device_scale_factor, bool mobile, | 138 const int* position_x, |
139 bool fit_window, const double* optional_scale, | 139 const int* position_y) { |
140 const double* optional_offset_x, const double* optional_offset_y) { | |
141 const static int max_size = 10000000; | 140 const static int max_size = 10000000; |
142 const static double max_scale = 10; | 141 const static double max_scale = 10; |
143 | 142 |
144 if (!host_) | 143 if (!host_) |
145 return Response::InternalError("Could not connect to view"); | 144 return Response::InternalError("Could not connect to view"); |
146 | 145 |
146 if (screen_width && screen_height && | |
147 (*screen_width < 0 || *screen_height < 0 || | |
148 *screen_width > max_size || *screen_height > max_size)) { | |
149 return Response::InvalidParams( | |
150 "Screen width and height values must be positive, not greater than " + | |
151 base::IntToString(max_size)); | |
152 } | |
153 | |
154 if (screen_width && screen_height && position_x && position_y && | |
155 (*position_x < 0 || *position_y < 0 || | |
156 *position_x > *screen_width || *position_y > *screen_height)) { | |
157 return Response::InvalidParams("View position should be on the screen"); | |
158 } | |
159 | |
147 if (width < 0 || height < 0 || width > max_size || height > max_size) { | 160 if (width < 0 || height < 0 || width > max_size || height > max_size) { |
148 return Response::InvalidParams( | 161 return Response::InvalidParams( |
149 "Width and height values must be positive, not greater than " + | 162 "Width and height values must be positive, not greater than " + |
150 base::IntToString(max_size)); | 163 base::IntToString(max_size)); |
151 } | 164 } |
152 | 165 |
153 if (device_scale_factor < 0) | 166 if (device_scale_factor < 0) |
154 return Response::InvalidParams("deviceScaleFactor must be non-negative"); | 167 return Response::InvalidParams("deviceScaleFactor must be non-negative"); |
155 | 168 |
156 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) { | 169 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) { |
157 return Response::InvalidParams( | 170 return Response::InvalidParams( |
158 "scale must be positive, not greater than " + | 171 "scale must be positive, not greater than " + |
159 base::IntToString(max_scale)); | 172 base::IntToString(max_scale)); |
160 } | 173 } |
161 | 174 |
162 blink::WebDeviceEmulationParams params; | 175 blink::WebDeviceEmulationParams params; |
163 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : | 176 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : |
164 blink::WebDeviceEmulationParams::Desktop; | 177 blink::WebDeviceEmulationParams::Desktop; |
178 if (screen_width && screen_height) | |
179 params.screenSize = blink::WebSize(*screen_width, *screen_height); | |
180 if (position_x && position_y) | |
181 params.viewPosition = blink::WebPoint(*position_x, *position_y); | |
165 params.deviceScaleFactor = device_scale_factor; | 182 params.deviceScaleFactor = device_scale_factor; |
166 params.viewSize = blink::WebSize(width, height); | 183 params.viewSize = blink::WebSize(width, height); |
167 params.fitToView = fit_window; | 184 params.fitToView = fit_window; |
168 params.scale = optional_scale ? *optional_scale : 1; | 185 params.scale = optional_scale ? *optional_scale : 1; |
169 params.offset = blink::WebFloatPoint( | 186 params.offset = blink::WebFloatPoint( |
170 optional_offset_x ? *optional_offset_x : 0.f, | 187 optional_offset_x ? *optional_offset_x : 0.f, |
171 optional_offset_y ? *optional_offset_y : 0.f); | 188 optional_offset_y ? *optional_offset_y : 0.f); |
172 | 189 |
173 if (device_emulation_enabled_ && params == device_emulation_params_) | 190 if (device_emulation_enabled_ && params == device_emulation_params_) |
174 return Response::OK(); | 191 return Response::OK(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 widget_host->GetRoutingID(), device_emulation_params_)); | 235 widget_host->GetRoutingID(), device_emulation_params_)); |
219 } else { | 236 } else { |
220 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 237 widget_host->Send(new ViewMsg_DisableDeviceEmulation( |
221 widget_host->GetRoutingID())); | 238 widget_host->GetRoutingID())); |
222 } | 239 } |
223 } | 240 } |
224 | 241 |
225 } // namespace emulation | 242 } // namespace emulation |
226 } // namespace devtools | 243 } // namespace devtools |
227 } // namespace content | 244 } // namespace content |
OLD | NEW |