blob: 5306124f8d30d269f2c50b6b5edd1a70b5d6ab0d [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
25namespace content {
26
David Bokan1bdb3701f2021-04-30 22:02:3527class CommitDeferringCondition;
danakjc492bf82020-09-09 20:02:4428class NavigationHandle;
29class NavigationRequest;
30class RenderFrameHostImpl;
31struct LoadCommittedDetails;
32struct OpenURLParams;
33
34// A delegate API used by Navigator to notify its embedder of navigation
35// related events.
Lei Zhanged9be3a2021-11-17 22:01:1836class NavigatorDelegate {
danakjc492bf82020-09-09 20:02:4437 public:
38 // Called when a navigation started. The same NavigationHandle will be
39 // provided for events related to the same navigation.
40 virtual void DidStartNavigation(NavigationHandle* navigation_handle) = 0;
41
42 // Called when a navigation was redirected.
43 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) = 0;
44
45 // Called when the navigation is about to be committed in a renderer.
46 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) = 0;
47
48 // Called when the navigation finished: it was either committed or canceled
49 // before commit. Note that |navigation_handle| will be destroyed at the end
50 // of this call.
51 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) = 0;
52
53 // TODO(clamy): all methods below that are related to navigation
54 // events should go away in favor of the ones above.
55
danakjc492bf82020-09-09 20:02:4456 // Handles post-navigation tasks in navigation BEFORE the entry has been
57 // committed to the NavigationController.
58 virtual void DidNavigateMainFramePreCommit(
Liviu Tinta235581962021-07-14 20:37:0759 FrameTreeNode* frame_tree_node,
danakjc492bf82020-09-09 20:02:4460 bool navigation_is_within_page) = 0;
61
62 // Handles post-navigation tasks in navigation AFTER the entry has been
63 // committed to the NavigationController. Note that the NavigationEntry is
64 // not provided since it may be invalid/changed after being committed. The
65 // NavigationController's last committed entry is for this navigation.
66 virtual void DidNavigateMainFramePostCommit(
67 RenderFrameHostImpl* render_frame_host,
Rakina Zata Amniff10975d2021-10-08 06:04:2468 const LoadCommittedDetails& details) = 0;
danakjc492bf82020-09-09 20:02:4469 virtual void DidNavigateAnyFramePostCommit(
70 RenderFrameHostImpl* render_frame_host,
Rakina Zata Amniff10975d2021-10-08 06:04:2471 const LoadCommittedDetails& details) = 0;
danakjc492bf82020-09-09 20:02:4472
danakjc492bf82020-09-09 20:02:4473 // Notification to the Navigator embedder that navigation state has
74 // changed. This method corresponds to
75 // WebContents::NotifyNavigationStateChanged.
76 virtual void NotifyChangedNavigationState(InvalidateTypes changed_flags) = 0;
77
78 // Opens a URL with the given parameters. See PageNavigator::OpenURL, which
79 // this is an alias of.
80 virtual WebContents* OpenURL(const OpenURLParams& params) = 0;
81
82 // Returns whether to continue a navigation that needs to transfer to a
83 // different process between the load start and commit.
Alexander Timina0ef6df2021-06-24 13:34:4684 virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation(
Ian Vollick1c6dd3e2022-04-13 02:06:2685 bool is_outermost_main_frame_navigation) = 0;
danakjc492bf82020-09-09 20:02:4486
87 // Returns the overridden user agent string if it's set.
88 virtual const blink::UserAgentOverride& GetUserAgentOverride() = 0;
89
90 // Returns the value to use for NavigationEntry::IsOverridingUserAgent() for
91 // a renderer initiated navigation.
92 virtual bool ShouldOverrideUserAgentForRendererInitiatedNavigation() = 0;
93
danakjc492bf82020-09-09 20:02:4494 // Returns the NavigationThrottles to add to this navigation. Normally these
95 // are defined by the content/ embedder, except in the case of interstitials
96 // where no NavigationThrottles are added to the navigation.
97 virtual std::vector<std::unique_ptr<NavigationThrottle>>
98 CreateThrottlesForNavigation(NavigationHandle* navigation_handle) = 0;
99
David Bokan1bdb3701f2021-04-30 22:02:35100 // Returns commit deferring conditions to add to this navigation.
101 virtual std::vector<std::unique_ptr<CommitDeferringCondition>>
102 CreateDeferringConditionsForNavigationCommit(
David Bokan51a6df832022-02-17 18:31:19103 NavigationHandle& navigation_handle,
104 CommitDeferringCondition::NavigationType type) = 0;
David Bokan1bdb3701f2021-04-30 22:02:35105
danakjc492bf82020-09-09 20:02:44106 // Called at the start of the navigation to get opaque data the embedder
107 // wants to see passed to the corresponding URLRequest on the IO thread.
108 // In the case of a navigation to an interstitial, no call will be made to the
109 // embedder and |nullptr| is returned.
110 virtual std::unique_ptr<NavigationUIData> GetNavigationUIData(
111 NavigationHandle* navigation_handle) = 0;
112
113 // Called when a navigation accessed ServiceWorker to check if it should be
114 // handled by the ServiceWorker or not.
115 virtual void OnServiceWorkerAccessed(NavigationHandle* navigation,
116 const GURL& scope,
117 AllowServiceWorkerResult allowed) = 0;
118
119 // Called when a network request issued by this navigation set or read a
120 // cookie.
121 virtual void OnCookiesAccessed(NavigationHandle* navigation,
122 const CookieAccessDetails& details) = 0;
123
Steven Valdeza06f680c2023-03-21 19:00:10124 // Called when a network request issued by this navigation accesses a Trust
125 // Token.
126 virtual void OnTrustTokensAccessed(
127 NavigationHandle* navigation,
128 const TrustTokenAccessDetails& details) = 0;
129
danakjc492bf82020-09-09 20:02:44130 // Does a global walk of the session history and all committed/pending-commit
131 // origins, and registers origins that match |origin| to their respective
132 // BrowsingInstances. |navigation_request_to_exclude| allows the
133 // NavigationRequest that initiates this process to avoid marking itself as
134 // non-opted-in before it gets the chance to opt-in.
W. James MacLeanc07dc41b2022-07-25 18:52:16135 virtual void RegisterExistingOriginAsHavingDefaultIsolation(
danakjc492bf82020-09-09 20:02:44136 const url::Origin& origin,
137 NavigationRequest* navigation_request_to_exclude) = 0;
danakjc492bf82020-09-09 20:02:44138};
139
140} // namespace content
141
142#endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_