1 // Copyright 2015 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.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
8 #include "content/public/browser/navigation_handle.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "content/common/content_export.h"
14 #include "content/public/browser/navigation_throttle.h"
19 class NavigatorDelegate
;
20 struct NavigationRequestInfo
;
22 // This class keeps track of a single navigation. It is created upon receipt of
23 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns
24 // the newly created NavigationHandleImpl as long as the navigation is ongoing.
25 // The NavigationHandleImpl in the RenderFrameHost will be reset when the
26 // navigation stops, that is if one of the following events happen:
27 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new
28 // navigation (see below for special cases where the DidStartProvisionalLoad
29 // message does not indicate the start of a new navigation).
30 // - The RenderFrameHost stops loading.
31 // - The RenderFrameHost receives a DidDropNavigation IPC.
33 // When the navigation encounters an error, the DidStartProvisionalLoad marking
34 // the start of the load of the error page will not be considered as marking a
35 // new navigation. It will not reset the NavigationHandleImpl in the
38 // If the navigation needs a cross-site transfer, then the NavigationHandleImpl
39 // will briefly be held by the RenderFrameHostManager, until a suitable
40 // RenderFrameHost for the navigation has been found. The ownership of the
41 // NavigationHandleImpl will then be transferred to the new RenderFrameHost.
42 // The DidStartProvisionalLoad received by the new RenderFrameHost for the
43 // transferring navigation will not reset the NavigationHandleImpl, as it does
44 // not mark the start of a new navigation.
46 // PlzNavigate: the NavigationHandleImpl is created just after creating a new
47 // NavigationRequest. It is then owned by the NavigationRequest until the
48 // navigation is ready to commit. The NavigationHandleImpl ownership is then
49 // transferred to the RenderFrameHost in which the navigation will commit.
51 // When PlzNavigate is enabled, the NavigationHandleImpl will never be reset
52 // following the receipt of a DidStartProvisionalLoad IPC. There are also no
53 // transferring navigations. The other causes of NavigationHandleImpl reset in
54 // the RenderFrameHost still apply.
55 class CONTENT_EXPORT NavigationHandleImpl
: public NavigationHandle
{
57 static scoped_ptr
<NavigationHandleImpl
> Create(const GURL
& url
,
59 NavigatorDelegate
* delegate
);
60 ~NavigationHandleImpl() override
;
62 // NavigationHandle implementation:
63 const GURL
& GetURL() override
;
64 bool IsInMainFrame() override
;
65 bool IsPost() override
;
66 const Referrer
& GetReferrer() override
;
67 bool HasUserGesture() override
;
68 ui::PageTransition
GetPageTransition() override
;
69 bool IsExternalProtocol() override
;
70 net::Error
GetNetErrorCode() override
;
71 bool IsSamePage() override
;
72 bool HasCommittedDocument() override
;
73 bool HasCommittedErrorPage() override
;
74 void RegisterThrottleForTesting(
75 scoped_ptr
<NavigationThrottle
> navigation_throttle
) override
;
76 NavigationThrottle::ThrottleCheckResult
CallWillStartRequestForTesting(
78 const Referrer
& sanitized_referrer
,
79 bool has_user_gesture
,
80 ui::PageTransition transition
,
81 bool is_external_protocol
) override
;
82 NavigationThrottle::ThrottleCheckResult
CallWillRedirectRequestForTesting(
84 bool new_method_is_post
,
85 const GURL
& new_referrer_url
,
86 bool new_is_external_protocol
) override
;
88 NavigatorDelegate
* delegate() const { return delegate_
; }
90 void set_net_error_code(net::Error net_error_code
) {
91 net_error_code_
= net_error_code
;
94 // Returns whether the navigation is currently being transferred from one
95 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC
96 // for the navigation URL, received in the new RenderFrameHost, should not
97 // indicate the start of a new navigation in that case.
98 bool is_transferring() const { return is_transferring_
; }
99 void set_is_transferring(bool is_transferring
) {
100 is_transferring_
= is_transferring
;
103 // Called when the URLRequest will start in the network stack.
104 NavigationThrottle::ThrottleCheckResult
WillStartRequest(
106 const Referrer
& sanitized_referrer
,
107 bool has_user_gesture
,
108 ui::PageTransition transition
,
109 bool is_external_protocol
);
111 // Called when the URLRequest will be redirected in the network stack.
112 NavigationThrottle::ThrottleCheckResult
WillRedirectRequest(
114 bool new_method_is_post
,
115 const GURL
& new_referrer_url
,
116 bool new_is_external_protocol
);
118 // Called when the navigation was redirected. This will update the |url_| and
119 // inform the delegate.
120 void DidRedirectNavigation(const GURL
& new_url
);
122 // Called when the navigation was committed. This will update the |state_|
123 // and inform the delegate,
124 void DidCommitNavigation(bool same_page
);
127 // Used to track the state the navigation is currently in.
132 DID_COMMIT_ERROR_PAGE
,
135 NavigationHandleImpl(const GURL
& url
,
136 const bool is_main_frame
,
137 NavigatorDelegate
* delegate
);
139 // See NavigationHandle for a description of those member variables.
141 const bool is_main_frame_
;
143 Referrer sanitized_referrer_
;
144 bool has_user_gesture_
;
145 ui::PageTransition transition_
;
146 bool is_external_protocol_
;
147 net::Error net_error_code_
;
150 // The state the navigation is in.
153 // Whether the navigation is in the middle of a transfer. Set to false when
154 // the DidStartProvisionalLoad is received from the new renderer.
155 bool is_transferring_
;
157 // The delegate that should be notified about events related to this
159 NavigatorDelegate
* delegate_
;
161 // A list of Throttles registered for this navigation.
162 ScopedVector
<NavigationThrottle
> throttles_
;
164 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl
);
167 } // namespace content
169 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_