| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // RenderFrameDevToolsAgentHost::FrameHostHolder ------------------------------- | 97 // RenderFrameDevToolsAgentHost::FrameHostHolder ------------------------------- |
| 97 | 98 |
| 98 class RenderFrameDevToolsAgentHost::FrameHostHolder { | 99 class RenderFrameDevToolsAgentHost::FrameHostHolder { |
| 99 public: | 100 public: |
| 100 FrameHostHolder( | 101 FrameHostHolder( |
| 101 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host); | 102 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host); |
| 102 ~FrameHostHolder(); | 103 ~FrameHostHolder(); |
| 103 | 104 |
| 104 RenderFrameHostImpl* host() const { return host_; } | 105 RenderFrameHostImpl* host() const { return host_; } |
| 105 | 106 |
| 106 void Attach(); | 107 void Attach(DevToolsSession* session); |
| 107 void Reattach(FrameHostHolder* old); | 108 void Reattach(FrameHostHolder* old); |
| 108 void Detach(); | 109 void Detach(int session_id); |
| 109 void DispatchProtocolMessage(int session_id, | 110 void DispatchProtocolMessage(int session_id, |
| 110 int call_id, | 111 int call_id, |
| 111 const std::string& method, | 112 const std::string& method, |
| 112 const std::string& message); | 113 const std::string& message); |
| 113 void InspectElement(int session_id, int x, int y); | 114 void InspectElement(int session_id, int x, int y); |
| 114 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); | 115 bool ProcessChunkedMessageFromAgent(const DevToolsMessageChunk& chunk); |
| 115 void Suspend(); | 116 void Suspend(); |
| 116 void Resume(); | 117 void Resume(); |
| 117 | 118 |
| 118 private: | 119 private: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 144 base::Unretained(this))) { | 145 base::Unretained(this))) { |
| 145 DCHECK(agent_); | 146 DCHECK(agent_); |
| 146 DCHECK(host_); | 147 DCHECK(host_); |
| 147 } | 148 } |
| 148 | 149 |
| 149 RenderFrameDevToolsAgentHost::FrameHostHolder::~FrameHostHolder() { | 150 RenderFrameDevToolsAgentHost::FrameHostHolder::~FrameHostHolder() { |
| 150 if (attached_) | 151 if (attached_) |
| 151 RevokePolicy(); | 152 RevokePolicy(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 void RenderFrameDevToolsAgentHost::FrameHostHolder::Attach() { | 155 void RenderFrameDevToolsAgentHost::FrameHostHolder::Attach( |
| 156 DevToolsSession* session) { |
| 155 host_->Send(new DevToolsAgentMsg_Attach( | 157 host_->Send(new DevToolsAgentMsg_Attach( |
| 156 host_->GetRoutingID(), agent_->GetId(), agent_->session()->session_id())); | 158 host_->GetRoutingID(), agent_->GetId(), session->session_id())); |
| 157 GrantPolicy(); | 159 GrantPolicy(); |
| 158 attached_ = true; | 160 attached_ = true; |
| 159 } | 161 } |
| 160 | 162 |
| 161 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( | 163 void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach( |
| 162 FrameHostHolder* old) { | 164 FrameHostHolder* old) { |
| 163 if (old) | 165 if (old) |
| 164 chunk_processor_.set_state_cookie(old->chunk_processor_.state_cookie()); | 166 chunk_processor_.set_state_cookie(old->chunk_processor_.state_cookie()); |
| 165 host_->Send(new DevToolsAgentMsg_Reattach( | 167 host_->Send(new DevToolsAgentMsg_Reattach( |
| 166 host_->GetRoutingID(), agent_->GetId(), agent_->session()->session_id(), | 168 host_->GetRoutingID(), agent_->GetId(), agent_->session()->session_id(), |
| 167 chunk_processor_.state_cookie())); | 169 chunk_processor_.state_cookie())); |
| 168 if (old) { | 170 if (old) { |
| 169 if (IsBrowserSideNavigationEnabled()) { | 171 if (IsBrowserSideNavigationEnabled()) { |
| 170 for (const auto& pair : | 172 for (const auto& pair : |
| 171 old->sent_messages_whose_reply_came_while_suspended_) { | 173 old->sent_messages_whose_reply_came_while_suspended_) { |
| 172 DispatchProtocolMessage(pair.second.session_id, pair.first, | 174 DispatchProtocolMessage(pair.second.session_id, pair.first, |
| 173 pair.second.method, pair.second.message); | 175 pair.second.method, pair.second.message); |
| 174 } | 176 } |
| 175 } | 177 } |
| 176 for (const auto& pair : old->sent_messages_) { | 178 for (const auto& pair : old->sent_messages_) { |
| 177 DispatchProtocolMessage(pair.second.session_id, pair.first, | 179 DispatchProtocolMessage(pair.second.session_id, pair.first, |
| 178 pair.second.method, pair.second.message); | 180 pair.second.method, pair.second.message); |
| 179 } | 181 } |
| 180 } | 182 } |
| 181 GrantPolicy(); | 183 GrantPolicy(); |
| 182 attached_ = true; | 184 attached_ = true; |
| 183 } | 185 } |
| 184 | 186 |
| 185 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() { | 187 void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach(int session_id) { |
| 186 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID())); | 188 host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID())); |
| 187 RevokePolicy(); | 189 RevokePolicy(); |
| 188 attached_ = false; | 190 attached_ = false; |
| 189 } | 191 } |
| 190 | 192 |
| 191 void RenderFrameDevToolsAgentHost::FrameHostHolder::GrantPolicy() { | 193 void RenderFrameDevToolsAgentHost::FrameHostHolder::GrantPolicy() { |
| 192 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( | 194 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( |
| 193 host_->GetProcess()->GetID()); | 195 host_->GetProcess()->GetID()); |
| 194 } | 196 } |
| 195 | 197 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 NavigationHandle* navigation_handle) { | 376 NavigationHandle* navigation_handle) { |
| 375 FrameTreeNode* frame_tree_node = | 377 FrameTreeNode* frame_tree_node = |
| 376 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); | 378 static_cast<NavigationHandleImpl*>(navigation_handle)->frame_tree_node(); |
| 377 while (frame_tree_node && frame_tree_node->parent()) { | 379 while (frame_tree_node && frame_tree_node->parent()) { |
| 378 frame_tree_node = frame_tree_node->parent(); | 380 frame_tree_node = frame_tree_node->parent(); |
| 379 } | 381 } |
| 380 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 382 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
| 381 // Note Page.setControlNavigations is intended to control navigations in the | 383 // Note Page.setControlNavigations is intended to control navigations in the |
| 382 // main frame and all child frames and |page_handler_| only exists for the | 384 // main frame and all child frames and |page_handler_| only exists for the |
| 383 // main frame. | 385 // main frame. |
| 384 if (agent_host && agent_host->page_handler_) { | 386 if (!agent_host || !agent_host->session()) |
| 385 return agent_host->page_handler_->CreateThrottleForNavigation( | 387 return nullptr; |
| 386 navigation_handle); | 388 protocol::PageHandler* page_handler = |
| 387 } | 389 protocol::PageHandler::FromSession(agent_host->session()); |
| 388 return nullptr; | 390 if (!page_handler) |
| 391 return nullptr; |
| 392 return page_handler->CreateThrottleForNavigation(navigation_handle); |
| 389 } | 393 } |
| 390 | 394 |
| 391 // static | 395 // static |
| 392 bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled( | 396 bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled( |
| 393 FrameTreeNode* frame_tree_node) { | 397 FrameTreeNode* frame_tree_node) { |
| 394 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 398 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
| 395 return agent_host && agent_host->network_handler_ && | 399 if (!agent_host || !agent_host->session()) |
| 396 agent_host->network_handler_->enabled(); | 400 return false; |
| 401 return protocol::NetworkHandler::FromSession(agent_host->session()) |
| 402 ->enabled(); |
| 397 } | 403 } |
| 398 | 404 |
| 399 // static | 405 // static |
| 400 std::string RenderFrameDevToolsAgentHost::UserAgentOverride( | 406 std::string RenderFrameDevToolsAgentHost::UserAgentOverride( |
| 401 FrameTreeNode* frame_tree_node) { | 407 FrameTreeNode* frame_tree_node) { |
| 402 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 408 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); |
| 403 if (agent_host && agent_host->network_handler_) | 409 if (!agent_host || !agent_host->session()) |
| 404 return agent_host->network_handler_->UserAgentOverride(); | 410 return std::string(); |
| 405 return std::string(); | 411 return protocol::NetworkHandler::FromSession(agent_host->session()) |
| 412 ->UserAgentOverride(); |
| 406 } | 413 } |
| 407 | 414 |
| 408 // static | 415 // static |
| 409 void RenderFrameDevToolsAgentHost::WebContentsCreated( | 416 void RenderFrameDevToolsAgentHost::WebContentsCreated( |
| 410 WebContents* web_contents) { | 417 WebContents* web_contents) { |
| 411 if (ShouldForceCreation()) { | 418 if (ShouldForceCreation()) { |
| 412 // Force agent host. | 419 // Force agent host. |
| 413 DevToolsAgentHost::GetOrCreateFor(web_contents); | 420 DevToolsAgentHost::GetOrCreateFor(web_contents); |
| 414 } | 421 } |
| 415 } | 422 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 483 |
| 477 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { | 484 BrowserContext* RenderFrameDevToolsAgentHost::GetBrowserContext() { |
| 478 WebContents* contents = web_contents(); | 485 WebContents* contents = web_contents(); |
| 479 return contents ? contents->GetBrowserContext() : nullptr; | 486 return contents ? contents->GetBrowserContext() : nullptr; |
| 480 } | 487 } |
| 481 | 488 |
| 482 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { | 489 WebContents* RenderFrameDevToolsAgentHost::GetWebContents() { |
| 483 return web_contents(); | 490 return web_contents(); |
| 484 } | 491 } |
| 485 | 492 |
| 486 void RenderFrameDevToolsAgentHost::Attach() { | 493 void RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) { |
| 487 session()->dispatcher()->setFallThroughForNotFound(true); | 494 session->SetFallThroughForNotFound(true); |
| 488 | 495 session->SetRenderFrameHost(handlers_frame_host_); |
| 489 if (!frame_tree_node_->parent()) { | 496 if (!frame_tree_node_->parent()) { |
| 490 emulation_handler_.reset(new protocol::EmulationHandler()); | 497 session->AddHandler(base::WrapUnique(new protocol::EmulationHandler())); |
| 491 emulation_handler_->Wire(session()->dispatcher()); | 498 session->AddHandler(base::WrapUnique(new protocol::PageHandler())); |
| 492 emulation_handler_->SetRenderFrameHost(handlers_frame_host_); | 499 session->AddHandler(base::WrapUnique(new protocol::SecurityHandler())); |
| 493 } | 500 } |
| 494 | 501 session->AddHandler(base::WrapUnique(new protocol::DOMHandler())); |
| 495 dom_handler_.reset(new protocol::DOMHandler()); | 502 session->AddHandler(base::WrapUnique(new protocol::InputHandler())); |
| 496 dom_handler_->Wire(session()->dispatcher()); | 503 session->AddHandler(base::WrapUnique(new protocol::InspectorHandler())); |
| 497 dom_handler_->SetRenderFrameHost(handlers_frame_host_); | 504 session->AddHandler(base::WrapUnique(new protocol::IOHandler( |
| 498 | 505 GetIOContext()))); |
| 499 input_handler_.reset(new protocol::InputHandler()); | 506 session->AddHandler(base::WrapUnique(new protocol::NetworkHandler())); |
| 500 input_handler_->Wire(session()->dispatcher()); | 507 session->AddHandler(base::WrapUnique(new protocol::SchemaHandler())); |
| 501 input_handler_->SetRenderFrameHost(handlers_frame_host_); | 508 session->AddHandler(base::WrapUnique(new protocol::ServiceWorkerHandler())); |
| 502 | 509 session->AddHandler(base::WrapUnique(new protocol::StorageHandler())); |
| 503 inspector_handler_.reset(new protocol::InspectorHandler()); | 510 session->AddHandler(base::WrapUnique(new protocol::TargetHandler())); |
| 504 inspector_handler_->Wire(session()->dispatcher()); | 511 session->AddHandler(base::WrapUnique(new protocol::TracingHandler( |
| 505 inspector_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 506 | |
| 507 io_handler_.reset(new protocol::IOHandler(GetIOContext())); | |
| 508 io_handler_->Wire(session()->dispatcher()); | |
| 509 | |
| 510 network_handler_.reset(new protocol::NetworkHandler()); | |
| 511 network_handler_->Wire(session()->dispatcher()); | |
| 512 network_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 513 | |
| 514 if (!frame_tree_node_->parent()) { | |
| 515 page_handler_.reset(new protocol::PageHandler()); | |
| 516 page_handler_->Wire(session()->dispatcher()); | |
| 517 page_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 518 } | |
| 519 | |
| 520 schema_handler_.reset(new protocol::SchemaHandler()); | |
| 521 schema_handler_->Wire(session()->dispatcher()); | |
| 522 | |
| 523 if (!frame_tree_node_->parent()) { | |
| 524 security_handler_.reset(new protocol::SecurityHandler()); | |
| 525 security_handler_->Wire(session()->dispatcher()); | |
| 526 security_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 527 } | |
| 528 | |
| 529 service_worker_handler_.reset(new protocol::ServiceWorkerHandler()); | |
| 530 service_worker_handler_->Wire(session()->dispatcher()); | |
| 531 service_worker_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 532 | |
| 533 storage_handler_.reset(new protocol::StorageHandler()); | |
| 534 storage_handler_->Wire(session()->dispatcher()); | |
| 535 storage_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 536 | |
| 537 target_handler_.reset(new protocol::TargetHandler()); | |
| 538 target_handler_->Wire(session()->dispatcher()); | |
| 539 target_handler_->SetRenderFrameHost(handlers_frame_host_); | |
| 540 | |
| 541 tracing_handler_.reset(new protocol::TracingHandler( | |
| 542 protocol::TracingHandler::Renderer, | 512 protocol::TracingHandler::Renderer, |
| 543 frame_tree_node_->frame_tree_node_id(), | 513 frame_tree_node_->frame_tree_node_id(), |
| 544 GetIOContext())); | 514 GetIOContext()))); |
| 545 tracing_handler_->Wire(session()->dispatcher()); | |
| 546 | 515 |
| 547 if (current_) | 516 if (current_) |
| 548 current_->Attach(); | 517 current_->Attach(session); |
| 549 if (pending_) | 518 if (pending_) |
| 550 pending_->Attach(); | 519 pending_->Attach(session); |
| 551 OnClientAttached(); | 520 OnClientAttached(); |
| 552 } | 521 } |
| 553 | 522 |
| 554 void RenderFrameDevToolsAgentHost::Detach() { | 523 void RenderFrameDevToolsAgentHost::DetachSession(int session_id) { |
| 555 dom_handler_->Disable(); | |
| 556 dom_handler_.reset(); | |
| 557 if (emulation_handler_) { | |
| 558 emulation_handler_->Disable(); | |
| 559 emulation_handler_.reset(); | |
| 560 } | |
| 561 input_handler_->Disable(); | |
| 562 input_handler_.reset(); | |
| 563 inspector_handler_->Disable(); | |
| 564 inspector_handler_.reset(); | |
| 565 io_handler_->Disable(); | |
| 566 io_handler_.reset(); | |
| 567 network_handler_->Disable(); | |
| 568 network_handler_.reset(); | |
| 569 if (page_handler_) { | |
| 570 page_handler_->Disable(); | |
| 571 page_handler_.reset(); | |
| 572 } | |
| 573 schema_handler_->Disable(); | |
| 574 schema_handler_.reset(); | |
| 575 if (security_handler_) { | |
| 576 security_handler_->Disable(); | |
| 577 security_handler_.reset(); | |
| 578 } | |
| 579 service_worker_handler_->Disable(); | |
| 580 service_worker_handler_.reset(); | |
| 581 storage_handler_->Disable(); | |
| 582 storage_handler_.reset(); | |
| 583 target_handler_->Disable(); | |
| 584 target_handler_.reset(); | |
| 585 tracing_handler_->Disable(); | |
| 586 tracing_handler_.reset(); | |
| 587 | |
| 588 if (current_) | 524 if (current_) |
| 589 current_->Detach(); | 525 current_->Detach(session_id); |
| 590 if (pending_) | 526 if (pending_) |
| 591 pending_->Detach(); | 527 pending_->Detach(session_id); |
| 592 OnClientDetached(); | 528 OnClientDetached(); |
| 593 } | 529 } |
| 594 | 530 |
| 595 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( | 531 bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage( |
| 532 DevToolsSession* session, |
| 596 const std::string& message) { | 533 const std::string& message) { |
| 597 int call_id = 0; | 534 int call_id = 0; |
| 598 std::string method; | 535 std::string method; |
| 599 if (session()->Dispatch(message, &call_id, &method) != | 536 if (session->Dispatch(message, true, &call_id, &method) != |
| 600 protocol::Response::kFallThrough) { | 537 protocol::Response::kFallThrough) { |
| 601 return true; | 538 return true; |
| 602 } | 539 } |
| 603 | 540 |
| 604 if (!navigating_handles_.empty()) { | 541 if (!navigating_handles_.empty()) { |
| 605 DCHECK(IsBrowserSideNavigationEnabled()); | 542 DCHECK(IsBrowserSideNavigationEnabled()); |
| 606 in_navigation_protocol_message_buffer_[call_id] = | 543 in_navigation_protocol_message_buffer_[call_id] = |
| 607 { session()->session_id(), method, message }; | 544 { session->session_id(), method, message }; |
| 608 return true; | 545 return true; |
| 609 } | 546 } |
| 610 | 547 |
| 611 if (current_) { | 548 if (current_) { |
| 612 current_->DispatchProtocolMessage( | 549 current_->DispatchProtocolMessage( |
| 613 session()->session_id(), call_id, method, message); | 550 session->session_id(), call_id, method, message); |
| 614 } | 551 } |
| 615 if (pending_) { | 552 if (pending_) { |
| 616 pending_->DispatchProtocolMessage( | 553 pending_->DispatchProtocolMessage( |
| 617 session()->session_id(), call_id, method, message); | 554 session->session_id(), call_id, method, message); |
| 618 } | 555 } |
| 619 return true; | 556 return true; |
| 620 } | 557 } |
| 621 | 558 |
| 622 void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) { | 559 void RenderFrameDevToolsAgentHost::InspectElement( |
| 560 DevToolsSession* session, |
| 561 int x, |
| 562 int y) { |
| 623 if (current_) | 563 if (current_) |
| 624 current_->InspectElement(session()->session_id(), x, y); | 564 current_->InspectElement(session->session_id(), x, y); |
| 625 if (pending_) | 565 if (pending_) |
| 626 pending_->InspectElement(session()->session_id(), x, y); | 566 pending_->InspectElement(session->session_id(), x, y); |
| 627 } | 567 } |
| 628 | 568 |
| 629 void RenderFrameDevToolsAgentHost::OnClientAttached() { | 569 void RenderFrameDevToolsAgentHost::OnClientAttached() { |
| 630 if (!web_contents()) | 570 if (!web_contents()) |
| 631 return; | 571 return; |
| 632 | 572 |
| 633 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); | 573 frame_trace_recorder_.reset(new DevToolsFrameTraceRecorder()); |
| 634 CreatePowerSaveBlocker(); | 574 CreatePowerSaveBlocker(); |
| 635 } | 575 } |
| 636 | 576 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 } else { | 646 } else { |
| 707 DiscardPending(); | 647 DiscardPending(); |
| 708 } | 648 } |
| 709 pending_handle_ = nullptr; | 649 pending_handle_ = nullptr; |
| 710 } else if (navigating_handles_.empty()) { | 650 } else if (navigating_handles_.empty()) { |
| 711 current_->Resume(); | 651 current_->Resume(); |
| 712 } | 652 } |
| 713 DispatchBufferedProtocolMessagesIfNecessary(); | 653 DispatchBufferedProtocolMessagesIfNecessary(); |
| 714 | 654 |
| 715 DCHECK(CheckConsistency()); | 655 DCHECK(CheckConsistency()); |
| 716 if (target_handler_ && navigation_handle->HasCommitted()) | 656 if (session() && navigation_handle->HasCommitted()) |
| 717 target_handler_->UpdateServiceWorkers(); | 657 protocol::TargetHandler::FromSession(session())->UpdateServiceWorkers(); |
| 718 } | 658 } |
| 719 | 659 |
| 720 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( | 660 void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame( |
| 721 RenderFrameHost* old_host, | 661 RenderFrameHost* old_host, |
| 722 RenderFrameHost* new_host) { | 662 RenderFrameHost* new_host) { |
| 723 // CommitPending may destruct |this|. | 663 // CommitPending may destruct |this|. |
| 724 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 664 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 725 | 665 |
| 726 if (IsBrowserSideNavigationEnabled()) | 666 if (IsBrowserSideNavigationEnabled()) |
| 727 return; | 667 return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 753 current_->Suspend(); | 693 current_->Suspend(); |
| 754 DCHECK(CheckConsistency()); | 694 DCHECK(CheckConsistency()); |
| 755 } | 695 } |
| 756 | 696 |
| 757 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( | 697 void RenderFrameDevToolsAgentHost::RenderFrameHostChanged( |
| 758 RenderFrameHost* old_host, | 698 RenderFrameHost* old_host, |
| 759 RenderFrameHost* new_host) { | 699 RenderFrameHost* new_host) { |
| 760 // CommitPending may destruct |this|. | 700 // CommitPending may destruct |this|. |
| 761 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 701 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 762 | 702 |
| 763 if (target_handler_) | 703 if (session()) |
| 764 target_handler_->UpdateFrames(); | 704 protocol::TargetHandler::FromSession(session())->UpdateFrames(); |
| 765 | 705 |
| 766 if (IsBrowserSideNavigationEnabled()) | 706 if (IsBrowserSideNavigationEnabled()) |
| 767 return; | 707 return; |
| 768 | 708 |
| 769 DCHECK(!pending_ || pending_->host() != old_host); | 709 DCHECK(!pending_ || pending_->host() != old_host); |
| 770 if (!current_ || current_->host() != old_host) { | 710 if (!current_ || current_->host() != old_host) { |
| 771 DCHECK(CheckConsistency()); | 711 DCHECK(CheckConsistency()); |
| 772 return; | 712 return; |
| 773 } | 713 } |
| 774 | 714 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 798 else | 738 else |
| 799 DCHECK(CheckConsistency()); | 739 DCHECK(CheckConsistency()); |
| 800 } | 740 } |
| 801 | 741 |
| 802 void RenderFrameDevToolsAgentHost::DestroyOnRenderFrameGone() { | 742 void RenderFrameDevToolsAgentHost::DestroyOnRenderFrameGone() { |
| 803 DCHECK(current_); | 743 DCHECK(current_); |
| 804 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 744 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 805 UpdateProtocolHandlers(nullptr); | 745 UpdateProtocolHandlers(nullptr); |
| 806 if (IsAttached()) | 746 if (IsAttached()) |
| 807 OnClientDetached(); | 747 OnClientDetached(); |
| 808 HostClosed(); | 748 ForceDetach(false); |
| 809 pending_.reset(); | 749 pending_.reset(); |
| 810 current_.reset(); | 750 current_.reset(); |
| 811 frame_tree_node_ = nullptr; | 751 frame_tree_node_ = nullptr; |
| 812 pending_handle_ = nullptr; | 752 pending_handle_ = nullptr; |
| 813 WebContentsObserver::Observe(nullptr); | 753 WebContentsObserver::Observe(nullptr); |
| 814 Release(); | 754 Release(); |
| 815 } | 755 } |
| 816 | 756 |
| 817 bool RenderFrameDevToolsAgentHost::CheckConsistency() { | 757 bool RenderFrameDevToolsAgentHost::CheckConsistency() { |
| 818 if (current_ && pending_ && current_->host() == pending_->host()) | 758 if (current_ && pending_ && current_->host() == pending_->host()) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 846 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 786 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 847 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 787 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 848 #if defined(OS_CHROMEOS) | 788 #if defined(OS_CHROMEOS) |
| 849 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: | 789 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
| 850 #endif | 790 #endif |
| 851 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 791 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 852 #if defined(OS_ANDROID) | 792 #if defined(OS_ANDROID) |
| 853 case base::TERMINATION_STATUS_OOM_PROTECTED: | 793 case base::TERMINATION_STATUS_OOM_PROTECTED: |
| 854 #endif | 794 #endif |
| 855 case base::TERMINATION_STATUS_LAUNCH_FAILED: | 795 case base::TERMINATION_STATUS_LAUNCH_FAILED: |
| 856 if (inspector_handler_) | 796 if (session()) |
| 857 inspector_handler_->TargetCrashed(); | 797 protocol::InspectorHandler::FromSession(session())->TargetCrashed(); |
| 858 current_frame_crashed_ = true; | 798 current_frame_crashed_ = true; |
| 859 break; | 799 break; |
| 860 default: | 800 default: |
| 861 if (inspector_handler_) | 801 if (session()) { |
| 862 inspector_handler_->TargetDetached("Render process gone."); | 802 protocol::InspectorHandler::FromSession(session()) |
| 803 ->TargetDetached("Render process gone."); |
| 804 } |
| 863 break; | 805 break; |
| 864 } | 806 } |
| 865 DCHECK(CheckConsistency()); | 807 DCHECK(CheckConsistency()); |
| 866 } | 808 } |
| 867 | 809 |
| 868 bool RenderFrameDevToolsAgentHost::OnMessageReceived( | 810 bool RenderFrameDevToolsAgentHost::OnMessageReceived( |
| 869 const IPC::Message& message) { | 811 const IPC::Message& message) { |
| 870 if (!current_) | 812 if (!current_) |
| 871 return false; | 813 return false; |
| 872 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) | 814 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 889 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 831 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| 890 OnDispatchOnInspectorFrontend) | 832 OnDispatchOnInspectorFrontend) |
| 891 IPC_MESSAGE_HANDLER(DevToolsAgentHostMsg_RequestNewWindow, | 833 IPC_MESSAGE_HANDLER(DevToolsAgentHostMsg_RequestNewWindow, |
| 892 OnRequestNewWindow) | 834 OnRequestNewWindow) |
| 893 IPC_MESSAGE_UNHANDLED(handled = false) | 835 IPC_MESSAGE_UNHANDLED(handled = false) |
| 894 IPC_END_MESSAGE_MAP() | 836 IPC_END_MESSAGE_MAP() |
| 895 return handled; | 837 return handled; |
| 896 } | 838 } |
| 897 | 839 |
| 898 void RenderFrameDevToolsAgentHost::DidAttachInterstitialPage() { | 840 void RenderFrameDevToolsAgentHost::DidAttachInterstitialPage() { |
| 899 if (page_handler_) | 841 protocol::PageHandler* page_handler = |
| 900 page_handler_->DidAttachInterstitialPage(); | 842 session() ? protocol::PageHandler::FromSession(session()) : nullptr; |
| 843 if (page_handler) |
| 844 page_handler->DidAttachInterstitialPage(); |
| 901 | 845 |
| 902 // TODO(dgozman): this may break for cross-process subframes. | 846 // TODO(dgozman): this may break for cross-process subframes. |
| 903 if (!pending_) { | 847 if (!pending_) { |
| 904 DCHECK(CheckConsistency()); | 848 DCHECK(CheckConsistency()); |
| 905 return; | 849 return; |
| 906 } | 850 } |
| 907 // Pending set in AboutToNavigateRenderFrame turned out to be interstitial. | 851 // Pending set in AboutToNavigateRenderFrame turned out to be interstitial. |
| 908 // Connect back to the real one. | 852 // Connect back to the real one. |
| 909 DiscardPending(); | 853 DiscardPending(); |
| 910 pending_handle_ = nullptr; | 854 pending_handle_ = nullptr; |
| 911 DCHECK(CheckConsistency()); | 855 DCHECK(CheckConsistency()); |
| 912 } | 856 } |
| 913 | 857 |
| 914 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { | 858 void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() { |
| 915 if (page_handler_) | 859 protocol::PageHandler* page_handler = |
| 916 page_handler_->DidDetachInterstitialPage(); | 860 session() ? protocol::PageHandler::FromSession(session()) : nullptr; |
| 861 if (page_handler) |
| 862 page_handler->DidDetachInterstitialPage(); |
| 917 } | 863 } |
| 918 | 864 |
| 919 void RenderFrameDevToolsAgentHost::DidCommitProvisionalLoadForFrame( | 865 void RenderFrameDevToolsAgentHost::DidCommitProvisionalLoadForFrame( |
| 920 RenderFrameHost* render_frame_host, | 866 RenderFrameHost* render_frame_host, |
| 921 const GURL& url, | 867 const GURL& url, |
| 922 ui::PageTransition transition_type) { | 868 ui::PageTransition transition_type) { |
| 923 // CommitPending may destruct |this|. | 869 // CommitPending may destruct |this|. |
| 924 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 870 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 925 | 871 |
| 926 if (IsBrowserSideNavigationEnabled()) | 872 if (IsBrowserSideNavigationEnabled()) |
| 927 return; | 873 return; |
| 928 if (pending_ && pending_->host() == render_frame_host) | 874 if (pending_ && pending_->host() == render_frame_host) |
| 929 CommitPending(); | 875 CommitPending(); |
| 930 DCHECK(CheckConsistency()); | 876 DCHECK(CheckConsistency()); |
| 931 if (target_handler_) | 877 if (session()) |
| 932 target_handler_->UpdateServiceWorkers(); | 878 protocol::TargetHandler::FromSession(session())->UpdateServiceWorkers(); |
| 933 } | 879 } |
| 934 | 880 |
| 935 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( | 881 void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad( |
| 936 RenderFrameHost* render_frame_host, | 882 RenderFrameHost* render_frame_host, |
| 937 const GURL& validated_url, | 883 const GURL& validated_url, |
| 938 int error_code, | 884 int error_code, |
| 939 const base::string16& error_description, | 885 const base::string16& error_description, |
| 940 bool was_ignored_by_handler) { | 886 bool was_ignored_by_handler) { |
| 941 if (IsBrowserSideNavigationEnabled()) | 887 if (IsBrowserSideNavigationEnabled()) |
| 942 return; | 888 return; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 971 | 917 |
| 972 void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers( | 918 void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers( |
| 973 RenderFrameHostImpl* host) { | 919 RenderFrameHostImpl* host) { |
| 974 #if DCHECK_IS_ON() | 920 #if DCHECK_IS_ON() |
| 975 // Check that we don't have stale host object here by accessing some random | 921 // Check that we don't have stale host object here by accessing some random |
| 976 // properties inside. | 922 // properties inside. |
| 977 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) | 923 if (handlers_frame_host_ && handlers_frame_host_->GetRenderWidgetHost()) |
| 978 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); | 924 handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID(); |
| 979 #endif | 925 #endif |
| 980 handlers_frame_host_ = host; | 926 handlers_frame_host_ = host; |
| 981 if (dom_handler_) | 927 if (session()) |
| 982 dom_handler_->SetRenderFrameHost(host); | 928 session()->SetRenderFrameHost(host); |
| 983 if (emulation_handler_) | |
| 984 emulation_handler_->SetRenderFrameHost(host); | |
| 985 if (input_handler_) | |
| 986 input_handler_->SetRenderFrameHost(host); | |
| 987 if (inspector_handler_) | |
| 988 inspector_handler_->SetRenderFrameHost(host); | |
| 989 if (network_handler_) | |
| 990 network_handler_->SetRenderFrameHost(host); | |
| 991 if (page_handler_) | |
| 992 page_handler_->SetRenderFrameHost(host); | |
| 993 if (service_worker_handler_) | |
| 994 service_worker_handler_->SetRenderFrameHost(host); | |
| 995 if (security_handler_) | |
| 996 security_handler_->SetRenderFrameHost(host); | |
| 997 if (storage_handler_) | |
| 998 storage_handler_->SetRenderFrameHost(host); | |
| 999 if (target_handler_) | |
| 1000 target_handler_->SetRenderFrameHost(host); | |
| 1001 } | 929 } |
| 1002 | 930 |
| 1003 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 931 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { |
| 1004 if (pending_) | 932 if (pending_) |
| 1005 DiscardPending(); | 933 DiscardPending(); |
| 1006 UpdateProtocolHandlers(nullptr); | 934 UpdateProtocolHandlers(nullptr); |
| 1007 disconnected_ = std::move(current_); | 935 disconnected_ = std::move(current_); |
| 1008 disconnected_->Detach(); | 936 if (session()) |
| 937 disconnected_->Detach(session()->session_id()); |
| 1009 frame_tree_node_ = nullptr; | 938 frame_tree_node_ = nullptr; |
| 1010 in_navigation_protocol_message_buffer_.clear(); | 939 in_navigation_protocol_message_buffer_.clear(); |
| 1011 navigating_handles_.clear(); | 940 navigating_handles_.clear(); |
| 1012 pending_handle_ = nullptr; | 941 pending_handle_ = nullptr; |
| 1013 WebContentsObserver::Observe(nullptr); | 942 WebContentsObserver::Observe(nullptr); |
| 1014 } | 943 } |
| 1015 | 944 |
| 1016 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { | 945 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { |
| 1017 // CommitPending may destruct |this|. | 946 // CommitPending may destruct |this|. |
| 1018 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 947 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 if (content::WebContents* contents = web_contents()) | 1057 if (content::WebContents* contents = web_contents()) |
| 1129 return contents->GetLastActiveTime(); | 1058 return contents->GetLastActiveTime(); |
| 1130 return base::TimeTicks(); | 1059 return base::TimeTicks(); |
| 1131 } | 1060 } |
| 1132 | 1061 |
| 1133 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( | 1062 void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( |
| 1134 const IPC::Message& message) { | 1063 const IPC::Message& message) { |
| 1135 ViewHostMsg_SwapCompositorFrame::Param param; | 1064 ViewHostMsg_SwapCompositorFrame::Param param; |
| 1136 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 1065 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
| 1137 return; | 1066 return; |
| 1138 if (page_handler_) { | 1067 if (!session()) |
| 1139 page_handler_->OnSwapCompositorFrame( | 1068 return; |
| 1069 protocol::PageHandler* page_handler = |
| 1070 protocol::PageHandler::FromSession(session()); |
| 1071 if (page_handler) { |
| 1072 page_handler->OnSwapCompositorFrame( |
| 1140 std::move(std::get<1>(param).metadata)); | 1073 std::move(std::get<1>(param).metadata)); |
| 1141 } | 1074 } |
| 1142 if (input_handler_) | 1075 protocol::InputHandler::FromSession(session()) |
| 1143 input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata); | 1076 ->OnSwapCompositorFrame(std::get<1>(param).metadata); |
| 1144 if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) { | 1077 protocol::TracingHandler* tracing_handler = |
| 1078 protocol::TracingHandler::FromSession(session()); |
| 1079 if (frame_trace_recorder_ && tracing_handler->did_initiate_recording()) { |
| 1145 frame_trace_recorder_->OnSwapCompositorFrame( | 1080 frame_trace_recorder_->OnSwapCompositorFrame( |
| 1146 current_ ? current_->host() : nullptr, std::get<1>(param).metadata); | 1081 current_ ? current_->host() : nullptr, std::get<1>(param).metadata); |
| 1147 } | 1082 } |
| 1148 } | 1083 } |
| 1149 | 1084 |
| 1150 void RenderFrameDevToolsAgentHost::SignalSynchronousSwapCompositorFrame( | 1085 void RenderFrameDevToolsAgentHost::SignalSynchronousSwapCompositorFrame( |
| 1151 RenderFrameHost* frame_host, | 1086 RenderFrameHost* frame_host, |
| 1152 cc::CompositorFrameMetadata frame_metadata) { | 1087 cc::CompositorFrameMetadata frame_metadata) { |
| 1153 scoped_refptr<RenderFrameDevToolsAgentHost> dtah(FindAgentHost(frame_host)); | 1088 scoped_refptr<RenderFrameDevToolsAgentHost> dtah(FindAgentHost(frame_host)); |
| 1154 if (dtah) { | 1089 if (dtah) { |
| 1155 // Unblock the compositor. | 1090 // Unblock the compositor. |
| 1156 BrowserThread::PostTask( | 1091 BrowserThread::PostTask( |
| 1157 BrowserThread::UI, FROM_HERE, | 1092 BrowserThread::UI, FROM_HERE, |
| 1158 base::Bind( | 1093 base::Bind( |
| 1159 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, | 1094 &RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame, |
| 1160 dtah.get(), | 1095 dtah.get(), |
| 1161 base::Passed(std::move(frame_metadata)))); | 1096 base::Passed(std::move(frame_metadata)))); |
| 1162 } | 1097 } |
| 1163 } | 1098 } |
| 1164 | 1099 |
| 1165 void RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame( | 1100 void RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame( |
| 1166 cc::CompositorFrameMetadata frame_metadata) { | 1101 cc::CompositorFrameMetadata frame_metadata) { |
| 1167 if (page_handler_) | 1102 if (!session()) |
| 1168 page_handler_->OnSynchronousSwapCompositorFrame(std::move(frame_metadata)); | 1103 return; |
| 1169 if (input_handler_) | 1104 protocol::PageHandler* page_handler = |
| 1170 input_handler_->OnSwapCompositorFrame(frame_metadata); | 1105 protocol::PageHandler::FromSession(session()); |
| 1171 if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) { | 1106 if (page_handler) |
| 1107 page_handler->OnSynchronousSwapCompositorFrame(std::move(frame_metadata)); |
| 1108 protocol::InputHandler::FromSession(session()) |
| 1109 ->OnSwapCompositorFrame(frame_metadata); |
| 1110 protocol::TracingHandler* tracing_handler = |
| 1111 protocol::TracingHandler::FromSession(session()); |
| 1112 if (frame_trace_recorder_ && tracing_handler->did_initiate_recording()) { |
| 1172 frame_trace_recorder_->OnSynchronousSwapCompositorFrame( | 1113 frame_trace_recorder_->OnSynchronousSwapCompositorFrame( |
| 1173 current_ ? current_->host() : nullptr, | 1114 current_ ? current_->host() : nullptr, |
| 1174 frame_metadata); | 1115 frame_metadata); |
| 1175 } | 1116 } |
| 1176 } | 1117 } |
| 1177 | 1118 |
| 1178 void RenderFrameDevToolsAgentHost::OnDispatchOnInspectorFrontend( | 1119 void RenderFrameDevToolsAgentHost::OnDispatchOnInspectorFrontend( |
| 1179 RenderFrameHost* sender, | 1120 RenderFrameHost* sender, |
| 1180 const DevToolsMessageChunk& message) { | 1121 const DevToolsMessageChunk& message) { |
| 1181 bool success = true; | 1122 bool success = true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1211 RenderFrameHost* host) { | 1152 RenderFrameHost* host) { |
| 1212 return (current_ && current_->host() == host) || | 1153 return (current_ && current_->host() == host) || |
| 1213 (pending_ && pending_->host() == host); | 1154 (pending_ && pending_->host() == host); |
| 1214 } | 1155 } |
| 1215 | 1156 |
| 1216 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1157 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1217 return current_ && current_->host()->GetParent(); | 1158 return current_ && current_->host()->GetParent(); |
| 1218 } | 1159 } |
| 1219 | 1160 |
| 1220 } // namespace content | 1161 } // namespace content |
| OLD | NEW |