#include "content/browser/preloading/prerender/prerender_host.h"
#include <memory>
#include <optional>
#include "base/debug/alias.h"
#include "base/feature_list.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/run_loop.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/trace_event/typed_macros.h"
#include "content/browser/client_hints/client_hints.h"
#include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/preloading/prefetch/no_vary_search_helper.h"
#include "content/browser/preloading/preloading_attempt_impl.h"
#include "content/browser/preloading/preloading_trigger_type_impl.h"
#include "content/browser/preloading/prerender/devtools_prerender_attempt.h"
#include "content/browser/preloading/prerender/prerender_features.h"
#include "content/browser/preloading/prerender/prerender_final_status.h"
#include "content/browser/preloading/prerender/prerender_host_registry.h"
#include "content/browser/preloading/prerender/prerender_metrics.h"
#include "content/browser/renderer_host/frame_tree.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/navigation_controller_impl.h"
#include "content/browser/renderer_host/navigation_entry_restore_context_impl.h"
#include "content/browser/renderer_host/navigation_request.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/preloading_trigger_type.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/referrer.h"
#include "net/base/load_flags.h"
#include "net/http/http_request_headers.h"
#include "third_party/blink/public/common/client_hints/enabled_client_hints.h"
#include "third_party/blink/public/common/features.h"
#include "url/origin.h"
namespace content {
namespace {
base::OnceCallback<void(int)>& GetHostCreationCallbackForTesting() { … }
}
PrerenderHost* PrerenderHost::GetFromFrameTreeNodeIfPrerendering(
FrameTreeNode& frame_tree_node) { … }
PrerenderHost& PrerenderHost::GetFromFrameTreeNode(
FrameTreeNode& frame_tree_node) { … }
bool PrerenderHost::AreHttpRequestHeadersCompatible(
const std::string& potential_activation_headers_str,
const std::string& prerender_headers_str,
PreloadingTriggerType trigger_type,
const std::string& histogram_suffix,
PrerenderCancellationReason& reason) { … }
void PrerenderHost::SetHostCreationCallbackForTesting(
base::OnceCallback<void(int host_id)> callback) { … }
PrerenderHost::PrerenderHost(
const PrerenderAttributes& attributes,
WebContentsImpl& web_contents,
base::WeakPtr<PreloadingAttempt> attempt,
std::unique_ptr<DevToolsPrerenderAttempt> devtools_attempt)
: … { … }
bool PrerenderHost::IsActivationHeaderMatch(
const net::HttpRequestHeaders& potential_activation_headers,
const net::HttpRequestHeaders& prerender_headers,
PrerenderCancellationReason& reason) { … }
PrerenderHost::~PrerenderHost() { … }
void PrerenderHost::DidStopLoading() { … }
bool PrerenderHost::IsHidden() { … }
FrameTree* PrerenderHost::LoadingTree() { … }
void PrerenderHost::SetFocusedFrame(FrameTreeNode* node,
SiteInstanceGroup* source) { … }
FrameTree* PrerenderHost::GetOwnedPictureInPictureFrameTree() { … }
FrameTree* PrerenderHost::GetPictureInPictureOpenerFrameTree() { … }
int PrerenderHost::GetOuterDelegateFrameTreeNodeId() { … }
RenderFrameHostImpl* PrerenderHost::GetProspectiveOuterDocument() { … }
void PrerenderHost::ActivateAndShowRepostFormWarningDialog() { … }
bool PrerenderHost::ShouldPreserveAbortedURLs() { … }
bool PrerenderHost::StartPrerendering() { … }
void PrerenderHost::DidStartNavigation(NavigationHandle* navigation_handle) { … }
void PrerenderHost::ReadyToCommitNavigation(
NavigationHandle* navigation_handle) { … }
void PrerenderHost::DidFinishNavigation(NavigationHandle* navigation_handle) { … }
std::unique_ptr<StoredPage> PrerenderHost::Activate(
NavigationRequest& navigation_request) { … }
bool PrerenderHost::IsFramePolicyCompatibleWithPrimaryFrameTree() { … }
bool PrerenderHost::AreInitialPrerenderNavigationParamsCompatibleWithNavigation(
NavigationRequest& navigation_request,
PrerenderCancellationReason& reason) { … }
PrerenderHost::ActivationNavigationParamsMatch
PrerenderHost::AreBeginNavigationParamsCompatibleWithNavigation(
const blink::mojom::BeginNavigationParams& potential_activation,
bool allow_initiator_and_transition_mismatch,
PrerenderCancellationReason& reason) { … }
PrerenderHost::ActivationNavigationParamsMatch
PrerenderHost::AreCommonNavigationParamsCompatibleWithNavigation(
const blink::mojom::CommonNavigationParams& potential_activation,
bool allow_initiator_and_transition_mismatch) { … }
RenderFrameHostImpl* PrerenderHost::GetPrerenderedMainFrameHost() { … }
FrameTree& PrerenderHost::GetPrerenderFrameTree() { … }
void PrerenderHost::RecordFailedFinalStatus(
base::PassKey<PrerenderHostRegistry>,
const PrerenderCancellationReason& reason) { … }
void PrerenderHost::RecordFailedFinalStatusImpl(
const PrerenderCancellationReason& reason) { … }
void PrerenderHost::RecordActivation(NavigationRequest& navigation_request) { … }
PrerenderHost::LoadingOutcome PrerenderHost::WaitForLoadStopForTesting() { … }
const GURL& PrerenderHost::GetInitialUrl() const { … }
void PrerenderHost::AddObserver(Observer* observer) { … }
void PrerenderHost::RemoveObserver(Observer* observer) { … }
std::optional<int64_t> PrerenderHost::GetInitialNavigationId() const { … }
void PrerenderHost::SetInitialNavigation(NavigationRequest* navigation) { … }
void PrerenderHost::SetTriggeringOutcome(PreloadingTriggeringOutcome outcome) { … }
void PrerenderHost::SetFailureReason(
const PrerenderCancellationReason& reason) { … }
std::optional<UrlMatchType> PrerenderHost::IsUrlMatch(const GURL& url) const { … }
bool PrerenderHost::IsNoVarySearchHintUrlMatch(const GURL& url) const { … }
void PrerenderHost::OnAcceptClientHintChanged(
const url::Origin& origin,
const std::vector<network::mojom::WebClientHintsType>& client_hints_type) { … }
void PrerenderHost::GetAllowedClientHintsOnPage(
const url::Origin& origin,
blink::EnabledClientHints* client_hints) const { … }
std::string PrerenderHost::GetHistogramSuffix() const { … }
void PrerenderHost::Cancel(PrerenderFinalStatus status) { … }
void PrerenderHost::MaybeSetNoVarySearch(
network::mojom::NoVarySearchWithParseError&
no_vary_search_with_parse_error) { … }
bool PrerenderHost::IsInitialNavigation(
const NavigationRequest& navigation_request) const { … }
base::TimeDelta PrerenderHost::WaitUntilHeadTimeout() { … }
void PrerenderHost::OnWaitingForHeadersStarted(
NavigationHandle& navigation_handle,
WaitingForHeadersStartedReason reason) { … }
void PrerenderHost::OnWaitingForHeadersFinished(
NavigationHandle& navigation_handle,
WaitingForHeadersFinishedReason reason) { … }
}