// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ #define CONTENT_PUBLIC_BROWSER_NAVIGATION_HANDLE_H_ #include #include #include #include "base/memory/safe_ref.h" #include "base/supports_user_data.h" #include "content/common/content_export.h" #include "content/public/browser/frame_type.h" #include "content/public/browser/navigation_handle_timing.h" #include "content/public/browser/navigation_throttle.h" #include "content/public/browser/prerender_trigger_type.h" #include "content/public/browser/reload_type.h" #include "content/public/browser/restore_type.h" #include "content/public/common/referrer.h" #include "net/base/auth.h" #include "net/base/ip_endpoint.h" #include "net/base/isolation_info.h" #include "net/base/net_errors.h" #include "net/dns/public/resolve_error_info.h" #include "net/http/http_response_info.h" #include "services/metrics/public/cpp/ukm_source_id.h" #include "services/network/public/mojom/web_sandbox_flags.mojom-forward.h" #include "third_party/blink/public/common/navigation/impression.h" #include "third_party/blink/public/common/tokens/tokens.h" #include "third_party/blink/public/mojom/loader/referrer.mojom.h" #include "third_party/blink/public/mojom/loader/transferrable_url_loader.mojom-forward.h" #include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h" #include "ui/base/page_transition_types.h" #if BUILDFLAG(IS_ANDROID) #include "base/android/scoped_java_ref.h" #endif class GURL; namespace net { class HttpRequestHeaders; class HttpResponseHeaders; class ProxyServer; } // namespace net namespace perfetto::protos::pbzero { class NavigationHandle; } // namespace perfetto::protos::pbzero namespace content { class CommitDeferringCondition; struct GlobalRenderFrameHostId; struct GlobalRequestID; class NavigationEntry; class NavigationThrottle; class NavigationUIData; class RenderFrameHost; class SiteInstance; class WebContents; // A NavigationHandle tracks information related to a single navigation. // NavigationHandles are provided to several WebContentsObserver methods to // allow observers to track specific navigations. Observers should clear any // references to a NavigationHandle at the time of // WebContentsObserver::DidFinishNavigation, just before the handle is // destroyed. class CONTENT_EXPORT NavigationHandle : public base::SupportsUserData { public: ~NavigationHandle() override = default; // Parameters available at navigation start time ----------------------------- // // These parameters are always available during the navigation. Note that // some may change during navigation (e.g. due to server redirects). // Get a unique ID for this navigation. virtual int64_t GetNavigationId() = 0; // Get the page UKM ID that will be in use once this navigation fully commits // (the eventual value of GetRenderFrameHost()->GetPageUkmSourceId()). virtual ukm::SourceId GetNextPageUkmSourceId() = 0; // The URL the frame is navigating to. This may change during the navigation // when encountering a server redirect. // This URL may not be the same as the virtual URL returned from // WebContents::GetVisibleURL and WebContents::GetLastCommittedURL. For // example, viewing a page's source navigates to the URL of the page, but the // virtual URL is prefixed with "view-source:". // Note: The URL of a NavigationHandle can change over its lifetime. // e.g. URLs might be rewritten by the renderer before being committed. virtual const GURL& GetURL() = 0; // Returns the SiteInstance where the frame being navigated was at the start // of the navigation. If a frame in SiteInstance A navigates a frame in // SiteInstance B to a URL in SiteInstance C, then this returns B. virtual SiteInstance* GetStartingSiteInstance() = 0; // Returns the SiteInstance of the initiator of the navigation. If a frame in // SiteInstance A navigates a frame in SiteInstance B to a URL in SiteInstance // C, then this returns A. virtual SiteInstance* GetSourceSiteInstance() = 0; // Whether the navigation is taking place in a main frame or in a subframe. // This can also return true for navigations in the root of a non-primary // page, so consider whether you want to call IsInPrimaryMainFrame() instead. // See the documentation below for details. The return value remains constant // over the navigation lifetime. virtual bool IsInMainFrame() const = 0; // Whether the navigation is taking place in the main frame of the primary // frame tree. With MPArch (crbug.com/1164280), a WebContents may have // additional frame trees for prerendering pages in addition to the primary // frame tree (holding the page currently shown to the user). The return // value remains constant over the navigation lifetime. virtual bool IsInPrimaryMainFrame() const = 0; // Whether the navigation is taking place in a main frame which does not have // an outer document. For example, this will return true for the primary main // frame and for a prerendered main frame, but false for a . See // documentation for `RenderFrameHost::GetParentOrOuterDocument()` for more // details. virtual bool IsInOutermostMainFrame() = 0; // Prerender2: // Whether the navigation is taking place in the main frame of the // prerendered frame tree. Prerender will create separate frame trees to load // a page in the background, which later then be activated by a separate // prerender page activation navigation in the primary main frame. This // returns false for prerender page activation navigations, which should be // checked by IsPrerenderedPageActivation(). The return value remains // constant over the navigation lifetime. virtual bool IsInPrerenderedMainFrame() = 0; // Prerender2: // Returns true if this navigation will activate a prerendered page. It is // only meaningful to call this after BeginNavigation(). virtual bool IsPrerenderedPageActivation() const = 0; // FencedFrame: // Returns true if the navigation is taking place in a frame in a fenced frame // tree. virtual bool IsInFencedFrameTree() const = 0; // Returns the type of the frame in which this navigation is taking place. virtual FrameType GetNavigatingFrameType() const = 0; // Whether the navigation was initiated by the renderer process. Examples of // renderer-initiated navigations include: // * link click // * changing window.location.href // * redirect via the tag // * using window.history.pushState() or window.history.replaceState() // * using window.history.forward() or window.history.back() // // This method returns false for browser-initiated navigations, including: // * any navigation initiated from the omnibox // * navigations via suggestions in browser UI // * navigations via browser UI: Ctrl-R, refresh/forward/back/home buttons // * any other "explicit" URL navigations, e.g. bookmarks virtual bool IsRendererInitiated() = 0; // Whether the previous document in this frame was same-origin with the new // one created by this navigation. // // |HasCommitted()| must be true before calling this function. // // Note: This doesn't take the initiator of the navigation into consideration. // For instance, a parent (A) can initiate a navigation in its iframe, // replacing document (B) by (C). This methods compare (B) with (C). virtual bool IsSameOrigin() = 0; // Returns the FrameTreeNode ID for the frame in which the navigation is // performed. This ID is browser-global and uniquely identifies a frame that // hosts content. The return value remains constant over the navigation // lifetime. // // However, because of prerender activations, the RenderFrameHost that this // navigation is committed into may later transfer to another FrameTreeNode. // See documentation for RenderFrameHost::GetFrameTreeNodeId() for more // details. virtual int GetFrameTreeNodeId() = 0; // Returns the RenderFrameHost for the parent frame, or nullptr if this // navigation is taking place in the main frame. This value will not change // during a navigation. virtual RenderFrameHost* GetParentFrame() = 0; // Returns the document owning the frame this NavigationHandle is located // in, which will either be a parent (for