Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.h

Issue 2321543002: Merge CrossSiteResourceHandler and NavigationResourceThrottle (Closed)
Patch Set: Addressed nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 bool new_is_external_protocol, 215 bool new_is_external_protocol,
214 scoped_refptr<net::HttpResponseHeaders> response_headers, 216 scoped_refptr<net::HttpResponseHeaders> response_headers,
215 const ThrottleChecksFinishedCallback& callback); 217 const ThrottleChecksFinishedCallback& callback);
216 218
217 // Called when the URLRequest has delivered response headers and metadata. 219 // Called when the URLRequest has delivered response headers and metadata.
218 // |callback| will be called when all throttle checks have completed, 220 // |callback| will be called when all throttle checks have completed,
219 // allowing the caller to cancel the navigation or let it proceed. 221 // allowing the caller to cancel the navigation or let it proceed.
220 // NavigationHandle will not call |callback| with a result of DEFER. 222 // NavigationHandle will not call |callback| with a result of DEFER.
221 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called 223 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called
222 // with |render_frame_host| and |response_headers| just before calling 224 // with |render_frame_host| and |response_headers| just before calling
223 // |callback|. 225 // |callback|. Should a transfer navigation happen, |transfer_callback| will
226 // be run on the IO thread.
227 // PlzNavigate: transfer navigations are not possible.
224 void WillProcessResponse( 228 void WillProcessResponse(
225 RenderFrameHostImpl* render_frame_host, 229 RenderFrameHostImpl* render_frame_host,
226 scoped_refptr<net::HttpResponseHeaders> response_headers, 230 scoped_refptr<net::HttpResponseHeaders> response_headers,
227 const SSLStatus& ssl_status, 231 const SSLStatus& ssl_status,
232 const GlobalRequestID& request_id,
233 bool should_replace_current_entry,
234 bool is_download,
235 bool is_stream,
236 const base::Closure& transfer_callback,
228 const ThrottleChecksFinishedCallback& callback); 237 const ThrottleChecksFinishedCallback& callback);
229 238
230 // Returns the FrameTreeNode this navigation is happening in. 239 // Returns the FrameTreeNode this navigation is happening in.
231 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } 240 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
232 241
233 // Called when the navigation is ready to be committed in 242 // Called when the navigation is ready to be committed in
234 // |render_frame_host|. This will update the |state_| and inform the 243 // |render_frame_host|. This will update the |state_| and inform the
235 // delegate. 244 // delegate.
236 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); 245 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host);
237 246
238 // Called when the navigation was committed in |render_frame_host|. This will 247 // Called when the navigation was committed in |render_frame_host|. This will
239 // update the |state_|. 248 // update the |state_|.
240 void DidCommitNavigation( 249 void DidCommitNavigation(
241 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 250 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
242 bool same_page, 251 bool same_page,
243 RenderFrameHostImpl* render_frame_host); 252 RenderFrameHostImpl* render_frame_host);
244 253
245 // Called during commit. Takes ownership of the embedder's NavigationData 254 // Called during commit. Takes ownership of the embedder's NavigationData
246 // instance. This NavigationData may have been cloned prior to being added 255 // instance. This NavigationData may have been cloned prior to being added
247 // here. 256 // here.
248 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) { 257 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) {
249 navigation_data_ = std::move(navigation_data); 258 navigation_data_ = std::move(navigation_data);
250 } 259 }
251 260
252 SSLStatus ssl_status() { return ssl_status_; } 261 SSLStatus ssl_status() { return ssl_status_; }
253 262
263 // This is valid after the network response has started.
264 // TODO(clamy): See if this can be initialized earlier if needed by
265 // non-transfer code. There may be some issues in PlzNavigate, where
266 // WillStartRequest will be called before starting a request on the IO thread.
267 const GlobalRequestID& request_id() const {
268 DCHECK_GE(state_, WILL_PROCESS_RESPONSE);
269 return request_id_;
270 }
271
272 // Called when the navigation is transferred to a different renderer.
273 void Transfer();
274
254 private: 275 private:
255 friend class NavigationHandleImplTest; 276 friend class NavigationHandleImplTest;
256 277
257 // Used to track the state the navigation is currently in. 278 // Used to track the state the navigation is currently in.
258 enum State { 279 enum State {
259 INITIAL = 0, 280 INITIAL = 0,
260 WILL_SEND_REQUEST, 281 WILL_SEND_REQUEST,
261 DEFERRING_START, 282 DEFERRING_START,
262 WILL_REDIRECT_REQUEST, 283 WILL_REDIRECT_REQUEST,
263 DEFERRING_REDIRECT, 284 DEFERRING_REDIRECT,
(...skipping 10 matching lines...) Expand all
274 bool is_renderer_initiated, 295 bool is_renderer_initiated,
275 bool is_synchronous, 296 bool is_synchronous,
276 bool is_srcdoc, 297 bool is_srcdoc,
277 const base::TimeTicks& navigation_start, 298 const base::TimeTicks& navigation_start,
278 int pending_nav_entry_id); 299 int pending_nav_entry_id);
279 300
280 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest(); 301 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest();
281 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest(); 302 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest();
282 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse(); 303 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse();
283 304
305 // Called when WillProcessResponse checks are done, to find the final
306 // RenderFrameHost for the navigation. Checks whether the navigation should be
307 // transferred. Returns false if the transfer attempt results in the
308 // destruction of this NavigationHandle and the navigation should no longer
309 // proceed. This can happen when the RenderFrameHostManager determines a
310 // transfer is needed, but WebContentsDelegate::ShouldTransferNavigation
311 // returns false.
312 bool MaybeTransferAndProceed();
313
314 // Helper method for MaybeTransferAndProceed. Returns false if the transfer
315 // attempt results in the destruction of this NavigationHandle.
316 bool MaybeTransferAndProceedInternal();
317
284 // Helper function to run and reset the |complete_callback_|. This marks the 318 // Helper function to run and reset the |complete_callback_|. This marks the
285 // end of a round of NavigationThrottleChecks. 319 // end of a round of NavigationThrottleChecks.
286 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result); 320 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result);
287 321
288 // Used in tests. 322 // Used in tests.
289 State state() const { return state_; } 323 State state() const { return state_; }
290 324
291 // Populates |throttles_| with the throttles for this navigation. 325 // Populates |throttles_| with the throttles for this navigation.
292 void RegisterNavigationThrottles(); 326 void RegisterNavigationThrottles();
293 327
294 // See NavigationHandle for a description of those member variables. 328 // See NavigationHandle for a description of those member variables.
295 GURL url_; 329 GURL url_;
296 Referrer sanitized_referrer_; 330 Referrer sanitized_referrer_;
297 bool has_user_gesture_; 331 bool has_user_gesture_;
298 ui::PageTransition transition_; 332 ui::PageTransition transition_;
299 bool is_external_protocol_; 333 bool is_external_protocol_;
300 net::Error net_error_code_; 334 net::Error net_error_code_;
301 RenderFrameHostImpl* render_frame_host_; 335 RenderFrameHostImpl* render_frame_host_;
302 const bool is_renderer_initiated_; 336 const bool is_renderer_initiated_;
303 bool is_same_page_; 337 bool is_same_page_;
304 const bool is_synchronous_; 338 const bool is_synchronous_;
305 const bool is_srcdoc_; 339 const bool is_srcdoc_;
306 bool was_redirected_; 340 bool was_redirected_;
307 scoped_refptr<net::HttpResponseHeaders> response_headers_; 341 scoped_refptr<net::HttpResponseHeaders> response_headers_;
308 342
343 // The original url of the navigation. This may differ from |url_| if the
344 // navigation encounters redirects.
345 const GURL original_url_;
346
309 // The HTTP method used for the navigation. 347 // The HTTP method used for the navigation.
310 std::string method_; 348 std::string method_;
311 349
312 // The POST body associated with this navigation. This will be null for GET 350 // The POST body associated with this navigation. This will be null for GET
313 // and/or other non-POST requests (or if a response to a POST request was a 351 // and/or other non-POST requests (or if a response to a POST request was a
314 // redirect that changed the method to GET - for example 302). 352 // redirect that changed the method to GET - for example 302).
315 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; 353 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_;
316 354
317 // The state the navigation is in. 355 // The state the navigation is in.
318 State state_; 356 State state_;
(...skipping 26 matching lines...) Expand all
345 // PlzNavigate 383 // PlzNavigate
346 // Manages the lifetime of a pre-created ServiceWorkerProviderHost until a 384 // Manages the lifetime of a pre-created ServiceWorkerProviderHost until a
347 // corresponding ServiceWorkerNetworkProvider is created in the renderer. 385 // corresponding ServiceWorkerNetworkProvider is created in the renderer.
348 std::unique_ptr<ServiceWorkerNavigationHandle> service_worker_handle_; 386 std::unique_ptr<ServiceWorkerNavigationHandle> service_worker_handle_;
349 387
350 // Embedder data tied to this navigation. 388 // Embedder data tied to this navigation.
351 std::unique_ptr<NavigationData> navigation_data_; 389 std::unique_ptr<NavigationData> navigation_data_;
352 390
353 SSLStatus ssl_status_; 391 SSLStatus ssl_status_;
354 392
393 // The id of the URLRequest tied to this navigation.
394 GlobalRequestID request_id_;
395
396 // Whether the current NavigationEntry should be replaced upon commit.
397 bool should_replace_current_entry_;
398
399 // The chain of redirects.
400 std::vector<GURL> redirect_chain_;
401
402 // A callback to run on the IO thread if the navigation transfers.
403 base::Closure transfer_callback_;
404
405 // Whether the navigation ended up being a download or a stream.
406 bool is_download_;
407 bool is_stream_;
408
409 base::WeakPtrFactory<NavigationHandleImpl> weak_factory_;
410
355 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); 411 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl);
356 }; 412 };
357 413
358 } // namespace content 414 } // namespace content
359 415
360 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 416 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698