OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ |
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ |
7 | 7 |
8 #include "content/public/browser/navigation_handle.h" | 8 #include "content/public/browser/navigation_handle.h" |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" |
12 #include "content/browser/frame_host/render_frame_host_impl.h" | 13 #include "content/browser/frame_host/render_frame_host_impl.h" |
13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/navigation_throttle.h" |
14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 | 19 |
18 class NavigatorDelegate; | 20 class NavigatorDelegate; |
19 struct NavigationRequestInfo; | 21 struct NavigationRequestInfo; |
20 | 22 |
21 // This class keeps track of a single navigation. It is created upon receipt of | 23 // This class keeps track of a single navigation. It is created upon receipt of |
22 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns | 24 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns |
23 // the newly created NavigationHandleImpl as long as the navigation is ongoing. | 25 // the newly created NavigationHandleImpl as long as the navigation is ongoing. |
(...skipping 23 matching lines...) Expand all Loading... |
47 // navigation is ready to commit. The NavigationHandleImpl ownership is then | 49 // navigation is ready to commit. The NavigationHandleImpl ownership is then |
48 // transferred to the RenderFrameHost in which the navigation will commit. | 50 // transferred to the RenderFrameHost in which the navigation will commit. |
49 // | 51 // |
50 // When PlzNavigate is enabled, the NavigationHandleImpl will never be reset | 52 // When PlzNavigate is enabled, the NavigationHandleImpl will never be reset |
51 // following the receipt of a DidStartProvisionalLoad IPC. There are also no | 53 // following the receipt of a DidStartProvisionalLoad IPC. There are also no |
52 // transferring navigations. The other causes of NavigationHandleImpl reset in | 54 // transferring navigations. The other causes of NavigationHandleImpl reset in |
53 // the RenderFrameHost still apply. | 55 // the RenderFrameHost still apply. |
54 class CONTENT_EXPORT NavigationHandleImpl : public NavigationHandle { | 56 class CONTENT_EXPORT NavigationHandleImpl : public NavigationHandle { |
55 public: | 57 public: |
56 static scoped_ptr<NavigationHandleImpl> Create(const GURL& url, | 58 static scoped_ptr<NavigationHandleImpl> Create(const GURL& url, |
57 const bool is_main_frame, | 59 bool is_main_frame, |
58 NavigatorDelegate* delegate); | 60 NavigatorDelegate* delegate); |
59 | |
60 ~NavigationHandleImpl() override; | 61 ~NavigationHandleImpl() override; |
61 | 62 |
62 // NavigationHandle implementation: | 63 // NavigationHandle implementation: |
63 const GURL& GetURL() const override; | 64 const GURL& GetURL() override; |
64 net::Error GetNetErrorCode() const override; | 65 bool IsInMainFrame() override; |
65 bool IsInMainFrame() const override; | 66 bool IsPost() override; |
| 67 const Referrer& GetReferrer() override; |
| 68 bool HasUserGesture() override; |
| 69 ui::PageTransition GetPageTransition() override; |
| 70 bool IsExternalProtocol() override; |
| 71 net::Error GetNetErrorCode() override; |
66 RenderFrameHostImpl* GetRenderFrameHost() override; | 72 RenderFrameHostImpl* GetRenderFrameHost() override; |
67 bool IsSamePage() override; | 73 bool IsSamePage() override; |
68 bool HasCommitted() override; | 74 bool HasCommitted() override; |
69 bool IsErrorPage() override; | 75 bool IsErrorPage() override; |
| 76 void RegisterThrottleForTesting( |
| 77 scoped_ptr<NavigationThrottle> navigation_throttle) override; |
| 78 NavigationThrottle::ThrottleCheckResult CallWillStartRequestForTesting( |
| 79 bool is_post, |
| 80 const Referrer& sanitized_referrer, |
| 81 bool has_user_gesture, |
| 82 ui::PageTransition transition, |
| 83 bool is_external_protocol) override; |
| 84 NavigationThrottle::ThrottleCheckResult CallWillRedirectRequestForTesting( |
| 85 const GURL& new_url, |
| 86 bool new_method_is_post, |
| 87 const GURL& new_referrer_url, |
| 88 bool new_is_external_protocol) override; |
| 89 |
| 90 NavigatorDelegate* delegate() const { return delegate_; } |
70 | 91 |
71 void set_net_error_code(net::Error net_error_code) { | 92 void set_net_error_code(net::Error net_error_code) { |
72 net_error_code_ = net_error_code; | 93 net_error_code_ = net_error_code; |
73 } | 94 } |
74 | 95 |
75 // Returns whether the navigation is currently being transferred from one | 96 // Returns whether the navigation is currently being transferred from one |
76 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC | 97 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC |
77 // for the navigation URL, received in the new RenderFrameHost, should not | 98 // for the navigation URL, received in the new RenderFrameHost, should not |
78 // indicate the start of a new navigation in that case. | 99 // indicate the start of a new navigation in that case. |
79 bool is_transferring() const { return is_transferring_; } | 100 bool is_transferring() const { return is_transferring_; } |
80 void set_is_transferring(bool is_transferring) { | 101 void set_is_transferring(bool is_transferring) { |
81 is_transferring_ = is_transferring; | 102 is_transferring_ = is_transferring; |
82 } | 103 } |
83 | 104 |
| 105 // Called when the URLRequest will start in the network stack. |
| 106 NavigationThrottle::ThrottleCheckResult WillStartRequest( |
| 107 bool is_post, |
| 108 const Referrer& sanitized_referrer, |
| 109 bool has_user_gesture, |
| 110 ui::PageTransition transition, |
| 111 bool is_external_protocol); |
| 112 |
| 113 // Called when the URLRequest will be redirected in the network stack. |
| 114 NavigationThrottle::ThrottleCheckResult WillRedirectRequest( |
| 115 const GURL& new_url, |
| 116 bool new_method_is_post, |
| 117 const GURL& new_referrer_url, |
| 118 bool new_is_external_protocol); |
| 119 |
84 // Called when the navigation was redirected. This will update the |url_| and | 120 // Called when the navigation was redirected. This will update the |url_| and |
85 // inform the delegate. | 121 // inform the delegate. |
86 void DidRedirectNavigation(const GURL& new_url); | 122 void DidRedirectNavigation(const GURL& new_url); |
87 | 123 |
88 // Called when the navigation is ready to be committed in | 124 // Called when the navigation is ready to be committed in |
89 // |render_frame_host|. This will update the |state_| and inform the | 125 // |render_frame_host|. This will update the |state_| and inform the |
90 // delegate. | 126 // delegate. |
91 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); | 127 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); |
92 | 128 |
93 // Called when the navigation was committed in |render_frame_host|. This will | 129 // Called when the navigation was committed in |render_frame_host|. This will |
94 // update the |state_|. | 130 // update the |state_|. |
95 void DidCommitNavigation(bool same_page, | 131 void DidCommitNavigation(bool same_page, |
96 RenderFrameHostImpl* render_frame_host); | 132 RenderFrameHostImpl* render_frame_host); |
97 | 133 |
98 private: | 134 private: |
99 // Used to track the state the navigation is currently in. | 135 // Used to track the state the navigation is currently in. |
100 enum State { | 136 enum State { |
101 DID_START = 0, | 137 INITIAL = 0, |
| 138 WILL_SEND_REQUEST, |
102 READY_TO_COMMIT, | 139 READY_TO_COMMIT, |
103 DID_COMMIT, | 140 DID_COMMIT, |
104 DID_COMMIT_ERROR_PAGE, | 141 DID_COMMIT_ERROR_PAGE, |
105 }; | 142 }; |
106 | 143 |
107 NavigationHandleImpl(const GURL& url, | 144 NavigationHandleImpl(const GURL& url, |
108 const bool is_main_frame, | 145 const bool is_main_frame, |
109 NavigatorDelegate* delegate); | 146 NavigatorDelegate* delegate); |
110 | 147 |
111 // See NavigationHandle for a description of those member variables. | 148 // See NavigationHandle for a description of those member variables. |
112 GURL url_; | 149 GURL url_; |
| 150 const bool is_main_frame_; |
| 151 bool is_post_; |
| 152 Referrer sanitized_referrer_; |
| 153 bool has_user_gesture_; |
| 154 ui::PageTransition transition_; |
| 155 bool is_external_protocol_; |
113 net::Error net_error_code_; | 156 net::Error net_error_code_; |
114 State state_; | |
115 const bool is_main_frame_; | |
116 RenderFrameHostImpl* render_frame_host_; | 157 RenderFrameHostImpl* render_frame_host_; |
117 bool is_same_page_; | 158 bool is_same_page_; |
118 | 159 |
| 160 // The state the navigation is in. |
| 161 State state_; |
| 162 |
119 // Whether the navigation is in the middle of a transfer. Set to false when | 163 // Whether the navigation is in the middle of a transfer. Set to false when |
120 // the DidStartProvisionalLoad is received from the new renderer. | 164 // the DidStartProvisionalLoad is received from the new renderer. |
121 bool is_transferring_; | 165 bool is_transferring_; |
122 | 166 |
123 // The delegate that should be notified about events related to this | 167 // The delegate that should be notified about events related to this |
124 // navigation. | 168 // navigation. |
125 NavigatorDelegate* delegate_; | 169 NavigatorDelegate* delegate_; |
126 | 170 |
| 171 // A list of Throttles registered for this navigation. |
| 172 ScopedVector<NavigationThrottle> throttles_; |
| 173 |
127 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); | 174 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); |
128 }; | 175 }; |
129 | 176 |
130 } // namespace content | 177 } // namespace content |
131 | 178 |
132 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ | 179 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ |
OLD | NEW |