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

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

Issue 2392283005: Reland "Merge of CrossSiteResourceHandler and NavigationResourceThrottle." (Closed)
Patch Set: Added debugging code from issue 2393903002 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 NavigationUIData; 31 class NavigationUIData;
31 class NavigatorDelegate; 32 class NavigatorDelegate;
32 class ResourceRequestBodyImpl; 33 class ResourceRequestBodyImpl;
33 class ServiceWorkerContextWrapper; 34 class ServiceWorkerContextWrapper;
34 class ServiceWorkerNavigationHandle; 35 class ServiceWorkerNavigationHandle;
36 class SiteInstance;
35 37
36 // This class keeps track of a single navigation. It is created upon receipt of 38 // This class keeps track of a single navigation. It is created upon receipt of
37 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns 39 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns
38 // the newly created NavigationHandleImpl as long as the navigation is ongoing. 40 // the newly created NavigationHandleImpl as long as the navigation is ongoing.
39 // The NavigationHandleImpl in the RenderFrameHost will be reset when the 41 // The NavigationHandleImpl in the RenderFrameHost will be reset when the
40 // navigation stops, that is if one of the following events happen: 42 // navigation stops, that is if one of the following events happen:
41 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new 43 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new
42 // navigation (see below for special cases where the DidStartProvisionalLoad 44 // navigation (see below for special cases where the DidStartProvisionalLoad
43 // message does not indicate the start of a new navigation). 45 // message does not indicate the start of a new navigation).
44 // - The RenderFrameHost stops loading. 46 // - The RenderFrameHost stops loading.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 bool new_is_external_protocol, 218 bool new_is_external_protocol,
217 scoped_refptr<net::HttpResponseHeaders> response_headers, 219 scoped_refptr<net::HttpResponseHeaders> response_headers,
218 const ThrottleChecksFinishedCallback& callback); 220 const ThrottleChecksFinishedCallback& callback);
219 221
220 // Called when the URLRequest has delivered response headers and metadata. 222 // Called when the URLRequest has delivered response headers and metadata.
221 // |callback| will be called when all throttle checks have completed, 223 // |callback| will be called when all throttle checks have completed,
222 // allowing the caller to cancel the navigation or let it proceed. 224 // allowing the caller to cancel the navigation or let it proceed.
223 // NavigationHandle will not call |callback| with a result of DEFER. 225 // NavigationHandle will not call |callback| with a result of DEFER.
224 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called 226 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called
225 // with |render_frame_host| and |response_headers| just before calling 227 // with |render_frame_host| and |response_headers| just before calling
226 // |callback|. 228 // |callback|. Should a transfer navigation happen, |transfer_callback| will
229 // be run on the IO thread.
230 // PlzNavigate: transfer navigations are not possible.
227 void WillProcessResponse( 231 void WillProcessResponse(
228 RenderFrameHostImpl* render_frame_host, 232 RenderFrameHostImpl* render_frame_host,
229 scoped_refptr<net::HttpResponseHeaders> response_headers, 233 scoped_refptr<net::HttpResponseHeaders> response_headers,
230 const SSLStatus& ssl_status, 234 const SSLStatus& ssl_status,
235 const GlobalRequestID& request_id,
236 bool should_replace_current_entry,
237 bool is_download,
238 bool is_stream,
239 const base::Closure& transfer_callback,
231 const ThrottleChecksFinishedCallback& callback); 240 const ThrottleChecksFinishedCallback& callback);
232 241
233 // Returns the FrameTreeNode this navigation is happening in. 242 // Returns the FrameTreeNode this navigation is happening in.
234 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } 243 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
235 244
236 // Called when the navigation is ready to be committed in 245 // Called when the navigation is ready to be committed in
237 // |render_frame_host|. This will update the |state_| and inform the 246 // |render_frame_host|. This will update the |state_| and inform the
238 // delegate. 247 // delegate.
239 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); 248 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host);
240 249
241 // Called when the navigation was committed in |render_frame_host|. This will 250 // Called when the navigation was committed in |render_frame_host|. This will
242 // update the |state_|. 251 // update the |state_|.
243 void DidCommitNavigation( 252 void DidCommitNavigation(
244 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 253 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
245 bool same_page, 254 bool same_page,
246 RenderFrameHostImpl* render_frame_host); 255 RenderFrameHostImpl* render_frame_host);
247 256
248 // Called during commit. Takes ownership of the embedder's NavigationData 257 // Called during commit. Takes ownership of the embedder's NavigationData
249 // instance. This NavigationData may have been cloned prior to being added 258 // instance. This NavigationData may have been cloned prior to being added
250 // here. 259 // here.
251 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) { 260 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) {
252 navigation_data_ = std::move(navigation_data); 261 navigation_data_ = std::move(navigation_data);
253 } 262 }
254 263
255 SSLStatus ssl_status() { return ssl_status_; } 264 SSLStatus ssl_status() { return ssl_status_; }
256 265
266 // This is valid after the network response has started.
267 // TODO(clamy): See if this can be initialized earlier if needed by
268 // non-transfer code. There may be some issues in PlzNavigate, where
269 // WillStartRequest will be called before starting a request on the IO thread.
270 const GlobalRequestID& request_id() const {
271 DCHECK_GE(state_, WILL_PROCESS_RESPONSE);
272 return request_id_;
273 }
274
275 // Called when the navigation is transferred to a different renderer.
276 void Transfer();
277
257 NavigationUIData* navigation_ui_data() const { 278 NavigationUIData* navigation_ui_data() const {
258 return navigation_ui_data_.get(); 279 return navigation_ui_data_.get();
259 } 280 }
260 281
261 private: 282 private:
262 friend class NavigationHandleImplTest; 283 friend class NavigationHandleImplTest;
263 284
264 // Used to track the state the navigation is currently in. 285 // Used to track the state the navigation is currently in.
265 enum State { 286 enum State {
266 INITIAL = 0, 287 INITIAL = 0,
(...skipping 15 matching lines...) Expand all
282 bool is_synchronous, 303 bool is_synchronous,
283 bool is_srcdoc, 304 bool is_srcdoc,
284 const base::TimeTicks& navigation_start, 305 const base::TimeTicks& navigation_start,
285 int pending_nav_entry_id, 306 int pending_nav_entry_id,
286 bool started_from_context_menu); 307 bool started_from_context_menu);
287 308
288 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest(); 309 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest();
289 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest(); 310 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest();
290 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse(); 311 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse();
291 312
313 // Called when WillProcessResponse checks are done, to find the final
314 // RenderFrameHost for the navigation. Checks whether the navigation should be
315 // transferred. Returns false if the transfer attempt results in the
316 // destruction of this NavigationHandle and the navigation should no longer
317 // proceed. This can happen when the RenderFrameHostManager determines a
318 // transfer is needed, but WebContentsDelegate::ShouldTransferNavigation
319 // returns false.
320 bool MaybeTransferAndProceed();
321
322 // Helper method for MaybeTransferAndProceed. Returns false if the transfer
323 // attempt results in the destruction of this NavigationHandle.
324 bool MaybeTransferAndProceedInternal();
325
292 // Helper function to run and reset the |complete_callback_|. This marks the 326 // Helper function to run and reset the |complete_callback_|. This marks the
293 // end of a round of NavigationThrottleChecks. 327 // end of a round of NavigationThrottleChecks.
294 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result); 328 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result);
295 329
296 // Used in tests. 330 // Used in tests.
297 State state() const { return state_; } 331 State state() const { return state_; }
298 332
299 // Populates |throttles_| with the throttles for this navigation. 333 // Populates |throttles_| with the throttles for this navigation.
300 void RegisterNavigationThrottles(); 334 void RegisterNavigationThrottles();
301 335
302 // See NavigationHandle for a description of those member variables. 336 // See NavigationHandle for a description of those member variables.
303 GURL url_; 337 GURL url_;
304 Referrer sanitized_referrer_; 338 Referrer sanitized_referrer_;
305 bool has_user_gesture_; 339 bool has_user_gesture_;
306 ui::PageTransition transition_; 340 ui::PageTransition transition_;
307 bool is_external_protocol_; 341 bool is_external_protocol_;
308 net::Error net_error_code_; 342 net::Error net_error_code_;
309 RenderFrameHostImpl* render_frame_host_; 343 RenderFrameHostImpl* render_frame_host_;
310 const bool is_renderer_initiated_; 344 const bool is_renderer_initiated_;
311 bool is_same_page_; 345 bool is_same_page_;
312 const bool is_synchronous_; 346 const bool is_synchronous_;
313 const bool is_srcdoc_; 347 const bool is_srcdoc_;
314 bool was_redirected_; 348 bool was_redirected_;
315 scoped_refptr<net::HttpResponseHeaders> response_headers_; 349 scoped_refptr<net::HttpResponseHeaders> response_headers_;
316 350
351 // The original url of the navigation. This may differ from |url_| if the
352 // navigation encounters redirects.
353 const GURL original_url_;
354
317 // The HTTP method used for the navigation. 355 // The HTTP method used for the navigation.
318 std::string method_; 356 std::string method_;
319 357
320 // The POST body associated with this navigation. This will be null for GET 358 // The POST body associated with this navigation. This will be null for GET
321 // and/or other non-POST requests (or if a response to a POST request was a 359 // and/or other non-POST requests (or if a response to a POST request was a
322 // redirect that changed the method to GET - for example 302). 360 // redirect that changed the method to GET - for example 302).
323 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; 361 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_;
324 362
325 // The state the navigation is in. 363 // The state the navigation is in.
326 State state_; 364 State state_;
(...skipping 30 matching lines...) Expand all
357 395
358 // Embedder data from the IO thread tied to this navigation. 396 // Embedder data from the IO thread tied to this navigation.
359 std::unique_ptr<NavigationData> navigation_data_; 397 std::unique_ptr<NavigationData> navigation_data_;
360 398
361 // PlzNavigate 399 // PlzNavigate
362 // Embedder data from the UI thread tied to this navigation. 400 // Embedder data from the UI thread tied to this navigation.
363 std::unique_ptr<NavigationUIData> navigation_ui_data_; 401 std::unique_ptr<NavigationUIData> navigation_ui_data_;
364 402
365 SSLStatus ssl_status_; 403 SSLStatus ssl_status_;
366 404
405 // The id of the URLRequest tied to this navigation.
406 GlobalRequestID request_id_;
407
408 // Whether the current NavigationEntry should be replaced upon commit.
409 bool should_replace_current_entry_;
410
411 // The chain of redirects.
412 std::vector<GURL> redirect_chain_;
413
414 // A callback to run on the IO thread if the navigation transfers.
415 base::Closure transfer_callback_;
416
417 // Whether the navigation ended up being a download or a stream.
418 bool is_download_;
419 bool is_stream_;
420
367 // False by default unless the navigation started within a context menu. 421 // False by default unless the navigation started within a context menu.
368 bool started_from_context_menu_; 422 bool started_from_context_menu_;
369 423
424 base::WeakPtrFactory<NavigationHandleImpl> weak_factory_;
425
370 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); 426 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl);
371 }; 427 };
372 428
373 } // namespace content 429 } // namespace content
374 430
375 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 431 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698