| 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" | |
| 9 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 11 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
| 12 #include "content/browser/devtools/devtools_frame_trace_recorder.h" | 11 #include "content/browser/devtools/devtools_frame_trace_recorder.h" |
| 13 #include "content/browser/devtools/devtools_manager.h" | 12 #include "content/browser/devtools/devtools_manager.h" |
| 14 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" | 13 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" |
| 15 #include "content/browser/devtools/protocol/dom_handler.h" | 14 #include "content/browser/devtools/protocol/dom_handler.h" |
| 16 #include "content/browser/devtools/protocol/emulation_handler.h" | 15 #include "content/browser/devtools/protocol/emulation_handler.h" |
| 17 #include "content/browser/devtools/protocol/input_handler.h" | 16 #include "content/browser/devtools/protocol/input_handler.h" |
| 18 #include "content/browser/devtools/protocol/inspector_handler.h" | 17 #include "content/browser/devtools/protocol/inspector_handler.h" |
| 19 #include "content/browser/devtools/protocol/network_handler.h" | 18 #include "content/browser/devtools/protocol/network_handler.h" |
| 20 #include "content/browser/devtools/protocol/page_handler.h" | 19 #include "content/browser/devtools/protocol/page_handler.h" |
| 21 #include "content/browser/devtools/protocol/power_handler.h" | 20 #include "content/browser/devtools/protocol/power_handler.h" |
| 22 #include "content/browser/devtools/protocol/service_worker_handler.h" | 21 #include "content/browser/devtools/protocol/service_worker_handler.h" |
| 23 #include "content/browser/devtools/protocol/tracing_handler.h" | 22 #include "content/browser/devtools/protocol/tracing_handler.h" |
| 24 #include "content/browser/frame_host/render_frame_host_impl.h" | 23 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 25 #include "content/browser/renderer_host/render_process_host_impl.h" | 24 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 26 #include "content/browser/renderer_host/render_view_host_impl.h" | 25 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 27 #include "content/browser/site_instance_impl.h" | 26 #include "content/browser/site_instance_impl.h" |
| 28 #include "content/browser/web_contents/web_contents_impl.h" | 27 #include "content/browser/web_contents/web_contents_impl.h" |
| 29 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
| 30 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
| 31 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
| 32 #include "content/public/browser/devtools_manager_delegate.h" | |
| 33 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
| 35 #include "content/public/browser/render_widget_host_iterator.h" | 33 #include "content/public/browser/render_widget_host_iterator.h" |
| 36 #include "content/public/browser/web_contents_delegate.h" | 34 #include "content/public/browser/web_contents_delegate.h" |
| 37 | 35 |
| 38 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
| 39 #include "content/browser/power_save_blocker_impl.h" | 37 #include "content/browser/power_save_blocker_impl.h" |
| 40 #include "content/public/browser/render_widget_host_view.h" | 38 #include "content/public/browser/render_widget_host_view.h" |
| 41 #endif | 39 #endif |
| 42 | 40 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 inspector_handler_(new devtools::inspector::InspectorHandler()), | 138 inspector_handler_(new devtools::inspector::InspectorHandler()), |
| 141 network_handler_(new devtools::network::NetworkHandler()), | 139 network_handler_(new devtools::network::NetworkHandler()), |
| 142 page_handler_(new devtools::page::PageHandler()), | 140 page_handler_(new devtools::page::PageHandler()), |
| 143 power_handler_(new devtools::power::PowerHandler()), | 141 power_handler_(new devtools::power::PowerHandler()), |
| 144 service_worker_handler_( | 142 service_worker_handler_( |
| 145 new devtools::service_worker::ServiceWorkerHandler()), | 143 new devtools::service_worker::ServiceWorkerHandler()), |
| 146 tracing_handler_(new devtools::tracing::TracingHandler( | 144 tracing_handler_(new devtools::tracing::TracingHandler( |
| 147 devtools::tracing::TracingHandler::Renderer)), | 145 devtools::tracing::TracingHandler::Renderer)), |
| 148 emulation_handler_(new devtools::emulation::EmulationHandler( | 146 emulation_handler_(new devtools::emulation::EmulationHandler( |
| 149 page_handler_.get())), | 147 page_handler_.get())), |
| 150 protocol_handler_(new DevToolsProtocolHandler( | |
| 151 base::Bind(&RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend, | |
| 152 base::Unretained(this)))), | |
| 153 frame_trace_recorder_(new DevToolsFrameTraceRecorder()), | 148 frame_trace_recorder_(new DevToolsFrameTraceRecorder()), |
| 154 reattaching_(false) { | 149 reattaching_(false) { |
| 155 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 150 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
| 156 dispatcher->SetDOMHandler(dom_handler_.get()); | 151 dispatcher->SetDOMHandler(dom_handler_.get()); |
| 157 dispatcher->SetEmulationHandler(emulation_handler_.get()); | 152 dispatcher->SetEmulationHandler(emulation_handler_.get()); |
| 158 dispatcher->SetInputHandler(input_handler_.get()); | 153 dispatcher->SetInputHandler(input_handler_.get()); |
| 159 dispatcher->SetInspectorHandler(inspector_handler_.get()); | 154 dispatcher->SetInspectorHandler(inspector_handler_.get()); |
| 160 dispatcher->SetNetworkHandler(network_handler_.get()); | 155 dispatcher->SetNetworkHandler(network_handler_.get()); |
| 161 dispatcher->SetPageHandler(page_handler_.get()); | 156 dispatcher->SetPageHandler(page_handler_.get()); |
| 162 dispatcher->SetPowerHandler(power_handler_.get()); | 157 dispatcher->SetPowerHandler(power_handler_.get()); |
| 163 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); | 158 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); |
| 164 dispatcher->SetTracingHandler(tracing_handler_.get()); | 159 dispatcher->SetTracingHandler(tracing_handler_.get()); |
| 165 SetRenderFrameHost(rfh); | 160 SetRenderFrameHost(rfh); |
| 166 g_instances.Get().push_back(this); | 161 g_instances.Get().push_back(this); |
| 167 AddRef(); // Balanced in RenderFrameHostDestroyed. | 162 AddRef(); // Balanced in RenderFrameHostDestroyed. |
| 168 DevToolsManager::GetInstance()->AgentHostChanged(this); | 163 DevToolsManager::GetInstance()->AgentHostChanged(this); |
| 169 } | 164 } |
| 170 | 165 |
| 171 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { | 166 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { |
| 172 WebContents* contents = web_contents(); | 167 WebContents* contents = web_contents(); |
| 173 return contents ? contents->GetBrowserContext() : nullptr; | 168 return contents ? contents->GetBrowserContext() : nullptr; |
| 174 } | 169 } |
| 175 | 170 |
| 176 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { | 171 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { |
| 177 return web_contents(); | 172 return web_contents(); |
| 178 } | 173 } |
| 179 | 174 |
| 180 void RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | |
| 181 const std::string& message) { | |
| 182 scoped_ptr<base::DictionaryValue> command = | |
| 183 protocol_handler_->ParseCommand(message); | |
| 184 if (!command) | |
| 185 return; | |
| 186 | |
| 187 DevToolsManagerDelegate* delegate = | |
| 188 DevToolsManager::GetInstance()->delegate(); | |
| 189 if (delegate) { | |
| 190 scoped_ptr<base::DictionaryValue> response( | |
| 191 delegate->HandleCommand(this, command.get())); | |
| 192 if (response) { | |
| 193 std::string json_response; | |
| 194 base::JSONWriter::Write(response.get(), &json_response); | |
| 195 DispatchOnInspectorFrontend(json_response); | |
| 196 return; | |
| 197 } | |
| 198 } | |
| 199 | |
| 200 if (protocol_handler_->HandleOptionalCommand(command.Pass())) | |
| 201 return; | |
| 202 | |
| 203 IPCDevToolsAgentHost::DispatchProtocolMessage(message); | |
| 204 } | |
| 205 | |
| 206 void RenderFrameDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { | 175 void RenderFrameDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { |
| 207 if (!render_frame_host_) | 176 if (!render_frame_host_) |
| 208 return; | 177 return; |
| 209 msg->set_routing_id(render_frame_host_->GetRoutingID()); | 178 msg->set_routing_id(render_frame_host_->GetRoutingID()); |
| 210 render_frame_host_->Send(msg); | 179 render_frame_host_->Send(msg); |
| 211 } | 180 } |
| 212 | 181 |
| 213 void RenderFrameDevToolsAgentHost::OnClientAttached() { | 182 void RenderFrameDevToolsAgentHost::OnClientAttached() { |
| 214 if (!render_frame_host_) | 183 if (!render_frame_host_) |
| 215 return; | 184 return; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 return host == render_frame_host_; | 519 return host == render_frame_host_; |
| 551 } | 520 } |
| 552 | 521 |
| 553 void RenderFrameDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 522 void RenderFrameDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 554 const DevToolsMessageChunk& message) { | 523 const DevToolsMessageChunk& message) { |
| 555 if (!IsAttached() || !render_frame_host_) | 524 if (!IsAttached() || !render_frame_host_) |
| 556 return; | 525 return; |
| 557 ProcessChunkedMessageFromAgent(message); | 526 ProcessChunkedMessageFromAgent(message); |
| 558 } | 527 } |
| 559 | 528 |
| 560 void RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend( | |
| 561 const std::string& message) { | |
| 562 if (!IsAttached() || !render_frame_host_) | |
| 563 return; | |
| 564 SendMessageToClient(message); | |
| 565 } | |
| 566 | |
| 567 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 529 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 568 return render_frame_host_ && render_frame_host_->GetParent(); | 530 return render_frame_host_ && render_frame_host_->GetParent(); |
| 569 } | 531 } |
| 570 | 532 |
| 571 } // namespace content | 533 } // namespace content |
| OLD | NEW |