| 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" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 return agent_host->page_handler_->CreateThrottleForNavigation( | 371 return agent_host->page_handler_->CreateThrottleForNavigation( |
| 372 navigation_handle); | 372 navigation_handle); |
| 373 } | 373 } |
| 374 return nullptr; | 374 return nullptr; |
| 375 } | 375 } |
| 376 | 376 |
| 377 // static | 377 // static |
| 378 bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled( | 378 bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled( |
| 379 FrameTreeNode* frame_tree_node) { | 379 FrameTreeNode* frame_tree_node) { |
| 380 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 380 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
| 381 if (!agent_host) | 381 return agent_host && agent_host->network_handler_ && |
| 382 return false; | 382 agent_host->network_handler_->enabled(); |
| 383 return agent_host->network_handler_->enabled(); | |
| 384 } | 383 } |
| 385 | 384 |
| 386 // static | 385 // static |
| 387 void RenderFrameDevToolsAgentHost::WebContentsCreated( | 386 void RenderFrameDevToolsAgentHost::WebContentsCreated( |
| 388 WebContents* web_contents) { | 387 WebContents* web_contents) { |
| 389 if (ShouldForceCreation()) { | 388 if (ShouldForceCreation()) { |
| 390 // Force agent host. | 389 // Force agent host. |
| 391 DevToolsAgentHost::GetOrCreateFor(web_contents); | 390 DevToolsAgentHost::GetOrCreateFor(web_contents); |
| 392 } | 391 } |
| 393 } | 392 } |
| 394 | 393 |
| 395 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( | 394 RenderFrameDevToolsAgentHost::RenderFrameDevToolsAgentHost( |
| 396 RenderFrameHostImpl* host) | 395 RenderFrameHostImpl* host) |
| 397 : DevToolsAgentHostImpl(base::GenerateGUID()), | 396 : DevToolsAgentHostImpl(base::GenerateGUID()), |
| 398 dom_handler_(new devtools::dom::DOMHandler()), | |
| 399 input_handler_(new devtools::input::InputHandler()), | 397 input_handler_(new devtools::input::InputHandler()), |
| 400 inspector_handler_(new devtools::inspector::InspectorHandler()), | |
| 401 network_handler_(new devtools::network::NetworkHandler()), | |
| 402 page_handler_(nullptr), | |
| 403 schema_handler_(new devtools::schema::SchemaHandler()), | |
| 404 security_handler_(nullptr), | 398 security_handler_(nullptr), |
| 405 service_worker_handler_( | 399 service_worker_handler_( |
| 406 new devtools::service_worker::ServiceWorkerHandler()), | 400 new devtools::service_worker::ServiceWorkerHandler()), |
| 407 storage_handler_(new devtools::storage::StorageHandler()), | 401 storage_handler_(new devtools::storage::StorageHandler()), |
| 408 target_handler_(new devtools::target::TargetHandler()), | 402 target_handler_(new devtools::target::TargetHandler()), |
| 409 emulation_handler_(nullptr), | |
| 410 frame_trace_recorder_(nullptr), | 403 frame_trace_recorder_(nullptr), |
| 411 protocol_handler_(new DevToolsProtocolHandler(this)), | 404 protocol_handler_(new DevToolsProtocolHandler(this)), |
| 412 handlers_frame_host_(nullptr), | 405 handlers_frame_host_(nullptr), |
| 413 current_frame_crashed_(false), | 406 current_frame_crashed_(false), |
| 414 pending_handle_(nullptr), | 407 pending_handle_(nullptr), |
| 415 frame_tree_node_(host->frame_tree_node()) { | 408 frame_tree_node_(host->frame_tree_node()) { |
| 416 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 409 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
| 417 dispatcher->SetDOMHandler(dom_handler_.get()); | |
| 418 dispatcher->SetInputHandler(input_handler_.get()); | 410 dispatcher->SetInputHandler(input_handler_.get()); |
| 419 dispatcher->SetInspectorHandler(inspector_handler_.get()); | |
| 420 dispatcher->SetNetworkHandler(network_handler_.get()); | |
| 421 dispatcher->SetSchemaHandler(schema_handler_.get()); | |
| 422 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); | 411 dispatcher->SetServiceWorkerHandler(service_worker_handler_.get()); |
| 423 dispatcher->SetStorageHandler(storage_handler_.get()); | 412 dispatcher->SetStorageHandler(storage_handler_.get()); |
| 424 dispatcher->SetTargetHandler(target_handler_.get()); | 413 dispatcher->SetTargetHandler(target_handler_.get()); |
| 425 | 414 |
| 426 if (!host->GetParent()) { | 415 if (!host->GetParent()) { |
| 427 security_handler_.reset(new devtools::security::SecurityHandler()); | 416 security_handler_.reset(new devtools::security::SecurityHandler()); |
| 428 page_handler_.reset(new devtools::page::PageHandler()); | |
| 429 emulation_handler_.reset( | |
| 430 new devtools::emulation::EmulationHandler()); | |
| 431 dispatcher->SetSecurityHandler(security_handler_.get()); | 417 dispatcher->SetSecurityHandler(security_handler_.get()); |
| 432 dispatcher->SetPageHandler(page_handler_.get()); | |
| 433 dispatcher->SetEmulationHandler(emulation_handler_.get()); | |
| 434 } | 418 } |
| 435 | 419 |
| 436 SetPending(host); | 420 SetPending(host); |
| 437 CommitPending(); | 421 CommitPending(); |
| 438 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); | 422 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host)); |
| 439 | 423 |
| 440 if (web_contents() && web_contents()->GetCrashedStatus() != | 424 if (web_contents() && web_contents()->GetCrashedStatus() != |
| 441 base::TERMINATION_STATUS_STILL_RUNNING) { | 425 base::TERMINATION_STATUS_STILL_RUNNING) { |
| 442 current_frame_crashed_ = true; | 426 current_frame_crashed_ = true; |
| 443 } | 427 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 return contents ? contents->GetBrowserContext() : nullptr; | 474 return contents ? contents->GetBrowserContext() : nullptr; |
| 491 } | 475 } |
| 492 | 476 |
| 493 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { | 477 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { |
| 494 return web_contents(); | 478 return web_contents(); |
| 495 } | 479 } |
| 496 | 480 |
| 497 void RenderFrameDevToolsAgentHost::Attach() { | 481 void RenderFrameDevToolsAgentHost::Attach() { |
| 498 session()->dispatcher()->setFallThroughForNotFound(true); | 482 session()->dispatcher()->setFallThroughForNotFound(true); |
| 499 | 483 |
| 484 if (!frame_tree_node_->parent()) { |
| 485 emulation_handler_.reset(new protocol::EmulationHandler()); |
| 486 emulation_handler_->Wire(session()->dispatcher()); |
| 487 emulation_handler_->SetRenderFrameHost(handlers_frame_host_); |
| 488 } |
| 489 |
| 490 dom_handler_.reset(new protocol::DOMHandler()); |
| 491 dom_handler_->Wire(session()->dispatcher()); |
| 492 dom_handler_->SetRenderFrameHost(handlers_frame_host_); |
| 493 |
| 494 inspector_handler_.reset(new protocol::InspectorHandler()); |
| 495 inspector_handler_->Wire(session()->dispatcher()); |
| 496 inspector_handler_->SetRenderFrameHost(handlers_frame_host_); |
| 497 |
| 500 io_handler_.reset(new protocol::IOHandler(GetIOContext())); | 498 io_handler_.reset(new protocol::IOHandler(GetIOContext())); |
| 501 io_handler_->Wire(session()->dispatcher()); | 499 io_handler_->Wire(session()->dispatcher()); |
| 502 | 500 |
| 501 network_handler_.reset(new protocol::NetworkHandler()); |
| 502 network_handler_->Wire(session()->dispatcher()); |
| 503 network_handler_->SetRenderFrameHost(handlers_frame_host_); |
| 504 |
| 505 if (!frame_tree_node_->parent()) { |
| 506 page_handler_.reset(new protocol::PageHandler()); |
| 507 page_handler_->Wire(session()->dispatcher()); |
| 508 page_handler_->SetRenderFrameHost(handlers_frame_host_); |
| 509 } |
| 510 |
| 511 schema_handler_.reset(new protocol::SchemaHandler()); |
| 512 schema_handler_->Wire(session()->dispatcher()); |
| 513 |
| 503 tracing_handler_.reset(new protocol::TracingHandler( | 514 tracing_handler_.reset(new protocol::TracingHandler( |
| 504 protocol::TracingHandler::Renderer, | 515 protocol::TracingHandler::Renderer, |
| 505 frame_tree_node_->frame_tree_node_id(), | 516 frame_tree_node_->frame_tree_node_id(), |
| 506 GetIOContext())); | 517 GetIOContext())); |
| 507 tracing_handler_->Wire(session()->dispatcher()); | 518 tracing_handler_->Wire(session()->dispatcher()); |
| 508 | 519 |
| 509 if (current_) | 520 if (current_) |
| 510 current_->Attach(); | 521 current_->Attach(); |
| 511 if (pending_) | 522 if (pending_) |
| 512 pending_->Attach(); | 523 pending_->Attach(); |
| 513 OnClientAttached(); | 524 OnClientAttached(); |
| 514 } | 525 } |
| 515 | 526 |
| 516 void RenderFrameDevToolsAgentHost::Detach() { | 527 void RenderFrameDevToolsAgentHost::Detach() { |
| 528 dom_handler_->Disable(); |
| 529 dom_handler_.reset(); |
| 530 if (emulation_handler_) { |
| 531 emulation_handler_->Disable(); |
| 532 emulation_handler_.reset(); |
| 533 } |
| 534 inspector_handler_->Disable(); |
| 535 inspector_handler_.reset(); |
| 517 io_handler_->Disable(); | 536 io_handler_->Disable(); |
| 518 io_handler_.reset(); | 537 io_handler_.reset(); |
| 538 network_handler_->Disable(); |
| 539 network_handler_.reset(); |
| 540 if (page_handler_) { |
| 541 page_handler_->Disable(); |
| 542 page_handler_.reset(); |
| 543 } |
| 544 schema_handler_->Disable(); |
| 545 schema_handler_.reset(); |
| 519 tracing_handler_->Disable(); | 546 tracing_handler_->Disable(); |
| 520 tracing_handler_.reset(); | 547 tracing_handler_.reset(); |
| 521 | 548 |
| 522 if (current_) | 549 if (current_) |
| 523 current_->Detach(); | 550 current_->Detach(); |
| 524 if (pending_) | 551 if (pending_) |
| 525 pending_->Detach(); | 552 pending_->Detach(); |
| 526 OnClientDetached(); | 553 OnClientDetached(); |
| 527 } | 554 } |
| 528 | 555 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 return; | 600 return; |
| 574 | 601 |
| 575 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); | 602 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); |
| 576 CreatePowerSaveBlocker(); | 603 CreatePowerSaveBlocker(); |
| 577 } | 604 } |
| 578 | 605 |
| 579 void RenderFrameDevToolsAgentHost::OnClientDetached() { | 606 void RenderFrameDevToolsAgentHost::OnClientDetached() { |
| 580 #if defined(OS_ANDROID) | 607 #if defined(OS_ANDROID) |
| 581 power_save_blocker_.reset(); | 608 power_save_blocker_.reset(); |
| 582 #endif | 609 #endif |
| 583 if (emulation_handler_) | |
| 584 emulation_handler_->Detached(); | |
| 585 if (page_handler_) | |
| 586 page_handler_->Detached(); | |
| 587 service_worker_handler_->Detached(); | 610 service_worker_handler_->Detached(); |
| 588 target_handler_->Detached(); | 611 target_handler_->Detached(); |
| 589 frame_trace_recorder_.reset(); | 612 frame_trace_recorder_.reset(); |
| 590 in_navigation_protocol_message_buffer_.clear(); | 613 in_navigation_protocol_message_buffer_.clear(); |
| 591 } | 614 } |
| 592 | 615 |
| 593 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { | 616 RenderFrameDevToolsAgentHost::~RenderFrameDevToolsAgentHost() { |
| 594 Instances::iterator it = std::find(g_instances.Get().begin(), | 617 Instances::iterator it = std::find(g_instances.Get().begin(), |
| 595 g_instances.Get().end(), | 618 g_instances.Get().end(), |
| 596 this); | 619 this); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 813 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 791 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 814 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 792 #if defined(OS_CHROMEOS) | 815 #if defined(OS_CHROMEOS) |
| 793 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: | 816 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
| 794 #endif | 817 #endif |
| 795 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 818 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 796 #if defined(OS_ANDROID) | 819 #if defined(OS_ANDROID) |
| 797 case base::TERMINATION_STATUS_OOM_PROTECTED: | 820 case base::TERMINATION_STATUS_OOM_PROTECTED: |
| 798 #endif | 821 #endif |
| 799 case base::TERMINATION_STATUS_LAUNCH_FAILED: | 822 case base::TERMINATION_STATUS_LAUNCH_FAILED: |
| 800 inspector_handler_->TargetCrashed(); | 823 if (inspector_handler_) |
| 824 inspector_handler_->TargetCrashed(); |
| 801 current_frame_crashed_ = true; | 825 current_frame_crashed_ = true; |
| 802 break; | 826 break; |
| 803 default: | 827 default: |
| 804 inspector_handler_->TargetDetached("Render process gone."); | 828 if (inspector_handler_) |
| 829 inspector_handler_->TargetDetached("Render process gone."); |
| 805 break; | 830 break; |
| 806 } | 831 } |
| 807 DCHECK(CheckConsistency()); | 832 DCHECK(CheckConsistency()); |
| 808 } | 833 } |
| 809 | 834 |
| 810 bool RenderFrameDevToolsAgentHost::OnMessageReceived( | 835 bool RenderFrameDevToolsAgentHost::OnMessageReceived( |
| 811 const IPC::Message& message) { | 836 const IPC::Message& message) { |
| 812 if (!current_) | 837 if (!current_) |
| 813 return false; | 838 return false; |
| 814 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) | 839 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 | 937 |
| 913 void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers( | 938 void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers( |
| 914 RenderFrameHostImpl* host) { | 939 RenderFrameHostImpl* host) { |
| 915 #if DCHECK_IS_ON() | 940 #if DCHECK_IS_ON() |
| 916 // Check that we don't have stale host object here by accessing some random | 941 // Check that we don't have stale host object here by accessing some random |
| 917 // properties inside. | 942 // properties inside. |
| 918 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) | 943 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) |
| 919 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); | 944 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); |
| 920 #endif | 945 #endif |
| 921 handlers_frame_host_ = host; | 946 handlers_frame_host_ = host; |
| 922 dom_handler_->SetRenderFrameHost(host); | 947 if (dom_handler_) |
| 948 dom_handler_->SetRenderFrameHost(host); |
| 923 if (emulation_handler_) | 949 if (emulation_handler_) |
| 924 emulation_handler_->SetRenderFrameHost(host); | 950 emulation_handler_->SetRenderFrameHost(host); |
| 925 input_handler_->SetRenderWidgetHost( | 951 input_handler_->SetRenderWidgetHost( |
| 926 host ? host->GetRenderWidgetHost() : nullptr); | 952 host ? host->GetRenderWidgetHost() : nullptr); |
| 927 inspector_handler_->SetRenderFrameHost(host); | 953 if (inspector_handler_) |
| 928 network_handler_->SetRenderFrameHost(host); | 954 inspector_handler_->SetRenderFrameHost(host); |
| 955 if (network_handler_) |
| 956 network_handler_->SetRenderFrameHost(host); |
| 929 if (page_handler_) | 957 if (page_handler_) |
| 930 page_handler_->SetRenderFrameHost(host); | 958 page_handler_->SetRenderFrameHost(host); |
| 931 service_worker_handler_->SetRenderFrameHost(host); | 959 service_worker_handler_->SetRenderFrameHost(host); |
| 932 if (security_handler_) | 960 if (security_handler_) |
| 933 security_handler_->SetRenderFrameHost(host); | 961 security_handler_->SetRenderFrameHost(host); |
| 934 if (storage_handler_) | 962 if (storage_handler_) |
| 935 storage_handler_->SetRenderFrameHost(host); | 963 storage_handler_->SetRenderFrameHost(host); |
| 936 target_handler_->SetRenderFrameHost(host); | 964 target_handler_->SetRenderFrameHost(host); |
| 937 } | 965 } |
| 938 | 966 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 if (content::WebContents* contents = web_contents()) | 1092 if (content::WebContents* contents = web_contents()) |
| 1065 return contents->GetLastActiveTime(); | 1093 return contents->GetLastActiveTime(); |
| 1066 return base::TimeTicks(); | 1094 return base::TimeTicks(); |
| 1067 } | 1095 } |
| 1068 | 1096 |
| 1069 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( | 1097 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( |
| 1070 const IPC::Message& message) { | 1098 const IPC::Message& message) { |
| 1071 ViewHostMsg_SwapCompositorFrame::Param param; | 1099 ViewHostMsg_SwapCompositorFrame::Param param; |
| 1072 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 1100 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
| 1073 return; | 1101 return; |
| 1074 if (page_handler_) | 1102 if (page_handler_) { |
| 1075 page_handler_->OnSwapCompositorFrame( | 1103 page_handler_->OnSwapCompositorFrame( |
| 1076 std::move(std::get<1>(param).metadata)); | 1104 std::move(std::get<1>(param).metadata)); |
| 1105 } |
| 1077 if (input_handler_) | 1106 if (input_handler_) |
| 1078 input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata); | 1107 input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata); |
| 1079 if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) { | 1108 if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) { |
| 1080 frame_trace_recorder_->OnSwapCompositorFrame( | 1109 frame_trace_recorder_->OnSwapCompositorFrame( |
| 1081 current_ ? current_->host() : nullptr, std::get<1>(param).metadata); | 1110 current_ ? current_->host() : nullptr, std::get<1>(param).metadata); |
| 1082 } | 1111 } |
| 1083 } | 1112 } |
| 1084 | 1113 |
| 1085 void RenderFrameDevToolsAgentHost::SignalSynchronousSwapCompositorFrame( | 1114 void RenderFrameDevToolsAgentHost::SignalSynchronousSwapCompositorFrame( |
| 1086 RenderFrameHost* frame_host, | 1115 RenderFrameHost* frame_host, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 RenderFrameHost* host) { | 1175 RenderFrameHost* host) { |
| 1147 return (current_ && current_->host() == host) || | 1176 return (current_ && current_->host() == host) || |
| 1148 (pending_ && pending_->host() == host); | 1177 (pending_ && pending_->host() == host); |
| 1149 } | 1178 } |
| 1150 | 1179 |
| 1151 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1180 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1152 return current_ && current_->host()->GetParent(); | 1181 return current_ && current_->host()->GetParent(); |
| 1153 } | 1182 } |
| 1154 | 1183 |
| 1155 } // namespace content | 1184 } // namespace content |
| OLD | NEW |