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

DevTools: remove most protocol types from InterceptedRequestInfo

This removes protocol types used for response headers and auth
challenge from InterceptedRequestInfo and replaces them with

net: :HttpResponseHeaders and net::AuthChallengeInfo.
Change-Id: I4fa916d0d6bf77a9c4de183396372a87948992c7
Reviewed-on: https://chromium-review.googlesource.com/c/1297573
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602386}
parent 57324312
...@@ -14,6 +14,11 @@ ...@@ -14,6 +14,11 @@
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
namespace net {
class AuthChallengeInfo;
class HttpResponseHeaders;
} // namespace net
namespace content { namespace content {
struct InterceptedRequestInfo { struct InterceptedRequestInfo {
...@@ -21,18 +26,15 @@ struct InterceptedRequestInfo { ...@@ -21,18 +26,15 @@ struct InterceptedRequestInfo {
~InterceptedRequestInfo(); ~InterceptedRequestInfo();
std::string interception_id; std::string interception_id;
std::unique_ptr<protocol::Network::Request> network_request;
base::UnguessableToken frame_id; base::UnguessableToken frame_id;
ResourceType resource_type; ResourceType resource_type;
bool is_navigation; bool is_navigation;
int response_error_code;
std::unique_ptr<protocol::Network::Request> network_request;
scoped_refptr<net::AuthChallengeInfo> auth_challenge;
scoped_refptr<net::HttpResponseHeaders> response_headers;
protocol::Maybe<bool> is_download; protocol::Maybe<bool> is_download;
protocol::Maybe<protocol::Object> redirect_headers;
protocol::Maybe<int> redirect_status_code;
protocol::Maybe<protocol::String> redirect_url; protocol::Maybe<protocol::String> redirect_url;
protocol::Maybe<protocol::Network::AuthChallenge> auth_challenge;
int response_error_code;
protocol::Maybe<int> http_response_status_code;
protocol::Maybe<protocol::Object> response_headers;
}; };
class DevToolsNetworkInterceptor { class DevToolsNetworkInterceptor {
......
...@@ -793,15 +793,7 @@ void DevToolsURLInterceptorRequestJob::OnSubRequestAuthRequired( ...@@ -793,15 +793,7 @@ void DevToolsURLInterceptorRequestJob::OnSubRequestAuthRequired(
waiting_for_user_response_ = WaitingForUserResponse::WAITING_FOR_AUTH_ACK; waiting_for_user_response_ = WaitingForUserResponse::WAITING_FOR_AUTH_ACK;
std::unique_ptr<InterceptedRequestInfo> request_info = BuildRequestInfo(); std::unique_ptr<InterceptedRequestInfo> request_info = BuildRequestInfo();
request_info->auth_challenge = request_info->auth_challenge = auth_info;
protocol::Network::AuthChallenge::Create()
.SetSource(auth_info->is_proxy
? protocol::Network::AuthChallenge::SourceEnum::Proxy
: protocol::Network::AuthChallenge::SourceEnum::Server)
.SetOrigin(auth_info->challenger.Serialize())
.SetScheme(auth_info->scheme)
.SetRealm(auth_info->realm)
.Build();
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
base::BindOnce(callback_, std::move(request_info))); base::BindOnce(callback_, std::move(request_info)));
} }
...@@ -839,24 +831,12 @@ void DevToolsURLInterceptorRequestJob::OnSubRequestRedirectReceived( ...@@ -839,24 +831,12 @@ void DevToolsURLInterceptorRequestJob::OnSubRequestRedirectReceived(
// Otherwise we will need to ask what to do via DevTools protocol. // Otherwise we will need to ask what to do via DevTools protocol.
*defer_redirect = true; *defer_redirect = true;
size_t iter = 0;
std::string header_name;
std::string header_value;
std::unique_ptr<protocol::DictionaryValue> headers_dict(
protocol::DictionaryValue::create());
while (request.response_headers()->EnumerateHeaderLines(&iter, &header_name,
&header_value)) {
headers_dict->setString(header_name, header_value);
}
redirect_.reset(new net::RedirectInfo(redirectinfo)); redirect_.reset(new net::RedirectInfo(redirectinfo));
waiting_for_user_response_ = WaitingForUserResponse::WAITING_FOR_REQUEST_ACK; waiting_for_user_response_ = WaitingForUserResponse::WAITING_FOR_REQUEST_ACK;
std::unique_ptr<InterceptedRequestInfo> request_info = BuildRequestInfo(); std::unique_ptr<InterceptedRequestInfo> request_info = BuildRequestInfo();
request_info->response_headers = request_info->response_headers = request.response_headers();
protocol::Object::fromValue(headers_dict.get(), nullptr);
request_info->http_response_status_code = redirectinfo.status_code;
request_info->redirect_url = redirectinfo.new_url.spec(); request_info->redirect_url = redirectinfo.new_url.spec();
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
base::BindOnce(callback_, std::move(request_info))); base::BindOnce(callback_, std::move(request_info)));
...@@ -879,19 +859,8 @@ void DevToolsURLInterceptorRequestJob::OnInterceptedRequestResponseStarted( ...@@ -879,19 +859,8 @@ void DevToolsURLInterceptorRequestJob::OnInterceptedRequestResponseStarted(
} else { } else {
std::unique_ptr<protocol::DictionaryValue> headers_dict( std::unique_ptr<protocol::DictionaryValue> headers_dict(
protocol::DictionaryValue::create()); protocol::DictionaryValue::create());
if (sub_request_->request()->response_headers()) {
size_t iter = 0;
std::string name;
std::string value;
while (sub_request_->request()->response_headers()->EnumerateHeaderLines(
&iter, &name, &value)) {
headers_dict->setString(name, value);
}
}
request_info->http_response_status_code =
sub_request_->request()->GetResponseCode();
request_info->response_headers = request_info->response_headers =
protocol::Object::fromValue(headers_dict.get(), nullptr); sub_request_->request()->response_headers();
request_info->is_download = IsDownload(request(), sub_request_->request()); request_info->is_download = IsDownload(request(), sub_request_->request());
} }
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
......
...@@ -1165,22 +1165,8 @@ std::unique_ptr<InterceptedRequestInfo> InterceptionJob::BuildRequestInfo( ...@@ -1165,22 +1165,8 @@ std::unique_ptr<InterceptedRequestInfo> InterceptionJob::BuildRequestInfo(
result->is_navigation = resource_type == RESOURCE_TYPE_MAIN_FRAME || result->is_navigation = resource_type == RESOURCE_TYPE_MAIN_FRAME ||
resource_type == RESOURCE_TYPE_SUB_FRAME; resource_type == RESOURCE_TYPE_SUB_FRAME;
// TODO(caseq): merge with NetworkHandler::BuildResponse() if (head && head->headers)
if (head && head->headers) { result->response_headers = head->headers;
result->http_response_status_code = head->headers->response_code();
auto headers_dict = protocol::DictionaryValue::create();
size_t iter = 0;
std::string name;
std::string value;
while (head->headers->EnumerateHeaderLines(&iter, &name, &value)) {
std::string old_value;
bool merge_with_another = headers_dict->getString(name, &old_value);
headers_dict->setString(
name, merge_with_another ? old_value + '\n' + value : value);
}
result->response_headers =
protocol::Object::fromValue(headers_dict.get(), nullptr);
}
return result; return result;
} }
...@@ -1389,7 +1375,6 @@ void InterceptionJob::OnReceiveRedirect( ...@@ -1389,7 +1375,6 @@ void InterceptionJob::OnReceiveRedirect(
std::unique_ptr<InterceptedRequestInfo> request_info = std::unique_ptr<InterceptedRequestInfo> request_info =
BuildRequestInfo(&head); BuildRequestInfo(&head);
request_info->http_response_status_code = redirect_info.status_code;
request_info->redirect_url = redirect_info.new_url.spec(); request_info->redirect_url = redirect_info.new_url.spec();
NotifyClient(std::move(request_info)); NotifyClient(std::move(request_info));
} }
...@@ -1468,15 +1453,7 @@ void InterceptionJob::OnAuthRequest( ...@@ -1468,15 +1453,7 @@ void InterceptionJob::OnAuthRequest(
} }
state_ = State::kAuthRequired; state_ = State::kAuthRequired;
auto request_info = BuildRequestInfo(nullptr); auto request_info = BuildRequestInfo(nullptr);
request_info->auth_challenge = request_info->auth_challenge = auth_info;
protocol::Network::AuthChallenge::Create()
.SetSource(auth_info->is_proxy
? protocol::Network::AuthChallenge::SourceEnum::Proxy
: protocol::Network::AuthChallenge::SourceEnum::Server)
.SetOrigin(auth_info->challenger.Serialize())
.SetScheme(auth_info->scheme)
.SetRealm(auth_info->realm)
.Build();
pending_auth_callback_ = std::move(callback); pending_auth_callback_ = std::move(callback);
NotifyClient(std::move(request_info)); NotifyClient(std::move(request_info));
} }
......
...@@ -1436,22 +1436,29 @@ std::unique_ptr<protocol::Network::SecurityDetails> BuildSecurityDetails( ...@@ -1436,22 +1436,29 @@ std::unique_ptr<protocol::Network::SecurityDetails> BuildSecurityDetails(
return security_details; return security_details;
} }
std::unique_ptr<protocol::Object> BuildResponseHeaders(
scoped_refptr<net::HttpResponseHeaders> headers) {
auto headers_dict = DictionaryValue::create();
if (!headers)
return std::make_unique<protocol::Object>(std::move(headers_dict));
size_t iterator = 0;
std::string name;
std::string value;
while (headers->EnumerateHeaderLines(&iterator, &name, &value)) {
std::string old_value;
bool merge_with_another = headers_dict->getString(name, &old_value);
headers_dict->setString(
name, merge_with_another ? old_value + '\n' + value : value);
}
return std::make_unique<protocol::Object>(std::move(headers_dict));
}
std::unique_ptr<Network::Response> BuildResponse( std::unique_ptr<Network::Response> BuildResponse(
const GURL& url, const GURL& url,
const network::ResourceResponseInfo& info) { const network::ResourceResponseInfo& info) {
std::unique_ptr<DictionaryValue> headers_dict(DictionaryValue::create());
int status = 0; int status = 0;
std::string status_text; std::string status_text;
if (info.headers) { if (info.headers) {
size_t iterator = 0;
std::string name;
std::string value;
while (info.headers->EnumerateHeaderLines(&iterator, &name, &value)) {
std::string old_value;
bool merge_with_another = headers_dict->getString(name, &old_value);
headers_dict->setString(
name, merge_with_another ? old_value + '\n' + value : value);
}
status = info.headers->response_code(); status = info.headers->response_code();
status_text = info.headers->GetStatusText(); status_text = info.headers->GetStatusText();
} else if (url.SchemeIs(url::kDataScheme)) { } else if (url.SchemeIs(url::kDataScheme)) {
...@@ -1465,7 +1472,7 @@ std::unique_ptr<Network::Response> BuildResponse( ...@@ -1465,7 +1472,7 @@ std::unique_ptr<Network::Response> BuildResponse(
.SetUrl(NetworkHandler::ExtractFragment(url, &url_fragment)) .SetUrl(NetworkHandler::ExtractFragment(url, &url_fragment))
.SetStatus(status) .SetStatus(status)
.SetStatusText(status_text) .SetStatusText(status_text)
.SetHeaders(Object::fromValue(headers_dict.get(), nullptr)) .SetHeaders(BuildResponseHeaders(info.headers))
.SetMimeType(info.mime_type) .SetMimeType(info.mime_type)
.SetConnectionReused(info.load_timing.socket_reused) .SetConnectionReused(info.load_timing.socket_reused)
.SetConnectionId(info.load_timing.socket_log_id) .SetConnectionId(info.load_timing.socket_log_id)
...@@ -2114,13 +2121,34 @@ void NetworkHandler::RequestIntercepted( ...@@ -2114,13 +2121,34 @@ void NetworkHandler::RequestIntercepted(
protocol::Maybe<protocol::Network::ErrorReason> error_reason; protocol::Maybe<protocol::Network::ErrorReason> error_reason;
if (info->response_error_code < 0) if (info->response_error_code < 0)
error_reason = NetErrorToString(info->response_error_code); error_reason = NetErrorToString(info->response_error_code);
Maybe<int> status_code;
Maybe<protocol::Network::Headers> response_headers;
if (info->response_headers) {
status_code = info->response_headers->response_code();
response_headers = BuildResponseHeaders(info->response_headers);
}
std::unique_ptr<protocol::Network::AuthChallenge> auth_challenge;
if (info->auth_challenge) {
auth_challenge =
protocol::Network::AuthChallenge::Create()
.SetSource(info->auth_challenge->is_proxy
? Network::AuthChallenge::SourceEnum::Proxy
: Network::AuthChallenge::SourceEnum::Server)
.SetOrigin(info->auth_challenge->challenger.Serialize())
.SetScheme(info->auth_challenge->scheme)
.SetRealm(info->auth_challenge->realm)
.Build();
}
frontend_->RequestIntercepted( frontend_->RequestIntercepted(
info->interception_id, std::move(info->network_request), info->interception_id, std::move(info->network_request),
info->frame_id.ToString(), ResourceTypeToString(info->resource_type), info->frame_id.ToString(), ResourceTypeToString(info->resource_type),
info->is_navigation, std::move(info->is_download), info->is_navigation, std::move(info->is_download),
std::move(info->redirect_url), std::move(info->auth_challenge), std::move(info->redirect_url), std::move(auth_challenge),
std::move(error_reason), std::move(info->http_response_status_code), std::move(error_reason), std::move(status_code),
std::move(info->response_headers)); std::move(response_headers));
} }
void NetworkHandler::SetNetworkConditions( void NetworkHandler::SetNetworkConditions(
......
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