#include "content/browser/loader/keep_alive_url_loader.h"
#include <memory>
#include <utility>
#include <vector>
#include "base/check_is_test.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/typed_macros.h"
#include "base/unguessable_token.h"
#include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/loader/keep_alive_attribution_request_helper.h"
#include "content/browser/renderer_host/mixed_content_checker.h"
#include "content/browser/renderer_host/policy_container_host.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "content/public/common/url_utils.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
#include "services/network/public/cpp/content_security_policy/content_security_policy.h"
#include "services/network/public/cpp/content_security_policy/csp_context.h"
#include "services/network/public/cpp/devtools_observer_util.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/content_security_policy.mojom.h"
#include "services/network/public/mojom/early_hints.mojom.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "services/network/public/mojom/url_request.mojom.h"
#include "third_party/blink/public/common/features.h"
namespace content {
namespace {
constexpr base::TimeDelta kDefaultDisconnectedKeepAliveURLLoaderTimeout = …;
base::TimeDelta GetDisconnectedKeepAliveURLLoaderTimeout() { … }
enum class FetchLaterBrowserMetricType { … };
void LogFetchLaterMetric(const FetchLaterBrowserMetricType& type) { … }
class KeepAliveURLLoaderCSPContext final : public network::CSPContext { … };
bool IsRedirectAllowedByCSP(
const std::vector<network::mojom::ContentSecurityPolicyPtr>& policies,
const GURL& url,
const GURL& url_before_redirects,
bool has_followed_redirect) { … }
}
class KeepAliveURLLoader::ForwardingClient final
: public network::mojom::URLLoaderClient { … };
struct KeepAliveURLLoader::StoredURLLoad { … };
KeepAliveURLLoader::KeepAliveURLLoader(
int32_t request_id,
uint32_t options,
const network::ResourceRequest& resource_request,
mojo::PendingRemote<network::mojom::URLLoaderClient> forwarding_client,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory,
scoped_refptr<PolicyContainerHost> policy_container_host,
WeakDocumentPtr weak_document_ptr,
BrowserContext* browser_context,
URLLoaderThrottlesGetter throttles_getter,
base::PassKey<KeepAliveURLLoaderService>,
std::unique_ptr<KeepAliveAttributionRequestHelper>
attribution_request_helper)
: … { … }
void KeepAliveURLLoader::Start() { … }
KeepAliveURLLoader::~KeepAliveURLLoader() { … }
void KeepAliveURLLoader::set_on_delete_callback(
OnDeleteCallback on_delete_callback) { … }
base::WeakPtr<KeepAliveURLLoader> KeepAliveURLLoader::GetWeakPtr() { … }
bool KeepAliveURLLoader::IsStarted() const { … }
RenderFrameHostImpl* KeepAliveURLLoader::GetInitiator() const { … }
void KeepAliveURLLoader::FollowRedirect(
const std::vector<std::string>& removed_headers,
const net::HttpRequestHeaders& modified_headers,
const net::HttpRequestHeaders& modified_cors_exempt_headers,
const std::optional<GURL>& new_url) { … }
void KeepAliveURLLoader::SetPriority(net::RequestPriority priority,
int intra_priority_value) { … }
void KeepAliveURLLoader::PauseReadingBodyFromNet() { … }
void KeepAliveURLLoader::ResumeReadingBodyFromNet() { … }
void KeepAliveURLLoader::EndReceiveRedirect(
const net::RedirectInfo& redirect_info,
network::mojom::URLResponseHeadPtr head) { … }
void KeepAliveURLLoader::OnReceiveResponse(
network::mojom::URLResponseHeadPtr response,
mojo::ScopedDataPipeConsumerHandle body,
std::optional<mojo_base::BigBuffer> cached_metadata) { … }
void KeepAliveURLLoader::OnComplete(
const network::URLLoaderCompletionStatus& completion_status) { … }
bool KeepAliveURLLoader::HasReceivedResponse() const { … }
void KeepAliveURLLoader::ForwardURLLoad() { … }
bool KeepAliveURLLoader::IsForwardURLLoadStarted() const { … }
bool KeepAliveURLLoader::IsRendererConnected() const { … }
net::Error KeepAliveURLLoader::WillFollowRedirect(
const net::RedirectInfo& redirect_info) const { … }
void KeepAliveURLLoader::CancelWithStatus(
const network::URLLoaderCompletionStatus& status) { … }
void KeepAliveURLLoader::ForwardingClient::OnDisconnected() { … }
void KeepAliveURLLoader::OnURLLoaderDisconnected() { … }
void KeepAliveURLLoader::OnDisconnectedLoaderTimerFired() { … }
void KeepAliveURLLoader::Shutdown() { … }
bool KeepAliveURLLoader::IsFetchLater() const { … }
void KeepAliveURLLoader::SendNow() { … }
void KeepAliveURLLoader::Cancel() { … }
void KeepAliveURLLoader::DeleteSelf() { … }
void KeepAliveURLLoader::SetObserverForTesting(
scoped_refptr<TestObserver> observer) { … }
void KeepAliveURLLoader::LogFetchKeepAliveRequestMetric(
std::string_view request_state_name) { … }
}