| 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 26 matching lines...) Expand all Loading... |
| 37 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 namespace content { | 40 namespace content { |
| 41 | 41 |
| 42 typedef std::vector<RenderViewDevToolsAgentHost*> Instances; | 42 typedef std::vector<RenderViewDevToolsAgentHost*> Instances; |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 45 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
| 46 | 46 |
| 47 static RenderViewDevToolsAgentHost* FindAgentHost(RenderFrameHost* host) { |
| 48 if (g_instances == NULL) |
| 49 return NULL; |
| 50 for (Instances::iterator it = g_instances.Get().begin(); |
| 51 it != g_instances.Get().end(); ++it) { |
| 52 if ((*it)->HasRenderFrameHost(host)) |
| 53 return *it; |
| 54 } |
| 55 return NULL; |
| 56 } |
| 57 |
| 47 // Returns RenderViewDevToolsAgentHost attached to any of RenderFrameHost | 58 // Returns RenderViewDevToolsAgentHost attached to any of RenderFrameHost |
| 48 // instances associated with |web_contents| | 59 // instances associated with |web_contents| |
| 49 static RenderViewDevToolsAgentHost* FindAgentHost(WebContents* web_contents) { | 60 static RenderViewDevToolsAgentHost* FindAgentHost(WebContents* web_contents) { |
| 50 if (g_instances == NULL) | 61 if (g_instances == NULL) |
| 51 return NULL; | 62 return NULL; |
| 52 for (Instances::iterator it = g_instances.Get().begin(); | 63 for (Instances::iterator it = g_instances.Get().begin(); |
| 53 it != g_instances.Get().end(); ++it) { | 64 it != g_instances.Get().end(); ++it) { |
| 54 if ((*it)->GetWebContents() == web_contents) | 65 if ((*it)->GetWebContents() == web_contents) |
| 55 return *it; | 66 return *it; |
| 56 } | 67 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 108 } |
| 98 std::vector<WebContents*> result(set.size()); | 109 std::vector<WebContents*> result(set.size()); |
| 99 std::copy(set.begin(), set.end(), result.begin()); | 110 std::copy(set.begin(), set.end(), result.begin()); |
| 100 return result; | 111 return result; |
| 101 } | 112 } |
| 102 | 113 |
| 103 // static | 114 // static |
| 104 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( | 115 void RenderViewDevToolsAgentHost::OnCancelPendingNavigation( |
| 105 RenderFrameHost* pending, | 116 RenderFrameHost* pending, |
| 106 RenderFrameHost* current) { | 117 RenderFrameHost* current) { |
| 107 if (current->GetParent()) | 118 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(pending); |
| 108 return; | |
| 109 WebContents* web_contents = | |
| 110 WebContents::FromRenderFrameHost(pending); | |
| 111 RenderViewDevToolsAgentHost* agent_host = FindAgentHost(web_contents); | |
| 112 if (!agent_host) | 119 if (!agent_host) |
| 113 return; | 120 return; |
| 114 agent_host->DisconnectRenderFrameHost(); | 121 agent_host->DisconnectRenderFrameHost(); |
| 115 agent_host->ConnectRenderFrameHost(current); | 122 agent_host->ConnectRenderFrameHost(current); |
| 116 } | 123 } |
| 117 | 124 |
| 118 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderFrameHost* rfh) | 125 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost(RenderFrameHost* rfh) |
| 119 : render_frame_host_(NULL), | 126 : render_frame_host_(NULL), |
| 120 dom_handler_(new devtools::dom::DOMHandler()), | 127 dom_handler_(new devtools::dom::DOMHandler()), |
| 121 input_handler_(new devtools::input::InputHandler()), | 128 input_handler_(new devtools::input::InputHandler()), |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 RenderViewDevToolsAgentHost::~RenderViewDevToolsAgentHost() { | 267 RenderViewDevToolsAgentHost::~RenderViewDevToolsAgentHost() { |
| 261 Instances::iterator it = std::find(g_instances.Get().begin(), | 268 Instances::iterator it = std::find(g_instances.Get().begin(), |
| 262 g_instances.Get().end(), | 269 g_instances.Get().end(), |
| 263 this); | 270 this); |
| 264 if (it != g_instances.Get().end()) | 271 if (it != g_instances.Get().end()) |
| 265 g_instances.Get().erase(it); | 272 g_instances.Get().erase(it); |
| 266 } | 273 } |
| 267 | 274 |
| 268 // TODO(creis): Consider removing this in favor of RenderFrameHostChanged. | 275 // TODO(creis): Consider removing this in favor of RenderFrameHostChanged. |
| 269 void RenderViewDevToolsAgentHost::AboutToNavigateRenderFrame( | 276 void RenderViewDevToolsAgentHost::AboutToNavigateRenderFrame( |
| 270 RenderFrameHost* render_frame_host) { | 277 RenderFrameHost* old_host, |
| 271 if (!render_frame_host_) | 278 RenderFrameHost* new_host) { |
| 272 return; | 279 if (render_frame_host_ != old_host) |
| 273 if (render_frame_host->GetParent()) | |
| 274 return; | 280 return; |
| 275 | 281 |
| 276 // TODO(creis): This will need to be updated for --site-per-process, since | 282 // TODO(creis): This will need to be updated for --site-per-process, since |
| 277 // RenderViewHost is going away and navigations could happen in any frame. | 283 // RenderViewHost is going away and navigations could happen in any frame. |
| 278 if (render_frame_host_ == render_frame_host) { | 284 if (render_frame_host_ == new_host) { |
| 279 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 285 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 280 render_frame_host_->GetRenderViewHost()); | 286 render_frame_host_->GetRenderViewHost()); |
| 281 if (rvh->render_view_termination_status() == | 287 if (rvh->render_view_termination_status() == |
| 282 base::TERMINATION_STATUS_STILL_RUNNING) | 288 base::TERMINATION_STATUS_STILL_RUNNING) |
| 283 return; | 289 return; |
| 284 } | 290 } |
| 285 ReattachToRenderFrameHost(render_frame_host); | 291 ReattachToRenderFrameHost(new_host); |
| 286 } | 292 } |
| 287 | 293 |
| 288 void RenderViewDevToolsAgentHost::RenderFrameHostChanged( | 294 void RenderViewDevToolsAgentHost::RenderFrameHostChanged( |
| 289 RenderFrameHost* old_host, | 295 RenderFrameHost* old_host, |
| 290 RenderFrameHost* new_host) { | 296 RenderFrameHost* new_host) { |
| 291 if (new_host->GetParent()) | 297 if (old_host == render_frame_host_ && new_host != render_frame_host_) { |
| 292 return; | |
| 293 if (new_host != render_frame_host_) { | |
| 294 // AboutToNavigateRenderFrame was not called for renderer-initiated | 298 // AboutToNavigateRenderFrame was not called for renderer-initiated |
| 295 // navigation. | 299 // navigation. |
| 296 ReattachToRenderFrameHost(new_host); | 300 ReattachToRenderFrameHost(new_host); |
| 297 } | 301 } |
| 298 } | 302 } |
| 299 | 303 |
| 300 void | 304 void |
| 301 RenderViewDevToolsAgentHost::ReattachToRenderFrameHost(RenderFrameHost* rfh) { | 305 RenderViewDevToolsAgentHost::ReattachToRenderFrameHost(RenderFrameHost* rfh) { |
| 302 DCHECK(!reattaching_); | 306 DCHECK(!reattaching_); |
| 303 reattaching_ = true; | 307 reattaching_ = true; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 const NotificationSource& source, | 395 const NotificationSource& source, |
| 392 const NotificationDetails& details) { | 396 const NotificationDetails& details) { |
| 393 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { | 397 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { |
| 394 bool visible = *Details<bool>(details).ptr(); | 398 bool visible = *Details<bool>(details).ptr(); |
| 395 page_handler_->OnVisibilityChanged(visible); | 399 page_handler_->OnVisibilityChanged(visible); |
| 396 } | 400 } |
| 397 } | 401 } |
| 398 | 402 |
| 399 void RenderViewDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { | 403 void RenderViewDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { |
| 400 DCHECK(!render_frame_host_); | 404 DCHECK(!render_frame_host_); |
| 401 DCHECK(!rfh->GetParent()); | |
| 402 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); | 405 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); |
| 403 | 406 |
| 404 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); | 407 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); |
| 405 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 408 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 406 rfh->GetRenderViewHost()); | 409 rfh->GetRenderViewHost()); |
| 407 dom_handler_->SetRenderViewHost(rvh); | 410 dom_handler_->SetRenderViewHost(rvh); |
| 408 input_handler_->SetRenderViewHost(rvh); | 411 input_handler_->SetRenderViewHost(rvh); |
| 409 network_handler_->SetRenderViewHost(rvh); | 412 network_handler_->SetRenderViewHost(rvh); |
| 410 page_handler_->SetRenderViewHost(rvh); | 413 page_handler_->SetRenderViewHost(rvh); |
| 411 | 414 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 page_handler_->OnSwapCompositorFrame(get<1>(param).metadata); | 497 page_handler_->OnSwapCompositorFrame(get<1>(param).metadata); |
| 495 } | 498 } |
| 496 | 499 |
| 497 void RenderViewDevToolsAgentHost::SynchronousSwapCompositorFrame( | 500 void RenderViewDevToolsAgentHost::SynchronousSwapCompositorFrame( |
| 498 const cc::CompositorFrameMetadata& frame_metadata) { | 501 const cc::CompositorFrameMetadata& frame_metadata) { |
| 499 if (!render_frame_host_) | 502 if (!render_frame_host_) |
| 500 return; | 503 return; |
| 501 page_handler_->OnSwapCompositorFrame(frame_metadata); | 504 page_handler_->OnSwapCompositorFrame(frame_metadata); |
| 502 } | 505 } |
| 503 | 506 |
| 507 bool RenderViewDevToolsAgentHost::HasRenderFrameHost( |
| 508 RenderFrameHost* host) { |
| 509 return host == render_frame_host_; |
| 510 } |
| 511 |
| 504 void RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 512 void RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 505 const DevToolsMessageChunk& message) { | 513 const DevToolsMessageChunk& message) { |
| 506 if (!IsAttached() || !render_frame_host_) | 514 if (!IsAttached() || !render_frame_host_) |
| 507 return; | 515 return; |
| 508 ProcessChunkedMessageFromAgent(message); | 516 ProcessChunkedMessageFromAgent(message); |
| 509 } | 517 } |
| 510 | 518 |
| 511 void RenderViewDevToolsAgentHost::DispatchOnInspectorFrontend( | 519 void RenderViewDevToolsAgentHost::DispatchOnInspectorFrontend( |
| 512 const std::string& message) { | 520 const std::string& message) { |
| 513 if (!IsAttached() || !render_frame_host_) | 521 if (!IsAttached() || !render_frame_host_) |
| 514 return; | 522 return; |
| 515 SendMessageToClient(message); | 523 SendMessageToClient(message); |
| 516 } | 524 } |
| 517 | 525 |
| 518 } // namespace content | 526 } // namespace content |
| OLD | NEW |