Index: content/browser/devtools/protocol/page_handler.cc |
diff --git a/content/browser/devtools/protocol/page_handler.cc b/content/browser/devtools/protocol/page_handler.cc |
index 356cefa580e011268593f79615d006c3c3289773..337b1c370e9f4fc4d077cf70fe28fa9015901b1a 100644 |
--- a/content/browser/devtools/protocol/page_handler.cc |
+++ b/content/browser/devtools/protocol/page_handler.cc |
@@ -9,6 +9,7 @@ |
#include "base/base64.h" |
#include "base/bind.h" |
#include "base/strings/string16.h" |
+#include "base/strings/string_number_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/threading/worker_pool.h" |
#include "content/browser/devtools/protocol/color_picker.h" |
@@ -17,6 +18,7 @@ |
#include "content/browser/renderer_host/render_view_host_impl.h" |
#include "content/browser/renderer_host/render_widget_host_view_base.h" |
#include "content/browser/web_contents/web_contents_impl.h" |
+#include "content/common/devtools_messages.h" |
#include "content/common/view_messages.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/javascript_dialog_manager.h" |
@@ -106,6 +108,7 @@ typedef DevToolsProtocolClient::Response Response; |
PageHandler::PageHandler() |
: enabled_(false), |
touch_emulation_enabled_(false), |
+ device_emulation_enabled_(false), |
screencast_enabled_(false), |
screencast_quality_(kDefaultScreenshotQuality), |
screencast_max_width_(-1), |
@@ -133,6 +136,7 @@ void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) { |
frame_recorder_->SetRenderViewHost(host); |
host_ = host; |
UpdateTouchEventEmulationState(); |
+ UpdateDeviceEmulationState(); |
} |
void PageHandler::SetClient(scoped_ptr<Client> client) { |
@@ -183,7 +187,9 @@ Response PageHandler::Disable() { |
enabled_ = false; |
touch_emulation_enabled_ = false; |
screencast_enabled_ = false; |
+ device_emulation_enabled_ = false; |
UpdateTouchEventEmulationState(); |
+ UpdateDeviceEmulationState(); |
color_picker_->SetEnabled(false); |
return Response::FallThrough(); |
} |
@@ -342,7 +348,9 @@ Response PageHandler::CanEmulate(bool* result) { |
#else |
if (host_) { |
if (WebContents* web_contents = WebContents::FromRenderViewHost(host_)) { |
- *result = !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme); |
+ *result = |
+ !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme) && |
pfeldman
2015/03/13 13:00:17
DEBUG_DEVTOOLS ?
dgozman
2015/03/13 15:57:27
Done.
|
+ web_contents->GetMainFrame()->GetRenderViewHost() == host_; |
} else { |
*result = true; |
} |
@@ -353,6 +361,60 @@ Response PageHandler::CanEmulate(bool* result) { |
return Response::OK(); |
} |
+Response PageHandler::SetDeviceMetricsOverride( |
+ int width, int height, double device_scale_factor, bool mobile, |
+ bool fit_window, const double* optional_scale, |
+ const double* optional_offset_x, const double* optional_offset_y) { |
+ const static int max_size = 10000000; |
+ const static double max_scale = 10; |
+ |
+ if (!host_) |
+ return Response::InternalError("Could not connect to view"); |
+ |
+ if (width < 0 || height < 0 || width > max_size || height > max_size) { |
+ return Response::InvalidParams( |
+ "Width and height values must be positive, not greater than " + |
+ base::IntToString(max_size)); |
+ } |
+ |
+ if (device_scale_factor < 0) |
+ return Response::InvalidParams("deviceScaleFactor must be non-negative"); |
+ |
+ if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) { |
+ return Response::InvalidParams( |
+ "scale must be positive, not greater than " + |
+ base::IntToString(max_scale)); |
+ } |
+ |
+ blink::WebDeviceEmulationParams params; |
+ params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile : |
+ blink::WebDeviceEmulationParams::Desktop; |
+ params.deviceScaleFactor = device_scale_factor; |
+ params.viewSize = blink::WebSize(width, height); |
+ params.fitToView = fit_window; |
+ params.scale = optional_scale ? *optional_scale : 1; |
+ params.offset = blink::WebFloatPoint( |
+ optional_offset_x ? *optional_offset_x : 0.f, |
+ optional_offset_y ? *optional_offset_y : 0.f); |
+ |
+ if (device_emulation_enabled_ && params == device_emulation_params_) |
+ return Response::OK(); |
+ |
+ device_emulation_enabled_ = true; |
+ device_emulation_params_ = params; |
+ UpdateDeviceEmulationState(); |
+ return Response::OK(); |
+} |
+ |
+Response PageHandler::ClearDeviceMetricsOverride() { |
+ if (!device_emulation_enabled_) |
+ return Response::OK(); |
+ |
+ device_emulation_enabled_ = false; |
+ UpdateDeviceEmulationState(); |
+ return Response::OK(); |
+} |
+ |
Response PageHandler::StartScreencast(const std::string* format, |
const int* quality, |
const int* max_width, |
@@ -453,6 +515,18 @@ void PageHandler::UpdateTouchEventEmulationState() { |
web_contents->SetForceDisableOverscrollContent(enabled); |
} |
+void PageHandler::UpdateDeviceEmulationState() { |
+ if (!host_) |
+ return; |
+ if (device_emulation_enabled_) { |
+ host_->GetMainFrame()->Send(new DevToolsMsg_EnableDeviceEmulation( |
+ host_->GetMainFrame()->GetRoutingID(), device_emulation_params_)); |
+ } else { |
+ host_->GetMainFrame()->Send(new DevToolsMsg_DisableDeviceEmulation( |
+ host_->GetMainFrame()->GetRoutingID())); |
+ } |
+} |
+ |
void PageHandler::NotifyScreencastVisibility(bool visible) { |
if (visible) |
capture_retry_count_ = kCaptureRetryLimit; |