Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2013 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_NAVIGATOR_DELEGATE_H_ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_ |
| 7 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 8 | #include "content/common/navigation_client.mojom.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 9 | #include "content/public/browser/allow_service_worker_result.h" |
David Bokan | 51a6df83 | 2022-02-17 18:31:19 | [diff] [blame] | 10 | #include "content/public/browser/commit_deferring_condition.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 11 | #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 Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 17 | #include "content/public/browser/trust_token_access_details.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 18 | |
| 19 | class GURL; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 20 | |
| 21 | namespace blink { |
| 22 | struct UserAgentOverride; |
| 23 | } // namespace blink |
| 24 | |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 25 | namespace network::mojom { |
| 26 | class SharedDictionaryAccessDetails; |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 27 | class DeviceBoundSession; |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 28 | } // namespace network::mojom |
| 29 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 30 | namespace content { |
| 31 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 32 | class CommitDeferringCondition; |
Dave Tapuska | 94a6978a | 2024-11-22 14:37:29 | [diff] [blame] | 33 | class FrameTree; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 34 | class NavigationHandle; |
| 35 | class NavigationRequest; |
Takashi Toyoshima | be55153 | 2025-05-02 18:13:52 | [diff] [blame] | 36 | class NavigationThrottleRegistry; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 37 | class RenderFrameHostImpl; |
Takashi Toyoshima | 96a07bb | 2025-06-06 06:45:58 | [diff] [blame] | 38 | class WebContents; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 39 | struct LoadCommittedDetails; |
| 40 | struct OpenURLParams; |
| 41 | |
| 42 | // A delegate API used by Navigator to notify its embedder of navigation |
| 43 | // related events. |
Lei Zhang | ed9be3a | 2021-11-17 22:01:18 | [diff] [blame] | 44 | class NavigatorDelegate { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 45 | 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 Liu | c6cc30ec | 2024-03-14 16:54:16 | [diff] [blame] | 61 | // 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 71 | // TODO(clamy): all methods below that are related to navigation |
| 72 | // events should go away in favor of the ones above. |
| 73 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 74 | // Handles post-navigation tasks in navigation BEFORE the entry has been |
| 75 | // committed to the NavigationController. |
| 76 | virtual void DidNavigateMainFramePreCommit( |
William Liu | b26568da | 2024-02-21 20:46:14 | [diff] [blame] | 77 | NavigationHandle* navigation_handle, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 78 | 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 Amni | ff10975d | 2021-10-08 06:04:24 | [diff] [blame] | 86 | const LoadCommittedDetails& details) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 87 | virtual void DidNavigateAnyFramePostCommit( |
| 88 | RenderFrameHostImpl* render_frame_host, |
Rakina Zata Amni | ff10975d | 2021-10-08 06:04:24 | [diff] [blame] | 89 | const LoadCommittedDetails& details) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 90 | |
Rakina Zata Amni | 742c202 | 2024-07-02 05:29:17 | [diff] [blame] | 91 | // 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 97 | // 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 Lin | 0d795c6 | 2024-03-28 03:54:05 | [diff] [blame] | 104 | virtual WebContents* OpenURL(const OpenURLParams& params, |
| 105 | base::OnceCallback<void(NavigationHandle&)> |
| 106 | navigation_handle_callback) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 107 | |
| 108 | // Returns whether to continue a navigation that needs to transfer to a |
| 109 | // different process between the load start and commit. |
Alexander Timin | a0ef6df | 2021-06-24 13:34:46 | [diff] [blame] | 110 | virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation( |
Ian Vollick | 1c6dd3e | 2022-04-13 02:06:26 | [diff] [blame] | 111 | bool is_outermost_main_frame_navigation) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 112 | |
| 113 | // Returns the overridden user agent string if it's set. |
Dave Tapuska | 94a6978a | 2024-11-22 14:37:29 | [diff] [blame] | 114 | virtual const blink::UserAgentOverride& GetUserAgentOverride( |
| 115 | FrameTree& frame_tree) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 116 | |
| 117 | // Returns the value to use for NavigationEntry::IsOverridingUserAgent() for |
| 118 | // a renderer initiated navigation. |
| 119 | virtual bool ShouldOverrideUserAgentForRendererInitiatedNavigation() = 0; |
| 120 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 121 | // 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 Toyoshima | 2a7f8cc0 | 2025-05-07 07:58:46 | [diff] [blame] | 124 | virtual void CreateThrottlesForNavigation( |
| 125 | NavigationThrottleRegistry& registry) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 126 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 127 | // Returns commit deferring conditions to add to this navigation. |
| 128 | virtual std::vector<std::unique_ptr<CommitDeferringCondition>> |
| 129 | CreateDeferringConditionsForNavigationCommit( |
David Bokan | 51a6df83 | 2022-02-17 18:31:19 | [diff] [blame] | 130 | NavigationHandle& navigation_handle, |
| 131 | CommitDeferringCondition::NavigationType type) = 0; |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 132 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 133 | // 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 Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 151 | // 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 Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 157 | // 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 Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 163 | // Called when a network request issued by this navigation accesses a |
| 164 | // device bound session. |
| 165 | virtual void OnDeviceBoundSessionAccessed( |
| 166 | NavigationHandle* navigation, |
Daniel Rubery | 7cdfa53 | 2025-01-24 16:57:50 | [diff] [blame] | 167 | const net::device_bound_sessions::SessionAccess& access) = 0; |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 168 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 169 | // 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 MacLean | c07dc41b | 2022-07-25 18:52:16 | [diff] [blame] | 174 | virtual void RegisterExistingOriginAsHavingDefaultIsolation( |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 175 | const url::Origin& origin, |
| 176 | NavigationRequest* navigation_request_to_exclude) = 0; |
Lijin Shen | e4511c1 | 2024-03-19 19:31:30 | [diff] [blame] | 177 | |
| 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 Culquicondor | da38be1 | 2025-01-13 16:16:23 | [diff] [blame] | 185 | |
| 186 | // Whether animations when performing forward transitions are supported. |
| 187 | virtual bool SupportsForwardTransitionAnimation() = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | } // namespace content |
| 191 | |
| 192 | #endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_ |