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 <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "content/browser/frame_host/frame_tree_node.h" | 16 #include "content/browser/frame_host/frame_tree_node.h" |
17 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 #include "content/public/browser/global_request_id.h" | |
19 #include "content/public/browser/navigation_data.h" | 20 #include "content/public/browser/navigation_data.h" |
20 #include "content/public/browser/navigation_throttle.h" | 21 #include "content/public/browser/navigation_throttle.h" |
21 #include "content/public/browser/ssl_status.h" | 22 #include "content/public/browser/ssl_status.h" |
22 #include "content/public/common/request_context_type.h" | 23 #include "content/public/common/request_context_type.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
25 struct FrameHostMsg_DidCommitProvisionalLoad_Params; | 26 struct FrameHostMsg_DidCommitProvisionalLoad_Params; |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 class NavigatorDelegate; | 30 class NavigatorDelegate; |
30 class ResourceRequestBodyImpl; | 31 class ResourceRequestBodyImpl; |
32 class SiteInstance; | |
31 | 33 |
32 // This class keeps track of a single navigation. It is created upon receipt of | 34 // This class keeps track of a single navigation. It is created upon receipt of |
33 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns | 35 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns |
34 // the newly created NavigationHandleImpl as long as the navigation is ongoing. | 36 // the newly created NavigationHandleImpl as long as the navigation is ongoing. |
35 // The NavigationHandleImpl in the RenderFrameHost will be reset when the | 37 // The NavigationHandleImpl in the RenderFrameHost will be reset when the |
36 // navigation stops, that is if one of the following events happen: | 38 // navigation stops, that is if one of the following events happen: |
37 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new | 39 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new |
38 // navigation (see below for special cases where the DidStartProvisionalLoad | 40 // navigation (see below for special cases where the DidStartProvisionalLoad |
39 // message does not indicate the start of a new navigation). | 41 // message does not indicate the start of a new navigation). |
40 // - The RenderFrameHost stops loading. | 42 // - The RenderFrameHost stops loading. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 146 |
145 // Returns whether the navigation is currently being transferred from one | 147 // Returns whether the navigation is currently being transferred from one |
146 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC | 148 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC |
147 // for the navigation URL, received in the new RenderFrameHost, should not | 149 // for the navigation URL, received in the new RenderFrameHost, should not |
148 // indicate the start of a new navigation in that case. | 150 // indicate the start of a new navigation in that case. |
149 bool is_transferring() const { return is_transferring_; } | 151 bool is_transferring() const { return is_transferring_; } |
150 void set_is_transferring(bool is_transferring) { | 152 void set_is_transferring(bool is_transferring) { |
151 is_transferring_ = is_transferring; | 153 is_transferring_ = is_transferring; |
152 } | 154 } |
153 | 155 |
154 // Updates the RenderFrameHost that is about to commit the navigation. This | |
155 // is used during transfer navigations. | |
156 void set_render_frame_host(RenderFrameHostImpl* render_frame_host) { | |
157 render_frame_host_ = render_frame_host; | |
158 } | |
159 | |
160 // Returns the POST body associated with this navigation. This will be | 156 // Returns the POST body associated with this navigation. This will be |
161 // null for GET and/or other non-POST requests (or if a response to a POST | 157 // null for GET and/or other non-POST requests (or if a response to a POST |
162 // request was a redirect that changed the method to GET - for example 302). | 158 // request was a redirect that changed the method to GET - for example 302). |
163 const scoped_refptr<ResourceRequestBodyImpl>& resource_request_body() const { | 159 const scoped_refptr<ResourceRequestBodyImpl>& resource_request_body() const { |
164 return resource_request_body_; | 160 return resource_request_body_; |
165 } | 161 } |
166 | 162 |
167 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> | 163 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> |
168 ThrottleChecksFinishedCallback; | 164 ThrottleChecksFinishedCallback; |
169 | 165 |
(...skipping 21 matching lines...) Expand all Loading... | |
191 bool new_is_external_protocol, | 187 bool new_is_external_protocol, |
192 scoped_refptr<net::HttpResponseHeaders> response_headers, | 188 scoped_refptr<net::HttpResponseHeaders> response_headers, |
193 const ThrottleChecksFinishedCallback& callback); | 189 const ThrottleChecksFinishedCallback& callback); |
194 | 190 |
195 // Called when the URLRequest has delivered response headers and metadata. | 191 // Called when the URLRequest has delivered response headers and metadata. |
196 // |callback| will be called when all throttle checks have completed, | 192 // |callback| will be called when all throttle checks have completed, |
197 // allowing the caller to cancel the navigation or let it proceed. | 193 // allowing the caller to cancel the navigation or let it proceed. |
198 // NavigationHandle will not call |callback| with a result of DEFER. | 194 // NavigationHandle will not call |callback| with a result of DEFER. |
199 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called | 195 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called |
200 // with |render_frame_host| and |response_headers| just before calling | 196 // with |render_frame_host| and |response_headers| just before calling |
201 // |callback|. | 197 // |callback|. Should a transfer navigation happen, |transfer_callback| will |
198 // be run on the IO thread. | |
199 // PlzNavigate: transfer navigations are not possible. | |
202 void WillProcessResponse( | 200 void WillProcessResponse( |
203 RenderFrameHostImpl* render_frame_host, | 201 RenderFrameHostImpl* render_frame_host, |
204 scoped_refptr<net::HttpResponseHeaders> response_headers, | 202 scoped_refptr<net::HttpResponseHeaders> response_headers, |
205 const SSLStatus& ssl_status, | 203 const SSLStatus& ssl_status, |
204 const GlobalRequestID& request_id, | |
205 bool should_replace_current_entry, | |
206 bool is_download, | |
207 bool is_stream, | |
208 const base::Closure& transfer_callback, | |
206 const ThrottleChecksFinishedCallback& callback); | 209 const ThrottleChecksFinishedCallback& callback); |
207 | 210 |
208 // Returns the FrameTreeNode this navigation is happening in. | 211 // Returns the FrameTreeNode this navigation is happening in. |
209 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } | 212 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } |
210 | 213 |
211 // Called when the navigation is ready to be committed in | 214 // Called when the navigation is ready to be committed in |
212 // |render_frame_host|. This will update the |state_| and inform the | 215 // |render_frame_host|. This will update the |state_| and inform the |
213 // delegate. | 216 // delegate. |
214 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); | 217 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); |
215 | 218 |
216 // Called when the navigation was committed in |render_frame_host|. This will | 219 // Called when the navigation was committed in |render_frame_host|. This will |
217 // update the |state_|. | 220 // update the |state_|. |
218 void DidCommitNavigation( | 221 void DidCommitNavigation( |
219 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 222 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
220 bool same_page, | 223 bool same_page, |
221 RenderFrameHostImpl* render_frame_host); | 224 RenderFrameHostImpl* render_frame_host); |
222 | 225 |
223 // Called during commit. Takes ownership of the embedder's NavigationData | 226 // Called during commit. Takes ownership of the embedder's NavigationData |
224 // instance. This NavigationData may have been cloned prior to being added | 227 // instance. This NavigationData may have been cloned prior to being added |
225 // here. | 228 // here. |
226 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) { | 229 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) { |
227 navigation_data_ = std::move(navigation_data); | 230 navigation_data_ = std::move(navigation_data); |
228 } | 231 } |
229 | 232 |
230 SSLStatus ssl_status() { return ssl_status_; } | 233 SSLStatus ssl_status() { return ssl_status_; } |
231 | 234 |
235 const GlobalRequestID& request_id() const { return request_id_; } | |
Charlie Reis
2016/09/16 21:19:26
Please comment about the timeline that this is val
clamy
2016/09/20 15:57:22
Done. Added a DCHECK as well. As explained in the
| |
236 | |
237 // Called when the navigation is transferred to a SiteInstance. | |
238 void TransferToSiteInstance(SiteInstance* site_instance); | |
239 | |
240 // Called when a RenderFrameHost has been created for the SiteInstance the | |
241 // navigation is transferred to. | |
242 void TransferToRenderFrameHost(RenderFrameHostImpl* render_frame_host); | |
243 | |
232 private: | 244 private: |
233 friend class NavigationHandleImplTest; | 245 friend class NavigationHandleImplTest; |
234 | 246 |
235 // Used to track the state the navigation is currently in. | 247 // Used to track the state the navigation is currently in. |
236 enum State { | 248 enum State { |
237 INITIAL = 0, | 249 INITIAL = 0, |
238 WILL_SEND_REQUEST, | 250 WILL_SEND_REQUEST, |
239 DEFERRING_START, | 251 DEFERRING_START, |
240 WILL_REDIRECT_REQUEST, | 252 WILL_REDIRECT_REQUEST, |
241 DEFERRING_REDIRECT, | 253 DEFERRING_REDIRECT, |
(...skipping 10 matching lines...) Expand all Loading... | |
252 bool is_renderer_initiated, | 264 bool is_renderer_initiated, |
253 bool is_synchronous, | 265 bool is_synchronous, |
254 bool is_srcdoc, | 266 bool is_srcdoc, |
255 const base::TimeTicks& navigation_start, | 267 const base::TimeTicks& navigation_start, |
256 int pending_nav_entry_id); | 268 int pending_nav_entry_id); |
257 | 269 |
258 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest(); | 270 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest(); |
259 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest(); | 271 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest(); |
260 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse(); | 272 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse(); |
261 | 273 |
274 // Called when WillProcessResponse checks are done, to find the final | |
275 // RenderFrameHost for the navigation. Returns true if the navigation should | |
Charlie Reis
2016/09/16 21:19:26
Can you mention a case when it would return false?
clamy
2016/09/20 15:57:22
Updated the comment following the naming change su
| |
276 // proceed. | |
277 bool FindFinalRenderFrameHost(); | |
278 | |
279 // Check whether the navigation should be transferred. Returns false if the | |
280 // transfer attempt results in the destruction of this NavigationHandle. | |
281 bool MaybeTransferAndProceed(); | |
282 | |
262 // Helper function to run and reset the |complete_callback_|. This marks the | 283 // Helper function to run and reset the |complete_callback_|. This marks the |
263 // end of a round of NavigationThrottleChecks. | 284 // end of a round of NavigationThrottleChecks. |
264 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result); | 285 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result); |
265 | 286 |
266 // Used in tests. | 287 // Used in tests. |
267 State state() const { return state_; } | 288 State state() const { return state_; } |
268 | 289 |
269 // Populates |throttles_| with the throttles for this navigation. | 290 // Populates |throttles_| with the throttles for this navigation. |
270 void RegisterNavigationThrottles(); | 291 void RegisterNavigationThrottles(); |
271 | 292 |
272 // See NavigationHandle for a description of those member variables. | 293 // See NavigationHandle for a description of those member variables. |
273 GURL url_; | 294 GURL url_; |
274 Referrer sanitized_referrer_; | 295 Referrer sanitized_referrer_; |
275 bool has_user_gesture_; | 296 bool has_user_gesture_; |
276 ui::PageTransition transition_; | 297 ui::PageTransition transition_; |
277 bool is_external_protocol_; | 298 bool is_external_protocol_; |
278 net::Error net_error_code_; | 299 net::Error net_error_code_; |
279 RenderFrameHostImpl* render_frame_host_; | 300 RenderFrameHostImpl* render_frame_host_; |
280 const bool is_renderer_initiated_; | 301 const bool is_renderer_initiated_; |
281 bool is_same_page_; | 302 bool is_same_page_; |
282 const bool is_synchronous_; | 303 const bool is_synchronous_; |
283 const bool is_srcdoc_; | 304 const bool is_srcdoc_; |
284 bool was_redirected_; | 305 bool was_redirected_; |
285 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 306 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
286 | 307 |
308 // The original url of the navigation. This may differ from |url_| if the | |
309 // navigation encounters redirects. | |
310 const GURL original_url_; | |
311 | |
287 // The HTTP method used for the navigation. | 312 // The HTTP method used for the navigation. |
288 std::string method_; | 313 std::string method_; |
289 | 314 |
290 // The POST body associated with this navigation. This will be null for GET | 315 // The POST body associated with this navigation. This will be null for GET |
291 // and/or other non-POST requests (or if a response to a POST request was a | 316 // and/or other non-POST requests (or if a response to a POST request was a |
292 // redirect that changed the method to GET - for example 302). | 317 // redirect that changed the method to GET - for example 302). |
293 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; | 318 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; |
294 | 319 |
295 // The state the navigation is in. | 320 // The state the navigation is in. |
296 State state_; | 321 State state_; |
(...skipping 21 matching lines...) Expand all Loading... | |
318 RequestContextType request_context_type_; | 343 RequestContextType request_context_type_; |
319 | 344 |
320 // This callback will be run when all throttle checks have been performed. | 345 // This callback will be run when all throttle checks have been performed. |
321 ThrottleChecksFinishedCallback complete_callback_; | 346 ThrottleChecksFinishedCallback complete_callback_; |
322 | 347 |
323 // Embedder data tied to this navigation. | 348 // Embedder data tied to this navigation. |
324 std::unique_ptr<NavigationData> navigation_data_; | 349 std::unique_ptr<NavigationData> navigation_data_; |
325 | 350 |
326 SSLStatus ssl_status_; | 351 SSLStatus ssl_status_; |
327 | 352 |
353 // The id of the URLRequest tied to this navigation. | |
354 GlobalRequestID request_id_; | |
355 | |
356 // Whether the current NavigationEntry should be replaced upon commit. | |
357 bool should_replace_current_entry_; | |
Charlie Reis
2016/09/16 21:19:26
I'm curious, why did these become necessary in the
clamy
2016/09/20 15:57:22
Most of them are data that was contained in the Cr
Charlie Reis
2016/09/21 03:31:47
CrossSiteTransferringRequest only had the GlobalRe
| |
358 | |
359 // The chain of redirects. | |
360 std::vector<GURL> redirect_chain_; | |
361 | |
362 // A callback to run on the IO thread if the navigation transfers. | |
363 base::Closure transfer_callback_; | |
364 | |
365 // Whether the navigation ended up being a download or a stream. | |
366 bool is_download_; | |
367 bool is_stream_; | |
368 | |
369 base::WeakPtrFactory<NavigationHandleImpl> weak_factory_; | |
370 | |
328 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); | 371 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); |
329 }; | 372 }; |
330 | 373 |
331 } // namespace content | 374 } // namespace content |
332 | 375 |
333 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ | 376 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ |
OLD | NEW |