1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 8 #include "content/public/browser/allow_service_worker_result.h" 9 #include "content/public/browser/cookie_access_details.h" 10 #include "content/public/browser/invalidate_type.h" 11 #include "content/public/browser/navigation_controller.h" 12 #include "content/public/browser/navigation_throttle.h" 13 #include "content/public/browser/navigation_ui_data.h" 14 #include "content/public/browser/reload_type.h" 15 16 class GURL; 17 struct FrameHostMsg_DidCommitProvisionalLoad_Params; 18 19 namespace blink { 20 struct UserAgentOverride; 21 } // namespace blink 22 23 namespace content { 24 25 class FrameTreeNode; 26 class NavigationHandle; 27 class NavigationRequest; 28 class RenderFrameHostImpl; 29 struct LoadCommittedDetails; 30 struct OpenURLParams; 31 32 // A delegate API used by Navigator to notify its embedder of navigation 33 // related events. 34 class CONTENT_EXPORT NavigatorDelegate { 35 public: 36 // Called when a navigation started. The same NavigationHandle will be 37 // provided for events related to the same navigation. 38 virtual void DidStartNavigation(NavigationHandle* navigation_handle) = 0; 39 40 // Called when a navigation was redirected. 41 virtual void DidRedirectNavigation(NavigationHandle* navigation_handle) = 0; 42 43 // Called when the navigation is about to be committed in a renderer. 44 virtual void ReadyToCommitNavigation(NavigationHandle* navigation_handle) = 0; 45 46 // Called when the navigation finished: it was either committed or canceled 47 // before commit. Note that |navigation_handle| will be destroyed at the end 48 // of this call. 49 virtual void DidFinishNavigation(NavigationHandle* navigation_handle) = 0; 50 51 // TODO(clamy): all methods below that are related to navigation 52 // events should go away in favor of the ones above. 53 54 // Document load in |render_frame_host| failed. 55 virtual void DidFailLoadWithError(RenderFrameHostImpl* render_frame_host, 56 const GURL& url, 57 int error_code) = 0; 58 59 // Handles post-navigation tasks in navigation BEFORE the entry has been 60 // committed to the NavigationController. 61 virtual void DidNavigateMainFramePreCommit( 62 bool navigation_is_within_page) = 0; 63 64 // Handles post-navigation tasks in navigation AFTER the entry has been 65 // committed to the NavigationController. Note that the NavigationEntry is 66 // not provided since it may be invalid/changed after being committed. The 67 // NavigationController's last committed entry is for this navigation. 68 virtual void DidNavigateMainFramePostCommit( 69 RenderFrameHostImpl* render_frame_host, 70 const LoadCommittedDetails& details, 71 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) = 0; 72 virtual void DidNavigateAnyFramePostCommit( 73 RenderFrameHostImpl* render_frame_host, 74 const LoadCommittedDetails& details, 75 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) = 0; 76 77 virtual bool CanOverscrollContent() const = 0; 78 79 // Notification to the Navigator embedder that navigation state has 80 // changed. This method corresponds to 81 // WebContents::NotifyNavigationStateChanged. 82 virtual void NotifyChangedNavigationState(InvalidateTypes changed_flags) = 0; 83 84 // Opens a URL with the given parameters. See PageNavigator::OpenURL, which 85 // this is an alias of. 86 virtual WebContents* OpenURL(const OpenURLParams& params) = 0; 87 88 // Returns whether to continue a navigation that needs to transfer to a 89 // different process between the load start and commit. 90 virtual bool ShouldTransferNavigation(bool is_main_frame_navigation) = 0; 91 92 // Returns the overridden user agent string if it's set. 93 virtual const blink::UserAgentOverride& GetUserAgentOverride() = 0; 94 95 // Returns the value to use for NavigationEntry::IsOverridingUserAgent() for 96 // a renderer initiated navigation. 97 virtual bool ShouldOverrideUserAgentForRendererInitiatedNavigation() = 0; 98 99 // A RenderFrameHost in the specified |frame_tree_node| started loading a new 100 // document. This corresponds to Blink's notion of the throbber starting. 101 // |to_different_document| will be true unless the load is a fragment 102 // navigation, or triggered by history.pushState/replaceState. 103 virtual void DidStartLoading(FrameTreeNode* frame_tree_node, 104 bool to_different_document) = 0; 105 106 // A document stopped loading. This corresponds to Blink's notion of the 107 // throbber stopping. 108 virtual void DidStopLoading() = 0; 109 110 // The load progress was changed. 111 virtual void DidChangeLoadProgress() = 0; 112 113 // Returns the NavigationThrottles to add to this navigation. Normally these 114 // are defined by the content/ embedder, except in the case of interstitials 115 // where no NavigationThrottles are added to the navigation. 116 virtual std::vector<std::unique_ptr<NavigationThrottle>> 117 CreateThrottlesForNavigation(NavigationHandle* navigation_handle) = 0; 118 119 // Called at the start of the navigation to get opaque data the embedder 120 // wants to see passed to the corresponding URLRequest on the IO thread. 121 // In the case of a navigation to an interstitial, no call will be made to the 122 // embedder and |nullptr| is returned. 123 virtual std::unique_ptr<NavigationUIData> GetNavigationUIData( 124 NavigationHandle* navigation_handle) = 0; 125 126 // Called when a navigation accessed ServiceWorker to check if it should be 127 // handled by the ServiceWorker or not. 128 virtual void OnServiceWorkerAccessed(NavigationHandle* navigation, 129 const GURL& scope, 130 AllowServiceWorkerResult allowed) = 0; 131 132 // Called when a network request issued by this navigation set or read a 133 // cookie. 134 virtual void OnCookiesAccessed(NavigationHandle* navigation, 135 const CookieAccessDetails& details) = 0; 136 137 // Does a global walk of the session history and all committed/pending-commit 138 // origins, and registers origins that match |origin| to their respective 139 // BrowsingInstances. |navigation_request_to_exclude| allows the 140 // NavigationRequest that initiates this process to avoid marking itself as 141 // non-opted-in before it gets the chance to opt-in. 142 virtual void RegisterExistingOriginToPreventOptInIsolation( 143 const url::Origin& origin, 144 NavigationRequest* navigation_request_to_exclude) = 0; 145 }; 146 147 } // namespace content 148 149 #endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATOR_DELEGATE_H_ 150