#include "content/public/test/url_loader_interceptor.h"
#include <string>
#include <string_view>
#include <utility>
#include "base/containers/unique_ptr_adapters.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/synchronization/lock.h"
#include "base/test/bind.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "content/browser/loader/url_loader_factory_utils.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/service_worker/embedded_worker_instance.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/mock_render_process_host.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "net/http/http_util.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/parsed_headers.h"
#include "services/network/public/cpp/url_loader_factory_builder.h"
#include "services/network/public/mojom/early_hints.mojom.h"
#include "services/network/public/mojom/url_loader.mojom.h"
namespace content {
namespace {
base::FilePath GetDataFilePath(const std::string& relative_path) { … }
static std::string ReadFile(const base::FilePath& path) { … }
}
class URLLoaderInterceptor::IOState
: public base::RefCountedThreadSafe<URLLoaderInterceptor::IOState,
BrowserThread::DeleteOnIOThread> { … };
class URLLoaderClientInterceptor : public network::mojom::URLLoaderClient { … };
class URLLoaderInterceptor::Interceptor
: public network::mojom::URLLoaderFactory { … };
class URLLoaderInterceptor::Wrapper final { … };
URLLoaderInterceptor::RequestParams::RequestParams() = default;
URLLoaderInterceptor::RequestParams::~RequestParams() = default;
URLLoaderInterceptor::RequestParams::RequestParams(RequestParams&& other) =
default;
URLLoaderInterceptor::RequestParams& URLLoaderInterceptor::RequestParams::
operator=(RequestParams&& other) = default;
URLLoaderInterceptor::URLLoaderInterceptor(
InterceptCallback intercept_callback,
const URLLoaderCompletionStatusCallback& completion_status_callback,
base::OnceClosure ready_callback)
: … { … }
URLLoaderInterceptor::~URLLoaderInterceptor() { … }
const GURL& URLLoaderInterceptor::GetLastRequestURL() { … }
const net::HttpRequestHeaders& URLLoaderInterceptor::GetLastRequestHeaders() { … }
void URLLoaderInterceptor::SetLastRequestURL(const GURL& url) { … }
void URLLoaderInterceptor::SetLastRequestHeaders(
const net::HttpRequestHeaders& headers) { … }
std::unique_ptr<URLLoaderInterceptor>
URLLoaderInterceptor::ServeFilesFromDirectoryAtOrigin(
const std::string& relative_base_path,
const GURL& origin,
base::RepeatingCallback<void(const GURL&)> callback) { … }
void URLLoaderInterceptor::WriteResponse(
std::string_view headers,
std::string_view body,
network::mojom::URLLoaderClient* client,
std::optional<net::SSLInfo> ssl_info,
std::optional<GURL> url) { … }
void URLLoaderInterceptor::WriteResponse(
const std::string& relative_path,
network::mojom::URLLoaderClient* client,
const std::string* headers,
std::optional<net::SSLInfo> ssl_info,
std::optional<GURL> url) { … }
void URLLoaderInterceptor::WriteResponse(
const base::FilePath& file_path,
network::mojom::URLLoaderClient* client,
const std::string* headers,
std::optional<net::SSLInfo> ssl_info,
std::optional<GURL> url) { … }
void URLLoaderInterceptor::InterceptorCallback(
int process_id,
network::URLLoaderFactoryBuilder& factory_builder) { … }
bool URLLoaderInterceptor::Intercept(RequestParams* params) { … }
void URLLoaderInterceptor::IOState::WrapperBindingError(Wrapper* wrapper) { … }
void URLLoaderInterceptor::IOState::Initialize(
const URLLoaderCompletionStatusCallback& completion_status_callback,
base::OnceClosure closure) { … }
void URLLoaderInterceptor::IOState::CreateURLLoaderFactoryForRenderProcess(
mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver,
int process_id,
mojo::PendingRemote<network::mojom::URLLoaderFactory> original_factory) { … }
std::unique_ptr<content::URLLoaderInterceptor>
URLLoaderInterceptor::SetupRequestFailForURL(const GURL& url,
net::Error error,
base::OnceClosure ready_callback) { … }
}