Commit 3dfc0ccd authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

DevTools: extract interface for DevToolsURLRequestInterceptor

This extracts DevToolsNetworkInterceptor as an interface between
NetworkHandler and the implementation of network request interceptor.
The only current implementation is DevToolsURLRequestInterceptor, but
the URLLoader-based implementation will share the interface.

Bug: 812464
Change-Id: I3c3c00fce2bae7e9278b05eb688f3dda1e8b10c3
Reviewed-on: https://chromium-review.googlesource.com/920795
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537469}
parent 44f26d00
......@@ -582,6 +582,8 @@ jumbo_source_set("browser") {
"devtools/devtools_io_context.h",
"devtools/devtools_manager.cc",
"devtools/devtools_manager.h",
"devtools/devtools_network_interceptor.cc",
"devtools/devtools_network_interceptor.h",
"devtools/devtools_network_transaction_factory.cc",
"devtools/devtools_pipe_handler.cc",
"devtools/devtools_pipe_handler.h",
......
......@@ -26,9 +26,8 @@ DevToolsInterceptorController::StartInterceptingRequests(
const base::UnguessableToken& target_id =
target_frame->devtools_frame_token();
auto filter_entry =
std::make_unique<DevToolsURLRequestInterceptor::FilterEntry>(
target_id, std::move(intercepted_patterns), std::move(callback));
auto filter_entry = std::make_unique<DevToolsNetworkInterceptor::FilterEntry>(
target_id, std::move(intercepted_patterns), std::move(callback));
DevToolsTargetRegistry::RegistrationHandle registration_handle =
target_registry_->RegisterWebContents(
WebContentsImpl::FromFrameTreeNode(target_frame));
......@@ -37,8 +36,8 @@ DevToolsInterceptorController::StartInterceptingRequests(
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&DevToolsURLRequestInterceptor::AddFilterEntry,
interceptor_, std::move(filter_entry)));
base::BindOnce(&DevToolsNetworkInterceptor::AddFilterEntry, interceptor_,
std::move(filter_entry)));
return handle;
}
......@@ -50,7 +49,7 @@ void DevToolsInterceptorController::ContinueInterceptedRequest(
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&DevToolsURLRequestInterceptor::ContinueInterceptedRequest,
base::BindOnce(&DevToolsNetworkInterceptor::ContinueInterceptedRequest,
interceptor_, interception_id,
base::Passed(std::move(modifications)),
base::Passed(std::move(callback))));
......@@ -72,9 +71,8 @@ void DevToolsInterceptorController::GetResponseBody(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&DevToolsURLRequestInterceptor::GetResponseBody,
interceptor_, std::move(interception_id),
std::move(callback)));
base::BindOnce(&DevToolsNetworkInterceptor::GetResponseBody, interceptor_,
std::move(interception_id), std::move(callback)));
}
void DevToolsInterceptorController::NavigationStarted(
......@@ -97,7 +95,7 @@ DevToolsInterceptorController::FromBrowserContext(BrowserContext* context) {
}
DevToolsInterceptorController::DevToolsInterceptorController(
base::WeakPtr<DevToolsURLRequestInterceptor> interceptor,
base::WeakPtr<DevToolsNetworkInterceptor> interceptor,
std::unique_ptr<DevToolsTargetRegistry> target_registry,
BrowserContext* browser_context)
: interceptor_(interceptor),
......@@ -112,8 +110,8 @@ DevToolsInterceptorController::~DevToolsInterceptorController() = default;
InterceptionHandle::InterceptionHandle(
DevToolsTargetRegistry::RegistrationHandle registration,
base::WeakPtr<DevToolsURLRequestInterceptor> interceptor,
DevToolsURLRequestInterceptor::FilterEntry* entry)
base::WeakPtr<DevToolsNetworkInterceptor> interceptor,
DevToolsNetworkInterceptor::FilterEntry* entry)
: registration_(registration),
interceptor_(std::move(interceptor)),
entry_(entry) {}
......@@ -121,17 +119,16 @@ InterceptionHandle::InterceptionHandle(
InterceptionHandle::~InterceptionHandle() {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&DevToolsURLRequestInterceptor::RemoveFilterEntry,
base::BindOnce(&DevToolsNetworkInterceptor::RemoveFilterEntry,
interceptor_, entry_));
}
void InterceptionHandle::UpdatePatterns(
std::vector<DevToolsURLRequestInterceptor::Pattern> patterns) {
std::vector<DevToolsNetworkInterceptor::Pattern> patterns) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&DevToolsURLRequestInterceptor::UpdatePatterns,
interceptor_, base::Unretained(entry_),
std::move(patterns)));
base::BindOnce(&DevToolsNetworkInterceptor::UpdatePatterns, interceptor_,
base::Unretained(entry_), std::move(patterns)));
}
} // namespace content
......@@ -25,13 +25,13 @@ struct GlobalRequestID;
class DevToolsInterceptorController : public base::SupportsUserData::Data {
public:
using GetResponseBodyForInterceptionCallback =
DevToolsURLRequestInterceptor::GetResponseBodyForInterceptionCallback;
DevToolsNetworkInterceptor::GetResponseBodyForInterceptionCallback;
using RequestInterceptedCallback =
DevToolsURLRequestInterceptor::RequestInterceptedCallback;
DevToolsNetworkInterceptor::RequestInterceptedCallback;
using ContinueInterceptedRequestCallback =
DevToolsURLRequestInterceptor::ContinueInterceptedRequestCallback;
using Modifications = DevToolsURLRequestInterceptor::Modifications;
using Pattern = DevToolsURLRequestInterceptor::Pattern;
DevToolsNetworkInterceptor::ContinueInterceptedRequestCallback;
using Modifications = DevToolsNetworkInterceptor::Modifications;
using Pattern = DevToolsNetworkInterceptor::Pattern;
static DevToolsInterceptorController* FromBrowserContext(
BrowserContext* context);
......@@ -58,7 +58,7 @@ class DevToolsInterceptorController : public base::SupportsUserData::Data {
friend class DevToolsURLRequestInterceptor;
DevToolsInterceptorController(
base::WeakPtr<DevToolsURLRequestInterceptor> interceptor,
base::WeakPtr<DevToolsNetworkInterceptor> interceptor,
std::unique_ptr<DevToolsTargetRegistry> target_registry,
BrowserContext* browser_context);
......@@ -66,7 +66,7 @@ class DevToolsInterceptorController : public base::SupportsUserData::Data {
const GlobalRequestID& request_id);
void NavigationFinished(const std::string& interception_id);
base::WeakPtr<DevToolsURLRequestInterceptor> interceptor_;
base::WeakPtr<DevToolsNetworkInterceptor> interceptor_;
std::unique_ptr<DevToolsTargetRegistry> target_registry_;
base::flat_map<std::string, GlobalRequestID> navigation_requests_;
base::flat_set<GlobalRequestID> canceled_navigation_requests_;
......@@ -78,17 +78,17 @@ class DevToolsInterceptorController : public base::SupportsUserData::Data {
class InterceptionHandle {
public:
~InterceptionHandle();
void UpdatePatterns(std::vector<DevToolsURLRequestInterceptor::Pattern>);
void UpdatePatterns(std::vector<DevToolsNetworkInterceptor::Pattern>);
private:
friend class DevToolsInterceptorController;
InterceptionHandle(DevToolsTargetRegistry::RegistrationHandle registration,
base::WeakPtr<DevToolsURLRequestInterceptor> interceptor,
DevToolsURLRequestInterceptor::FilterEntry* entry);
base::WeakPtr<DevToolsNetworkInterceptor> interceptor,
DevToolsNetworkInterceptor::FilterEntry* entry);
DevToolsTargetRegistry::RegistrationHandle registration_;
base::WeakPtr<DevToolsURLRequestInterceptor> interceptor_;
DevToolsURLRequestInterceptor::FilterEntry* entry_;
base::WeakPtr<DevToolsNetworkInterceptor> interceptor_;
DevToolsNetworkInterceptor::FilterEntry* entry_;
DISALLOW_COPY_AND_ASSIGN(InterceptionHandle);
};
......
// 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_network_interceptor.h"
namespace content {
InterceptedRequestInfo::InterceptedRequestInfo()
: response_error_code(net::OK) {}
InterceptedRequestInfo::~InterceptedRequestInfo() = default;
DevToolsNetworkInterceptor::FilterEntry::FilterEntry(
const base::UnguessableToken& target_id,
std::vector<Pattern> patterns,
RequestInterceptedCallback callback)
: target_id(target_id),
patterns(std::move(patterns)),
callback(std::move(callback)) {}
DevToolsNetworkInterceptor::FilterEntry::FilterEntry(FilterEntry&&) {}
DevToolsNetworkInterceptor::FilterEntry::~FilterEntry() {}
} // namespace content
// 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_NETWORK_INTERCEPTOR_H_
#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_INTERCEPTOR_H_
#include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/optional.h"
#include "base/unguessable_token.h"
#include "content/browser/devtools/protocol/network.h"
#include "content/public/common/resource_type.h"
#include "net/base/net_errors.h"
namespace content {
struct InterceptedRequestInfo {
InterceptedRequestInfo();
~InterceptedRequestInfo();
std::string interception_id;
std::unique_ptr<protocol::Network::Request> network_request;
base::UnguessableToken frame_id;
ResourceType resource_type;
bool is_navigation;
protocol::Maybe<protocol::Object> redirect_headers;
protocol::Maybe<int> redirect_status_code;
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 {
public:
using RequestInterceptedCallback =
base::RepeatingCallback<void(std::unique_ptr<InterceptedRequestInfo>)>;
using ContinueInterceptedRequestCallback =
protocol::Network::Backend::ContinueInterceptedRequestCallback;
using GetResponseBodyForInterceptionCallback =
protocol::Network::Backend::GetResponseBodyForInterceptionCallback;
struct Modifications {
Modifications(base::Optional<net::Error> error_reason,
base::Optional<std::string> raw_response,
protocol::Maybe<std::string> modified_url,
protocol::Maybe<std::string> modified_method,
protocol::Maybe<std::string> modified_post_data,
protocol::Maybe<protocol::Network::Headers> modified_headers,
protocol::Maybe<protocol::Network::AuthChallengeResponse>
auth_challenge_response,
bool mark_as_canceled);
~Modifications();
// If none of the following are set then the request will be allowed to
// continue unchanged.
base::Optional<net::Error> error_reason; // Finish with error.
base::Optional<std::string> raw_response; // Finish with mock response.
// Optionally modify before sending to network.
protocol::Maybe<std::string> modified_url;
protocol::Maybe<std::string> modified_method;
protocol::Maybe<std::string> modified_post_data;
protocol::Maybe<protocol::Network::Headers> modified_headers;
// AuthChallengeResponse is mutually exclusive with the above.
protocol::Maybe<protocol::Network::AuthChallengeResponse>
auth_challenge_response;
bool mark_as_canceled;
};
enum InterceptionStage {
REQUEST,
RESPONSE,
// Note: Both is not sent from front-end. It is used if both Request
// and HeadersReceived was found it upgrades it to Both.
BOTH,
DONT_INTERCEPT
};
struct Pattern {
public:
Pattern();
~Pattern();
Pattern(const Pattern& other);
Pattern(const std::string& url_pattern,
base::flat_set<ResourceType> resource_types,
InterceptionStage interception_stage);
const std::string url_pattern;
const base::flat_set<ResourceType> resource_types;
InterceptionStage interception_stage;
};
struct FilterEntry {
FilterEntry(const base::UnguessableToken& target_id,
std::vector<Pattern> patterns,
RequestInterceptedCallback callback);
FilterEntry(FilterEntry&&);
~FilterEntry();
const base::UnguessableToken target_id;
std::vector<Pattern> patterns;
const RequestInterceptedCallback callback;
DISALLOW_COPY_AND_ASSIGN(FilterEntry);
};
virtual void AddFilterEntry(std::unique_ptr<FilterEntry> entry) = 0;
virtual void RemoveFilterEntry(const FilterEntry* entry) = 0;
virtual void UpdatePatterns(FilterEntry* entry,
std::vector<Pattern> patterns) = 0;
virtual void GetResponseBody(
std::string interception_id,
std::unique_ptr<GetResponseBodyForInterceptionCallback> callback) = 0;
virtual void ContinueInterceptedRequest(
std::string interception_id,
std::unique_ptr<Modifications> modifications,
std::unique_ptr<ContinueInterceptedRequestCallback> callback) = 0;
};
} // namespace content
#endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_INTERCEPTOR_H_
......@@ -527,7 +527,7 @@ DevToolsURLInterceptorRequestJob::DevToolsURLInterceptorRequestJob(
net::URLRequest* original_request,
net::NetworkDelegate* original_network_delegate,
const base::UnguessableToken& devtools_token,
DevToolsURLRequestInterceptor::RequestInterceptedCallback callback,
DevToolsNetworkInterceptor::RequestInterceptedCallback callback,
bool is_redirect,
ResourceType resource_type,
InterceptionStage stage_to_intercept)
......@@ -870,7 +870,7 @@ void DevToolsURLInterceptorRequestJob::StopIntercepting() {
// Fallthough.
case WaitingForUserResponse::WAITING_FOR_REQUEST_ACK:
ProcessInterceptionRespose(
std::make_unique<DevToolsURLRequestInterceptor::Modifications>(
std::make_unique<DevToolsNetworkInterceptor::Modifications>(
base::nullopt, base::nullopt, protocol::Maybe<std::string>(),
protocol::Maybe<std::string>(), protocol::Maybe<std::string>(),
protocol::Maybe<protocol::Network::Headers>(),
......@@ -884,7 +884,7 @@ void DevToolsURLInterceptorRequestJob::StopIntercepting() {
ResponseEnum::Default)
.Build();
ProcessAuthRespose(
std::make_unique<DevToolsURLRequestInterceptor::Modifications>(
std::make_unique<DevToolsNetworkInterceptor::Modifications>(
base::nullopt, base::nullopt, protocol::Maybe<std::string>(),
protocol::Maybe<std::string>(), protocol::Maybe<std::string>(),
protocol::Maybe<protocol::Network::Headers>(),
......@@ -899,7 +899,7 @@ void DevToolsURLInterceptorRequestJob::StopIntercepting() {
}
void DevToolsURLInterceptorRequestJob::ContinueInterceptedRequest(
std::unique_ptr<DevToolsURLRequestInterceptor::Modifications> modifications,
std::unique_ptr<DevToolsNetworkInterceptor::Modifications> modifications,
std::unique_ptr<ContinueInterceptedRequestCallback> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
switch (waiting_for_user_response_) {
......@@ -1022,8 +1022,7 @@ DevToolsURLInterceptorRequestJob::BuildRequestInfo() {
}
void DevToolsURLInterceptorRequestJob::ProcessInterceptionRespose(
std::unique_ptr<DevToolsURLRequestInterceptor::Modifications>
modifications) {
std::unique_ptr<DevToolsNetworkInterceptor::Modifications> modifications) {
bool is_response_ack = waiting_for_user_response_ ==
WaitingForUserResponse::WAITING_FOR_RESPONSE_ACK;
waiting_for_user_response_ = WaitingForUserResponse::NOT_WAITING;
......@@ -1120,8 +1119,7 @@ void DevToolsURLInterceptorRequestJob::ProcessInterceptionRespose(
}
bool DevToolsURLInterceptorRequestJob::ProcessAuthRespose(
std::unique_ptr<DevToolsURLRequestInterceptor::Modifications>
modifications) {
std::unique_ptr<DevToolsNetworkInterceptor::Modifications> modifications) {
waiting_for_user_response_ = WaitingForUserResponse::NOT_WAITING;
protocol::Network::AuthChallengeResponse* auth_challenge_response =
......
......@@ -33,10 +33,10 @@ class DevToolsURLInterceptorRequestJob : public net::URLRequestJob {
net::URLRequest* original_request,
net::NetworkDelegate* original_network_delegate,
const base::UnguessableToken& devtools_token,
DevToolsURLRequestInterceptor::RequestInterceptedCallback callback,
DevToolsNetworkInterceptor::RequestInterceptedCallback callback,
bool is_redirect,
ResourceType resource_type,
DevToolsURLRequestInterceptor::InterceptionStage stage_to_intercept);
DevToolsNetworkInterceptor::InterceptionStage stage_to_intercept);
~DevToolsURLInterceptorRequestJob() override;
......@@ -64,12 +64,11 @@ class DevToolsURLInterceptorRequestJob : public net::URLRequestJob {
protocol::Network::Backend::ContinueInterceptedRequestCallback;
using GetResponseBodyForInterceptionCallback =
protocol::Network::Backend::GetResponseBodyForInterceptionCallback;
using InterceptionStage = DevToolsURLRequestInterceptor::InterceptionStage;
using InterceptionStage = DevToolsNetworkInterceptor::InterceptionStage;
// Must be called only once per interception. Must be called on IO thread.
void ContinueInterceptedRequest(
std::unique_ptr<DevToolsURLRequestInterceptor::Modifications>
modifications,
std::unique_ptr<DevToolsNetworkInterceptor::Modifications> modifications,
std::unique_ptr<ContinueInterceptedRequestCallback> callback);
void GetResponseBody(
std::unique_ptr<GetResponseBodyForInterceptionCallback> callback);
......@@ -125,12 +124,10 @@ class DevToolsURLInterceptorRequestJob : public net::URLRequestJob {
void ProcessRedirect(int status_code, const std::string& new_url);
void ProcessInterceptionRespose(
std::unique_ptr<DevToolsURLRequestInterceptor::Modifications>
modification);
std::unique_ptr<DevToolsNetworkInterceptor::Modifications> modification);
bool ProcessAuthRespose(
std::unique_ptr<DevToolsURLRequestInterceptor::Modifications>
modification);
std::unique_ptr<DevToolsNetworkInterceptor::Modifications> modification);
enum class WaitingForUserResponse {
NOT_WAITING,
......@@ -150,10 +147,10 @@ class DevToolsURLInterceptorRequestJob : public net::URLRequestJob {
const std::string interception_id_;
const intptr_t owning_entry_id_;
const base::UnguessableToken devtools_token_;
DevToolsURLRequestInterceptor::RequestInterceptedCallback callback_;
DevToolsNetworkInterceptor::RequestInterceptedCallback callback_;
const bool is_redirect_;
const ResourceType resource_type_;
DevToolsURLRequestInterceptor::InterceptionStage stage_to_intercept_;
InterceptionStage stage_to_intercept_;
std::vector<std::unique_ptr<GetResponseBodyForInterceptionCallback>>
pending_body_requests_;
......
......@@ -16,22 +16,6 @@
namespace content {
InterceptedRequestInfo::InterceptedRequestInfo()
: response_error_code(net::OK) {}
InterceptedRequestInfo::~InterceptedRequestInfo() = default;
DevToolsURLRequestInterceptor::FilterEntry::FilterEntry(
const base::UnguessableToken& target_id,
std::vector<Pattern> patterns,
RequestInterceptedCallback callback)
: target_id(target_id),
patterns(std::move(patterns)),
callback(std::move(callback)) {}
DevToolsURLRequestInterceptor::FilterEntry::FilterEntry(FilterEntry&&) {}
DevToolsURLRequestInterceptor::FilterEntry::~FilterEntry() {}
// static
bool DevToolsURLRequestInterceptor::IsNavigationRequest(
ResourceType resource_type) {
......
......@@ -11,10 +11,9 @@
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/unguessable_token.h"
#include "content/browser/devtools/devtools_network_interceptor.h"
#include "content/browser/devtools/devtools_target_registry.h"
#include "content/browser/devtools/protocol/network.h"
#include "content/public/common/resource_type.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_interceptor.h"
namespace content {
......@@ -25,116 +24,32 @@ class DevToolsTargetRegistry;
class DevToolsURLInterceptorRequestJob;
class ResourceRequestInfo;
struct InterceptedRequestInfo {
InterceptedRequestInfo();
~InterceptedRequestInfo();
std::string interception_id;
std::unique_ptr<protocol::Network::Request> network_request;
base::UnguessableToken frame_id;
ResourceType resource_type;
bool is_navigation;
protocol::Maybe<protocol::Object> redirect_headers;
protocol::Maybe<int> redirect_status_code;
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;
};
// An interceptor that creates DevToolsURLInterceptorRequestJobs for requests
// from pages where interception has been enabled via
// Network.setRequestInterceptionEnabled.
// This class is constructed on the UI thread but only accessed on IO thread.
class DevToolsURLRequestInterceptor : public net::URLRequestInterceptor {
class DevToolsURLRequestInterceptor : public net::URLRequestInterceptor,
public DevToolsNetworkInterceptor {
public:
using RequestInterceptedCallback =
base::Callback<void(std::unique_ptr<InterceptedRequestInfo>)>;
static bool IsNavigationRequest(ResourceType resource_type);
explicit DevToolsURLRequestInterceptor(BrowserContext* browser_context);
~DevToolsURLRequestInterceptor() override;
using ContinueInterceptedRequestCallback =
protocol::Network::Backend::ContinueInterceptedRequestCallback;
using GetResponseBodyForInterceptionCallback =
protocol::Network::Backend::GetResponseBodyForInterceptionCallback;
struct Modifications {
Modifications(base::Optional<net::Error> error_reason,
base::Optional<std::string> raw_response,
protocol::Maybe<std::string> modified_url,
protocol::Maybe<std::string> modified_method,
protocol::Maybe<std::string> modified_post_data,
protocol::Maybe<protocol::Network::Headers> modified_headers,
protocol::Maybe<protocol::Network::AuthChallengeResponse>
auth_challenge_response,
bool mark_as_canceled);
~Modifications();
bool RequestShouldContineUnchanged() const;
// If none of the following are set then the request will be allowed to
// continue unchanged.
base::Optional<net::Error> error_reason; // Finish with error.
base::Optional<std::string> raw_response; // Finish with mock response.
// Optionally modify before sending to network.
protocol::Maybe<std::string> modified_url;
protocol::Maybe<std::string> modified_method;
protocol::Maybe<std::string> modified_post_data;
protocol::Maybe<protocol::Network::Headers> modified_headers;
// AuthChallengeResponse is mutually exclusive with the above.
protocol::Maybe<protocol::Network::AuthChallengeResponse>
auth_challenge_response;
bool mark_as_canceled;
};
enum InterceptionStage {
REQUEST,
RESPONSE,
// Note: Both is not sent from front-end. It is used if both Request
// and HeadersReceived was found it upgrades it to Both.
BOTH,
DONT_INTERCEPT
};
struct Pattern {
public:
Pattern();
~Pattern();
Pattern(const Pattern& other);
Pattern(const std::string& url_pattern,
base::flat_set<ResourceType> resource_types,
InterceptionStage interception_stage);
const std::string url_pattern;
const base::flat_set<ResourceType> resource_types;
InterceptionStage interception_stage;
};
struct FilterEntry {
FilterEntry(const base::UnguessableToken& target_id,
std::vector<Pattern> patterns,
RequestInterceptedCallback callback);
FilterEntry(FilterEntry&&);
~FilterEntry();
const base::UnguessableToken target_id;
std::vector<Pattern> patterns;
const DevToolsURLRequestInterceptor::RequestInterceptedCallback callback;
DISALLOW_COPY_AND_ASSIGN(FilterEntry);
};
void AddFilterEntry(std::unique_ptr<FilterEntry> entry);
void RemoveFilterEntry(const FilterEntry* entry);
void UpdatePatterns(FilterEntry* entry, std::vector<Pattern> patterns);
// net::URLRequestInterceptor implementation:
// DevToolsNetworkInterceptor implementation.
void AddFilterEntry(std::unique_ptr<FilterEntry> entry) override;
void RemoveFilterEntry(const FilterEntry* entry) override;
void UpdatePatterns(FilterEntry* entry,
std::vector<Pattern> patterns) override;
void GetResponseBody(std::string interception_id,
std::unique_ptr<GetResponseBodyForInterceptionCallback>
callback) override;
void ContinueInterceptedRequest(
std::string interception_id,
std::unique_ptr<Modifications> modifications,
std::unique_ptr<ContinueInterceptedRequestCallback> callback) override;
// net::URLRequestInterceptor implementation.
net::URLRequestJob* MaybeInterceptRequest(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override;
......@@ -150,31 +65,19 @@ class DevToolsURLRequestInterceptor : public net::URLRequestInterceptor {
// Registers a |sub_request| that should not be intercepted.
void RegisterSubRequest(const net::URLRequest* sub_request);
// Unregisters a |sub_request|.
void UnregisterSubRequest(const net::URLRequest* sub_request);
// To make the user's life easier we make sure requests in a redirect chain
// all have the same id.
void ExpectRequestAfterRedirect(const net::URLRequest* request,
std::string id);
void JobFinished(const std::string& interception_id, bool is_navigation);
void GetResponseBody(
std::string interception_id,
std::unique_ptr<GetResponseBodyForInterceptionCallback> callback);
void ContinueInterceptedRequest(
std::string interception_id,
std::unique_ptr<DevToolsURLRequestInterceptor::Modifications>
modifications,
std::unique_ptr<ContinueInterceptedRequestCallback> callback);
private:
net::URLRequestJob* InnerMaybeInterceptRequest(
net::URLRequest* request,
net::NetworkDelegate* network_delegate);
FilterEntry* FilterEntryForRequest(const base::UnguessableToken target_id,
FilterEntry* FilterEntryForRequest(base::UnguessableToken target_id,
const GURL& url,
ResourceType resource_type,
InterceptionStage* stage);
......
......@@ -477,15 +477,15 @@ String securityState(const GURL& url, const net::CertStatus& cert_status) {
return Security::SecurityStateEnum::Secure;
}
DevToolsURLRequestInterceptor::InterceptionStage ToInterceptorStage(
DevToolsNetworkInterceptor::InterceptionStage ToInterceptorStage(
const protocol::Network::InterceptionStage& interceptor_stage) {
if (interceptor_stage == protocol::Network::InterceptionStageEnum::Request)
return DevToolsURLRequestInterceptor::REQUEST;
return DevToolsNetworkInterceptor::REQUEST;
if (interceptor_stage ==
protocol::Network::InterceptionStageEnum::HeadersReceived)
return DevToolsURLRequestInterceptor::RESPONSE;
return DevToolsNetworkInterceptor::RESPONSE;
NOTREACHED();
return DevToolsURLRequestInterceptor::REQUEST;
return DevToolsNetworkInterceptor::REQUEST;
}
net::Error NetErrorFromString(const std::string& error, bool* ok) {
......@@ -1388,7 +1388,7 @@ DispatchResponse NetworkHandler::SetRequestInterception(
return Response::OK();
}
std::vector<DevToolsURLRequestInterceptor::Pattern> interceptor_patterns;
std::vector<DevToolsNetworkInterceptor::Pattern> interceptor_patterns;
for (size_t i = 0; i < patterns->length(); ++i) {
base::flat_set<ResourceType> resource_types;
std::string resource_type = patterns->get(i)->GetResourceType("");
......@@ -1398,7 +1398,7 @@ DispatchResponse NetworkHandler::SetRequestInterception(
"Cannot intercept resources of type '%s'", resource_type.c_str()));
}
}
interceptor_patterns.push_back(DevToolsURLRequestInterceptor::Pattern(
interceptor_patterns.push_back(DevToolsNetworkInterceptor::Pattern(
patterns->get(i)->GetUrlPattern("*"), std::move(resource_types),
ToInterceptorStage(patterns->get(i)->GetInterceptionStage(
protocol::Network::InterceptionStageEnum::Request))));
......@@ -1458,7 +1458,7 @@ void NetworkHandler::ContinueInterceptedRequest(
interceptor->ContinueInterceptedRequest(
interception_id,
std::make_unique<DevToolsURLRequestInterceptor::Modifications>(
std::make_unique<DevToolsNetworkInterceptor::Modifications>(
std::move(error), std::move(raw_response), std::move(url),
std::move(method), std::move(post_data), std::move(headers),
std::move(auth_challenge_response), mark_as_canceled),
......
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