blob: 356a16c6285c620b6badff10d6f6a6ded3191fb8 [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;
27} // namespace network::mojom
28
danakjc492bf82020-09-09 20:02:4429namespace content {
30
David Bokan1bdb3701f2021-04-30 22:02:3531class CommitDeferringCondition;
danakjc492bf82020-09-09 20:02:4432class NavigationHandle;
33class NavigationRequest;
34class RenderFrameHostImpl;
35struct LoadCommittedDetails;
36struct OpenURLParams;
37
38// A delegate API used by Navigator to notify its embedder of navigation
39// related events.
Lei Zhanged9be3a2021-11-17 22:01:1840class NavigatorDelegate {
danakjc492bf82020-09-09 20:02:4441 public:
42 // Called when a navigation started. The same NavigationHandle will be
43 // provided for events related to the same navigation.
44 virtual void DidStartNavigation(NavigationHandle* navigation_handle) = 0;
45
46 // Called when a navigation was redirected.
47 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) = 0;
48
49 // Called when the navigation is about to be committed in a renderer.
50 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) = 0;
51
52 // Called when the navigation finished: it was either committed or canceled
53 // before commit. Note that |navigation_handle| will be destroyed at the end
54 // of this call.
55 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) = 0;
56
William Liuc6cc30ec2024-03-14 16:54:1657 // Called when the navigation gets cancelled before it even starts (i.e.,
58 // the respective `NavigationRequest::StartNavigation()`). This can happen
59 // when the user decides to not leave the current page by interacting with the
60 // BeforeUnload dialog. Can also happen if `BeginNavigationImpl()` reaches an
61 // early out. If the navigation never starts, `DidFinishNavigation()` won't be
62 // fired. Use this API to observe the destruction of such a navigation
63 // request.
64 virtual void DidCancelNavigationBeforeStart(
65 NavigationHandle* navigation_handle) = 0;
66
danakjc492bf82020-09-09 20:02:4467 // TODO(clamy): all methods below that are related to navigation
68 // events should go away in favor of the ones above.
69
danakjc492bf82020-09-09 20:02:4470 // Handles post-navigation tasks in navigation BEFORE the entry has been
71 // committed to the NavigationController.
72 virtual void DidNavigateMainFramePreCommit(
William Liub26568da2024-02-21 20:46:1473 NavigationHandle* navigation_handle,
danakjc492bf82020-09-09 20:02:4474 bool navigation_is_within_page) = 0;
75
76 // Handles post-navigation tasks in navigation AFTER the entry has been
77 // committed to the NavigationController. Note that the NavigationEntry is
78 // not provided since it may be invalid/changed after being committed. The
79 // NavigationController's last committed entry is for this navigation.
80 virtual void DidNavigateMainFramePostCommit(
81 RenderFrameHostImpl* render_frame_host,
Rakina Zata Amniff10975d2021-10-08 06:04:2482 const LoadCommittedDetails& details) = 0;
danakjc492bf82020-09-09 20:02:4483 virtual void DidNavigateAnyFramePostCommit(
84 RenderFrameHostImpl* render_frame_host,
Rakina Zata Amniff10975d2021-10-08 06:04:2485 const LoadCommittedDetails& details) = 0;
danakjc492bf82020-09-09 20:02:4486
Rakina Zata Amni742c2022024-07-02 05:29:1787 // Called when the NavigationHandleTiming associated with `navigation_handle`
88 // has been updated. See the comment at
89 // `WebContentsObserver::DidUpdateNavigationHandleTiming()` for more details.
90 virtual void DidUpdateNavigationHandleTiming(
91 NavigationHandle* navigation_handle) = 0;
92
danakjc492bf82020-09-09 20:02:4493 // Notification to the Navigator embedder that navigation state has
94 // changed. This method corresponds to
95 // WebContents::NotifyNavigationStateChanged.
96 virtual void NotifyChangedNavigationState(InvalidateTypes changed_flags) = 0;
97
98 // Opens a URL with the given parameters. See PageNavigator::OpenURL, which
99 // this is an alias of.
HuanPo Lin0d795c62024-03-28 03:54:05100 virtual WebContents* OpenURL(const OpenURLParams& params,
101 base::OnceCallback<void(NavigationHandle&)>
102 navigation_handle_callback) = 0;
danakjc492bf82020-09-09 20:02:44103
104 // Returns whether to continue a navigation that needs to transfer to a
105 // different process between the load start and commit.
Alexander Timina0ef6df2021-06-24 13:34:46106 virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation(
Ian Vollick1c6dd3e2022-04-13 02:06:26107 bool is_outermost_main_frame_navigation) = 0;
danakjc492bf82020-09-09 20:02:44108
109 // Returns the overridden user agent string if it's set.
110 virtual const blink::UserAgentOverride& GetUserAgentOverride() = 0;
111
112 // Returns the value to use for NavigationEntry::IsOverridingUserAgent() for
113 // a renderer initiated navigation.
114 virtual bool ShouldOverrideUserAgentForRendererInitiatedNavigation() = 0;
115
danakjc492bf82020-09-09 20:02:44116 // Returns the NavigationThrottles to add to this navigation. Normally these
117 // are defined by the content/ embedder, except in the case of interstitials
118 // where no NavigationThrottles are added to the navigation.
119 virtual std::vector<std::unique_ptr<NavigationThrottle>>
120 CreateThrottlesForNavigation(NavigationHandle* navigation_handle) = 0;
121
David Bokan1bdb3701f2021-04-30 22:02:35122 // Returns commit deferring conditions to add to this navigation.
123 virtual std::vector<std::unique_ptr<CommitDeferringCondition>>
124 CreateDeferringConditionsForNavigationCommit(
David Bokan51a6df832022-02-17 18:31:19125 NavigationHandle& navigation_handle,
126 CommitDeferringCondition::NavigationType type) = 0;
David Bokan1bdb3701f2021-04-30 22:02:35127
danakjc492bf82020-09-09 20:02:44128 // Called at the start of the navigation to get opaque data the embedder
129 // wants to see passed to the corresponding URLRequest on the IO thread.
130 // In the case of a navigation to an interstitial, no call will be made to the
131 // embedder and |nullptr| is returned.
132 virtual std::unique_ptr<NavigationUIData> GetNavigationUIData(
133 NavigationHandle* navigation_handle) = 0;
134
135 // Called when a navigation accessed ServiceWorker to check if it should be
136 // handled by the ServiceWorker or not.
137 virtual void OnServiceWorkerAccessed(NavigationHandle* navigation,
138 const GURL& scope,
139 AllowServiceWorkerResult allowed) = 0;
140
141 // Called when a network request issued by this navigation set or read a
142 // cookie.
143 virtual void OnCookiesAccessed(NavigationHandle* navigation,
144 const CookieAccessDetails& details) = 0;
145
Steven Valdeza06f680c2023-03-21 19:00:10146 // Called when a network request issued by this navigation accesses a Trust
147 // Token.
148 virtual void OnTrustTokensAccessed(
149 NavigationHandle* navigation,
150 const TrustTokenAccessDetails& details) = 0;
151
Tsuyoshi Horobcd0b9f62023-06-28 11:35:32152 // Called when a network request issued by this navigation accesses a shared
153 // dictionary.
154 virtual void OnSharedDictionaryAccessed(
155 NavigationHandle* navigation,
156 const network::mojom::SharedDictionaryAccessDetails& details) = 0;
157
danakjc492bf82020-09-09 20:02:44158 // Does a global walk of the session history and all committed/pending-commit
159 // origins, and registers origins that match |origin| to their respective
160 // BrowsingInstances. |navigation_request_to_exclude| allows the
161 // NavigationRequest that initiates this process to avoid marking itself as
162 // non-opted-in before it gets the chance to opt-in.
W. James MacLeanc07dc41b2022-07-25 18:52:16163 virtual void RegisterExistingOriginAsHavingDefaultIsolation(
danakjc492bf82020-09-09 20:02:44164 const url::Origin& origin,
165 NavigationRequest* navigation_request_to_exclude) = 0;
Lijin Shene4511c12024-03-19 19:31:30166
167 // Request to capture the content area as a bitmap. Return false if the
168 // embedder is not overlaying any content on the current navigation entry's
169 // Document. Return true if a bitmap will be captured. Callback must be
170 // dispatched asynchronously (with an empty bitmap if the capture fails,
171 // e.g. not enough memory) if this returns true.
172 virtual bool MaybeCopyContentAreaAsBitmap(
173 base::OnceCallback<void(const SkBitmap&)> callback) = 0;
danakjc492bf82020-09-09 20:02:44174};
175
176} // namespace content
177
178#endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_