Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/render_view_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #include "content/public/browser/render_widget_host_view.h" | 38 #include "content/public/browser/render_widget_host_view.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 namespace content { | 41 namespace content { |
| 42 | 42 |
| 43 typedef std::vector<RenderViewDevToolsAgentHost*> Instances; | 43 typedef std::vector<RenderViewDevToolsAgentHost*> Instances; |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 46 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
| 47 | 47 |
| 48 // Returns RenderViewDevToolsAgentHost attached to any of RenderFrameHost | 48 static RenderViewDevToolsAgentHost* FindAgentHost(RenderFrameHost* host) { |
| 49 // instances associated with |web_contents| | |
| 50 static RenderViewDevToolsAgentHost* FindAgentHost(WebContents* web_contents) { | |
| 51 if (g_instances == NULL) | 49 if (g_instances == NULL) |
| 52 return NULL; | 50 return NULL; |
| 53 for (Instances::iterator it = g_instances.Get().begin(); | 51 for (Instances::iterator it = g_instances.Get().begin(); |
| 54 it != g_instances.Get().end(); ++it) { | 52 it != g_instances.Get().end(); ++it) { |
| 55 if ((*it)->GetWebContents() == web_contents) | 53 if ((*it)->HasRenderFrameHost(host)) |
| 56 return *it; | 54 return *it; |
| 57 } | 55 } |
| 58 return NULL; | 56 return NULL; |
| 59 } | 57 } |
| 60 | 58 |
| 59 // Returns RenderViewDevToolsAgentHost attached to any of RenderFrameHost | |
|
dgozman
2015/01/22 13:54:09
The comment is wrong. It's only for the main frame
pfeldman
2015/01/22 22:10:05
Done.
| |
| 60 // instances associated with |web_contents| | |
| 61 static RenderViewDevToolsAgentHost* FindAgentHost(WebContents* web_contents) { | |
| 62 return FindAgentHost(web_contents->GetMainFrame()); | |
| 63 } | |
| 64 | |
| 61 } // namespace | 65 } // namespace |
| 62 | 66 |
| 63 scoped_refptr<DevToolsAgentHost> | 67 scoped_refptr<DevToolsAgentHost> |
| 64 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { | 68 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { |
| 65 RenderViewDevToolsAgentHost* result = FindAgentHost(web_contents); | 69 RenderViewDevToolsAgentHost* result = FindAgentHost(web_contents); |
| 66 if (!result) | 70 if (!result) |
| 67 result = new RenderViewDevToolsAgentHost(web_contents->GetMainFrame()); | 71 result = new RenderViewDevToolsAgentHost(web_contents->GetMainFrame()); |
| 68 return result; | 72 return result; |
| 69 } | 73 } |
| 70 | 74 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 98 } | 102 } |
| 99 std::vector<WebContents*> result(set.size()); | 103 std::vector<WebContents*> result(set.size()); |
| 100 std::copy(set.begin(), set.end(), result.begin()); | 104 std::copy(set.begin(), set.end(), result.begin()); |
| 101 return result; | 105 return result; |
| 102 } | 106 } |
| 103 | 107 |
| 104 // static | 108 // static |
| 105 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( | 109 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( |
| 106 RenderFrameHost* pending, | 110 RenderFrameHost* pending, |
| 107 RenderFrameHost* current) { | 111 RenderFrameHost* current) { |
| 108 if (current->GetParent()) | 112 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(current); |
|
dgozman
2015/01/22 13:54:09
pending
pfeldman
2015/01/22 22:10:05
Done, but we'll have to carefully manage the state
| |
| 109 return; | |
| 110 WebContents* web_contents = | |
| 111 WebContents::FromRenderFrameHost(pending); | |
| 112 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(web_contents); | |
| 113 if (!agent_host) | 113 if (!agent_host) |
| 114 return; | 114 return; |
| 115 agent_host->DisconnectRenderFrameHost(); | 115 agent_host->DisconnectRenderFrameHost(); |
| 116 agent_host->ConnectRenderFrameHost(current); | 116 agent_host->ConnectRenderFrameHost(current); |
| 117 } | 117 } |
| 118 | 118 |
| 119 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderFrameHost* rfh) | 119 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderFrameHost* rfh) |
| 120 : render_frame_host_(NULL), | 120 : render_frame_host_(NULL), |
| 121 dom_handler_(new devtools::dom::DOMHandler()), | 121 dom_handler_(new devtools::dom::DOMHandler()), |
| 122 input_handler_(new devtools::input::InputHandler()), | 122 input_handler_(new devtools::input::InputHandler()), |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 } | 259 } |
| 260 | 260 |
| 261 RenderViewDevToolsAgentHost::~RenderViewDevToolsAgentHost() { | 261 RenderViewDevToolsAgentHost::~RenderViewDevToolsAgentHost() { |
| 262 Instances::iterator it = std::find(g_instances.Get().begin(), | 262 Instances::iterator it = std::find(g_instances.Get().begin(), |
| 263 g_instances.Get().end(), | 263 g_instances.Get().end(), |
| 264 this); | 264 this); |
| 265 if (it != g_instances.Get().end()) | 265 if (it != g_instances.Get().end()) |
| 266 g_instances.Get().erase(it); | 266 g_instances.Get().erase(it); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // TODO(creis): Consider removing this in favor of RenderFrameHostChanged. | 269 // TODO(creis): Consider removing this in favor of RenderFrameHostChanged. |
|
dgozman
2015/01/22 13:54:09
Remove TODO? This (or similar) notification is not
nasko
2015/01/22 21:20:12
I do believe that this notification will go away,
pfeldman
2015/01/22 22:10:05
Leave the TODO for now, as agreed.
| |
| 270 void RenderViewDevToolsAgentHost::AboutToNavigateRenderFrame( | 270 void RenderViewDevToolsAgentHost::AboutToNavigateRenderFrame( |
| 271 RenderFrameHost* render_frame_host) { | 271 RenderFrameHost* old_host, |
| 272 if (!render_frame_host_) | 272 RenderFrameHost* new_host) { |
| 273 return; | 273 if (render_frame_host_ != old_host) |
| 274 if (render_frame_host->GetParent()) | |
| 275 return; | 274 return; |
| 276 | 275 |
| 277 // TODO(creis): This will need to be updated for --site-per-process, since | 276 // TODO(creis): This will need to be updated for --site-per-process, since |
| 278 // RenderViewHost is going away and navigations could happen in any frame. | 277 // RenderViewHost is going away and navigations could happen in any frame. |
| 279 if (render_frame_host_ == render_frame_host) { | 278 if (render_frame_host_ == new_host) { |
| 280 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 279 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 281 render_frame_host_->GetRenderViewHost()); | 280 render_frame_host_->GetRenderViewHost()); |
| 282 if (rvh->render_view_termination_status() == | 281 if (rvh->render_view_termination_status() == |
| 283 base::TERMINATION_STATUS_STILL_RUNNING) | 282 base::TERMINATION_STATUS_STILL_RUNNING) |
| 284 return; | 283 return; |
| 285 } | 284 } |
| 286 ReattachToRenderFrameHost(render_frame_host); | 285 ReattachToRenderFrameHost(new_host); |
| 287 } | 286 } |
| 288 | 287 |
| 289 void RenderViewDevToolsAgentHost::RenderFrameHostChanged( | 288 void RenderViewDevToolsAgentHost::RenderFrameHostChanged( |
| 290 RenderFrameHost* old_host, | 289 RenderFrameHost* old_host, |
| 291 RenderFrameHost* new_host) { | 290 RenderFrameHost* new_host) { |
| 292 if (new_host->GetParent()) | 291 if (old_host == render_frame_host_ && new_host != render_frame_host_) { |
| 293 return; | |
| 294 if (new_host != render_frame_host_) { | |
| 295 // AboutToNavigateRenderFrame was not called for renderer-initiated | 292 // AboutToNavigateRenderFrame was not called for renderer-initiated |
|
nasko
2015/01/22 21:20:12
Since you already handle this case, why is AboutTo
pfeldman
2015/01/22 22:10:05
It is too late, we've already failed to seed the r
| |
| 296 // navigation. | 293 // navigation. |
| 297 ReattachToRenderFrameHost(new_host); | 294 ReattachToRenderFrameHost(new_host); |
| 298 } | 295 } |
| 299 } | 296 } |
| 300 | 297 |
| 301 void | 298 void |
| 302 RenderViewDevToolsAgentHost::ReattachToRenderFrameHost(RenderFrameHost* rfh) { | 299 RenderViewDevToolsAgentHost::ReattachToRenderFrameHost(RenderFrameHost* rfh) { |
| 303 DCHECK(!reattaching_); | 300 DCHECK(!reattaching_); |
| 304 reattaching_ = true; | 301 reattaching_ = true; |
| 305 DisconnectRenderFrameHost(); | 302 DisconnectRenderFrameHost(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 const NotificationSource& source, | 391 const NotificationSource& source, |
| 395 const NotificationDetails& details) { | 392 const NotificationDetails& details) { |
| 396 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { | 393 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { |
| 397 bool visible = *Details<bool>(details).ptr(); | 394 bool visible = *Details<bool>(details).ptr(); |
| 398 page_handler_->OnVisibilityChanged(visible); | 395 page_handler_->OnVisibilityChanged(visible); |
| 399 } | 396 } |
| 400 } | 397 } |
| 401 | 398 |
| 402 void RenderViewDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { | 399 void RenderViewDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { |
| 403 DCHECK(!render_frame_host_); | 400 DCHECK(!render_frame_host_); |
| 404 DCHECK(!rfh->GetParent()); | |
|
dgozman
2015/01/22 13:54:09
I think we can keep this until we support child fr
pfeldman
2015/01/22 22:10:04
Ack. But it is only called for GetMainFrame and I
| |
| 405 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); | 401 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); |
| 406 | 402 |
| 407 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); | 403 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); |
| 408 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 404 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 409 rfh->GetRenderViewHost()); | 405 rfh->GetRenderViewHost()); |
| 410 dom_handler_->SetRenderViewHost(rvh); | 406 dom_handler_->SetRenderViewHost(rvh); |
| 411 input_handler_->SetRenderViewHost(rvh); | 407 input_handler_->SetRenderViewHost(rvh); |
| 412 network_handler_->SetRenderViewHost(rvh); | 408 network_handler_->SetRenderViewHost(rvh); |
| 413 page_handler_->SetRenderViewHost(rvh); | 409 page_handler_->SetRenderViewHost(rvh); |
| 414 | 410 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 page_handler_->OnSwapCompositorFrame(get<1>(param).metadata); | 493 page_handler_->OnSwapCompositorFrame(get<1>(param).metadata); |
| 498 } | 494 } |
| 499 | 495 |
| 500 void RenderViewDevToolsAgentHost::SynchronousSwapCompositorFrame( | 496 void RenderViewDevToolsAgentHost::SynchronousSwapCompositorFrame( |
| 501 const cc::CompositorFrameMetadata& frame_metadata) { | 497 const cc::CompositorFrameMetadata& frame_metadata) { |
| 502 if (!render_frame_host_) | 498 if (!render_frame_host_) |
| 503 return; | 499 return; |
| 504 page_handler_->OnSwapCompositorFrame(frame_metadata); | 500 page_handler_->OnSwapCompositorFrame(frame_metadata); |
| 505 } | 501 } |
| 506 | 502 |
| 503 bool RenderViewDevToolsAgentHost::HasRenderFrameHost( | |
| 504 RenderFrameHost* host) { | |
| 505 return host == render_frame_host_; | |
| 506 } | |
| 507 | |
| 507 void RenderViewDevToolsAgentHost::OnSaveAgentRuntimeState( | 508 void RenderViewDevToolsAgentHost::OnSaveAgentRuntimeState( |
| 508 const std::string& state) { | 509 const std::string& state) { |
| 509 if (!render_frame_host_) | 510 if (!render_frame_host_) |
| 510 return; | 511 return; |
| 511 state_ = state; | 512 state_ = state; |
| 512 } | 513 } |
| 513 | 514 |
| 514 void RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 515 void RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 515 const std::string& message, | 516 const std::string& message, |
| 516 uint32 total_size) { | 517 uint32 total_size) { |
| 517 if (!IsAttached() || !render_frame_host_) | 518 if (!IsAttached() || !render_frame_host_) |
| 518 return; | 519 return; |
| 519 ProcessChunkedMessageFromAgent(message, total_size); | 520 ProcessChunkedMessageFromAgent(message, total_size); |
| 520 } | 521 } |
| 521 | 522 |
| 522 void RenderViewDevToolsAgentHost::DispatchOnInspectorFrontend( | 523 void RenderViewDevToolsAgentHost::DispatchOnInspectorFrontend( |
| 523 const std::string& message) { | 524 const std::string& message) { |
| 524 if (!IsAttached() || !render_frame_host_) | 525 if (!IsAttached() || !render_frame_host_) |
| 525 return; | 526 return; |
| 526 SendMessageToClient(message); | 527 SendMessageToClient(message); |
| 527 } | 528 } |
| 528 | 529 |
| 529 } // namespace content | 530 } // namespace content |
| OLD | NEW |