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

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

Issue 2657323003: Convert HistoryTabHelper to use the new navigation callbacks. (Closed)
Patch Set: nit Created 3 years, 10 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 #include "content/browser/frame_host/navigation_handle_impl.h" 5 #include "content/browser/frame_host/navigation_handle_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/debug/dump_without_crashing.h" 9 #include "base/debug/dump_without_crashing.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 DCHECK_CURRENTLY_ON(BrowserThread::IO); 52 DCHECK_CURRENTLY_ON(BrowserThread::IO);
53 if (ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get()) 53 if (ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get())
54 rdh->CancelRequest(id.child_id, id.request_id); 54 rdh->CancelRequest(id.child_id, id.request_id);
55 } 55 }
56 56
57 } // namespace 57 } // namespace
58 58
59 // static 59 // static
60 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( 60 std::unique_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
61 const GURL& url, 61 const GURL& url,
62 const std::vector<GURL>& redirect_chain,
62 FrameTreeNode* frame_tree_node, 63 FrameTreeNode* frame_tree_node,
63 bool is_renderer_initiated, 64 bool is_renderer_initiated,
64 bool is_same_page, 65 bool is_same_page,
65 const base::TimeTicks& navigation_start, 66 const base::TimeTicks& navigation_start,
66 int pending_nav_entry_id, 67 int pending_nav_entry_id,
67 bool started_from_context_menu) { 68 bool started_from_context_menu) {
68 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl( 69 return std::unique_ptr<NavigationHandleImpl>(new NavigationHandleImpl(
69 url, frame_tree_node, is_renderer_initiated, is_same_page, 70 url, redirect_chain, frame_tree_node, is_renderer_initiated, is_same_page,
70 navigation_start, pending_nav_entry_id, 71 navigation_start, pending_nav_entry_id,
71 started_from_context_menu)); 72 started_from_context_menu));
72 } 73 }
73 74
74 NavigationHandleImpl::NavigationHandleImpl( 75 NavigationHandleImpl::NavigationHandleImpl(
75 const GURL& url, 76 const GURL& url,
77 const std::vector<GURL>& redirect_chain,
76 FrameTreeNode* frame_tree_node, 78 FrameTreeNode* frame_tree_node,
77 bool is_renderer_initiated, 79 bool is_renderer_initiated,
78 bool is_same_page, 80 bool is_same_page,
79 const base::TimeTicks& navigation_start, 81 const base::TimeTicks& navigation_start,
80 int pending_nav_entry_id, 82 int pending_nav_entry_id,
81 bool started_from_context_menu) 83 bool started_from_context_menu)
82 : url_(url), 84 : url_(url),
83 has_user_gesture_(false), 85 has_user_gesture_(false),
84 transition_(ui::PAGE_TRANSITION_LINK), 86 transition_(ui::PAGE_TRANSITION_LINK),
85 is_external_protocol_(false), 87 is_external_protocol_(false),
86 net_error_code_(net::OK), 88 net_error_code_(net::OK),
87 render_frame_host_(nullptr), 89 render_frame_host_(nullptr),
88 is_renderer_initiated_(is_renderer_initiated), 90 is_renderer_initiated_(is_renderer_initiated),
89 is_same_page_(is_same_page), 91 is_same_page_(is_same_page),
90 was_redirected_(false), 92 was_redirected_(false),
93 did_replace_entry_(false),
94 should_update_history_(false),
91 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), 95 connection_info_(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN),
92 original_url_(url), 96 original_url_(url),
93 state_(INITIAL), 97 state_(INITIAL),
94 is_transferring_(false), 98 is_transferring_(false),
95 frame_tree_node_(frame_tree_node), 99 frame_tree_node_(frame_tree_node),
96 next_index_(0), 100 next_index_(0),
97 navigation_start_(navigation_start), 101 navigation_start_(navigation_start),
98 pending_nav_entry_id_(pending_nav_entry_id), 102 pending_nav_entry_id_(pending_nav_entry_id),
99 request_context_type_(REQUEST_CONTEXT_TYPE_UNSPECIFIED), 103 request_context_type_(REQUEST_CONTEXT_TYPE_UNSPECIFIED),
100 mixed_content_context_type_(blink::WebMixedContentContextType::Blockable), 104 mixed_content_context_type_(blink::WebMixedContentContextType::Blockable),
101 should_replace_current_entry_(false), 105 should_replace_current_entry_(false),
106 redirect_chain_(redirect_chain),
102 is_download_(false), 107 is_download_(false),
103 is_stream_(false), 108 is_stream_(false),
104 started_from_context_menu_(started_from_context_menu), 109 started_from_context_menu_(started_from_context_menu),
105 reload_type_(ReloadType::NONE), 110 reload_type_(ReloadType::NONE),
106 weak_factory_(this) { 111 weak_factory_(this) {
107 DCHECK(!navigation_start.is_null()); 112 DCHECK(!navigation_start.is_null());
108 redirect_chain_.push_back(url); 113 if (redirect_chain_.empty())
114 redirect_chain_.push_back(url);
109 115
110 starting_site_instance_ = 116 starting_site_instance_ =
111 frame_tree_node_->current_frame_host()->GetSiteInstance(); 117 frame_tree_node_->current_frame_host()->GetSiteInstance();
112 118
113 if (pending_nav_entry_id_) { 119 if (pending_nav_entry_id_) {
114 NavigationControllerImpl* nav_controller = 120 NavigationControllerImpl* nav_controller =
115 static_cast<NavigationControllerImpl*>( 121 static_cast<NavigationControllerImpl*>(
116 frame_tree_node_->navigator()->GetController()); 122 frame_tree_node_->navigator()->GetController());
117 NavigationEntryImpl* nav_entry = 123 NavigationEntryImpl* nav_entry =
118 nav_controller->GetEntryWithUniqueID(pending_nav_entry_id_); 124 nav_controller->GetEntryWithUniqueID(pending_nav_entry_id_);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 276 }
271 277
272 bool NavigationHandleImpl::HasCommitted() { 278 bool NavigationHandleImpl::HasCommitted() {
273 return state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE; 279 return state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE;
274 } 280 }
275 281
276 bool NavigationHandleImpl::IsErrorPage() { 282 bool NavigationHandleImpl::IsErrorPage() {
277 return state_ == DID_COMMIT_ERROR_PAGE; 283 return state_ == DID_COMMIT_ERROR_PAGE;
278 } 284 }
279 285
286 bool NavigationHandleImpl::DidReplaceEntry() {
287 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE);
288 return did_replace_entry_;
289 }
290
291 bool NavigationHandleImpl::ShouldUpdateHistory() {
292 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE);
293 return should_update_history_;
294 }
295
280 const GURL& NavigationHandleImpl::GetPreviousURL() { 296 const GURL& NavigationHandleImpl::GetPreviousURL() {
281 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE); 297 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE);
282 return previous_url_; 298 return previous_url_;
283 } 299 }
284 300
285 net::HostPortPair NavigationHandleImpl::GetSocketAddress() { 301 net::HostPortPair NavigationHandleImpl::GetSocketAddress() {
286 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE); 302 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE);
287 return socket_address_; 303 return socket_address_;
288 } 304 }
289 305
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 RequestContextType request_context_type, 483 RequestContextType request_context_type,
468 blink::WebMixedContentContextType mixed_content_context_type, 484 blink::WebMixedContentContextType mixed_content_context_type,
469 const ThrottleChecksFinishedCallback& callback) { 485 const ThrottleChecksFinishedCallback& callback) {
470 if (method != "POST") 486 if (method != "POST")
471 DCHECK(!resource_request_body); 487 DCHECK(!resource_request_body);
472 488
473 // Update the navigation parameters. 489 // Update the navigation parameters.
474 method_ = method; 490 method_ = method;
475 if (method_ == "POST") 491 if (method_ == "POST")
476 resource_request_body_ = resource_request_body; 492 resource_request_body_ = resource_request_body;
477 sanitized_referrer_ = sanitized_referrer;
478 has_user_gesture_ = has_user_gesture; 493 has_user_gesture_ = has_user_gesture;
479 transition_ = transition; 494 transition_ = transition;
495 // Mirrors the logic in RenderFrameImpl::SendDidCommitProvisionalLoad.
496 if (transition_ & ui::PAGE_TRANSITION_CLIENT_REDIRECT) {
497 // If the page contained a client redirect (meta refresh,
498 // document.location), set the referrer appropriately.
499 sanitized_referrer_ =
500 Referrer(redirect_chain_[0], sanitized_referrer.policy);
501 } else {
502 sanitized_referrer_ = sanitized_referrer;
503 }
480 is_external_protocol_ = is_external_protocol; 504 is_external_protocol_ = is_external_protocol;
481 request_context_type_ = request_context_type; 505 request_context_type_ = request_context_type;
482 mixed_content_context_type_ = mixed_content_context_type; 506 mixed_content_context_type_ = mixed_content_context_type;
483 state_ = WILL_SEND_REQUEST; 507 state_ = WILL_SEND_REQUEST;
484 complete_callback_ = callback; 508 complete_callback_ = callback;
485 509
486 RegisterNavigationThrottles(); 510 RegisterNavigationThrottles();
487 511
488 if (IsBrowserSideNavigationEnabled()) 512 if (IsBrowserSideNavigationEnabled())
489 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this); 513 navigation_ui_data_ = GetDelegate()->GetNavigationUIData(this);
(...skipping 10 matching lines...) Expand all
500 const GURL& new_url, 524 const GURL& new_url,
501 const std::string& new_method, 525 const std::string& new_method,
502 const GURL& new_referrer_url, 526 const GURL& new_referrer_url,
503 bool new_is_external_protocol, 527 bool new_is_external_protocol,
504 scoped_refptr<net::HttpResponseHeaders> response_headers, 528 scoped_refptr<net::HttpResponseHeaders> response_headers,
505 net::HttpResponseInfo::ConnectionInfo connection_info, 529 net::HttpResponseInfo::ConnectionInfo connection_info,
506 const ThrottleChecksFinishedCallback& callback) { 530 const ThrottleChecksFinishedCallback& callback) {
507 // Update the navigation parameters. 531 // Update the navigation parameters.
508 url_ = new_url; 532 url_ = new_url;
509 method_ = new_method; 533 method_ = new_method;
510 sanitized_referrer_.url = new_referrer_url; 534
511 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); 535 if (!(transition_ & ui::PAGE_TRANSITION_CLIENT_REDIRECT)) {
536 sanitized_referrer_.url = new_referrer_url;
537 sanitized_referrer_ =
538 Referrer::SanitizeForRequest(url_, sanitized_referrer_);
539 }
540
512 is_external_protocol_ = new_is_external_protocol; 541 is_external_protocol_ = new_is_external_protocol;
513 response_headers_ = response_headers; 542 response_headers_ = response_headers;
514 connection_info_ = connection_info; 543 connection_info_ = connection_info;
515 was_redirected_ = true; 544 was_redirected_ = true;
516 redirect_chain_.push_back(new_url); 545 redirect_chain_.push_back(new_url);
517 if (new_method != "POST") 546 if (new_method != "POST")
518 resource_request_body_ = nullptr; 547 resource_request_body_ = nullptr;
519 548
520 state_ = WILL_REDIRECT_REQUEST; 549 state_ = WILL_REDIRECT_REQUEST;
521 complete_callback_ = callback; 550 complete_callback_ = callback;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); 602 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host);
574 render_frame_host_ = render_frame_host; 603 render_frame_host_ = render_frame_host;
575 state_ = READY_TO_COMMIT; 604 state_ = READY_TO_COMMIT;
576 605
577 if (!IsRendererDebugURL(url_)) 606 if (!IsRendererDebugURL(url_))
578 GetDelegate()->ReadyToCommitNavigation(this); 607 GetDelegate()->ReadyToCommitNavigation(this);
579 } 608 }
580 609
581 void NavigationHandleImpl::DidCommitNavigation( 610 void NavigationHandleImpl::DidCommitNavigation(
582 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 611 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
583 bool same_page, 612 bool did_replace_entry,
584 const GURL& previous_url, 613 const GURL& previous_url,
585 RenderFrameHostImpl* render_frame_host) { 614 RenderFrameHostImpl* render_frame_host) {
586 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); 615 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host);
587 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node()); 616 DCHECK_EQ(frame_tree_node_, render_frame_host->frame_tree_node());
588 CHECK_EQ(url_, params.url); 617 CHECK_EQ(url_, params.url);
589 618
619 did_replace_entry_ = did_replace_entry;
590 method_ = params.method; 620 method_ = params.method;
591 has_user_gesture_ = (params.gesture == NavigationGestureUser); 621 has_user_gesture_ = (params.gesture == NavigationGestureUser);
592 transition_ = params.transition; 622 transition_ = params.transition;
623 should_update_history_ = params.should_update_history;
593 render_frame_host_ = render_frame_host; 624 render_frame_host_ = render_frame_host;
594 previous_url_ = previous_url; 625 previous_url_ = previous_url;
595 base_url_ = params.base_url; 626 base_url_ = params.base_url;
596 socket_address_ = params.socket_address; 627 socket_address_ = params.socket_address;
597 628
598 // If an error page reloads, net_error_code might be 200 but we still want to 629 // If an error page reloads, net_error_code might be 200 but we still want to
599 // count it as an error page. 630 // count it as an error page.
600 if (params.base_url.spec() == kUnreachableWebDataURL || 631 if (params.base_url.spec() == kUnreachableWebDataURL ||
601 net_error_code_ != net::OK) { 632 net_error_code_ != net::OK) {
602 state_ = DID_COMMIT_ERROR_PAGE; 633 state_ = DID_COMMIT_ERROR_PAGE;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 content::AncestorThrottle::MaybeCreateThrottleFor(this); 879 content::AncestorThrottle::MaybeCreateThrottleFor(this);
849 if (ancestor_throttle) 880 if (ancestor_throttle)
850 throttles_.push_back(std::move(ancestor_throttle)); 881 throttles_.push_back(std::move(ancestor_throttle));
851 882
852 throttles_.insert(throttles_.begin(), 883 throttles_.insert(throttles_.begin(),
853 std::make_move_iterator(throttles_to_register.begin()), 884 std::make_move_iterator(throttles_to_register.begin()),
854 std::make_move_iterator(throttles_to_register.end())); 885 std::make_move_iterator(throttles_to_register.end()));
855 } 886 }
856 887
857 } // namespace content 888 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.h ('k') | content/browser/frame_host/navigation_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698