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 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "content/browser/frame_host/frame_tree_node.h" | 17 #include "content/browser/frame_host/frame_tree_node.h" |
18 #include "content/browser/frame_host/render_frame_host_impl.h" | 18 #include "content/browser/frame_host/render_frame_host_impl.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 #include "content/public/browser/global_request_id.h" | |
20 #include "content/public/browser/navigation_data.h" | 21 #include "content/public/browser/navigation_data.h" |
21 #include "content/public/browser/navigation_throttle.h" | 22 #include "content/public/browser/navigation_throttle.h" |
22 #include "content/public/browser/ssl_status.h" | 23 #include "content/public/browser/ssl_status.h" |
23 #include "content/public/common/request_context_type.h" | 24 #include "content/public/common/request_context_type.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
26 struct FrameHostMsg_DidCommitProvisionalLoad_Params; | 27 struct FrameHostMsg_DidCommitProvisionalLoad_Params; |
27 | 28 |
28 namespace content { | 29 namespace content { |
29 | 30 |
30 class NavigatorDelegate; | 31 class NavigatorDelegate; |
31 class ResourceRequestBodyImpl; | 32 class ResourceRequestBodyImpl; |
33 class SiteInstance; | |
32 | 34 |
33 // This class keeps track of a single navigation. It is created upon receipt of | 35 // This class keeps track of a single navigation. It is created upon receipt of |
34 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns | 36 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns |
35 // the newly created NavigationHandleImpl as long as the navigation is ongoing. | 37 // the newly created NavigationHandleImpl as long as the navigation is ongoing. |
36 // The NavigationHandleImpl in the RenderFrameHost will be reset when the | 38 // The NavigationHandleImpl in the RenderFrameHost will be reset when the |
37 // navigation stops, that is if one of the following events happen: | 39 // navigation stops, that is if one of the following events happen: |
38 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new | 40 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new |
39 // navigation (see below for special cases where the DidStartProvisionalLoad | 41 // navigation (see below for special cases where the DidStartProvisionalLoad |
40 // message does not indicate the start of a new navigation). | 42 // message does not indicate the start of a new navigation). |
41 // - The RenderFrameHost stops loading. | 43 // - The RenderFrameHost stops loading. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 bool new_is_external_protocol, | 196 bool new_is_external_protocol, |
195 scoped_refptr<net::HttpResponseHeaders> response_headers, | 197 scoped_refptr<net::HttpResponseHeaders> response_headers, |
196 const ThrottleChecksFinishedCallback& callback); | 198 const ThrottleChecksFinishedCallback& callback); |
197 | 199 |
198 // Called when the URLRequest has delivered response headers and metadata. | 200 // Called when the URLRequest has delivered response headers and metadata. |
199 // |callback| will be called when all throttle checks have completed, | 201 // |callback| will be called when all throttle checks have completed, |
200 // allowing the caller to cancel the navigation or let it proceed. | 202 // allowing the caller to cancel the navigation or let it proceed. |
201 // NavigationHandle will not call |callback| with a result of DEFER. | 203 // NavigationHandle will not call |callback| with a result of DEFER. |
202 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called | 204 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called |
203 // with |render_frame_host| and |response_headers| just before calling | 205 // with |render_frame_host| and |response_headers| just before calling |
204 // |callback|. | 206 // |callback|. Should a transfer navigation happen, |transfer_callback| will |
207 // be run on the IO thread. | |
208 // PlzNavigate: transfer navigations are not possible. | |
205 void WillProcessResponse( | 209 void WillProcessResponse( |
206 RenderFrameHostImpl* render_frame_host, | 210 RenderFrameHostImpl* render_frame_host, |
207 scoped_refptr<net::HttpResponseHeaders> response_headers, | 211 scoped_refptr<net::HttpResponseHeaders> response_headers, |
208 const SSLStatus& ssl_status, | 212 const SSLStatus& ssl_status, |
213 const GlobalRequestID& request_id, | |
214 bool should_replace_current_entry, | |
215 bool is_download, | |
216 bool is_stream, | |
217 const base::Closure& transfer_callback, | |
209 const ThrottleChecksFinishedCallback& callback); | 218 const ThrottleChecksFinishedCallback& callback); |
210 | 219 |
211 // Returns the FrameTreeNode this navigation is happening in. | 220 // Returns the FrameTreeNode this navigation is happening in. |
212 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } | 221 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } |
213 | 222 |
214 // Called when the navigation is ready to be committed in | 223 // Called when the navigation is ready to be committed in |
215 // |render_frame_host|. This will update the |state_| and inform the | 224 // |render_frame_host|. This will update the |state_| and inform the |
216 // delegate. | 225 // delegate. |
217 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); | 226 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); |
218 | 227 |
219 // Called when the navigation was committed in |render_frame_host|. This will | 228 // Called when the navigation was committed in |render_frame_host|. This will |
220 // update the |state_|. | 229 // update the |state_|. |
221 void DidCommitNavigation( | 230 void DidCommitNavigation( |
222 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 231 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
223 bool same_page, | 232 bool same_page, |
224 RenderFrameHostImpl* render_frame_host); | 233 RenderFrameHostImpl* render_frame_host); |
225 | 234 |
226 // Called during commit. Takes ownership of the embedder's NavigationData | 235 // Called during commit. Takes ownership of the embedder's NavigationData |
227 // instance. This NavigationData may have been cloned prior to being added | 236 // instance. This NavigationData may have been cloned prior to being added |
228 // here. | 237 // here. |
229 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) { | 238 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) { |
230 navigation_data_ = std::move(navigation_data); | 239 navigation_data_ = std::move(navigation_data); |
231 } | 240 } |
232 | 241 |
233 SSLStatus ssl_status() { return ssl_status_; } | 242 SSLStatus ssl_status() { return ssl_status_; } |
234 | 243 |
244 // This is valid after the network response has started. | |
245 // TODO(clamy): See if this can be initialized earlier if needed by | |
246 // non-transfer code. There may some issue in PlzNavigate, where | |
nasko
2016/09/22 22:44:55
nit: "There may some issue in PlzNavigate" doesn't
clamy
2016/09/26 12:20:32
Done.
| |
247 // WillStartRequest will be called before starting a request on the IO thread. | |
248 const GlobalRequestID& request_id() const { | |
249 DCHECK_GE(state_, WILL_PROCESS_RESPONSE); | |
250 return request_id_; | |
251 } | |
252 | |
253 // Called when the navigation is transferred to a different renderer. | |
254 void Transfer(); | |
255 | |
235 private: | 256 private: |
236 friend class NavigationHandleImplTest; | 257 friend class NavigationHandleImplTest; |
237 | 258 |
238 // Used to track the state the navigation is currently in. | 259 // Used to track the state the navigation is currently in. |
239 enum State { | 260 enum State { |
240 INITIAL = 0, | 261 INITIAL = 0, |
241 WILL_SEND_REQUEST, | 262 WILL_SEND_REQUEST, |
242 DEFERRING_START, | 263 DEFERRING_START, |
243 WILL_REDIRECT_REQUEST, | 264 WILL_REDIRECT_REQUEST, |
244 DEFERRING_REDIRECT, | 265 DEFERRING_REDIRECT, |
(...skipping 10 matching lines...) Expand all Loading... | |
255 bool is_renderer_initiated, | 276 bool is_renderer_initiated, |
256 bool is_synchronous, | 277 bool is_synchronous, |
257 bool is_srcdoc, | 278 bool is_srcdoc, |
258 const base::TimeTicks& navigation_start, | 279 const base::TimeTicks& navigation_start, |
259 int pending_nav_entry_id); | 280 int pending_nav_entry_id); |
260 | 281 |
261 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest(); | 282 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest(); |
262 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest(); | 283 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest(); |
263 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse(); | 284 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse(); |
264 | 285 |
286 // Called when WillProcessResponse checks are done, to find the final | |
287 // RenderFrameHost for the navigation. Checks whether the navigation should be | |
288 // transferred. Returns false if the transfer attempt results in the | |
289 // destruction of this NavigationHandle and the navigation should no longer | |
290 // proceed. This can happen when the RenderFrameHostManager determines a | |
291 // transfer is needed, but WebContentsDelegate::ShouldTransferNavigation | |
292 // returns false. | |
293 bool MaybeTransferAndProceed(); | |
294 | |
295 // Helper method for MaybeTransferAndProceed. Returns false if the transfer | |
296 // attempt results in the destruction of this NavigationHandle. | |
297 bool MaybeTransferAndProceedInternal(); | |
298 | |
265 // Helper function to run and reset the |complete_callback_|. This marks the | 299 // Helper function to run and reset the |complete_callback_|. This marks the |
266 // end of a round of NavigationThrottleChecks. | 300 // end of a round of NavigationThrottleChecks. |
267 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result); | 301 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result); |
268 | 302 |
269 // Used in tests. | 303 // Used in tests. |
270 State state() const { return state_; } | 304 State state() const { return state_; } |
271 | 305 |
272 // Populates |throttles_| with the throttles for this navigation. | 306 // Populates |throttles_| with the throttles for this navigation. |
273 void RegisterNavigationThrottles(); | 307 void RegisterNavigationThrottles(); |
274 | 308 |
275 // See NavigationHandle for a description of those member variables. | 309 // See NavigationHandle for a description of those member variables. |
276 GURL url_; | 310 GURL url_; |
277 Referrer sanitized_referrer_; | 311 Referrer sanitized_referrer_; |
278 bool has_user_gesture_; | 312 bool has_user_gesture_; |
279 ui::PageTransition transition_; | 313 ui::PageTransition transition_; |
280 bool is_external_protocol_; | 314 bool is_external_protocol_; |
281 net::Error net_error_code_; | 315 net::Error net_error_code_; |
282 RenderFrameHostImpl* render_frame_host_; | 316 RenderFrameHostImpl* render_frame_host_; |
283 const bool is_renderer_initiated_; | 317 const bool is_renderer_initiated_; |
284 bool is_same_page_; | 318 bool is_same_page_; |
285 const bool is_synchronous_; | 319 const bool is_synchronous_; |
286 const bool is_srcdoc_; | 320 const bool is_srcdoc_; |
287 bool was_redirected_; | 321 bool was_redirected_; |
288 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 322 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
289 | 323 |
324 // The original url of the navigation. This may differ from |url_| if the | |
325 // navigation encounters redirects. | |
326 const GURL original_url_; | |
327 | |
290 // The HTTP method used for the navigation. | 328 // The HTTP method used for the navigation. |
291 std::string method_; | 329 std::string method_; |
292 | 330 |
293 // The POST body associated with this navigation. This will be null for GET | 331 // The POST body associated with this navigation. This will be null for GET |
294 // and/or other non-POST requests (or if a response to a POST request was a | 332 // and/or other non-POST requests (or if a response to a POST request was a |
295 // redirect that changed the method to GET - for example 302). | 333 // redirect that changed the method to GET - for example 302). |
296 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; | 334 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; |
297 | 335 |
298 // The state the navigation is in. | 336 // The state the navigation is in. |
299 State state_; | 337 State state_; |
(...skipping 21 matching lines...) Expand all Loading... | |
321 RequestContextType request_context_type_; | 359 RequestContextType request_context_type_; |
322 | 360 |
323 // This callback will be run when all throttle checks have been performed. | 361 // This callback will be run when all throttle checks have been performed. |
324 ThrottleChecksFinishedCallback complete_callback_; | 362 ThrottleChecksFinishedCallback complete_callback_; |
325 | 363 |
326 // Embedder data tied to this navigation. | 364 // Embedder data tied to this navigation. |
327 std::unique_ptr<NavigationData> navigation_data_; | 365 std::unique_ptr<NavigationData> navigation_data_; |
328 | 366 |
329 SSLStatus ssl_status_; | 367 SSLStatus ssl_status_; |
330 | 368 |
369 // The id of the URLRequest tied to this navigation. | |
370 GlobalRequestID request_id_; | |
371 | |
372 // Whether the current NavigationEntry should be replaced upon commit. | |
373 bool should_replace_current_entry_; | |
374 | |
375 // The chain of redirects. | |
376 std::vector<GURL> redirect_chain_; | |
377 | |
378 // A callback to run on the IO thread if the navigation transfers. | |
379 base::Closure transfer_callback_; | |
380 | |
381 // Whether the navigation ended up being a download or a stream. | |
382 bool is_download_; | |
383 bool is_stream_; | |
384 | |
385 base::WeakPtrFactory<NavigationHandleImpl> weak_factory_; | |
386 | |
331 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); | 387 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); |
332 }; | 388 }; |
333 | 389 |
334 } // namespace content | 390 } // namespace content |
335 | 391 |
336 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ | 392 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ |
OLD | NEW |