blob: dd41492bee1e9863b7d6392e648bcc094dbf8be7 [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;
38struct LoadCommittedDetails;
39struct OpenURLParams;
40
41// A delegate API used by Navigator to notify its embedder of navigation
42// related events.
Lei Zhanged9be3a2021-11-17 22:01:1843class NavigatorDelegate {
danakjc492bf82020-09-09 20:02:4444 public:
45 // Called when a navigation started. The same NavigationHandle will be
46 // provided for events related to the same navigation.
47 virtual void DidStartNavigation(NavigationHandle* navigation_handle) = 0;
48
49 // Called when a navigation was redirected.
50 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) = 0;
51
52 // Called when the navigation is about to be committed in a renderer.
53 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) = 0;
54
55 // Called when the navigation finished: it was either committed or canceled
56 // before commit. Note that |navigation_handle| will be destroyed at the end
57 // of this call.
58 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) = 0;
59
William Liuc6cc30ec2024-03-14 16:54:1660 // Called when the navigation gets cancelled before it even starts (i.e.,
61 // the respective `NavigationRequest::StartNavigation()`). This can happen
62 // when the user decides to not leave the current page by interacting with the
63 // BeforeUnload dialog. Can also happen if `BeginNavigationImpl()` reaches an
64 // early out. If the navigation never starts, `DidFinishNavigation()` won't be
65 // fired. Use this API to observe the destruction of such a navigation
66 // request.
67 virtual void DidCancelNavigationBeforeStart(
68 NavigationHandle* navigation_handle) = 0;
69
danakjc492bf82020-09-09 20:02:4470 // TODO(clamy): all methods below that are related to navigation
71 // events should go away in favor of the ones above.
72
danakjc492bf82020-09-09 20:02:4473 // Handles post-navigation tasks in navigation BEFORE the entry has been
74 // committed to the NavigationController.
75 virtual void DidNavigateMainFramePreCommit(
William Liub26568da2024-02-21 20:46:1476 NavigationHandle* navigation_handle,
danakjc492bf82020-09-09 20:02:4477 bool navigation_is_within_page) = 0;
78
79 // Handles post-navigation tasks in navigation AFTER the entry has been
80 // committed to the NavigationController. Note that the NavigationEntry is
81 // not provided since it may be invalid/changed after being committed. The
82 // NavigationController's last committed entry is for this navigation.
83 virtual void DidNavigateMainFramePostCommit(
84 RenderFrameHostImpl* render_frame_host,
Rakina Zata Amniff10975d2021-10-08 06:04:2485 const LoadCommittedDetails& details) = 0;
danakjc492bf82020-09-09 20:02:4486 virtual void DidNavigateAnyFramePostCommit(
87 RenderFrameHostImpl* render_frame_host,
Rakina Zata Amniff10975d2021-10-08 06:04:2488 const LoadCommittedDetails& details) = 0;
danakjc492bf82020-09-09 20:02:4489
Rakina Zata Amni742c2022024-07-02 05:29:1790 // Called when the NavigationHandleTiming associated with `navigation_handle`
91 // has been updated. See the comment at
92 // `WebContentsObserver::DidUpdateNavigationHandleTiming()` for more details.
93 virtual void DidUpdateNavigationHandleTiming(
94 NavigationHandle* navigation_handle) = 0;
95
danakjc492bf82020-09-09 20:02:4496 // Notification to the Navigator embedder that navigation state has
97 // changed. This method corresponds to
98 // WebContents::NotifyNavigationStateChanged.
99 virtual void NotifyChangedNavigationState(InvalidateTypes changed_flags) = 0;
100
101 // Opens a URL with the given parameters. See PageNavigator::OpenURL, which
102 // this is an alias of.
HuanPo Lin0d795c62024-03-28 03:54:05103 virtual WebContents* OpenURL(const OpenURLParams& params,
104 base::OnceCallback<void(NavigationHandle&)>
105 navigation_handle_callback) = 0;
danakjc492bf82020-09-09 20:02:44106
107 // Returns whether to continue a navigation that needs to transfer to a
108 // different process between the load start and commit.
Alexander Timina0ef6df2021-06-24 13:34:46109 virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation(
Ian Vollick1c6dd3e2022-04-13 02:06:26110 bool is_outermost_main_frame_navigation) = 0;
danakjc492bf82020-09-09 20:02:44111
112 // Returns the overridden user agent string if it's set.
Dave Tapuska94a6978a2024-11-22 14:37:29113 virtual const blink::UserAgentOverride& GetUserAgentOverride(
114 FrameTree& frame_tree) = 0;
danakjc492bf82020-09-09 20:02:44115
116 // Returns the value to use for NavigationEntry::IsOverridingUserAgent() for
117 // a renderer initiated navigation.
118 virtual bool ShouldOverrideUserAgentForRendererInitiatedNavigation() = 0;
119
danakjc492bf82020-09-09 20:02:44120 // Returns the NavigationThrottles to add to this navigation. Normally these
121 // are defined by the content/ embedder, except in the case of interstitials
122 // where no NavigationThrottles are added to the navigation.
Takashi Toyoshimabe551532025-05-02 18:13:52123 // TODO(https://crbug.com/412524375): New code should add a NavigationThrottle
124 // via the given `registry` instead of returning a NavigationThrottle from
125 // this method. Once all existing NavigationThrottles are migrated, the
126 // returned type will be changed to `void`.
danakjc492bf82020-09-09 20:02:44127 virtual std::vector<std::unique_ptr<NavigationThrottle>>
Takashi Toyoshimabe551532025-05-02 18:13:52128 CreateThrottlesForNavigation(NavigationThrottleRegistry& registry) = 0;
danakjc492bf82020-09-09 20:02:44129
David Bokan1bdb3701f2021-04-30 22:02:35130 // Returns commit deferring conditions to add to this navigation.
131 virtual std::vector<std::unique_ptr<CommitDeferringCondition>>
132 CreateDeferringConditionsForNavigationCommit(
David Bokan51a6df832022-02-17 18:31:19133 NavigationHandle& navigation_handle,
134 CommitDeferringCondition::NavigationType type) = 0;
David Bokan1bdb3701f2021-04-30 22:02:35135
danakjc492bf82020-09-09 20:02:44136 // Called at the start of the navigation to get opaque data the embedder
137 // wants to see passed to the corresponding URLRequest on the IO thread.
138 // In the case of a navigation to an interstitial, no call will be made to the
139 // embedder and |nullptr| is returned.
140 virtual std::unique_ptr<NavigationUIData> GetNavigationUIData(
141 NavigationHandle* navigation_handle) = 0;
142
143 // Called when a navigation accessed ServiceWorker to check if it should be
144 // handled by the ServiceWorker or not.
145 virtual void OnServiceWorkerAccessed(NavigationHandle* navigation,
146 const GURL& scope,
147 AllowServiceWorkerResult allowed) = 0;
148
149 // Called when a network request issued by this navigation set or read a
150 // cookie.
151 virtual void OnCookiesAccessed(NavigationHandle* navigation,
152 const CookieAccessDetails& details) = 0;
153
Steven Valdeza06f680c2023-03-21 19:00:10154 // Called when a network request issued by this navigation accesses a Trust
155 // Token.
156 virtual void OnTrustTokensAccessed(
157 NavigationHandle* navigation,
158 const TrustTokenAccessDetails& details) = 0;
159
Tsuyoshi Horobcd0b9f62023-06-28 11:35:32160 // Called when a network request issued by this navigation accesses a shared
161 // dictionary.
162 virtual void OnSharedDictionaryAccessed(
163 NavigationHandle* navigation,
164 const network::mojom::SharedDictionaryAccessDetails& details) = 0;
165
Daniel Rubery6420d74302024-11-19 01:42:40166 // Called when a network request issued by this navigation accesses a
167 // device bound session.
168 virtual void OnDeviceBoundSessionAccessed(
169 NavigationHandle* navigation,
Daniel Rubery7cdfa532025-01-24 16:57:50170 const net::device_bound_sessions::SessionAccess& access) = 0;
Daniel Rubery6420d74302024-11-19 01:42:40171
danakjc492bf82020-09-09 20:02:44172 // Does a global walk of the session history and all committed/pending-commit
173 // origins, and registers origins that match |origin| to their respective
174 // BrowsingInstances. |navigation_request_to_exclude| allows the
175 // NavigationRequest that initiates this process to avoid marking itself as
176 // non-opted-in before it gets the chance to opt-in.
W. James MacLeanc07dc41b2022-07-25 18:52:16177 virtual void RegisterExistingOriginAsHavingDefaultIsolation(
danakjc492bf82020-09-09 20:02:44178 const url::Origin& origin,
179 NavigationRequest* navigation_request_to_exclude) = 0;
Lijin Shene4511c12024-03-19 19:31:30180
181 // Request to capture the content area as a bitmap. Return false if the
182 // embedder is not overlaying any content on the current navigation entry's
183 // Document. Return true if a bitmap will be captured. Callback must be
184 // dispatched asynchronously (with an empty bitmap if the capture fails,
185 // e.g. not enough memory) if this returns true.
186 virtual bool MaybeCopyContentAreaAsBitmap(
187 base::OnceCallback<void(const SkBitmap&)> callback) = 0;
Aldo Culquicondorda38be12025-01-13 16:16:23188
189 // Whether animations when performing forward transitions are supported.
190 virtual bool SupportsForwardTransitionAnimation() = 0;
danakjc492bf82020-09-09 20:02:44191};
192
193} // namespace content
194
195#endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_