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

Unified Diff: content/browser/devtools/protocol/emulation_handler.cc

Issue 1043173003: [DevTools] Move Page and Emulation handlers to RenderFrameHostImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/emulation_handler.cc
diff --git a/content/browser/devtools/protocol/emulation_handler.cc b/content/browser/devtools/protocol/emulation_handler.cc
index c57d8999dacc729c0be2ccba774181b441605b21..e5f2fed27be85190242e44ceec143a5b4c688491 100644
--- a/content/browser/devtools/protocol/emulation_handler.cc
+++ b/content/browser/devtools/protocol/emulation_handler.cc
@@ -40,7 +40,7 @@ EmulationHandler::EmulationHandler(page::PageHandler* page_handler)
: touch_emulation_enabled_(false),
device_emulation_enabled_(false),
page_handler_(page_handler),
- host_(nullptr)
+ web_contents_(nullptr)
{
page_handler->SetScreencastListener(this);
}
@@ -52,11 +52,11 @@ void EmulationHandler::ScreencastEnabledChanged() {
UpdateTouchEventEmulationState();
}
-void EmulationHandler::SetRenderViewHost(RenderViewHostImpl* host) {
- if (host_ == host)
+void EmulationHandler::SetWebContents(WebContentsImpl* web_contents) {
+ if (web_contents_ == web_contents)
return;
- host_ = host;
+ web_contents_ = web_contents;
UpdateTouchEventEmulationState();
UpdateDeviceEmulationState();
}
@@ -70,16 +70,11 @@ void EmulationHandler::Detached() {
Response EmulationHandler::SetGeolocationOverride(
double* latitude, double* longitude, double* accuracy) {
- if (!host_)
+ if (!web_contents_)
return Response::InternalError("Could not connect to view");
- WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
- WebContents::FromRenderViewHost(host_));
- if (!web_contents)
- return Response::InternalError("No WebContents to override");
-
GeolocationServiceContext* geolocation_context =
- web_contents->GetGeolocationServiceContext();
+ web_contents_->GetGeolocationServiceContext();
scoped_ptr<Geoposition> geoposition(new Geoposition());
if (latitude && longitude && accuracy) {
geoposition->latitude = *latitude;
@@ -97,16 +92,11 @@ Response EmulationHandler::SetGeolocationOverride(
}
Response EmulationHandler::ClearGeolocationOverride() {
- if (!host_)
+ if (!web_contents_)
return Response::InternalError("Could not connect to view");
- WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
- WebContents::FromRenderViewHost(host_));
- if (!web_contents)
- return Response::InternalError("No WebContents to override");
-
GeolocationServiceContext* geolocation_context =
- web_contents->GetGeolocationServiceContext();
+ web_contents_->GetGeolocationServiceContext();
geolocation_context->ClearOverride();
return Response::OK();
}
@@ -124,15 +114,11 @@ Response EmulationHandler::CanEmulate(bool* result) {
#if defined(OS_ANDROID)
*result = false;
#else
- if (host_) {
- if (WebContents* web_contents = WebContents::FromRenderViewHost(host_)) {
- *result = web_contents->GetMainFrame()->GetRenderViewHost() == host_;
+ if (web_contents_) {
+ *result = true;
#if defined(DEBUG_DEVTOOLS)
- *result &= !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme);
+ *result &= !web_contents_->GetVisibleURL().SchemeIs(kChromeDevToolsScheme);
#endif // defined(DEBUG_DEVTOOLS)
- } else {
- *result = true;
- }
} else {
*result = true;
}
@@ -147,7 +133,7 @@ Response EmulationHandler::SetDeviceMetricsOverride(
const static int max_size = 10000000;
const static double max_scale = 10;
- if (!host_)
+ if (!web_contents_)
return Response::InternalError("Could not connect to view");
if (width < 0 || height < 0 || width > max_size || height > max_size) {
@@ -194,28 +180,35 @@ Response EmulationHandler::ClearDeviceMetricsOverride() {
return Response::OK();
}
+RenderWidgetHostImpl* EmulationHandler::GetRenderWidgetHost() {
+ // TODO(dgozman): there should be a way to get main RenderWidgetHost from
+ // WebContents without RenderViewHost.
nasko 2015/03/31 14:43:36 WebContentsImpl::GetMainFrame()->GetRenderWidgetHo
dgozman 2015/03/31 15:05:23 So, do you think it's a property of frame? This cl
dgozman 2015/03/31 16:44:59 Done.
+ return web_contents_ ?
+ static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()) :
+ nullptr;
+}
+
void EmulationHandler::UpdateTouchEventEmulationState() {
- if (!host_)
+ if (!web_contents_)
return;
bool enabled = touch_emulation_enabled_ ||
page_handler_->screencast_enabled();
ui::GestureProviderConfigType config_type =
TouchEmulationConfigurationToType(touch_emulation_configuration_);
- host_->SetTouchEventEmulationEnabled(enabled, config_type);
- WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
- WebContents::FromRenderViewHost(host_));
- if (web_contents)
- web_contents->SetForceDisableOverscrollContent(enabled);
+ GetRenderWidgetHost()->SetTouchEventEmulationEnabled(enabled, config_type);
+ web_contents_->SetForceDisableOverscrollContent(enabled);
}
void EmulationHandler::UpdateDeviceEmulationState() {
- if (!host_)
+ if (!web_contents_)
return;
+ RenderWidgetHostImpl* widget_host = GetRenderWidgetHost();
if (device_emulation_enabled_) {
- host_->Send(new ViewMsg_EnableDeviceEmulation(
- host_->GetRoutingID(), device_emulation_params_));
+ widget_host->Send(new ViewMsg_EnableDeviceEmulation(
+ widget_host->GetRoutingID(), device_emulation_params_));
} else {
- host_->Send(new ViewMsg_DisableDeviceEmulation(host_->GetRoutingID()));
+ widget_host->Send(new ViewMsg_DisableDeviceEmulation(
+ widget_host->GetRoutingID()));
}
}
« no previous file with comments | « content/browser/devtools/protocol/emulation_handler.h ('k') | content/browser/devtools/protocol/page_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698