| Index: content/browser/devtools/render_frame_devtools_agent_host.cc
|
| diff --git a/content/browser/devtools/render_frame_devtools_agent_host.cc b/content/browser/devtools/render_frame_devtools_agent_host.cc
|
| index c8bd69438eef9499073e2a3cb0d4d58e890741d8..a4654300f607c71b842624e1dd7d95183f7c1c96 100644
|
| --- a/content/browser/devtools/render_frame_devtools_agent_host.cc
|
| +++ b/content/browser/devtools/render_frame_devtools_agent_host.cc
|
| @@ -10,6 +10,7 @@
|
| #include "base/guid.h"
|
| #include "base/json/json_reader.h"
|
| #include "base/lazy_instance.h"
|
| +#include "base/memory/ptr_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "build/build_config.h"
|
| #include "content/browser/bad_message.h"
|
| @@ -103,9 +104,9 @@ class RenderFrameDevToolsAgentHost::FrameHostHolder {
|
|
|
| RenderFrameHostImpl* host() const { return host_; }
|
|
|
| - void Attach();
|
| + void Attach(DevToolsSession* session);
|
| void Reattach(FrameHostHolder* old);
|
| - void Detach();
|
| + void Detach(int session_id);
|
| void DispatchProtocolMessage(int session_id,
|
| int call_id,
|
| const std::string& method,
|
| @@ -151,9 +152,10 @@ RenderFrameDevToolsAgentHost::FrameHostHolder::~FrameHostHolder() {
|
| RevokePolicy();
|
| }
|
|
|
| -void RenderFrameDevToolsAgentHost::FrameHostHolder::Attach() {
|
| +void RenderFrameDevToolsAgentHost::FrameHostHolder::Attach(
|
| + DevToolsSession* session) {
|
| host_->Send(new DevToolsAgentMsg_Attach(
|
| - host_->GetRoutingID(), agent_->GetId(), agent_->session()->session_id()));
|
| + host_->GetRoutingID(), agent_->GetId(), session->session_id()));
|
| GrantPolicy();
|
| attached_ = true;
|
| }
|
| @@ -182,7 +184,7 @@ void RenderFrameDevToolsAgentHost::FrameHostHolder::Reattach(
|
| attached_ = true;
|
| }
|
|
|
| -void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach() {
|
| +void RenderFrameDevToolsAgentHost::FrameHostHolder::Detach(int session_id) {
|
| host_->Send(new DevToolsAgentMsg_Detach(host_->GetRoutingID()));
|
| RevokePolicy();
|
| attached_ = false;
|
| @@ -381,28 +383,33 @@ RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(
|
| // Note Page.setControlNavigations is intended to control navigations in the
|
| // main frame and all child frames and |page_handler_| only exists for the
|
| // main frame.
|
| - if (agent_host && agent_host->page_handler_) {
|
| - return agent_host->page_handler_->CreateThrottleForNavigation(
|
| - navigation_handle);
|
| - }
|
| - return nullptr;
|
| + if (!agent_host || !agent_host->session())
|
| + return nullptr;
|
| + protocol::PageHandler* page_handler =
|
| + protocol::PageHandler::FromSession(agent_host->session());
|
| + if (!page_handler)
|
| + return nullptr;
|
| + return page_handler->CreateThrottleForNavigation(navigation_handle);
|
| }
|
|
|
| // static
|
| bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled(
|
| FrameTreeNode* frame_tree_node) {
|
| RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node);
|
| - return agent_host && agent_host->network_handler_ &&
|
| - agent_host->network_handler_->enabled();
|
| + if (!agent_host || !agent_host->session())
|
| + return false;
|
| + return protocol::NetworkHandler::FromSession(agent_host->session())
|
| + ->enabled();
|
| }
|
|
|
| // static
|
| std::string RenderFrameDevToolsAgentHost::UserAgentOverride(
|
| FrameTreeNode* frame_tree_node) {
|
| RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node);
|
| - if (agent_host && agent_host->network_handler_)
|
| - return agent_host->network_handler_->UserAgentOverride();
|
| - return std::string();
|
| + if (!agent_host || !agent_host->session())
|
| + return std::string();
|
| + return protocol::NetworkHandler::FromSession(agent_host->session())
|
| + ->UserAgentOverride();
|
| }
|
|
|
| // static
|
| @@ -483,120 +490,50 @@ WebContents* RenderFrameDevToolsAgentHost::GetWebContents() {
|
| return web_contents();
|
| }
|
|
|
| -void RenderFrameDevToolsAgentHost::Attach() {
|
| - session()->dispatcher()->setFallThroughForNotFound(true);
|
| -
|
| - if (!frame_tree_node_->parent()) {
|
| - emulation_handler_.reset(new protocol::EmulationHandler());
|
| - emulation_handler_->Wire(session()->dispatcher());
|
| - emulation_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| - }
|
| -
|
| - dom_handler_.reset(new protocol::DOMHandler());
|
| - dom_handler_->Wire(session()->dispatcher());
|
| - dom_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| -
|
| - input_handler_.reset(new protocol::InputHandler());
|
| - input_handler_->Wire(session()->dispatcher());
|
| - input_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| -
|
| - inspector_handler_.reset(new protocol::InspectorHandler());
|
| - inspector_handler_->Wire(session()->dispatcher());
|
| - inspector_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| -
|
| - io_handler_.reset(new protocol::IOHandler(GetIOContext()));
|
| - io_handler_->Wire(session()->dispatcher());
|
| -
|
| - network_handler_.reset(new protocol::NetworkHandler());
|
| - network_handler_->Wire(session()->dispatcher());
|
| - network_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| -
|
| - if (!frame_tree_node_->parent()) {
|
| - page_handler_.reset(new protocol::PageHandler());
|
| - page_handler_->Wire(session()->dispatcher());
|
| - page_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| - }
|
| -
|
| - schema_handler_.reset(new protocol::SchemaHandler());
|
| - schema_handler_->Wire(session()->dispatcher());
|
| -
|
| +void RenderFrameDevToolsAgentHost::AttachSession(DevToolsSession* session) {
|
| + session->SetFallThroughForNotFound(true);
|
| + session->SetRenderFrameHost(handlers_frame_host_);
|
| if (!frame_tree_node_->parent()) {
|
| - security_handler_.reset(new protocol::SecurityHandler());
|
| - security_handler_->Wire(session()->dispatcher());
|
| - security_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| + session->AddHandler(base::WrapUnique(new protocol::EmulationHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::PageHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::SecurityHandler()));
|
| }
|
| -
|
| - service_worker_handler_.reset(new protocol::ServiceWorkerHandler());
|
| - service_worker_handler_->Wire(session()->dispatcher());
|
| - service_worker_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| -
|
| - storage_handler_.reset(new protocol::StorageHandler());
|
| - storage_handler_->Wire(session()->dispatcher());
|
| - storage_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| -
|
| - target_handler_.reset(new protocol::TargetHandler());
|
| - target_handler_->Wire(session()->dispatcher());
|
| - target_handler_->SetRenderFrameHost(handlers_frame_host_);
|
| -
|
| - tracing_handler_.reset(new protocol::TracingHandler(
|
| + session->AddHandler(base::WrapUnique(new protocol::DOMHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::InputHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::InspectorHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::IOHandler(
|
| + GetIOContext())));
|
| + session->AddHandler(base::WrapUnique(new protocol::NetworkHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::SchemaHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::ServiceWorkerHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::StorageHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::TargetHandler()));
|
| + session->AddHandler(base::WrapUnique(new protocol::TracingHandler(
|
| protocol::TracingHandler::Renderer,
|
| frame_tree_node_->frame_tree_node_id(),
|
| - GetIOContext()));
|
| - tracing_handler_->Wire(session()->dispatcher());
|
| + GetIOContext())));
|
|
|
| if (current_)
|
| - current_->Attach();
|
| + current_->Attach(session);
|
| if (pending_)
|
| - pending_->Attach();
|
| + pending_->Attach(session);
|
| OnClientAttached();
|
| }
|
|
|
| -void RenderFrameDevToolsAgentHost::Detach() {
|
| - dom_handler_->Disable();
|
| - dom_handler_.reset();
|
| - if (emulation_handler_) {
|
| - emulation_handler_->Disable();
|
| - emulation_handler_.reset();
|
| - }
|
| - input_handler_->Disable();
|
| - input_handler_.reset();
|
| - inspector_handler_->Disable();
|
| - inspector_handler_.reset();
|
| - io_handler_->Disable();
|
| - io_handler_.reset();
|
| - network_handler_->Disable();
|
| - network_handler_.reset();
|
| - if (page_handler_) {
|
| - page_handler_->Disable();
|
| - page_handler_.reset();
|
| - }
|
| - schema_handler_->Disable();
|
| - schema_handler_.reset();
|
| - if (security_handler_) {
|
| - security_handler_->Disable();
|
| - security_handler_.reset();
|
| - }
|
| - service_worker_handler_->Disable();
|
| - service_worker_handler_.reset();
|
| - storage_handler_->Disable();
|
| - storage_handler_.reset();
|
| - target_handler_->Disable();
|
| - target_handler_.reset();
|
| - tracing_handler_->Disable();
|
| - tracing_handler_.reset();
|
| -
|
| +void RenderFrameDevToolsAgentHost::DetachSession(int session_id) {
|
| if (current_)
|
| - current_->Detach();
|
| + current_->Detach(session_id);
|
| if (pending_)
|
| - pending_->Detach();
|
| + pending_->Detach(session_id);
|
| OnClientDetached();
|
| }
|
|
|
| bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage(
|
| + DevToolsSession* session,
|
| const std::string& message) {
|
| int call_id = 0;
|
| std::string method;
|
| - if (session()->Dispatch(message, &call_id, &method) !=
|
| + if (session->Dispatch(message, true, &call_id, &method) !=
|
| protocol::Response::kFallThrough) {
|
| return true;
|
| }
|
| @@ -604,26 +541,29 @@ bool RenderFrameDevToolsAgentHost::DispatchProtocolMessage(
|
| if (!navigating_handles_.empty()) {
|
| DCHECK(IsBrowserSideNavigationEnabled());
|
| in_navigation_protocol_message_buffer_[call_id] =
|
| - { session()->session_id(), method, message };
|
| + { session->session_id(), method, message };
|
| return true;
|
| }
|
|
|
| if (current_) {
|
| current_->DispatchProtocolMessage(
|
| - session()->session_id(), call_id, method, message);
|
| + session->session_id(), call_id, method, message);
|
| }
|
| if (pending_) {
|
| pending_->DispatchProtocolMessage(
|
| - session()->session_id(), call_id, method, message);
|
| + session->session_id(), call_id, method, message);
|
| }
|
| return true;
|
| }
|
|
|
| -void RenderFrameDevToolsAgentHost::InspectElement(int x, int y) {
|
| +void RenderFrameDevToolsAgentHost::InspectElement(
|
| + DevToolsSession* session,
|
| + int x,
|
| + int y) {
|
| if (current_)
|
| - current_->InspectElement(session()->session_id(), x, y);
|
| + current_->InspectElement(session->session_id(), x, y);
|
| if (pending_)
|
| - pending_->InspectElement(session()->session_id(), x, y);
|
| + pending_->InspectElement(session->session_id(), x, y);
|
| }
|
|
|
| void RenderFrameDevToolsAgentHost::OnClientAttached() {
|
| @@ -713,8 +653,8 @@ void RenderFrameDevToolsAgentHost::DidFinishNavigation(
|
| DispatchBufferedProtocolMessagesIfNecessary();
|
|
|
| DCHECK(CheckConsistency());
|
| - if (target_handler_ && navigation_handle->HasCommitted())
|
| - target_handler_->UpdateServiceWorkers();
|
| + if (session() && navigation_handle->HasCommitted())
|
| + protocol::TargetHandler::FromSession(session())->UpdateServiceWorkers();
|
| }
|
|
|
| void RenderFrameDevToolsAgentHost::AboutToNavigateRenderFrame(
|
| @@ -760,8 +700,8 @@ void RenderFrameDevToolsAgentHost::RenderFrameHostChanged(
|
| // CommitPending may destruct |this|.
|
| scoped_refptr<RenderFrameDevToolsAgentHost> protect(this);
|
|
|
| - if (target_handler_)
|
| - target_handler_->UpdateFrames();
|
| + if (session())
|
| + protocol::TargetHandler::FromSession(session())->UpdateFrames();
|
|
|
| if (IsBrowserSideNavigationEnabled())
|
| return;
|
| @@ -805,7 +745,7 @@ void RenderFrameDevToolsAgentHost::DestroyOnRenderFrameGone() {
|
| UpdateProtocolHandlers(nullptr);
|
| if (IsAttached())
|
| OnClientDetached();
|
| - HostClosed();
|
| + ForceDetach(false);
|
| pending_.reset();
|
| current_.reset();
|
| frame_tree_node_ = nullptr;
|
| @@ -853,13 +793,15 @@ void RenderFrameDevToolsAgentHost::RenderProcessGone(
|
| case base::TERMINATION_STATUS_OOM_PROTECTED:
|
| #endif
|
| case base::TERMINATION_STATUS_LAUNCH_FAILED:
|
| - if (inspector_handler_)
|
| - inspector_handler_->TargetCrashed();
|
| + if (session())
|
| + protocol::InspectorHandler::FromSession(session())->TargetCrashed();
|
| current_frame_crashed_ = true;
|
| break;
|
| default:
|
| - if (inspector_handler_)
|
| - inspector_handler_->TargetDetached("Render process gone.");
|
| + if (session()) {
|
| + protocol::InspectorHandler::FromSession(session())
|
| + ->TargetDetached("Render process gone.");
|
| + }
|
| break;
|
| }
|
| DCHECK(CheckConsistency());
|
| @@ -896,8 +838,10 @@ bool RenderFrameDevToolsAgentHost::OnMessageReceived(
|
| }
|
|
|
| void RenderFrameDevToolsAgentHost::DidAttachInterstitialPage() {
|
| - if (page_handler_)
|
| - page_handler_->DidAttachInterstitialPage();
|
| + protocol::PageHandler* page_handler =
|
| + session() ? protocol::PageHandler::FromSession(session()) : nullptr;
|
| + if (page_handler)
|
| + page_handler->DidAttachInterstitialPage();
|
|
|
| // TODO(dgozman): this may break for cross-process subframes.
|
| if (!pending_) {
|
| @@ -912,8 +856,10 @@ void RenderFrameDevToolsAgentHost::DidAttachInterstitialPage() {
|
| }
|
|
|
| void RenderFrameDevToolsAgentHost::DidDetachInterstitialPage() {
|
| - if (page_handler_)
|
| - page_handler_->DidDetachInterstitialPage();
|
| + protocol::PageHandler* page_handler =
|
| + session() ? protocol::PageHandler::FromSession(session()) : nullptr;
|
| + if (page_handler)
|
| + page_handler->DidDetachInterstitialPage();
|
| }
|
|
|
| void RenderFrameDevToolsAgentHost::DidCommitProvisionalLoadForFrame(
|
| @@ -928,8 +874,8 @@ void RenderFrameDevToolsAgentHost::DidCommitProvisionalLoadForFrame(
|
| if (pending_ && pending_->host() == render_frame_host)
|
| CommitPending();
|
| DCHECK(CheckConsistency());
|
| - if (target_handler_)
|
| - target_handler_->UpdateServiceWorkers();
|
| + if (session())
|
| + protocol::TargetHandler::FromSession(session())->UpdateServiceWorkers();
|
| }
|
|
|
| void RenderFrameDevToolsAgentHost::DidFailProvisionalLoad(
|
| @@ -978,26 +924,8 @@ void RenderFrameDevToolsAgentHost::UpdateProtocolHandlers(
|
| handlers_frame_host_->GetRenderWidgetHost()->GetRoutingID();
|
| #endif
|
| handlers_frame_host_ = host;
|
| - if (dom_handler_)
|
| - dom_handler_->SetRenderFrameHost(host);
|
| - if (emulation_handler_)
|
| - emulation_handler_->SetRenderFrameHost(host);
|
| - if (input_handler_)
|
| - input_handler_->SetRenderFrameHost(host);
|
| - if (inspector_handler_)
|
| - inspector_handler_->SetRenderFrameHost(host);
|
| - if (network_handler_)
|
| - network_handler_->SetRenderFrameHost(host);
|
| - if (page_handler_)
|
| - page_handler_->SetRenderFrameHost(host);
|
| - if (service_worker_handler_)
|
| - service_worker_handler_->SetRenderFrameHost(host);
|
| - if (security_handler_)
|
| - security_handler_->SetRenderFrameHost(host);
|
| - if (storage_handler_)
|
| - storage_handler_->SetRenderFrameHost(host);
|
| - if (target_handler_)
|
| - target_handler_->SetRenderFrameHost(host);
|
| + if (session())
|
| + session()->SetRenderFrameHost(host);
|
| }
|
|
|
| void RenderFrameDevToolsAgentHost::DisconnectWebContents() {
|
| @@ -1005,7 +933,8 @@ void RenderFrameDevToolsAgentHost::DisconnectWebContents() {
|
| DiscardPending();
|
| UpdateProtocolHandlers(nullptr);
|
| disconnected_ = std::move(current_);
|
| - disconnected_->Detach();
|
| + if (session())
|
| + disconnected_->Detach(session()->session_id());
|
| frame_tree_node_ = nullptr;
|
| in_navigation_protocol_message_buffer_.clear();
|
| navigating_handles_.clear();
|
| @@ -1135,13 +1064,19 @@ void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame(
|
| ViewHostMsg_SwapCompositorFrame::Param param;
|
| if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m))
|
| return;
|
| - if (page_handler_) {
|
| - page_handler_->OnSwapCompositorFrame(
|
| + if (!session())
|
| + return;
|
| + protocol::PageHandler* page_handler =
|
| + protocol::PageHandler::FromSession(session());
|
| + if (page_handler) {
|
| + page_handler->OnSwapCompositorFrame(
|
| std::move(std::get<1>(param).metadata));
|
| }
|
| - if (input_handler_)
|
| - input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata);
|
| - if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) {
|
| + protocol::InputHandler::FromSession(session())
|
| + ->OnSwapCompositorFrame(std::get<1>(param).metadata);
|
| + protocol::TracingHandler* tracing_handler =
|
| + protocol::TracingHandler::FromSession(session());
|
| + if (frame_trace_recorder_ && tracing_handler->did_initiate_recording()) {
|
| frame_trace_recorder_->OnSwapCompositorFrame(
|
| current_ ? current_->host() : nullptr, std::get<1>(param).metadata);
|
| }
|
| @@ -1164,11 +1099,17 @@ void RenderFrameDevToolsAgentHost::SignalSynchronousSwapCompositorFrame(
|
|
|
| void RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame(
|
| cc::CompositorFrameMetadata frame_metadata) {
|
| - if (page_handler_)
|
| - page_handler_->OnSynchronousSwapCompositorFrame(std::move(frame_metadata));
|
| - if (input_handler_)
|
| - input_handler_->OnSwapCompositorFrame(frame_metadata);
|
| - if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) {
|
| + if (!session())
|
| + return;
|
| + protocol::PageHandler* page_handler =
|
| + protocol::PageHandler::FromSession(session());
|
| + if (page_handler)
|
| + page_handler->OnSynchronousSwapCompositorFrame(std::move(frame_metadata));
|
| + protocol::InputHandler::FromSession(session())
|
| + ->OnSwapCompositorFrame(frame_metadata);
|
| + protocol::TracingHandler* tracing_handler =
|
| + protocol::TracingHandler::FromSession(session());
|
| + if (frame_trace_recorder_ && tracing_handler->did_initiate_recording()) {
|
| frame_trace_recorder_->OnSynchronousSwapCompositorFrame(
|
| current_ ? current_->host() : nullptr,
|
| frame_metadata);
|
|
|