| 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/devtools_session.h" | 20 #include "content/browser/devtools/devtools_session.h" |
| 20 #include "content/browser/devtools/page_navigation_throttle.h" | 21 #include "content/browser/devtools/page_navigation_throttle.h" |
| 21 #include "content/browser/devtools/protocol/dom_handler.h" | 22 #include "content/browser/devtools/protocol/dom_handler.h" |
| 22 #include "content/browser/devtools/protocol/emulation_handler.h" | 23 #include "content/browser/devtools/protocol/emulation_handler.h" |
| 23 #include "content/browser/devtools/protocol/input_handler.h" | 24 #include "content/browser/devtools/protocol/input_handler.h" |
| 24 #include "content/browser/devtools/protocol/inspector_handler.h" | 25 #include "content/browser/devtools/protocol/inspector_handler.h" |
| 25 #include "content/browser/devtools/protocol/io_handler.h" | 26 #include "content/browser/devtools/protocol/io_handler.h" |
| 26 #include "content/browser/devtools/protocol/network_handler.h" | 27 #include "content/browser/devtools/protocol/network_handler.h" |
| 27 #include "content/browser/devtools/protocol/page_handler.h" | 28 #include "content/browser/devtools/protocol/page_handler.h" |
| 29 #include "content/browser/devtools/protocol/protocol.h" |
| 28 #include "content/browser/devtools/protocol/schema_handler.h" | 30 #include "content/browser/devtools/protocol/schema_handler.h" |
| 29 #include "content/browser/devtools/protocol/security_handler.h" | 31 #include "content/browser/devtools/protocol/security_handler.h" |
| 30 #include "content/browser/devtools/protocol/service_worker_handler.h" | 32 #include "content/browser/devtools/protocol/service_worker_handler.h" |
| 31 #include "content/browser/devtools/protocol/storage_handler.h" | 33 #include "content/browser/devtools/protocol/storage_handler.h" |
| 32 #include "content/browser/devtools/protocol/target_handler.h" | 34 #include "content/browser/devtools/protocol/target_handler.h" |
| 33 #include "content/browser/devtools/protocol/tracing_handler.h" | 35 #include "content/browser/devtools/protocol/tracing_handler.h" |
| 34 #include "content/browser/frame_host/navigation_handle_impl.h" | 36 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 35 #include "content/browser/frame_host/render_frame_host_impl.h" | 37 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 36 #include "content/browser/renderer_host/input/input_router_impl.h" | 38 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 37 #include "content/browser/renderer_host/render_process_host_impl.h" | 39 #include "content/browser/renderer_host/render_process_host_impl.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 DevToolsAgentHost::GetOrCreateFor(web_contents); | 391 DevToolsAgentHost::GetOrCreateFor(web_contents); |
| 390 } | 392 } |
| 391 } | 393 } |
| 392 | 394 |
| 393 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( | 395 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( |
| 394 RenderFrameHostImpl* host) | 396 RenderFrameHostImpl* host) |
| 395 : DevToolsAgentHostImpl(base::GenerateGUID()), | 397 : DevToolsAgentHostImpl(base::GenerateGUID()), |
| 396 dom_handler_(new devtools::dom::DOMHandler()), | 398 dom_handler_(new devtools::dom::DOMHandler()), |
| 397 input_handler_(new devtools::input::InputHandler()), | 399 input_handler_(new devtools::input::InputHandler()), |
| 398 inspector_handler_(new devtools::inspector::InspectorHandler()), | 400 inspector_handler_(new devtools::inspector::InspectorHandler()), |
| 399 io_handler_(new devtools::io::IOHandler(GetIOContext())), | |
| 400 network_handler_(new devtools::network::NetworkHandler()), | 401 network_handler_(new devtools::network::NetworkHandler()), |
| 401 page_handler_(nullptr), | 402 page_handler_(nullptr), |
| 402 schema_handler_(new devtools::schema::SchemaHandler()), | 403 schema_handler_(new devtools::schema::SchemaHandler()), |
| 403 security_handler_(nullptr), | 404 security_handler_(nullptr), |
| 404 service_worker_handler_( | 405 service_worker_handler_( |
| 405 new devtools::service_worker::ServiceWorkerHandler()), | 406 new devtools::service_worker::ServiceWorkerHandler()), |
| 406 storage_handler_(new devtools::storage::StorageHandler()), | 407 storage_handler_(new devtools::storage::StorageHandler()), |
| 407 target_handler_(new devtools::target::TargetHandler()), | 408 target_handler_(new devtools::target::TargetHandler()), |
| 408 tracing_handler_(new devtools::tracing::TracingHandler( | |
| 409 devtools::tracing::TracingHandler::Renderer, | |
| 410 host->GetFrameTreeNodeId(), | |
| 411 GetIOContext())), | |
| 412 emulation_handler_(nullptr), | 409 emulation_handler_(nullptr), |
| 413 frame_trace_recorder_(nullptr), | 410 frame_trace_recorder_(nullptr), |
| 414 protocol_handler_(new DevToolsProtocolHandler(this)), | 411 protocol_handler_(new DevToolsProtocolHandler(this)), |
| 415 handlers_frame_host_(nullptr), | 412 handlers_frame_host_(nullptr), |
| 416 current_frame_crashed_(false), | 413 current_frame_crashed_(false), |
| 417 pending_handle_(nullptr), | 414 pending_handle_(nullptr), |
| 418 frame_tree_node_(host->frame_tree_node()) { | 415 frame_tree_node_(host->frame_tree_node()) { |
| 419 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 416 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
| 420 dispatcher->SetDOMHandler(dom_handler_.get()); | 417 dispatcher->SetDOMHandler(dom_handler_.get()); |
| 421 dispatcher->SetInputHandler(input_handler_.get()); | 418 dispatcher->SetInputHandler(input_handler_.get()); |
| 422 dispatcher->SetInspectorHandler(inspector_handler_.get()); | 419 dispatcher->SetInspectorHandler(inspector_handler_.get()); |
| 423 dispatcher->SetIOHandler(io_handler_.get()); | |
| 424 dispatcher->SetNetworkHandler(network_handler_.get()); | 420 dispatcher->SetNetworkHandler(network_handler_.get()); |
| 425 dispatcher->SetSchemaHandler(schema_handler_.get()); | 421 dispatcher->SetSchemaHandler(schema_handler_.get()); |
| 426 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); | 422 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); |
| 427 dispatcher->SetStorageHandler(storage_handler_.get()); | 423 dispatcher->SetStorageHandler(storage_handler_.get()); |
| 428 dispatcher->SetTargetHandler(target_handler_.get()); | 424 dispatcher->SetTargetHandler(target_handler_.get()); |
| 429 dispatcher->SetTracingHandler(tracing_handler_.get()); | |
| 430 | 425 |
| 431 if (!host->GetParent()) { | 426 if (!host->GetParent()) { |
| 432 security_handler_.reset(new devtools::security::SecurityHandler()); | 427 security_handler_.reset(new devtools::security::SecurityHandler()); |
| 433 page_handler_.reset(new devtools::page::PageHandler()); | 428 page_handler_.reset(new devtools::page::PageHandler()); |
| 434 emulation_handler_.reset( | 429 emulation_handler_.reset( |
| 435 new devtools::emulation::EmulationHandler()); | 430 new devtools::emulation::EmulationHandler()); |
| 436 dispatcher->SetSecurityHandler(security_handler_.get()); | 431 dispatcher->SetSecurityHandler(security_handler_.get()); |
| 437 dispatcher->SetPageHandler(page_handler_.get()); | 432 dispatcher->SetPageHandler(page_handler_.get()); |
| 438 dispatcher->SetEmulationHandler(emulation_handler_.get()); | 433 dispatcher->SetEmulationHandler(emulation_handler_.get()); |
| 439 } | 434 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { | 488 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { |
| 494 WebContents* contents = web_contents(); | 489 WebContents* contents = web_contents(); |
| 495 return contents ? contents->GetBrowserContext() : nullptr; | 490 return contents ? contents->GetBrowserContext() : nullptr; |
| 496 } | 491 } |
| 497 | 492 |
| 498 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { | 493 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { |
| 499 return web_contents(); | 494 return web_contents(); |
| 500 } | 495 } |
| 501 | 496 |
| 502 void RenderFrameDevToolsAgentHost::Attach() { | 497 void RenderFrameDevToolsAgentHost::Attach() { |
| 498 session()->dispatcher()->setFallThroughForNotFound(true); |
| 499 |
| 500 io_handler_.reset(new protocol::IOHandler(GetIOContext())); |
| 501 io_handler_->Wire(session()->dispatcher()); |
| 502 |
| 503 tracing_handler_.reset(new protocol::TracingHandler( |
| 504 protocol::TracingHandler::Renderer, |
| 505 frame_tree_node_->frame_tree_node_id(), |
| 506 GetIOContext())); |
| 507 tracing_handler_->Wire(session()->dispatcher()); |
| 508 |
| 503 if (current_) | 509 if (current_) |
| 504 current_->Attach(); | 510 current_->Attach(); |
| 505 if (pending_) | 511 if (pending_) |
| 506 pending_->Attach(); | 512 pending_->Attach(); |
| 507 OnClientAttached(); | 513 OnClientAttached(); |
| 508 } | 514 } |
| 509 | 515 |
| 510 void RenderFrameDevToolsAgentHost::Detach() { | 516 void RenderFrameDevToolsAgentHost::Detach() { |
| 517 io_handler_->Disable(); |
| 518 io_handler_.reset(); |
| 519 tracing_handler_->Disable(); |
| 520 tracing_handler_.reset(); |
| 521 |
| 511 if (current_) | 522 if (current_) |
| 512 current_->Detach(); | 523 current_->Detach(); |
| 513 if (pending_) | 524 if (pending_) |
| 514 pending_->Detach(); | 525 pending_->Detach(); |
| 515 OnClientDetached(); | 526 OnClientDetached(); |
| 516 } | 527 } |
| 517 | 528 |
| 518 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 529 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( |
| 519 const std::string& message) { | 530 const std::string& message) { |
| 531 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); |
| 532 std::unique_ptr<protocol::Value> protocolValue = |
| 533 protocol::toProtocolValue(value.get(), 1000); |
| 534 if (session()->dispatcher()->dispatch(std::move(protocolValue)) != |
| 535 protocol::Response::kFallThrough) { |
| 536 return true; |
| 537 } |
| 538 |
| 520 int call_id = 0; | 539 int call_id = 0; |
| 521 std::string method; | 540 std::string method; |
| 522 if (protocol_handler_->HandleOptionalMessage(session()->session_id(), message, | 541 if (protocol_handler_->HandleOptionalMessage( |
| 523 &call_id, &method)) | 542 session()->session_id(), std::move(value), &call_id, &method)) { |
| 524 return true; | 543 return true; |
| 544 } |
| 525 | 545 |
| 526 if (!navigating_handles_.empty()) { | 546 if (!navigating_handles_.empty()) { |
| 527 DCHECK(IsBrowserSideNavigationEnabled()); | 547 DCHECK(IsBrowserSideNavigationEnabled()); |
| 528 in_navigation_protocol_message_buffer_[call_id] = | 548 in_navigation_protocol_message_buffer_[call_id] = |
| 529 { session()->session_id(), method, message }; | 549 { session()->session_id(), method, message }; |
| 530 return true; | 550 return true; |
| 531 } | 551 } |
| 532 | 552 |
| 533 if (current_) { | 553 if (current_) { |
| 534 current_->DispatchProtocolMessage( | 554 current_->DispatchProtocolMessage( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 559 void RenderFrameDevToolsAgentHost::OnClientDetached() { | 579 void RenderFrameDevToolsAgentHost::OnClientDetached() { |
| 560 #if defined(OS_ANDROID) | 580 #if defined(OS_ANDROID) |
| 561 power_save_blocker_.reset(); | 581 power_save_blocker_.reset(); |
| 562 #endif | 582 #endif |
| 563 if (emulation_handler_) | 583 if (emulation_handler_) |
| 564 emulation_handler_->Detached(); | 584 emulation_handler_->Detached(); |
| 565 if (page_handler_) | 585 if (page_handler_) |
| 566 page_handler_->Detached(); | 586 page_handler_->Detached(); |
| 567 service_worker_handler_->Detached(); | 587 service_worker_handler_->Detached(); |
| 568 target_handler_->Detached(); | 588 target_handler_->Detached(); |
| 569 tracing_handler_->Detached(); | |
| 570 frame_trace_recorder_.reset(); | 589 frame_trace_recorder_.reset(); |
| 571 in_navigation_protocol_message_buffer_.clear(); | 590 in_navigation_protocol_message_buffer_.clear(); |
| 572 } | 591 } |
| 573 | 592 |
| 574 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { | 593 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { |
| 575 Instances::iterator it = std::find(g_instances.Get().begin(), | 594 Instances::iterator it = std::find(g_instances.Get().begin(), |
| 576 g_instances.Get().end(), | 595 g_instances.Get().end(), |
| 577 this); | 596 this); |
| 578 if (it != g_instances.Get().end()) | 597 if (it != g_instances.Get().end()) |
| 579 g_instances.Get().erase(it); | 598 g_instances.Get().erase(it); |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 RenderFrameHost* host) { | 1140 RenderFrameHost* host) { |
| 1122 return (current_ && current_->host() == host) || | 1141 return (current_ && current_->host() == host) || |
| 1123 (pending_ && pending_->host() == host); | 1142 (pending_ && pending_->host() == host); |
| 1124 } | 1143 } |
| 1125 | 1144 |
| 1126 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1145 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1127 return current_ && current_->host()->GetParent(); | 1146 return current_ && current_->host()->GetParent(); |
| 1128 } | 1147 } |
| 1129 | 1148 |
| 1130 } // namespace content | 1149 } // namespace content |
| OLD | NEW |