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; |
| 27 | } // namespace network::mojom |
| 28 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 29 | namespace content { |
| 30 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 31 | class CommitDeferringCondition; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 32 | class NavigationHandle; |
| 33 | class NavigationRequest; |
| 34 | class RenderFrameHostImpl; |
| 35 | struct LoadCommittedDetails; |
| 36 | struct OpenURLParams; |
| 37 | |
| 38 | // A delegate API used by Navigator to notify its embedder of navigation |
| 39 | // related events. |
Lei Zhang | ed9be3a | 2021-11-17 22:01:18 | [diff] [blame] | 40 | class NavigatorDelegate { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 41 | 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 Liu | c6cc30ec | 2024-03-14 16:54:16 | [diff] [blame] | 57 | // 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 67 | // TODO(clamy): all methods below that are related to navigation |
| 68 | // events should go away in favor of the ones above. |
| 69 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 70 | // Handles post-navigation tasks in navigation BEFORE the entry has been |
| 71 | // committed to the NavigationController. |
| 72 | virtual void DidNavigateMainFramePreCommit( |
William Liu | b26568da | 2024-02-21 20:46:14 | [diff] [blame] | 73 | NavigationHandle* navigation_handle, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 74 | 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 Amni | ff10975d | 2021-10-08 06:04:24 | [diff] [blame] | 82 | const LoadCommittedDetails& details) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 83 | virtual void DidNavigateAnyFramePostCommit( |
| 84 | RenderFrameHostImpl* render_frame_host, |
Rakina Zata Amni | ff10975d | 2021-10-08 06:04:24 | [diff] [blame] | 85 | const LoadCommittedDetails& details) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 86 | |
Rakina Zata Amni | 742c202 | 2024-07-02 05:29:17 | [diff] [blame^] | 87 | // 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 93 | // 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 Lin | 0d795c6 | 2024-03-28 03:54:05 | [diff] [blame] | 100 | virtual WebContents* OpenURL(const OpenURLParams& params, |
| 101 | base::OnceCallback<void(NavigationHandle&)> |
| 102 | navigation_handle_callback) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 103 | |
| 104 | // Returns whether to continue a navigation that needs to transfer to a |
| 105 | // different process between the load start and commit. |
Alexander Timin | a0ef6df | 2021-06-24 13:34:46 | [diff] [blame] | 106 | virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation( |
Ian Vollick | 1c6dd3e | 2022-04-13 02:06:26 | [diff] [blame] | 107 | bool is_outermost_main_frame_navigation) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 108 | |
| 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 116 | // 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 Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 122 | // Returns commit deferring conditions to add to this navigation. |
| 123 | virtual std::vector<std::unique_ptr<CommitDeferringCondition>> |
| 124 | CreateDeferringConditionsForNavigationCommit( |
David Bokan | 51a6df83 | 2022-02-17 18:31:19 | [diff] [blame] | 125 | NavigationHandle& navigation_handle, |
| 126 | CommitDeferringCondition::NavigationType type) = 0; |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 127 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 128 | // 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 Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 146 | // 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 Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 152 | // 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 158 | // 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 MacLean | c07dc41b | 2022-07-25 18:52:16 | [diff] [blame] | 163 | virtual void RegisterExistingOriginAsHavingDefaultIsolation( |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 164 | const url::Origin& origin, |
| 165 | NavigationRequest* navigation_request_to_exclude) = 0; |
Lijin Shen | e4511c1 | 2024-03-19 19:31:30 | [diff] [blame] | 166 | |
| 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; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | } // namespace content |
| 177 | |
| 178 | #endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_ |