| 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/json/json_reader.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "content/browser/bad_message.h" | 16 #include "content/browser/bad_message.h" |
| 16 #include "content/browser/child_process_security_policy_impl.h" | 17 #include "content/browser/child_process_security_policy_impl.h" |
| 17 #include "content/browser/devtools/devtools_frame_trace_recorder.h" | 18 #include "content/browser/devtools/devtools_frame_trace_recorder.h" |
| 18 #include "content/browser/devtools/devtools_manager.h" | 19 #include "content/browser/devtools/devtools_manager.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" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 NavigationHandle* navigation_handle) { | 373 NavigationHandle* navigation_handle) { |
| 373 FrameTreeNode* frame_tree_node = | 374 FrameTreeNode* frame_tree_node = |
| 374 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); | 375 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); |
| 375 while (frame_tree_node && frame_tree_node->parent()) { | 376 while (frame_tree_node && frame_tree_node->parent()) { |
| 376 frame_tree_node = frame_tree_node->parent(); | 377 frame_tree_node = frame_tree_node->parent(); |
| 377 } | 378 } |
| 378 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 379 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
| 379 // Note Page.setControlNavigations is intended to control navigations in the | 380 // Note Page.setControlNavigations is intended to control navigations in the |
| 380 // main frame and all child frames and |page_handler_| only exists for the | 381 // main frame and all child frames and |page_handler_| only exists for the |
| 381 // main frame. | 382 // main frame. |
| 382 if (agent_host && agent_host->page_handler_) { | 383 if (!agent_host || !agent_host->session()) |
| 383 return agent_host->page_handler_->CreateThrottleForNavigation( | 384 return nullptr; |
| 384 navigation_handle); | 385 protocol::PageHandler* page_handler = agent_host->session()->GetPageHandler(); |
| 385 } | 386 if (!page_handler) |
| 386 return nullptr; | 387 return nullptr; |
| 388 return page_handler->CreateThrottleForNavigation(navigation_handle); |
| 387 } | 389 } |
| 388 | 390 |
| 389 // static | 391 // static |
| 390 bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled( | 392 bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled( |
| 391 FrameTreeNode* frame_tree_node) { | 393 FrameTreeNode* frame_tree_node) { |
| 392 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 394 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
| 393 return agent_host && agent_host->network_handler_ && | 395 if (!agent_host || !agent_host->session()) |
| 394 agent_host->network_handler_->enabled(); | 396 return false; |
| 397 protocol::NetworkHandler* network_handler = |
| 398 agent_host->session()->GetNetworkHandler(); |
| 399 return network_handler && network_handler->enabled(); |
| 395 } | 400 } |
| 396 | 401 |
| 397 // static | 402 // static |
| 398 std::string RenderFrameDevToolsAgentHost::UserAgentOverride( | 403 std::string RenderFrameDevToolsAgentHost::UserAgentOverride( |
| 399 FrameTreeNode* frame_tree_node) { | 404 FrameTreeNode* frame_tree_node) { |
| 400 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 405 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
| 401 if (agent_host && agent_host->network_handler_) | 406 if (!agent_host || !agent_host->session()) |
| 402 return agent_host->network_handler_->UserAgentOverride(); | 407 return std::string(); |
| 403 return std::string(); | 408 protocol::NetworkHandler* network_handler = |
| 409 agent_host->session()->GetNetworkHandler(); |
| 410 if (!network_handler) |
| 411 return std::string(); |
| 412 return network_handler->UserAgentOverride(); |
| 404 } | 413 } |
| 405 | 414 |
| 406 // static | 415 // static |
| 407 void RenderFrameDevToolsAgentHost::WebContentsCreated( | 416 void RenderFrameDevToolsAgentHost::WebContentsCreated( |
| 408 WebContents* web_contents) { | 417 WebContents* web_contents) { |
| 409 if (ShouldForceCreation()) { | 418 if (ShouldForceCreation()) { |
| 410 // Force agent host. | 419 // Force agent host. |
| 411 DevToolsAgentHost::GetOrCreateFor(web_contents); | 420 DevToolsAgentHost::GetOrCreateFor(web_contents); |
| 412 } | 421 } |
| 413 } | 422 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 | 483 |
| 475 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { | 484 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { |
| 476 WebContents* contents = web_contents(); | 485 WebContents* contents = web_contents(); |
| 477 return contents ? contents->GetBrowserContext() : nullptr; | 486 return contents ? contents->GetBrowserContext() : nullptr; |
| 478 } | 487 } |
| 479 | 488 |
| 480 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { | 489 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { |
| 481 return web_contents(); | 490 return web_contents(); |
| 482 } | 491 } |
| 483 | 492 |
| 484 void RenderFrameDevToolsAgentHost::Attach() { | 493 void RenderFrameDevToolsAgentHost::Attach(DevToolsSession* session) { |
| 485 session()->dispatcher()->setFallThroughForNotFound(true); | 494 session->SetFallThroughForNotFound(true); |
| 486 | 495 session->SetRenderFrameHost(handlers_frame_host_); |
| 487 if (!frame_tree_node_->parent()) { | 496 if (!frame_tree_node_->parent()) { |
| 488 emulation_handler_.reset(new protocol::EmulationHandler()); | 497 session->AddHandler(base::WrapUnique(new protocol::EmulationHandler())); |
| 489 emulation_handler_->Wire(session()->dispatcher()); | 498 session->AddHandler(base::WrapUnique(new protocol::PageHandler())); |
| 490 emulation_handler_->SetRenderFrameHost(handlers_frame_host_); | 499 session->AddHandler(base::WrapUnique(new protocol::SecurityHandler())); |
| 491 } | 500 } |
| 492 | 501 session->AddHandler(base::WrapUnique(new protocol::DOMHandler())); |
| 493 dom_handler_.reset(new protocol::DOMHandler()); | 502 session->AddHandler(base::WrapUnique(new protocol::InputHandler())); |
| 494 dom_handler_->Wire(session()->dispatcher()); | 503 session->AddHandler(base::WrapUnique(new protocol::InspectorHandler())); |
| 495 dom_handler_->SetRenderFrameHost(handlers_frame_host_); | 504 session->AddHandler(base::WrapUnique(new protocol::IOHandler( |
| 496 | 505 GetIOContext()))); |
| 497 input_handler_.reset(new protocol::InputHandler()); | 506 session->AddHandler(base::WrapUnique(new protocol::NetworkHandler())); |
| 498 input_handler_->Wire(session()->dispatcher()); | 507 session->AddHandler(base::WrapUnique(new protocol::SchemaHandler())); |
| 499 input_handler_->SetRenderFrameHost(handlers_frame_host_); | 508 session->AddHandler(base::WrapUnique(new protocol::ServiceWorkerHandler())); |
| 500 | 509 session->AddHandler(base::WrapUnique(new protocol::StorageHandler())); |
| 501 inspector_handler_.reset(new protocol::InspectorHandler()); | 510 session->AddHandler(base::WrapUnique(new protocol::TargetHandler())); |
| 502 inspector_handler_->Wire(session()->dispatcher()); | 511 session->AddHandler(base::WrapUnique(new protocol::TracingHandler( |
| 503 inspector_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 504 | |
| 505 io_handler_.reset(new protocol::IOHandler(GetIOContext())); | |
| 506 io_handler_->Wire(session()->dispatcher()); | |
| 507 | |
| 508 network_handler_.reset(new protocol::NetworkHandler()); | |
| 509 network_handler_->Wire(session()->dispatcher()); | |
| 510 network_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 511 | |
| 512 if (!frame_tree_node_->parent()) { | |
| 513 page_handler_.reset(new protocol::PageHandler()); | |
| 514 page_handler_->Wire(session()->dispatcher()); | |
| 515 page_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 516 } | |
| 517 | |
| 518 schema_handler_.reset(new protocol::SchemaHandler()); | |
| 519 schema_handler_->Wire(session()->dispatcher()); | |
| 520 | |
| 521 if (!frame_tree_node_->parent()) { | |
| 522 security_handler_.reset(new protocol::SecurityHandler()); | |
| 523 security_handler_->Wire(session()->dispatcher()); | |
| 524 security_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 525 } | |
| 526 | |
| 527 service_worker_handler_.reset(new protocol::ServiceWorkerHandler()); | |
| 528 service_worker_handler_->Wire(session()->dispatcher()); | |
| 529 service_worker_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 530 | |
| 531 storage_handler_.reset(new protocol::StorageHandler()); | |
| 532 storage_handler_->Wire(session()->dispatcher()); | |
| 533 storage_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 534 | |
| 535 target_handler_.reset(new protocol::TargetHandler()); | |
| 536 target_handler_->Wire(session()->dispatcher()); | |
| 537 target_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 538 | |
| 539 tracing_handler_.reset(new protocol::TracingHandler( | |
| 540 protocol::TracingHandler::Renderer, | 512 protocol::TracingHandler::Renderer, |
| 541 frame_tree_node_->frame_tree_node_id(), | 513 frame_tree_node_->frame_tree_node_id(), |
| 542 GetIOContext())); | 514 GetIOContext()))); |
| 543 tracing_handler_->Wire(session()->dispatcher()); | |
| 544 | 515 |
| 545 if (current_) | 516 if (current_) |
| 546 current_->Attach(); | 517 current_->Attach(); |
| 547 if (pending_) | 518 if (pending_) |
| 548 pending_->Attach(); | 519 pending_->Attach(); |
| 549 OnClientAttached(); | 520 OnClientAttached(); |
| 550 } | 521 } |
| 551 | 522 |
| 552 void RenderFrameDevToolsAgentHost::Detach() { | 523 void RenderFrameDevToolsAgentHost::Detach(DevToolsSession* session) { |
| 553 dom_handler_->Disable(); | |
| 554 dom_handler_.reset(); | |
| 555 if (emulation_handler_) { | |
| 556 emulation_handler_->Disable(); | |
| 557 emulation_handler_.reset(); | |
| 558 } | |
| 559 input_handler_->Disable(); | |
| 560 input_handler_.reset(); | |
| 561 inspector_handler_->Disable(); | |
| 562 inspector_handler_.reset(); | |
| 563 io_handler_->Disable(); | |
| 564 io_handler_.reset(); | |
| 565 network_handler_->Disable(); | |
| 566 network_handler_.reset(); | |
| 567 if (page_handler_) { | |
| 568 page_handler_->Disable(); | |
| 569 page_handler_.reset(); | |
| 570 } | |
| 571 schema_handler_->Disable(); | |
| 572 schema_handler_.reset(); | |
| 573 if (security_handler_) { | |
| 574 security_handler_->Disable(); | |
| 575 security_handler_.reset(); | |
| 576 } | |
| 577 service_worker_handler_->Disable(); | |
| 578 service_worker_handler_.reset(); | |
| 579 storage_handler_->Disable(); | |
| 580 storage_handler_.reset(); | |
| 581 target_handler_->Disable(); | |
| 582 target_handler_.reset(); | |
| 583 tracing_handler_->Disable(); | |
| 584 tracing_handler_.reset(); | |
| 585 | |
| 586 if (current_) | 524 if (current_) |
| 587 current_->Detach(); | 525 current_->Detach(); |
| 588 if (pending_) | 526 if (pending_) |
| 589 pending_->Detach(); | 527 pending_->Detach(); |
| 590 OnClientDetached(); | 528 OnClientDetached(); |
| 591 } | 529 } |
| 592 | 530 |
| 593 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 531 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( |
| 532 DevToolsSession* session, |
| 594 const std::string& message) { | 533 const std::string& message) { |
| 595 int call_id = 0; | 534 int call_id = 0; |
| 596 std::string method; | 535 std::string method; |
| 597 if (session()->Dispatch(message, &call_id, &method) != | 536 if (session->Dispatch(message, true, &call_id, &method) != |
| 598 protocol::Response::kFallThrough) { | 537 protocol::Response::kFallThrough) { |
| 599 return true; | 538 return true; |
| 600 } | 539 } |
| 601 | 540 |
| 602 if (!navigating_handles_.empty()) { | 541 if (!navigating_handles_.empty()) { |
| 603 DCHECK(IsBrowserSideNavigationEnabled()); | 542 DCHECK(IsBrowserSideNavigationEnabled()); |
| 604 in_navigation_protocol_message_buffer_[call_id] = | 543 in_navigation_protocol_message_buffer_[call_id] = |
| 605 { session()->session_id(), method, message }; | 544 { session->session_id(), method, message }; |
| 606 return true; | 545 return true; |
| 607 } | 546 } |
| 608 | 547 |
| 609 if (current_) { | 548 if (current_) { |
| 610 current_->DispatchProtocolMessage( | 549 current_->DispatchProtocolMessage( |
| 611 session()->session_id(), call_id, method, message); | 550 session->session_id(), call_id, method, message); |
| 612 } | 551 } |
| 613 if (pending_) { | 552 if (pending_) { |
| 614 pending_->DispatchProtocolMessage( | 553 pending_->DispatchProtocolMessage( |
| 615 session()->session_id(), call_id, method, message); | 554 session->session_id(), call_id, method, message); |
| 616 } | 555 } |
| 617 return true; | 556 return true; |
| 618 } | 557 } |
| 619 | 558 |
| 620 void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) { | 559 void RenderFrameDevToolsAgentHost::InspectElement( |
| 560 DevToolsSession* session, |
| 561 int x, |
| 562 int y) { |
| 621 if (current_) | 563 if (current_) |
| 622 current_->InspectElement(session()->session_id(), x, y); | 564 current_->InspectElement(session->session_id(), x, y); |
| 623 if (pending_) | 565 if (pending_) |
| 624 pending_->InspectElement(session()->session_id(), x, y); | 566 pending_->InspectElement(session->session_id(), x, y); |
| 625 } | 567 } |
| 626 | 568 |
| 627 void RenderFrameDevToolsAgentHost::OnClientAttached() { | 569 void RenderFrameDevToolsAgentHost::OnClientAttached() { |
| 628 if (!web_contents()) | 570 if (!web_contents()) |
| 629 return; | 571 return; |
| 630 | 572 |
| 631 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); | 573 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); |
| 632 CreatePowerSaveBlocker(); | 574 CreatePowerSaveBlocker(); |
| 633 } | 575 } |
| 634 | 576 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 } else { | 646 } else { |
| 705 DiscardPending(); | 647 DiscardPending(); |
| 706 } | 648 } |
| 707 pending_handle_ = nullptr; | 649 pending_handle_ = nullptr; |
| 708 } else if (navigating_handles_.empty()) { | 650 } else if (navigating_handles_.empty()) { |
| 709 current_->Resume(); | 651 current_->Resume(); |
| 710 } | 652 } |
| 711 DispatchBufferedProtocolMessagesIfNecessary(); | 653 DispatchBufferedProtocolMessagesIfNecessary(); |
| 712 | 654 |
| 713 DCHECK(CheckConsistency()); | 655 DCHECK(CheckConsistency()); |
| 714 if (target_handler_ && navigation_handle->HasCommitted()) | 656 protocol::TargetHandler* target_handler = |
| 715 target_handler_->UpdateServiceWorkers(); | 657 session() ? session()->GetTargetHandler() : nullptr; |
| 658 if (target_handler && navigation_handle->HasCommitted()) |
| 659 target_handler->UpdateServiceWorkers(); |
| 716 } | 660 } |
| 717 | 661 |
| 718 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( | 662 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( |
| 719 RenderFrameHost* old_host, | 663 RenderFrameHost* old_host, |
| 720 RenderFrameHost* new_host) { | 664 RenderFrameHost* new_host) { |
| 721 // CommitPending may destruct |this|. | 665 // CommitPending may destruct |this|. |
| 722 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 666 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 723 | 667 |
| 724 if (IsBrowserSideNavigationEnabled()) | 668 if (IsBrowserSideNavigationEnabled()) |
| 725 return; | 669 return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 751 current_->Suspend(); | 695 current_->Suspend(); |
| 752 DCHECK(CheckConsistency()); | 696 DCHECK(CheckConsistency()); |
| 753 } | 697 } |
| 754 | 698 |
| 755 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 699 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( |
| 756 RenderFrameHost* old_host, | 700 RenderFrameHost* old_host, |
| 757 RenderFrameHost* new_host) { | 701 RenderFrameHost* new_host) { |
| 758 // CommitPending may destruct |this|. | 702 // CommitPending may destruct |this|. |
| 759 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 703 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 760 | 704 |
| 761 if (target_handler_) | 705 protocol::TargetHandler* target_handler = |
| 762 target_handler_->UpdateFrames(); | 706 session() ? session()->GetTargetHandler() : nullptr; |
| 707 if (target_handler) |
| 708 target_handler->UpdateFrames(); |
| 763 | 709 |
| 764 if (IsBrowserSideNavigationEnabled()) | 710 if (IsBrowserSideNavigationEnabled()) |
| 765 return; | 711 return; |
| 766 | 712 |
| 767 DCHECK(!pending_ || pending_->host() != old_host); | 713 DCHECK(!pending_ || pending_->host() != old_host); |
| 768 if (!current_ || current_->host() != old_host) { | 714 if (!current_ || current_->host() != old_host) { |
| 769 DCHECK(CheckConsistency()); | 715 DCHECK(CheckConsistency()); |
| 770 return; | 716 return; |
| 771 } | 717 } |
| 772 | 718 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 779 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 834 if (web_contents()->GetNativeView()) { | 780 if (web_contents()->GetNativeView()) { |
| 835 power_save_blocker_->InitDisplaySleepBlocker( | 781 power_save_blocker_->InitDisplaySleepBlocker( |
| 836 web_contents()->GetNativeView()); | 782 web_contents()->GetNativeView()); |
| 837 } | 783 } |
| 838 #endif | 784 #endif |
| 839 } | 785 } |
| 840 | 786 |
| 841 void RenderFrameDevToolsAgentHost::RenderProcessGone( | 787 void RenderFrameDevToolsAgentHost::RenderProcessGone( |
| 842 base::TerminationStatus status) { | 788 base::TerminationStatus status) { |
| 789 protocol::InspectorHandler* inspector_handler = |
| 790 session() ? session()->GetInspectorHandler() : nullptr; |
| 843 switch(status) { | 791 switch(status) { |
| 844 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 792 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 845 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 793 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 846 #if defined(OS_CHROMEOS) | 794 #if defined(OS_CHROMEOS) |
| 847 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: | 795 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
| 848 #endif | 796 #endif |
| 849 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 797 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 850 #if defined(OS_ANDROID) | 798 #if defined(OS_ANDROID) |
| 851 case base::TERMINATION_STATUS_OOM_PROTECTED: | 799 case base::TERMINATION_STATUS_OOM_PROTECTED: |
| 852 #endif | 800 #endif |
| 853 case base::TERMINATION_STATUS_LAUNCH_FAILED: | 801 case base::TERMINATION_STATUS_LAUNCH_FAILED: |
| 854 if (inspector_handler_) | 802 if (inspector_handler) |
| 855 inspector_handler_->TargetCrashed(); | 803 inspector_handler->TargetCrashed(); |
| 856 current_frame_crashed_ = true; | 804 current_frame_crashed_ = true; |
| 857 break; | 805 break; |
| 858 default: | 806 default: |
| 859 if (inspector_handler_) | 807 if (inspector_handler) |
| 860 inspector_handler_->TargetDetached("Render process gone."); | 808 inspector_handler->TargetDetached("Render process gone."); |
| 861 break; | 809 break; |
| 862 } | 810 } |
| 863 DCHECK(CheckConsistency()); | 811 DCHECK(CheckConsistency()); |
| 864 } | 812 } |
| 865 | 813 |
| 866 bool RenderFrameDevToolsAgentHost::OnMessageReceived( | 814 bool RenderFrameDevToolsAgentHost::OnMessageReceived( |
| 867 const IPC::Message& message) { | 815 const IPC::Message& message) { |
| 868 if (!current_) | 816 if (!current_) |
| 869 return false; | 817 return false; |
| 870 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) | 818 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 887 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 835 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| 888 OnDispatchOnInspectorFrontend) | 836 OnDispatchOnInspectorFrontend) |
| 889 IPC_MESSAGE_HANDLER(DevToolsAgentHostMsg_RequestNewWindow, | 837 IPC_MESSAGE_HANDLER(DevToolsAgentHostMsg_RequestNewWindow, |
| 890 OnRequestNewWindow) | 838 OnRequestNewWindow) |
| 891 IPC_MESSAGE_UNHANDLED(handled = false) | 839 IPC_MESSAGE_UNHANDLED(handled = false) |
| 892 IPC_END_MESSAGE_MAP() | 840 IPC_END_MESSAGE_MAP() |
| 893 return handled; | 841 return handled; |
| 894 } | 842 } |
| 895 | 843 |
| 896 void RenderFrameDevToolsAgentHost::DidAttachInterstitialPage() { | 844 void RenderFrameDevToolsAgentHost::DidAttachInterstitialPage() { |
| 897 if (page_handler_) | 845 protocol::PageHandler* page_handler = |
| 898 page_handler_->DidAttachInterstitialPage(); | 846 session() ? session()->GetPageHandler() : nullptr; |
| 847 if (page_handler) |
| 848 page_handler->DidAttachInterstitialPage(); |
| 899 | 849 |
| 900 // TODO(dgozman): this may break for cross-process subframes. | 850 // TODO(dgozman): this may break for cross-process subframes. |
| 901 if (!pending_) { | 851 if (!pending_) { |
| 902 DCHECK(CheckConsistency()); | 852 DCHECK(CheckConsistency()); |
| 903 return; | 853 return; |
| 904 } | 854 } |
| 905 // Pending set in AboutToNavigateRenderFrame turned out to be interstitial. | 855 // Pending set in AboutToNavigateRenderFrame turned out to be interstitial. |
| 906 // Connect back to the real one. | 856 // Connect back to the real one. |
| 907 DiscardPending(); | 857 DiscardPending(); |
| 908 pending_handle_ = nullptr; | 858 pending_handle_ = nullptr; |
| 909 DCHECK(CheckConsistency()); | 859 DCHECK(CheckConsistency()); |
| 910 } | 860 } |
| 911 | 861 |
| 912 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { | 862 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { |
| 913 if (page_handler_) | 863 protocol::PageHandler* page_handler = |
| 914 page_handler_->DidDetachInterstitialPage(); | 864 session() ? session()->GetPageHandler() : nullptr; |
| 865 if (page_handler) |
| 866 page_handler->DidDetachInterstitialPage(); |
| 915 } | 867 } |
| 916 | 868 |
| 917 void RenderFrameDevToolsAgentHost::DidCommitProvisionalLoadForFrame( | 869 void RenderFrameDevToolsAgentHost::DidCommitProvisionalLoadForFrame( |
| 918 RenderFrameHost* render_frame_host, | 870 RenderFrameHost* render_frame_host, |
| 919 const GURL& url, | 871 const GURL& url, |
| 920 ui::PageTransition transition_type) { | 872 ui::PageTransition transition_type) { |
| 921 // CommitPending may destruct |this|. | 873 // CommitPending may destruct |this|. |
| 922 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 874 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 923 | 875 |
| 924 if (IsBrowserSideNavigationEnabled()) | 876 if (IsBrowserSideNavigationEnabled()) |
| 925 return; | 877 return; |
| 926 if (pending_ && pending_->host() == render_frame_host) | 878 if (pending_ && pending_->host() == render_frame_host) |
| 927 CommitPending(); | 879 CommitPending(); |
| 928 DCHECK(CheckConsistency()); | 880 DCHECK(CheckConsistency()); |
| 929 if (target_handler_) | 881 protocol::TargetHandler* target_handler = |
| 930 target_handler_->UpdateServiceWorkers(); | 882 session() ? session()->GetTargetHandler() : nullptr; |
| 883 if (target_handler) |
| 884 target_handler->UpdateServiceWorkers(); |
| 931 } | 885 } |
| 932 | 886 |
| 933 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( | 887 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( |
| 934 RenderFrameHost* render_frame_host, | 888 RenderFrameHost* render_frame_host, |
| 935 const GURL& validated_url, | 889 const GURL& validated_url, |
| 936 int error_code, | 890 int error_code, |
| 937 const base::string16& error_description, | 891 const base::string16& error_description, |
| 938 bool was_ignored_by_handler) { | 892 bool was_ignored_by_handler) { |
| 939 if (IsBrowserSideNavigationEnabled()) | 893 if (IsBrowserSideNavigationEnabled()) |
| 940 return; | 894 return; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 969 | 923 |
| 970 void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers( | 924 void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers( |
| 971 RenderFrameHostImpl* host) { | 925 RenderFrameHostImpl* host) { |
| 972 #if DCHECK_IS_ON() | 926 #if DCHECK_IS_ON() |
| 973 // Check that we don't have stale host object here by accessing some random | 927 // Check that we don't have stale host object here by accessing some random |
| 974 // properties inside. | 928 // properties inside. |
| 975 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) | 929 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) |
| 976 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); | 930 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); |
| 977 #endif | 931 #endif |
| 978 handlers_frame_host_ = host; | 932 handlers_frame_host_ = host; |
| 979 if (dom_handler_) | 933 if (session()) |
| 980 dom_handler_->SetRenderFrameHost(host); | 934 session()->SetRenderFrameHost(host); |
| 981 if (emulation_handler_) | |
| 982 emulation_handler_->SetRenderFrameHost(host); | |
| 983 if (input_handler_) | |
| 984 input_handler_->SetRenderFrameHost(host); | |
| 985 if (inspector_handler_) | |
| 986 inspector_handler_->SetRenderFrameHost(host); | |
| 987 if (network_handler_) | |
| 988 network_handler_->SetRenderFrameHost(host); | |
| 989 if (page_handler_) | |
| 990 page_handler_->SetRenderFrameHost(host); | |
| 991 if (service_worker_handler_) | |
| 992 service_worker_handler_->SetRenderFrameHost(host); | |
| 993 if (security_handler_) | |
| 994 security_handler_->SetRenderFrameHost(host); | |
| 995 if (storage_handler_) | |
| 996 storage_handler_->SetRenderFrameHost(host); | |
| 997 if (target_handler_) | |
| 998 target_handler_->SetRenderFrameHost(host); | |
| 999 } | 935 } |
| 1000 | 936 |
| 1001 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 937 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { |
| 1002 if (pending_) | 938 if (pending_) |
| 1003 DiscardPending(); | 939 DiscardPending(); |
| 1004 UpdateProtocolHandlers(nullptr); | 940 UpdateProtocolHandlers(nullptr); |
| 1005 disconnected_ = std::move(current_); | 941 disconnected_ = std::move(current_); |
| 1006 disconnected_->Detach(); | 942 disconnected_->Detach(); |
| 1007 frame_tree_node_ = nullptr; | 943 frame_tree_node_ = nullptr; |
| 1008 in_navigation_protocol_message_buffer_.clear(); | 944 in_navigation_protocol_message_buffer_.clear(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 if (content::WebContents* contents = web_contents()) | 1062 if (content::WebContents* contents = web_contents()) |
| 1127 return contents->GetLastActiveTime(); | 1063 return contents->GetLastActiveTime(); |
| 1128 return base::TimeTicks(); | 1064 return base::TimeTicks(); |
| 1129 } | 1065 } |
| 1130 | 1066 |
| 1131 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( | 1067 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( |
| 1132 const IPC::Message& message) { | 1068 const IPC::Message& message) { |
| 1133 ViewHostMsg_SwapCompositorFrame::Param param; | 1069 ViewHostMsg_SwapCompositorFrame::Param param; |
| 1134 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 1070 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
| 1135 return; | 1071 return; |
| 1136 if (page_handler_) { | 1072 protocol::PageHandler* page_handler = |
| 1137 page_handler_->OnSwapCompositorFrame( | 1073 session() ? session()->GetPageHandler() : nullptr; |
| 1074 if (page_handler) { |
| 1075 page_handler->OnSwapCompositorFrame( |
| 1138 std::move(std::get<1>(param).metadata)); | 1076 std::move(std::get<1>(param).metadata)); |
| 1139 } | 1077 } |
| 1140 if (input_handler_) | 1078 protocol::InputHandler* input_handler = |
| 1141 input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata); | 1079 session() ? session()->GetInputHandler() : nullptr; |
| 1142 if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) { | 1080 if (input_handler) |
| 1081 input_handler->OnSwapCompositorFrame(std::get<1>(param).metadata); |
| 1082 protocol::TracingHandler* tracing_handler = |
| 1083 session() ? session()->GetTracingHandler() : nullptr; |
| 1084 if (frame_trace_recorder_ && tracing_handler && |
| 1085 tracing_handler->did_initiate_recording()) { |
| 1143 frame_trace_recorder_->OnSwapCompositorFrame( | 1086 frame_trace_recorder_->OnSwapCompositorFrame( |
| 1144 current_ ? current_->host() : nullptr, std::get<1>(param).metadata); | 1087 current_ ? current_->host() : nullptr, std::get<1>(param).metadata); |
| 1145 } | 1088 } |
| 1146 } | 1089 } |
| 1147 | 1090 |
| 1148 void RenderFrameDevToolsAgentHost::SignalSynchronousSwapCompositorFrame( | 1091 void RenderFrameDevToolsAgentHost::SignalSynchronousSwapCompositorFrame( |
| 1149 RenderFrameHost* frame_host, | 1092 RenderFrameHost* frame_host, |
| 1150 cc::CompositorFrameMetadata frame_metadata) { | 1093 cc::CompositorFrameMetadata frame_metadata) { |
| 1151 scoped_refptr<RenderFrameDevToolsAgentHost> dtah(FindAgentHost(frame_host)); | 1094 scoped_refptr<RenderFrameDevToolsAgentHost> dtah(FindAgentHost(frame_host)); |
| 1152 if (dtah) { | 1095 if (dtah) { |
| 1153 // Unblock the compositor. | 1096 // Unblock the compositor. |
| 1154 BrowserThread::PostTask( | 1097 BrowserThread::PostTask( |
| 1155 BrowserThread::UI, FROM_HERE, | 1098 BrowserThread::UI, FROM_HERE, |
| 1156 base::Bind( | 1099 base::Bind( |
| 1157 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, | 1100 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, |
| 1158 dtah.get(), | 1101 dtah.get(), |
| 1159 base::Passed(std::move(frame_metadata)))); | 1102 base::Passed(std::move(frame_metadata)))); |
| 1160 } | 1103 } |
| 1161 } | 1104 } |
| 1162 | 1105 |
| 1163 void RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame( | 1106 void RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame( |
| 1164 cc::CompositorFrameMetadata frame_metadata) { | 1107 cc::CompositorFrameMetadata frame_metadata) { |
| 1165 if (page_handler_) | 1108 protocol::PageHandler* page_handler = |
| 1166 page_handler_->OnSynchronousSwapCompositorFrame(std::move(frame_metadata)); | 1109 session() ? session()->GetPageHandler() : nullptr; |
| 1167 if (input_handler_) | 1110 if (page_handler) |
| 1168 input_handler_->OnSwapCompositorFrame(frame_metadata); | 1111 page_handler->OnSynchronousSwapCompositorFrame(std::move(frame_metadata)); |
| 1169 if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) { | 1112 protocol::InputHandler* input_handler = |
| 1113 session() ? session()->GetInputHandler() : nullptr; |
| 1114 if (input_handler) |
| 1115 input_handler->OnSwapCompositorFrame(frame_metadata); |
| 1116 protocol::TracingHandler* tracing_handler = |
| 1117 session() ? session()->GetTracingHandler() : nullptr; |
| 1118 if (frame_trace_recorder_ && tracing_handler && |
| 1119 tracing_handler->did_initiate_recording()) { |
| 1170 frame_trace_recorder_->OnSynchronousSwapCompositorFrame( | 1120 frame_trace_recorder_->OnSynchronousSwapCompositorFrame( |
| 1171 current_ ? current_->host() : nullptr, | 1121 current_ ? current_->host() : nullptr, |
| 1172 frame_metadata); | 1122 frame_metadata); |
| 1173 } | 1123 } |
| 1174 } | 1124 } |
| 1175 | 1125 |
| 1176 void RenderFrameDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 1126 void RenderFrameDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 1177 RenderFrameHost* sender, | 1127 RenderFrameHost* sender, |
| 1178 const DevToolsMessageChunk& message) { | 1128 const DevToolsMessageChunk& message) { |
| 1179 bool success = true; | 1129 bool success = true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1209 RenderFrameHost* host) { | 1159 RenderFrameHost* host) { |
| 1210 return (current_ && current_->host() == host) || | 1160 return (current_ && current_->host() == host) || |
| 1211 (pending_ && pending_->host() == host); | 1161 (pending_ && pending_->host() == host); |
| 1212 } | 1162 } |
| 1213 | 1163 |
| 1214 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1164 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1215 return current_ && current_->host()->GetParent(); | 1165 return current_ && current_->host()->GetParent(); |
| 1216 } | 1166 } |
| 1217 | 1167 |
| 1218 } // namespace content | 1168 } // namespace content |
| OLD | NEW |