Commit f2d4ff7a authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

Extract instrumentation methods from RenderFrameDevToolsAgentHost into devtools_instrumentation

Bug: 899303
Change-Id: If13f08e4e45e4f4f4cfc16bd4f2921cab22ecc07
Reviewed-on: https://chromium-review.googlesource.com/c/1303181
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603598}
parent 5ea9871e
...@@ -623,6 +623,8 @@ jumbo_source_set("browser") { ...@@ -623,6 +623,8 @@ jumbo_source_set("browser") {
"devtools/devtools_frame_trace_recorder.h", "devtools/devtools_frame_trace_recorder.h",
"devtools/devtools_http_handler.cc", "devtools/devtools_http_handler.cc",
"devtools/devtools_http_handler.h", "devtools/devtools_http_handler.h",
"devtools/devtools_instrumentation.cc",
"devtools/devtools_instrumentation.h",
"devtools/devtools_interceptor_controller.cc", "devtools/devtools_interceptor_controller.cc",
"devtools/devtools_interceptor_controller.h", "devtools/devtools_interceptor_controller.h",
"devtools/devtools_io_context.cc", "devtools/devtools_io_context.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/devtools/protocol/emulation_handler.h"
#include "content/browser/devtools/protocol/network_handler.h"
#include "content/browser/devtools/protocol/page_handler.h"
#include "content/browser/devtools/protocol/target_handler.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/navigation_handle_impl.h"
#include "content/browser/frame_host/navigation_request.h"
#include "content/browser/web_package/signed_exchange_envelope.h"
#include "content/common/navigation_params.mojom.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
#include "net/ssl/ssl_info.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
namespace content {
namespace devtools_instrumentation {
namespace {
template <typename Handler, typename... MethodArgs, typename... Args>
void DispatchToAgents(FrameTreeNode* frame_tree_node,
void (Handler::*method)(MethodArgs...),
Args&&... args) {
DevToolsAgentHostImpl* agent_host =
RenderFrameDevToolsAgentHost::GetFor(frame_tree_node);
if (!agent_host)
return;
for (auto* h : Handler::ForAgentHost(agent_host))
(h->*method)(std::forward<Args>(args)...);
}
template <typename Handler, typename... MethodArgs, typename... Args>
void DispatchToAgents(int frame_tree_node_id,
void (Handler::*method)(MethodArgs...),
Args&&... args) {
FrameTreeNode* ftn = FrameTreeNode::GloballyFindByID(frame_tree_node_id);
if (ftn)
DispatchToAgents(ftn, method, std::forward<Args>(args)...);
}
} // namespace
void OnResetNavigationRequest(NavigationRequest* navigation_request) {
// Traverse frame chain all the way to the top and report to all
// page handlers that the navigation completed.
for (FrameTreeNode* node = navigation_request->frame_tree_node(); node;
node = node->parent()) {
DispatchToAgents(node, &protocol::PageHandler::NavigationReset,
navigation_request);
}
}
void OnNavigationResponseReceived(const NavigationRequest& nav_request,
const network::ResourceResponse& response) {
FrameTreeNode* ftn = nav_request.frame_tree_node();
std::string id = nav_request.devtools_navigation_token().ToString();
std::string frame_id = ftn->devtools_frame_token().ToString();
GURL url = nav_request.common_params().url;
DispatchToAgents(ftn, &protocol::NetworkHandler::ResponseReceived, id, id,
url, protocol::Network::ResourceTypeEnum::Document,
response.head, frame_id);
}
void OnNavigationRequestFailed(
const NavigationRequest& nav_request,
const network::URLLoaderCompletionStatus& status) {
FrameTreeNode* ftn = nav_request.frame_tree_node();
std::string id = nav_request.devtools_navigation_token().ToString();
DispatchToAgents(ftn, &protocol::NetworkHandler::LoadingComplete, id,
protocol::Network::ResourceTypeEnum::Document, status);
}
void OnSignedExchangeReceived(
FrameTreeNode* frame_tree_node,
base::Optional<const base::UnguessableToken> devtools_navigation_token,
const GURL& outer_request_url,
const network::ResourceResponseHead& outer_response,
const base::Optional<SignedExchangeEnvelope>& envelope,
const scoped_refptr<net::X509Certificate>& certificate,
const base::Optional<net::SSLInfo>& ssl_info,
const std::vector<SignedExchangeError>& errors) {
DispatchToAgents(frame_tree_node,
&protocol::NetworkHandler::OnSignedExchangeReceived,
devtools_navigation_token, outer_request_url, outer_response,
envelope, certificate, ssl_info, errors);
}
void OnSignedExchangeCertificateRequestSent(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const base::UnguessableToken& loader_id,
const network::ResourceRequest& request,
const GURL& signed_exchange_url) {
DispatchToAgents(frame_tree_node, &protocol::NetworkHandler::RequestSent,
request_id.ToString(), loader_id.ToString(), request,
protocol::Network::Initiator::TypeEnum::SignedExchange,
signed_exchange_url);
}
void OnSignedExchangeCertificateResponseReceived(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const base::UnguessableToken& loader_id,
const GURL& url,
const network::ResourceResponseHead& head) {
DispatchToAgents(frame_tree_node, &protocol::NetworkHandler::ResponseReceived,
request_id.ToString(), loader_id.ToString(), url,
protocol::Network::ResourceTypeEnum::Other, head,
protocol::Maybe<std::string>());
}
void OnSignedExchangeCertificateRequestCompleted(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const network::URLLoaderCompletionStatus& status) {
DispatchToAgents(frame_tree_node, &protocol::NetworkHandler::LoadingComplete,
request_id.ToString(),
protocol::Network::ResourceTypeEnum::Other, status);
}
std::vector<std::unique_ptr<NavigationThrottle>> CreateNavigationThrottles(
NavigationHandleImpl* navigation_handle) {
std::vector<std::unique_ptr<NavigationThrottle>> result;
FrameTreeNode* frame_tree_node = navigation_handle->frame_tree_node();
DevToolsAgentHostImpl* agent_host =
RenderFrameDevToolsAgentHost::GetFor(frame_tree_node);
if (agent_host) {
// Interception might throttle navigations in inspected frames.
for (auto* network_handler :
protocol::NetworkHandler::ForAgentHost(agent_host)) {
std::unique_ptr<NavigationThrottle> throttle =
network_handler->CreateThrottleForNavigation(navigation_handle);
if (throttle)
result.push_back(std::move(throttle));
}
}
if (!frame_tree_node->parent())
return result;
agent_host = RenderFrameDevToolsAgentHost::GetFor(frame_tree_node->parent());
if (agent_host) {
for (auto* target_handler :
protocol::TargetHandler::ForAgentHost(agent_host)) {
std::unique_ptr<NavigationThrottle> throttle =
target_handler->CreateThrottleForNavigation(navigation_handle);
if (throttle)
result.push_back(std::move(throttle));
}
}
return result;
}
void ApplyNetworkRequestOverrides(FrameTreeNode* frame_tree_node,
mojom::BeginNavigationParams* begin_params,
bool* report_raw_headers) {
bool disable_cache = false;
DevToolsAgentHostImpl* agent_host =
RenderFrameDevToolsAgentHost::GetFor(frame_tree_node);
if (!agent_host)
return;
net::HttpRequestHeaders headers;
headers.AddHeadersFromString(begin_params->headers);
for (auto* network : protocol::NetworkHandler::ForAgentHost(agent_host)) {
if (!network->enabled())
continue;
*report_raw_headers = true;
network->ApplyOverrides(&headers, &begin_params->skip_service_worker,
&disable_cache);
}
for (auto* emulation : protocol::EmulationHandler::ForAgentHost(agent_host))
emulation->ApplyOverrides(&headers);
if (disable_cache) {
begin_params->load_flags &=
~(net::LOAD_VALIDATE_CACHE | net::LOAD_SKIP_CACHE_VALIDATION |
net::LOAD_ONLY_FROM_CACHE | net::LOAD_DISABLE_CACHE);
begin_params->load_flags |= net::LOAD_BYPASS_CACHE;
}
begin_params->headers = headers.ToString();
}
bool WillCreateURLLoaderFactory(
RenderFrameHostImpl* rfh,
bool is_navigation,
bool is_download,
network::mojom::URLLoaderFactoryRequest* target_factory_request) {
DevToolsAgentHostImpl* agent_host =
RenderFrameDevToolsAgentHost::GetFor(rfh->frame_tree_node());
if (!agent_host)
return false;
DCHECK(!is_download || is_navigation);
bool had_interceptors = false;
const auto& network_handlers =
protocol::NetworkHandler::ForAgentHost(agent_host);
for (auto it = network_handlers.rbegin(); it != network_handlers.rend();
++it) {
had_interceptors =
(*it)->MaybeCreateProxyForInterception(rfh, is_navigation, is_download,
target_factory_request) ||
had_interceptors;
}
return had_interceptors;
}
void OnNavigationRequestWillBeSent(
const NavigationRequest& navigation_request) {
DispatchToAgents(navigation_request.frame_tree_node(),
&protocol::NetworkHandler::NavigationRequestWillBeSent,
navigation_request);
}
} // namespace devtools_instrumentation
} // namespace content
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_INSTRUMENTATION_H_
#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_INSTRUMENTATION_H_
/*
The functions in this file are for routing instrumentation signals
to the relevant set of devtools protocol handlers.
*/
#include <vector>
#include "base/optional.h"
#include "content/common/navigation_params.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
class GURL;
namespace base {
class UnguessableToken;
}
namespace net {
class SSLInfo;
class X509Certificate;
} // namespace net
namespace network {
struct ResourceResponse;
}
namespace content {
class SignedExchangeEnvelope;
class FrameTreeNode;
class NavigationHandleImpl;
class NavigationRequest;
class NavigationThrottle;
class RenderFrameHostImpl;
struct SignedExchangeError;
namespace devtools_instrumentation {
void ApplyNetworkRequestOverrides(FrameTreeNode* frame_tree_node,
mojom::BeginNavigationParams* begin_params,
bool* report_raw_headers);
bool WillCreateURLLoaderFactory(
RenderFrameHostImpl* rfh,
bool is_navigation,
bool is_download,
network::mojom::URLLoaderFactoryRequest* loader_factory_request);
void OnResetNavigationRequest(NavigationRequest* navigation_request);
void OnNavigationRequestWillBeSent(const NavigationRequest& navigation_request);
void OnNavigationResponseReceived(const NavigationRequest& nav_request,
const network::ResourceResponse& response);
void OnNavigationRequestFailed(
const NavigationRequest& nav_request,
const network::URLLoaderCompletionStatus& status);
void OnSignedExchangeReceived(
FrameTreeNode* frame_tree_node,
base::Optional<const base::UnguessableToken> devtools_navigation_token,
const GURL& outer_request_url,
const network::ResourceResponseHead& outer_response,
const base::Optional<SignedExchangeEnvelope>& header,
const scoped_refptr<net::X509Certificate>& certificate,
const base::Optional<net::SSLInfo>& ssl_info,
const std::vector<SignedExchangeError>& errors);
void OnSignedExchangeCertificateRequestSent(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const base::UnguessableToken& loader_id,
const network::ResourceRequest& request,
const GURL& signed_exchange_url);
void OnSignedExchangeCertificateResponseReceived(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const base::UnguessableToken& loader_id,
const GURL& url,
const network::ResourceResponseHead& head);
void OnSignedExchangeCertificateRequestCompleted(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const network::URLLoaderCompletionStatus& status);
std::vector<std::unique_ptr<NavigationThrottle>> CreateNavigationThrottles(
NavigationHandleImpl* navigation_handle);
} // namespace devtools_instrumentation
} // namespace content
#endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_INSTRUMENTATION_H_
...@@ -54,9 +54,6 @@ ...@@ -54,9 +54,6 @@
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/browser_side_navigation_policy.h" #include "content/public/common/browser_side_navigation_policy.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
#include "net/ssl/ssl_info.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/web/devtools_agent.mojom.h" #include "third_party/blink/public/web/devtools_agent.mojom.h"
...@@ -99,27 +96,6 @@ FrameTreeNode* GetFrameTreeNodeAncestor(FrameTreeNode* frame_tree_node) { ...@@ -99,27 +96,6 @@ FrameTreeNode* GetFrameTreeNodeAncestor(FrameTreeNode* frame_tree_node) {
} // namespace } // namespace
template <typename Handler, typename... MethodArgs, typename... Args>
void DispatchToAgents(FrameTreeNode* frame_tree_node,
void (Handler::*method)(MethodArgs...),
Args&&... args) {
RenderFrameDevToolsAgentHost* agent_host =
FindAgentHost(GetFrameTreeNodeAncestor(frame_tree_node));
if (!agent_host)
return;
for (auto* h : Handler::ForAgentHost(agent_host))
(h->*method)(std::forward<Args>(args)...);
}
template <typename Handler, typename... MethodArgs, typename... Args>
void DispatchToAgents(int frame_tree_node_id,
void (Handler::*method)(MethodArgs...),
Args&&... args) {
FrameTreeNode* ftn = FrameTreeNode::GloballyFindByID(frame_tree_node_id);
if (ftn)
DispatchToAgents(ftn, method, std::forward<Args>(args)...);
}
// static // static
scoped_refptr<DevToolsAgentHost> scoped_refptr<DevToolsAgentHost>
DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) {
...@@ -133,6 +109,12 @@ DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { ...@@ -133,6 +109,12 @@ DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) {
} }
// static // static
DevToolsAgentHostImpl* RenderFrameDevToolsAgentHost::GetFor(
FrameTreeNode* frame_tree_node) {
frame_tree_node = GetFrameTreeNodeAncestor(frame_tree_node);
return FindAgentHost(frame_tree_node);
}
scoped_refptr<DevToolsAgentHost> RenderFrameDevToolsAgentHost::GetOrCreateFor( scoped_refptr<DevToolsAgentHost> RenderFrameDevToolsAgentHost::GetOrCreateFor(
FrameTreeNode* frame_tree_node) { FrameTreeNode* frame_tree_node) {
frame_tree_node = GetFrameTreeNodeAncestor(frame_tree_node); frame_tree_node = GetFrameTreeNodeAncestor(frame_tree_node);
...@@ -192,199 +174,6 @@ void RenderFrameDevToolsAgentHost::AddAllAgentHosts( ...@@ -192,199 +174,6 @@ void RenderFrameDevToolsAgentHost::AddAllAgentHosts(
} }
} }
// static
void RenderFrameDevToolsAgentHost::OnResetNavigationRequest(
NavigationRequest* navigation_request) {
// Traverse frame chain all the way to the top and report to all
// page handlers that the navigation completed.
for (FrameTreeNode* node = navigation_request->frame_tree_node(); node;
node = node->parent()) {
DispatchToAgents(node, &protocol::PageHandler::NavigationReset,
navigation_request);
}
}
// static
void RenderFrameDevToolsAgentHost::OnNavigationResponseReceived(
const NavigationRequest& nav_request,
const network::ResourceResponse& response) {
FrameTreeNode* ftn = nav_request.frame_tree_node();
std::string id = nav_request.devtools_navigation_token().ToString();
std::string frame_id = ftn->devtools_frame_token().ToString();
GURL url = nav_request.common_params().url;
DispatchToAgents(ftn, &protocol::NetworkHandler::ResponseReceived, id, id,
url, protocol::Network::ResourceTypeEnum::Document,
response.head, frame_id);
}
// static
void RenderFrameDevToolsAgentHost::OnNavigationRequestFailed(
const NavigationRequest& nav_request,
const network::URLLoaderCompletionStatus& status) {
FrameTreeNode* ftn = nav_request.frame_tree_node();
std::string id = nav_request.devtools_navigation_token().ToString();
DispatchToAgents(ftn, &protocol::NetworkHandler::LoadingComplete, id,
protocol::Network::ResourceTypeEnum::Document, status);
}
// static
void RenderFrameDevToolsAgentHost::OnSignedExchangeReceived(
FrameTreeNode* frame_tree_node,
base::Optional<const base::UnguessableToken> devtools_navigation_token,
const GURL& outer_request_url,
const network::ResourceResponseHead& outer_response,
const base::Optional<SignedExchangeEnvelope>& envelope,
const scoped_refptr<net::X509Certificate>& certificate,
const base::Optional<net::SSLInfo>& ssl_info,
const std::vector<SignedExchangeError>& errors) {
DispatchToAgents(frame_tree_node,
&protocol::NetworkHandler::OnSignedExchangeReceived,
devtools_navigation_token, outer_request_url, outer_response,
envelope, certificate, ssl_info, errors);
}
// static
void RenderFrameDevToolsAgentHost::OnSignedExchangeCertificateRequestSent(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const base::UnguessableToken& loader_id,
const network::ResourceRequest& request,
const GURL& signed_exchange_url) {
DispatchToAgents(frame_tree_node, &protocol::NetworkHandler::RequestSent,
request_id.ToString(), loader_id.ToString(), request,
protocol::Network::Initiator::TypeEnum::SignedExchange,
signed_exchange_url);
}
// static
void RenderFrameDevToolsAgentHost::OnSignedExchangeCertificateResponseReceived(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const base::UnguessableToken& loader_id,
const GURL& url,
const network::ResourceResponseHead& head) {
DispatchToAgents(frame_tree_node, &protocol::NetworkHandler::ResponseReceived,
request_id.ToString(), loader_id.ToString(), url,
protocol::Network::ResourceTypeEnum::Other, head,
protocol::Maybe<std::string>());
}
// static
void RenderFrameDevToolsAgentHost::OnSignedExchangeCertificateRequestCompleted(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const network::URLLoaderCompletionStatus& status) {
DispatchToAgents(frame_tree_node, &protocol::NetworkHandler::LoadingComplete,
request_id.ToString(),
protocol::Network::ResourceTypeEnum::Other, status);
}
// static
std::vector<std::unique_ptr<NavigationThrottle>>
RenderFrameDevToolsAgentHost::CreateNavigationThrottles(
NavigationHandleImpl* navigation_handle) {
std::vector<std::unique_ptr<NavigationThrottle>> result;
FrameTreeNode* frame_tree_node = navigation_handle->frame_tree_node();
// Interception might throttle navigations in inspected frames.
RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node);
if (agent_host) {
for (auto* network_handler :
protocol::NetworkHandler::ForAgentHost(agent_host)) {
std::unique_ptr<NavigationThrottle> throttle =
network_handler->CreateThrottleForNavigation(navigation_handle);
if (throttle)
result.push_back(std::move(throttle));
}
}
agent_host = nullptr;
if (frame_tree_node->parent()) {
// Target domain of the parent frame's DevTools may want to pause
// this frame to do some setup.
agent_host =
FindAgentHost(GetFrameTreeNodeAncestor(frame_tree_node->parent()));
}
if (agent_host) {
for (auto* target_handler :
protocol::TargetHandler::ForAgentHost(agent_host)) {
std::unique_ptr<NavigationThrottle> throttle =
target_handler->CreateThrottleForNavigation(navigation_handle);
if (throttle)
result.push_back(std::move(throttle));
}
}
return result;
}
// static
void RenderFrameDevToolsAgentHost::ApplyOverrides(
FrameTreeNode* frame_tree_node,
mojom::BeginNavigationParams* begin_params,
bool* report_raw_headers) {
bool disable_cache = false;
frame_tree_node = GetFrameTreeNodeAncestor(frame_tree_node);
RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node);
if (!agent_host)
return;
net::HttpRequestHeaders headers;
headers.AddHeadersFromString(begin_params->headers);
for (auto* network : protocol::NetworkHandler::ForAgentHost(agent_host)) {
// TODO(caseq): consider chaining intercepting proxies from multiple agents.
if (!network->enabled())
continue;
*report_raw_headers = true;
network->ApplyOverrides(&headers, &begin_params->skip_service_worker,
&disable_cache);
}
for (auto* emulation : protocol::EmulationHandler::ForAgentHost(agent_host))
emulation->ApplyOverrides(&headers);
if (disable_cache) {
begin_params->load_flags &=
~(net::LOAD_VALIDATE_CACHE | net::LOAD_SKIP_CACHE_VALIDATION |
net::LOAD_ONLY_FROM_CACHE | net::LOAD_DISABLE_CACHE);
begin_params->load_flags |= net::LOAD_BYPASS_CACHE;
}
begin_params->headers = headers.ToString();
}
// static
bool RenderFrameDevToolsAgentHost::WillCreateURLLoaderFactory(
RenderFrameHostImpl* rfh,
bool is_navigation,
bool is_download,
network::mojom::URLLoaderFactoryRequest* target_factory_request) {
FrameTreeNode* frame_tree_node = rfh->frame_tree_node();
frame_tree_node = GetFrameTreeNodeAncestor(frame_tree_node);
RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node);
if (!agent_host)
return false;
DCHECK(!is_download || is_navigation);
bool had_interceptors = false;
const auto& network_handlers =
protocol::NetworkHandler::ForAgentHost(agent_host);
for (auto it = network_handlers.rbegin(); it != network_handlers.rend();
++it) {
had_interceptors =
(*it)->MaybeCreateProxyForInterception(rfh, is_navigation, is_download,
target_factory_request) ||
had_interceptors;
}
return had_interceptors;
}
// static
void RenderFrameDevToolsAgentHost::OnNavigationRequestWillBeSent(
const NavigationRequest& navigation_request) {
DispatchToAgents(navigation_request.frame_tree_node(),
&protocol::NetworkHandler::NavigationRequestWillBeSent,
navigation_request);
}
// static // static
void RenderFrameDevToolsAgentHost::WebContentsCreated( void RenderFrameDevToolsAgentHost::WebContentsCreated(
WebContents* web_contents) { WebContents* web_contents) {
......
...@@ -27,40 +27,28 @@ ...@@ -27,40 +27,28 @@
#include "ui/android/view_android.h" #include "ui/android/view_android.h"
#endif // OS_ANDROID #endif // OS_ANDROID
namespace base {
class UnguessableToken;
}
namespace network {
struct ResourceResponse;
}
namespace viz { namespace viz {
class CompositorFrameMetadata; class CompositorFrameMetadata;
} }
namespace net {
class SSLInfo;
class X509Certificate;
}
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class DevToolsFrameTraceRecorder; class DevToolsFrameTraceRecorder;
class FrameTreeNode; class FrameTreeNode;
class NavigationHandleImpl; class NavigationHandleImpl;
class NavigationRequest;
class NavigationThrottle;
class RenderFrameHostImpl; class RenderFrameHostImpl;
class SignedExchangeEnvelope;
struct SignedExchangeError;
class CONTENT_EXPORT RenderFrameDevToolsAgentHost class CONTENT_EXPORT RenderFrameDevToolsAgentHost
: public DevToolsAgentHostImpl, : public DevToolsAgentHostImpl,
private WebContentsObserver { private WebContentsObserver {
public: public:
static void AddAllAgentHosts(DevToolsAgentHost::List* result); static void AddAllAgentHosts(DevToolsAgentHost::List* result);
// Returns appropriate agent host for given frame tree node, traversing
// up to local root as needed.
static DevToolsAgentHostImpl* GetFor(FrameTreeNode* frame_tree_node);
// Similar to GetFor(), but creates a host if it doesn't exist yet.
static scoped_refptr<DevToolsAgentHost> GetOrCreateFor( static scoped_refptr<DevToolsAgentHost> GetOrCreateFor(
FrameTreeNode* frame_tree_node); FrameTreeNode* frame_tree_node);
...@@ -72,60 +60,6 @@ class CONTENT_EXPORT RenderFrameDevToolsAgentHost ...@@ -72,60 +60,6 @@ class CONTENT_EXPORT RenderFrameDevToolsAgentHost
static scoped_refptr<DevToolsAgentHost> FindForDangling( static scoped_refptr<DevToolsAgentHost> FindForDangling(
FrameTreeNode* frame_tree_node); FrameTreeNode* frame_tree_node);
static void OnWillSendNavigationRequest(
FrameTreeNode* frame_tree_node,
mojom::BeginNavigationParams* begin_params,
bool* report_raw_headers);
static void OnResetNavigationRequest(NavigationRequest* navigation_request);
static void ApplyOverrides(FrameTreeNode* frame_tree_node,
mojom::BeginNavigationParams* begin_params,
bool* report_raw_headers);
static bool WillCreateURLLoaderFactory(
RenderFrameHostImpl* rfh,
bool is_navigation,
bool is_download,
network::mojom::URLLoaderFactoryRequest* loader_factory_request);
static void OnNavigationRequestWillBeSent(
const NavigationRequest& navigation_request);
static void OnNavigationResponseReceived(
const NavigationRequest& nav_request,
const network::ResourceResponse& response);
static void OnNavigationRequestFailed(
const NavigationRequest& nav_request,
const network::URLLoaderCompletionStatus& status);
static void OnSignedExchangeReceived(
FrameTreeNode* frame_tree_node,
base::Optional<const base::UnguessableToken> devtools_navigation_token,
const GURL& outer_request_url,
const network::ResourceResponseHead& outer_response,
const base::Optional<SignedExchangeEnvelope>& header,
const scoped_refptr<net::X509Certificate>& certificate,
const base::Optional<net::SSLInfo>& ssl_info,
const std::vector<SignedExchangeError>& errors);
static void OnSignedExchangeCertificateRequestSent(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const base::UnguessableToken& loader_id,
const network::ResourceRequest& request,
const GURL& signed_exchange_url);
static void OnSignedExchangeCertificateResponseReceived(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const base::UnguessableToken& loader_id,
const GURL& url,
const network::ResourceResponseHead& head);
static void OnSignedExchangeCertificateRequestCompleted(
FrameTreeNode* frame_tree_node,
const base::UnguessableToken& request_id,
const network::URLLoaderCompletionStatus& status);
static std::vector<std::unique_ptr<NavigationThrottle>>
CreateNavigationThrottles(NavigationHandleImpl* navigation_handle);
static bool IsNetworkHandlerEnabled(FrameTreeNode* frame_tree_node);
static void WebContentsCreated(WebContents* web_contents); static void WebContentsCreated(WebContents* web_contents);
static void SignalSynchronousSwapCompositorFrame( static void SignalSynchronousSwapCompositorFrame(
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include "components/download/public/common/url_download_handler_factory.h" #include "components/download/public/common/url_download_handler_factory.h"
#include "content/browser/byte_stream.h" #include "content/browser/byte_stream.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h" #include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/download/byte_stream_input_stream.h" #include "content/browser/download/byte_stream_input_stream.h"
#include "content/browser/download/download_resource_handler.h" #include "content/browser/download/download_resource_handler.h"
#include "content/browser/download/download_utils.h" #include "content/browser/download/download_utils.h"
...@@ -279,7 +279,7 @@ CreateDownloadURLLoaderFactoryGetter(StoragePartitionImpl* storage_partition, ...@@ -279,7 +279,7 @@ CreateDownloadURLLoaderFactoryGetter(StoragePartitionImpl* storage_partition,
network::mojom::URLLoaderFactoryPtrInfo devtools_factory_ptr_info; network::mojom::URLLoaderFactoryPtrInfo devtools_factory_ptr_info;
network::mojom::URLLoaderFactoryRequest devtools_factory_request = network::mojom::URLLoaderFactoryRequest devtools_factory_request =
MakeRequest(&devtools_factory_ptr_info); MakeRequest(&devtools_factory_ptr_info);
if (RenderFrameDevToolsAgentHost::WillCreateURLLoaderFactory( if (devtools_instrumentation::WillCreateURLLoaderFactory(
static_cast<RenderFrameHostImpl*>(rfh), true, is_download, static_cast<RenderFrameHostImpl*>(rfh), true, is_download,
&devtools_factory_request)) { &devtools_factory_request)) {
proxy_factory_ptr_info = std::move(devtools_factory_ptr_info); proxy_factory_ptr_info = std::move(devtools_factory_ptr_info);
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h" #include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/frame_host/frame_tree.h" #include "content/browser/frame_host/frame_tree.h"
#include "content/browser/frame_host/navigation_request.h" #include "content/browser/frame_host/navigation_request.h"
#include "content/browser/frame_host/navigator.h" #include "content/browser/frame_host/navigator.h"
...@@ -354,8 +354,7 @@ bool FrameTreeNode::CommitPendingFramePolicy() { ...@@ -354,8 +354,7 @@ bool FrameTreeNode::CommitPendingFramePolicy() {
void FrameTreeNode::TransferNavigationRequestOwnership( void FrameTreeNode::TransferNavigationRequestOwnership(
RenderFrameHostImpl* render_frame_host) { RenderFrameHostImpl* render_frame_host) {
RenderFrameDevToolsAgentHost::OnResetNavigationRequest( devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
navigation_request_.get());
render_frame_host->SetNavigationRequest(std::move(navigation_request_)); render_frame_host->SetNavigationRequest(std::move(navigation_request_));
} }
...@@ -399,8 +398,7 @@ void FrameTreeNode::ResetNavigationRequest(bool keep_state, ...@@ -399,8 +398,7 @@ void FrameTreeNode::ResetNavigationRequest(bool keep_state,
if (!navigation_request_) if (!navigation_request_)
return; return;
RenderFrameDevToolsAgentHost::OnResetNavigationRequest( devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
navigation_request_.get());
// The renderer should be informed if the caller allows to do so and the // The renderer should be informed if the caller allows to do so and the
// navigation came from a BeginNavigation IPC. // navigation came from a BeginNavigation IPC.
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "content/browser/appcache/appcache_navigation_handle.h" #include "content/browser/appcache/appcache_navigation_handle.h"
#include "content/browser/appcache/appcache_service_impl.h" #include "content/browser/appcache/appcache_service_impl.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h" #include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/frame_host/ancestor_throttle.h" #include "content/browser/frame_host/ancestor_throttle.h"
#include "content/browser/frame_host/blocked_scheme_navigation_throttle.h" #include "content/browser/frame_host/blocked_scheme_navigation_throttle.h"
#include "content/browser/frame_host/debug_urls.h" #include "content/browser/frame_host/debug_urls.h"
...@@ -1374,7 +1374,7 @@ void NavigationHandleImpl::RegisterNavigationThrottles() { ...@@ -1374,7 +1374,7 @@ void NavigationHandleImpl::RegisterNavigationThrottles() {
AddThrottle(OriginPolicyThrottle::MaybeCreateThrottleFor(this)); AddThrottle(OriginPolicyThrottle::MaybeCreateThrottleFor(this));
for (auto& throttle : for (auto& throttle :
RenderFrameDevToolsAgentHost::CreateNavigationThrottles(this)) { devtools_instrumentation::CreateNavigationThrottles(this)) {
AddThrottle(std::move(throttle)); AddThrottle(std::move(throttle));
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "content/browser/appcache/appcache_navigation_handle.h" #include "content/browser/appcache/appcache_navigation_handle.h"
#include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h" #include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/download/download_manager_impl.h" #include "content/browser/download/download_manager_impl.h"
#include "content/browser/frame_host/debug_urls.h" #include "content/browser/frame_host/debug_urls.h"
#include "content/browser/frame_host/frame_tree.h" #include "content/browser/frame_host/frame_tree.h"
...@@ -509,7 +509,7 @@ NavigationRequest::NavigationRequest( ...@@ -509,7 +509,7 @@ NavigationRequest::NavigationRequest(
NavigationRequest::~NavigationRequest() { NavigationRequest::~NavigationRequest() {
TRACE_EVENT_ASYNC_END0("navigation", "NavigationRequest", this); TRACE_EVENT_ASYNC_END0("navigation", "NavigationRequest", this);
if (state_ == STARTED) { if (state_ == STARTED) {
RenderFrameDevToolsAgentHost::OnNavigationRequestFailed( devtools_instrumentation::OnNavigationRequestFailed(
*this, network::URLLoaderCompletionStatus(net::ERR_ABORTED)); *this, network::URLLoaderCompletionStatus(net::ERR_ABORTED));
} }
} }
...@@ -1061,7 +1061,7 @@ void NavigationRequest::OnResponseStarted( ...@@ -1061,7 +1061,7 @@ void NavigationRequest::OnResponseStarted(
} }
} }
RenderFrameDevToolsAgentHost::OnNavigationResponseReceived(*this, *response); devtools_instrumentation::OnNavigationResponseReceived(*this, *response);
// The response code indicates that this is an error page, but we don't // The response code indicates that this is an error page, but we don't
// know how to display the content. We follow Firefox here and show our // know how to display the content. We follow Firefox here and show our
...@@ -1127,7 +1127,7 @@ void NavigationRequest::OnRequestFailedInternal( ...@@ -1127,7 +1127,7 @@ void NavigationRequest::OnRequestFailedInternal(
error_page_content.has_value())); error_page_content.has_value()));
common_params_.previews_state = content::PREVIEWS_OFF; common_params_.previews_state = content::PREVIEWS_OFF;
RenderFrameDevToolsAgentHost::OnNavigationRequestFailed(*this, status); devtools_instrumentation::OnNavigationRequestFailed(*this, status);
// TODO(https://crbug.com/757633): Check that ssl_info.has_value() if // TODO(https://crbug.com/757633): Check that ssl_info.has_value() if
// net_error is a certificate error. // net_error is a certificate error.
...@@ -1370,9 +1370,9 @@ void NavigationRequest::OnStartChecksComplete( ...@@ -1370,9 +1370,9 @@ void NavigationRequest::OnStartChecksComplete(
// Give DevTools a chance to override begin params (headers, skip SW) // Give DevTools a chance to override begin params (headers, skip SW)
// before actually loading resource. // before actually loading resource.
bool report_raw_headers = false; bool report_raw_headers = false;
RenderFrameDevToolsAgentHost::ApplyOverrides( devtools_instrumentation::ApplyNetworkRequestOverrides(
frame_tree_node_, begin_params_.get(), &report_raw_headers); frame_tree_node_, begin_params_.get(), &report_raw_headers);
RenderFrameDevToolsAgentHost::OnNavigationRequestWillBeSent(*this); devtools_instrumentation::OnNavigationRequestWillBeSent(*this);
loader_ = NavigationURLLoader::Create( loader_ = NavigationURLLoader::Create(
browser_context->GetResourceContext(), partition, browser_context->GetResourceContext(), partition,
...@@ -1429,7 +1429,7 @@ void NavigationRequest::OnRedirectChecksComplete( ...@@ -1429,7 +1429,7 @@ void NavigationRequest::OnRedirectChecksComplete(
return; return;
} }
RenderFrameDevToolsAgentHost::OnNavigationRequestWillBeSent(*this); devtools_instrumentation::OnNavigationRequestWillBeSent(*this);
base::Optional<net::HttpRequestHeaders> embedder_additional_headers; base::Optional<net::HttpRequestHeaders> embedder_additional_headers;
GetContentClient()->browser()->NavigationRequestRedirected( GetContentClient()->browser()->NavigationRequestRedirected(
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "content/browser/browser_main_loop.h" #include "content/browser/browser_main_loop.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/dedicated_worker/dedicated_worker_host.h" #include "content/browser/dedicated_worker/dedicated_worker_host.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h" #include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/dom_storage/dom_storage_context_wrapper.h" #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
#include "content/browser/download/mhtml_generation_manager.h" #include "content/browser/download/mhtml_generation_manager.h"
#include "content/browser/file_url_loader_factory.h" #include "content/browser/file_url_loader_factory.h"
...@@ -4313,8 +4313,8 @@ void RenderFrameHostImpl::CommitNavigation( ...@@ -4313,8 +4313,8 @@ void RenderFrameHostImpl::CommitNavigation(
browser_context, this, false /* is_navigation */, browser_context, this, false /* is_navigation */,
GetOriginForURLLoaderFactory(common_params.url, GetSiteInstance()), GetOriginForURLLoaderFactory(common_params.url, GetSiteInstance()),
&factory_request, nullptr /* bypass_redirect_checks */); &factory_request, nullptr /* bypass_redirect_checks */);
// Keep DevTools proxy lasy, i.e. closest to the network. // Keep DevTools proxy last, i.e. closest to the network.
RenderFrameDevToolsAgentHost::WillCreateURLLoaderFactory( devtools_instrumentation::WillCreateURLLoaderFactory(
this, false /* is_navigation */, false /* is_download */, this, false /* is_navigation */, false /* is_download */,
&factory_request); &factory_request);
factory.second->Clone(std::move(factory_request)); factory.second->Clone(std::move(factory_request));
...@@ -5047,7 +5047,7 @@ bool RenderFrameHostImpl::CreateNetworkServiceDefaultFactoryInternal( ...@@ -5047,7 +5047,7 @@ bool RenderFrameHostImpl::CreateNetworkServiceDefaultFactoryInternal(
} }
// Keep DevTools proxy last, i.e. closest to the network. // Keep DevTools proxy last, i.e. closest to the network.
RenderFrameDevToolsAgentHost::WillCreateURLLoaderFactory( devtools_instrumentation::WillCreateURLLoaderFactory(
this, false /* is_navigation */, false /* is_download */, this, false /* is_navigation */, false /* is_download */,
&default_factory_request); &default_factory_request);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "content/browser/appcache/appcache_navigation_handle_core.h" #include "content/browser/appcache/appcache_navigation_handle_core.h"
#include "content/browser/appcache/appcache_request_handler.h" #include "content/browser/appcache/appcache_request_handler.h"
#include "content/browser/blob_storage/chrome_blob_storage_context.h" #include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h" #include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/file_url_loader_factory.h" #include "content/browser/file_url_loader_factory.h"
#include "content/browser/fileapi/file_system_url_loader_factory.h" #include "content/browser/fileapi/file_system_url_loader_factory.h"
#include "content/browser/frame_host/frame_tree_node.h" #include "content/browser/frame_host/frame_tree_node.h"
...@@ -1652,7 +1652,7 @@ NavigationURLLoaderImpl::NavigationURLLoaderImpl( ...@@ -1652,7 +1652,7 @@ NavigationURLLoaderImpl::NavigationURLLoaderImpl(
partition->browser_context(), frame_tree_node->current_frame_host(), partition->browser_context(), frame_tree_node->current_frame_host(),
true /* is_navigation */, navigation_request_initiator, true /* is_navigation */, navigation_request_initiator,
&factory_request, &bypass_redirect_checks); &factory_request, &bypass_redirect_checks);
if (RenderFrameDevToolsAgentHost::WillCreateURLLoaderFactory( if (devtools_instrumentation::WillCreateURLLoaderFactory(
frame_tree_node->current_frame_host(), true, false, frame_tree_node->current_frame_host(), true, false,
&factory_request)) { &factory_request)) {
use_proxy = true; use_proxy = true;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h" #include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/frame_host/frame_tree_node.h" #include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/web_package/signed_exchange_envelope.h" #include "content/browser/web_package/signed_exchange_envelope.h"
#include "content/browser/web_package/signed_exchange_error.h" #include "content/browser/web_package/signed_exchange_error.h"
...@@ -41,7 +41,7 @@ void CertificateRequestSentOnUI( ...@@ -41,7 +41,7 @@ void CertificateRequestSentOnUI(
FrameTreeNode::GloballyFindByID(frame_tree_node_id_getter.Run()); FrameTreeNode::GloballyFindByID(frame_tree_node_id_getter.Run());
if (!frame_tree_node) if (!frame_tree_node)
return; return;
RenderFrameDevToolsAgentHost::OnSignedExchangeCertificateRequestSent( devtools_instrumentation::OnSignedExchangeCertificateRequestSent(
frame_tree_node, request_id, loader_id, request, signed_exchange_url); frame_tree_node, request_id, loader_id, request, signed_exchange_url);
} }
...@@ -55,7 +55,7 @@ void CertificateResponseReceivedOnUI( ...@@ -55,7 +55,7 @@ void CertificateResponseReceivedOnUI(
FrameTreeNode::GloballyFindByID(frame_tree_node_id_getter.Run()); FrameTreeNode::GloballyFindByID(frame_tree_node_id_getter.Run());
if (!frame_tree_node) if (!frame_tree_node)
return; return;
RenderFrameDevToolsAgentHost::OnSignedExchangeCertificateResponseReceived( devtools_instrumentation::OnSignedExchangeCertificateResponseReceived(
frame_tree_node, request_id, loader_id, url, response->head); frame_tree_node, request_id, loader_id, url, response->head);
} }
...@@ -67,7 +67,7 @@ void CertificateRequestCompletedOnUI( ...@@ -67,7 +67,7 @@ void CertificateRequestCompletedOnUI(
FrameTreeNode::GloballyFindByID(frame_tree_node_id_getter.Run()); FrameTreeNode::GloballyFindByID(frame_tree_node_id_getter.Run());
if (!frame_tree_node) if (!frame_tree_node)
return; return;
RenderFrameDevToolsAgentHost::OnSignedExchangeCertificateRequestCompleted( devtools_instrumentation::OnSignedExchangeCertificateRequestCompleted(
frame_tree_node, request_id, status); frame_tree_node, request_id, status);
} }
...@@ -84,7 +84,7 @@ void OnSignedExchangeReceivedOnUI( ...@@ -84,7 +84,7 @@ void OnSignedExchangeReceivedOnUI(
FrameTreeNode::GloballyFindByID(frame_tree_node_id_getter.Run()); FrameTreeNode::GloballyFindByID(frame_tree_node_id_getter.Run());
if (!frame_tree_node) if (!frame_tree_node)
return; return;
RenderFrameDevToolsAgentHost::OnSignedExchangeReceived( devtools_instrumentation::OnSignedExchangeReceived(
frame_tree_node, devtools_navigation_token, outer_request_url, frame_tree_node, devtools_navigation_token, outer_request_url,
outer_response->head, envelope, certificate, ssl_info, errors); outer_response->head, envelope, certificate, ssl_info, errors);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment