blob: 776c2bf064a1e419bdf4f8c0d1645a7c6b2312f6 [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#ifndef CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_ATTRIBUTES_H_
6#define CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_ATTRIBUTES_H_
Lingqi Chica31e242021-09-24 03:54:167
Liviu Tintacf066d52024-07-24 16:00:558#include <optional>
Asami Doi02406272021-11-12 05:01:449#include <string>
10
kenossc3f9a2c2025-03-06 15:35:5111#include "content/browser/preloading/preload_pipeline_info_impl.h"
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3012#include "content/browser/preloading/speculation_rules/speculation_rules_params.h"
Lei Zhang7ab313752021-11-17 01:26:0013#include "content/common/content_export.h"
Avi Drissmandcc8e682024-09-04 14:14:4814#include "content/public/browser/frame_tree_node_id.h"
kenossc3f9a2c2025-03-06 15:35:5115#include "content/public/browser/preload_pipeline_info.h"
Domenic Denicolabb5d843c2023-07-18 01:47:3316#include "content/public/browser/preloading.h"
Kouhei Ueno3f37992b2023-11-09 23:29:0217#include "content/public/browser/preloading_trigger_type.h"
Hiroki Nakagawab930733e2023-01-04 16:40:5218#include "content/public/browser/web_contents.h"
Lingqi Chica31e242021-09-24 03:54:1619#include "content/public/common/referrer.h"
Liviu Tinta44e732aa2024-05-28 15:52:3620#include "net/http/http_no_vary_search_data.h"
Hiroki Nakagawa8348bc42024-12-13 16:24:4221#include "net/http/http_request_headers.h"
Robert Lind75062bf2021-10-28 12:50:5522#include "services/metrics/public/cpp/ukm_source_id.h"
23#include "third_party/blink/public/mojom/navigation/navigation_params.mojom.h"
Lingqi Chica31e242021-09-24 03:54:1624#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
Robert Lincf483562021-12-01 00:29:5525#include "ui/base/page_transition_types.h"
Lingqi Chica31e242021-09-24 03:54:1626
27namespace content {
28
Lingqi Chica31e242021-09-24 03:54:1629// Records the basic attributes of a prerender request.
Robert Lind75062bf2021-10-28 12:50:5530struct CONTENT_EXPORT PrerenderAttributes {
Lingqi Chi8ebe71e2024-10-22 07:08:3931 // - `prerendering_url` indicates the initial URL of the prerender request.
32 // The real url might be changed during the prerendering navigation, e.g.,
33 // redirection.
34 // - `initiator_render_frame_host`: the render frame host that initiates this
35 // prerender request. It could be null if the prerender is initiated by
36 // browser.
37 // - `initiator_web_contents`: the web contents that the initiator render
38 // frame host belongs to. Note that `initiator_web_contents` is non-null
39 // even if `initiator_render_frame_host` is null, because the attempted
40 // prerender could be triggered by other components of a WebContents.
Robert Linc37fb582021-11-11 03:18:4741 PrerenderAttributes(
42 const GURL& prerendering_url,
Kouhei Ueno3f37992b2023-11-09 23:29:0243 PreloadingTriggerType trigger_type,
Asami Doi02406272021-11-12 05:01:4444 const std::string& embedder_histogram_suffix,
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3045 std::optional<SpeculationRulesParams> speculation_rules_params,
Robert Linc37fb582021-11-11 03:18:4746 Referrer referrer,
Rulong Chen(陈汝龙)bf12169c2024-12-16 05:38:1647 std::optional<net::HttpNoVarySearchData> no_vary_search_hint,
Lingqi Chi8ebe71e2024-10-22 07:08:3948 RenderFrameHost* initiator_render_frame_host,
Hiroki Nakagawab930733e2023-01-04 16:40:5249 base::WeakPtr<WebContents> initiator_web_contents,
Lingqi Chi21d9feb2022-02-02 09:42:1850 ui::PageTransition transition_type,
Taiyo Mizuhashibc91f802024-06-20 19:37:2251 bool should_warm_up_compositor,
Lingqi Chia2efa8c2024-11-08 10:20:2952 bool should_prepare_paint_tree,
Lingqi Chibc88ab52025-07-24 00:54:1453 bool should_pause_javascript_execution,
Liviu Tintacf066d52024-07-24 16:00:5554 base::RepeatingCallback<bool(const GURL&,
55 const std::optional<UrlMatchType>&)>
56 url_match_predicate,
Arthur Sonzognifd1e08d2024-03-05 15:59:3657 base::RepeatingCallback<void(NavigationHandle&)>
HuanPo Lin2ebb36c2023-10-06 01:48:4858 prerender_navigation_handle_callback,
Jiacheng Guoea20d392025-07-07 01:08:1459 scoped_refptr<PreloadPipelineInfoImpl> preload_pipeline_info,
60 bool allow_reuse);
Lingqi Chi21d9feb2022-02-02 09:42:1861
Robert Lind75062bf2021-10-28 12:50:5562 ~PrerenderAttributes();
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3063
64 // Copyable and movable.
Robert Lind75062bf2021-10-28 12:50:5565 PrerenderAttributes(const PrerenderAttributes&);
Kevin McNeed0c355222024-04-30 17:46:2866 PrerenderAttributes& operator=(const PrerenderAttributes&);
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3067 PrerenderAttributes(PrerenderAttributes&&) noexcept;
68 PrerenderAttributes& operator=(PrerenderAttributes&&) noexcept;
Robert Lind75062bf2021-10-28 12:50:5569
Robert Linc37fb582021-11-11 03:18:4770 bool IsBrowserInitiated() const { return !initiator_origin.has_value(); }
71
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3072 std::optional<blink::mojom::SpeculationTargetHint> GetTargetHint() const;
73 std::optional<blink::mojom::SpeculationEagerness> GetEagerness() const;
Hiroki Nakagawad60f9ff2025-03-27 04:20:2774 std::optional<SpeculationRulesTags> GetTags() const;
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3075
Robert Lind75062bf2021-10-28 12:50:5576 GURL prerendering_url;
Robert Linc37fb582021-11-11 03:18:4777
Kouhei Ueno3f37992b2023-11-09 23:29:0278 PreloadingTriggerType trigger_type;
Robert Linc37fb582021-11-11 03:18:4779
Asami Doi02406272021-11-12 05:01:4480 // Used for kEmbedder trigger type to avoid exposing information of embedders
81 // to content/. Only used for metrics.
82 std::string embedder_histogram_suffix;
83
Arthur Sonzognic686e8f2024-01-11 08:36:3784 // This is std::nullopt when prerendering is initiated by browser.
Hiroki Nakagawaeeecc56e2025-03-27 02:57:3085 std::optional<SpeculationRulesParams> speculation_rules_params;
Hiroki Nakagawa134ada62023-10-16 10:50:2686
Lingqi Chica31e242021-09-24 03:54:1687 Referrer referrer;
Robert Linc37fb582021-11-11 03:18:4788
Hiroki Nakagawa8348bc42024-12-13 16:24:4289#if BUILDFLAG(IS_ANDROID)
90 // Additional headers to be attached to prerendering navigation. Currently
91 // this is used only for Android WebView.
92 net::HttpRequestHeaders additional_headers;
93#endif // BUILDFLAG(IS_ANDROID)
94
Liviu Tinta44e732aa2024-05-28 15:52:3695 // Records the No-Vary-Search hint of the corresponding speculation rule.
96 // This is std::nullopt when No-Vary-Search hint is not specified.
Rulong Chen(陈汝龙)bf12169c2024-12-16 05:38:1697 std::optional<net::HttpNoVarySearchData> no_vary_search_hint;
Liviu Tinta44e732aa2024-05-28 15:52:3698
Arthur Sonzognic686e8f2024-01-11 08:36:3799 // This is std::nullopt when prerendering is initiated by the browser
Robert Linc37fb582021-11-11 03:18:47100 // (not by a renderer using Speculation Rules API).
Arthur Sonzognic686e8f2024-01-11 08:36:37101 std::optional<url::Origin> initiator_origin;
Robert Linc37fb582021-11-11 03:18:47102
Robert Linc37fb582021-11-11 03:18:47103 // This is ChildProcessHost::kInvalidUniqueID when prerendering is initiated
104 // by the browser.
Kevin McNee4396e1e2023-09-08 15:17:12105 int initiator_process_id = ChildProcessHost::kInvalidUniqueID;
Robert Linc37fb582021-11-11 03:18:47106
Hiroki Nakagawab930733e2023-01-04 16:40:52107 // This hosts a primary page that is initiating this prerender attempt.
108 base::WeakPtr<WebContents> initiator_web_contents;
109
Arthur Sonzognic686e8f2024-01-11 08:36:37110 // This is std::nullopt when prerendering is initiated by the browser.
111 std::optional<blink::LocalFrameToken> initiator_frame_token;
Robert Linc37fb582021-11-11 03:18:47112
Avi Drissmandcc8e682024-09-04 14:14:48113 // This is invalid when prerendering is initiated by the browser.
114 FrameTreeNodeId initiator_frame_tree_node_id;
Robert Lin286e2eb92022-05-10 23:41:53115
Robert Linc37fb582021-11-11 03:18:47116 // This is ukm::kInvalidSourceId when prerendering is initiated by the
117 // browser.
Kevin McNee4396e1e2023-09-08 15:17:12118 ukm::SourceId initiator_ukm_id = ukm::kInvalidSourceId;
Lingqi Chica31e242021-09-24 03:54:16119
Robert Lincf483562021-12-01 00:29:55120 ui::PageTransition transition_type;
121
Taiyo Mizuhashibc91f802024-06-20 19:37:22122 // If true, warms up compositor on a certain loading event of prerender
123 // initial navigation. Please see crbug.com/41496019 and comments on
124 // Page::should_warm_up_compositor_on_prerender_ for more details.
125 bool should_warm_up_compositor = false;
126
Lingqi Chia2efa8c2024-11-08 10:20:29127 // Whether to dry run paint phase to pre-build a paint tree for the page, so
128 // then the intermediate result can be reused after activation.
129 bool should_prepare_paint_tree = false;
130
Lingqi Chibc88ab52025-07-24 00:54:14131 // Whether to pause the renderer process's JavaScript execution.
132 bool should_pause_javascript_execution = false;
133
Domenic Denicolabb5d843c2023-07-18 01:47:33134 // If the caller wants to override the default holdback processing, they can
135 // set this. Otherwise, it will be computed as part of
136 // PrerenderHostRegistry::CreateAndStartHost.
137 PreloadingHoldbackStatus holdback_status_override =
138 PreloadingHoldbackStatus::kUnspecified;
139
Hiroki Nakagawa64cc27c2022-02-03 02:11:14140 // Triggers can specify their own predicate judging whether two URLs are
141 // considered as pointing to the same destination. The URLs must be in
142 // same-origin.
Liviu Tintacf066d52024-07-24 16:00:55143 base::RepeatingCallback<bool(const GURL&, const std::optional<UrlMatchType>&)>
144 url_match_predicate;
Lingqi Chi21d9feb2022-02-02 09:42:18145
Arthur Sonzognifd1e08d2024-03-05 15:59:36146 base::RepeatingCallback<void(NavigationHandle&)>
HuanPo Lin2ebb36c2023-10-06 01:48:48147 prerender_navigation_handle_callback;
148
kenoss3bd73b82024-10-10 20:33:49149 // Information of preload pipeline that this prerender belongs to.
kenossc3f9a2c2025-03-06 15:35:51150 scoped_refptr<PreloadPipelineInfoImpl> preload_pipeline_info;
kenoss3bd73b82024-10-10 20:33:49151
Jiacheng Guoea20d392025-07-07 01:08:14152 // Whether the created prerender host can be reused for future navigations.
153 bool allow_reuse = false;
154
Arthur Sonzognic686e8f2024-01-11 08:36:37155 // This is std::nullopt when prerendering is initiated by the browser.
156 std::optional<base::UnguessableToken> initiator_devtools_navigation_token;
Robert Lina5f5ca72023-03-23 02:44:48157
Lingqi Chica31e242021-09-24 03:54:16158 // Serialises this struct into a trace.
159 void WriteIntoTrace(perfetto::TracedValue trace_context) const;
160};
161
162} // namespace content
163
Sreeja Kamishettyc227f7a2022-07-08 22:33:15164#endif // CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_ATTRIBUTES_H_