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" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 Response EmulationHandler::ClearDeviceMetricsOverride() { | 239 Response EmulationHandler::ClearDeviceMetricsOverride() { |
240 if (!device_emulation_enabled_) | 240 if (!device_emulation_enabled_) |
241 return Response::OK(); | 241 return Response::OK(); |
242 | 242 |
243 device_emulation_enabled_ = false; | 243 device_emulation_enabled_ = false; |
244 UpdateDeviceEmulationState(); | 244 UpdateDeviceEmulationState(); |
245 return Response::OK(); | 245 return Response::OK(); |
246 } | 246 } |
247 | 247 |
| 248 Response EmulationHandler::GetFrameSize(int* width, int* height) { |
| 249 // Get size of frame from RWHV if available. |
| 250 RenderWidgetHostImpl* widget_host = |
| 251 host_ ? host_->GetRenderWidgetHost() : nullptr; |
| 252 if (!widget_host) |
| 253 return Response::ServerError("Target does not support GetFrameSize"); |
| 254 |
| 255 gfx::Size size = widget_host->GetView()->GetViewBounds().size(); |
| 256 *width = size.width(); |
| 257 *height = size.height(); |
| 258 return Response::OK(); |
| 259 } |
| 260 |
| 261 Response EmulationHandler::SetFrameSize(int width, int height) { |
| 262 if (width < 0 || height < 0) |
| 263 return Response::InvalidParams("Width and height must be non-negative"); |
| 264 |
| 265 // Set size of frame by resizing RWHV if available. |
| 266 RenderWidgetHostImpl* widget_host = |
| 267 host_ ? host_->GetRenderWidgetHost() : nullptr; |
| 268 if (!widget_host) |
| 269 return Response::ServerError("Target does not support SetFrameSize"); |
| 270 |
| 271 widget_host->GetView()->SetSize(gfx::Size(width, height)); |
| 272 return Response::OK(); |
| 273 } |
| 274 |
248 WebContentsImpl* EmulationHandler::GetWebContents() { | 275 WebContentsImpl* EmulationHandler::GetWebContents() { |
249 return host_ ? | 276 return host_ ? |
250 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) : | 277 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) : |
251 nullptr; | 278 nullptr; |
252 } | 279 } |
253 | 280 |
254 void EmulationHandler::UpdateTouchEventEmulationState() { | 281 void EmulationHandler::UpdateTouchEventEmulationState() { |
255 RenderWidgetHostImpl* widget_host = | 282 RenderWidgetHostImpl* widget_host = |
256 host_ ? host_->GetRenderWidgetHost() : nullptr; | 283 host_ ? host_->GetRenderWidgetHost() : nullptr; |
257 if (!widget_host) | 284 if (!widget_host) |
(...skipping 16 matching lines...) Expand all Loading... |
274 widget_host->GetRoutingID(), device_emulation_params_)); | 301 widget_host->GetRoutingID(), device_emulation_params_)); |
275 } else { | 302 } else { |
276 widget_host->Send(new ViewMsg_DisableDeviceEmulation( | 303 widget_host->Send(new ViewMsg_DisableDeviceEmulation( |
277 widget_host->GetRoutingID())); | 304 widget_host->GetRoutingID())); |
278 } | 305 } |
279 } | 306 } |
280 | 307 |
281 } // namespace emulation | 308 } // namespace emulation |
282 } // namespace devtools | 309 } // namespace devtools |
283 } // namespace content | 310 } // namespace content |
OLD | NEW |