Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Sreeja Kamishetty | c227f7a | 2022-07-08 22:33:15 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_ATTRIBUTES_H_ |
| 6 | #define CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_ATTRIBUTES_H_ |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 7 | |
Liviu Tinta | cf066d5 | 2024-07-24 16:00:55 | [diff] [blame] | 8 | #include <optional> |
Asami Doi | 0240627 | 2021-11-12 05:01:44 | [diff] [blame] | 9 | #include <string> |
| 10 | |
kenoss | c3f9a2c | 2025-03-06 15:35:51 | [diff] [blame] | 11 | #include "content/browser/preloading/preload_pipeline_info_impl.h" |
Hiroki Nakagawa | eeecc56e | 2025-03-27 02:57:30 | [diff] [blame] | 12 | #include "content/browser/preloading/speculation_rules/speculation_rules_params.h" |
Lei Zhang | 7ab31375 | 2021-11-17 01:26:00 | [diff] [blame] | 13 | #include "content/common/content_export.h" |
Avi Drissman | dcc8e68 | 2024-09-04 14:14:48 | [diff] [blame] | 14 | #include "content/public/browser/frame_tree_node_id.h" |
kenoss | c3f9a2c | 2025-03-06 15:35:51 | [diff] [blame] | 15 | #include "content/public/browser/preload_pipeline_info.h" |
Domenic Denicola | bb5d843c | 2023-07-18 01:47:33 | [diff] [blame] | 16 | #include "content/public/browser/preloading.h" |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 17 | #include "content/public/browser/preloading_trigger_type.h" |
Hiroki Nakagawa | b930733e | 2023-01-04 16:40:52 | [diff] [blame] | 18 | #include "content/public/browser/web_contents.h" |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 19 | #include "content/public/common/referrer.h" |
Liviu Tinta | 44e732aa | 2024-05-28 15:52:36 | [diff] [blame] | 20 | #include "net/http/http_no_vary_search_data.h" |
Hiroki Nakagawa | 8348bc4 | 2024-12-13 16:24:42 | [diff] [blame] | 21 | #include "net/http/http_request_headers.h" |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 22 | #include "services/metrics/public/cpp/ukm_source_id.h" |
| 23 | #include "third_party/blink/public/mojom/navigation/navigation_params.mojom.h" |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 24 | #include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h" |
Robert Lin | cf48356 | 2021-12-01 00:29:55 | [diff] [blame] | 25 | #include "ui/base/page_transition_types.h" |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 26 | |
| 27 | namespace content { |
| 28 | |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 29 | // Records the basic attributes of a prerender request. |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 30 | struct CONTENT_EXPORT PrerenderAttributes { |
Lingqi Chi | 8ebe71e | 2024-10-22 07:08:39 | [diff] [blame] | 31 | // - `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 Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 41 | PrerenderAttributes( |
| 42 | const GURL& prerendering_url, |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 43 | PreloadingTriggerType trigger_type, |
Asami Doi | 0240627 | 2021-11-12 05:01:44 | [diff] [blame] | 44 | const std::string& embedder_histogram_suffix, |
Hiroki Nakagawa | eeecc56e | 2025-03-27 02:57:30 | [diff] [blame] | 45 | std::optional<SpeculationRulesParams> speculation_rules_params, |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 46 | Referrer referrer, |
Rulong Chen(陈汝龙) | bf12169c | 2024-12-16 05:38:16 | [diff] [blame] | 47 | std::optional<net::HttpNoVarySearchData> no_vary_search_hint, |
Lingqi Chi | 8ebe71e | 2024-10-22 07:08:39 | [diff] [blame] | 48 | RenderFrameHost* initiator_render_frame_host, |
Hiroki Nakagawa | b930733e | 2023-01-04 16:40:52 | [diff] [blame] | 49 | base::WeakPtr<WebContents> initiator_web_contents, |
Lingqi Chi | 21d9feb | 2022-02-02 09:42:18 | [diff] [blame] | 50 | ui::PageTransition transition_type, |
Taiyo Mizuhashi | bc91f80 | 2024-06-20 19:37:22 | [diff] [blame] | 51 | bool should_warm_up_compositor, |
Lingqi Chi | a2efa8c | 2024-11-08 10:20:29 | [diff] [blame] | 52 | bool should_prepare_paint_tree, |
Lingqi Chi | bc88ab5 | 2025-07-24 00:54:14 | [diff] [blame] | 53 | bool should_pause_javascript_execution, |
Liviu Tinta | cf066d5 | 2024-07-24 16:00:55 | [diff] [blame] | 54 | base::RepeatingCallback<bool(const GURL&, |
| 55 | const std::optional<UrlMatchType>&)> |
| 56 | url_match_predicate, |
Arthur Sonzogni | fd1e08d | 2024-03-05 15:59:36 | [diff] [blame] | 57 | base::RepeatingCallback<void(NavigationHandle&)> |
HuanPo Lin | 2ebb36c | 2023-10-06 01:48:48 | [diff] [blame] | 58 | prerender_navigation_handle_callback, |
Jiacheng Guo | ea20d39 | 2025-07-07 01:08:14 | [diff] [blame] | 59 | scoped_refptr<PreloadPipelineInfoImpl> preload_pipeline_info, |
| 60 | bool allow_reuse); |
Lingqi Chi | 21d9feb | 2022-02-02 09:42:18 | [diff] [blame] | 61 | |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 62 | ~PrerenderAttributes(); |
Hiroki Nakagawa | eeecc56e | 2025-03-27 02:57:30 | [diff] [blame] | 63 | |
| 64 | // Copyable and movable. |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 65 | PrerenderAttributes(const PrerenderAttributes&); |
Kevin McNee | d0c35522 | 2024-04-30 17:46:28 | [diff] [blame] | 66 | PrerenderAttributes& operator=(const PrerenderAttributes&); |
Hiroki Nakagawa | eeecc56e | 2025-03-27 02:57:30 | [diff] [blame] | 67 | PrerenderAttributes(PrerenderAttributes&&) noexcept; |
| 68 | PrerenderAttributes& operator=(PrerenderAttributes&&) noexcept; |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 69 | |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 70 | bool IsBrowserInitiated() const { return !initiator_origin.has_value(); } |
| 71 | |
Hiroki Nakagawa | eeecc56e | 2025-03-27 02:57:30 | [diff] [blame] | 72 | std::optional<blink::mojom::SpeculationTargetHint> GetTargetHint() const; |
| 73 | std::optional<blink::mojom::SpeculationEagerness> GetEagerness() const; |
Hiroki Nakagawa | d60f9ff | 2025-03-27 04:20:27 | [diff] [blame] | 74 | std::optional<SpeculationRulesTags> GetTags() const; |
Hiroki Nakagawa | eeecc56e | 2025-03-27 02:57:30 | [diff] [blame] | 75 | |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 76 | GURL prerendering_url; |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 77 | |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 78 | PreloadingTriggerType trigger_type; |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 79 | |
Asami Doi | 0240627 | 2021-11-12 05:01:44 | [diff] [blame] | 80 | // 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 Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 84 | // This is std::nullopt when prerendering is initiated by browser. |
Hiroki Nakagawa | eeecc56e | 2025-03-27 02:57:30 | [diff] [blame] | 85 | std::optional<SpeculationRulesParams> speculation_rules_params; |
Hiroki Nakagawa | 134ada6 | 2023-10-16 10:50:26 | [diff] [blame] | 86 | |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 87 | Referrer referrer; |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 88 | |
Hiroki Nakagawa | 8348bc4 | 2024-12-13 16:24:42 | [diff] [blame] | 89 | #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 Tinta | 44e732aa | 2024-05-28 15:52:36 | [diff] [blame] | 95 | // 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(陈汝龙) | bf12169c | 2024-12-16 05:38:16 | [diff] [blame] | 97 | std::optional<net::HttpNoVarySearchData> no_vary_search_hint; |
Liviu Tinta | 44e732aa | 2024-05-28 15:52:36 | [diff] [blame] | 98 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 99 | // This is std::nullopt when prerendering is initiated by the browser |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 100 | // (not by a renderer using Speculation Rules API). |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 101 | std::optional<url::Origin> initiator_origin; |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 102 | |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 103 | // This is ChildProcessHost::kInvalidUniqueID when prerendering is initiated |
| 104 | // by the browser. |
Kevin McNee | 4396e1e | 2023-09-08 15:17:12 | [diff] [blame] | 105 | int initiator_process_id = ChildProcessHost::kInvalidUniqueID; |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 106 | |
Hiroki Nakagawa | b930733e | 2023-01-04 16:40:52 | [diff] [blame] | 107 | // This hosts a primary page that is initiating this prerender attempt. |
| 108 | base::WeakPtr<WebContents> initiator_web_contents; |
| 109 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 110 | // This is std::nullopt when prerendering is initiated by the browser. |
| 111 | std::optional<blink::LocalFrameToken> initiator_frame_token; |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 112 | |
Avi Drissman | dcc8e68 | 2024-09-04 14:14:48 | [diff] [blame] | 113 | // This is invalid when prerendering is initiated by the browser. |
| 114 | FrameTreeNodeId initiator_frame_tree_node_id; |
Robert Lin | 286e2eb9 | 2022-05-10 23:41:53 | [diff] [blame] | 115 | |
Robert Lin | c37fb58 | 2021-11-11 03:18:47 | [diff] [blame] | 116 | // This is ukm::kInvalidSourceId when prerendering is initiated by the |
| 117 | // browser. |
Kevin McNee | 4396e1e | 2023-09-08 15:17:12 | [diff] [blame] | 118 | ukm::SourceId initiator_ukm_id = ukm::kInvalidSourceId; |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 119 | |
Robert Lin | cf48356 | 2021-12-01 00:29:55 | [diff] [blame] | 120 | ui::PageTransition transition_type; |
| 121 | |
Taiyo Mizuhashi | bc91f80 | 2024-06-20 19:37:22 | [diff] [blame] | 122 | // 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 Chi | a2efa8c | 2024-11-08 10:20:29 | [diff] [blame] | 127 | // 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 Chi | bc88ab5 | 2025-07-24 00:54:14 | [diff] [blame] | 131 | // Whether to pause the renderer process's JavaScript execution. |
| 132 | bool should_pause_javascript_execution = false; |
| 133 | |
Domenic Denicola | bb5d843c | 2023-07-18 01:47:33 | [diff] [blame] | 134 | // 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 Nakagawa | 64cc27c | 2022-02-03 02:11:14 | [diff] [blame] | 140 | // 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 Tinta | cf066d5 | 2024-07-24 16:00:55 | [diff] [blame] | 143 | base::RepeatingCallback<bool(const GURL&, const std::optional<UrlMatchType>&)> |
| 144 | url_match_predicate; |
Lingqi Chi | 21d9feb | 2022-02-02 09:42:18 | [diff] [blame] | 145 | |
Arthur Sonzogni | fd1e08d | 2024-03-05 15:59:36 | [diff] [blame] | 146 | base::RepeatingCallback<void(NavigationHandle&)> |
HuanPo Lin | 2ebb36c | 2023-10-06 01:48:48 | [diff] [blame] | 147 | prerender_navigation_handle_callback; |
| 148 | |
kenoss | 3bd73b8 | 2024-10-10 20:33:49 | [diff] [blame] | 149 | // Information of preload pipeline that this prerender belongs to. |
kenoss | c3f9a2c | 2025-03-06 15:35:51 | [diff] [blame] | 150 | scoped_refptr<PreloadPipelineInfoImpl> preload_pipeline_info; |
kenoss | 3bd73b8 | 2024-10-10 20:33:49 | [diff] [blame] | 151 | |
Jiacheng Guo | ea20d39 | 2025-07-07 01:08:14 | [diff] [blame] | 152 | // Whether the created prerender host can be reused for future navigations. |
| 153 | bool allow_reuse = false; |
| 154 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 155 | // This is std::nullopt when prerendering is initiated by the browser. |
| 156 | std::optional<base::UnguessableToken> initiator_devtools_navigation_token; |
Robert Lin | a5f5ca7 | 2023-03-23 02:44:48 | [diff] [blame] | 157 | |
Lingqi Chi | ca31e24 | 2021-09-24 03:54:16 | [diff] [blame] | 158 | // Serialises this struct into a trace. |
| 159 | void WriteIntoTrace(perfetto::TracedValue trace_context) const; |
| 160 | }; |
| 161 | |
| 162 | } // namespace content |
| 163 | |
Sreeja Kamishetty | c227f7a | 2022-07-08 22:33:15 | [diff] [blame] | 164 | #endif // CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_ATTRIBUTES_H_ |