blob: cdc193f1046fd077cf1b036d10eb66edc57876ac [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2021 The Chromium Authors
Lingqi Chica31e242021-09-24 03:54:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Sreeja Kamishettyc227f7a2022-07-08 22:33:155#include "content/browser/preloading/prerender/prerender_attributes.h"
Asami Doicf0f1642021-11-25 05:00:266
Liviu Tintacf066d52024-07-24 16:00:557#include <optional>
8
Lingqi Chi8ebe71e2024-10-22 07:08:399#include "content/browser/renderer_host/render_frame_host_impl.h"
10#include "content/public/browser/render_frame_host.h"
Lingqi Chica31e242021-09-24 03:54:1611#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
12
13namespace content {
14
15void PrerenderAttributes::WriteIntoTrace(
16 perfetto::TracedValue trace_context) const {
17 auto dict = std::move(trace_context).WriteDictionary();
Robert Lind75062bf2021-10-28 12:50:5518 dict.Add("url", prerendering_url);
Lingqi Chica31e242021-09-24 03:54:1619 dict.Add("trigger_type", trigger_type);
20}
21
Robert Lind75062bf2021-10-28 12:50:5522PrerenderAttributes::PrerenderAttributes(
23 const GURL& prerendering_url,
Kouhei Ueno3f37992b2023-11-09 23:29:0224 PreloadingTriggerType trigger_type,
Asami Doi02406272021-11-12 05:01:4425 const std::string& embedder_histogram_suffix,
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3026 std::optional<SpeculationRulesParams> speculation_rules_params,
Robert Lind75062bf2021-10-28 12:50:5527 Referrer referrer,
Rulong Chen(陈汝龙)bf12169c2024-12-16 05:38:1628 std::optional<net::HttpNoVarySearchData> no_vary_search_hint,
Lingqi Chi8ebe71e2024-10-22 07:08:3929 RenderFrameHost* initiator_render_frame_host,
Hiroki Nakagawab930733e2023-01-04 16:40:5230 base::WeakPtr<WebContents> initiator_web_contents,
Lingqi Chi21d9feb2022-02-02 09:42:1831 ui::PageTransition transition_type,
Taiyo Mizuhashibc91f802024-06-20 19:37:2232 bool should_warm_up_compositor,
Lingqi Chia2efa8c2024-11-08 10:20:2933 bool should_prepare_paint_tree,
Lingqi Chibc88ab52025-07-24 00:54:1434 bool should_pause_javascript_execution,
Liviu Tintacf066d52024-07-24 16:00:5535 base::RepeatingCallback<bool(const GURL&,
36 const std::optional<UrlMatchType>&)>
37 url_match_predicate,
Arthur Sonzognifd1e08d2024-03-05 15:59:3638 base::RepeatingCallback<void(NavigationHandle&)>
HuanPo Lin2ebb36c2023-10-06 01:48:4839 prerender_navigation_handle_callback,
Jiacheng Guoea20d392025-07-07 01:08:1440 scoped_refptr<PreloadPipelineInfoImpl> preload_pipeline_info,
41 bool allow_reuse)
Robert Lind75062bf2021-10-28 12:50:5542 : prerendering_url(prerendering_url),
43 trigger_type(trigger_type),
Asami Doi02406272021-11-12 05:01:4444 embedder_histogram_suffix(embedder_histogram_suffix),
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3045 speculation_rules_params(std::move(speculation_rules_params)),
Kevin McNeed0c355222024-04-30 17:46:2846 referrer(std::move(referrer)),
Rulong Chen(陈汝龙)bf12169c2024-12-16 05:38:1647 no_vary_search_hint(std::move(no_vary_search_hint)),
Hiroki Nakagawab930733e2023-01-04 16:40:5248 initiator_web_contents(std::move(initiator_web_contents)),
Lingqi Chi21d9feb2022-02-02 09:42:1849 transition_type(transition_type),
Taiyo Mizuhashibc91f802024-06-20 19:37:2250 should_warm_up_compositor(should_warm_up_compositor),
Lingqi Chia2efa8c2024-11-08 10:20:2951 should_prepare_paint_tree(should_prepare_paint_tree),
Lingqi Chibc88ab52025-07-24 00:54:1452 should_pause_javascript_execution(should_pause_javascript_execution),
Robert Lina5f5ca72023-03-23 02:44:4853 url_match_predicate(std::move(url_match_predicate)),
HuanPo Lin2ebb36c2023-10-06 01:48:4854 prerender_navigation_handle_callback(
55 std::move(prerender_navigation_handle_callback)),
Jiacheng Guoea20d392025-07-07 01:08:1456 preload_pipeline_info(std::move(preload_pipeline_info)),
57 allow_reuse(allow_reuse) {
Lingqi Chi8ebe71e2024-10-22 07:08:3958 if (initiator_render_frame_host) {
59 initiator_origin = initiator_render_frame_host->GetLastCommittedOrigin();
Emily Andrewsd15fd762024-12-10 20:41:5460 initiator_process_id =
61 initiator_render_frame_host->GetProcess()->GetDeprecatedID();
Lingqi Chi8ebe71e2024-10-22 07:08:3962 initiator_frame_token = initiator_render_frame_host->GetFrameToken();
63 initiator_frame_tree_node_id =
64 initiator_render_frame_host->GetFrameTreeNodeId();
65 initiator_ukm_id = initiator_render_frame_host->GetPageUkmSourceId();
66 auto* rfhi = static_cast<RenderFrameHostImpl*>(initiator_render_frame_host);
67 initiator_devtools_navigation_token = rfhi->GetDevToolsNavigationToken();
68 }
69
Robert Lina5f5ca72023-03-23 02:44:4870 CHECK(!IsBrowserInitiated() ||
71 !initiator_devtools_navigation_token.has_value());
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3072 CHECK(!IsBrowserInitiated() || !this->speculation_rules_params.has_value());
Robert Lina5f5ca72023-03-23 02:44:4873}
Robert Lind75062bf2021-10-28 12:50:5574
75PrerenderAttributes::~PrerenderAttributes() = default;
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3076
Kevin McNeed0c355222024-04-30 17:46:2877PrerenderAttributes::PrerenderAttributes(const PrerenderAttributes&) = default;
78PrerenderAttributes& PrerenderAttributes::operator=(
79 const PrerenderAttributes&) = default;
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3080PrerenderAttributes::PrerenderAttributes(PrerenderAttributes&&) noexcept =
Kevin McNeed0c355222024-04-30 17:46:2881 default;
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3082PrerenderAttributes& PrerenderAttributes::operator=(
83 PrerenderAttributes&&) noexcept = default;
84
85std::optional<blink::mojom::SpeculationTargetHint>
86PrerenderAttributes::GetTargetHint() const {
87 return speculation_rules_params.has_value()
88 ? std::make_optional(speculation_rules_params->target_hint)
89 : std::nullopt;
90}
91
92std::optional<blink::mojom::SpeculationEagerness>
93PrerenderAttributes::GetEagerness() const {
94 return speculation_rules_params.has_value()
95 ? std::make_optional(speculation_rules_params->eagerness)
96 : std::nullopt;
97}
Robert Lind75062bf2021-10-28 12:50:5598
Hiroki Nakagawad60f9ff2025-03-27 04:20:2799std::optional<SpeculationRulesTags> PrerenderAttributes::GetTags() const {
Hiroki Nakagawac91e36222025-05-02 11:00:27100 return speculation_rules_params.has_value()
101 ? std::make_optional(speculation_rules_params->tags)
102 : std::nullopt;
Hiroki Nakagawad60f9ff2025-03-27 04:20:27103}
104
Lingqi Chica31e242021-09-24 03:54:16105} // namespace content