| 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_frame_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_frame_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" |
| 11 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
| 12 #include "content/browser/devtools/devtools_frame_trace_recorder.h" | 12 #include "content/browser/devtools/devtools_frame_trace_recorder.h" |
| 13 #include "content/browser/devtools/devtools_manager.h" | 13 #include "content/browser/devtools/devtools_manager.h" |
| 14 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" | 14 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" |
| 15 #include "content/browser/devtools/protocol/dom_handler.h" | 15 #include "content/browser/devtools/protocol/dom_handler.h" |
| 16 #include "content/browser/devtools/protocol/emulation_handler.h" |
| 16 #include "content/browser/devtools/protocol/input_handler.h" | 17 #include "content/browser/devtools/protocol/input_handler.h" |
| 17 #include "content/browser/devtools/protocol/inspector_handler.h" | 18 #include "content/browser/devtools/protocol/inspector_handler.h" |
| 18 #include "content/browser/devtools/protocol/network_handler.h" | 19 #include "content/browser/devtools/protocol/network_handler.h" |
| 19 #include "content/browser/devtools/protocol/page_handler.h" | 20 #include "content/browser/devtools/protocol/page_handler.h" |
| 20 #include "content/browser/devtools/protocol/power_handler.h" | 21 #include "content/browser/devtools/protocol/power_handler.h" |
| 21 #include "content/browser/devtools/protocol/service_worker_handler.h" | 22 #include "content/browser/devtools/protocol/service_worker_handler.h" |
| 22 #include "content/browser/devtools/protocol/tracing_handler.h" | 23 #include "content/browser/devtools/protocol/tracing_handler.h" |
| 23 #include "content/browser/frame_host/render_frame_host_impl.h" | 24 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 24 #include "content/browser/renderer_host/render_process_host_impl.h" | 25 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 25 #include "content/browser/renderer_host/render_view_host_impl.h" | 26 #include "content/browser/renderer_host/render_view_host_impl.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 dom_handler_(new devtools::dom::DOMHandler()), | 138 dom_handler_(new devtools::dom::DOMHandler()), |
| 138 input_handler_(new devtools::input::InputHandler()), | 139 input_handler_(new devtools::input::InputHandler()), |
| 139 inspector_handler_(new devtools::inspector::InspectorHandler()), | 140 inspector_handler_(new devtools::inspector::InspectorHandler()), |
| 140 network_handler_(new devtools::network::NetworkHandler()), | 141 network_handler_(new devtools::network::NetworkHandler()), |
| 141 page_handler_(new devtools::page::PageHandler()), | 142 page_handler_(new devtools::page::PageHandler()), |
| 142 power_handler_(new devtools::power::PowerHandler()), | 143 power_handler_(new devtools::power::PowerHandler()), |
| 143 service_worker_handler_( | 144 service_worker_handler_( |
| 144 new devtools::service_worker::ServiceWorkerHandler()), | 145 new devtools::service_worker::ServiceWorkerHandler()), |
| 145 tracing_handler_(new devtools::tracing::TracingHandler( | 146 tracing_handler_(new devtools::tracing::TracingHandler( |
| 146 devtools::tracing::TracingHandler::Renderer)), | 147 devtools::tracing::TracingHandler::Renderer)), |
| 148 emulation_handler_(new devtools::emulation::EmulationHandler( |
| 149 page_handler_.get())), |
| 147 protocol_handler_(new DevToolsProtocolHandler( | 150 protocol_handler_(new DevToolsProtocolHandler( |
| 148 base::Bind(&RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend, | 151 base::Bind(&RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend, |
| 149 base::Unretained(this)))), | 152 base::Unretained(this)))), |
| 150 frame_trace_recorder_(new DevToolsFrameTraceRecorder()), | 153 frame_trace_recorder_(new DevToolsFrameTraceRecorder()), |
| 151 reattaching_(false) { | 154 reattaching_(false) { |
| 152 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 155 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
| 153 dispatcher->SetDOMHandler(dom_handler_.get()); | 156 dispatcher->SetDOMHandler(dom_handler_.get()); |
| 157 dispatcher->SetEmulationHandler(emulation_handler_.get()); |
| 154 dispatcher->SetInputHandler(input_handler_.get()); | 158 dispatcher->SetInputHandler(input_handler_.get()); |
| 155 dispatcher->SetInspectorHandler(inspector_handler_.get()); | 159 dispatcher->SetInspectorHandler(inspector_handler_.get()); |
| 156 dispatcher->SetNetworkHandler(network_handler_.get()); | 160 dispatcher->SetNetworkHandler(network_handler_.get()); |
| 157 dispatcher->SetPageHandler(page_handler_.get()); | 161 dispatcher->SetPageHandler(page_handler_.get()); |
| 158 dispatcher->SetPowerHandler(power_handler_.get()); | 162 dispatcher->SetPowerHandler(power_handler_.get()); |
| 159 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); | 163 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); |
| 160 dispatcher->SetTracingHandler(tracing_handler_.get()); | 164 dispatcher->SetTracingHandler(tracing_handler_.get()); |
| 161 SetRenderFrameHost(rfh); | 165 SetRenderFrameHost(rfh); |
| 162 g_instances.Get().push_back(this); | 166 g_instances.Get().push_back(this); |
| 163 AddRef(); // Balanced in RenderFrameHostDestroyed. | 167 AddRef(); // Balanced in RenderFrameHostDestroyed. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 power_save_blocker_.get()-> | 237 power_save_blocker_.get()-> |
| 234 InitDisplaySleepBlocker(rvh->GetView()->GetNativeView()); | 238 InitDisplaySleepBlocker(rvh->GetView()->GetNativeView()); |
| 235 } | 239 } |
| 236 #endif | 240 #endif |
| 237 } | 241 } |
| 238 | 242 |
| 239 void RenderFrameDevToolsAgentHost::OnClientDetached() { | 243 void RenderFrameDevToolsAgentHost::OnClientDetached() { |
| 240 #if defined(OS_ANDROID) | 244 #if defined(OS_ANDROID) |
| 241 power_save_blocker_.reset(); | 245 power_save_blocker_.reset(); |
| 242 #endif | 246 #endif |
| 247 emulation_handler_->Detached(); |
| 243 page_handler_->Detached(); | 248 page_handler_->Detached(); |
| 244 power_handler_->Detached(); | 249 power_handler_->Detached(); |
| 245 service_worker_handler_->Detached(); | 250 service_worker_handler_->Detached(); |
| 246 tracing_handler_->Detached(); | 251 tracing_handler_->Detached(); |
| 247 ClientDetachedFromRenderer(); | 252 ClientDetachedFromRenderer(); |
| 248 | 253 |
| 249 // TODO(kaznacheev): Move this call back to DevToolsManager when | 254 // TODO(kaznacheev): Move this call back to DevToolsManager when |
| 250 // extensions::ProcessManager no longer relies on this notification. | 255 // extensions::ProcessManager no longer relies on this notification. |
| 251 if (!reattaching_) | 256 if (!reattaching_) |
| 252 DevToolsAgentHostImpl::NotifyCallbacks(this, false); | 257 DevToolsAgentHostImpl::NotifyCallbacks(this, false); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 DCHECK(!render_frame_host_); | 430 DCHECK(!render_frame_host_); |
| 426 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); | 431 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); |
| 427 // TODO(dgozman): here we should DCHECK that frame host is either root or | 432 // TODO(dgozman): here we should DCHECK that frame host is either root or |
| 428 // cross process subframe, but this requires handling cross-process | 433 // cross process subframe, but this requires handling cross-process |
| 429 // navigation. See http://crbug.com/464993. | 434 // navigation. See http://crbug.com/464993. |
| 430 | 435 |
| 431 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); | 436 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); |
| 432 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 437 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 433 rfh->GetRenderViewHost()); | 438 rfh->GetRenderViewHost()); |
| 434 dom_handler_->SetRenderViewHost(rvh); | 439 dom_handler_->SetRenderViewHost(rvh); |
| 440 emulation_handler_->SetRenderViewHost(rvh); |
| 435 input_handler_->SetRenderViewHost(rvh); | 441 input_handler_->SetRenderViewHost(rvh); |
| 436 network_handler_->SetRenderViewHost(rvh); | 442 network_handler_->SetRenderViewHost(rvh); |
| 437 page_handler_->SetRenderViewHost(rvh); | 443 page_handler_->SetRenderViewHost(rvh); |
| 438 service_worker_handler_->SetRenderFrameHost(render_frame_host_); | 444 service_worker_handler_->SetRenderFrameHost(render_frame_host_); |
| 439 | 445 |
| 440 registrar_.Add( | 446 registrar_.Add( |
| 441 this, | 447 this, |
| 442 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 448 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 443 content::Source<RenderWidgetHost>(rvh)); | 449 content::Source<RenderWidgetHost>(rvh)); |
| 444 } | 450 } |
| 445 | 451 |
| 446 void RenderFrameDevToolsAgentHost::ClearRenderFrameHost() { | 452 void RenderFrameDevToolsAgentHost::ClearRenderFrameHost() { |
| 447 DCHECK(render_frame_host_); | 453 DCHECK(render_frame_host_); |
| 448 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 454 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 449 render_frame_host_->GetRenderViewHost()); | 455 render_frame_host_->GetRenderViewHost()); |
| 450 registrar_.Remove( | 456 registrar_.Remove( |
| 451 this, | 457 this, |
| 452 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 458 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 453 content::Source<RenderWidgetHost>(rvh)); | 459 content::Source<RenderWidgetHost>(rvh)); |
| 454 render_frame_host_ = nullptr; | 460 render_frame_host_ = nullptr; |
| 455 dom_handler_->SetRenderViewHost(nullptr); | 461 dom_handler_->SetRenderViewHost(nullptr); |
| 462 emulation_handler_->SetRenderViewHost(nullptr); |
| 456 input_handler_->SetRenderViewHost(nullptr); | 463 input_handler_->SetRenderViewHost(nullptr); |
| 457 network_handler_->SetRenderViewHost(nullptr); | 464 network_handler_->SetRenderViewHost(nullptr); |
| 458 page_handler_->SetRenderViewHost(nullptr); | 465 page_handler_->SetRenderViewHost(nullptr); |
| 459 service_worker_handler_->SetRenderFrameHost(nullptr); | 466 service_worker_handler_->SetRenderFrameHost(nullptr); |
| 460 } | 467 } |
| 461 | 468 |
| 462 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 469 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { |
| 463 DisconnectRenderFrameHost(); | 470 DisconnectRenderFrameHost(); |
| 464 } | 471 } |
| 465 | 472 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 if (!IsAttached() || !render_frame_host_) | 562 if (!IsAttached() || !render_frame_host_) |
| 556 return; | 563 return; |
| 557 SendMessageToClient(message); | 564 SendMessageToClient(message); |
| 558 } | 565 } |
| 559 | 566 |
| 560 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 567 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 561 return render_frame_host_ && render_frame_host_->GetParent(); | 568 return render_frame_host_ && render_frame_host_->GetParent(); |
| 562 } | 569 } |
| 563 | 570 |
| 564 } // namespace content | 571 } // namespace content |
| OLD | NEW |