| 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 <tuple> | 7 #include <tuple> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/json/json_reader.h" |
| 11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "content/browser/bad_message.h" | 15 #include "content/browser/bad_message.h" |
| 15 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
| 16 #include "content/browser/devtools/devtools_frame_trace_recorder.h" | 17 #include "content/browser/devtools/devtools_frame_trace_recorder.h" |
| 17 #include "content/browser/devtools/devtools_manager.h" | 18 #include "content/browser/devtools/devtools_manager.h" |
| 18 #include "content/browser/devtools/devtools_protocol_handler.h" | 19 #include "content/browser/devtools/devtools_protocol_handler.h" |
| 19 #include "content/browser/devtools/page_navigation_throttle.h" | 20 #include "content/browser/devtools/page_navigation_throttle.h" |
| 20 #include "content/browser/devtools/protocol/dom_handler.h" | 21 #include "content/browser/devtools/protocol/dom_handler.h" |
| 21 #include "content/browser/devtools/protocol/emulation_handler.h" | 22 #include "content/browser/devtools/protocol/emulation_handler.h" |
| 22 #include "content/browser/devtools/protocol/input_handler.h" | 23 #include "content/browser/devtools/protocol/input_handler.h" |
| 23 #include "content/browser/devtools/protocol/inspector_handler.h" | 24 #include "content/browser/devtools/protocol/inspector_handler.h" |
| 24 #include "content/browser/devtools/protocol/io_handler.h" | 25 #include "content/browser/devtools/protocol/io_handler.h" |
| 25 #include "content/browser/devtools/protocol/network_handler.h" | 26 #include "content/browser/devtools/protocol/network_handler.h" |
| 26 #include "content/browser/devtools/protocol/page_handler.h" | 27 #include "content/browser/devtools/protocol/page_handler.h" |
| 28 #include "content/browser/devtools/protocol/protocol.h" |
| 27 #include "content/browser/devtools/protocol/schema_handler.h" | 29 #include "content/browser/devtools/protocol/schema_handler.h" |
| 28 #include "content/browser/devtools/protocol/security_handler.h" | 30 #include "content/browser/devtools/protocol/security_handler.h" |
| 29 #include "content/browser/devtools/protocol/service_worker_handler.h" | 31 #include "content/browser/devtools/protocol/service_worker_handler.h" |
| 30 #include "content/browser/devtools/protocol/storage_handler.h" | 32 #include "content/browser/devtools/protocol/storage_handler.h" |
| 31 #include "content/browser/devtools/protocol/target_handler.h" | 33 #include "content/browser/devtools/protocol/target_handler.h" |
| 32 #include "content/browser/devtools/protocol/tracing_handler.h" | 34 #include "content/browser/devtools/protocol/tracing_handler.h" |
| 33 #include "content/browser/frame_host/navigation_handle_impl.h" | 35 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 34 #include "content/browser/frame_host/render_frame_host_impl.h" | 36 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 35 #include "content/browser/renderer_host/input/input_router_impl.h" | 37 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 36 #include "content/browser/renderer_host/render_process_host_impl.h" | 38 #include "content/browser/renderer_host/render_process_host_impl.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 DevToolsAgentHost::GetOrCreateFor(web_contents); | 390 DevToolsAgentHost::GetOrCreateFor(web_contents); |
| 389 } | 391 } |
| 390 } | 392 } |
| 391 | 393 |
| 392 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( | 394 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( |
| 393 RenderFrameHostImpl* host) | 395 RenderFrameHostImpl* host) |
| 394 : DevToolsAgentHostImpl(base::GenerateGUID()), | 396 : DevToolsAgentHostImpl(base::GenerateGUID()), |
| 395 dom_handler_(new devtools::dom::DOMHandler()), | 397 dom_handler_(new devtools::dom::DOMHandler()), |
| 396 input_handler_(new devtools::input::InputHandler()), | 398 input_handler_(new devtools::input::InputHandler()), |
| 397 inspector_handler_(new devtools::inspector::InspectorHandler()), | 399 inspector_handler_(new devtools::inspector::InspectorHandler()), |
| 398 io_handler_(new devtools::io::IOHandler(GetIOContext())), | 400 io_handler_(new protocol::IOHandler(GetIOContext())), |
| 399 network_handler_(new devtools::network::NetworkHandler()), | 401 network_handler_(new devtools::network::NetworkHandler()), |
| 400 page_handler_(nullptr), | 402 page_handler_(nullptr), |
| 401 schema_handler_(new devtools::schema::SchemaHandler()), | 403 schema_handler_(new devtools::schema::SchemaHandler()), |
| 402 security_handler_(nullptr), | 404 security_handler_(nullptr), |
| 403 service_worker_handler_( | 405 service_worker_handler_( |
| 404 new devtools::service_worker::ServiceWorkerHandler()), | 406 new devtools::service_worker::ServiceWorkerHandler()), |
| 405 storage_handler_(new devtools::storage::StorageHandler()), | 407 storage_handler_(new devtools::storage::StorageHandler()), |
| 406 target_handler_(new devtools::target::TargetHandler()), | 408 target_handler_(new devtools::target::TargetHandler()), |
| 407 tracing_handler_(new devtools::tracing::TracingHandler( | 409 tracing_handler_(new protocol::TracingHandler( |
| 408 devtools::tracing::TracingHandler::Renderer, | 410 protocol::TracingHandler::Renderer, |
| 409 host->GetFrameTreeNodeId(), | 411 host->GetFrameTreeNodeId(), |
| 410 GetIOContext())), | 412 GetIOContext())), |
| 411 emulation_handler_(nullptr), | 413 emulation_handler_(nullptr), |
| 412 frame_trace_recorder_(nullptr), | 414 frame_trace_recorder_(nullptr), |
| 413 protocol_handler_(new DevToolsProtocolHandler(this)), | 415 protocol_handler_(new DevToolsProtocolHandler(this)), |
| 416 protocol_dispatcher_(new protocol::UberDispatcher(this, true)), |
| 414 handlers_frame_host_(nullptr), | 417 handlers_frame_host_(nullptr), |
| 415 current_frame_crashed_(false), | 418 current_frame_crashed_(false), |
| 416 pending_handle_(nullptr), | 419 pending_handle_(nullptr), |
| 417 frame_tree_node_(host->frame_tree_node()) { | 420 frame_tree_node_(host->frame_tree_node()) { |
| 418 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 421 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
| 419 dispatcher->SetDOMHandler(dom_handler_.get()); | 422 dispatcher->SetDOMHandler(dom_handler_.get()); |
| 420 dispatcher->SetInputHandler(input_handler_.get()); | 423 dispatcher->SetInputHandler(input_handler_.get()); |
| 421 dispatcher->SetInspectorHandler(inspector_handler_.get()); | 424 dispatcher->SetInspectorHandler(inspector_handler_.get()); |
| 422 dispatcher->SetIOHandler(io_handler_.get()); | 425 io_handler_->Wire(protocol_dispatcher_.get()); |
| 423 dispatcher->SetNetworkHandler(network_handler_.get()); | 426 dispatcher->SetNetworkHandler(network_handler_.get()); |
| 424 dispatcher->SetSchemaHandler(schema_handler_.get()); | 427 dispatcher->SetSchemaHandler(schema_handler_.get()); |
| 425 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); | 428 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); |
| 426 dispatcher->SetStorageHandler(storage_handler_.get()); | 429 dispatcher->SetStorageHandler(storage_handler_.get()); |
| 427 dispatcher->SetTargetHandler(target_handler_.get()); | 430 dispatcher->SetTargetHandler(target_handler_.get()); |
| 428 dispatcher->SetTracingHandler(tracing_handler_.get()); | 431 tracing_handler_->Wire(protocol_dispatcher_.get()); |
| 429 | 432 |
| 430 if (!host->GetParent()) { | 433 if (!host->GetParent()) { |
| 431 security_handler_.reset(new devtools::security::SecurityHandler()); | 434 security_handler_.reset(new devtools::security::SecurityHandler()); |
| 432 page_handler_.reset(new devtools::page::PageHandler()); | 435 page_handler_.reset(new devtools::page::PageHandler()); |
| 433 emulation_handler_.reset( | 436 emulation_handler_.reset( |
| 434 new devtools::emulation::EmulationHandler()); | 437 new devtools::emulation::EmulationHandler()); |
| 435 dispatcher->SetSecurityHandler(security_handler_.get()); | 438 dispatcher->SetSecurityHandler(security_handler_.get()); |
| 436 dispatcher->SetPageHandler(page_handler_.get()); | 439 dispatcher->SetPageHandler(page_handler_.get()); |
| 437 dispatcher->SetEmulationHandler(emulation_handler_.get()); | 440 dispatcher->SetEmulationHandler(emulation_handler_.get()); |
| 438 } | 441 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 void RenderFrameDevToolsAgentHost::Detach() { | 512 void RenderFrameDevToolsAgentHost::Detach() { |
| 510 if (current_) | 513 if (current_) |
| 511 current_->Detach(); | 514 current_->Detach(); |
| 512 if (pending_) | 515 if (pending_) |
| 513 pending_->Detach(); | 516 pending_->Detach(); |
| 514 OnClientDetached(); | 517 OnClientDetached(); |
| 515 } | 518 } |
| 516 | 519 |
| 517 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 520 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( |
| 518 const std::string& message) { | 521 const std::string& message) { |
| 522 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); |
| 523 if (protocol_dispatcher_->dispatch( |
| 524 protocol::toProtocolValue(value.get(), 1000)) != |
| 525 protocol::Response::kFallThrough) { |
| 526 return true; |
| 527 } |
| 528 |
| 519 int call_id = 0; | 529 int call_id = 0; |
| 520 std::string method; | 530 std::string method; |
| 521 if (protocol_handler_->HandleOptionalMessage(session_id(), message, &call_id, | 531 if (protocol_handler_->HandleOptionalMessage( |
| 522 &method)) | 532 session_id(), std::move(value), &call_id, &method)) { |
| 523 return true; | 533 return true; |
| 534 } |
| 524 | 535 |
| 525 if (!navigating_handles_.empty()) { | 536 if (!navigating_handles_.empty()) { |
| 526 DCHECK(IsBrowserSideNavigationEnabled()); | 537 DCHECK(IsBrowserSideNavigationEnabled()); |
| 527 in_navigation_protocol_message_buffer_[call_id] = | 538 in_navigation_protocol_message_buffer_[call_id] = |
| 528 { session_id(), method, message }; | 539 { session_id(), method, message }; |
| 529 return true; | 540 return true; |
| 530 } | 541 } |
| 531 | 542 |
| 532 if (current_) | 543 if (current_) |
| 533 current_->DispatchProtocolMessage(session_id(), call_id, method, message); | 544 current_->DispatchProtocolMessage(session_id(), call_id, method, message); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 RenderFrameHost* host) { | 1127 RenderFrameHost* host) { |
| 1117 return (current_ && current_->host() == host) || | 1128 return (current_ && current_->host() == host) || |
| 1118 (pending_ && pending_->host() == host); | 1129 (pending_ && pending_->host() == host); |
| 1119 } | 1130 } |
| 1120 | 1131 |
| 1121 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1132 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1122 return current_ && current_->host()->GetParent(); | 1133 return current_ && current_->host()->GetParent(); |
| 1123 } | 1134 } |
| 1124 | 1135 |
| 1125 } // namespace content | 1136 } // namespace content |
| OLD | NEW |