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 "content/common/content_export.h"
17 class NavigatorDelegate
;
18 struct NavigationRequestInfo
;
20 // This class keeps track of a single navigation. It is created upon receipt of
21 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns
22 // the newly created NavigationHandleImpl as long as the navigation is ongoing.
23 // The NavigationHandleImpl in the RenderFrameHost will be reset when the
24 // navigation stops, that is if one of the following events happen:
25 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new
26 // navigation (see below for special cases where the DidStartProvisionalLoad
27 // message does not indicate the start of a new navigation).
28 // - The RenderFrameHost stops loading.
29 // - The RenderFrameHost receives a DidDropNavigation IPC.
31 // When the navigation encounters an error, the DidStartProvisionalLoad marking
32 // the start of the load of the error page will not be considered as marking a
33 // new navigation. It will not reset the NavigationHandleImpl in the
36 // If the navigation needs a cross-site transfer, then the NavigationHandleImpl
37 // will briefly be held by the RenderFrameHostManager, until a suitable
38 // RenderFrameHost for the navigation has been found. The ownership of the
39 // NavigationHandleImpl will then be transferred to the new RenderFrameHost.
40 // The DidStartProvisionalLoad received by the new RenderFrameHost for the
41 // transferring navigation will not reset the NavigationHandleImpl, as it does
42 // not mark the start of a new navigation.
44 // PlzNavigate: the NavigationHandleImpl is created just after creating a new
45 // NavigationRequest. It is then owned by the NavigationRequest until the
46 // navigation is ready to commit. The NavigationHandleImpl ownership is then
47 // transferred to the RenderFrameHost in which the navigation will commit.
49 // When PlzNavigate is enabled, the NavigationHandleImpl will never be reset
50 // following the receipt of a DidStartProvisionalLoad IPC. There are also no
51 // transferring navigations. The other causes of NavigationHandleImpl reset in
52 // the RenderFrameHost still apply.
53 class CONTENT_EXPORT NavigationHandleImpl
: public NavigationHandle
{
55 static scoped_ptr
<NavigationHandleImpl
> Create(const GURL
& url
,
56 const bool is_main_frame
,
57 NavigatorDelegate
* delegate
);
59 ~NavigationHandleImpl() override
;
61 // NavigationHandle implementation:
62 const GURL
& GetURL() const override
;
63 net::Error
GetNetErrorCode() const override
;
64 bool IsInMainFrame() const override
;
65 bool HasCommittedDocument() const override
;
66 bool HasCommittedErrorPage() const override
;
68 void set_net_error_code(net::Error net_error_code
) {
69 net_error_code_
= net_error_code
;
72 // Returns whether the navigation is currently being transferred from one
73 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC
74 // for the navigation URL, received in the new RenderFrameHost, should not
75 // indicate the start of a new navigation in that case.
76 bool is_transferring() const { return is_transferring_
; }
77 void set_is_transferring(bool is_transferring
) {
78 is_transferring_
= is_transferring
;
81 // Called when the navigation was redirected. This will update the |url_| and
82 // inform the delegate.
83 void DidRedirectNavigation(const GURL
& new_url
);
85 // Called when the navigation was committed. This will update the |state_|
86 // and inform the delegate,
87 void DidCommitNavigation();
90 // Used to track the state the navigation is currently in.
94 DID_COMMIT_ERROR_PAGE
,
97 NavigationHandleImpl(const GURL
& url
,
98 const bool is_main_frame
,
99 NavigatorDelegate
* delegate
);
101 // See NavigationHandle for a description of those member variables.
103 net::Error net_error_code_
;
105 const bool is_main_frame_
;
107 // Whether the navigation is in the middle of a transfer. Set to false when
108 // the DidStartProvisionalLoad is received from the new renderer.
109 bool is_transferring_
;
111 // The delegate that should be notified about events related to this
113 NavigatorDelegate
* delegate_
;
115 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl
);
118 } // namespace content
120 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_