Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
danakj | c492bf8 | 2020-09-09 20:02:44 | [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 | |
| 5 | #ifndef CONTENT_BROWSER_RENDERER_HOST_NAVIGATION_REQUEST_H_ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_NAVIGATION_REQUEST_H_ |
| 7 | |
| 8 | #include <memory> |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 9 | #include <optional> |
Cammie Smith Barnes | a0da2cf | 2021-01-11 22:09:37 | [diff] [blame] | 10 | #include <string> |
Daniel Cheng | d08a43a | 2023-03-16 05:10:50 | [diff] [blame] | 11 | #include <utility> |
Cammie Smith Barnes | a0da2cf | 2021-01-11 22:09:37 | [diff] [blame] | 12 | #include <vector> |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 13 | |
Lukasz Anforowicz | 0e07b765 | 2021-06-04 18:27:51 | [diff] [blame] | 14 | #include "base/debug/crash_logging.h" |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 15 | #include "base/functional/callback.h" |
| 16 | #include "base/functional/callback_forward.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 17 | #include "base/memory/raw_ptr.h" |
Keishi Hattori | 130ae0a | 2023-03-27 03:48:47 | [diff] [blame] | 18 | #include "base/memory/raw_ptr_exclusion.h" |
David Bokan | 42f8dc2 | 2022-02-23 17:33:28 | [diff] [blame] | 19 | #include "base/memory/safe_ref.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 20 | #include "base/memory/weak_ptr.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 21 | #include "base/strings/string_util.h" |
| 22 | #include "base/time/time.h" |
| 23 | #include "base/timer/timer.h" |
| 24 | #include "build/build_config.h" |
Matt Menke | 4e20908 | 2021-11-09 04:59:31 | [diff] [blame] | 25 | #include "content/browser/fenced_frame/fenced_frame_url_mapping.h" |
Ming-Ying Chung | 977404c | 2023-11-08 12:30:10 | [diff] [blame] | 26 | #include "content/browser/loader/keep_alive_url_loader_service.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 27 | #include "content/browser/loader/navigation_url_loader_delegate.h" |
Yao Xiao | 58c2f2c | 2023-05-16 20:05:18 | [diff] [blame] | 28 | #include "content/browser/loader/subresource_proxying_url_loader_service.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 29 | #include "content/browser/navigation_subresource_loader_params.h" |
Keita Suzuki | 633dd486 | 2025-08-02 01:59:10 | [diff] [blame] | 30 | #include "content/browser/preloading/prerender/reserved_prerender_host_info.h" |
Jiacheng Guo | 2d8489d7 | 2025-08-18 06:51:14 | [diff] [blame] | 31 | #include "content/browser/prerender_host_id.h" |
Lei Zhang | a4ddcf65 | 2023-03-02 18:54:06 | [diff] [blame] | 32 | #include "content/browser/renderer_host/browsing_context_group_swap.h" |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 33 | #include "content/browser/renderer_host/commit_deferring_condition_runner.h" |
Giovanni Ortuño Urquidi | e0a77b4 | 2025-03-28 14:31:35 | [diff] [blame] | 34 | #include "content/browser/renderer_host/cookie_access_observers.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 35 | #include "content/browser/renderer_host/navigation_controller_impl.h" |
Titouan Rigoudy | 4f281953 | 2022-04-29 15:35:53 | [diff] [blame] | 36 | #include "content/browser/renderer_host/navigation_policy_container_builder.h" |
Takashi Toyoshima | 96a07bb | 2025-06-06 06:45:58 | [diff] [blame] | 37 | #include "content/browser/renderer_host/navigation_throttle_registry_impl.h" |
Miyoung Shin | 3299cbf | 2022-11-22 01:41:10 | [diff] [blame] | 38 | #include "content/browser/renderer_host/navigation_type.h" |
Antonio Sartori | 5ecc8b93 | 2021-03-05 06:56:10 | [diff] [blame] | 39 | #include "content/browser/renderer_host/render_frame_host_impl.h" |
Khushal Sagar | 91b54422 | 2024-03-12 17:36:59 | [diff] [blame] | 40 | #include "content/browser/renderer_host/scoped_view_transition_resources.h" |
Camille Lamy | 103a1b28 | 2024-04-17 01:11:36 | [diff] [blame] | 41 | #include "content/browser/security/coop/cross_origin_opener_policy_status.h" |
Camille Lamy | 36afacd | 2025-01-16 14:25:18 | [diff] [blame] | 42 | #include "content/browser/security/dip/document_isolation_policy_reporter.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 43 | #include "content/browser/site_instance_impl.h" |
Rakina Zata Amni | a229230 | 2023-04-04 06:22:11 | [diff] [blame] | 44 | #include "content/browser/webui/web_ui_controller_factory_registry.h" |
Stephan Hartmann | fd036971 | 2023-04-10 07:05:59 | [diff] [blame] | 45 | #include "content/browser/webui/web_ui_impl.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 46 | #include "content/common/content_export.h" |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 47 | #include "content/common/navigation_client.mojom-forward.h" |
Keita Suzuki | f300e44 | 2025-07-16 07:38:11 | [diff] [blame] | 48 | #include "content/public/browser/error_navigation_trigger.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 49 | #include "content/public/browser/global_routing_id.h" |
| 50 | #include "content/public/browser/navigation_handle.h" |
| 51 | #include "content/public/browser/navigation_throttle.h" |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 52 | #include "content/public/browser/preloading_trigger_type.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 53 | #include "content/public/browser/render_process_host_observer.h" |
Jeremy Roman | 04ad4e3f | 2021-12-22 18:54:54 | [diff] [blame] | 54 | #include "content/public/browser/weak_document_ptr.h" |
Rakina Zata Amni | a229230 | 2023-04-04 06:22:11 | [diff] [blame] | 55 | #include "content/public/browser/web_ui_controller.h" |
Patrick Monette | 779c154 | 2025-01-17 17:18:36 | [diff] [blame] | 56 | #include "content/public/common/content_constants.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 57 | #include "mojo/public/cpp/bindings/associated_remote.h" |
| 58 | #include "mojo/public/cpp/bindings/pending_associated_remote.h" |
| 59 | #include "mojo/public/cpp/bindings/pending_remote.h" |
| 60 | #include "mojo/public/cpp/system/data_pipe.h" |
Igor Ruvinov | dcb8198 | 2023-06-21 22:22:17 | [diff] [blame] | 61 | #include "mojo/public/cpp/system/simple_watcher.h" |
Matt Menke | 7f2e1ac5 | 2020-12-10 01:16:10 | [diff] [blame] | 62 | #include "net/base/isolation_info.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 63 | #include "net/dns/public/resolve_error_info.h" |
Tsuyoshi Horo | 3023b5d | 2023-11-28 21:40:31 | [diff] [blame] | 64 | #include "net/http/http_connection_info.h" |
Hayato Ito | 5750b44 | 2025-05-29 02:38:06 | [diff] [blame] | 65 | #include "services/metrics/public/cpp/ukm_builders.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 66 | #include "services/metrics/public/cpp/ukm_source_id.h" |
Antonio Sartori | 5ecc8b93 | 2021-03-05 06:56:10 | [diff] [blame] | 67 | #include "services/network/public/cpp/content_security_policy/csp_context.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 68 | #include "services/network/public/mojom/blocked_by_response_reason.mojom-shared.h" |
| 69 | #include "services/network/public/mojom/content_security_policy.mojom.h" |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 70 | #include "services/network/public/mojom/shared_dictionary_access_observer.mojom.h" |
Steven Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 71 | #include "services/network/public/mojom/trust_token_access_observer.mojom-shared.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 72 | #include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h" |
sbingler | a07ae73 | 2022-12-02 20:49:05 | [diff] [blame] | 73 | #include "third_party/blink/public/common/runtime_feature_state/runtime_feature_state_context.h" |
Chris Hamilton | 83272dc | 2021-02-23 00:24:02 | [diff] [blame] | 74 | #include "third_party/blink/public/common/tokens/tokens.h" |
Mike Jackson | 82654a3a | 2025-02-13 07:48:22 | [diff] [blame] | 75 | #include "third_party/blink/public/mojom/confidence_level.mojom.h" |
Kouhei Ueno | a0297b0b | 2023-06-15 05:39:48 | [diff] [blame] | 76 | #include "third_party/blink/public/mojom/lcp_critical_path_predictor/lcp_critical_path_predictor.mojom.h" |
Henrique Ferreiro | 621b3ad | 2021-02-15 12:51:41 | [diff] [blame] | 77 | #include "third_party/blink/public/mojom/loader/mixed_content.mojom-forward.h" |
Yao Xiao | 720ef9d6 | 2022-12-09 05:18:29 | [diff] [blame] | 78 | #include "third_party/blink/public/mojom/navigation/navigation_initiator_activation_and_ad_status.mojom.h" |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 79 | #include "third_party/blink/public/mojom/navigation/navigation_params.mojom-forward.h" |
Lukasz Anforowicz | 36d24d3 | 2022-02-15 19:02:53 | [diff] [blame] | 80 | #include "url/gurl.h" |
Lei Zhang | b570a3f | 2025-06-17 20:19:22 | [diff] [blame] | 81 | #include "url/gurl_debug.h" |
Lukasz Anforowicz | 0e07b765 | 2021-06-04 18:27:51 | [diff] [blame] | 82 | #include "url/origin.h" |
Lei Zhang | b570a3f | 2025-06-17 20:19:22 | [diff] [blame] | 83 | #include "url/origin_debug.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 84 | |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 85 | #if BUILDFLAG(IS_ANDROID) |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 86 | #include "base/android/scoped_java_ref.h" |
| 87 | #include "content/browser/android/navigation_handle_proxy.h" |
| 88 | #endif |
| 89 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 90 | namespace network { |
Yoav Weiss | 93d38b50 | 2025-05-06 15:55:51 | [diff] [blame] | 91 | struct IntegrityPolicy; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 92 | struct URLLoaderCompletionStatus; |
| 93 | } // namespace network |
| 94 | |
Clark DuVall | 3d91432d | 2021-12-07 20:29:44 | [diff] [blame] | 95 | namespace ui { |
| 96 | class CompositorLock; |
| 97 | } // namespace ui |
| 98 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 99 | namespace content { |
| 100 | |
Camille Lamy | d1f015d | 2024-07-06 14:14:10 | [diff] [blame] | 101 | class AgentClusterKey; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 102 | class CrossOriginEmbedderPolicyReporter; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 103 | class FrameTreeNode; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 104 | class NavigationUIData; |
Lei Zhang | a4ddcf65 | 2023-03-02 18:54:06 | [diff] [blame] | 105 | class NavigationURLLoader; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 106 | class NavigatorDelegate; |
| 107 | class PrefetchedSignedExchangeCache; |
Lei Zhang | a4ddcf65 | 2023-03-02 18:54:06 | [diff] [blame] | 108 | class PrerenderHostRegistry; |
| 109 | class RenderFrameHostCSPContext; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 110 | class ServiceWorkerMainResourceHandle; |
Lei Zhang | a4ddcf65 | 2023-03-02 18:54:06 | [diff] [blame] | 111 | class SubframeHistoryNavigationThrottle; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 112 | |
Matt Falkenhagen | 54adeaa | 2021-07-06 14:10:00 | [diff] [blame] | 113 | // The primary implementation of NavigationHandle. |
| 114 | // |
| 115 | // Lives from navigation start until the navigation has been committed. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 116 | class CONTENT_EXPORT NavigationRequest |
| 117 | : public NavigationHandle, |
| 118 | public NavigationURLLoaderDelegate, |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 119 | public CommitDeferringConditionRunner::Delegate, |
Yao Xiao | 6e1f7d3 | 2022-01-07 03:28:40 | [diff] [blame] | 120 | public FencedFrameURLMapping::MappingResultObserver, |
Rakina Zata Amni | af55b5b6 | 2022-07-19 23:11:03 | [diff] [blame] | 121 | public mojom::NavigationRendererCancellationListener, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 122 | private RenderProcessHostObserver, |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 123 | private network::mojom::TrustTokenAccessObserver, |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 124 | private network::mojom::SharedDictionaryAccessObserver, |
| 125 | public network::mojom::DeviceBoundSessionAccessObserver { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 126 | public: |
| 127 | // Keeps track of the various stages of a NavigationRequest. |
| 128 | // To see what state transitions are allowed, see |SetState|. |
| 129 | enum NavigationState { |
| 130 | // Initial state. |
| 131 | NOT_STARTED = 0, |
| 132 | |
| 133 | // Waiting for a BeginNavigation IPC from the renderer in a |
| 134 | // browser-initiated navigation. If there is no live renderer when the |
| 135 | // request is created, this stage is skipped. |
| 136 | WAITING_FOR_RENDERER_RESPONSE, |
| 137 | |
| 138 | // TODO(zetamoo): Merge this state with WILL_START_REQUEST. |
| 139 | // Temporary state where: |
| 140 | // - Before unload handlers have run and this navigation is allowed to |
| 141 | // start. |
| 142 | // - The navigation is still not visible to embedders (via |
| 143 | // NavigationHandle). |
| 144 | WILL_START_NAVIGATION, |
| 145 | |
| 146 | // The navigation is visible to embedders (via NavigationHandle). Wait for |
| 147 | // the NavigationThrottles to finish running the WillStartRequest event. |
| 148 | // This is potentially asynchronous. |
Adithya Srinivasan | b00dceb0 | 2021-10-28 15:47:57 | [diff] [blame] | 149 | // For navigations that have already committed synchronously in the renderer |
| 150 | // (see |is_synchronous_renderer_commit_|), this will synchronously proceed |
| 151 | // to DID_COMMIT directly without any waiting (or the navigation might not |
| 152 | // commit in certain cases, and be cleared in this state). All other |
| 153 | // navigations can only reach DID_COMMIT from READY_TO_COMMIT. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 154 | WILL_START_REQUEST, |
| 155 | |
| 156 | // The request is being redirected. Wait for the NavigationThrottles to |
| 157 | // finish running the WillRedirectRequest event. This is potentially |
| 158 | // asynchronous. |
| 159 | WILL_REDIRECT_REQUEST, |
| 160 | |
| 161 | // The response is being processed. Wait for the NavigationThrottles to |
| 162 | // finish running the WillProcessResponse event. This is potentially |
| 163 | // asynchronous. |
| 164 | WILL_PROCESS_RESPONSE, |
| 165 | |
Nate Chapin | 060cb95 | 2023-02-08 21:13:07 | [diff] [blame] | 166 | // The navigation does not require a request/response. Wait only for |
| 167 | // NavigationThrottles to finish before calling CommitNavigation(). This |
| 168 | // will only be asynchronous if a throttle defers the navigation. |
| 169 | WILL_COMMIT_WITHOUT_URL_LOADER, |
| 170 | |
Matt Falkenhagen | 54adeaa | 2021-07-06 14:10:00 | [diff] [blame] | 171 | // The browser process has asked the renderer to commit the response |
| 172 | // and is waiting for acknowledgement that it has been committed. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 173 | READY_TO_COMMIT, |
| 174 | |
| 175 | // The response has been committed. This is one of the two final states of |
| 176 | // the request. |
| 177 | DID_COMMIT, |
| 178 | |
| 179 | // The request is being canceled. |
| 180 | CANCELING, |
| 181 | |
| 182 | // The request is failing. Wait for the NavigationThrottles to finish |
| 183 | // running the WillFailRequest event. This is potentially asynchronous. |
| 184 | WILL_FAIL_REQUEST, |
| 185 | |
Matt Falkenhagen | 54adeaa | 2021-07-06 14:10:00 | [diff] [blame] | 186 | // The request failed with a net error code and an error page should be |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 187 | // displayed. This is one of the two final states for the request. |
| 188 | DID_COMMIT_ERROR_PAGE, |
| 189 | }; |
| 190 | |
Rakina Zata Amni | 7af54b1 | 2022-06-28 10:36:17 | [diff] [blame] | 191 | // The RenderFrameHost currently associated with the navigation. Note that the |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 192 | // final value will only be known when the response is received, or the |
Rakina Zata Amni | 7af54b1 | 2022-06-28 10:36:17 | [diff] [blame] | 193 | // navigation fails, as server redirects can modify the RenderFrameHost to use |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 194 | // for the navigation. |
Rakina Zata Amni | 7af54b1 | 2022-06-28 10:36:17 | [diff] [blame] | 195 | enum class AssociatedRenderFrameHostType { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 196 | NONE = 0, |
Rakina Zata Amni | 7af54b1 | 2022-06-28 10:36:17 | [diff] [blame] | 197 | // The navigation reuses the current RenderFrameHost. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 198 | CURRENT, |
Rakina Zata Amni | 7af54b1 | 2022-06-28 10:36:17 | [diff] [blame] | 199 | // The navigation uses a new RenderFrameHost, the speculative |
| 200 | // RenderFrameHost. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 201 | SPECULATIVE, |
| 202 | }; |
| 203 | |
Hiroki Nakagawa | 1aef8b0 | 2021-06-25 10:30:33 | [diff] [blame] | 204 | // This enum is used in UMA histograms, so existing values should neither be |
| 205 | // reordered or removed. |
| 206 | enum class OriginAgentClusterEndResult { |
W. James MacLean | 04279f5 | 2022-03-21 16:33:56 | [diff] [blame] | 207 | // The first four enums are for use when OAC-by-default is disabled. |
Hiroki Nakagawa | 1aef8b0 | 2021-06-25 10:30:33 | [diff] [blame] | 208 | kNotRequestedAndNotOriginKeyed, |
| 209 | kNotRequestedButOriginKeyed, |
| 210 | kRequestedButNotOriginKeyed, |
| 211 | kRequestedAndOriginKeyed, |
W. James MacLean | 04279f5 | 2022-03-21 16:33:56 | [diff] [blame] | 212 | // The remaining enums are for use when OAC-by-default is enabled. |
| 213 | kExplicitlyNotRequestedAndNotOriginKeyed, |
| 214 | kExplicitlyNotRequestedButOriginKeyed, |
| 215 | kExplicitlyRequestedButNotOriginKeyed, |
| 216 | kExplicitlyRequestedAndOriginKeyed, |
| 217 | kNotExplicitlyRequestedButNotOriginKeyed, |
| 218 | kNotExplicitlyRequestedAndOriginKeyed, |
| 219 | kMaxValue = kNotExplicitlyRequestedAndOriginKeyed |
Hiroki Nakagawa | 1aef8b0 | 2021-06-25 10:30:33 | [diff] [blame] | 220 | }; |
| 221 | |
Andrew Verge | 754c70a | 2025-04-17 17:19:19 | [diff] [blame] | 222 | // If this navigation is a browser-initiated error page navigation, this enum |
| 223 | // describes the scenario that triggered the navigation, and how session |
| 224 | // history will be affected as a result. |
| 225 | enum class BrowserInitiatedErrorNavigationType { |
| 226 | // This navigation is not a browser-initiated error page navigation. The |
| 227 | // default value for all newly-created NavigationRequests. |
| 228 | kNone, |
| 229 | |
| 230 | // This is a normal error navigation as triggered by |
| 231 | // NavigationControllerImpl::NavigateFrameToErrorPage(). The current session |
| 232 | // history item will be fully replaced when the navigation commits. |
| 233 | kRegular, |
| 234 | |
| 235 | // This is a post-commit error page navigation as triggered by |
| 236 | // NavigationController::LoadPostCommitErrorPage(). The current session |
| 237 | // history item will be set aside when the navigation commits, and replaced |
| 238 | // when any following navigation commits. |
| 239 | kPostCommit, |
| 240 | }; |
| 241 | |
Yue Ru Sun | 12880493 | 2020-09-30 22:19:17 | [diff] [blame] | 242 | // Creates a request for a browser-initiated navigation. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 243 | static std::unique_ptr<NavigationRequest> CreateBrowserInitiated( |
| 244 | FrameTreeNode* frame_tree_node, |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 245 | blink::mojom::CommonNavigationParamsPtr common_params, |
| 246 | blink::mojom::CommitNavigationParamsPtr commit_params, |
Alex Moshchuk | 9321e6a | 2022-12-07 21:58:31 | [diff] [blame] | 247 | bool was_opener_suppressed, |
Alex Moshchuk | 9321e6a | 2022-12-07 21:58:31 | [diff] [blame] | 248 | const std::string& extra_headers, |
| 249 | FrameNavigationEntry* frame_entry, |
| 250 | NavigationEntryImpl* entry, |
| 251 | bool is_form_submission, |
| 252 | std::unique_ptr<NavigationUIData> navigation_ui_data, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 253 | const std::optional<blink::Impression>& impression, |
Alex Moshchuk | 9321e6a | 2022-12-07 21:58:31 | [diff] [blame] | 254 | bool is_pdf, |
Camillia Smith Barnes | 6a64396 | 2023-03-03 00:28:58 | [diff] [blame] | 255 | bool is_embedder_initiated_fenced_frame_navigation = false, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 256 | std::optional<std::u16string> embedder_shared_storage_context = |
| 257 | std::nullopt); |
Alex Moshchuk | 9321e6a | 2022-12-07 21:58:31 | [diff] [blame] | 258 | |
| 259 | // Creates a request for either a browser-initiated navigation or a |
Liam Brady | edb866e | 2025-01-22 22:28:13 | [diff] [blame] | 260 | // renderer-initiated navigation. Returns nullptr if the navigation could not |
| 261 | // be started, such as when network access has been revoked (see |
| 262 | // RenderFrameHost::IsUntrustedNetworkDisabled()). Normally, |
| 263 | // renderer-initiated navigations use CreateRendererInitiated(), but some |
| 264 | // legacy renderer-initiated navigation paths, such as OpenURL, are stuck |
| 265 | // using this path instead; these cases specify `browser_initiated` as false. |
Alex Moshchuk | 9321e6a | 2022-12-07 21:58:31 | [diff] [blame] | 266 | // |
| 267 | // Do NOT add more uses of this function. Browser-initiated navigations |
| 268 | // should use CreateBrowserInitiated() and renderer-initiated navigations |
| 269 | // should use CreateRendererInitiated(). |
| 270 | // |
Alison Gale | 81f4f2c7 | 2024-04-22 19:33:31 | [diff] [blame] | 271 | // TODO(crbug.com/40249771): Refactor the remaining uses of this function to |
Alex Moshchuk | 9321e6a | 2022-12-07 21:58:31 | [diff] [blame] | 272 | // use either CreateBrowserInitiated() or CreateRendererInitiated() and then |
| 273 | // remove this helper. |
| 274 | static std::unique_ptr<NavigationRequest> Create( |
| 275 | FrameTreeNode* frame_tree_node, |
| 276 | blink::mojom::CommonNavigationParamsPtr common_params, |
| 277 | blink::mojom::CommitNavigationParamsPtr commit_params, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 278 | bool browser_initiated, |
John Delaney | 8623c64 | 2021-01-06 17:37:07 | [diff] [blame] | 279 | bool was_opener_suppressed, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 280 | const std::optional<blink::LocalFrameToken>& initiator_frame_token, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 281 | int initiator_process_id, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 282 | const std::string& extra_headers, |
| 283 | FrameNavigationEntry* frame_entry, |
| 284 | NavigationEntryImpl* entry, |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 285 | bool is_form_submission, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 286 | std::unique_ptr<NavigationUIData> navigation_ui_data, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 287 | const std::optional<blink::Impression>& impression, |
Yao Xiao | 720ef9d6 | 2022-12-09 05:18:29 | [diff] [blame] | 288 | blink::mojom::NavigationInitiatorActivationAndAdStatus |
| 289 | initiator_activation_and_ad_status, |
Nan Lin | 944e9b4e | 2022-04-12 13:51:22 | [diff] [blame] | 290 | bool is_pdf, |
Sergey Poromov | dd557c1 | 2023-03-01 11:28:45 | [diff] [blame] | 291 | bool is_embedder_initiated_fenced_frame_navigation = false, |
Camillia Smith Barnes | 6a64396 | 2023-03-03 00:28:58 | [diff] [blame] | 292 | bool is_container_initiated = false, |
Kevin McNee | 6455638a | 2024-06-27 22:05:03 | [diff] [blame] | 293 | bool has_rel_opener = false, |
W. James MacLean | 443ef3e | 2024-07-16 13:42:34 | [diff] [blame] | 294 | net::StorageAccessApiStatus storage_access_api_status = |
| 295 | net::StorageAccessApiStatus::kNone, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 296 | std::optional<std::u16string> embedder_shared_storage_context = |
| 297 | std::nullopt); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 298 | |
Yue Ru Sun | 12880493 | 2020-09-30 22:19:17 | [diff] [blame] | 299 | // Creates a request for a renderer-initiated navigation. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 300 | static std::unique_ptr<NavigationRequest> CreateRendererInitiated( |
| 301 | FrameTreeNode* frame_tree_node, |
| 302 | NavigationEntryImpl* entry, |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 303 | blink::mojom::CommonNavigationParamsPtr common_params, |
| 304 | blink::mojom::BeginNavigationParamsPtr begin_params, |
Charlie Reis | 99b2eba2 | 2025-01-31 19:18:57 | [diff] [blame] | 305 | int current_history_list_index, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 306 | int current_history_list_length, |
| 307 | bool override_user_agent, |
| 308 | scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory, |
| 309 | mojo::PendingAssociatedRemote<mojom::NavigationClient> navigation_client, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 310 | scoped_refptr<PrefetchedSignedExchangeCache> |
| 311 | prefetched_signed_exchange_cache, |
Rakina Zata Amni | af55b5b6 | 2022-07-19 23:11:03 | [diff] [blame] | 312 | mojo::PendingReceiver<mojom::NavigationRendererCancellationListener> |
| 313 | renderer_cancellation_listener); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 314 | |
Hiroki Nakagawa | 544acd4 | 2021-06-17 13:58:44 | [diff] [blame] | 315 | // Creates a NavigationRequest for synchronous navigation that have committed |
| 316 | // in the renderer process. Those are: |
| 317 | // - same-document renderer-initiated navigations. |
| 318 | // - synchronous about:blank navigations. |
| 319 | // |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 320 | // TODO(clamy): Eventually, this should only be called for same-document |
| 321 | // renderer-initiated navigations. |
Hiroki Nakagawa | 544acd4 | 2021-06-17 13:58:44 | [diff] [blame] | 322 | static std::unique_ptr<NavigationRequest> CreateForSynchronousRendererCommit( |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 323 | FrameTreeNode* frame_tree_node, |
| 324 | RenderFrameHostImpl* render_frame_host, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 325 | bool is_same_document, |
Rakina Zata Amni | a8866d2 | 2020-11-19 10:05:10 | [diff] [blame] | 326 | const GURL& url, |
| 327 | const url::Origin& origin, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 328 | const std::optional<GURL>& initiator_base_url, |
Matt Menke | 7f2e1ac5 | 2020-12-10 01:16:10 | [diff] [blame] | 329 | const net::IsolationInfo& isolation_info_for_subresources, |
Rakina Zata Amni | a8866d2 | 2020-11-19 10:05:10 | [diff] [blame] | 330 | blink::mojom::ReferrerPtr referrer, |
| 331 | const ui::PageTransition& transition, |
| 332 | bool should_replace_current_entry, |
Rakina Zata Amni | 2635778 | 2020-12-03 11:45:01 | [diff] [blame] | 333 | const std::string& method, |
Rakina Zata Amni | ff10975d | 2021-10-08 06:04:24 | [diff] [blame] | 334 | bool has_transient_activation, |
Rakina Zata Amni | eca2799 | 2020-12-12 10:48:31 | [diff] [blame] | 335 | bool is_overriding_user_agent, |
Rakina Zata Amni | a8866d2 | 2020-11-19 10:05:10 | [diff] [blame] | 336 | const std::vector<GURL>& redirects, |
Rakina Zata Amni | eca2799 | 2020-12-12 10:48:31 | [diff] [blame] | 337 | const GURL& original_url, |
Rakina Zata Amni | a8866d2 | 2020-11-19 10:05:10 | [diff] [blame] | 338 | std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter, |
Camille Lamy | 36afacd | 2025-01-16 14:25:18 | [diff] [blame] | 339 | std::unique_ptr<DocumentIsolationPolicyReporter> dip_reporter, |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 340 | int http_response_code, |
| 341 | base::TimeTicks actual_navigation_start); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 342 | |
| 343 | static NavigationRequest* From(NavigationHandle* handle); |
| 344 | |
| 345 | // If |type| is a reload, returns the equivalent ReloadType. Otherwise returns |
| 346 | // ReloadType::NONE. |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 347 | static ReloadType NavigationTypeToReloadType( |
| 348 | blink::mojom::NavigationType type); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 349 | |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 350 | NavigationRequest(const NavigationRequest&) = delete; |
| 351 | NavigationRequest& operator=(const NavigationRequest&) = delete; |
| 352 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 353 | ~NavigationRequest() override; |
| 354 | |
| 355 | // Returns true if this request's URL matches |origin| and the request state |
| 356 | // is at (or past) WILL_PROCESS_RESPONSE. |
| 357 | bool HasCommittingOrigin(const url::Origin& origin); |
| 358 | |
Alex Moshchuk | 3b8eb3b | 2021-03-24 06:16:56 | [diff] [blame] | 359 | // Returns true if this navigation's COOP header implies that the destination |
| 360 | // site of this navigation should be site-isolated. In addition to checking |
| 361 | // for eligible COOP header values, this function also verifies other |
| 362 | // criteria, such as whether this feature is enabled on the device (e.g., |
| 363 | // above memory threshold) or whether the site is already isolated. |
| 364 | bool ShouldRequestSiteIsolationForCOOP(); |
| 365 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 366 | // NavigationHandle implementation: |
William Liu | b26568da | 2024-02-21 20:46:14 | [diff] [blame] | 367 | int64_t GetNavigationId() const override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 368 | ukm::SourceId GetNextPageUkmSourceId() override; |
| 369 | const GURL& GetURL() override; |
| 370 | SiteInstanceImpl* GetStartingSiteInstance() override; |
| 371 | SiteInstanceImpl* GetSourceSiteInstance() override; |
Rakina Zata Amni | 1846325 | 2021-08-10 17:48:10 | [diff] [blame] | 372 | bool IsInMainFrame() const override; |
| 373 | bool IsInPrimaryMainFrame() const override; |
Takashi Toyoshima | 1a925f0 | 2025-06-13 17:56:14 | [diff] [blame] | 374 | bool IsInOutermostMainFrame() const override; |
Takashi Toyoshima | 3638f9c0 | 2023-01-18 06:47:57 | [diff] [blame] | 375 | bool IsInPrerenderedMainFrame() const override; |
Miyoung Shin | da2cde1 | 2022-08-29 12:54:39 | [diff] [blame] | 376 | bool IsPrerenderedPageActivation() const override; |
| 377 | bool IsInFencedFrameTree() const override; |
W. James MacLean | 5d4f8e55 | 2025-03-17 16:58:15 | [diff] [blame] | 378 | bool IsGuestViewMainFrame() const override; |
Julie Jeongeun Kim | f38c1eca | 2021-12-14 07:46:55 | [diff] [blame] | 379 | FrameType GetNavigatingFrameType() const override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 380 | bool IsRendererInitiated() override; |
Yao Xiao | 720ef9d6 | 2022-12-09 05:18:29 | [diff] [blame] | 381 | blink::mojom::NavigationInitiatorActivationAndAdStatus |
| 382 | GetNavigationInitiatorActivationAndAdStatus() override; |
Yoav Weiss | 3e46271d | 2021-04-30 20:35:21 | [diff] [blame] | 383 | bool IsSameOrigin() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 384 | bool WasServerRedirect() override; |
| 385 | const std::vector<GURL>& GetRedirectChain() override; |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 386 | FrameTreeNodeId GetFrameTreeNodeId() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 387 | RenderFrameHostImpl* GetParentFrame() override; |
Dave Tapuska | c8de3b0 | 2021-12-03 21:51:01 | [diff] [blame] | 388 | RenderFrameHostImpl* GetParentFrameOrOuterDocument() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 389 | base::TimeTicks NavigationStart() override; |
| 390 | base::TimeTicks NavigationInputStart() override; |
| 391 | const NavigationHandleTiming& GetNavigationHandleTiming() override; |
| 392 | bool IsPost() override; |
Min Qin | 3669650b | 2024-08-07 18:13:52 | [diff] [blame] | 393 | std::string GetRequestMethod() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 394 | const blink::mojom::Referrer& GetReferrer() override; |
| 395 | void SetReferrer(blink::mojom::ReferrerPtr referrer) override; |
| 396 | bool HasUserGesture() override; |
| 397 | ui::PageTransition GetPageTransition() override; |
| 398 | NavigationUIData* GetNavigationUIData() override; |
| 399 | bool IsExternalProtocol() override; |
| 400 | net::Error GetNetErrorCode() override; |
Keita Suzuki | c205764 | 2025-05-13 07:39:49 | [diff] [blame] | 401 | int GetNetExtendedErrorCode() override; |
Keita Suzuki | f300e44 | 2025-07-16 07:38:11 | [diff] [blame] | 402 | std::optional<ErrorNavigationTrigger> GetErrorNavigationTrigger() override; |
Alexander Timin | 074cd18 | 2022-03-23 18:11:22 | [diff] [blame] | 403 | RenderFrameHostImpl* GetRenderFrameHost() const override; |
Daniel Cheng | 284c3894 | 2022-09-22 23:30:34 | [diff] [blame] | 404 | bool IsSameDocument() const override; |
Rakina Zata Amni | c0a74fa | 2024-04-24 00:32:43 | [diff] [blame] | 405 | bool IsHistory() const override; |
Alexander Timin | 074cd18 | 2022-03-23 18:11:22 | [diff] [blame] | 406 | bool HasCommitted() const override; |
| 407 | bool IsErrorPage() const override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 408 | bool HasSubframeNavigationEntryCommitted() override; |
| 409 | bool DidReplaceEntry() override; |
| 410 | bool ShouldUpdateHistory() override; |
Kevin McNee | b49d2b8 | 2022-06-14 16:53:14 | [diff] [blame] | 411 | const GURL& GetPreviousPrimaryMainFrameURL() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 412 | net::IPEndPoint GetSocketAddress() override; |
| 413 | const net::HttpRequestHeaders& GetRequestHeaders() override; |
| 414 | void RemoveRequestHeader(const std::string& header_name) override; |
| 415 | void SetRequestHeader(const std::string& header_name, |
| 416 | const std::string& header_value) override; |
| 417 | void SetCorsExemptRequestHeader(const std::string& header_name, |
| 418 | const std::string& header_value) override; |
Kouhei Ueno | a0297b0b | 2023-06-15 05:39:48 | [diff] [blame] | 419 | void SetLCPPNavigationHint( |
| 420 | const blink::mojom::LCPCriticalPathPredictorNavigationTimeHint& hint) |
| 421 | override; |
Kouhei Ueno | 0cea93273 | 2023-08-04 00:19:41 | [diff] [blame] | 422 | const blink::mojom::LCPCriticalPathPredictorNavigationTimeHintPtr& |
| 423 | GetLCPPNavigationHint() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 424 | const net::HttpResponseHeaders* GetResponseHeaders() override; |
Tsuyoshi Horo | 3023b5d | 2023-11-28 21:40:31 | [diff] [blame] | 425 | net::HttpConnectionInfo GetConnectionInfo() override; |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 426 | const std::optional<net::SSLInfo>& GetSSLInfo() override; |
| 427 | const std::optional<net::AuthChallengeInfo>& GetAuthChallengeInfo() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 428 | net::ResolveErrorInfo GetResolveErrorInfo() override; |
| 429 | net::IsolationInfo GetIsolationInfo() override; |
| 430 | void RegisterThrottleForTesting( |
| 431 | std::unique_ptr<NavigationThrottle> navigation_throttle) override; |
| 432 | bool IsDeferredForTesting() override; |
David Bokan | 3d0d408 | 2021-07-27 17:40:26 | [diff] [blame] | 433 | bool IsCommitDeferringConditionDeferredForTesting() override; |
David Bokan | 5e2c64f | 2022-03-08 19:59:53 | [diff] [blame] | 434 | CommitDeferringCondition* GetCommitDeferringConditionForTesting() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 435 | bool WasStartedFromContextMenu() override; |
| 436 | const GURL& GetSearchableFormURL() override; |
| 437 | const std::string& GetSearchableFormEncoding() override; |
William Liu | 2b6336bc | 2023-09-07 14:42:39 | [diff] [blame] | 438 | ReloadType GetReloadType() const override; |
| 439 | RestoreType GetRestoreType() const override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 440 | const GURL& GetBaseURLForDataURL() override; |
| 441 | const GlobalRequestID& GetGlobalRequestID() override; |
| 442 | bool IsDownload() override; |
| 443 | bool IsFormSubmission() override; |
| 444 | bool WasInitiatedByLinkClick() override; |
| 445 | bool IsSignedExchangeInnerResponse() override; |
| 446 | bool HasPrefetchedAlternativeSubresourceSignedExchange() override; |
| 447 | bool WasResponseCached() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 448 | const std::string& GetHrefTranslate() override; |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 449 | const std::optional<blink::Impression>& GetImpression() override; |
| 450 | const std::optional<blink::LocalFrameToken>& GetInitiatorFrameToken() |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 451 | override; |
Liam Brady | 767b85e | 2023-07-05 16:59:59 | [diff] [blame] | 452 | int GetInitiatorProcessId() override; |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 453 | const std::optional<url::Origin>& GetInitiatorOrigin() override; |
| 454 | const std::optional<GURL>& GetInitiatorBaseUrl() override; |
Cammie Smith Barnes | a0da2cf | 2021-01-11 22:09:37 | [diff] [blame] | 455 | const std::vector<std::string>& GetDnsAliases() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 456 | bool IsSameProcess() override; |
William Liu | 2b6336bc | 2023-09-07 14:42:39 | [diff] [blame] | 457 | NavigationEntry* GetNavigationEntry() const override; |
Aldo Culquicondor | 3d10ff0 | 2025-01-30 19:01:03 | [diff] [blame] | 458 | int GetNavigationEntryOffset() const override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 459 | void RegisterSubresourceOverride( |
| 460 | blink::mojom::TransferrableURLLoaderPtr transferrable_loader) override; |
Alexander Timin | 8690530c | 2021-06-19 00:34:32 | [diff] [blame] | 461 | GlobalRenderFrameHostId GetPreviousRenderFrameHostId() override; |
Patrick Monette | 779c154 | 2025-01-17 17:18:36 | [diff] [blame] | 462 | ChildProcessId GetExpectedRenderProcessHostId() override; |
Fergal Daly | 7fa1171 | 2025-08-18 07:28:47 | [diff] [blame] | 463 | bool IsServedFromBackForwardCache() const override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 464 | void SetIsOverridingUserAgent(bool override_ua) override; |
Daniel Cheng | f776864c | 2020-09-26 09:55:22 | [diff] [blame] | 465 | void SetSilentlyIgnoreErrors() override; |
Kyra | 800d1d01 | 2024-03-27 17:05:48 | [diff] [blame] | 466 | void SetVisitedLinkSalt(uint64_t salt) override; |
Arthur Sonzogni | dc8508ab | 2023-08-17 08:42:42 | [diff] [blame] | 467 | network::mojom::WebSandboxFlags SandboxFlagsInitiator() override; |
Michael Thiessen | 8fd3520b | 2023-03-10 20:55:47 | [diff] [blame] | 468 | network::mojom::WebSandboxFlags SandboxFlagsInherited() override; |
Rakina Zata Amni | b0c816b | 2020-11-11 04:07:01 | [diff] [blame] | 469 | network::mojom::WebSandboxFlags SandboxFlagsToCommit() override; |
Alex Turner | 12519eb | 2020-11-16 22:23:46 | [diff] [blame] | 470 | bool IsWaitingToCommit() override; |
Kenichi Ishibashi | 784dd40 | 2021-10-15 00:19:24 | [diff] [blame] | 471 | bool WasResourceHintsReceived() override; |
Daniel Hosseinian | 46c816c | 2021-10-19 02:43:10 | [diff] [blame] | 472 | bool IsPdf() override; |
Alexander Timin | 074cd18 | 2022-03-23 18:11:22 | [diff] [blame] | 473 | void WriteIntoTrace(perfetto::TracedProto<TraceProto> context) const override; |
Chris Thompson | 066eed2 | 2021-10-07 20:20:43 | [diff] [blame] | 474 | bool SetNavigationTimeout(base::TimeDelta timeout) override; |
Mustafa Acer | 7b99ac2 | 2024-07-23 14:57:28 | [diff] [blame] | 475 | void CancelNavigationTimeout() override; |
Igor Ruvinov | 0ea2ebb | 2022-12-01 16:33:06 | [diff] [blame] | 476 | void SetAllowCookiesFromBrowser(bool allow_cookies_from_browser) override; |
Igor Ruvinov | dcb8198 | 2023-06-21 22:22:17 | [diff] [blame] | 477 | void GetResponseBody(ResponseBodyCallback callback) override; |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 478 | PreloadingTriggerType GetPrerenderTriggerType() override; |
Asami Doi | cf0f164 | 2021-11-25 05:00:26 | [diff] [blame] | 479 | std::string GetPrerenderEmbedderHistogramSuffix() override; |
Keita Suzuki | 1b7cf51 | 2025-08-02 02:46:59 | [diff] [blame] | 480 | bool IsPrerenderHostReused() override; |
Michael Thiessen | ca245a38 | 2022-02-21 16:11:17 | [diff] [blame] | 481 | #if BUILDFLAG(IS_ANDROID) |
| 482 | const base::android::JavaRef<jobject>& GetJavaNavigationHandle() override; |
| 483 | #endif |
David Bokan | 42f8dc2 | 2022-02-23 17:33:28 | [diff] [blame] | 484 | base::SafeRef<NavigationHandle> GetSafeRef() override; |
Anthony Vallee-Dubois | 2c802217 | 2022-08-22 15:29:41 | [diff] [blame] | 485 | bool ExistingDocumentWasDiscarded() const override; |
Jonathan Njeunje | 5861859 | 2023-04-06 21:10:02 | [diff] [blame] | 486 | blink::RuntimeFeatureStateContext& GetMutableRuntimeFeatureStateContext() |
| 487 | override; |
Erik Chen | 5fe571f | 2023-10-11 23:01:15 | [diff] [blame] | 488 | void SetContentSettings( |
| 489 | blink::mojom::RendererContentSettingsPtr content_settings) override; |
Erik Chen | 7ce5f05 | 2023-10-19 22:28:24 | [diff] [blame] | 490 | blink::mojom::RendererContentSettingsPtr GetContentSettingsForTesting() |
| 491 | override; |
John Delaney | 4cf7d6ea | 2023-11-09 17:29:56 | [diff] [blame] | 492 | void SetIsAdTagged() override; |
Rakina Zata Amni | 58681c6 | 2024-06-25 06:32:13 | [diff] [blame] | 493 | std::optional<NavigationDiscardReason> GetNavigationDiscardReason() override; |
Kyra | 800d1d01 | 2024-03-27 17:05:48 | [diff] [blame] | 494 | // NOTE: Read function comments in NavigationHandle before use! |
| 495 | std::optional<url::Origin> GetOriginToCommit() override; |
Jonathan Njeunje | 5861859 | 2023-04-06 21:10:02 | [diff] [blame] | 496 | // End of NavigationHandle implementation. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 497 | |
Jonathan Njeunje | 5861859 | 2023-04-06 21:10:02 | [diff] [blame] | 498 | // mojom::NavigationRendererCancellationListener implementation: |
Rakina Zata Amni | af55b5b6 | 2022-07-19 23:11:03 | [diff] [blame] | 499 | void RendererCancellationWindowEnded() override; |
Jonathan Njeunje | 5861859 | 2023-04-06 21:10:02 | [diff] [blame] | 500 | // End of mojom::NavigationRendererCancellationListener implementation. |
Rakina Zata Amni | af55b5b6 | 2022-07-19 23:11:03 | [diff] [blame] | 501 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 502 | void RegisterCommitDeferringConditionForTesting( |
| 503 | std::unique_ptr<CommitDeferringCondition> condition); |
| 504 | |
Giovanni Ortuño Urquidi | e0a77b4 | 2025-03-28 14:31:35 | [diff] [blame] | 505 | // Used by tests that want to control the timing of cookie access |
| 506 | // notifications. |
| 507 | void SetCookieAccessObserversForTesting( |
| 508 | std::unique_ptr<CookieAccessObservers> cookie_access_observers); |
| 509 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 510 | // Called on the UI thread by the Navigator to start the navigation. |
| 511 | // The NavigationRequest can be deleted while BeginNavigation() is called. |
| 512 | void BeginNavigation(); |
| 513 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 514 | const blink::mojom::CommonNavigationParams& common_params() const { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 515 | return *common_params_; |
| 516 | } |
| 517 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 518 | const blink::mojom::BeginNavigationParams& begin_params() const { |
Harkiran Bolaria | 2d0e3893 | 2021-04-27 17:44:35 | [diff] [blame] | 519 | return *begin_params_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 520 | } |
| 521 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 522 | const blink::mojom::CommitNavigationParams& commit_params() const { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 523 | return *commit_params_; |
| 524 | } |
| 525 | |
Charlie Reis | 9e20dd1 | 2025-01-02 20:11:53 | [diff] [blame] | 526 | // This describes the cases where the navigation start time is adjusted to be |
| 527 | // later in time, after BeforeUnloadCompleted. This enum is used in UMA |
| 528 | // histograms, so existing values should be neither reordered nor removed. |
| 529 | enum class NavigationStartAdjustmentType { |
| 530 | // No adjustment to the navigation start time was made. |
| 531 | kNone = 0, |
| 532 | // The start time was adjusted so that the navigation could proceed via a |
| 533 | // posted task, even though there were no beforeunload handlers registered. |
| 534 | kLegacyPostTask = 1, |
| 535 | // The start time was adjusted because beforeunload handlers ran, but no |
| 536 | // dialog was displayed to the user. |
| 537 | kBeforeUnloadHandlers = 2, |
| 538 | // The start time was adjusted because a beforeunload dialog was shown. |
| 539 | kBeforeUnloadDialog = 3, |
| 540 | kMaxValue = kBeforeUnloadDialog, |
| 541 | }; |
| 542 | |
| 543 | // Updates the navigation start time, after beforeunload has completed. |
| 544 | // `for_legacy` indicates that the navigation proceeded in a separate task for |
| 545 | // legacy reasons, without running beforeunload handlers. `showed_dialog` |
| 546 | // indicates whether the beforeunload handlers actually displayed a dialog. |
| 547 | void UpdateNavigationStartTime(const base::TimeTicks& time, |
| 548 | bool for_legacy, |
| 549 | bool showed_dialog); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 550 | |
Shuran Huang | d11e73e | 2021-04-14 16:10:12 | [diff] [blame] | 551 | void set_is_cross_site_cross_browsing_context_group( |
| 552 | bool is_cross_site_cross_browsing_context_group) { |
| 553 | commit_params_->is_cross_site_cross_browsing_context_group = |
| 554 | is_cross_site_cross_browsing_context_group; |
Shuran Huang | ecc0bfe2 | 2020-10-26 20:15:04 | [diff] [blame] | 555 | } |
| 556 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 557 | NavigationURLLoader* loader_for_testing() const { return loader_.get(); } |
| 558 | |
| 559 | NavigationState state() const { return state_; } |
| 560 | |
| 561 | FrameTreeNode* frame_tree_node() const { return frame_tree_node_; } |
| 562 | |
Nate Chapin | d7e7fe8 | 2021-06-30 01:15:43 | [diff] [blame] | 563 | bool is_synchronous_renderer_commit() const { |
| 564 | return is_synchronous_renderer_commit_; |
| 565 | } |
| 566 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 567 | SiteInstanceImpl* dest_site_instance() const { |
| 568 | return dest_site_instance_.get(); |
| 569 | } |
| 570 | |
Avi Drissman | 78865bbb | 2024-08-22 20:57:19 | [diff] [blame] | 571 | std::optional<BindingsPolicySet> bindings() const { return bindings_; } |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 572 | |
Hiroki Nakagawa | 0756559 | 2021-06-04 11:36:17 | [diff] [blame] | 573 | bool browser_initiated() const { |
| 574 | return commit_params_->is_browser_initiated; |
| 575 | } |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 576 | |
| 577 | bool from_begin_navigation() const { return from_begin_navigation_; } |
| 578 | |
Rakina Zata Amni | 8d4ed05 | 2022-12-07 23:03:30 | [diff] [blame] | 579 | AssociatedRenderFrameHostType GetAssociatedRFHType() const; |
| 580 | |
| 581 | void SetAssociatedRFHType(AssociatedRenderFrameHostType type); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 582 | |
Rakina Zata Amni | 7b75ae34 | 2023-03-03 05:59:14 | [diff] [blame] | 583 | bool HasRenderFrameHost() const { return render_frame_host_.has_value(); } |
| 584 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 585 | void set_was_discarded() { commit_params_->was_discarded = true; } |
| 586 | |
| 587 | void set_net_error(net::Error net_error) { net_error_ = net_error; } |
| 588 | |
| 589 | const std::string& GetMimeType() { |
| 590 | return response_head_ ? response_head_->mime_type : base::EmptyString(); |
| 591 | } |
| 592 | |
| 593 | const network::mojom::URLResponseHead* response() { |
| 594 | return response_head_.get(); |
| 595 | } |
| 596 | |
Rakina Zata Amni | ba3eecb | 2020-11-02 10:12:28 | [diff] [blame] | 597 | const mojo::DataPipeConsumerHandle& response_body() { |
| 598 | DCHECK_EQ(state_, WILL_PROCESS_RESPONSE); |
| 599 | return response_body_.get(); |
| 600 | } |
| 601 | |
| 602 | mojo::ScopedDataPipeConsumerHandle& mutable_response_body_for_testing() { |
| 603 | return response_body_; |
| 604 | } |
| 605 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 606 | void SetWaitingForRendererResponse(); |
| 607 | |
| 608 | // Notifies the NavigatorDelegate the navigation started. This should be |
| 609 | // called after any previous NavigationRequest for the FrameTreeNode has been |
Hiroki Nakagawa | adcffc50 | 2021-06-16 10:47:51 | [diff] [blame] | 610 | // destroyed. |
| 611 | void StartNavigation(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 612 | |
| 613 | void set_on_start_checks_complete_closure_for_testing( |
| 614 | base::OnceClosure closure) { |
| 615 | on_start_checks_complete_closure_ = std::move(closure); |
| 616 | } |
| 617 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 618 | // Updates the destination SiteInfo for this navigation. This is called on |
| 619 | // redirects. |post_redirect_process| is the renderer process that should |
| 620 | // handle the navigation following the redirect if it can be handled by an |
| 621 | // existing RenderProcessHost. Otherwise, it should be null. |
Arthur Hemery | 3a991c09 | 2021-12-22 12:04:24 | [diff] [blame] | 622 | void UpdateSiteInfo(RenderProcessHost* post_redirect_process); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 623 | |
| 624 | int nav_entry_id() const { return nav_entry_id_; } |
| 625 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 626 | // For automation driver-initiated navigations over the devtools protocol, |
| 627 | // |devtools_navigation_token_| is used to tag the navigation. This navigation |
| 628 | // token is then sent into the renderer and lands on the DocumentLoader. That |
| 629 | // way subsequent Blink-level frame lifecycle events can be associated with |
| 630 | // the concrete navigation. |
| 631 | // - The value should not be sent back to the browser. |
| 632 | // - The value on DocumentLoader may be generated in the renderer in some |
| 633 | // cases, and thus shouldn't be trusted. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 634 | // TODO(crbug.com/40549185): Replace devtools navigation token with the |
| 635 | // generic navigation token that can be passed from renderer to the browser. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 636 | const base::UnguessableToken& devtools_navigation_token() const { |
| 637 | return devtools_navigation_token_; |
| 638 | } |
| 639 | |
Mike Jackson | 82654a3a | 2025-02-13 07:48:22 | [diff] [blame] | 640 | blink::mojom::ConfidenceLevel navigation_confidence() const { |
| 641 | return confidence_level_; |
| 642 | } |
| 643 | |
Alex Moshchuk | d0d759c2 | 2025-05-09 18:18:35 | [diff] [blame] | 644 | // This token is passed in various IPCs pertaining to navigations, such as |
| 645 | // frame and proxy creation as well as CommitNavigation, and is used by |
| 646 | // renderer-side metrics code to tie together different IPCs that were sent as |
| 647 | // part of performing a particular navigation. It is not intended to be used |
| 648 | // for anything other than metrics and trace events. |
| 649 | // |
| 650 | // Note that this token is stored in CommitNavigationParams, even though it's |
| 651 | // also needed before CommitNavigation (e.g., it needs to be included in frame |
| 652 | // and proxy creation IPCs which are sent before CommitNavigation) - this |
| 653 | // should be ok since commit_params() are initialized when a NavigationRequest |
| 654 | // is created. |
| 655 | const base::UnguessableToken& navigation_metrics_token() const { |
| 656 | return commit_params().navigation_metrics_token; |
| 657 | } |
| 658 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 659 | // Called on same-document navigation requests that need to be restarted as |
| 660 | // cross-document navigations. This happens when a same-document commit fails |
| 661 | // due to another navigation committing in the meantime. |
| 662 | void ResetForCrossDocumentRestart(); |
| 663 | |
| 664 | // If the navigation redirects cross-process or otherwise is forced to use a |
| 665 | // different SiteInstance than anticipated (e.g., for switching between error |
| 666 | // states), then reset any sensitive state that shouldn't carry over to the |
| 667 | // new process. |
| 668 | void ResetStateForSiteInstanceChange(); |
| 669 | |
Sohom | 7299b22 | 2023-01-20 15:20:52 | [diff] [blame] | 670 | // If a navigation has been cancelled, and was initiated by the parent |
| 671 | // document, report it with the appropriate ResourceTiming entry information. |
| 672 | // |
| 673 | // The ResourceTiming entry may not be sent if the current frame |
| 674 | // does not have a parent, or if the navigation was cancelled before |
| 675 | // a request was made. |
| 676 | void MaybeAddResourceTimingEntryForCancelledNavigation(); |
| 677 | |
Sergey Poromov | dd557c1 | 2023-03-01 11:28:45 | [diff] [blame] | 678 | // Adds a resource timing entry to the parent in case of cancelled navigations |
| 679 | // and failed <object> navigations. |
| 680 | void AddResourceTimingEntryForFailedSubframeNavigation( |
| 681 | const network::URLLoaderCompletionStatus& status); |
| 682 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 683 | // Lazily initializes and returns the mojo::NavigationClient interface used |
Nasko Oskov | d22f9bf87 | 2020-12-23 00:31:35 | [diff] [blame] | 684 | // for commit. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 685 | mojom::NavigationClient* GetCommitNavigationClient(); |
| 686 | |
| 687 | void set_transition(ui::PageTransition transition) { |
| 688 | common_params_->transition = transition; |
| 689 | } |
| 690 | |
| 691 | void set_has_user_gesture(bool has_user_gesture) { |
| 692 | common_params_->has_user_gesture = has_user_gesture; |
| 693 | } |
| 694 | |
| 695 | // Ignores any interface disconnect that might happen to the |
| 696 | // navigation_client used to commit. |
| 697 | void IgnoreCommitInterfaceDisconnection(); |
| 698 | |
| 699 | // Resume and CancelDeferredNavigation must only be called by the |
| 700 | // NavigationThrottle that is currently deferring the navigation. |
| 701 | // |resuming_throttle| and |cancelling_throttle| are the throttles calling |
| 702 | // these methods. |
| 703 | void Resume(NavigationThrottle* resuming_throttle); |
| 704 | void CancelDeferredNavigation(NavigationThrottle* cancelling_throttle, |
| 705 | NavigationThrottle::ThrottleCheckResult result); |
| 706 | |
Takashi Toyoshima | 96a07bb | 2025-06-06 06:45:58 | [diff] [blame] | 707 | // Returns the underlying NavigationThrottleRegistry for tests to manipulate. |
Takashi Toyoshima | cc4d947f | 2025-06-24 08:38:34 | [diff] [blame] | 708 | NavigationThrottleRegistryImpl* GetNavigationThrottleRegistryForTesting() { |
Takashi Toyoshima | 96a07bb | 2025-06-06 06:45:58 | [diff] [blame] | 709 | return throttle_registry_.get(); |
| 710 | } |
| 711 | |
Rakina Zata Amni | af55b5b6 | 2022-07-19 23:11:03 | [diff] [blame] | 712 | // Simulates renderer cancelling the navigation. |
| 713 | void RendererRequestedNavigationCancellationForTesting(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 714 | |
| 715 | typedef base::OnceCallback<bool(NavigationThrottle::ThrottleCheckResult)> |
| 716 | ThrottleChecksFinishedCallback; |
| 717 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 718 | // Called when the navigation was committed. |
| 719 | // This will update the |state_|. |
| 720 | // |navigation_entry_committed| indicates whether the navigation changed which |
| 721 | // NavigationEntry is current. |
| 722 | // |did_replace_entry| is true if the committed entry has replaced the |
| 723 | // existing one. A non-user initiated redirect causes such replacement. |
Fergal Daly | 8e33cf6 | 2020-12-12 01:06:07 | [diff] [blame] | 724 | |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 725 | void DidCommitNavigation(const mojom::DidCommitProvisionalLoadParams& params, |
| 726 | bool navigation_entry_committed, |
| 727 | bool did_replace_entry, |
Miyoung Shin | 3299cbf | 2022-11-22 01:41:10 | [diff] [blame] | 728 | const GURL& previous_main_frame_url); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 729 | |
| 730 | NavigationType navigation_type() const { |
| 731 | DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE); |
| 732 | return navigation_type_; |
| 733 | } |
| 734 | |
Miyoung Shin | 3299cbf | 2022-11-22 01:41:10 | [diff] [blame] | 735 | void set_navigation_type(NavigationType navigation_type) { |
| 736 | navigation_type_ = navigation_type; |
| 737 | } |
| 738 | |
Andrew Verge | 754c70a | 2025-04-17 17:19:19 | [diff] [blame] | 739 | void set_browser_initiated_error_navigation_type( |
| 740 | BrowserInitiatedErrorNavigationType type) { |
| 741 | browser_initiated_error_navigation_type_ = type; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 742 | } |
| 743 | |
Andrew Verge | 754c70a | 2025-04-17 17:19:19 | [diff] [blame] | 744 | BrowserInitiatedErrorNavigationType |
| 745 | browser_initiated_error_navigation_type() { |
| 746 | return browser_initiated_error_navigation_type_; |
| 747 | } |
| 748 | |
| 749 | void set_error_page_html(const std::string& error_page_html) { |
| 750 | CHECK(browser_initiated_error_navigation_type_ != |
| 751 | BrowserInitiatedErrorNavigationType::kNone); |
| 752 | error_page_html_ = error_page_html; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | void set_from_download_cross_origin_redirect( |
| 756 | bool from_download_cross_origin_redirect) { |
| 757 | from_download_cross_origin_redirect_ = from_download_cross_origin_redirect; |
| 758 | } |
| 759 | |
| 760 | // This should be a private method. The only valid reason to be used |
| 761 | // outside of the class constructor is in the case of an initial history |
| 762 | // navigation in a subframe. This allows a browser-initiated NavigationRequest |
| 763 | // to be canceled by the renderer. |
| 764 | void SetNavigationClient( |
| 765 | mojo::PendingAssociatedRemote<mojom::NavigationClient> navigation_client); |
| 766 | |
Lukasz Anforowicz | 39a8aef | 2020-12-17 23:50:15 | [diff] [blame] | 767 | // Whether the navigation loads an MHTML document or a subframe of an MHTML |
| 768 | // document. The navigation might or might not be fullfilled from the MHTML |
| 769 | // archive (see `is_mhtml_subframe_loaded_from_achive` in the NeedsUrlLoader |
| 770 | // method). The navigation will commit in the main frame process. |
| 771 | bool IsMhtmlOrSubframe(); |
arthursonzogni | 3fc224b | 2020-10-07 10:41:16 | [diff] [blame] | 772 | |
Lukasz Anforowicz | 39a8aef | 2020-12-17 23:50:15 | [diff] [blame] | 773 | // Whether this navigation navigates a subframe of an MHTML document. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 774 | bool IsForMhtmlSubframe() const; |
| 775 | |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 776 | // Whether the navigation has a non-OK net error code. |
| 777 | // Note that this is different from IsErrorPage(), which only returns true if |
| 778 | // the navigation has finished committing an error page. The net error code |
| 779 | // can be non-OK before commit and also in cases that didn't result in the |
| 780 | // navigation being committed (e.g. canceled navigations). |
| 781 | virtual bool DidEncounterError() const; |
| 782 | |
Yao Xiao | 6e1f7d3 | 2022-01-07 03:28:40 | [diff] [blame] | 783 | void set_begin_navigation_callback_for_testing(base::OnceClosure callback) { |
| 784 | begin_navigation_callback_for_testing_ = std::move(callback); |
| 785 | } |
| 786 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 787 | void set_complete_callback_for_testing( |
| 788 | ThrottleChecksFinishedCallback callback) { |
| 789 | complete_callback_for_testing_ = std::move(callback); |
| 790 | } |
| 791 | |
Daniel Cheng | e8b6940 | 2021-05-25 20:44:44 | [diff] [blame] | 792 | network::mojom::URLLoaderClientEndpointsPtr& |
| 793 | mutable_url_loader_client_endpoints_for_testing() { |
| 794 | return url_loader_client_endpoints_; |
| 795 | } |
| 796 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 797 | void set_ready_to_commit_callback_for_testing(base::OnceClosure callback) { |
| 798 | ready_to_commit_callback_for_testing_ = std::move(callback); |
| 799 | } |
| 800 | |
Rakina Zata Amni | 49657c77 | 2023-03-31 06:41:53 | [diff] [blame] | 801 | // Whether this navigation is queued, waiting for an existing pending commit |
| 802 | // RenderFrameHost to finish navigating. |
| 803 | bool IsQueued() const { return !!resume_commit_closure_; } |
| 804 | |
Rakina Zata Amni | af55b5b6 | 2022-07-19 23:11:03 | [diff] [blame] | 805 | void set_renderer_cancellation_window_ended_callback( |
| 806 | base::OnceClosure callback) { |
| 807 | DCHECK(!renderer_cancellation_window_ended()); |
| 808 | renderer_cancellation_window_ended_callback_ = std::move(callback); |
| 809 | } |
| 810 | |
| 811 | bool renderer_cancellation_window_ended() const { |
| 812 | return renderer_cancellation_window_ended_; |
| 813 | } |
| 814 | |
| 815 | // Returns true if this navigation should wait for the renderer-initiated |
| 816 | // navigation cancellation window to end before committing, and returns false |
| 817 | // otherwise. See comment for `renderer_cancellation_listener_` for more |
| 818 | // details. |
| 819 | bool ShouldWaitForRendererCancellationWindowToEnd(); |
| 820 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 821 | // Sets the READY_TO_COMMIT -> DID_COMMIT timeout. Resets the timeout to the |
| 822 | // default value if |timeout| is zero. |
| 823 | static void SetCommitTimeoutForTesting(const base::TimeDelta& timeout); |
| 824 | |
Mingyu Lei | 2e0b586e | 2023-07-25 18:26:00 | [diff] [blame] | 825 | // Returns the `rfh_restored_from_back_forward_cache_` if the navigation is |
| 826 | // a BFCache restore, or nullptr otherwise. |
| 827 | RenderFrameHostImpl* GetRenderFrameHostRestoredFromBackForwardCache() const; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 828 | |
Matt Falkenhagen | a0b95d7b | 2021-08-06 20:37:40 | [diff] [blame] | 829 | // The NavigatorDelegate to notify/query for various navigation events. This |
| 830 | // is always the WebContents. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 831 | NavigatorDelegate* GetDelegate() const; |
| 832 | |
| 833 | blink::mojom::RequestContextType request_context_type() const { |
| 834 | return begin_params_->request_context_type; |
| 835 | } |
| 836 | |
| 837 | network::mojom::RequestDestination request_destination() const { |
Nan Lin | d91c815 | 2021-10-21 16:22:37 | [diff] [blame] | 838 | return common_params_->request_destination; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 839 | } |
| 840 | |
Henrique Ferreiro | 621b3ad | 2021-02-15 12:51:41 | [diff] [blame] | 841 | blink::mojom::MixedContentContextType mixed_content_context_type() const { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 842 | return begin_params_->mixed_content_context_type; |
| 843 | } |
| 844 | |
| 845 | // Returns true if the navigation was started by the Navigator by calling |
| 846 | // BeginNavigation(), or if the request was created at commit time by calling |
| 847 | // CreateForCommit(). |
| 848 | bool IsNavigationStarted() const; |
| 849 | |
Aman Verma | c59efd0 | 2024-11-18 20:30:17 | [diff] [blame] | 850 | std::unique_ptr<viz::PeakGpuMemoryTracker> TakePeakGpuMemoryTracker(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 851 | |
Kenichi Ishibashi | 7eb8cf6 | 2021-04-07 12:35:05 | [diff] [blame] | 852 | std::unique_ptr<NavigationEarlyHintsManager> TakeEarlyHintsManager(); |
| 853 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 854 | // Returns true for navigation responses to be rendered in a renderer process. |
| 855 | // This excludes: |
Sharon Yang | 9e72728 | 2023-11-13 19:51:40 | [diff] [blame] | 856 | // - 204/205 navigation responses |
| 857 | // - Most downloads |
| 858 | // (Note: downloads with unsuccessful response codes will render an error |
| 859 | // page, causing this to return true.) |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 860 | // |
Sharon Yang | 9e72728 | 2023-11-13 19:51:40 | [diff] [blame] | 861 | // Must not be called before having received the response. After |
| 862 | // OnResponseStarted(), this is expected to be equivalent to |
| 863 | // HasRenderFrameHost(). |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 864 | bool response_should_be_rendered() const { |
| 865 | DCHECK_GE(state_, WILL_PROCESS_RESPONSE); |
| 866 | return response_should_be_rendered_; |
| 867 | } |
| 868 | |
Titouan Rigoudy | ff5a84b | 2023-07-25 16:02:20 | [diff] [blame] | 869 | // Returns the `ClientSecurityState` we should pass to |
| 870 | // `NavigationURLLoaderFactory`. |
| 871 | // |
| 872 | // For subresource requests the `ClientSecurityState` is passed through |
| 873 | // `URLLoaderFactoryParams`, since each request client has a dedicated |
| 874 | // factory. That does not work for navigation requests because they all share |
| 875 | // a common factory, so each request is tagged with a `ClientSecurityState` to |
| 876 | // use instead. |
| 877 | network::mojom::ClientSecurityStatePtr |
| 878 | BuildClientSecurityStateForNavigationFetch(); |
| 879 | |
| 880 | // Returns the `ClientSecurityState` to be used for subresource fetches by the |
| 881 | // document we are navigating to. |
| 882 | // |
| 883 | // Must only be called after `ReadyToCommitNavigation()`. |
| 884 | network::mojom::ClientSecurityStatePtr |
| 885 | BuildClientSecurityStateForCommittedDocument(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 886 | |
| 887 | bool ua_change_requires_reload() const { return ua_change_requires_reload_; } |
| 888 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 889 | void SetRequiredCSP(network::mojom::ContentSecurityPolicyPtr csp); |
| 890 | network::mojom::ContentSecurityPolicyPtr TakeRequiredCSP(); |
| 891 | |
Arthur Sonzogni | 6445759 | 2022-11-22 11:08:59 | [diff] [blame] | 892 | bool is_credentialless() const { return is_credentialless_; } |
Antonio Sartori | 5abc8de | 2021-07-13 08:42:47 | [diff] [blame] | 893 | |
Titouan Rigoudy | 2f995bc | 2021-02-19 19:39:41 | [diff] [blame] | 894 | // Returns a pointer to the policies copied from the navigation initiator. |
| 895 | // Returns nullptr if this navigation had no initiator. |
| 896 | const PolicyContainerPolicies* GetInitiatorPolicyContainerPolicies() const; |
| 897 | |
Daniel Cheng | 284c3894 | 2022-09-22 23:30:34 | [diff] [blame] | 898 | // The DocumentToken that should be used for the document created as a result |
| 899 | // of committing this navigation. |
| 900 | // - must only be called for cross-document navigations |
| 901 | // - must not be called before the navigation is ready to commit |
| 902 | const blink::DocumentToken& GetDocumentToken() const; |
| 903 | |
Titouan Rigoudy | 2f995bc | 2021-02-19 19:39:41 | [diff] [blame] | 904 | // Returns the policies of the new document being navigated to. |
| 905 | // |
| 906 | // Must only be called after ReadyToCommitNavigation(). |
| 907 | const PolicyContainerPolicies& GetPolicyContainerPolicies() const; |
| 908 | |
| 909 | // Creates a new policy container for Blink connected to this navigation's |
| 910 | // PolicyContainerHost. |
| 911 | // |
| 912 | // Must only be called after ReadyToCommitNavigation(). |
| 913 | blink::mojom::PolicyContainerPtr CreatePolicyContainerForBlink(); |
| 914 | |
Ming-Ying Chung | c327e53 | 2023-04-17 05:55:29 | [diff] [blame] | 915 | // Returns a new refptr to this navigation's PolicyContainerHost. |
| 916 | // |
| 917 | // Must only be called after ReadyToCommitNavigation(). |
| 918 | // It is invalid to call after `TakePolicyContainerHost()`. |
| 919 | scoped_refptr<PolicyContainerHost> GetPolicyContainerHost(); |
| 920 | |
Titouan Rigoudy | 2f995bc | 2021-02-19 19:39:41 | [diff] [blame] | 921 | // Moves this navigation's PolicyContainerHost out of this instance. |
| 922 | // |
| 923 | // Must only be called after ReadyToCommitNavigation(). |
Antonio Sartori | db967c5 | 2021-01-20 09:54:30 | [diff] [blame] | 924 | scoped_refptr<PolicyContainerHost> TakePolicyContainerHost(); |
Antonio Sartori | 3cfa3b6 | 2020-10-09 10:42:40 | [diff] [blame] | 925 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 926 | CrossOriginEmbedderPolicyReporter* coep_reporter() { |
| 927 | return coep_reporter_.get(); |
| 928 | } |
| 929 | |
Camille Lamy | 36afacd | 2025-01-16 14:25:18 | [diff] [blame] | 930 | DocumentIsolationPolicyReporter* dip_reporter() { |
| 931 | return dip_reporter_.get(); |
| 932 | } |
| 933 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 934 | std::unique_ptr<CrossOriginEmbedderPolicyReporter> TakeCoepReporter(); |
Camille Lamy | 36afacd | 2025-01-16 14:25:18 | [diff] [blame] | 935 | std::unique_ptr<DocumentIsolationPolicyReporter> TakeDipReporter(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 936 | |
| 937 | // Returns UKM SourceId for the page we are navigating away from. |
| 938 | // Equal to GetRenderFrameHost()->GetPageUkmSourceId() for subframe |
| 939 | // and same-document navigations and to |
| 940 | // RenderFrameHost::FromID(GetPreviousRenderFrameHostId()) |
| 941 | // ->GetPageUkmSourceId() for main-frame cross-document navigations. |
Takashi Toyoshima | c27d7b4 | 2023-07-27 05:09:26 | [diff] [blame] | 942 | // Note: If this method is called on a prerender navigation, it will return |
| 943 | // ukm::kInvalidSourceId due to our data collection policy. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 944 | ukm::SourceId GetPreviousPageUkmSourceId(); |
| 945 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 946 | void OnServiceWorkerAccessed(const GURL& scope, |
| 947 | AllowServiceWorkerResult allowed); |
| 948 | |
| 949 | // Take all cookie observers associated with this navigation. |
| 950 | // Typically this is called when navigation commits to move these observers to |
| 951 | // the committed document. |
Daniel Cheng | 9c9fa1a | 2022-01-14 03:42:11 | [diff] [blame] | 952 | [[nodiscard]] std::vector< |
Giovanni Ortuño Urquidi | d2e5fab | 2025-04-02 20:44:03 | [diff] [blame] | 953 | std::pair<mojo::PendingReceiver<network::mojom::CookieAccessObserver>, |
| 954 | CookieAccessDetails::Source>> |
Daniel Cheng | 9c9fa1a | 2022-01-14 03:42:11 | [diff] [blame] | 955 | TakeCookieObservers(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 956 | |
Giovanni Ortuño Urquidi | e0a77b4 | 2025-03-28 14:31:35 | [diff] [blame] | 957 | void NotifyCookiesAccessed( |
| 958 | std::vector<network::mojom::CookieAccessDetailsPtr> details_vector, |
| 959 | CookieAccessDetails::Source source); |
| 960 | |
Steven Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 961 | // Take all Trust Token observers associated with this navigation. |
| 962 | // Typically this is called when navigation commits to move these observers to |
| 963 | // the committed document. |
| 964 | [[nodiscard]] std::vector< |
| 965 | mojo::PendingReceiver<network::mojom::TrustTokenAccessObserver>> |
| 966 | TakeTrustTokenObservers(); |
| 967 | |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 968 | // Take all shared dictionary observers associated with this navigation. |
| 969 | // Typically this is called when navigation commits to move these observers to |
| 970 | // the committed document. |
| 971 | [[nodiscard]] std::vector< |
| 972 | mojo::PendingReceiver<network::mojom::SharedDictionaryAccessObserver>> |
| 973 | TakeSharedDictionaryAccessObservers(); |
| 974 | |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 975 | [[nodiscard]] std::vector< |
| 976 | mojo::PendingReceiver<network::mojom::DeviceBoundSessionAccessObserver>> |
| 977 | TakeDeviceBoundSessionAccessObservers(); |
| 978 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 979 | // Returns the coop status information relevant to the current navigation. |
| 980 | CrossOriginOpenerPolicyStatus& coop_status() { return coop_status_; } |
| 981 | |
Rakina Zata Amni | 21e66f2 | 2021-09-17 00:41:51 | [diff] [blame] | 982 | // Returns true if this is a NavigationRequest represents a WebView |
| 983 | // loadDataWithBaseUrl navigation. |
Rakina Zata Amni | 8a1c6b3 | 2021-09-29 06:41:29 | [diff] [blame] | 984 | bool IsLoadDataWithBaseURL() const; |
Rakina Zata Amni | eca2799 | 2020-12-12 10:48:31 | [diff] [blame] | 985 | |
Robbie McElrath | e28ca82 | 2021-09-27 20:23:29 | [diff] [blame] | 986 | // Calculates the origin that this NavigationRequest may commit. |
| 987 | // |
| 988 | // GetTentativeOriginAtRequestTime must be called before the final HTTP |
| 989 | // response is received (unlike GetOriginToCommit), but the returned origin |
| 990 | // may differ from the final origin committed by this navigation (e.g. the |
| 991 | // origin may change because of subsequent redirects, or because of CSP |
Lukasz Anforowicz | 435e68d | 2022-11-09 21:47:44 | [diff] [blame] | 992 | // headers in the final response; or because no commit may happen at all in |
| 993 | // case of downloads or 204 responses). Prefer to use GetOriginToCommit if |
Robbie McElrath | e28ca82 | 2021-09-27 20:23:29 | [diff] [blame] | 994 | // possible. |
| 995 | url::Origin GetTentativeOriginAtRequestTime(); |
| 996 | |
Daniel Cheng | 738266dc | 2020-09-11 19:56:28 | [diff] [blame] | 997 | // If this navigation fails with net::ERR_BLOCKED_BY_CLIENT, act as if it were |
| 998 | // cancelled by the user and do not commit an error page. |
| 999 | void SetSilentlyIgnoreBlockedByClient() { |
| 1000 | silently_ignore_blocked_by_client_ = true; |
| 1001 | } |
| 1002 | |
W. James MacLean | 46cf2621 | 2020-10-01 16:43:37 | [diff] [blame] | 1003 | // Returns the current url from GetURL() packaged with other state required to |
| 1004 | // properly determine SiteInstances and process allocation. |
| 1005 | UrlInfo GetUrlInfo(); |
| 1006 | |
arthursonzogni | 7ddc654 | 2021-04-09 09:16:50 | [diff] [blame] | 1007 | bool is_overriding_user_agent() const { |
| 1008 | return commit_params_->is_overriding_user_agent; |
Rakina Zata Amni | b597d63 | 2020-12-01 00:56:00 | [diff] [blame] | 1009 | } |
| 1010 | |
Matt Menke | 7f2e1ac5 | 2020-12-10 01:16:10 | [diff] [blame] | 1011 | // Returns the IsolationInfo that should be used to load subresources. |
| 1012 | const net::IsolationInfo& isolation_info_for_subresources() const { |
| 1013 | return isolation_info_for_subresources_; |
| 1014 | } |
| 1015 | |
Rakina Zata Amni | 1f34f4d | 2020-12-12 09:36:21 | [diff] [blame] | 1016 | // NeedsUrlLoader() returns true if the navigation needs to use the |
| 1017 | // NavigationURLLoader for loading the document. |
| 1018 | // |
| 1019 | // A few types of navigations don't make any network requests. They can be |
| 1020 | // committed immediately in BeginNavigation(). They self-contain the data |
| 1021 | // needed for commit: |
| 1022 | // - about:blank: The renderer already knows how to load the empty document. |
| 1023 | // - about:srcdoc: The data is stored in the iframe srcdoc attribute. |
| 1024 | // - same-document: Only the history and URL are updated, no new document. |
| 1025 | // - MHTML subframe: The data is in the archive, owned by the main frame. |
| 1026 | // |
| 1027 | // Note #1: Even though "data:" URLs don't generate actual network requests, |
| 1028 | // including within MHTML subframes, they are still handled by the network |
| 1029 | // stack. The reason is that a few of them can't always be handled otherwise. |
| 1030 | // For instance: |
| 1031 | // - the ones resulting in downloads. |
| 1032 | // - the "invalid" ones. An error page is generated instead. |
| 1033 | // - the ones with an unsupported MIME type. |
| 1034 | // - the ones targeting the top-level frame on Android. |
| 1035 | // |
| 1036 | // Note #2: Even though "javascript:" URL and RendererDebugURL fit very well |
| 1037 | // in this category, they don't use the NavigationRequest. |
| 1038 | // |
Nate Chapin | 060cb95 | 2023-02-08 21:13:07 | [diff] [blame] | 1039 | // Note #3: Navigations that do not use a URL loader do not send the usual |
| 1040 | // set of callbacks to NavigationThrottle. Instead, they send a single |
| 1041 | // separate callback, WillCommitWithoutUrlLoader(). |
Rakina Zata Amni | 1f34f4d | 2020-12-12 09:36:21 | [diff] [blame] | 1042 | bool NeedsUrlLoader(); |
| 1043 | |
Jonathan Hao | 90ddbd4 | 2023-07-12 14:23:48 | [diff] [blame] | 1044 | network::mojom::PrivateNetworkRequestPolicy private_network_request_policy() |
Arthur Hemery | 373a780 | 2020-12-23 16:32:36 | [diff] [blame] | 1045 | const { |
Jonathan Hao | 90ddbd4 | 2023-07-12 14:23:48 | [diff] [blame] | 1046 | return private_network_request_policy_; |
Arthur Hemery | 373a780 | 2020-12-23 16:32:36 | [diff] [blame] | 1047 | } |
| 1048 | |
Alexander Timin | 23c110b | 2021-01-14 02:39:04 | [diff] [blame] | 1049 | // Whether this navigation request waits for the result of beforeunload before |
| 1050 | // proceeding. |
| 1051 | bool IsWaitingForBeforeUnload(); |
| 1052 | |
Rakina Zata Amni | 6345d2f | 2021-02-12 04:07:57 | [diff] [blame] | 1053 | // Returns the original request url: |
| 1054 | // - If this navigation resulted in an error page, this will return the URL |
| 1055 | // of the page that failed to load. |
| 1056 | // - If this is navigation is triggered by loadDataWithBaseURL or related |
| 1057 | // functions, this will return the data URL (or data header, in case of |
| 1058 | // loadDataAsStringWithBaseURL). |
| 1059 | // - Otherwise, this will return the first URL in |redirect_chain_|. This |
| 1060 | // means if the navigation is started due to a client redirect, we will return |
| 1061 | // the URL of the page that initiated the client redirect. Otherwise we will |
| 1062 | // return the first destination URL for this navigation. |
| 1063 | // NOTE: This might result in a different value than original_url in |
| 1064 | // |commit_params_|, which is always set to the first destination URL for this |
| 1065 | // navigation. |
| 1066 | const GURL& GetOriginalRequestURL(); |
| 1067 | |
Kevin McNee | b49d2b8 | 2022-06-14 16:53:14 | [diff] [blame] | 1068 | // The previous main frame URL. This may be empty if there was no last |
| 1069 | // committed entry. |
| 1070 | const GURL& GetPreviousMainFrameURL() const; |
| 1071 | |
Carlos Caballero | a383797 | 2021-04-13 12:25:38 | [diff] [blame] | 1072 | // Whether this navigation is activating an existing page (e.g. served from |
| 1073 | // the BackForwardCache or Prerender) |
Julie Jeongeun Kim | 5a66adb4 | 2021-08-11 07:14:10 | [diff] [blame] | 1074 | bool IsPageActivation() const override; |
Carlos Caballero | a383797 | 2021-04-13 12:25:38 | [diff] [blame] | 1075 | |
Rakina Zata Amni | da410b46 | 2024-09-17 00:07:48 | [diff] [blame] | 1076 | // Returns whether the navigation type is a restore navigation. |
| 1077 | bool IsRestore() const; |
| 1078 | |
| 1079 | // Returns whether the navigation type is a reload navigation. |
| 1080 | bool IsReload() const; |
| 1081 | |
Harkiran Bolaria | 8bee006 | 2021-08-12 10:06:34 | [diff] [blame] | 1082 | // Sets state pertaining to prerender activations. This is only called if |
| 1083 | // this navigation is a prerender activation. |
| 1084 | void SetPrerenderActivationNavigationState( |
| 1085 | std::unique_ptr<NavigationEntryImpl> prerender_navigation_entry, |
| 1086 | const blink::mojom::FrameReplicationState& replication_state); |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 1087 | |
| 1088 | std::unique_ptr<NavigationEntryImpl> TakePrerenderNavigationEntry(); |
| 1089 | |
Harkiran Bolaria | 8bee006 | 2021-08-12 10:06:34 | [diff] [blame] | 1090 | // Returns value that is only valid for prerender activation navigations. |
| 1091 | const blink::mojom::FrameReplicationState& |
| 1092 | prerender_main_frame_replication_state() { |
| 1093 | return prerender_navigation_state_->prerender_main_frame_replication_state; |
| 1094 | } |
| 1095 | |
W. James MacLean | 53e24b7 | 2023-05-09 20:57:07 | [diff] [blame] | 1096 | // Origin-keyed Agent Cluster (OAC) state needs to be tracked for origins that |
| 1097 | // opt-in or opt-out, so that a given origin is treated consistently within a |
| 1098 | // given BrowsingInstance. This ensures that foo.example.com will have the |
| 1099 | // same OAC state in a BrowsingInstance even if multiple documents in the |
| 1100 | // origin have different headers. |
| 1101 | // |
| 1102 | // This function ensures that this OAC state is tracked in cases where it is |
| 1103 | // not handled elsewhere. For example, OAC origins that end up in origin-keyed |
| 1104 | // processes already track their OAC state during SiteInstance creation. |
| 1105 | // However, SiteInstance does not track origin state in the following cases, |
| 1106 | // which this function handles: |
| 1107 | // |
| 1108 | // 1) If process isolation for OAC is disabled (e.g., on low-memory Android |
| 1109 | // devices), the origin will use a site-keyed SiteInstance that does not |
| 1110 | // record OAC state for the origin. |
| 1111 | // |
| 1112 | // 2) If the origin has no header but ends up with OAC-by-default (and |
| 1113 | // kOriginKeyedProcessesByDefault is not enabled), the origin will use a |
| 1114 | // site-keyed SiteInstance. |
| 1115 | // |
| 1116 | // 3) If the origin opts-out of OAC using a header, it will use a site-keyed |
| 1117 | // SiteInstance. |
| 1118 | // |
W. James MacLean | 2a84fbf | 2023-05-12 18:13:43 | [diff] [blame] | 1119 | // 4)If the origin opts-in to OAC using a header, but it is first placed in a |
| 1120 | // speculative RenderFrameHost before the header is received, it creates a |
| 1121 | // SiteInfo with default isolation and an origin-keyed process (by default). |
| 1122 | // In this case, the origin was not tracked when the SiteInstance was created, |
| 1123 | // and needs to be tracked later when the opt-in header is observed. |
| 1124 | // |
W. James MacLean | 53e24b7 | 2023-05-09 20:57:07 | [diff] [blame] | 1125 | // In all of these cases, this function updates the BrowsingInstance to keep |
| 1126 | // track of the OAC state for this NavigationRequest's origin. |
| 1127 | // |
| 1128 | // TODO(wjmaclean): Cases 1 and 2 will not be necessary once we use |
| 1129 | // origin-keyed SiteInstances within a site-keyed process, via |
W. James MacLean | 2a84fbf | 2023-05-12 18:13:43 | [diff] [blame] | 1130 | // SiteInstanceGroup. Cases 3 and 4 will still be needed at that point, but |
| 1131 | // might become simpler. |
W. James MacLean | 53e24b7 | 2023-05-09 20:57:07 | [diff] [blame] | 1132 | void AddOriginAgentClusterStateIfNecessary( |
| 1133 | const IsolationContext& isolation_context); |
| 1134 | |
Antonio Sartori | 0a7117a | 2021-04-01 09:23:37 | [diff] [blame] | 1135 | // Store a console message, which will be sent to the final RenderFrameHost |
| 1136 | // immediately after requesting the navigation to commit. |
| 1137 | // |
| 1138 | // /!\ WARNING /!\: Beware of not leaking cross-origin information to a |
| 1139 | // potentially compromised renderer when using this method. |
| 1140 | void AddDeferredConsoleMessage(blink::mojom::ConsoleMessageLevel level, |
| 1141 | std::string message); |
| 1142 | |
Yao Xiao | 6e1f7d3 | 2022-01-07 03:28:40 | [diff] [blame] | 1143 | bool is_deferred_on_fenced_frame_url_mapping_for_testing() const { |
| 1144 | return is_deferred_on_fenced_frame_url_mapping_; |
| 1145 | } |
| 1146 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1147 | base::WeakPtr<NavigationRequest> GetWeakPtr(); |
| 1148 | |
Khushal Sagar | c05a8b29 | 2024-02-28 15:29:25 | [diff] [blame] | 1149 | bool is_running_potential_prerender_activation_checks() const { |
| 1150 | return is_running_potential_prerender_activation_checks_; |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 1151 | } |
| 1152 | |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 1153 | FrameTreeNodeId prerender_frame_tree_node_id() const { |
David Bokan | f7db706 | 2021-05-27 16:23:10 | [diff] [blame] | 1154 | DCHECK(prerender_frame_tree_node_id_.has_value()) |
| 1155 | << "Must be called after StartNavigation()"; |
| 1156 | return prerender_frame_tree_node_id_.value(); |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1157 | } |
| 1158 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1159 | const std::optional<FencedFrameProperties>& GetFencedFrameProperties() const { |
Garrett Tanzer | 291a2d5 | 2023-03-20 22:41:57 | [diff] [blame] | 1160 | return fenced_frame_properties_; |
| 1161 | } |
| 1162 | |
Garrett Tanzer | 29de711 | 2022-12-06 21:26:32 | [diff] [blame] | 1163 | // Compute and return the `FencedFrameProperties` that this |
| 1164 | // `NavigationRequest` acts under, i.e. the properties attached to this |
Xiaochen Zhou | 86f2e71 | 2023-09-13 19:55:04 | [diff] [blame] | 1165 | // `NavigationRequest` if present. |
| 1166 | // Otherwise, returns the fenced frame properties associated with the given |
| 1167 | // source. See `FrameTreeNode::GetFencedFrameProperties()` on how fenced |
| 1168 | // frame properties are obtained for different sources. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 1169 | // TODO(crbug.com/40060657): Once navigation support for urn::uuid in iframes |
Xiaochen Zhou | 86f2e71 | 2023-09-13 19:55:04 | [diff] [blame] | 1170 | // is deprecated, remove the parameter `node_source`. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1171 | const std::optional<FencedFrameProperties>& ComputeFencedFrameProperties( |
Xiaochen Zhou | 86f2e71 | 2023-09-13 19:55:04 | [diff] [blame] | 1172 | FencedFramePropertiesNodeSource node_source = |
| 1173 | FencedFramePropertiesNodeSource::kClosestAncestor) const; |
Garrett Tanzer | 29de711 | 2022-12-06 21:26:32 | [diff] [blame] | 1174 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1175 | const std::optional<base::UnguessableToken> ComputeFencedFrameNonce() const; |
Garrett Tanzer | 34cb92fe | 2022-09-28 17:50:54 | [diff] [blame] | 1176 | |
Daniel Cheng | e8b6940 | 2021-05-25 20:44:44 | [diff] [blame] | 1177 | void RenderFallbackContentForObjectTag(); |
| 1178 | |
Titouan Rigoudy | 6f54ec5 | 2021-07-12 19:36:34 | [diff] [blame] | 1179 | // Returns the vector of web features used during the navigation, whose |
| 1180 | // recording was delayed until the new document that used them commits. |
| 1181 | // |
| 1182 | // Empties this instance's vector. |
| 1183 | std::vector<blink::mojom::WebFeature> TakeWebFeaturesToLog(); |
| 1184 | |
Yao Xiao | 58c2f2c | 2023-05-16 20:05:18 | [diff] [blame] | 1185 | void set_subresource_proxying_url_loader_service_bind_context( |
| 1186 | base::WeakPtr<SubresourceProxyingURLLoaderService::BindContext> |
| 1187 | bind_context) { |
| 1188 | DCHECK(!subresource_proxying_url_loader_service_bind_context_); |
| 1189 | subresource_proxying_url_loader_service_bind_context_ = bind_context; |
Yao Xiao | 549be447 | 2023-01-03 22:53:12 | [diff] [blame] | 1190 | } |
| 1191 | |
Ming-Ying Chung | ae4dbb7 | 2023-12-07 05:32:37 | [diff] [blame] | 1192 | base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> |
| 1193 | keep_alive_url_loader_factory_context() { |
| 1194 | return keep_alive_url_loader_factory_context_; |
| 1195 | } |
| 1196 | |
Ming-Ying Chung | 977404c | 2023-11-08 12:30:10 | [diff] [blame] | 1197 | void set_keep_alive_url_loader_factory_context( |
Rakina Zata Amni | a68329fe | 2025-07-02 10:15:03 | [diff] [blame] | 1198 | base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> factory_context); |
Ming-Ying Chung | 977404c | 2023-11-08 12:30:10 | [diff] [blame] | 1199 | |
Nan Lin | c643c96 | 2025-02-21 01:47:43 | [diff] [blame] | 1200 | base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> |
| 1201 | fetch_later_loader_factory_context() { |
| 1202 | return fetch_later_loader_factory_context_; |
| 1203 | } |
| 1204 | |
Ming-Ying Chung | 977404c | 2023-11-08 12:30:10 | [diff] [blame] | 1205 | void set_fetch_later_loader_factory_context( |
Rakina Zata Amni | a68329fe | 2025-07-02 10:15:03 | [diff] [blame] | 1206 | base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> factory_context); |
| 1207 | |
| 1208 | void SetKeepAliveURLLoaderFactoryContextForTesting( |
| 1209 | base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> factory_context); |
| 1210 | void SetFetchLaterLoaderFactoryContextForTesting( |
| 1211 | base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> factory_context); |
Ming-Ying Chung | 977404c | 2023-11-08 12:30:10 | [diff] [blame] | 1212 | |
Lukasz Anforowicz | 0e07b765 | 2021-06-04 18:27:51 | [diff] [blame] | 1213 | // Helper for logging crash keys related to a NavigationRequest (e.g. |
Lukasz Anforowicz | 36d24d3 | 2022-02-15 19:02:53 | [diff] [blame] | 1214 | // "navigation_request_url", "navigation_request_initiator", and |
| 1215 | // "navigation_request_is_same_document"). The crash keys will be logged if a |
| 1216 | // ScopedCrashKeys instance exists when a crash or DumpWithoutCrashing |
| 1217 | // happens. |
Lukasz Anforowicz | 0e07b765 | 2021-06-04 18:27:51 | [diff] [blame] | 1218 | class ScopedCrashKeys { |
| 1219 | public: |
| 1220 | explicit ScopedCrashKeys(NavigationRequest& navigation_request); |
| 1221 | ~ScopedCrashKeys(); |
| 1222 | |
| 1223 | // No copy constructor and no copy assignment operator. |
| 1224 | ScopedCrashKeys(const ScopedCrashKeys&) = delete; |
| 1225 | ScopedCrashKeys& operator=(const ScopedCrashKeys&) = delete; |
| 1226 | |
| 1227 | private: |
| 1228 | url::debug::ScopedOriginCrashKey initiator_origin_; |
Lukasz Anforowicz | 36d24d3 | 2022-02-15 19:02:53 | [diff] [blame] | 1229 | url::debug::ScopedUrlCrashKey url_; |
| 1230 | base::debug::ScopedCrashKeyString is_same_document_; |
Lukasz Anforowicz | 0e07b765 | 2021-06-04 18:27:51 | [diff] [blame] | 1231 | }; |
| 1232 | |
W. James MacLean | 00568d7 | 2022-02-24 19:36:55 | [diff] [blame] | 1233 | // Used in tests to indicate this navigation should force a BrowsingInstance |
| 1234 | // swap. |
| 1235 | void set_force_new_browsing_instance(bool force_new_browsing_instance) { |
| 1236 | force_new_browsing_instance_ = force_new_browsing_instance; |
| 1237 | } |
| 1238 | |
| 1239 | // When this returns true, it indicates this navigation should force a |
| 1240 | // BrowsingInstance swap. Used only in tests. |
| 1241 | bool force_new_browsing_instance() { return force_new_browsing_instance_; } |
| 1242 | |
Steve Kobes | 8d111ba | 2024-11-12 15:23:51 | [diff] [blame] | 1243 | // Marks this navigation as requiring a new compositor (RenderWidgetHost). |
| 1244 | void set_force_new_compositor(bool force_new_compositor) { |
| 1245 | force_new_compositor_ = force_new_compositor; |
| 1246 | } |
| 1247 | |
| 1248 | // True if this navigation requires a new compositor (RenderWidgetHost). |
| 1249 | bool force_new_compositor() { return force_new_compositor_; } |
| 1250 | |
Julie Jeongeun Kim | 4a5fef2 | 2022-04-02 02:08:38 | [diff] [blame] | 1251 | const scoped_refptr<NavigationOrDocumentHandle>& |
| 1252 | navigation_or_document_handle() { |
| 1253 | return navigation_or_document_handle_; |
| 1254 | } |
| 1255 | |
Khushal Sagar | 7b26135c6 | 2022-11-08 20:25:42 | [diff] [blame] | 1256 | // Initializes state which is passed from the old Document to the new Document |
| 1257 | // for a ViewTransition. |
Khushal Sagar | 91b54422 | 2024-03-12 17:36:59 | [diff] [blame] | 1258 | void SetViewTransitionState( |
| 1259 | std::unique_ptr<ScopedViewTransitionResources> resources, |
| 1260 | blink::ViewTransitionState view_transition_state); |
Khushal Sagar | 7b26135c6 | 2022-11-08 20:25:42 | [diff] [blame] | 1261 | |
Jonathan Njeunje | 5861859 | 2023-04-06 21:10:02 | [diff] [blame] | 1262 | // Returns a const reference to a blink::RuntimeFeatureStateContext (RFSC) |
| 1263 | // object. Once the commit params are sent to the renderer we no longer allow |
| 1264 | // write access to the RFSC, but read access is still available. |
sbingler | a07ae73 | 2022-12-02 20:49:05 | [diff] [blame] | 1265 | // |
Jonathan Njeunje | 5861859 | 2023-04-06 21:10:02 | [diff] [blame] | 1266 | // Note: This method has another |
| 1267 | // version, `GetMutableRuntimeFeatureStateContext()`, accessible via |
| 1268 | // NavigationHandle and will return a mutable reference to the RFSC. |
sbingler | a07ae73 | 2022-12-02 20:49:05 | [diff] [blame] | 1269 | const blink::RuntimeFeatureStateContext& GetRuntimeFeatureStateContext(); |
| 1270 | |
Arthur Hemery | a2e2c5f1 | 2023-01-16 15:00:15 | [diff] [blame] | 1271 | BrowsingContextGroupSwap browsing_context_group_swap() const { |
| 1272 | return browsing_context_group_swap_; |
| 1273 | } |
| 1274 | |
Nate Chapin | 6c43c02 | 2023-02-13 23:32:42 | [diff] [blame] | 1275 | // If the navigation fails before commit and |pending_navigation_api_key_| has |
| 1276 | // been set, then the renderer will be notified of the pre-commit failure and |
| 1277 | // provide |pending_navigation_api_key_| so that the Navigation API can fire |
| 1278 | // events and reject promises. |
| 1279 | // This should only be set if this request's frame initiated the navigation, |
| 1280 | // because only the initiating frame has outstanding promises to reject. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1281 | void set_pending_navigation_api_key(std::optional<std::string> key) { |
Nate Chapin | 6c43c02 | 2023-02-13 23:32:42 | [diff] [blame] | 1282 | pending_navigation_api_key_ = key; |
| 1283 | } |
| 1284 | |
Nate Chapin | 154b14b | 2023-02-17 18:28:16 | [diff] [blame] | 1285 | // Returns the navigation token for this request if this NavigationRequest |
| 1286 | // is for a history navigation, and it might be cancelled via the navigate |
| 1287 | // event. In that case, any associated subframe history navigations will be |
| 1288 | // deferred until this navigation commits. |
| 1289 | // This may only be called if this is a main-frame same-document navigation. |
| 1290 | // Will return a valid token if canceling traversals via the navigate event is |
| 1291 | // enabled, this is a history navigation, a navigate event is registered in |
| 1292 | // the renderer, and the frame has met the user activation requirements to be |
| 1293 | // allowed to cancel the navigation. |
| 1294 | // This token will then be provided to the subframe NavigationRequests via |
| 1295 | // set_main_frame_same_document_history_token(). |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1296 | std::optional<base::UnguessableToken> |
Nate Chapin | 154b14b | 2023-02-17 18:28:16 | [diff] [blame] | 1297 | GetNavigationTokenForDeferringSubframes(); |
| 1298 | |
| 1299 | // For subframe NavigationRequests, these set and return the main frame's |
| 1300 | // NavigationRequest token, in the case that the main frame returns it from |
Nate Chapin | 17e648f | 2023-05-09 16:58:35 | [diff] [blame] | 1301 | // GetNavigationTokenForDeferringSubframes(). Note that by the time |
| 1302 | // `main_frame_same_document_history_token()` is called, the NavigationRequest |
| 1303 | // represented by that token may have already finished and been deleted, so |
| 1304 | // any attempt to lookup based on this token must null-check the request. |
Nate Chapin | 154b14b | 2023-02-17 18:28:16 | [diff] [blame] | 1305 | void set_main_frame_same_document_history_token( |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1306 | std::optional<base::UnguessableToken> token) { |
Nate Chapin | 154b14b | 2023-02-17 18:28:16 | [diff] [blame] | 1307 | main_frame_same_document_navigation_token_ = token; |
| 1308 | } |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1309 | std::optional<base::UnguessableToken> |
Nate Chapin | 154b14b | 2023-02-17 18:28:16 | [diff] [blame] | 1310 | main_frame_same_document_history_token() { |
| 1311 | return main_frame_same_document_navigation_token_; |
| 1312 | } |
| 1313 | |
| 1314 | // When a SubframeHistoryNavigationThrottle is created, it registers itself |
| 1315 | // with the NavigationRequest for the main frame. If the main frame |
| 1316 | // NavigationRequest commits, then these throttles will be resumed in |
| 1317 | // UnblockPendingSubframeNavigationRequestsIfNeeded(). |
| 1318 | // If it is canceled instead, these throttles will all be canceled. |
| 1319 | // Takes a WeakPtr because `throttle` is owned by another NavigationRequest, |
| 1320 | // and that request may be canceled outside of our control, in which case |
| 1321 | // `throttle` will be destroyed. |
| 1322 | void AddDeferredSubframeNavigationThrottle( |
| 1323 | base::WeakPtr<SubframeHistoryNavigationThrottle> throttle); |
| 1324 | |
Mingyu Lei | 1fa6a1f | 2023-02-21 13:17:46 | [diff] [blame] | 1325 | std::unique_ptr<RenderFrameHostImpl::CookieChangeListener> |
| 1326 | TakeCookieChangeListener() { |
| 1327 | return std::move(cookie_change_listener_); |
| 1328 | } |
| 1329 | |
Daniel Rubery | 03e7199 | 2025-02-19 22:03:30 | [diff] [blame] | 1330 | std::unique_ptr<RenderFrameHostImpl::DeviceBoundSessionObserver> |
| 1331 | TakeDeviceBoundSessionObserver() { |
| 1332 | return std::move(device_bound_session_observer_); |
| 1333 | } |
| 1334 | |
Rakina Zata Amni | 49657c77 | 2023-03-31 06:41:53 | [diff] [blame] | 1335 | // Returns true if there is a speculative RFH that has a pending commit |
| 1336 | // cross-document navigation, and this NavigationRequest is not a pending |
| 1337 | // commit NavigationRequest itself. This means that this navigation should be |
| 1338 | // queued (i.e. wait for the pending commit navigation to finish committing), |
| 1339 | // before continuing and creating a new speculative RFH to commit in, so that |
| 1340 | // it won't cause the existing pending commit RFH to be deleted. This function |
| 1341 | // should only be called for navigations that are owned by the FrameTreeNode |
| 1342 | // (i.e. it hasn't moved to the RenderFrameHost that it will commit in yet), |
| 1343 | // as only those navigations can be queued. |
| 1344 | bool ShouldQueueDueToExistingPendingCommitRFH() const; |
| 1345 | |
| 1346 | void set_resume_commit_closure(base::OnceClosure closure) { |
Daniel Cheng | d08a43a | 2023-03-16 05:10:50 | [diff] [blame] | 1347 | resume_commit_closure_ = std::move(closure); |
| 1348 | } |
| 1349 | |
Daniel Cheng | 557868f | 2023-07-28 00:10:20 | [diff] [blame] | 1350 | // Records metrics for `GetFrameHostForNavigation()` attempts that failed due |
| 1351 | // to this `NavigationRequest` being in the pending commit state. |
| 1352 | // `commit_attempt` should be true if `GetFrameHostForNavigation()` failed |
| 1353 | // when trying to get a RenderFrameHost when committing a navigation. |
| 1354 | void RecordMetricsForBlockedGetFrameHostAttempt(bool commit_attempt); |
| 1355 | |
Rakina Zata Amni | 208f767 | 2023-04-07 12:21:25 | [diff] [blame] | 1356 | // Creates a WebUI object for this navigation and saves it in `web_ui_`. Later |
Rakina Zata Amni | 4fffc98 | 2023-04-09 12:44:12 | [diff] [blame] | 1357 | // on, the WebUI created will be moved to `frame_host` (if `frame_host` is |
| 1358 | // null, it means a RenderFrameHost has not been picked for the navigation). |
Rakina Zata Amni | bbae651 | 2023-04-11 21:49:50 | [diff] [blame] | 1359 | void CreateWebUIIfNeeded(RenderFrameHostImpl* frame_host); |
Rakina Zata Amni | 208f767 | 2023-04-07 12:21:25 | [diff] [blame] | 1360 | |
| 1361 | bool HasWebUI() { return !!web_ui_; } |
| 1362 | |
Rakina Zata Amni | bbae651 | 2023-04-11 21:49:50 | [diff] [blame] | 1363 | WebUIImpl* web_ui() { return web_ui_.get(); } |
| 1364 | |
Rakina Zata Amni | 208f767 | 2023-04-07 12:21:25 | [diff] [blame] | 1365 | std::unique_ptr<WebUIImpl> TakeWebUI() { |
| 1366 | CHECK(HasWebUI()); |
| 1367 | return std::move(web_ui_); |
| 1368 | } |
Rakina Zata Amni | a229230 | 2023-04-04 06:22:11 | [diff] [blame] | 1369 | |
Camillia Smith Barnes | 3cad1ba | 2023-10-30 20:10:16 | [diff] [blame] | 1370 | bool shared_storage_writable_eligible() const { |
| 1371 | return shared_storage_writable_eligible_; |
| 1372 | } |
Camillia Smith Barnes | 6d2966c8 | 2023-08-23 21:16:18 | [diff] [blame] | 1373 | |
Rakina Zata Amni | 1ca8dfdb | 2023-04-22 01:59:26 | [diff] [blame] | 1374 | enum ErrorPageProcess { |
| 1375 | kNotErrorPage, |
| 1376 | kPostCommitErrorPage, |
| 1377 | kCurrentProcess, |
| 1378 | kDestinationProcess, |
| 1379 | kIsolatedProcess |
| 1380 | }; |
| 1381 | // Helper to determine whether a navigation is committing an error page and |
| 1382 | // should stay in the current process (kCurrentProcess), the destination |
| 1383 | // URL's process (kDestinationProcess), an isolated process |
| 1384 | // (kIsolatedProcess), or is a post-commit error page that does not have any |
| 1385 | // specific process requirements and goes through the "normal navigation" |
| 1386 | // path. Returns kNotErrorPage if the navigation is not anerror page |
| 1387 | // navigation. |
| 1388 | ErrorPageProcess ComputeErrorPageProcess(); |
| 1389 | |
Alex Moshchuk | 854e0be7 | 2023-08-04 22:35:35 | [diff] [blame] | 1390 | // This describes the reason for performing an early RenderFrameHost swap, if |
| 1391 | // any. This enum is used in UMA histograms, so existing values should be |
| 1392 | // neither reordered nor removed. |
| 1393 | enum class EarlyRenderFrameHostSwapType { |
| 1394 | kNone = 0, |
| 1395 | kInitialFrame = 1, |
| 1396 | kCrashedFrame = 2, |
Khushal Sagar | 3e7ea37 | 2024-05-28 13:34:48 | [diff] [blame] | 1397 | kNavigationTransition = 3, // DEPRECATED |
Alex Moshchuk | 663e88d | 2023-09-15 16:21:00 | [diff] [blame] | 1398 | kMaxValue = kNavigationTransition, |
Alex Moshchuk | 854e0be7 | 2023-08-04 22:35:35 | [diff] [blame] | 1399 | }; |
| 1400 | |
| 1401 | // Remember if this navigation triggered an early swap of a speculative |
| 1402 | // RenderFrameHost to become a current RenderFrameHost prior to the |
| 1403 | // navigation commit, and if so, what triggered it. |
| 1404 | void set_early_render_frame_host_swap_type( |
| 1405 | EarlyRenderFrameHostSwapType type) { |
| 1406 | early_render_frame_host_swap_type_ = type; |
| 1407 | } |
Lijin Shen | e4511c1 | 2024-03-19 19:31:30 | [diff] [blame] | 1408 | EarlyRenderFrameHostSwapType early_render_frame_host_swap_type() const { |
Alex Moshchuk | 663e88d | 2023-09-15 16:21:00 | [diff] [blame] | 1409 | return early_render_frame_host_swap_type_; |
| 1410 | } |
Alex Moshchuk | 854e0be7 | 2023-08-04 22:35:35 | [diff] [blame] | 1411 | |
Rakina Zata Amni | 0c8ffbe | 2023-10-05 19:32:56 | [diff] [blame] | 1412 | void set_previous_render_frame_host_id(GlobalRenderFrameHostId id) { |
| 1413 | previous_render_frame_host_id_ = id; |
| 1414 | } |
| 1415 | |
murakinonoka | c3e32a3 | 2024-01-16 06:01:30 | [diff] [blame] | 1416 | // Returns true if URL Loader has been created and hasn't been reset yet for |
| 1417 | // this navigation. |
| 1418 | bool HasLoader() const; |
| 1419 | |
Khushal Sagar | 2dd8a3d | 2024-02-13 20:49:25 | [diff] [blame] | 1420 | // Notifies that an IPC will be sent to the old Document's renderer to |
Khushal Sagar | 21c62681 | 2024-02-29 23:32:18 | [diff] [blame] | 1421 | // dispatch the `pageswap` event. Returns the parameters which should be |
Khushal Sagar | 2dd8a3d | 2024-02-13 20:49:25 | [diff] [blame] | 1422 | // used for the event if this is a same-origin navigation. |
Khushal Sagar | 21c62681 | 2024-02-29 23:32:18 | [diff] [blame] | 1423 | blink::mojom::PageSwapEventParamsPtr WillDispatchPageSwap(); |
Khushal Sagar | 2dd8a3d | 2024-02-13 20:49:25 | [diff] [blame] | 1424 | |
Khushal Sagar | 21c62681 | 2024-02-29 23:32:18 | [diff] [blame] | 1425 | // Returns true if this navigation is eligible for dispatching a `pageswap` |
Khushal Sagar | c05a8b29 | 2024-02-28 15:29:25 | [diff] [blame] | 1426 | // event on the old Document and the event has not been dispatched already. |
Khushal Sagar | 21c62681 | 2024-02-29 23:32:18 | [diff] [blame] | 1427 | bool ShouldDispatchPageSwapEvent() const; |
Khushal Sagar | d48998dc | 2024-02-26 16:05:32 | [diff] [blame] | 1428 | |
Khushal Sagar | 8e96670 | 2024-03-13 19:49:16 | [diff] [blame] | 1429 | // Returns true if there have been any cross-origin redirects in the |
| 1430 | // navigation's lifetime. A redirect is cross-origin if the redirect url is |
| 1431 | // cross-origin with "previous URL" of the navigation. previous URL here is |
| 1432 | // either the initial URL (which the navigation started with) or the URL from |
| 1433 | // the last redirect. |
| 1434 | // |
| 1435 | // Note: This will be false if the initial url is cross-origin and there are |
| 1436 | // no redirects. |
| 1437 | bool did_encounter_cross_origin_redirect() const { |
| 1438 | return did_encounter_cross_origin_redirect_; |
| 1439 | } |
| 1440 | |
Vladimir Levin | 6e894a9 | 2024-06-12 18:02:46 | [diff] [blame] | 1441 | // Determines whether this navigation request was initiated by an animated |
| 1442 | // transition. |
| 1443 | void set_was_initiated_by_animated_transition() { |
| 1444 | was_initiated_by_animated_transition_ = true; |
| 1445 | } |
| 1446 | bool was_initiated_by_animated_transition() const { |
| 1447 | return was_initiated_by_animated_transition_; |
| 1448 | } |
| 1449 | |
Rakina Zata Amni | 58681c6 | 2024-06-25 06:32:13 | [diff] [blame] | 1450 | void set_navigation_discard_reason( |
| 1451 | NavigationDiscardReason navigation_discard_reason) { |
| 1452 | CHECK(!navigation_discard_reason_.has_value()); |
| 1453 | navigation_discard_reason_ = navigation_discard_reason; |
| 1454 | } |
| 1455 | |
Keita Suzuki | f300e44 | 2025-07-16 07:38:11 | [diff] [blame] | 1456 | void set_extended_error_code(int extended_error_code) { |
| 1457 | CHECK(!extended_error_code_); |
| 1458 | extended_error_code_ = extended_error_code; |
| 1459 | } |
| 1460 | |
| 1461 | void set_error_navigation_trigger( |
| 1462 | ErrorNavigationTrigger error_navigation_trigger) { |
| 1463 | CHECK(!error_navigation_trigger_.has_value()); |
| 1464 | error_navigation_trigger_ = error_navigation_trigger; |
| 1465 | } |
| 1466 | |
Rakina Zata Amni | 63a7ab0 | 2024-09-15 07:40:03 | [diff] [blame] | 1467 | // Returns the type of this navigation (e.g. history, browser-initiated, etc) |
| 1468 | // to set as a discard reason on another navigation that is being discarded |
| 1469 | // because this navigation is taking its place in the FrameTreeNode. |
Rakina Zata Amni | b5dbc9f | 2024-07-16 07:47:33 | [diff] [blame] | 1470 | NavigationDiscardReason GetTypeForNavigationDiscardReason(); |
| 1471 | |
Mustafa Emre Acer | 1001b3d | 2024-07-09 23:10:43 | [diff] [blame] | 1472 | void set_force_no_https_upgrade() { force_no_https_upgrade_ = true; } |
| 1473 | |
William Liu | 0c323bfce | 2024-11-13 21:21:10 | [diff] [blame] | 1474 | bool was_reset_for_cross_document_restart() const { |
| 1475 | return was_reset_for_cross_document_restart_; |
| 1476 | } |
| 1477 | |
Diana Qu | 2d6c85b | 2025-06-17 01:13:14 | [diff] [blame] | 1478 | // Returns the document sequence number from the associated |
| 1479 | // FrameNavigationEntry, if this NavigationRequest corresponds to a session |
| 1480 | // history navigation. The value is cleared if the navigation performs a |
| 1481 | // redirect or results in an origin change, in which case the |
| 1482 | // NavigationRequest is no longer tied to the original entry. |
| 1483 | int64_t frame_entry_document_sequence_number() const { |
| 1484 | return frame_entry_document_sequence_number_; |
| 1485 | } |
| 1486 | |
John Kim | 1a6735b | 2025-08-12 19:16:50 | [diff] [blame] | 1487 | // Returns the canvas noise token used for canvas noising on the renderer. |
| 1488 | // Only one token should be generated per page and should use the main frame's |
| 1489 | // origin to generate such. Main frames should use this accessor to populate |
| 1490 | // the content::Page and subsequent blink::Pages. Subframes should not use |
| 1491 | // this accessor, but instead should use `PageImpl::canvas_noise_token()` to |
| 1492 | // get the canvas noise token. |
| 1493 | std::optional<uint64_t> canvas_noise_token() { |
| 1494 | CHECK(IsInMainFrame()); |
| 1495 | return canvas_noise_token_; |
| 1496 | } |
| 1497 | |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 1498 | // Called when the browser process is about to process beforeunload handlers |
| 1499 | // for this navigation, including sending an IPC to the renderer process to |
| 1500 | // run beforeunload handlers when necessary. |
| 1501 | void WillStartBeforeUnload(); |
| 1502 | |
| 1503 | // This struct holds timestamps of various stages of one navigation. This is |
| 1504 | // useful for recording a trace of a navigation, as well as metrics for |
| 1505 | // durations of all intervals within a navigation once a navigation finishes |
| 1506 | // committing. Note that a navigation finishes committing once |
| 1507 | // RenderFrameHostImpl::DidCommitNavigation completes, which could be slightly |
| 1508 | // after the corresponding NavigationRequest has been destroyed. |
| 1509 | // |
| 1510 | // Over the course of a navigation, various timestamps are kept in different |
| 1511 | // places, such as NavigationRequest fields, NavigationHandleTiming, |
| 1512 | // CommonNavigationParams, etc. The purpose of this struct is to bring all the |
| 1513 | // relevant timestamps into one place, and make it possible to record a |
| 1514 | // complete navigation timeline after NavigationRequest destruction. Note that |
| 1515 | // this is different from NavigationHandleTiming, because the latter is in |
| 1516 | // content/public and exposed to content embedders, making it tricky to modify |
| 1517 | // or extend. |
| 1518 | // |
| 1519 | // This struct should be created near the end of NavigationRequest's lifetime |
| 1520 | // (see `GenerateNavigationTimelineForMetrics()`), and `MarkFinish()` should |
| 1521 | // be called at the end of a navigation before using the `Timeline`'s |
| 1522 | // timestamp values in traces and metrics. |
| 1523 | struct Timeline { |
| 1524 | Timeline(); |
| 1525 | Timeline(const Timeline& timeline); |
| 1526 | ~Timeline(); |
| 1527 | |
| 1528 | // Record the timestamp for when the navigation finishes. Should be done at |
| 1529 | // the end of RenderFrameHostImpl::DidCommitNavigationInternal() before |
| 1530 | // recording a trace of this timeline. |
| 1531 | void MarkFinish(); |
| 1532 | |
| 1533 | // The timestamps below are in chronological order. Note that some of them |
| 1534 | // might be null depending on the navigation (e.g., navigations that don't |
| 1535 | // use the network stack will not populate the loader-related timestamps, |
| 1536 | // and renderer-initiated same-document navigations would be missing most |
| 1537 | // timestamps except for `start`, `finish`, and the DidCommit IPC |
| 1538 | // timestamps). |
| 1539 | |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 1540 | // The time at which the navigation starts, as accurately as we can |
| 1541 | // determine. Note that for renderer-initiated navigations, this will be the |
| 1542 | // time when the navigation starts in the renderer. |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 1543 | // |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 1544 | // Note that this may not be the start time used by many current navigation |
| 1545 | // related metrics, such as FCP, since those often use `common_params_start` |
| 1546 | // to avoid including beforeunload durations. |
| 1547 | // TODO(crbug.com/385170155): Update these metrics to have a more consistent |
| 1548 | // and representative start time and duration. |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 1549 | base::TimeTicks start; |
| 1550 | |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 1551 | // For navigations that start in the renderer and target local frames, this |
| 1552 | // is the time at which "beforeunload phase 1" starts, when ShouldClose is |
| 1553 | // called for any local frames that may be affected. This is null for other |
| 1554 | // types of navigations which do not use beforeunload phase 1 (e.g., browser |
| 1555 | // initiated navigations, or navigations that target remote frames). See |
| 1556 | // also beforeunload_phase2_start, for the second phase of running |
| 1557 | // beforeunload handlers which may exist in other processes. |
| 1558 | // |
| 1559 | // The delta between this and `start` captures the time the renderer process |
| 1560 | // spends initializing the navigation, including notifying |
| 1561 | // RenderFrameObserver::DidStartNavigation observers. |
| 1562 | base::TimeTicks beforeunload_phase1_start; |
| 1563 | |
| 1564 | // The time "beforeunload phase 1" ends in the initiating renderer process, |
| 1565 | // or null if that phase is not used in this navigation. Recording this |
| 1566 | // allows beforeunload duration to be excluded from navigation metrics, |
| 1567 | // since that time may include user-visible dialogs or JavaScript code that |
| 1568 | // is out of our control. |
| 1569 | base::TimeTicks beforeunload_phase1_end; |
| 1570 | |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 1571 | // The time at which the NavigationRequest is created. The delta between |
| 1572 | // this and `start` covers the time between starting the navigation |
| 1573 | // (possibly in the renderer process) and the browser process starting |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 1574 | // doing work for it. It is often useful to exclude beforeunload phase 1 |
| 1575 | // duration from this delta. |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 1576 | base::TimeTicks navigation_request_creation; |
| 1577 | |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 1578 | // The time "beforeunload phase 2" processing was started by the browser |
| 1579 | // process. This phase can occur on any type of navigation (e.g., browser or |
| 1580 | // renderer initiated), to run beforeunload handlers in any process that may |
| 1581 | // be affected by the navigation (e.g., remote frames, OOPIFs). Might be |
| 1582 | // null if the navigation did not need to run beforeunload handlers, or if |
| 1583 | // all of the necessary handlers have already run in "beforeunload phase 1." |
| 1584 | // Note that legacy PostTask cases (which do not run beforeunload handlers) |
| 1585 | // are not treated as beforeunload phase 2. |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 1586 | // |
| 1587 | // The delta between this and `navigation_request_creation` captures the |
| 1588 | // time the browser process spends initializing the navigation, including |
| 1589 | // creating a speculative RenderFrameHost (if needed) and picking a target |
| 1590 | // SiteInstance/process. |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 1591 | base::TimeTicks beforeunload_phase2_start; |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 1592 | |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 1593 | // The time "beforeunload phase 2" processing ends, or null if that phase is |
| 1594 | // not used in this navigation. Recording this allows beforeunload duration |
| 1595 | // to be excluded from navigation metrics, since that may include |
| 1596 | // user-visible dialogs or JavaScript code that is out of our control. |
| 1597 | base::TimeTicks beforeunload_phase2_end; |
| 1598 | |
| 1599 | // The adjusted start time used by many navigation metrics, such as FCP. |
| 1600 | // This is currently set inconsistently, and can be after beforeunload phase |
| 1601 | // 1 in the initiating renderer, or early in a browser-initiated navigation, |
| 1602 | // or after beforeunload phase 2 in the browser process if that phase is |
| 1603 | // used. As a result, this value may not be in chronological order in this |
| 1604 | // struct, and it is mainly recorded here for metrics that measure the start |
| 1605 | // time inconsistency. |
| 1606 | // TODO(crbug.com/385170155): Remove this once navigation start metrics are |
| 1607 | // more consistent. |
| 1608 | base::TimeTicks common_params_start; |
| 1609 | |
| 1610 | // The time at which NavigationRequest::BeginNavigation() is called. This is |
| 1611 | // a decision point at which a network request may or may not be made. The |
| 1612 | // delta between this and `navigation_request_creation` (with any |
| 1613 | // beforeunload phase 2 duration removed) captures additional navigation |
| 1614 | // work in the browser process. |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 1615 | base::TimeTicks begin_navigation; |
| 1616 | |
| 1617 | // The time at which the NavigationURLLoader for the navigation was started. |
| 1618 | // This captures the time for additional initialization in the browser |
| 1619 | // process before the network request is sent, including processing of |
| 1620 | // WillStartRequest NavigationThrottle events. |
| 1621 | base::TimeTicks loader_start; |
| 1622 | // The time when the browser is ready to fetch the document using an HTTP |
| 1623 | // request. |
| 1624 | base::TimeTicks loader_fetch_start; |
| 1625 | // The time when the final (which might also be the first) headers are |
| 1626 | // received. |
| 1627 | base::TimeTicks loader_receive_headers; |
| 1628 | // The time when the HTTP response is received and |
| 1629 | // NavigationRequest::OnResponseStarted() is called. The delta between this |
| 1630 | // and `loader_start` captures the time spent waiting for a response from |
| 1631 | // the network stack. |
| 1632 | base::TimeTicks receive_response; |
| 1633 | // The time when the CommitNavigation IPC is sent to the renderer process. |
| 1634 | // Might be null if a navigation doesn't send the CommitNavigation IPC, such |
| 1635 | // as for renderer-initiated same-document navigations or synchronous |
| 1636 | // about:blank navigations. The delta between this and `receive_response` |
| 1637 | // captures the time spent running throttles and possibly selecting a more |
| 1638 | // appropriate renderer process. |
| 1639 | base::TimeTicks commit_ipc_sent; |
| 1640 | // The time when the renderer receives the CommitNavigation IPC. Taken in |
| 1641 | // the renderer process. Might be null in the same cases as |
| 1642 | // `commit_ipc_sent` above. The delta between this and `commit_ipc_sent` |
| 1643 | // represents the mojo and task delay to deliver the CommitNavigation |
| 1644 | // message from the browser process to renderer process. |
| 1645 | base::TimeTicks renderer_commit_ipc_received; |
| 1646 | // The time when the renderer finishes processing the navigation commit and |
| 1647 | // replies to the browser's CommitNavigation IPC. Taken in the renderer |
| 1648 | // process. The delta between this and `renderer_commit_ipc_received` |
| 1649 | // represents the total time the renderer process spend on committing the |
| 1650 | // navigation (e.g., swapping in the new frame/document and destroying the |
| 1651 | // old document). |
| 1652 | base::TimeTicks renderer_did_commit_ipc_sent; |
| 1653 | // The time at which the DidCommitNavigation IPC (which is usually a |
| 1654 | // response to the CommitNavigation IPC) is received by RenderFrameHost. The |
| 1655 | // delta between `renderer_did_commit_ipc_sent` and this represents the mojo |
| 1656 | // delay to deliver the response from the renderer process to the browser |
| 1657 | // process. |
| 1658 | base::TimeTicks did_commit_ipc_received; |
| 1659 | // The time at which DidCommitNavigation is completed. This includes the |
| 1660 | // time to commit the navigation, dispatch events such as |
| 1661 | // DidFinishNavigation() to observers, and destroy the NavigationRequest. |
| 1662 | // `MarkFinish()` is used to record this timestamp at the end of navigation. |
| 1663 | base::TimeTicks finish; |
| 1664 | }; |
| 1665 | |
| 1666 | // Fill in the timestamps needed to generate a trace of the navigation |
| 1667 | // timeline. This should only be called when processing the |
| 1668 | // DidCommitNavigation IPC, once the final DidCommitProvisionalLoadParams are |
| 1669 | // received from the renderer and timestamps from prior navigation stages are |
| 1670 | // already collected. |
| 1671 | // |
| 1672 | // Note that this leaves the `finish` timestamp empty in the returned |
| 1673 | // `Timeline` object. `finish` cannot be recorded within NavigationRequest |
| 1674 | // because a navigation actually ends after a NavigationRequest is destroyed. |
| 1675 | // `MarkFinish()` should be called on the returned `Timeline` to manually |
| 1676 | // record that timestamp before using it to record trace events or metrics. |
| 1677 | NavigationRequest::Timeline GenerateNavigationTimelineForMetrics( |
| 1678 | const mojom::DidCommitProvisionalLoadParams& params, |
| 1679 | const base::TimeTicks& did_commit_ipc_received_time); |
| 1680 | |
Hayato Ito | 5750b44 | 2025-05-29 02:38:06 | [diff] [blame] | 1681 | // Returns a UKM builder for the navigation timeline if UKMs should be |
| 1682 | // recorded for this navigation. Navigation timeline UKMs are recorded at the |
| 1683 | // frequency of 0.001. |
| 1684 | std::optional<ukm::builders::NavigationTimeline> |
| 1685 | GetNavigationTimelineUkmBuilder(); |
| 1686 | |
Takashi Toyoshima | 96a07bb | 2025-06-06 06:45:58 | [diff] [blame] | 1687 | // Called when the NavigationThrottleRunner is done processing the navigation |
| 1688 | // event of type `event`. `result` is the final |
| 1689 | // NavigationThrottle::ThrottleCheckResult for this event. |
| 1690 | void OnNavigationEventProcessed( |
| 1691 | NavigationThrottleEvent event, |
| 1692 | NavigationThrottle::ThrottleCheckResult result); |
| 1693 | |
Jiacheng Guo | 2d8489d7 | 2025-08-18 06:51:14 | [diff] [blame] | 1694 | // Returns the PrerenderHostId driving the navigation. If the navigation |
| 1695 | // is not derived from a prerendered page, the default-consturcted null |
| 1696 | // value will be returned. |
| 1697 | PrerenderHostId GetPrerenderHostId() const; |
| 1698 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1699 | private: |
| 1700 | friend class NavigationRequestTest; |
Nasko Oskov | 32f9589 | 2025-06-02 20:45:08 | [diff] [blame] | 1701 | FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, SanitizeRedirectsForCommit); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1702 | |
Antonio Sartori | 0a7117a | 2021-04-01 09:23:37 | [diff] [blame] | 1703 | struct ConsoleMessage { |
| 1704 | blink::mojom::ConsoleMessageLevel level; |
| 1705 | std::string message; |
| 1706 | }; |
| 1707 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1708 | NavigationRequest( |
| 1709 | FrameTreeNode* frame_tree_node, |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 1710 | blink::mojom::CommonNavigationParamsPtr common_params, |
| 1711 | blink::mojom::BeginNavigationParamsPtr begin_params, |
| 1712 | blink::mojom::CommitNavigationParamsPtr commit_params, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1713 | bool browser_initiated, |
| 1714 | bool from_begin_navigation, |
Hiroki Nakagawa | adcffc50 | 2021-06-16 10:47:51 | [diff] [blame] | 1715 | bool is_synchronous_renderer_commit, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1716 | const FrameNavigationEntry* frame_navigation_entry, |
| 1717 | NavigationEntryImpl* navitation_entry, |
| 1718 | std::unique_ptr<NavigationUIData> navigation_ui_data, |
Hiroki Nakagawa | b078d3ef | 2021-06-03 06:55:43 | [diff] [blame] | 1719 | scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1720 | mojo::PendingAssociatedRemote<mojom::NavigationClient> navigation_client, |
Hiroki Nakagawa | a67fe9c3 | 2021-06-04 01:15:49 | [diff] [blame] | 1721 | scoped_refptr<PrefetchedSignedExchangeCache> |
| 1722 | prefetched_signed_exchange_cache, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1723 | std::optional<base::SafeRef<RenderFrameHostImpl>> |
Mingyu Lei | 2e0b586e | 2023-07-25 18:26:00 | [diff] [blame] | 1724 | rfh_restored_from_back_forward_cache, |
John Delaney | 8623c64 | 2021-01-06 17:37:07 | [diff] [blame] | 1725 | int initiator_process_id, |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 1726 | bool was_opener_suppressed, |
Nan Lin | 944e9b4e | 2022-04-12 13:51:22 | [diff] [blame] | 1727 | bool is_pdf, |
Garrett Tanzer | 4785246 | 2022-07-20 18:16:41 | [diff] [blame] | 1728 | bool is_embedder_initiated_fenced_frame_navigation = false, |
Rakina Zata Amni | af55b5b6 | 2022-07-19 23:11:03 | [diff] [blame] | 1729 | mojo::PendingReceiver<mojom::NavigationRendererCancellationListener> |
Camillia Smith Barnes | 6a64396 | 2023-03-03 00:28:58 | [diff] [blame] | 1730 | renderer_cancellation_listener = mojo::NullReceiver(), |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1731 | std::optional<std::u16string> embedder_shared_storage_context = |
| 1732 | std::nullopt); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1733 | |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 1734 | // Checks if this navigation may activate a prerendered page. If it's |
| 1735 | // possible, schedules to start running CommitDeferringConditions for |
| 1736 | // prerendered page activation and returns true. |
| 1737 | bool MaybeStartPrerenderingActivationChecks(); |
| 1738 | |
| 1739 | // Called from OnCommitDeferringConditionChecksComplete() if this request is |
| 1740 | // activating a prerendered page. |
| 1741 | void OnPrerenderingActivationChecksComplete( |
| 1742 | CommitDeferringCondition::NavigationType navigation_type, |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 1743 | std::optional<FrameTreeNodeId> candidate_prerender_frame_tree_node_id); |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 1744 | |
Yao Xiao | 6e1f7d3 | 2022-01-07 03:28:40 | [diff] [blame] | 1745 | // Get the `FencedFrameURLMapping` associated with the current page. |
| 1746 | FencedFrameURLMapping& GetFencedFrameURLMap(); |
| 1747 | |
| 1748 | // True if this is a fenced frame navigation to an urn:uuid. |
| 1749 | bool NeedFencedFrameURLMapping(); |
| 1750 | |
| 1751 | // FencedFrameURLMapping::MappingResultObserver implementation. |
| 1752 | // Called from `FencedFrameURLMapping` when the mapping decision is made, and |
| 1753 | // resume the deferred navigation. |
| 1754 | void OnFencedFrameURLMappingComplete( |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1755 | const std::optional<FencedFrameProperties>& properties) override; |
Yao Xiao | 6e1f7d3 | 2022-01-07 03:28:40 | [diff] [blame] | 1756 | |
| 1757 | // Called from BeginNavigation(), OnPrerenderingActivationChecksComplete(), |
| 1758 | // or OnFencedFrameURLMappingComplete(). |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 1759 | void BeginNavigationImpl(); |
| 1760 | |
Domenic Denicola | 5fdc2b7f | 2021-01-15 20:29:17 | [diff] [blame] | 1761 | // Checks if the response requests an isolated origin via the |
| 1762 | // Origin-Agent-Cluster header, and if so opts in the origin to be isolated. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1763 | void CheckForIsolationOptIn(const GURL& url); |
| 1764 | |
Hiroki Nakagawa | 1aef8b0 | 2021-06-25 10:30:33 | [diff] [blame] | 1765 | // Returns whether this navigation request is requesting opt-in |
| 1766 | // origin-isolation. |
W. James MacLean | c07dc41b | 2022-07-25 18:52:16 | [diff] [blame] | 1767 | bool IsOriginAgentClusterOptInRequested(); |
| 1768 | |
| 1769 | // Returns whether this navigation request is requesting opt-out from |
| 1770 | // origin-isolation. Always returns false if |
| 1771 | // AreOriginAgentClustersEnabledByDefault() is false. |
| 1772 | bool IsOriginAgentClusterOptOutRequested(); |
Hiroki Nakagawa | 1aef8b0 | 2021-06-25 10:30:33 | [diff] [blame] | 1773 | |
W. James MacLean | 53e24b7 | 2023-05-09 20:57:07 | [diff] [blame] | 1774 | // Returns whether this NavigationRequest should use an origin-keyed agent |
| 1775 | // cluster, specifically in cases where no Origin-Agent-Cluster header has |
| 1776 | // been observed, either because no response has yet been received or because |
| 1777 | // it had no such header. (Returns false if the header is observed.) |
| 1778 | // |
| 1779 | // Note that an origin-keyed process may be used if this returns true, if |
| 1780 | // kOriginKeyedProcessesByDefault is enabled. |
Daniel Vogelheim | c141399 | 2021-12-02 22:54:08 | [diff] [blame] | 1781 | bool IsIsolationImplied(); |
| 1782 | |
Hiroki Nakagawa | 1aef8b0 | 2021-06-25 10:30:33 | [diff] [blame] | 1783 | // The Origin-Agent-Cluster end result is determined early in the lifecycle of |
| 1784 | // a NavigationRequest, but used late. In particular, we want to trigger use |
| 1785 | // counters and console warnings once navigation has committed. |
Daniel Vogelheim | c141399 | 2021-12-02 22:54:08 | [diff] [blame] | 1786 | void DetermineOriginAgentClusterEndResult(); |
Hiroki Nakagawa | 1aef8b0 | 2021-06-25 10:30:33 | [diff] [blame] | 1787 | void ProcessOriginAgentClusterEndResult(); |
| 1788 | |
Daniel Cheng | 273a2c1 | 2022-09-28 02:28:22 | [diff] [blame] | 1789 | void PopulateDocumentTokenForCrossDocumentNavigation(); |
| 1790 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1791 | // NavigationURLLoaderDelegate implementation. |
| 1792 | void OnRequestRedirected( |
| 1793 | const net::RedirectInfo& redirect_info, |
Brianna Goldstein | d22b064 | 2022-10-11 16:30:50 | [diff] [blame] | 1794 | const net::NetworkAnonymizationKey& network_anonymization_key, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1795 | network::mojom::URLResponseHeadPtr response_head) override; |
| 1796 | void OnResponseStarted( |
| 1797 | network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints, |
| 1798 | network::mojom::URLResponseHeadPtr response_head, |
| 1799 | mojo::ScopedDataPipeConsumerHandle response_body, |
Matt Menke | 7f615a1 | 2020-12-11 17:06:44 | [diff] [blame] | 1800 | GlobalRequestID request_id, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1801 | bool is_download, |
Brianna Goldstein | d22b064 | 2022-10-11 16:30:50 | [diff] [blame] | 1802 | net::NetworkAnonymizationKey network_anonymization_key, |
Hiroshige Hayashizaki | 9e0f286 | 2024-02-09 16:54:00 | [diff] [blame] | 1803 | SubresourceLoaderParams subresource_loader_params, |
Kenichi Ishibashi | cf248fb | 2021-04-07 22:29:35 | [diff] [blame] | 1804 | EarlyHints early_hints) override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1805 | void OnRequestFailed( |
| 1806 | const network::URLLoaderCompletionStatus& status) override; |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1807 | std::optional<NavigationEarlyHintsManagerParams> |
Kenichi Ishibashi | 1f67a2d | 2021-09-02 01:36:48 | [diff] [blame] | 1808 | CreateNavigationEarlyHintsManagerParams( |
Kenichi Ishibashi | f3f8052 | 2021-07-16 02:37:07 | [diff] [blame] | 1809 | const network::mojom::EarlyHints& early_hints) override; |
Hiroshige Hayashizaki | 83cd175 | 2025-07-31 17:46:25 | [diff] [blame] | 1810 | bool ShouldClearParsedHeadersOnTestReceiveRedirect() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1811 | |
Daniel Cheng | d08a43a | 2023-03-16 05:10:50 | [diff] [blame] | 1812 | // Selecting a `RenderFrameHost` to commit a navigation may occasionally fail. |
| 1813 | // When this happens, the navigation will bind a closure to continue the |
| 1814 | // navigation and assign it to `resume_commit_closure_`. This closure may run |
| 1815 | // even when it is still not possible to proceed; see the comment on the |
| 1816 | // `resume_commit_closure_` field for the full details. |
| 1817 | |
| 1818 | // Corresponds to navigations committing from `OnResponseStarted()`: |
| 1819 | void SelectFrameHostForOnResponseStarted( |
| 1820 | network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints, |
| 1821 | bool is_download, |
Hiroshige Hayashizaki | 9e0f286 | 2024-02-09 16:54:00 | [diff] [blame] | 1822 | SubresourceLoaderParams subresource_loader_params); |
Daniel Cheng | dfb15f3 | 2023-04-26 05:17:02 | [diff] [blame] | 1823 | void SelectFrameHostForOnRequestFailedInternal( |
Daniel Cheng | 77ae2b0 | 2023-05-10 04:16:46 | [diff] [blame] | 1824 | bool exists_in_cache, |
Daniel Cheng | dfb15f3 | 2023-04-26 05:17:02 | [diff] [blame] | 1825 | bool skip_throttles, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1826 | const std::optional<std::string>& error_page_content); |
Daniel Cheng | fa8ffcf | 2023-05-04 05:43:46 | [diff] [blame] | 1827 | void SelectFrameHostForCrossDocumentNavigationWithNoUrlLoader(); |
Daniel Cheng | d08a43a | 2023-03-16 05:10:50 | [diff] [blame] | 1828 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1829 | // To be called whenever a navigation request fails. If |skip_throttles| is |
| 1830 | // true, the registered NavigationThrottle(s) won't get a chance to intercept |
| 1831 | // NavigationThrottle::WillFailRequest. It should be used when a request |
| 1832 | // failed due to a throttle result itself. |error_page_content| is only used |
| 1833 | // when |skip_throttles| is true. If |collapse_frame| is true, the associated |
| 1834 | // frame tree node is collapsed. |
| 1835 | void OnRequestFailedInternal( |
| 1836 | const network::URLLoaderCompletionStatus& status, |
| 1837 | bool skip_throttles, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1838 | const std::optional<std::string>& error_page_content, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1839 | bool collapse_frame); |
| 1840 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1841 | // Called when the NavigationThrottles have been checked by the |
| 1842 | // NavigationHandle. |
| 1843 | void OnStartChecksComplete(NavigationThrottle::ThrottleCheckResult result); |
| 1844 | void OnRedirectChecksComplete(NavigationThrottle::ThrottleCheckResult result); |
| 1845 | void OnFailureChecksComplete(NavigationThrottle::ThrottleCheckResult result); |
| 1846 | void OnWillProcessResponseChecksComplete( |
| 1847 | NavigationThrottle::ThrottleCheckResult result); |
Nate Chapin | 060cb95 | 2023-02-08 21:13:07 | [diff] [blame] | 1848 | void OnWillCommitWithoutUrlLoaderChecksComplete( |
| 1849 | NavigationThrottle::ThrottleCheckResult result); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1850 | |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 1851 | // Runs CommitDeferringConditions. |
| 1852 | // |
| 1853 | // For prerendered page activation, this is called at the beginning of the |
| 1854 | // navigation (i.e., in BeginNavigation()). This is because activating a |
| 1855 | // prerendered page must be an atomic, synchronous operation so there is no |
| 1856 | // chance for the prerender to be cancelled during the operation. The |
| 1857 | // CommitDeferringConditions are asynchronous, so they run at the beginning |
| 1858 | // of navigation. Once they finish, the atomic activation sequence runs. |
| 1859 | void RunCommitDeferringConditions(); |
| 1860 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 1861 | // Similar to the NavigationThrottle checks above but this is called from |
| 1862 | // CommitDeferringConditionRunner rather than NavigationThrottles and is |
| 1863 | // invoked after all throttle checks and commit checks have completed and the |
| 1864 | // navigation can proceed to commit. |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 1865 | void OnCommitDeferringConditionChecksComplete( |
| 1866 | CommitDeferringCondition::NavigationType navigation_type, |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 1867 | std::optional<FrameTreeNodeId> candidate_prerender_frame_tree_node_id) |
| 1868 | override; |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 1869 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1870 | // Called either by OnFailureChecksComplete() or OnRequestFailed() directly. |
| 1871 | // |error_page_content| contains the content of the error page (i.e. flattened |
| 1872 | // HTML, JS, CSS). |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 1873 | void CommitErrorPage(const std::optional<std::string>& error_page_content); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1874 | |
| 1875 | // Have a RenderFrameHost commit the navigation. The NavigationRequest will |
Matt Falkenhagen | 54adeaa | 2021-07-06 14:10:00 | [diff] [blame] | 1876 | // be destroyed sometime after this call, typically after the renderer has |
| 1877 | // informed the browser process that the commit has finished. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1878 | void CommitNavigation(); |
| 1879 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 1880 | // Commits the navigation to an existing page (back-forward cache navigation |
| 1881 | // or prerender activation). NavigationRequest will be destroyed after this |
| 1882 | // call. |
| 1883 | void CommitPageActivation(); |
| 1884 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1885 | // Checks if the specified CSP context's relevant CSP directive |
Antonio Sartori | 60acdfb | 2024-09-12 09:39:04 | [diff] [blame] | 1886 | // allows the navigation. This is called to perform the frame-src check. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1887 | bool IsAllowedByCSPDirective( |
Antonio Sartori | 5ecc8b93 | 2021-03-05 06:56:10 | [diff] [blame] | 1888 | const std::vector<network::mojom::ContentSecurityPolicyPtr>& policies, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1889 | network::CSPContext* context, |
| 1890 | network::mojom::CSPDirectiveName directive, |
| 1891 | bool has_followed_redirect, |
| 1892 | bool url_upgraded_after_redirect, |
Nan Lin | 171fe9a | 2022-02-17 16:42:16 | [diff] [blame] | 1893 | bool is_opaque_fenced_frame, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1894 | network::CSPContext::CheckCSPDisposition disposition); |
| 1895 | |
Antonio Sartori | 60acdfb | 2024-09-12 09:39:04 | [diff] [blame] | 1896 | // Checks if CSP allows the navigation. This will check the frame-src and |
| 1897 | // fenced-frame-src directives. Returns net::OK if the checks |
Nan Lin | efd66c8 | 2022-01-24 20:33:15 | [diff] [blame] | 1898 | // pass, and net::ERR_ABORTED or net::ERR_BLOCKED_BY_CSP depending on which |
| 1899 | // checks fail. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1900 | net::Error CheckCSPDirectives( |
Antonio Sartori | 5ecc8b93 | 2021-03-05 06:56:10 | [diff] [blame] | 1901 | RenderFrameHostCSPContext parent_context, |
| 1902 | const PolicyContainerPolicies* parent_policies, |
| 1903 | RenderFrameHostCSPContext initiator_context, |
| 1904 | const PolicyContainerPolicies* initiator_policies, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1905 | bool has_followed_redirect, |
| 1906 | bool url_upgraded_after_redirect, |
| 1907 | bool is_response_check, |
| 1908 | network::CSPContext::CheckCSPDisposition disposition); |
| 1909 | |
| 1910 | // Check whether a request should be allowed to continue or should be blocked |
| 1911 | // because it violates a CSP. This method can have two side effects: |
| 1912 | // - If a CSP is configured to send reports and the request violates the CSP, |
| 1913 | // a report will be sent. |
| 1914 | // - The navigation request may be upgraded from HTTP to HTTPS if a CSP is |
| 1915 | // configured to upgrade insecure requests. |
| 1916 | net::Error CheckContentSecurityPolicy(bool has_followed_redirect, |
| 1917 | bool url_upgraded_after_redirect, |
| 1918 | bool is_response_check); |
| 1919 | |
| 1920 | // Builds the parameters used to commit a navigation to a page that was |
| 1921 | // restored from the back-forward cache. |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 1922 | mojom::DidCommitProvisionalLoadParamsPtr |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 1923 | MakeDidCommitProvisionalLoadParamsForBFCacheRestore(); |
| 1924 | |
| 1925 | // Builds the parameters used to commit a navigation to a prerendered page |
| 1926 | // that was activated. |
| 1927 | mojom::DidCommitProvisionalLoadParamsPtr |
| 1928 | MakeDidCommitProvisionalLoadParamsForPrerenderActivation(); |
| 1929 | |
| 1930 | // Builds generic activation parameters used to commit a navigation to a page. |
| 1931 | mojom::DidCommitProvisionalLoadParamsPtr |
| 1932 | MakeDidCommitProvisionalLoadParamsForActivation(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1933 | |
| 1934 | // This enum describes the result of the credentialed subresource check for |
| 1935 | // the request. |
| 1936 | enum class CredentialedSubresourceCheckResult { |
| 1937 | ALLOW_REQUEST, |
| 1938 | BLOCK_REQUEST, |
| 1939 | }; |
| 1940 | |
| 1941 | // Chrome blocks subresource requests whose URLs contain embedded credentials |
| 1942 | // (e.g. `https://user:[email protected]/page.html`). Check whether the |
| 1943 | // request should be allowed to continue or should be blocked. |
| 1944 | CredentialedSubresourceCheckResult CheckCredentialedSubresource() const; |
| 1945 | |
| 1946 | // This enum describes the result of the legacy protocol check for |
| 1947 | // the request. |
| 1948 | enum class LegacyProtocolInSubresourceCheckResult { |
| 1949 | ALLOW_REQUEST, |
| 1950 | BLOCK_REQUEST, |
| 1951 | }; |
| 1952 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1953 | // Block about:srcdoc navigation that aren't expected to happen. For instance, |
| 1954 | // main frame navigations or about:srcdoc#foo. |
| 1955 | enum class AboutSrcDocCheckResult { |
| 1956 | ALLOW_REQUEST, |
| 1957 | BLOCK_REQUEST, |
| 1958 | }; |
| 1959 | AboutSrcDocCheckResult CheckAboutSrcDoc() const; |
| 1960 | |
arthursonzogni | 898dcda5 | 2021-01-21 08:50:10 | [diff] [blame] | 1961 | // When the embedder requires the use of Content Security Policy via Embedded |
| 1962 | // Enforcement, framed documents must either: |
| 1963 | // 1. Use the 'allow-csp-from' header to opt-into enforcement. |
| 1964 | // 2. Enforce its own CSP that subsumes the required CSP. |
| 1965 | // Framed documents that fail to do either of these will be blocked. |
| 1966 | // |
| 1967 | // See: |
| 1968 | // - https://w3c.github.io/webappsec-cspee/#required-csp-header |
| 1969 | // - https://w3c.github.io/webappsec-cspee/#allow-csp-from-header |
| 1970 | // |
| 1971 | // SetupCSPEmbeddedEnforcement() retrieve the iframe 'csp' attribute applying. |
| 1972 | // CheckCSPEmbeddedEnforcement() inspects the response headers. It decides if |
| 1973 | // the 'csp' attribute should be installed into the child. This might also |
| 1974 | // block it and display an error page instead. |
| 1975 | void SetupCSPEmbeddedEnforcement(); |
| 1976 | enum class CSPEmbeddedEnforcementResult { |
| 1977 | ALLOW_RESPONSE, |
| 1978 | BLOCK_RESPONSE, |
| 1979 | }; |
| 1980 | CSPEmbeddedEnforcementResult CheckCSPEmbeddedEnforcement(); |
| 1981 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1982 | // Called before a commit. Updates the history index and length held in |
| 1983 | // CommitNavigationParams. This is used to update this shared state with the |
| 1984 | // renderer process. |
Alex Moshchuk | 2f89d70 | 2023-12-18 21:48:23 | [diff] [blame] | 1985 | void UpdateHistoryParamsInCommitNavigationParams(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1986 | |
Nasko Oskov | 32f9589 | 2025-06-02 20:45:08 | [diff] [blame] | 1987 | // Helper method to sanitize URLs for redirects before the commit IPC is sent |
| 1988 | // to the renderer process. Must be called right before sending the IPC. |
| 1989 | void SanitizeRedirectsForCommit( |
| 1990 | blink::mojom::CommitNavigationParamsPtr& commit_params); |
| 1991 | |
Daniel Cheng | d08a43a | 2023-03-16 05:10:50 | [diff] [blame] | 1992 | // The disconnect handler for the NavigationClient Mojo interface; used as a |
| 1993 | // signal to potentially cancel navigations, e.g. when the renderer replaces |
| 1994 | // an existing NavigationClient connection with a new one or when the renderer |
| 1995 | // process crashes. |
| 1996 | void OnNavigationClientDisconnected(uint32_t reason, |
| 1997 | const std::string& description); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 1998 | |
| 1999 | // Binds the given error_handler to be called when an interface disconnection |
| 2000 | // happens on the renderer side. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2001 | void HandleInterfaceDisconnection( |
Daniel Cheng | d08a43a | 2023-03-16 05:10:50 | [diff] [blame] | 2002 | mojo::AssociatedRemote<mojom::NavigationClient>&); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2003 | |
| 2004 | // When called, this NavigationRequest will no longer interpret the interface |
| 2005 | // disconnection on the renderer side as an AbortNavigation. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 2006 | // TODO(crbug.com/40276805): remove this function when |
Arthur Hemery | 243e3e1 | 2023-07-25 14:00:26 | [diff] [blame] | 2007 | // NavigationRequest properly handles interface disconnection in all cases. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2008 | void IgnoreInterfaceDisconnection(); |
| 2009 | |
Hiroki Nakagawa | 1aef8b0 | 2021-06-25 10:30:33 | [diff] [blame] | 2010 | // Sets ID of the RenderProcessHost we expect the navigation to commit in. |
| 2011 | // This is used to inform the RenderProcessHost to expect a navigation to the |
| 2012 | // url we're navigating to. |
| 2013 | void SetExpectedProcess(RenderProcessHost* expected_process); |
| 2014 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2015 | // Inform the RenderProcessHost to no longer expect a navigation. |
| 2016 | void ResetExpectedProcess(); |
| 2017 | |
| 2018 | // If this is a same-site main-frame navigation where we did a proactive |
| 2019 | // BrowsingInstance swap but we're reusing the old page's process, we need |
| 2020 | // to send the routing ID and the updated lifecycle state of the old page so |
| 2021 | // that we can run pagehide and visibilitychange handlers of the old page |
| 2022 | // when we commit the new page. |
| 2023 | void AddOldPageInfoToCommitParamsIfNeeded(); |
| 2024 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2025 | // Record download related UseCounters when navigation is a download before |
| 2026 | // filtered by download_policy. |
Arthur Sonzogni | 6d88b3e | 2022-12-15 14:03:24 | [diff] [blame] | 2027 | void RecordDownloadUseCountersPrePolicyCheck(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2028 | |
| 2029 | // Record download related UseCounters when navigation is a download after |
| 2030 | // filtered by download_policy. |
| 2031 | void RecordDownloadUseCountersPostPolicyCheck(); |
| 2032 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2033 | void OnWillStartRequestProcessed( |
| 2034 | NavigationThrottle::ThrottleCheckResult result); |
| 2035 | void OnWillRedirectRequestProcessed( |
| 2036 | NavigationThrottle::ThrottleCheckResult result); |
| 2037 | void OnWillFailRequestProcessed( |
| 2038 | NavigationThrottle::ThrottleCheckResult result); |
| 2039 | void OnWillProcessResponseProcessed( |
| 2040 | NavigationThrottle::ThrottleCheckResult result); |
Nate Chapin | 060cb95 | 2023-02-08 21:13:07 | [diff] [blame] | 2041 | void OnWillCommitWithoutUrlLoaderProcessed( |
| 2042 | NavigationThrottle::ThrottleCheckResult result); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2043 | |
| 2044 | void CancelDeferredNavigationInternal( |
| 2045 | NavigationThrottle::ThrottleCheckResult result); |
| 2046 | |
| 2047 | // TODO(zetamoo): Remove the Will* methods and fold them into their callers. |
| 2048 | |
| 2049 | // Called when the URLRequest will start in the network stack. |
| 2050 | void WillStartRequest(); |
| 2051 | |
| 2052 | // Called when the URLRequest will be redirected in the network stack. |
| 2053 | // This will also inform the delegate that the request was redirected. |
| 2054 | // |
| 2055 | // |post_redirect_process| is the renderer process we expect to use to commit |
| 2056 | // the navigation now that it has been redirected. It can be null if there is |
| 2057 | // no live process that can be used. In that case, a suitable renderer process |
| 2058 | // will be created at commit time. |
Aaron Colwell | dc50263c | 2020-09-18 01:54:22 | [diff] [blame] | 2059 | // |
Arthur Hemery | 3a991c09 | 2021-12-22 12:04:24 | [diff] [blame] | 2060 | void WillRedirectRequest(const GURL& new_referrer_url, |
| 2061 | RenderProcessHost* post_redirect_process); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2062 | |
| 2063 | // Called when the URLRequest will fail. |
| 2064 | void WillFailRequest(); |
| 2065 | |
| 2066 | // Called when the URLRequest has delivered response headers and metadata. |
| 2067 | // |callback| will be called when all throttle checks have completed, |
| 2068 | // allowing the caller to cancel the navigation or let it proceed. |
| 2069 | // NavigationHandle will not call |callback| with a result of DEFER. |
| 2070 | // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called |
| 2071 | // just before calling |callback|. |
| 2072 | void WillProcessResponse(); |
| 2073 | |
Nate Chapin | 060cb95 | 2023-02-08 21:13:07 | [diff] [blame] | 2074 | // Called when no URLRequest will be needed to perform this navigation, just |
| 2075 | // before commit. |
| 2076 | void WillCommitWithoutUrlLoader(); |
| 2077 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2078 | // Checks for attempts to navigate to a page that is already referenced more |
| 2079 | // than once in the frame's ancestors. This is a helper function used by |
| 2080 | // WillStartRequest and WillRedirectRequest to prevent the navigation. |
| 2081 | bool IsSelfReferentialURL(); |
| 2082 | |
| 2083 | // RenderProcessHostObserver implementation. |
| 2084 | void RenderProcessExited(RenderProcessHost* host, |
| 2085 | const ChildProcessTerminationInfo& info) override; |
| 2086 | void RenderProcessHostDestroyed(RenderProcessHost* host) override; |
| 2087 | |
| 2088 | // Updates navigation handle timings. |
Rakina Zata Amni | 742c202 | 2024-07-02 05:29:17 | [diff] [blame] | 2089 | void UpdateNavigationHandleTimingsOnResponseReceived(bool is_redirect, |
| 2090 | bool is_first_response); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2091 | void UpdateNavigationHandleTimingsOnCommitSent(); |
| 2092 | |
| 2093 | // Helper function that computes the SiteInfo for |common_params_.url|. |
| 2094 | // Note: |site_info_| should only be updated with the result of this function. |
Arthur Hemery | 3a991c09 | 2021-12-22 12:04:24 | [diff] [blame] | 2095 | SiteInfo GetSiteInfoForCommonParamsURL(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2096 | |
| 2097 | // Updates the state of the navigation handle after encountering a server |
| 2098 | // redirect. |
| 2099 | void UpdateStateFollowingRedirect(const GURL& new_referrer_url); |
| 2100 | |
Jonathan Hao | 90ddbd4 | 2023-07-12 14:23:48 | [diff] [blame] | 2101 | // Updates |private_network_request_policy_| for ReadyToCommitNavigation(). |
Titouan Rigoudy | 40a9b51 | 2020-09-18 16:18:09 | [diff] [blame] | 2102 | // |
| 2103 | // Must not be called for same-document navigation requests nor for requests |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 2104 | // served from the back-forward cache or from prerendered pages. |
Jonathan Hao | 513c700 | 2023-07-11 14:27:57 | [diff] [blame] | 2105 | void UpdatePrivateNetworkRequestPolicy(); |
Titouan Rigoudy | 40a9b51 | 2020-09-18 16:18:09 | [diff] [blame] | 2106 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2107 | // Called when the navigation is ready to be committed. This will update the |
| 2108 | // |state_| and inform the delegate. |
John Abd-El-Malek | 3739f881 | 2020-09-10 00:29:40 | [diff] [blame] | 2109 | void ReadyToCommitNavigation(bool is_error); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2110 | |
| 2111 | // Called if READY_TO_COMMIT -> COMMIT state transition takes an unusually |
| 2112 | // long time. |
| 2113 | void OnCommitTimeout(); |
| 2114 | |
| 2115 | // Called by the RenderProcessHost to handle the case when the process changed |
| 2116 | // its state of being blocked. |
| 2117 | void RenderProcessBlockedStateChanged(bool blocked); |
| 2118 | |
| 2119 | void StopCommitTimeout(); |
| 2120 | void RestartCommitTimeout(); |
| 2121 | |
| 2122 | std::vector<std::string> TakeRemovedRequestHeaders() { |
| 2123 | return std::move(removed_request_headers_); |
| 2124 | } |
| 2125 | |
| 2126 | net::HttpRequestHeaders TakeModifiedRequestHeaders() { |
| 2127 | return std::move(modified_request_headers_); |
| 2128 | } |
| 2129 | |
| 2130 | // Returns true if the contents of |common_params_| requires |
| 2131 | // |source_site_instance_| to be set. This is used to ensure that data: and |
| 2132 | // about:blank URLs with valid initiator origins always have |
| 2133 | // |source_site_instance_| set so that site isolation enforcements work |
| 2134 | // properly. |
| 2135 | bool RequiresInitiatorBasedSourceSiteInstance() const; |
| 2136 | |
| 2137 | // Sets |source_site_instance_| to a SiteInstance that is derived from |
| 2138 | // |common_params_->initiator_origin| and related to the |frame_tree_node_|'s |
| 2139 | // current SiteInstance. |source_site_instance_| is only set if it doesn't |
| 2140 | // already have a value and RequiresInitiatorBasedSourceSiteInstance() returns |
| 2141 | // true. |
| 2142 | void SetSourceSiteInstanceToInitiatorIfNeeded(); |
| 2143 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2144 | void ForceEnableOriginTrials(const std::vector<std::string>& trials) override; |
| 2145 | |
| 2146 | void CreateCoepReporter(StoragePartition* storage_partition); |
Camille Lamy | 36afacd | 2025-01-16 14:25:18 | [diff] [blame] | 2147 | void CreateDipReporter(StoragePartition* storage_partition); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2148 | |
Pâris Meuleman | 00d62b2 | 2022-01-14 13:43:42 | [diff] [blame] | 2149 | // [spec]: https://html.spec.whatwg.org/C/#obtain-an-embedder-policy |
| 2150 | // |
| 2151 | // Returns the CrossOriginEmbedderPolicy for the document, which is inherited |
| 2152 | // or retrieved from response headers. |
| 2153 | network::CrossOriginEmbedderPolicy ComputeCrossOriginEmbedderPolicy(); |
| 2154 | |
Yoav Weiss | 93d38b50 | 2025-05-06 15:55:51 | [diff] [blame] | 2155 | struct IntegrityPolicies { |
| 2156 | network::IntegrityPolicy enforced; |
| 2157 | network::IntegrityPolicy report_only; |
| 2158 | }; |
| 2159 | |
| 2160 | // Calculates the integrity policies for a document, based on the |
| 2161 | // `Integrity-Policy` and `Integrity-Policy-Report-Only` headers. |
| 2162 | IntegrityPolicies ComputeIntegrityPolicies(); |
| 2163 | |
Pâris Meuleman | 00d62b2 | 2022-01-14 13:43:42 | [diff] [blame] | 2164 | // [spec]: |
| 2165 | // https://html.spec.whatwg.org/C/#check-a-navigation-response's-adherence-to-its-embedder-policy |
| 2166 | // |
| 2167 | // Return whether the response's COEP is compatible with its parent's COEP. It |
| 2168 | // also sends COEP reports if needed. |
| 2169 | bool CheckResponseAdherenceToCoep(const GURL& url); |
Arthur Sonzogni | 8012958 | 2021-12-21 10:34:57 | [diff] [blame] | 2170 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2171 | std::optional<network::mojom::BlockedByResponseReason> EnforceCOEP(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2172 | |
Pâris MEULEMAN | a2e8623f | 2021-04-09 07:57:42 | [diff] [blame] | 2173 | // Check the COOP value of the page is compatible with the COEP value of each |
| 2174 | // of its documents. COOP:kSameOriginPlusCoep is incompatible with COEP:kNone. |
Hiroki Nakagawa | eb5e2fd | 2025-06-17 12:45:05 | [diff] [blame] | 2175 | // If they aren't, this emits a crash report. |
| 2176 | void CoopCoepSanityCheck(); |
Pâris MEULEMAN | a2e8623f | 2021-04-09 07:57:42 | [diff] [blame] | 2177 | |
Liam Brady | 25a1416 | 2022-12-02 15:25:57 | [diff] [blame] | 2178 | // Checks that, given an origin to be committed, all of the permissions |
| 2179 | // policies that a fenced frame requires to be enabled are enabled. If not, it |
| 2180 | // logs a console message and returns false. |
Liam Brady | b1c43c2 | 2022-08-11 23:33:47 | [diff] [blame] | 2181 | bool CheckPermissionsPoliciesForFencedFrames(const url::Origin&); |
| 2182 | |
Liam Brady | 25a1416 | 2022-12-02 15:25:57 | [diff] [blame] | 2183 | // Helper function that determines if a given required permissions policy |
| 2184 | // feature is properly enabled for a given origin to be committed. |
| 2185 | bool IsFencedFrameRequiredPolicyFeatureAllowed( |
| 2186 | const url::Origin&, |
Sandor «Alex» Major | e9545a7 | 2025-01-31 20:40:46 | [diff] [blame] | 2187 | const network::mojom::PermissionsPolicyFeature feature); |
Liam Brady | 25a1416 | 2022-12-02 15:25:57 | [diff] [blame] | 2188 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2189 | // Returns the user-agent override, or an empty string if one isn't set. |
| 2190 | std::string GetUserAgentOverride(); |
| 2191 | |
| 2192 | mojo::PendingRemote<network::mojom::CookieAccessObserver> |
| 2193 | CreateCookieAccessObserver(); |
| 2194 | |
Steven Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 2195 | mojo::PendingRemote<network::mojom::TrustTokenAccessObserver> |
| 2196 | CreateTrustTokenAccessObserver(); |
| 2197 | |
| 2198 | // network::mojom::TrustTokenAccessObserver: |
| 2199 | void OnTrustTokensAccessed( |
| 2200 | network::mojom::TrustTokenAccessDetailsPtr details) override; |
| 2201 | void Clone(mojo::PendingReceiver<network::mojom::TrustTokenAccessObserver> |
| 2202 | observer) override; |
| 2203 | |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 2204 | mojo::PendingRemote<network::mojom::SharedDictionaryAccessObserver> |
| 2205 | CreateSharedDictionaryAccessObserver(); |
| 2206 | |
| 2207 | // network::mojom::SharedDictionaryAccessObserver: |
| 2208 | void OnSharedDictionaryAccessed( |
| 2209 | network::mojom::SharedDictionaryAccessDetailsPtr details) override; |
| 2210 | void Clone( |
| 2211 | mojo::PendingReceiver<network::mojom::SharedDictionaryAccessObserver> |
| 2212 | observer) override; |
| 2213 | |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 2214 | mojo::PendingRemote<network::mojom::DeviceBoundSessionAccessObserver> |
| 2215 | CreateDeviceBoundSessionObserver(); |
| 2216 | |
| 2217 | // network::mojom::DeviceBoundSessionAccessObserver: |
| 2218 | void OnDeviceBoundSessionAccessed( |
Daniel Rubery | 7cdfa53 | 2025-01-24 16:57:50 | [diff] [blame] | 2219 | const net::device_bound_sessions::SessionAccess& access) override; |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 2220 | void Clone( |
| 2221 | mojo::PendingReceiver<network::mojom::DeviceBoundSessionAccessObserver> |
| 2222 | observer) override; |
| 2223 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2224 | // Convenience function to return the NavigationControllerImpl this |
| 2225 | // NavigationRequest is in. |
William Liu | 2b6336bc | 2023-09-07 14:42:39 | [diff] [blame] | 2226 | NavigationControllerImpl* GetNavigationController() const; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2227 | |
Hiroki Nakagawa | 1cb1455 | 2021-04-23 03:37:34 | [diff] [blame] | 2228 | // Convenience function to return the PrerenderHostRegistry this |
| 2229 | // NavigationRequest can be associated with. |
| 2230 | PrerenderHostRegistry& GetPrerenderHostRegistry(); |
| 2231 | |
Rakina Zata Amni | 39d8e7e | 2022-10-20 18:18:30 | [diff] [blame] | 2232 | // Returns the RenderFrameHost of the initiator document, iff there is such |
| 2233 | // a document and its RenderFrameHost has not committed a different document |
Titouan Rigoudy | 78d8311 | 2021-06-23 14:49:59 | [diff] [blame] | 2234 | // since this navigation started. Otherwise returns nullptr. |
| 2235 | RenderFrameHostImpl* GetInitiatorDocumentRenderFrameHost(); |
| 2236 | |
| 2237 | // Records the appropriate kAddressSpace* WebFeature for the response we just |
| 2238 | // received on the initiator document, if possible. |
| 2239 | void RecordAddressSpaceFeature(); |
| 2240 | |
arthursonzogni | adb8088 | 2021-03-11 10:43:30 | [diff] [blame] | 2241 | // Computes the PolicyContainerPolicies and the sandbox flags to use for |
| 2242 | // committing a regular document. |
| 2243 | // Called when the response to commit is known. |
| 2244 | void ComputePoliciesToCommit(); |
| 2245 | |
| 2246 | // Computes the PolicyContainerPolicies and the sandbox flags to use for |
| 2247 | // committing an error document. |
| 2248 | // |
| 2249 | // Note: |
| 2250 | // |ComputePoliciesToCommit()| can be followed by |
| 2251 | // |ComputePoliciesToCommitForErrorPage()|. This happens when the decision to |
| 2252 | // commit an error document happens after receiving the regular document's |
| 2253 | // response. |
| 2254 | void ComputePoliciesToCommitForError(); |
| 2255 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2256 | // DCHECK that tranistioning from the current state to |state| valid. This |
| 2257 | // does nothing in non-debug builds. |
| 2258 | void CheckStateTransition(NavigationState state) const; |
| 2259 | |
| 2260 | // Set |state_| to |state| and also DCHECK that this state transition is |
| 2261 | // valid. |
| 2262 | void SetState(NavigationState state); |
| 2263 | |
Daniel Cheng | 738266dc | 2020-09-11 19:56:28 | [diff] [blame] | 2264 | // When a navigation fails, one of two things can happen: |
| 2265 | // 1) An error page commits and replaces the old document. |
| 2266 | // 2) The navigation is canceled, and the previous document is kept. |
| 2267 | // |
| 2268 | // If appropriate, this applies (2), deletes |this|, and returns true. |
| 2269 | // In that case, the caller must immediately return. |
| 2270 | bool MaybeCancelFailedNavigation(); |
| 2271 | |
Antonio Sartori | 0a7117a | 2021-04-01 09:23:37 | [diff] [blame] | 2272 | // Called just after a navigation commits (also in case of error): it |
| 2273 | // sends all console messages to the final RenderFrameHost. |
| 2274 | void SendDeferredConsoleMessages(); |
| 2275 | |
Daniel Cheng | 9bd90f9 | 2021-04-23 20:49:45 | [diff] [blame] | 2276 | bool ShouldRenderFallbackContentForResponse( |
| 2277 | const net::HttpResponseHeaders& response_head) const; |
Daniel Cheng | 9bd90f9 | 2021-04-23 20:49:45 | [diff] [blame] | 2278 | |
Rakina Zata Amni | e36ce534 | 2021-07-17 04:10:55 | [diff] [blame] | 2279 | // Whether this is a same-URL navigation that should replace the current entry |
| 2280 | // or not. Called when the navigation just started. |
Nate Chapin | 8a7a042 | 2021-06-28 20:29:24 | [diff] [blame] | 2281 | bool ShouldReplaceCurrentEntryForSameUrlNavigation() const; |
| 2282 | |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 2283 | // Whether this navigation happens on the initial empty document or initial |
| 2284 | // NavigationEntry, and thus should replace the current entry. Called when the |
| 2285 | // navigation just started. |
| 2286 | bool ShouldReplaceCurrentEntryForNavigationFromInitialEmptyDocumentOrEntry() |
| 2287 | const; |
Rakina Zata Amni | 1846325 | 2021-08-10 17:48:10 | [diff] [blame] | 2288 | |
Rakina Zata Amni | e36ce534 | 2021-07-17 04:10:55 | [diff] [blame] | 2289 | // Whether a failed navigation should replace the current entry or not. Called |
| 2290 | // when an error page is about to be committed. |
| 2291 | bool ShouldReplaceCurrentEntryForFailedNavigation() const; |
| 2292 | |
Kenichi Ishibashi | 5997378 | 2021-07-02 07:01:14 | [diff] [blame] | 2293 | // Calculates the origin that this NavigationRequest may commit. See also the |
| 2294 | // comment of GetOriginToCommit(). Performs calculation without information |
| 2295 | // from RenderFrameHostImpl (e.g. CSPs are ignored). Should be used only in |
| 2296 | // situations where the final frame host hasn't been determined but the origin |
| 2297 | // is needed to create URLLoaderFactory. |
Lukasz Anforowicz | 435e68d | 2022-11-09 21:47:44 | [diff] [blame] | 2298 | url::Origin GetOriginForURLLoaderFactoryBeforeResponse( |
Kenichi Ishibashi | f3f8052 | 2021-07-16 02:37:07 | [diff] [blame] | 2299 | network::mojom::WebSandboxFlags sandbox_flags); |
Kenichi Ishibashi | 5997378 | 2021-07-02 07:01:14 | [diff] [blame] | 2300 | |
Lukasz Anforowicz | 435e68d | 2022-11-09 21:47:44 | [diff] [blame] | 2301 | // Superset of GetOriginForURLLoaderFactoryBeforeResponse(). Calculates |
Kenichi Ishibashi | 5997378 | 2021-07-02 07:01:14 | [diff] [blame] | 2302 | // the origin with information from the final frame host. Can be called only |
| 2303 | // after the final response is received or ready. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2304 | std::optional<url::Origin> GetOriginForURLLoaderFactoryAfterResponse(); |
Kenichi Ishibashi | 5997378 | 2021-07-02 07:01:14 | [diff] [blame] | 2305 | |
Camille Lamy | d1f015d | 2024-07-06 14:14:10 | [diff] [blame] | 2306 | // Computes the CrossOriginIsolationKey to use for committing the navigation. |
| 2307 | // A nullopt result means that either the cross-origin isolation status of the |
| 2308 | // request cannot be determined because we do not have final headers for the |
| 2309 | // navigation yet, or that the navigation is not cross-origin isolated. |
| 2310 | std::optional<AgentClusterKey::CrossOriginIsolationKey> |
| 2311 | ComputeCrossOriginIsolationKey(); |
| 2312 | |
Arthur Hemery | 821fa5d | 2021-08-30 13:32:42 | [diff] [blame] | 2313 | // Computes the web-exposed isolation information based on `coop_status_` and |
| 2314 | // current `frame_tree_node_` info. |
Arthur Hemery | 3a991c09 | 2021-12-22 12:04:24 | [diff] [blame] | 2315 | // If the return result is nullopt, it means that the WebExposedIsolationInfo |
| 2316 | // is not relevant or unknown. This can happen for example when we do not have |
| 2317 | // a network response yet, or when going to an "about:blank" page. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2318 | std::optional<WebExposedIsolationInfo> ComputeWebExposedIsolationInfo(); |
Arthur Hemery | 821fa5d | 2021-08-30 13:32:42 | [diff] [blame] | 2319 | |
Yao Xiao | 6e1f7d3 | 2022-01-07 03:28:40 | [diff] [blame] | 2320 | // Assign an invalid frame tree node id to `prerender_frame_tree_node_id_`. |
| 2321 | // Called as soon as when we are certain that this navigation won't activate a |
| 2322 | // prerendered page. This is needed because `IsPrerenderedPageActivation()`, |
| 2323 | // which may be called at any point after BeginNavigation(), will assume that |
| 2324 | // 'prerender_frame_tree_node_id_' has an value assigned. |
| 2325 | void MaybeAssignInvalidPrerenderFrameTreeNodeId(); |
| 2326 | |
Arthur Sonzogni | 258bee7ca | 2022-12-06 18:16:12 | [diff] [blame] | 2327 | // The NavigationDownloadPolicy is currently fully computed by the renderer |
| 2328 | // process. It is left empty for browser side initiated navigation. This is a |
| 2329 | // problem. This function is an incomplete attempt to start computing it from |
| 2330 | // the browser process instead. |
Alison Gale | 81f4f2c7 | 2024-04-22 19:33:31 | [diff] [blame] | 2331 | // TODO(crbug.com/40249217): Complete the implementation the browser |
Arthur Sonzogni | 258bee7ca | 2022-12-06 18:16:12 | [diff] [blame] | 2332 | // side implementation. |
| 2333 | void ComputeDownloadPolicy(); |
| 2334 | |
Arthur Sonzogni | 6d88b3e | 2022-12-15 14:03:24 | [diff] [blame] | 2335 | blink::NavigationDownloadPolicy& download_policy() { |
| 2336 | return common_params_->download_policy; |
| 2337 | } |
| 2338 | |
Rakina Zata Amni | 49657c77 | 2023-03-31 06:41:53 | [diff] [blame] | 2339 | // Called on FrameTreeNode's queued NavigationRequest (if any) when another |
| 2340 | // NavigationRequest associated with the same FrameTreeNode is destroyed and |
Rakina Zata Amni | d7b90f2 | 2023-04-06 12:56:40 | [diff] [blame] | 2341 | // the queued NavigationRequest can be resumed. Will post a task to run the |
| 2342 | // `resume_commit_closure_` asynchronously. |
| 2343 | void PostResumeCommitTask(); |
Daniel Cheng | a8a8009 | 2023-01-09 22:50:16 | [diff] [blame] | 2344 | |
Arthur Sonzogni | 9b2f54c | 2023-02-03 15:00:26 | [diff] [blame] | 2345 | // See https://crbug.com/1412365 |
| 2346 | void CheckSoftNavigationHeuristicsInvariants(); |
| 2347 | |
Nate Chapin | 154b14b | 2023-02-17 18:28:16 | [diff] [blame] | 2348 | // Used to resume any SubframeHistoryNavigationThrottles in this FrameTree |
| 2349 | // when this NavigationRequest commits. |
| 2350 | // `subframe_history_navigation_throttles_` will only be populated if this |
| 2351 | // IsInMainFrame(). |
| 2352 | void UnblockPendingSubframeNavigationRequestsIfNeeded(); |
| 2353 | |
Nate Chapin | 364a72e0 | 2023-11-27 19:56:59 | [diff] [blame] | 2354 | // If this request is a same-origin cross-document traversal (i.e., session |
| 2355 | // history navigation), this will send a message to the renderer to have it |
| 2356 | // fire the navigate event. Normally, the renderer fires the navigate event at |
| 2357 | // navigation start for cross-document navigations, before sending the |
| 2358 | // BeginNavigation to the browser. That doesn't work for traversals, because |
| 2359 | // the renderer don't know which frame(s) will navigate. This is called after |
| 2360 | // beforeunload events fire and after any navigation start throttles have |
| 2361 | // resumed, so we know the navigation is proceeding. The navigate event can't |
| 2362 | // cancel a cross-document traversal, so it can be sent in parallel, instead |
| 2363 | // of blocking and waiting for the result. |
| 2364 | void MaybeDispatchNavigateEventForCrossDocumentTraversal(); |
| 2365 | |
Mingyu Lei | 1fa6a1f | 2023-02-21 13:17:46 | [diff] [blame] | 2366 | // Returns if we should add/reset the `CookieChangeListener` for the current |
| 2367 | // navigation. |
| 2368 | bool ShouldAddCookieChangeListener(); |
| 2369 | |
Daniel Rubery | 03e7199 | 2025-02-19 22:03:30 | [diff] [blame] | 2370 | // Returns if we should add/reset the `DeviceBoundSessionObserver` for |
| 2371 | // the current navigation. |
| 2372 | bool ShouldAddDeviceBoundSessionObserver(); |
| 2373 | |
Mingyu Lei | 1fa6a1f | 2023-02-21 13:17:46 | [diff] [blame] | 2374 | // Returns the `StoragePartition` based on the config from the `site_info_`. |
| 2375 | StoragePartition* GetStoragePartitionWithCurrentSiteInfo(); |
| 2376 | |
Igor Ruvinov | dcb8198 | 2023-06-21 22:22:17 | [diff] [blame] | 2377 | // Passes the response body contents to the original caller using the stored |
| 2378 | // callback once the body has been successfully read from its corresponding |
| 2379 | // data pipe. |
| 2380 | void OnResponseBodyReady(MojoResult result); |
| 2381 | |
Alex Moshchuk | 854e0be7 | 2023-08-04 22:35:35 | [diff] [blame] | 2382 | // Helper to record early RenderFrameHost swap metrics at the end of a |
| 2383 | // navigation. |
| 2384 | void RecordEarlyRenderFrameHostSwapMetrics(); |
| 2385 | |
Sharon Yang | 945cea5 | 2023-10-16 21:14:03 | [diff] [blame] | 2386 | // Helpers for GetTentativeOriginAtRequestTime and GetOriginToCommit. |
Sharon Yang | 945cea5 | 2023-10-16 21:14:03 | [diff] [blame] | 2387 | url::Origin GetOriginForURLLoaderFactoryUnchecked(); |
| 2388 | |
Minoru Chikamune | 3c58bbd | 2024-01-22 10:19:35 | [diff] [blame] | 2389 | void MaybeRecordTraceEventsAndHistograms(); |
Minoru Chikamune | 6e45f70 | 2024-01-18 15:05:30 | [diff] [blame] | 2390 | |
Charlie Reis | 9e20dd1 | 2025-01-02 20:11:53 | [diff] [blame] | 2391 | // Records how much the navigation start time was adjusted for beforeunload |
| 2392 | // handlers, for various scenarios (legacy, beforeunload handlers only, and |
| 2393 | // beforeunload dialogs). See https://crbug.com/385170155. |
| 2394 | void MaybeRecordNavigationStartAdjustments(); |
| 2395 | |
Khushal Sagar | 91b54422 | 2024-03-12 17:36:59 | [diff] [blame] | 2396 | void ResetViewTransitionState(); |
| 2397 | |
Xiaochen Zhou | 8294af8 | 2024-05-30 20:48:02 | [diff] [blame] | 2398 | // This check is to prevent a race condition where a parent fenced frame |
| 2399 | // initiates a nested fenced frame navigation right before the entire frame |
| 2400 | // tree has network access disabled. If such navigation is allowed to commit, |
| 2401 | // the navigated fenced frame will have network access. This allows parent |
| 2402 | // fenced frame to communicate cross-site data into child fenced frame, which |
| 2403 | // is bad. So we need to disable navigations when both the embedder and nested |
| 2404 | // frames have already disabled network. |
| 2405 | bool IsDisabledEmbedderInitiatedFencedFrameNavigation(); |
| 2406 | |
Jiacheng Guo | c77135fb | 2024-06-06 12:38:01 | [diff] [blame] | 2407 | // Sets the expected process to the process of the current associated RFH. |
| 2408 | void SetExpectedProcessIfAssociated(); |
| 2409 | |
Camille Lamy | 17ad9e8 | 2024-06-21 11:06:30 | [diff] [blame] | 2410 | // Sets the Document-Isolation-Policy header to a default value in unsecure |
| 2411 | // contexts or if DocumentIsolationPolicy is not supported. |
| 2412 | void SanitizeDocumentIsolationPolicyHeader(); |
| 2413 | |
Liang Zhao | 5b299ce | 2025-01-17 18:34:24 | [diff] [blame] | 2414 | // Sets up service worker client info to inherit controller from the parent |
| 2415 | // frame if it is a same origin srcdoc iframe. |
| 2416 | // This method creates a ServiceWorkerClient associated with the navigating |
| 2417 | // frame. It should not be called when NavigationURLLoader is used as that |
| 2418 | // would also create ServiceWorkerClient and cause conflict. |
| 2419 | void InheritServiceWorkerControllerFromParentIfNeeded(); |
| 2420 | |
Diana Qu | 01f1c79 | 2025-06-04 20:33:45 | [diff] [blame] | 2421 | // If this navigation has a FrameNavigationEntry with a committed origin, |
| 2422 | // ensure that it matches the origin_to_commit when origin-sensitive state |
| 2423 | // (such as page_state) is being sent to the renderer. |
| 2424 | // |
| 2425 | // This invariant guards against scenarios where session history has been |
| 2426 | // unintentionally or maliciously corrupted, causing a document to commit |
| 2427 | // in a renderer under the wrong origin. This would violate site isolation |
| 2428 | // guarantees and could lead to security vulnerabilities. |
| 2429 | // |
| 2430 | // See https://crbug.com/41487933 for more background on the types of bugs |
| 2431 | // this protects against. |
| 2432 | void ValidateCommitOrigin(const url::Origin& origin_to_commit); |
| 2433 | |
Titouan Rigoudy | e10716b | 2020-09-29 13:29:55 | [diff] [blame] | 2434 | // Never null. The pointee node owns this navigation request instance. |
Keishi Hattori | 130ae0a | 2023-03-27 03:48:47 | [diff] [blame] | 2435 | // This field is not a raw_ptr because of incompatibilities with tracing |
| 2436 | // (TRACE_EVENT*), perfetto::TracedDictionary::Add and gmock/EXPECT_THAT. |
| 2437 | RAW_PTR_EXCLUSION FrameTreeNode* const frame_tree_node_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2438 | |
Hayato Ito | 5750b44 | 2025-05-29 02:38:06 | [diff] [blame] | 2439 | // Returns true if navigation timeline UKMs should be recorded. |
| 2440 | // This is also used in `MaybeRecordTraceEventsAndHistograms()`, which should |
| 2441 | // eventually be replaced with the navigation timeline metrics. |
| 2442 | bool ShouldRecordNavigationTimelineUkm() const; |
| 2443 | |
Hiroki Nakagawa | adcffc50 | 2021-06-16 10:47:51 | [diff] [blame] | 2444 | // Used for short-lived NavigationRequest created at DidCommit time for the |
| 2445 | // purpose of committing navigation that were not driven by the browser |
| 2446 | // process. This is used in only two cases: |
| 2447 | // - same-document navigation initiated by the renderer process. |
| 2448 | // - the synchronous about:blank navigation. |
| 2449 | const bool is_synchronous_renderer_commit_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2450 | |
Rakina Zata Amni | 7b75ae34 | 2023-03-03 05:59:14 | [diff] [blame] | 2451 | // The RenderFrameHost that this navigation intends to commit in. The value |
| 2452 | // will be set when we know the final RenderFrameHost that the navigation will |
| 2453 | // commit in (i.e. when we receive the final network response for most |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2454 | // navigations). Note that currently this can be reset to std::nullopt for |
Rakina Zata Amni | 7b75ae34 | 2023-03-03 05:59:14 | [diff] [blame] | 2455 | // cross-document restarts and some failed navigations. |
Alison Gale | 81f4f2c7 | 2024-04-22 19:33:31 | [diff] [blame] | 2456 | // TODO(crbug.com/40063115): Don't reset this on failed navigations, |
Rakina Zata Amni | 7b75ae34 | 2023-03-03 05:59:14 | [diff] [blame] | 2457 | // and ensure the NavigationRequest doesn't outlive the `render_frame_host_` |
| 2458 | // picked for failed Back/Forward Cache restores. |
| 2459 | // Invariant: At least one of |loader_| or |render_frame_host_| is |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2460 | // null/std::nullopt. |
| 2461 | std::optional< |
Paul Semel | 7e8f888 | 2023-06-07 20:44:41 | [diff] [blame] | 2462 | base::SafeRef<RenderFrameHostImpl, base::SafeRefDanglingUntriaged>> |
| 2463 | render_frame_host_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2464 | |
| 2465 | // Initialized on creation of the NavigationRequest. Sent to the renderer when |
| 2466 | // the navigation is ready to commit. |
| 2467 | // Note: When the navigation is ready to commit, the url in |common_params| |
| 2468 | // will be set to the final navigation url, obtained after following all |
| 2469 | // redirects. |
Hiroki Nakagawa | 0756559 | 2021-06-04 11:36:17 | [diff] [blame] | 2470 | // |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2471 | // Note: |common_params_| and |begin_params_| are not const as they can be |
| 2472 | // modified during redirects. |
Hiroki Nakagawa | 0756559 | 2021-06-04 11:36:17 | [diff] [blame] | 2473 | // |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2474 | // Note: |commit_params_| is not const because was_discarded will |
| 2475 | // be set in CreatedNavigationRequest. |
Hiroki Nakagawa | 0756559 | 2021-06-04 11:36:17 | [diff] [blame] | 2476 | // |
| 2477 | // Note: |commit_params_->is_browser_initiated| and |common_params_| may be |
| 2478 | // mutated by ContentBrowserClient::OverrideNavigationParams at construction |
| 2479 | // time (i.e. before we actually kick off the navigation). |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 2480 | blink::mojom::CommonNavigationParamsPtr common_params_; |
| 2481 | blink::mojom::BeginNavigationParamsPtr begin_params_; |
| 2482 | blink::mojom::CommitNavigationParamsPtr commit_params_; |
Yoav Weiss | 3e46271d | 2021-04-30 20:35:21 | [diff] [blame] | 2483 | bool same_origin_ = false; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2484 | |
| 2485 | // Stores the NavigationUIData for this navigation until the NavigationHandle |
| 2486 | // is created. This can be null if the embedded did not provide a |
| 2487 | // NavigationUIData at the beginning of the navigation. |
| 2488 | std::unique_ptr<NavigationUIData> navigation_ui_data_; |
| 2489 | |
| 2490 | // URLLoaderFactory to facilitate loading blob URLs. |
Hiroki Nakagawa | b078d3ef | 2021-06-03 06:55:43 | [diff] [blame] | 2491 | const scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2492 | |
Ming-Ying Chung | 763ee328 | 2023-10-10 19:30:36 | [diff] [blame] | 2493 | // A bundle of URLLoaderFactory to facilitate loading subresources. |
| 2494 | // It is shared between prefetch, topics, keep-alive, and fetchLater. |
| 2495 | scoped_refptr<network::SharedURLLoaderFactory> |
| 2496 | subresource_proxying_factory_bundle_ = nullptr; |
| 2497 | |
arthursonzogni | 5761f4c | 2020-11-20 12:39:31 | [diff] [blame] | 2498 | NavigationState state_ = NOT_STARTED; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2499 | bool is_navigation_started_ = false; |
| 2500 | |
Ali Juma | b377546 | 2023-10-20 21:31:08 | [diff] [blame] | 2501 | // Manages the lifetime of a pre-created ServiceWorkerContainerHost until a |
| 2502 | // corresponding container is created in the renderer. This must be destroyed |
| 2503 | // after `loader_` to avoid dangling pointers, since `loader_` can have a |
| 2504 | // raw_ptr to this object. |
| 2505 | std::unique_ptr<ServiceWorkerMainResourceHandle> service_worker_handle_; |
| 2506 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2507 | std::unique_ptr<NavigationURLLoader> loader_; |
| 2508 | |
Pete Williamson | 1d87f462 | 2022-10-18 19:36:43 | [diff] [blame] | 2509 | bool navigation_visible_to_embedder_ = false; |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 2510 | #if BUILDFLAG(IS_ANDROID) |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2511 | // For each C++ NavigationHandle, there is a Java counterpart. It is the JNI |
| 2512 | // bridge in between the two. |
| 2513 | std::unique_ptr<NavigationHandleProxy> navigation_handle_proxy_; |
| 2514 | #endif |
| 2515 | |
| 2516 | // These next items are used in browser-initiated navigations to store |
| 2517 | // information from the NavigationEntryImpl that is required after request |
| 2518 | // creation time. |
| 2519 | scoped_refptr<SiteInstanceImpl> source_site_instance_; |
| 2520 | scoped_refptr<SiteInstanceImpl> dest_site_instance_; |
| 2521 | const RestoreType restore_type_; |
| 2522 | const ReloadType reload_type_; |
| 2523 | const int nav_entry_id_; |
Avi Drissman | 78865bbb | 2024-08-22 20:57:19 | [diff] [blame] | 2524 | std::optional<BindingsPolicySet> bindings_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2525 | |
| 2526 | scoped_refptr<SiteInstanceImpl> starting_site_instance_; |
| 2527 | |
| 2528 | // Whether the navigation should be sent to a renderer a process. This is |
| 2529 | // true, except for 204/205 responses and downloads. |
Sharon Yang | 34f8998 | 2023-11-09 22:35:24 | [diff] [blame] | 2530 | bool response_should_be_rendered_ = true; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2531 | |
Ali Beyad | 3e6e467 | 2021-11-02 19:34:06 | [diff] [blame] | 2532 | // Whether devtools overrides were applied on the User-Agent request header. |
| 2533 | bool devtools_user_agent_override_ = false; |
| 2534 | |
Victor Tan | 5632348 | 2022-08-12 19:05:13 | [diff] [blame] | 2535 | // Whether devtools overrides were applied on the Accept-Language request |
| 2536 | // header. |
| 2537 | bool devtools_accept_language_override_ = false; |
| 2538 | |
Rakina Zata Amni | 7af54b1 | 2022-06-28 10:36:17 | [diff] [blame] | 2539 | // The type of RenderFrameHost associated with this navigation. |
| 2540 | AssociatedRenderFrameHostType associated_rfh_type_ = |
| 2541 | AssociatedRenderFrameHostType::NONE; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2542 | |
| 2543 | // Stores the SiteInstance created on redirects to check if there is an |
| 2544 | // existing RenderProcessHost that can commit the navigation so that the |
| 2545 | // renderer process is not deleted while the navigation is ongoing. If the |
| 2546 | // SiteInstance was a brand new SiteInstance, it is not stored. |
| 2547 | scoped_refptr<SiteInstance> speculative_site_instance_; |
| 2548 | |
| 2549 | // Whether the NavigationRequest was created after receiving a BeginNavigation |
| 2550 | // IPC. When true, main frame navigations should not commit in a different |
| 2551 | // process (unless asked by the content/ embedder). When true, the renderer |
| 2552 | // process expects to be notified if the navigation is aborted. |
| 2553 | const bool from_begin_navigation_; |
| 2554 | |
| 2555 | // Holds objects received from OnResponseStarted while the WillProcessResponse |
| 2556 | // checks are performed by the NavigationHandle. Once the checks have been |
| 2557 | // completed, these objects will be used to continue the navigation. |
| 2558 | network::mojom::URLResponseHeadPtr response_head_; |
| 2559 | mojo::ScopedDataPipeConsumerHandle response_body_; |
| 2560 | network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints_; |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2561 | std::optional<net::SSLInfo> ssl_info_; |
| 2562 | std::optional<net::AuthChallengeInfo> auth_challenge_info_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2563 | bool is_download_ = false; |
| 2564 | GlobalRequestID request_id_; |
Kenichi Ishibashi | 7eb8cf6 | 2021-04-07 12:35:05 | [diff] [blame] | 2565 | std::unique_ptr<NavigationEarlyHintsManager> early_hints_manager_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2566 | |
| 2567 | // Holds information for the navigation while the WillFailRequest |
| 2568 | // checks are performed by the NavigationHandle. |
arthursonzogni | 5761f4c | 2020-11-20 12:39:31 | [diff] [blame] | 2569 | bool has_stale_copy_in_cache_ = false; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2570 | net::Error net_error_ = net::OK; |
Karandeep Bhatia | 3de98e5 | 2021-03-13 03:48:45 | [diff] [blame] | 2571 | int extended_error_code_ = 0; |
| 2572 | |
Keita Suzuki | f300e44 | 2025-07-16 07:38:11 | [diff] [blame] | 2573 | // The trigger for the error navigation. |
| 2574 | std::optional<ErrorNavigationTrigger> error_navigation_trigger_; |
| 2575 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2576 | // Detailed host resolution error information. The error code in |
| 2577 | // |resolve_error_info_.error| should be consistent with (but not necessarily |
| 2578 | // the same as) |net_error_|. In the case of a host resolution error, for |
| 2579 | // example, |net_error_| should be ERR_NAME_NOT_RESOLVED while |
| 2580 | // |resolve_error_info_.error| may give a more detailed error such as |
| 2581 | // ERR_DNS_TIMED_OUT. |
| 2582 | net::ResolveErrorInfo resolve_error_info_; |
| 2583 | |
| 2584 | // Identifies in which RenderProcessHost this navigation is expected to |
| 2585 | // commit. |
Patrick Monette | 779c154 | 2025-01-17 17:18:36 | [diff] [blame] | 2586 | ChildProcessId expected_render_process_host_id_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2587 | |
| 2588 | // The SiteInfo of this navigation, as obtained from |
| 2589 | // SiteInstanceImpl::ComputeSiteInfo(). |
| 2590 | SiteInfo site_info_; |
| 2591 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2592 | base::OnceClosure on_start_checks_complete_closure_; |
| 2593 | |
| 2594 | // Used in the network service world to pass the subressource loader params |
Adrienne Walker | 5b98d1ee | 2021-10-19 16:57:41 | [diff] [blame] | 2595 | // to the renderer. Used by ServiceWorker and |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2596 | // SignedExchangeSubresourcePrefetch. |
Hiroshige Hayashizaki | 9e0f286 | 2024-02-09 16:54:00 | [diff] [blame] | 2597 | SubresourceLoaderParams subresource_loader_params_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2598 | |
Daniel Cheng | 284c3894 | 2022-09-22 23:30:34 | [diff] [blame] | 2599 | // DocumentToken to use for the newly-committed document in a cross-document |
| 2600 | // navigation. Currently set immediately before sending CommitNavigation to |
| 2601 | // the renderer. In the future, this may be populated earlier to allow lookup |
| 2602 | // of a navigation request by the document that it may create, similar to how |
| 2603 | // `NavigationOrDocumentHandle` behaves. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2604 | std::optional<blink::DocumentToken> document_token_; |
Daniel Cheng | 284c3894 | 2022-09-22 23:30:34 | [diff] [blame] | 2605 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2606 | // See comment on accessor. |
arthursonzogni | 5761f4c | 2020-11-20 12:39:31 | [diff] [blame] | 2607 | const base::UnguessableToken devtools_navigation_token_ = |
| 2608 | base::UnguessableToken::Create(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2609 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2610 | std::optional<std::vector<blink::mojom::TransferrableURLLoaderPtr>> |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2611 | subresource_overrides_; |
| 2612 | |
| 2613 | // The NavigationClient interface for that requested this navigation in the |
| 2614 | // case of a renderer initiated navigation. It is expected to be bound until |
| 2615 | // this navigation commits or is canceled. |
| 2616 | mojo::AssociatedRemote<mojom::NavigationClient> request_navigation_client_; |
| 2617 | |
| 2618 | // The NavigationClient interface used to commit the navigation. For now, this |
| 2619 | // is only used for same-site renderer-initiated navigation. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 2620 | // TODO(crbug.com/40276805): Extend to all types of navigation. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2621 | mojo::AssociatedRemote<mojom::NavigationClient> commit_navigation_client_; |
| 2622 | |
| 2623 | // If set, any redirects to HTTP for this navigation will be upgraded to |
| 2624 | // HTTPS. This is used only on subframe navigations, when |
| 2625 | // upgrade-insecure-requests is set as a CSP policy. |
| 2626 | bool upgrade_if_insecure_ = false; |
| 2627 | |
| 2628 | // The offset of the new document in the history. |
Hiroki Nakagawa | d69994c | 2021-06-01 21:20:45 | [diff] [blame] | 2629 | const int navigation_entry_offset_ = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2630 | |
Takashi Toyoshima | 96a07bb | 2025-06-06 06:45:58 | [diff] [blame] | 2631 | // Owns the NavigationThrottleRegistry associated with this navigation. |
Takashi Toyoshima | 96a07bb | 2025-06-06 06:45:58 | [diff] [blame] | 2632 | std::unique_ptr<NavigationThrottleRegistryImpl> throttle_registry_; |
| 2633 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 2634 | // Once the navigation has passed all throttle checks the navigation will |
| 2635 | // commit. However, we may need to defer the commit until certain conditions |
| 2636 | // are met. CommitDeferringConditionRunner is responsible for deferring a |
| 2637 | // commit if needed and resuming it, by calling |
| 2638 | // OnCommitDeferringConditionChecksComplete, once all checks passed. |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 2639 | // |
| 2640 | // For prerendered page activation, it doesn't run the NavigationThrottles and |
| 2641 | // run the CommitDeferringConditionRunner at the beginning of |
| 2642 | // BeginNavigation(). See the comment on RunCommitDeferringConditions() for |
| 2643 | // details. |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 2644 | std::unique_ptr<CommitDeferringConditionRunner> commit_deferrer_; |
| 2645 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2646 | // Indicates whether the navigation changed which NavigationEntry is current. |
| 2647 | bool subframe_entry_committed_ = false; |
| 2648 | |
| 2649 | // True if the committed entry has replaced the existing one. |
| 2650 | // A non-user initiated redirect causes such replacement. |
| 2651 | bool did_replace_entry_ = false; |
| 2652 | |
| 2653 | // Set to false if we want to update the session history but not update the |
Miyoung Shin | ba07a17 | 2022-02-14 13:38:54 | [diff] [blame] | 2654 | // browser history. E.g., on unreachable urls or navigations in non-primary |
Adithya Srinivasan | 39c8191 | 2024-07-11 20:44:21 | [diff] [blame] | 2655 | // frame trees. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2656 | bool should_update_history_ = false; |
| 2657 | |
| 2658 | // The previous main frame URL that the user was on. This may be empty if |
| 2659 | // there was no last committed entry. |
Fergal Daly | 8e33cf6 | 2020-12-12 01:06:07 | [diff] [blame] | 2660 | GURL previous_main_frame_url_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2661 | |
| 2662 | // The type of navigation that just occurred. Note that not all types of |
| 2663 | // navigations in the enum are valid here, since some of them don't actually |
| 2664 | // cause a "commit" and won't generate this notification. |
| 2665 | NavigationType navigation_type_ = NAVIGATION_TYPE_UNKNOWN; |
| 2666 | |
| 2667 | // The chain of redirects, including client-side redirect and the current URL. |
| 2668 | // TODO(zetamoo): Try to improve redirect tracking during navigation. |
| 2669 | std::vector<GURL> redirect_chain_; |
| 2670 | |
| 2671 | // TODO(zetamoo): Try to remove this by always sanitizing the referrer in |
| 2672 | // common_params_. |
| 2673 | blink::mojom::ReferrerPtr sanitized_referrer_; |
| 2674 | |
| 2675 | bool was_redirected_ = false; |
| 2676 | |
| 2677 | // Whether this navigation was triggered by a x-origin redirect following a |
| 2678 | // prior (most likely <a download>) download attempt. |
| 2679 | bool from_download_cross_origin_redirect_ = false; |
| 2680 | |
Kunihiko Sakamoto | 2bebcc1 | 2022-08-19 08:00:18 | [diff] [blame] | 2681 | // Used to hold prefetched signed exchanges. This is shared with the |
| 2682 | // navigation initiator's RenderFrameHostImpl. This also means that only the |
| 2683 | // navigations that were directly initiated by the frame that made the |
| 2684 | // prefetches could use the prefetched resources, which is a different |
| 2685 | // behavior from regular prefetches (where all prefetched resources are |
| 2686 | // stored and shared in http cache). |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2687 | scoped_refptr<PrefetchedSignedExchangeCache> |
| 2688 | prefetched_signed_exchange_cache_; |
| 2689 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2690 | // Timing information of loading for the navigation. Used for recording UMAs. |
arthursonzogni | 5761f4c | 2020-11-20 12:39:31 | [diff] [blame] | 2691 | NavigationHandleTiming navigation_handle_timing_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2692 | |
Charlie Reis | 9e20dd1 | 2025-01-02 20:11:53 | [diff] [blame] | 2693 | // The original value of navigation start for a given navigation, before any |
| 2694 | // adjustment is made to avoid counting beforeunload dialogs. This is null |
| 2695 | // (i.e., `TimeTicks()`) unless an adjustment was made. |
| 2696 | base::TimeTicks original_navigation_start_; |
| 2697 | |
| 2698 | // Tracks whether an adjustment to the navigation start time was done for |
| 2699 | // legacy PostTask reasons rather than for running a beforeunload handler. |
| 2700 | bool navigation_start_adjustment_for_legacy_ = false; |
| 2701 | |
| 2702 | // Tracks whether a beforeunload dialog was shown as part of this navigation. |
| 2703 | bool beforeunload_dialog_shown_ = false; |
| 2704 | |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 2705 | // The time this NavigationRequest was created. |
| 2706 | base::TimeTicks creation_time_ = base::TimeTicks().Now(); |
| 2707 | |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 2708 | // The time that the browser process started running beforeunload phase 2, |
| 2709 | // which is used to run any beforeunload handlers that were not run already in |
| 2710 | // an initiating renderer process during beforeunload phase 1 (and may include |
| 2711 | // handlers in a remote target frame or OOPIFs within the target frame). This |
| 2712 | // value is null if the navigation did not need to run beforeunload phase 2. |
| 2713 | // Note that legacy PostTask cases are not considered beforeunload phase 2, |
| 2714 | // because they do not run actual beforeunload handlers. |
| 2715 | base::TimeTicks beforeunload_phase2_start_time_; |
| 2716 | |
| 2717 | // The time that beforeunload phase 2 ended, if it ran. |
| 2718 | base::TimeTicks beforeunload_phase2_end_time_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2719 | |
Minoru Chikamune | 6e45f70 | 2024-01-18 15:05:30 | [diff] [blame] | 2720 | // The time BeginNavigation() was called. |
| 2721 | base::TimeTicks begin_navigation_time_; |
| 2722 | |
Minoru Chikamune | 6e45f70 | 2024-01-18 15:05:30 | [diff] [blame] | 2723 | // The time OnResponseStarted() was called. |
| 2724 | base::TimeTicks receive_response_time_; |
| 2725 | |
Alex Moshchuk | 8e9a7f9 | 2025-02-03 22:50:35 | [diff] [blame] | 2726 | // The time this navigation was ready to commit. |
| 2727 | base::TimeTicks ready_to_commit_time_; |
| 2728 | |
Minoru Chikamune | 6e45f70 | 2024-01-18 15:05:30 | [diff] [blame] | 2729 | // The first `fetchStart` time. This is different from the |
| 2730 | // `first_request_start_time` in `NavigationHandleTiming` since the |
| 2731 | // `first_fetch_start_time_` is the first time when the browser is |
| 2732 | // ready to fetch using an HTTP request, whereas the `requestStart` is |
| 2733 | // when the browser has obtained a connection and is ready to send the |
| 2734 | // HTTP request. |
| 2735 | base::TimeTicks first_fetch_start_time_; |
| 2736 | |
| 2737 | // The time when the final (which might also be the first) headers are |
| 2738 | // received. |
| 2739 | base::TimeTicks final_receive_headers_end_time_; |
| 2740 | |
Clark DuVall | c97bcf7 | 2021-12-08 22:58:24 | [diff] [blame] | 2741 | // The time WillStartRequest() was called. |
| 2742 | base::TimeTicks will_start_request_time_; |
| 2743 | |
Charlie Reis | 0e2b5d09 | 2025-04-24 05:12:18 | [diff] [blame] | 2744 | // For bfcache and prerender page activations, this is the time that the |
| 2745 | // activation commits (after ReadyToCommitNavigation), since no commit IPC is |
| 2746 | // sent to the renderer process. |
| 2747 | base::TimeTicks page_activation_commit_time_; |
| 2748 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2749 | // Set in ReadyToCommitNavigation. |
| 2750 | bool is_same_process_ = true; |
| 2751 | |
Andrew Verge | 754c70a | 2025-04-17 17:19:19 | [diff] [blame] | 2752 | // If set to a value other than NONE, starting the navigation will immediately |
| 2753 | // result in an error page with |net_error_| as the network error and |
| 2754 | // |error_page_html_| as the content. This value of this field indicates what |
| 2755 | // scenario prompted the error navigation. |
| 2756 | BrowserInitiatedErrorNavigationType browser_initiated_error_navigation_type_ = |
| 2757 | BrowserInitiatedErrorNavigationType::kNone; |
| 2758 | |
| 2759 | // If browser_initiated_error_navigation_type_ is set, this HTML will be |
| 2760 | // shown as the content of the resulting error page. |
| 2761 | std::string error_page_html_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2762 | |
Yao Xiao | 6e1f7d3 | 2022-01-07 03:28:40 | [diff] [blame] | 2763 | // This test-only callback will be run when BeginNavigation() is called. |
| 2764 | base::OnceClosure begin_navigation_callback_for_testing_; |
| 2765 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2766 | // This test-only callback will be run when all throttle checks have been |
| 2767 | // performed. If the callback returns true, On*ChecksComplete functions are |
| 2768 | // skipped, and only the test callback is being performed. |
| 2769 | // TODO(clamy): Revisit the unit test architecture. |
| 2770 | ThrottleChecksFinishedCallback complete_callback_for_testing_; |
| 2771 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 2772 | // Test-only callback. Called when we're ready to call CommitNavigation. |
| 2773 | // Unlike above, this is informational only; it does not affect the request. |
| 2774 | base::OnceClosure ready_to_commit_callback_for_testing_; |
| 2775 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2776 | // Unique id that identifies the navigation for which this NavigationRequest |
| 2777 | // is created. |
| 2778 | const int64_t navigation_id_ = ++unique_id_counter_; |
| 2779 | // static member for generating the unique id above. |
| 2780 | static int64_t unique_id_counter_; |
| 2781 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2782 | // Timer for detecting an unexpectedly long time to commit a navigation. |
| 2783 | base::OneShotTimer commit_timeout_timer_; |
| 2784 | |
Peter Kasting | 7ba9440c | 2020-11-22 01:49:02 | [diff] [blame] | 2785 | base::CallbackListSubscription |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2786 | render_process_blocked_state_changed_subscription_; |
| 2787 | |
| 2788 | // The headers used for the request. The value of this comes from |
| 2789 | // |begin_params_->headers|. If not set, it needs to be calculated. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2790 | std::optional<net::HttpRequestHeaders> request_headers_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2791 | |
| 2792 | // Used to update the request's headers. When modified during the navigation |
| 2793 | // start, the headers will be applied to the initial network request. When |
| 2794 | // modified during a redirect, the headers will be applied to the redirected |
| 2795 | // request. |
| 2796 | net::HttpRequestHeaders modified_request_headers_; |
| 2797 | |
| 2798 | net::HttpRequestHeaders cors_exempt_request_headers_; |
| 2799 | |
| 2800 | // Set of headers to remove during the redirect phase. This can only be |
| 2801 | // modified during the redirect phase. |
| 2802 | std::vector<std::string> removed_request_headers_; |
| 2803 | |
Mingyu Lei | 2e0b586e | 2023-07-25 18:26:00 | [diff] [blame] | 2804 | // The RenderFrameHost that is being restored from the back/forward cache. |
| 2805 | // This can be null if this navigation is not restoring a page from the |
| 2806 | // back/forward cache. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2807 | std::optional<base::SafeRef<RenderFrameHostImpl>> |
Mingyu Lei | 2e0b586e | 2023-07-25 18:26:00 | [diff] [blame] | 2808 | rfh_restored_from_back_forward_cache_; |
Rakina Zata Amni | 2eed632 | 2021-09-30 22:22:57 | [diff] [blame] | 2809 | |
| 2810 | // Whether the navigation is for restoring a page from the back/forward cache |
Mingyu Lei | 7956b8b | 2023-07-24 08:24:08 | [diff] [blame] | 2811 | // or not. |
Rakina Zata Amni | 2eed632 | 2021-09-30 22:22:57 | [diff] [blame] | 2812 | const bool is_back_forward_cache_restore_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2813 | |
| 2814 | // These are set to the values from the FrameNavigationEntry this |
| 2815 | // NavigationRequest is associated with (if any). |
| 2816 | int64_t frame_entry_item_sequence_number_ = -1; |
| 2817 | int64_t frame_entry_document_sequence_number_ = -1; |
| 2818 | |
| 2819 | // If non-empty, it represents the IsolationInfo explicitly asked to be used |
| 2820 | // for this NavigationRequest. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2821 | std::optional<net::IsolationInfo> isolation_info_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2822 | |
Rakina Zata Amni | 0c8ffbe | 2023-10-05 19:32:56 | [diff] [blame] | 2823 | // This is used to store the `RenderFrameHostManager::current_frame_host()` id |
| 2824 | // when the navigation commits and about to potentially change the current |
| 2825 | // RenderFrameHost. The ID (if set) refers to the RFH of the document that was |
| 2826 | // replaced when this navigation committed, while the ID saved in |
| 2827 | // `current_render_frame_host_id_at_construction_` below refers to the RFH of |
| 2828 | // the document that was there when this navigation was started. The two might |
| 2829 | // be different, since other navigations could commit and change the current |
| 2830 | // RFH before this navigation commits, which can happen with navigation |
| 2831 | // queueing or early RFH swap. |
| 2832 | GlobalRenderFrameHostId previous_render_frame_host_id_; |
| 2833 | |
| 2834 | // This is used to store the `RenderFrameHostManager::current_frame_host()` id |
| 2835 | // at request creation time. See also the comment for |
| 2836 | // `previous_render_frame_host_id_` above on how these two IDs may differ. |
| 2837 | const GlobalRenderFrameHostId current_render_frame_host_id_at_construction_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2838 | |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 2839 | // Frame token of the frame host that initiated the navigation, derived from |
Harkiran Bolaria | 2d0e3893 | 2021-04-27 17:44:35 | [diff] [blame] | 2840 | // |begin_params().initiator_frame_token|. This is best effort: it is only |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2841 | // defined for some renderer-initiated navigations (e.g., not drag and drop). |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 2842 | // The frame with the corresponding frame token may have been deleted before |
| 2843 | // the navigation begins. This parameter is defined if and only if |
| 2844 | // |initiator_process_id_| below is. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2845 | const std::optional<blink::LocalFrameToken> initiator_frame_token_; |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 2846 | |
| 2847 | // ID of the renderer process of the frame host that initiated the navigation. |
| 2848 | // This is defined if and only if |initiator_frame_token_| above is, and it is |
| 2849 | // only valid in conjunction with it. |
Hiroki Nakagawa | 656c818 | 2021-06-01 05:56:38 | [diff] [blame] | 2850 | const int initiator_process_id_ = ChildProcessHost::kInvalidUniqueID; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2851 | |
Hiroshige Hayashizaki | 8bf5788 | 2023-10-18 15:17:40 | [diff] [blame] | 2852 | // The initiator Document's token, if it is present when this |
| 2853 | // NavigationRequest was created. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2854 | std::optional<blink::DocumentToken> initiator_document_token_; |
Hiroshige Hayashizaki | 8bf5788 | 2023-10-18 15:17:40 | [diff] [blame] | 2855 | |
Arthur Sonzogni | dc8508ab | 2023-08-17 08:42:42 | [diff] [blame] | 2856 | // The sandbox flags of the navigation's initiator, if any. |
| 2857 | // WebSandboxFlags::kNone otherwise. |
| 2858 | const network::mojom::WebSandboxFlags sandbox_flags_initiator_; |
| 2859 | |
John Delaney | 8623c64 | 2021-01-06 17:37:07 | [diff] [blame] | 2860 | // Whether a navigation in a new window had the opener suppressed. False if |
| 2861 | // the navigation is not in a new window. Can only be true for renderer |
| 2862 | // initiated navigations which use `CreateBrowserInitiated()`. |
Hiroki Nakagawa | 656c818 | 2021-06-01 05:56:38 | [diff] [blame] | 2863 | const bool was_opener_suppressed_ = false; |
John Delaney | 8623c64 | 2021-01-06 17:37:07 | [diff] [blame] | 2864 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2865 | // This tracks a connection between the current pending entry and this |
| 2866 | // request, such that the pending entry can be discarded if no requests are |
| 2867 | // left referencing it. |
| 2868 | std::unique_ptr<NavigationControllerImpl::PendingEntryRef> pending_entry_ref_; |
| 2869 | |
| 2870 | // Used only by DCHECK. |
| 2871 | // True if the NavigationThrottles are running an event, the request then can |
| 2872 | // be cancelled for deferring. |
| 2873 | bool processing_navigation_throttle_ = false; |
| 2874 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2875 | // Holds the required CSP for this navigation. This will be moved into |
| 2876 | // the RenderFrameHost at DidCommitNavigation time. |
| 2877 | network::mojom::ContentSecurityPolicyPtr required_csp_; |
| 2878 | |
Antonio Sartori | 5abc8de | 2021-07-13 08:42:47 | [diff] [blame] | 2879 | // Whether the document loaded by this navigation will be committed inside an |
Arthur Sonzogni | 6445759 | 2022-11-22 11:08:59 | [diff] [blame] | 2880 | // iframe credentialless. Documents loaded inside credentialless iframes get |
| 2881 | // partitioned storage and use a transient NetworkAnonymizationKey. |
| 2882 | const bool is_credentialless_; |
Antonio Sartori | 5abc8de | 2021-07-13 08:42:47 | [diff] [blame] | 2883 | |
Titouan Rigoudy | 2f995bc | 2021-02-19 19:39:41 | [diff] [blame] | 2884 | // Non-nullopt from construction until |TakePolicyContainerHost()| is called. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 2885 | std::optional<NavigationPolicyContainerBuilder> policy_container_builder_; |
Antonio Sartori | 3cfa3b6 | 2020-10-09 10:42:40 | [diff] [blame] | 2886 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2887 | std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter_; |
| 2888 | |
Camille Lamy | 36afacd | 2025-01-16 14:25:18 | [diff] [blame] | 2889 | std::unique_ptr<DocumentIsolationPolicyReporter> dip_reporter_; |
| 2890 | |
Aman Verma | c59efd0 | 2024-11-18 20:30:17 | [diff] [blame] | 2891 | std::unique_ptr<viz::PeakGpuMemoryTracker> loading_mem_tracker_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2892 | |
| 2893 | // Structure tracking the effects of the CrossOriginOpenerPolicy on this |
| 2894 | // navigation. |
Hiroki Nakagawa | 656c818 | 2021-06-01 05:56:38 | [diff] [blame] | 2895 | CrossOriginOpenerPolicyStatus coop_status_{this}; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2896 | |
| 2897 | #if DCHECK_IS_ON() |
| 2898 | bool is_safe_to_delete_ = true; |
| 2899 | #endif |
| 2900 | |
| 2901 | // UKM source associated with the page we are navigated away from. |
| 2902 | const ukm::SourceId previous_page_ukm_source_id_; |
| 2903 | |
| 2904 | // If true, changes to the user-agent override require a reload. If false, a |
| 2905 | // reload is not necessary. |
| 2906 | bool ua_change_requires_reload_ = true; |
| 2907 | |
Daniel Cheng | f776864c | 2020-09-26 09:55:22 | [diff] [blame] | 2908 | // Controls whether or not an error page is displayed on error. If set to |
| 2909 | // true, an error will be treated as if the user simply cancelled the |
| 2910 | // navigation. |
| 2911 | bool silently_ignore_errors_ = false; |
| 2912 | |
| 2913 | // Similar but only suppresses the error page when the error code is |
| 2914 | // net::ERR_BLOCKED_BY_CLIENT. |
Daniel Cheng | 738266dc | 2020-09-11 19:56:28 | [diff] [blame] | 2915 | bool silently_ignore_blocked_by_client_ = false; |
| 2916 | |
Lukasz Anforowicz | 39a8aef | 2020-12-17 23:50:15 | [diff] [blame] | 2917 | // Whether the navigation loads an MHTML document or a subframe of an MHTML |
| 2918 | // document. The navigation might or might not be fullfilled from the MHTML |
| 2919 | // archive (see `is_mhtml_subframe_loaded_from_achive` in the NeedsUrlLoader |
| 2920 | // method). |
| 2921 | bool is_mhtml_or_subframe_ = false; |
arthursonzogni | 3fc224b | 2020-10-07 10:41:16 | [diff] [blame] | 2922 | |
Kenichi Ishibashi | cf248fb | 2021-04-07 22:29:35 | [diff] [blame] | 2923 | // True when at least one preload Link header was received via an Early Hints |
| 2924 | // response. This is set only for a main frame navigation. |
Kenichi Ishibashi | 784dd40 | 2021-10-15 00:19:24 | [diff] [blame] | 2925 | bool was_resource_hints_received_ = false; |
Kenichi Ishibashi | cf248fb | 2021-04-07 22:29:35 | [diff] [blame] | 2926 | |
Kenichi Ishibashi | 6301d036 | 2022-04-12 23:32:56 | [diff] [blame] | 2927 | // Set to true when this navigation has created parameters for |
| 2928 | // NavigationEarlyHintsManager. Used to check whether cross origin redirects |
| 2929 | // happened after Early Hints responses are received. |
| 2930 | bool did_create_early_hints_manager_params_ = false; |
| 2931 | |
| 2932 | // Set to true when an Early Hints response was received before cross origin |
| 2933 | // redirects during navigation. |
| 2934 | bool did_receive_early_hints_before_cross_origin_redirect_ = false; |
| 2935 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2936 | // Observers listening to cookie access notifications for the network requests |
Giovanni Ortuño Urquidi | e0a77b4 | 2025-03-28 14:31:35 | [diff] [blame] | 2937 | // made by this navigation. unique_ptr so it can be replaced in tests. |
| 2938 | std::unique_ptr<CookieAccessObservers> cookie_observers_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2939 | |
Steven Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 2940 | // Observers listening to Trust Token access notifications for the network |
| 2941 | // requests made by this navigation. |
| 2942 | mojo::ReceiverSet<network::mojom::TrustTokenAccessObserver> |
| 2943 | trust_token_observers_; |
| 2944 | |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 2945 | // Observers listening to shared dictionary access notifications for the |
| 2946 | // network requests made by this navigation. |
| 2947 | mojo::ReceiverSet<network::mojom::SharedDictionaryAccessObserver> |
| 2948 | shared_dictionary_observers_; |
| 2949 | |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 2950 | mojo::ReceiverSet<network::mojom::DeviceBoundSessionAccessObserver> |
| 2951 | device_bound_session_observers_; |
| 2952 | |
Domenic Denicola | 5fdc2b7f | 2021-01-15 20:29:17 | [diff] [blame] | 2953 | OriginAgentClusterEndResult origin_agent_cluster_end_result_ = |
| 2954 | OriginAgentClusterEndResult::kNotRequestedAndNotOriginKeyed; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2955 | |
Matt Menke | 7f2e1ac5 | 2020-12-10 01:16:10 | [diff] [blame] | 2956 | net::IsolationInfo isolation_info_for_subresources_; |
| 2957 | |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 2958 | // Set while CommitDeferringConditions are running for prerendered page |
| 2959 | // activation. This is needed as PrerenderHost hasn't been reserved and |
| 2960 | // prerender_frame_tree_node_id() is not available yet while they are |
| 2961 | // running. |
Khushal Sagar | c05a8b29 | 2024-02-28 15:29:25 | [diff] [blame] | 2962 | bool is_running_potential_prerender_activation_checks_ = false; |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 2963 | |
Yao Xiao | 6e1f7d3 | 2022-01-07 03:28:40 | [diff] [blame] | 2964 | // Set to true before the fenced frame url mapping. Reset to false when the |
| 2965 | // mapping finishes. If the initial mapping state of the urn:uuid is pending, |
| 2966 | // the mapping will finish asynchronously; otherwise, the mapping will finish |
| 2967 | // synchronously. |
| 2968 | bool is_deferred_on_fenced_frame_url_mapping_ = false; |
| 2969 | |
Yao Xiao | d8d248fa | 2022-12-09 22:28:30 | [diff] [blame] | 2970 | // The start time of fenced frame url mapping. |
| 2971 | base::TimeTicks fenced_frame_url_mapping_start_time_; |
| 2972 | |
David Bokan | f7db706 | 2021-05-27 16:23:10 | [diff] [blame] | 2973 | // The root frame tree node id of the prerendered page. This will be a valid |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 2974 | // FrameTreeNodeId value when this navigation will activate a prerendered |
| 2975 | // page. For all other navigations this will be an invalid FrameTreeNodeId. We |
| 2976 | // only know whether this is the case when BeginNavigation is called so the |
| 2977 | // optional will be empty until then and callers must not query its value |
| 2978 | // before it's been computed. |
Keita Suzuki | 633dd486 | 2025-08-02 01:59:10 | [diff] [blame] | 2979 | // TODO(crbug.com/427054641): Remove this field once the migration to use |
| 2980 | // `reserved_prerender_host_info_` is complete. |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 2981 | std::optional<FrameTreeNodeId> prerender_frame_tree_node_id_; |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 2982 | |
Harkiran Bolaria | 8bee006 | 2021-08-12 10:06:34 | [diff] [blame] | 2983 | // Contains state pertaining to a prerender activation. This is only used if |
| 2984 | // this navigation is a prerender activation. |
| 2985 | struct PrerenderActivationNavigationState { |
| 2986 | PrerenderActivationNavigationState(); |
| 2987 | ~PrerenderActivationNavigationState(); |
| 2988 | |
| 2989 | // Used to store a cloned NavigationEntry for activating a prerendered page. |
| 2990 | // |prerender_navigation_entry| is cloned and stored in NavigationRequest |
| 2991 | // when the prerendered page is transferred to the target FrameTree and is |
| 2992 | // consumed when NavigationController needs a new entry to commit. |
| 2993 | std::unique_ptr<NavigationEntryImpl> prerender_navigation_entry; |
| 2994 | |
| 2995 | // Used to store the FrameReplicationState for the prerendered page prior to |
| 2996 | // activation. Value is to be used to populate |
| 2997 | // DidCommitProvisionalLoadParams values and to verify the replication state |
| 2998 | // after activation. |
| 2999 | blink::mojom::FrameReplicationState prerender_main_frame_replication_state; |
| 3000 | }; |
| 3001 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 3002 | std::optional<PrerenderActivationNavigationState> prerender_navigation_state_; |
Hiroki Nakagawa | 5034e196 | 2020-11-12 09:11:30 | [diff] [blame] | 3003 | |
Arthur Hemery | 373a780 | 2020-12-23 16:32:36 | [diff] [blame] | 3004 | // The following fields that constitute the ClientSecurityState. This |
| 3005 | // state is used to take security decisions about the request, and later on |
| 3006 | // when passed to the RenderFrameHostImpl, about the fetching of subresources. |
| 3007 | // |
| 3008 | // They have some default values and get updated via inheritance or network |
| 3009 | // responses/redirects. Finally they get passed down to the |
| 3010 | // RenderFrameHostImpl at commit time. |
Arthur Hemery | 2c5cd1f | 2023-07-28 12:03:54 | [diff] [blame] | 3011 | // |
| 3012 | // The policy to apply to private network requests for subresources of the |
| 3013 | // document we are navigating to. Influenced by the document's policy |
| 3014 | // container, origin, and `ContentBrowserClient`. |
Jonathan Hao | 90ddbd4 | 2023-07-12 14:23:48 | [diff] [blame] | 3015 | network::mojom::PrivateNetworkRequestPolicy private_network_request_policy_ = |
| 3016 | network::mojom::PrivateNetworkRequestPolicy::kWarn; |
Arthur Hemery | 373a780 | 2020-12-23 16:32:36 | [diff] [blame] | 3017 | |
Titouan Rigoudy | 6f54ec5 | 2021-07-12 19:36:34 | [diff] [blame] | 3018 | // The list of web features that were used by the new document during |
| 3019 | // navigation. These can only be logged once the document commits, so they are |
| 3020 | // held in this vector until then. |
| 3021 | std::vector<blink::mojom::WebFeature> web_features_to_log_; |
| 3022 | |
Antonio Sartori | 0a7117a | 2021-04-01 09:23:37 | [diff] [blame] | 3023 | // Messages to be printed on the console in the target RenderFrameHost of this |
| 3024 | // NavigationRequest. |
| 3025 | std::vector<ConsoleMessage> console_messages_; |
| 3026 | |
Min Qin | 1b84727c | 2024-03-08 18:39:35 | [diff] [blame] | 3027 | // Indicates that this navigation is for PDF content in a renderer. On |
| 3028 | // Android, this can only be true when a PDF NativePage is created for |
| 3029 | // a main frame navigation. |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 3030 | bool is_pdf_ = false; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 3031 | |
Garrett Tanzer | 4785246 | 2022-07-20 18:16:41 | [diff] [blame] | 3032 | // Indicates that this navigation is an embedder-initiated navigation of a |
| 3033 | // fenced frame root. That is to say, the navigation is caused by a `src` |
| 3034 | // attribute mutation on the <fencedframe> element, which cannot be performed |
| 3035 | // from inside the fenced frame tree. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 3036 | // TODO(crbug.com/40202462): Make this `const` again once ShadowDOM is gone. |
Garrett Tanzer | 2975eeac | 2022-08-22 16:34:01 | [diff] [blame] | 3037 | bool is_embedder_initiated_fenced_frame_navigation_ = false; |
Garrett Tanzer | 4785246 | 2022-07-20 18:16:41 | [diff] [blame] | 3038 | |
Garrett Tanzer | 34cb92fe | 2022-09-28 17:50:54 | [diff] [blame] | 3039 | // On every embedder-initiated navigation of a fenced frame, i.e. |
| 3040 | // `is_embedder_initiated_fenced_frame_navigation_`, we reinitialize |
Garrett Tanzer | 2453345f | 2024-01-18 22:02:29 | [diff] [blame] | 3041 | // the fenced frame properties with the default `FencedFrameProperties(url)` |
Garrett Tanzer | 34cb92fe | 2022-09-28 17:50:54 | [diff] [blame] | 3042 | // constructor, which gives the fenced frame a fresh partition nonce. |
| 3043 | // |
Garrett Tanzer | 2453345f | 2024-01-18 22:02:29 | [diff] [blame] | 3044 | // If the embedder-initiated navigation is to a urn:uuid, we overwrite |
Garrett Tanzer | 34cb92fe | 2022-09-28 17:50:54 | [diff] [blame] | 3045 | // the default properties stored in this `NavigationRequest` with the |
| 3046 | // `FencedFrameProperties` bound to that urn:uuid, in |
| 3047 | // `NavigationRequest::OnFencedFrameURLMappingComplete`. |
| 3048 | // |
| 3049 | // For certain actions related to the pending `NavigationRequest` (rather |
| 3050 | // than the existing fenced frame document), e.g. partitioned network |
| 3051 | // requests for the pending navigation, we use the pending |
| 3052 | // `FencedFrameProperties`. |
| 3053 | // |
| 3054 | // If the navigation commits, this new set of fenced frame properties will be |
| 3055 | // stored in the fenced frame root FrameTreeNode in |
| 3056 | // `NavigationRequest::DidCommitNavigation`. |
| 3057 | // |
| 3058 | // If the navigation doesn't commit (e.g. an HTTP 204 response), the fenced |
| 3059 | // frame properties will not be stored in the fenced frame root. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 3060 | std::optional<FencedFrameProperties> fenced_frame_properties_; |
Garrett Tanzer | c69f464 | 2022-08-15 22:15:14 | [diff] [blame] | 3061 | |
Camillia Smith Barnes | 6a64396 | 2023-03-03 00:28:58 | [diff] [blame] | 3062 | // For fenced frames, any contextual string that was written by the embedder |
| 3063 | // via `blink::FencedFrameConfig::setSharedStorageContext()` to be later |
| 3064 | // retrieved only inside an eligible shared storage worklet in the fenced |
| 3065 | // frame via `sharedStorage.context`. absl:nullopt if this request is not for |
| 3066 | // a fenced frame or if the context string wasn't set prior to this |
| 3067 | // navigation. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 3068 | std::optional<std::u16string> embedder_shared_storage_context_; |
Camillia Smith Barnes | 6a64396 | 2023-03-03 00:28:58 | [diff] [blame] | 3069 | |
Asami Doi | 0240627 | 2021-11-12 05:01:44 | [diff] [blame] | 3070 | // Prerender2: |
Keita Suzuki | 633dd486 | 2025-08-02 01:59:10 | [diff] [blame] | 3071 | // The information about the reserved prerender host. This is used to pass |
| 3072 | // information about the reserved host including information required for |
| 3073 | // metrics collection. |
| 3074 | std::optional<ReservedPrerenderHostInfo> reserved_prerender_host_info_; |
Asami Doi | 0240627 | 2021-11-12 05:01:44 | [diff] [blame] | 3075 | |
Clark DuVall | 3d91432d | 2021-12-07 20:29:44 | [diff] [blame] | 3076 | // Prevents the compositor from requesting main frame updates early in |
| 3077 | // navigation. |
| 3078 | std::unique_ptr<ui::CompositorLock> compositor_lock_; |
| 3079 | |
W. James MacLean | 00568d7 | 2022-02-24 19:36:55 | [diff] [blame] | 3080 | // This navigation request should swap browsing instances as part of a test |
| 3081 | // reset. |
| 3082 | bool force_new_browsing_instance_ = false; |
| 3083 | |
Steve Kobes | 8d111ba | 2024-11-12 15:23:51 | [diff] [blame] | 3084 | // Indicates this navigation should use a new compositor. This is used by web |
| 3085 | // tests to ensure that input state is fully reset between tests. See comments |
| 3086 | // at RenderFrameHostImpl::must_be_replaced(). |
| 3087 | bool force_new_compositor_ = false; |
| 3088 | |
Yao Xiao | 9f73e88 | 2023-03-27 19:01:41 | [diff] [blame] | 3089 | // Whether the ongoing navigation resource request is eligible for topics |
| 3090 | // calculation. This is set before the initial request and each subsequent |
| 3091 | // redirect. If `topics_eligible_` is true, the request headers will contain |
| 3092 | // the "Sec-Browsing-Topics" header, and if the corresponding response headers |
| 3093 | // contain "Observe-Browsing-Topics: ?1", a topic observation will be stored. |
| 3094 | bool topics_eligible_ = false; |
| 3095 | |
Orr Bernstein | a0cc679 | 2023-11-14 22:12:35 | [diff] [blame] | 3096 | // Whether this navigation request is an iframe navigation for which the |
| 3097 | // adAuctionHeaders attribute is set. Only requests with this attribute may be |
| 3098 | // eligible for ad auction headerse, but not all requests with this attribute |
| 3099 | // are eligible. `ad_auction_headers_eligible_`, below, indicates whether or |
| 3100 | // not this request is eligible. |
| 3101 | const bool has_ad_auction_headers_attribute_ = false; |
| 3102 | |
| 3103 | // Whether the ongoing navigation resource request should have its Ad Auction |
| 3104 | // response headers examined for interception. This is set before the initial |
| 3105 | // request for iframe navigations that provide the `adAuctionHeaders` |
| 3106 | // attribute. On redirect or error, this is always set to false. If this is |
| 3107 | // set to true, the request headers will contain the "Sec-Ad-Auction-Fetch: |
| 3108 | // ?1" header, and several response headers will be intercepted. See |
| 3109 | // content/browser/interest_group/ad_auction_headers_util.h for more details. |
| 3110 | bool ad_auction_headers_eligible_ = false; |
| 3111 | |
Camillia Smith Barnes | 3cad1ba | 2023-10-30 20:10:16 | [diff] [blame] | 3112 | // Whether or not the original request (without considering redirects or |
| 3113 | // permissions policy) opted-in to write to shared storage from response |
| 3114 | // headers. See https://github.com/WICG/shared-storage#from-response-headers |
| 3115 | bool shared_storage_writable_opted_in_ = false; |
| 3116 | |
| 3117 | // Whether or not the current request is eligible to shared storage from |
Camillia Smith Barnes | 6d2966c8 | 2023-08-23 21:16:18 | [diff] [blame] | 3118 | // response headers. See |
| 3119 | // https://github.com/WICG/shared-storage#from-response-headers |
Camillia Smith Barnes | 3cad1ba | 2023-10-30 20:10:16 | [diff] [blame] | 3120 | bool shared_storage_writable_eligible_ = false; |
Camillia Smith Barnes | 6d2966c8 | 2023-08-23 21:16:18 | [diff] [blame] | 3121 | |
Yao Xiao | 58c2f2c | 2023-05-16 20:05:18 | [diff] [blame] | 3122 | // A WeakPtr for the BindContext associated with the browser routing loader |
| 3123 | // factory for the committing document. This will be set in |
| 3124 | // `CommitNavigation()`, and can become null if the corresponding factory is |
| 3125 | // destroyed. Upon `DidCommitNavigation()`, |
| 3126 | // `subresource_proxying_url_loader_service_bind_context_` will be notified |
| 3127 | // with the committed document. |
| 3128 | base::WeakPtr<SubresourceProxyingURLLoaderService::BindContext> |
| 3129 | subresource_proxying_url_loader_service_bind_context_; |
Yao Xiao | 549be447 | 2023-01-03 22:53:12 | [diff] [blame] | 3130 | |
Ming-Ying Chung | 977404c | 2023-11-08 12:30:10 | [diff] [blame] | 3131 | // A WeakPtr for the FactoryContext associated with the browser fetch |
| 3132 | // keepalive loader factory for the committing document. |
| 3133 | // This field will be set in `CommitNavigation()`, and can become null if the |
| 3134 | // corresponding factory is destroyed. |
| 3135 | // Upon `DidCommitNavigation()`, this field will be notified with the |
| 3136 | // committed document. |
| 3137 | base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> |
| 3138 | keep_alive_url_loader_factory_context_; |
| 3139 | // A WeakPtr for the FactoryContext associated with the browser fetchlater |
| 3140 | // loader factory for the committing document. |
| 3141 | // See also `keep_alive_url_loader_factory_context_` for the timing to update. |
| 3142 | base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> |
| 3143 | fetch_later_loader_factory_context_; |
| 3144 | |
Rakina Zata Amni | a68329fe | 2025-07-02 10:15:03 | [diff] [blame] | 3145 | // Set to true when the loaders above are set by unittests that want to avoid |
| 3146 | // setting a real connection to the renderer. |
| 3147 | bool did_set_keep_alive_url_loader_factory_context_for_testing_ = false; |
| 3148 | bool did_set_fetch_later_url_loader_factory_context_for_testing_ = false; |
| 3149 | |
Julie Jeongeun Kim | 4a5fef2 | 2022-04-02 02:08:38 | [diff] [blame] | 3150 | scoped_refptr<NavigationOrDocumentHandle> navigation_or_document_handle_; |
| 3151 | |
sbingler | a07ae73 | 2022-12-02 20:49:05 | [diff] [blame] | 3152 | // Exposes getters and setters for Blink Runtime-Enabled Features to the |
| 3153 | // browser process. Any feature set using the RuntimeFeatureStateContext |
| 3154 | // before navigation commit will be communicated back to the renderer process. |
| 3155 | // NOTE: these feature changes will apply to the "to-be-created" document. |
| 3156 | blink::RuntimeFeatureStateContext runtime_feature_state_context_; |
| 3157 | |
Rakina Zata Amni | af55b5b6 | 2022-07-19 23:11:03 | [diff] [blame] | 3158 | // Renderer-initiated navigations can be canceled until the JS task that |
| 3159 | // started the navigation finishes. See RendererCancellationThrottle for more |
| 3160 | // details. The window of time in which the renderer can cancel the navigation |
| 3161 | // is called the "cancellation window" and the navigation can't commit until |
| 3162 | // the cancellation window ended, which `renderer_cancellation_listener_` |
| 3163 | // listens to. `renderer_cancellation_window_ended_` is true if the |
| 3164 | // cancellation window had ended. If |
| 3165 | // `renderer_cancellation_window_ended_callback_` is set, the navigation is |
| 3166 | // being deferred by RendererCancellationThrottle to wait for the cancellation |
| 3167 | // window to finish or for the navigation to get canceled. If it is set when |
| 3168 | // the cancellation window ended, the callback will be run, to resume the |
| 3169 | // navigation. |
| 3170 | mojo::Receiver<mojom::NavigationRendererCancellationListener> |
| 3171 | renderer_cancellation_listener_{this}; |
| 3172 | bool renderer_cancellation_window_ended_ = false; |
| 3173 | base::OnceClosure renderer_cancellation_window_ended_callback_; |
| 3174 | |
Igor Ruvinov | 0ea2ebb | 2022-12-01 16:33:06 | [diff] [blame] | 3175 | // Whether a Cookie header added to this request should not be overwritten by |
| 3176 | // the network service. |
| 3177 | bool allow_cookies_from_browser_ = false; |
| 3178 | |
Daniel Cheng | a8a8009 | 2023-01-09 22:50:16 | [diff] [blame] | 3179 | // If the browser has asked the renderer to commit the navigation in a |
| 3180 | // speculative RenderFrameHost, but the renderer has not yet responded, a |
Rakina Zata Amni | 49657c77 | 2023-03-31 06:41:53 | [diff] [blame] | 3181 | // subsequent navigation request will be queued when it is about to pick its |
| 3182 | // final RenderFrameHost, to avoid deleting the previous navigation's pending |
| 3183 | // commit RenderFrameHost. A queued navigation should populate this field with |
| 3184 | // a closure that resumes committing the navigation when run. |
Daniel Cheng | a8a8009 | 2023-01-09 22:50:16 | [diff] [blame] | 3185 | // |
Rakina Zata Amni | 49657c77 | 2023-03-31 06:41:53 | [diff] [blame] | 3186 | // The closure should always be bound with a `WeakPtr` receiver. To avoid |
| 3187 | // weird reentrancy bugs, it will be run as a non-nested posted task, which |
| 3188 | // means the original NavigationRequest could already be deleted by the |
| 3189 | // time the closure runs. |
Daniel Cheng | a8a8009 | 2023-01-09 22:50:16 | [diff] [blame] | 3190 | base::OnceClosure resume_commit_closure_; |
| 3191 | |
Daniel Cheng | 557868f | 2023-07-28 00:10:20 | [diff] [blame] | 3192 | // Metrics for measuring the impact of navigation queueing. Note that while |
| 3193 | // `resume_commit_closure_` is set on the navigation that was *blocked*, these |
| 3194 | // metrics are set on the NavigationRequest that is *blocking*. |
| 3195 | struct PendingCommitMetrics { |
| 3196 | // When this `NavigationRequest` caused its speculative RenderFrameHost to |
| 3197 | // enter pending commit. |
| 3198 | base::TimeTicks start_time; |
| 3199 | // How many `GetFrameHostForNavigation()` calls failed in total. |
| 3200 | int blocked_count = 0; |
| 3201 | // How many `GetFrameHostForNavigation()` calls failed when trying to assign |
| 3202 | // a final `RenderFrameHost` for commit. |
| 3203 | int blocked_commit_count = 0; |
| 3204 | }; |
| 3205 | PendingCommitMetrics pending_commit_metrics_; |
| 3206 | |
Arthur Hemery | a2e2c5f1 | 2023-01-16 15:00:15 | [diff] [blame] | 3207 | // Records whether the new document will commit inside another BrowsingContext |
| 3208 | // group as a result of this navigation, and for what reason. Deciding whether |
| 3209 | // to clear the window name and to clear the proxies are based on this value. |
| 3210 | // |
| 3211 | // It is created with a default no-swap value, and is set within |
| 3212 | // RenderFrameHostManager::GetSiteInstanceForNavigation(). It is generally set |
| 3213 | // more than once, first for a speculative computation before receiving |
| 3214 | // headers, then for each redirect, and finally once a definitve response has |
| 3215 | // been received. It might also never be set if the navigation does not go |
| 3216 | // through SiteInstance selection, such as for a renderer initiated |
| 3217 | // same-document navigation. |
| 3218 | BrowsingContextGroupSwap browsing_context_group_swap_ = |
| 3219 | BrowsingContextGroupSwap::CreateDefault(); |
| 3220 | |
Nate Chapin | 6c43c02 | 2023-02-13 23:32:42 | [diff] [blame] | 3221 | // See `set_pending_navigation_api_key()` for context. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 3222 | std::optional<std::string> pending_navigation_api_key_; |
Nate Chapin | 6c43c02 | 2023-02-13 23:32:42 | [diff] [blame] | 3223 | |
Nate Chapin | 154b14b | 2023-02-17 18:28:16 | [diff] [blame] | 3224 | // If this NavigationRequest is for a main-frame same-document back/forward |
| 3225 | // navigation, any subframe NavigationRequests are deferred until the renderer |
| 3226 | // has a chance to fire a navigate event. If the navigate |
| 3227 | // event allows the navigation to proceed, |
| 3228 | // UnblockPendingSubframeNavigationRequestsIfNeeded() will resume these |
| 3229 | // requests |
| 3230 | std::vector<base::WeakPtr<SubframeHistoryNavigationThrottle>> |
| 3231 | subframe_history_navigation_throttles_; |
| 3232 | |
| 3233 | // If this NavigationRequest is in a subframe and part of a history traversal, |
| 3234 | // and the main frame is performing a same-document navigation, this token |
| 3235 | // may be set if there is a possibility that JS in the main frame will cancel |
| 3236 | // the history traversal via the navigate event. In that case, this token is |
| 3237 | // used to look up the main frame's NavigationRequest so that it can be passed |
| 3238 | // SubframeHistoryNavigationThrottle can defer this request until the main |
| 3239 | // frame commits. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 3240 | std::optional<base::UnguessableToken> |
Nate Chapin | 154b14b | 2023-02-17 18:28:16 | [diff] [blame] | 3241 | main_frame_same_document_navigation_token_; |
| 3242 | |
Mingyu Lei | 1fa6a1f | 2023-02-21 13:17:46 | [diff] [blame] | 3243 | // The listener that receives cookie change events and maintains cookie change |
| 3244 | // information for the domain of the URL that this `NavigationRequest` is |
| 3245 | // navigating to. The listener will observe all the cookie changes starting |
| 3246 | // from the navigation/redirection, and it will be moved to the |
| 3247 | // `RenderFrameHostImpl` when the navigation is committed and continues |
| 3248 | // observing until the destruction of the document. |
| 3249 | // See `RenderFrameHostImpl::CookieChangeListener`. |
| 3250 | std::unique_ptr<RenderFrameHostImpl::CookieChangeListener> |
| 3251 | cookie_change_listener_; |
| 3252 | |
Daniel Rubery | 03e7199 | 2025-02-19 22:03:30 | [diff] [blame] | 3253 | // The observer that receives device bound session events and |
| 3254 | // maintains device bound session information for the domain of the |
| 3255 | // URL that this `NavigationRequest` is navigating to. The observer |
| 3256 | // will observe all device bound session changes starting from the |
| 3257 | // navigation/redirection, and it will be moved to the |
| 3258 | // `RenderFrameHostImpl` when the navigation is committed and |
| 3259 | // continues observing until the destructoin of the document. |
| 3260 | // See `RenderFrameHostImpl::DeviceBoundSessionObserver`. |
| 3261 | std::unique_ptr<RenderFrameHostImpl::DeviceBoundSessionObserver> |
| 3262 | device_bound_session_observer_; |
| 3263 | |
Kouhei Ueno | a0297b0b | 2023-06-15 05:39:48 | [diff] [blame] | 3264 | // LCP Critical Path Predictor managed hint data those were already available |
| 3265 | // at the time of navigation. The hint is passed along to the renderer process |
| 3266 | // on commit along with the other navigation params. |
| 3267 | blink::mojom::LCPCriticalPathPredictorNavigationTimeHint lcpp_hint_; |
| 3268 | |
Rakina Zata Amni | 208f767 | 2023-04-07 12:21:25 | [diff] [blame] | 3269 | // The WebUI object to be used for this navigation. When a RenderFrameHost has |
| 3270 | // been picked for the navigation, the WebUI object will be moved to be owned |
| 3271 | // by the RenderFrameHost. |
| 3272 | std::unique_ptr<WebUIImpl> web_ui_; |
| 3273 | |
Igor Ruvinov | dcb8198 | 2023-06-21 22:22:17 | [diff] [blame] | 3274 | // Returns whether this navigation is currently deferred. |
| 3275 | bool IsDeferred(); |
| 3276 | |
| 3277 | // The watcher used to asynchronously read the response body from the data |
| 3278 | // pipe. Once the response body is read, it is passed to the original caller |
| 3279 | // using the stored callback. This is instantiated when a response body is |
| 3280 | // requested and destroyed upon returning the response body. |
| 3281 | std::unique_ptr<mojo::SimpleWatcher> response_body_watcher_; |
| 3282 | ResponseBodyCallback response_body_callback_; |
| 3283 | // Used to confirm that any NavigationThrottle that calls `GetResponseBody()` |
| 3284 | // becomes deferred. |
| 3285 | bool was_get_response_body_called_ = false; |
| 3286 | |
| 3287 | // Used to prevent re-entrancy into `Resume()`. |
| 3288 | bool is_resuming_ = false; |
| 3289 | |
Alex Moshchuk | 854e0be7 | 2023-08-04 22:35:35 | [diff] [blame] | 3290 | EarlyRenderFrameHostSwapType early_render_frame_host_swap_type_ = |
| 3291 | EarlyRenderFrameHostSwapType::kNone; |
| 3292 | |
John Delaney | 4cf7d6ea | 2023-11-09 17:29:56 | [diff] [blame] | 3293 | // Whether the embedder indicated this navigation is being used for |
| 3294 | // advertising porpoises. |
| 3295 | bool is_ad_tagged_ = false; |
| 3296 | |
Sharon Yang | 1311816 | 2023-11-14 19:40:23 | [diff] [blame] | 3297 | // This is the origin to commit value calculated at request time for data: URL |
| 3298 | // navigations. It is stored so that the opaque origin nonce can be maintained |
| 3299 | // across a navigation. This value is used when a speculative SiteInstance |
| 3300 | // is created so the site URL of the navigation can match the initiator |
| 3301 | // origin. We store the tentative origin to commit value, since we need it |
| 3302 | // before ready to commit time, which is when the regular origin to commit |
| 3303 | // value is available. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 3304 | std::optional<url::Origin> tentative_data_origin_to_commit_; |
Sharon Yang | 1311816 | 2023-11-14 19:40:23 | [diff] [blame] | 3305 | |
Khushal Sagar | 21c62681 | 2024-02-29 23:32:18 | [diff] [blame] | 3306 | // `pageswap` can be fired at different stages of the navigation lifecycle: |
Khushal Sagar | 2dd8a3d | 2024-02-13 20:49:25 | [diff] [blame] | 3307 | // - ready to commit if this navigation is associated with a ViewTransition. |
| 3308 | // - unload old document if there is no ViewTransition opt-in. |
Khushal Sagar | 21c62681 | 2024-02-29 23:32:18 | [diff] [blame] | 3309 | // This tracks whether the pageswap event has been fired for this |
Khushal Sagar | 2dd8a3d | 2024-02-13 20:49:25 | [diff] [blame] | 3310 | // navigation. |
Khushal Sagar | 21c62681 | 2024-02-29 23:32:18 | [diff] [blame] | 3311 | bool did_fire_page_swap_ = false; |
Khushal Sagar | 2dd8a3d | 2024-02-13 20:49:25 | [diff] [blame] | 3312 | |
Khushal Sagar | 8e96670 | 2024-03-13 19:49:16 | [diff] [blame] | 3313 | // Set if there has been any cross-origin redirects in the lifetime of this |
| 3314 | // request. |
| 3315 | bool did_encounter_cross_origin_redirect_ = false; |
| 3316 | |
Khushal Sagar | 91b54422 | 2024-03-12 17:36:59 | [diff] [blame] | 3317 | // A scoped reference on the ViewTransition resources generated for this |
| 3318 | // navigation. This is set after we received the cached results from the old |
| 3319 | // Document's renderer. If the navigation commits, the resources are |
| 3320 | // transferred to the new Document's view. If the navigation finishes without |
| 3321 | // committing, the resources are destroyed with this request. |
| 3322 | std::unique_ptr<ScopedViewTransitionResources> view_transition_resources_; |
| 3323 | |
Mustafa Emre Acer | 1001b3d | 2024-07-09 23:10:43 | [diff] [blame] | 3324 | // If true, this means that this navigation request was initiated by an |
Vladimir Levin | 6e894a9 | 2024-06-12 18:02:46 | [diff] [blame] | 3325 | // animated transition. |
| 3326 | bool was_initiated_by_animated_transition_ = false; |
| 3327 | |
Rakina Zata Amni | 58681c6 | 2024-06-25 06:32:13 | [diff] [blame] | 3328 | // If the navigation is cancelled/discarded before it commits, the reason |
| 3329 | // for cancellation will be saved. |
| 3330 | std::optional<NavigationDiscardReason> navigation_discard_reason_; |
| 3331 | |
Mustafa Emre Acer | 1001b3d | 2024-07-09 23:10:43 | [diff] [blame] | 3332 | // If true, HTTPS Upgrades will be disabled on this navigation request. |
| 3333 | bool force_no_https_upgrade_ = false; |
| 3334 | |
Min Qin | 3669650b | 2024-08-07 18:13:52 | [diff] [blame] | 3335 | // The initial request method of the request, before any redirects. |
| 3336 | std::string request_method_; |
| 3337 | |
William Liu | 0c323bfce | 2024-11-13 21:21:10 | [diff] [blame] | 3338 | // Set to true if `this` started as a same-document navigation but couldn't |
| 3339 | // commit, and was restarted as a cross-document navigation. See |
| 3340 | // `blink::mojom::CommitResult::RestartCrossDocument`. |
| 3341 | bool was_reset_for_cross_document_restart_ = false; |
| 3342 | |
Mike Jackson | 82654a3a | 2025-02-13 07:48:22 | [diff] [blame] | 3343 | // The confidence level captured at the time the navigation request was |
| 3344 | // instantiated. |
| 3345 | blink::mojom::ConfidenceLevel confidence_level_ = |
| 3346 | blink::mojom::ConfidenceLevel::kHigh; |
| 3347 | |
John Kim | 1a6735b | 2025-08-12 19:16:50 | [diff] [blame] | 3348 | // The token value for canvas noising. This should only be set on main frame |
| 3349 | // navigations that subsequently set the token value on the page. |
| 3350 | std::optional<uint64_t> canvas_noise_token_ = std::nullopt; |
| 3351 | |
Jiacheng Guo | 2d8489d7 | 2025-08-18 06:51:14 | [diff] [blame] | 3352 | // For NavigationRequests not in a prerendered page, the value will be the |
| 3353 | // default-constructed null value. |
| 3354 | const PrerenderHostId prerender_host_id_; |
| 3355 | |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 3356 | base::WeakPtrFactory<NavigationRequest> weak_factory_{this}; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 3357 | }; |
| 3358 | |
| 3359 | } // namespace content |
| 3360 | |
| 3361 | #endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATION_REQUEST_H_ |