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