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 d8ffcd5a5c062f7cbc8fb30463fba5b61fa0e9c9..8be8bc77a62031765e8f80b02e505f8cacdf7398 100644 |
--- a/content/browser/devtools/protocol/page_handler.cc |
+++ b/content/browser/devtools/protocol/page_handler.cc |
@@ -98,7 +98,7 @@ PageHandler::PageHandler() |
processing_screencast_frame_(false), |
color_picker_(new ColorPicker(base::Bind( |
&PageHandler::OnColorPicked, base::Unretained(this)))), |
- host_(nullptr), |
+ web_contents_(nullptr), |
screencast_listener_(nullptr), |
weak_factory_(this) { |
} |
@@ -106,12 +106,12 @@ PageHandler::PageHandler() |
PageHandler::~PageHandler() { |
} |
-void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) { |
- if (host_ == host) |
+void PageHandler::SetWebContents(WebContentsImpl* web_contents) { |
+ if (web_contents_ == web_contents) |
return; |
- color_picker_->SetRenderViewHost(host); |
- host_ = host; |
+ web_contents_ = web_contents; |
+ color_picker_->SetRenderWidgetHost(GetRenderWidgetHost()); |
} |
void PageHandler::SetClient(scoped_ptr<Client> client) { |
@@ -173,18 +173,14 @@ Response PageHandler::Disable() { |
Response PageHandler::Reload(const bool* ignoreCache, |
const std::string* script_to_evaluate_on_load, |
const std::string* script_preprocessor) { |
- if (!host_) |
+ if (!web_contents_) |
return Response::InternalError("Could not connect to view"); |
- WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
- if (!web_contents) |
- return Response::InternalError("No WebContents to reload"); |
- |
// Handle in browser only if it is crashed. |
- if (!web_contents->IsCrashed()) |
+ if (!web_contents_->IsCrashed()) |
return Response::FallThrough(); |
- web_contents->GetController().Reload(false); |
+ web_contents_->GetController().Reload(false); |
return Response::OK(); |
} |
@@ -194,28 +190,20 @@ Response PageHandler::Navigate(const std::string& url, |
if (!gurl.is_valid()) |
return Response::InternalError("Cannot navigate to invalid URL"); |
- if (!host_) |
+ if (!web_contents_) |
return Response::InternalError("Could not connect to view"); |
- WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
- if (!web_contents) |
- return Response::InternalError("No WebContents to navigate"); |
- |
- web_contents->GetController() |
+ web_contents_->GetController() |
.LoadURL(gurl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
return Response::FallThrough(); |
} |
Response PageHandler::GetNavigationHistory(int* current_index, |
NavigationEntries* entries) { |
- if (!host_) |
+ if (!web_contents_) |
return Response::InternalError("Could not connect to view"); |
- WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
- if (!web_contents) |
- return Response::InternalError("No WebContents to navigate"); |
- |
- NavigationController& controller = web_contents->GetController(); |
+ NavigationController& controller = web_contents_->GetController(); |
*current_index = controller.GetCurrentEntryIndex(); |
for (int i = 0; i != controller.GetEntryCount(); ++i) { |
entries->push_back(NavigationEntry::Create() |
@@ -228,14 +216,10 @@ Response PageHandler::GetNavigationHistory(int* current_index, |
} |
Response PageHandler::NavigateToHistoryEntry(int entry_id) { |
- if (!host_) |
+ if (!web_contents_) |
return Response::InternalError("Could not connect to view"); |
- WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
- if (!web_contents) |
- return Response::InternalError("No WebContents to navigate"); |
- |
- NavigationController& controller = web_contents->GetController(); |
+ NavigationController& controller = web_contents_->GetController(); |
for (int i = 0; i != controller.GetEntryCount(); ++i) { |
if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { |
controller.GoToIndex(i); |
@@ -247,10 +231,10 @@ Response PageHandler::NavigateToHistoryEntry(int entry_id) { |
} |
Response PageHandler::CaptureScreenshot(DevToolsCommandId command_id) { |
- if (!host_ || !host_->GetView()) |
+ if (!web_contents_ || !web_contents_->GetRenderWidgetHostView()) |
return Response::InternalError("Could not connect to view"); |
- host_->GetSnapshotFromBrowser( |
+ GetRenderWidgetHost()->GetSnapshotFromBrowser( |
base::Bind(&PageHandler::ScreenshotCaptured, |
weak_factory_.GetWeakPtr(), command_id)); |
return Response::OK(); |
@@ -269,7 +253,7 @@ Response PageHandler::StartScreencast(const std::string* format, |
const int* quality, |
const int* max_width, |
const int* max_height) { |
- if (!host_) |
+ if (!web_contents_) |
return Response::InternalError("Could not connect to view"); |
screencast_enabled_ = true; |
@@ -280,13 +264,15 @@ Response PageHandler::StartScreencast(const std::string* format, |
screencast_max_width_ = max_width ? *max_width : -1; |
screencast_max_height_ = max_height ? *max_height : -1; |
- bool visible = !host_->is_hidden(); |
+ bool visible = !GetRenderWidgetHost()->is_hidden(); |
NotifyScreencastVisibility(visible); |
if (visible) { |
- if (has_compositor_frame_metadata_) |
+ if (has_compositor_frame_metadata_) { |
InnerSwapCompositorFrame(); |
- else |
- host_->Send(new ViewMsg_ForceRedraw(host_->GetRoutingID(), 0)); |
+ } else { |
+ GetRenderWidgetHost()->Send( |
+ new ViewMsg_ForceRedraw(GetRenderWidgetHost()->GetRoutingID(), 0)); |
+ } |
} |
if (screencast_listener_) |
screencast_listener_->ScreencastEnabledChanged(); |
@@ -311,17 +297,13 @@ Response PageHandler::HandleJavaScriptDialog(bool accept, |
if (prompt_text) |
prompt_override = base::UTF8ToUTF16(*prompt_text); |
- if (!host_) |
+ if (!web_contents_) |
return Response::InternalError("Could not connect to view"); |
- WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
- if (!web_contents) |
- return Response::InternalError("No JavaScript dialog to handle"); |
- |
JavaScriptDialogManager* manager = |
- web_contents->GetDelegate()->GetJavaScriptDialogManager(web_contents); |
+ web_contents_->GetDelegate()->GetJavaScriptDialogManager(web_contents_); |
if (manager && manager->HandleJavaScriptDialog( |
- web_contents, accept, prompt_text ? &prompt_override : nullptr)) { |
+ web_contents_, accept, prompt_text ? &prompt_override : nullptr)) { |
return Response::OK(); |
} |
@@ -334,13 +316,21 @@ Response PageHandler::QueryUsageAndQuota(DevToolsCommandId command_id, |
} |
Response PageHandler::SetColorPickerEnabled(bool enabled) { |
- if (!host_) |
+ if (!web_contents_) |
return Response::InternalError("Could not connect to view"); |
color_picker_->SetEnabled(enabled); |
return Response::OK(); |
} |
+RenderWidgetHostImpl* PageHandler::GetRenderWidgetHost() { |
+ // TODO(dgozman): there should be a way to get main RenderWidgetHost from |
+ // WebContents without RenderViewHost. |
+ return web_contents_ ? |
+ static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()) : |
+ nullptr; |
+} |
+ |
void PageHandler::NotifyScreencastVisibility(bool visible) { |
if (visible) |
capture_retry_count_ = kCaptureRetryLimit; |
@@ -354,11 +344,11 @@ void PageHandler::InnerSwapCompositorFrame() { |
return; |
} |
- if (!host_ || !host_->GetView()) |
+ if (!web_contents_ || !web_contents_->GetRenderWidgetHostView()) |
return; |
RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
- host_->GetView()); |
+ web_contents_->GetRenderWidgetHostView()); |
// TODO(vkuzkokov): do not use previous frame metadata. |
cc::CompositorFrameMetadata& metadata = last_compositor_frame_metadata_; |
@@ -432,11 +422,11 @@ void PageHandler::ScreencastFrameEncoded( |
processing_screencast_frame_ = false; |
// Consider metadata empty in case it has no device scale factor. |
- if (metadata.device_scale_factor == 0 || !host_ || data.empty()) |
+ if (metadata.device_scale_factor == 0 || !web_contents_ || data.empty()) |
return; |
RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
- host_->GetView()); |
+ web_contents_->GetRenderWidgetHostView()); |
if (!view) |
return; |