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 | |
| 25 | namespace content { |
| 26 | |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 27 | class CommitDeferringCondition; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 28 | class NavigationHandle; |
| 29 | class NavigationRequest; |
| 30 | class RenderFrameHostImpl; |
| 31 | struct LoadCommittedDetails; |
| 32 | struct OpenURLParams; |
| 33 | |
| 34 | // A delegate API used by Navigator to notify its embedder of navigation |
| 35 | // related events. |
Lei Zhang | ed9be3a | 2021-11-17 22:01:18 | [diff] [blame] | 36 | class NavigatorDelegate { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 37 | 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 56 | // Handles post-navigation tasks in navigation BEFORE the entry has been |
| 57 | // committed to the NavigationController. |
| 58 | virtual void DidNavigateMainFramePreCommit( |
Liviu Tinta | 23558196 | 2021-07-14 20:37:07 | [diff] [blame] | 59 | FrameTreeNode* frame_tree_node, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 60 | 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 Amni | ff10975d | 2021-10-08 06:04:24 | [diff] [blame] | 68 | const LoadCommittedDetails& details) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 69 | virtual void DidNavigateAnyFramePostCommit( |
| 70 | RenderFrameHostImpl* render_frame_host, |
Rakina Zata Amni | ff10975d | 2021-10-08 06:04:24 | [diff] [blame] | 71 | const LoadCommittedDetails& details) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 72 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 73 | // 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 Timin | a0ef6df | 2021-06-24 13:34:46 | [diff] [blame] | 84 | virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation( |
Ian Vollick | 1c6dd3e | 2022-04-13 02:06:26 | [diff] [blame] | 85 | bool is_outermost_main_frame_navigation) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 86 | |
| 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 94 | // 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 Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 100 | // Returns commit deferring conditions to add to this navigation. |
| 101 | virtual std::vector<std::unique_ptr<CommitDeferringCondition>> |
| 102 | CreateDeferringConditionsForNavigationCommit( |
David Bokan | 51a6df83 | 2022-02-17 18:31:19 | [diff] [blame] | 103 | NavigationHandle& navigation_handle, |
| 104 | CommitDeferringCondition::NavigationType type) = 0; |
David Bokan | 1bdb3701f | 2021-04-30 22:02:35 | [diff] [blame] | 105 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 106 | // 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 Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame^] | 124 | // 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 130 | // 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 MacLean | c07dc41b | 2022-07-25 18:52:16 | [diff] [blame] | 135 | virtual void RegisterExistingOriginAsHavingDefaultIsolation( |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 136 | const url::Origin& origin, |
| 137 | NavigationRequest* navigation_request_to_exclude) = 0; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | } // namespace content |
| 141 | |
| 142 | #endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_ |