blob: 5ba2ce396de8a2ffff4789bca555c1573b44662e [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2013 The Chromium Authors
danakjc492bf82020-09-09 20:02:442// 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_NAVIGATOR_DELEGATE_H_
6#define CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_
7
David Bokan1bdb3701f2021-04-30 22:02:358#include "content/common/navigation_client.mojom.h"
danakjc492bf82020-09-09 20:02:449#include "content/public/browser/allow_service_worker_result.h"
David Bokan51a6df832022-02-17 18:31:1910#include "content/public/browser/commit_deferring_condition.h"
danakjc492bf82020-09-09 20:02:4411#include "content/public/browser/cookie_access_details.h"
12#include "content/public/browser/invalidate_type.h"
13#include "content/public/browser/navigation_controller.h"
14#include "content/public/browser/navigation_throttle.h"
15#include "content/public/browser/navigation_ui_data.h"
16#include "content/public/browser/reload_type.h"
Steven Valdeza06f680c2023-03-21 19:00:1017#include "content/public/browser/trust_token_access_details.h"
danakjc492bf82020-09-09 20:02:4418
19class GURL;
danakjc492bf82020-09-09 20:02:4420
21namespace blink {
22struct UserAgentOverride;
23} // namespace blink
24
Tsuyoshi Horobcd0b9f62023-06-28 11:35:3225namespace network::mojom {
26class SharedDictionaryAccessDetails;
Daniel Rubery6420d74302024-11-19 01:42:4027class DeviceBoundSession;
Tsuyoshi Horobcd0b9f62023-06-28 11:35:3228} // namespace network::mojom
29
danakjc492bf82020-09-09 20:02:4430namespace content {
31
David Bokan1bdb3701f2021-04-30 22:02:3532class CommitDeferringCondition;
Dave Tapuska94a6978a2024-11-22 14:37:2933class FrameTree;
danakjc492bf82020-09-09 20:02:4434class NavigationHandle;
35class NavigationRequest;
Takashi Toyoshimabe551532025-05-02 18:13:5236class NavigationThrottleRegistry;
danakjc492bf82020-09-09 20:02:4437class RenderFrameHostImpl;
Takashi Toyoshima96a07bb2025-06-06 06:45:5838class WebContents;
danakjc492bf82020-09-09 20:02:4439struct LoadCommittedDetails;
40struct OpenURLParams;
41
42// A delegate API used by Navigator to notify its embedder of navigation
43// related events.
Lei Zhanged9be3a2021-11-17 22:01:1844class NavigatorDelegate {
danakjc492bf82020-09-09 20:02:4445 public:
46 // Called when a navigation started. The same NavigationHandle will be
47 // provided for events related to the same navigation.
48 virtual void DidStartNavigation(NavigationHandle* navigation_handle) = 0;
49
50 // Called when a navigation was redirected.
51 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) = 0;
52
53 // Called when the navigation is about to be committed in a renderer.
54 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) = 0;
55
56 // Called when the navigation finished: it was either committed or canceled
57 // before commit. Note that |navigation_handle| will be destroyed at the end
58 // of this call.
59 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) = 0;
60
William Liuc6cc30ec2024-03-14 16:54:1661 // Called when the navigation gets cancelled before it even starts (i.e.,
62 // the respective `NavigationRequest::StartNavigation()`). This can happen
63 // when the user decides to not leave the current page by interacting with the
64 // BeforeUnload dialog. Can also happen if `BeginNavigationImpl()` reaches an
65 // early out. If the navigation never starts, `DidFinishNavigation()` won't be
66 // fired. Use this API to observe the destruction of such a navigation
67 // request.
68 virtual void DidCancelNavigationBeforeStart(
69 NavigationHandle* navigation_handle) = 0;
70
danakjc492bf82020-09-09 20:02:4471 // TODO(clamy): all methods below that are related to navigation
72 // events should go away in favor of the ones above.
73
danakjc492bf82020-09-09 20:02:4474 // Handles post-navigation tasks in navigation BEFORE the entry has been
75 // committed to the NavigationController.
76 virtual void DidNavigateMainFramePreCommit(
William Liub26568da2024-02-21 20:46:1477 NavigationHandle* navigation_handle,
danakjc492bf82020-09-09 20:02:4478 bool navigation_is_within_page) = 0;
79
80 // Handles post-navigation tasks in navigation AFTER the entry has been
81 // committed to the NavigationController. Note that the NavigationEntry is
82 // not provided since it may be invalid/changed after being committed. The
83 // NavigationController's last committed entry is for this navigation.
84 virtual void DidNavigateMainFramePostCommit(
85 RenderFrameHostImpl* render_frame_host,
Rakina Zata Amniff10975d2021-10-08 06:04:2486 const LoadCommittedDetails& details) = 0;
danakjc492bf82020-09-09 20:02:4487 virtual void DidNavigateAnyFramePostCommit(
88 RenderFrameHostImpl* render_frame_host,
Rakina Zata Amniff10975d2021-10-08 06:04:2489 const LoadCommittedDetails& details) = 0;
danakjc492bf82020-09-09 20:02:4490
Rakina Zata Amni742c2022024-07-02 05:29:1791 // Called when the NavigationHandleTiming associated with `navigation_handle`
92 // has been updated. See the comment at
93 // `WebContentsObserver::DidUpdateNavigationHandleTiming()` for more details.
94 virtual void DidUpdateNavigationHandleTiming(
95 NavigationHandle* navigation_handle) = 0;
96
danakjc492bf82020-09-09 20:02:4497 // Notification to the Navigator embedder that navigation state has
98 // changed. This method corresponds to
99 // WebContents::NotifyNavigationStateChanged.
100 virtual void NotifyChangedNavigationState(InvalidateTypes changed_flags) = 0;
101
102 // Opens a URL with the given parameters. See PageNavigator::OpenURL, which
103 // this is an alias of.
HuanPo Lin0d795c62024-03-28 03:54:05104 virtual WebContents* OpenURL(const OpenURLParams& params,
105 base::OnceCallback<void(NavigationHandle&)>
106 navigation_handle_callback) = 0;
danakjc492bf82020-09-09 20:02:44107
108 // Returns whether to continue a navigation that needs to transfer to a
109 // different process between the load start and commit.
Alexander Timina0ef6df2021-06-24 13:34:46110 virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation(
Ian Vollick1c6dd3e2022-04-13 02:06:26111 bool is_outermost_main_frame_navigation) = 0;
danakjc492bf82020-09-09 20:02:44112
113 // Returns the overridden user agent string if it's set.
Dave Tapuska94a6978a2024-11-22 14:37:29114 virtual const blink::UserAgentOverride& GetUserAgentOverride(
115 FrameTree& frame_tree) = 0;
danakjc492bf82020-09-09 20:02:44116
117 // Returns the value to use for NavigationEntry::IsOverridingUserAgent() for
118 // a renderer initiated navigation.
119 virtual bool ShouldOverrideUserAgentForRendererInitiatedNavigation() = 0;
120
danakjc492bf82020-09-09 20:02:44121 // Returns the NavigationThrottles to add to this navigation. Normally these
122 // are defined by the content/ embedder, except in the case of interstitials
123 // where no NavigationThrottles are added to the navigation.
Takashi Toyoshima2a7f8cc02025-05-07 07:58:46124 virtual void CreateThrottlesForNavigation(
125 NavigationThrottleRegistry& registry) = 0;
danakjc492bf82020-09-09 20:02:44126
David Bokan1bdb3701f2021-04-30 22:02:35127 // Returns commit deferring conditions to add to this navigation.
128 virtual std::vector<std::unique_ptr<CommitDeferringCondition>>
129 CreateDeferringConditionsForNavigationCommit(
David Bokan51a6df832022-02-17 18:31:19130 NavigationHandle& navigation_handle,
131 CommitDeferringCondition::NavigationType type) = 0;
David Bokan1bdb3701f2021-04-30 22:02:35132
danakjc492bf82020-09-09 20:02:44133 // Called at the start of the navigation to get opaque data the embedder
134 // wants to see passed to the corresponding URLRequest on the IO thread.
135 // In the case of a navigation to an interstitial, no call will be made to the
136 // embedder and |nullptr| is returned.
137 virtual std::unique_ptr<NavigationUIData> GetNavigationUIData(
138 NavigationHandle* navigation_handle) = 0;
139
140 // Called when a navigation accessed ServiceWorker to check if it should be
141 // handled by the ServiceWorker or not.
142 virtual void OnServiceWorkerAccessed(NavigationHandle* navigation,
143 const GURL& scope,
144 AllowServiceWorkerResult allowed) = 0;
145
146 // Called when a network request issued by this navigation set or read a
147 // cookie.
148 virtual void OnCookiesAccessed(NavigationHandle* navigation,
149 const CookieAccessDetails& details) = 0;
150
Steven Valdeza06f680c2023-03-21 19:00:10151 // Called when a network request issued by this navigation accesses a Trust
152 // Token.
153 virtual void OnTrustTokensAccessed(
154 NavigationHandle* navigation,
155 const TrustTokenAccessDetails& details) = 0;
156
Tsuyoshi Horobcd0b9f62023-06-28 11:35:32157 // Called when a network request issued by this navigation accesses a shared
158 // dictionary.
159 virtual void OnSharedDictionaryAccessed(
160 NavigationHandle* navigation,
161 const network::mojom::SharedDictionaryAccessDetails& details) = 0;
162
Daniel Rubery6420d74302024-11-19 01:42:40163 // Called when a network request issued by this navigation accesses a
164 // device bound session.
165 virtual void OnDeviceBoundSessionAccessed(
166 NavigationHandle* navigation,
Daniel Rubery7cdfa532025-01-24 16:57:50167 const net::device_bound_sessions::SessionAccess& access) = 0;
Daniel Rubery6420d74302024-11-19 01:42:40168
danakjc492bf82020-09-09 20:02:44169 // Does a global walk of the session history and all committed/pending-commit
170 // origins, and registers origins that match |origin| to their respective
171 // BrowsingInstances. |navigation_request_to_exclude| allows the
172 // NavigationRequest that initiates this process to avoid marking itself as
173 // non-opted-in before it gets the chance to opt-in.
W. James MacLeanc07dc41b2022-07-25 18:52:16174 virtual void RegisterExistingOriginAsHavingDefaultIsolation(
danakjc492bf82020-09-09 20:02:44175 const url::Origin& origin,
176 NavigationRequest* navigation_request_to_exclude) = 0;
Lijin Shene4511c12024-03-19 19:31:30177
178 // Request to capture the content area as a bitmap. Return false if the
179 // embedder is not overlaying any content on the current navigation entry's
180 // Document. Return true if a bitmap will be captured. Callback must be
181 // dispatched asynchronously (with an empty bitmap if the capture fails,
182 // e.g. not enough memory) if this returns true.
183 virtual bool MaybeCopyContentAreaAsBitmap(
184 base::OnceCallback<void(const SkBitmap&)> callback) = 0;
Aldo Culquicondorda38be12025-01-13 16:16:23185
186 // Whether animations when performing forward transitions are supported.
187 virtual bool SupportsForwardTransitionAnimation() = 0;
danakjc492bf82020-09-09 20:02:44188};
189
190} // namespace content
191
192#endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_