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

Side by Side Diff: content/browser/web_contents/navigation_controller_impl.cc

Issue 10830144: Consolidate all NavigationController::LoadURL and family functions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase onto TOT. Created 8 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/web_contents/navigation_controller_impl.h" 5 #include "content/browser/web_contents/navigation_controller_impl.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" // Temporary 9 #include "base/string_number_conversions.h" // Temporary
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 int index = 0; 556 int index = 0;
557 if (last_committed_entry_index_ != -1) 557 if (last_committed_entry_index_ != -1)
558 index = last_committed_entry_index_ + 1; 558 index = last_committed_entry_index_ + 1;
559 DiscardTransientEntry(); 559 DiscardTransientEntry();
560 entries_.insert( 560 entries_.insert(
561 entries_.begin() + index, linked_ptr<NavigationEntryImpl>(entry)); 561 entries_.begin() + index, linked_ptr<NavigationEntryImpl>(entry));
562 transient_entry_index_ = index; 562 transient_entry_index_ = index;
563 web_contents_->NotifyNavigationStateChanged(kInvalidateAll); 563 web_contents_->NotifyNavigationStateChanged(kInvalidateAll);
564 } 564 }
565 565
566 void NavigationControllerImpl::TransferURL(
567 const GURL& url,
568 const content::Referrer& referrer,
569 content::PageTransition transition,
570 const std::string& extra_headers,
571 const GlobalRequestID& transferred_global_request_id,
572 bool is_renderer_initiated) {
573 // The user initiated a load, we don't need to reload anymore.
574 needs_reload_ = false;
575
576 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
577 CreateNavigationEntry(
578 url, referrer, transition, is_renderer_initiated, extra_headers,
579 browser_context_));
580 entry->set_transferred_global_request_id(transferred_global_request_id);
581
582 LoadEntry(entry);
583 }
584
585 void NavigationControllerImpl::LoadURL( 566 void NavigationControllerImpl::LoadURL(
586 const GURL& url, 567 const GURL& url,
587 const content::Referrer& referrer, 568 const content::Referrer& referrer,
588 content::PageTransition transition, 569 content::PageTransition transition,
589 const std::string& extra_headers) { 570 const std::string& extra_headers) {
590 if (content::HandleDebugURL(url, transition)) 571 LoadURLParams params(url);
572 params.referrer = referrer;
573 params.transition_type = transition;
574 params.extra_headers = extra_headers;
575 LoadURLWithParams(params);
576 }
577
578 void NavigationControllerImpl::LoadURLWithParams(const LoadURLParams& params) {
579 if (content::HandleDebugURL(params.url, params.transition_type))
591 return; 580 return;
592 581
593 bool override = ShouldKeepOverride(GetLastCommittedEntry()); 582 // Checks based on params.load_type.
594 LoadURLWithUserAgentOverride(url, referrer, transition, false, extra_headers, 583 switch (params.load_type) {
595 override); 584 case LOAD_TYPE_DEFAULT:
596 } 585 break;
586 case LOAD_TYPE_BROWSER_INITIATED_HTTP_POST:
587 if (!params.url.SchemeIs(chrome::kHttpScheme) &&
588 !params.url.SchemeIs(chrome::kHttpsScheme)) {
589 NOTREACHED() << "Http post load must use http(s) scheme.";
590 return;
591 }
592 break;
593 case LOAD_TYPE_DATA:
594 if (!params.url.SchemeIs(chrome::kDataScheme)) {
595 NOTREACHED() << "Data load must use data scheme.";
596 return;
597 }
598 break;
599 default:
600 NOTREACHED();
601 break;
602 };
597 603
598 void NavigationControllerImpl::LoadURLFromRenderer(
599 const GURL& url,
600 const content::Referrer& referrer,
601 content::PageTransition transition,
602 const std::string& extra_headers) {
603 bool override = ShouldKeepOverride(GetLastCommittedEntry());
604 LoadURLWithUserAgentOverride(url, referrer, transition, true, extra_headers,
605 override);
606 }
607
608 void NavigationControllerImpl::LoadURLWithUserAgentOverride(
609 const GURL& url,
610 const content::Referrer& referrer,
611 content::PageTransition transition,
612 bool is_renderer_initiated,
613 const std::string& extra_headers,
614 bool is_overriding_user_agent) {
615 // The user initiated a load, we don't need to reload anymore. 604 // The user initiated a load, we don't need to reload anymore.
616 needs_reload_ = false; 605 needs_reload_ = false;
617 606
607 bool override = false;
608 switch (params.override_user_agent) {
609 case UA_OVERRIDE_INHERIT:
610 override = ShouldKeepOverride(GetLastCommittedEntry());
611 break;
612 case UA_OVERRIDE_TRUE:
613 override = true;
614 break;
615 case UA_OVERRIDE_FALSE:
616 override = false;
617 break;
618 default:
619 NOTREACHED();
620 break;
621 }
622
618 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 623 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
619 CreateNavigationEntry( 624 CreateNavigationEntry(
620 url, referrer, transition, is_renderer_initiated, extra_headers, 625 params.url,
626 params.referrer,
627 params.transition_type,
628 params.is_renderer_initiated,
629 params.extra_headers,
621 browser_context_)); 630 browser_context_));
622 entry->SetIsOverridingUserAgent(is_overriding_user_agent); 631 entry->SetIsOverridingUserAgent(override);
632 entry->set_transferred_global_request_id(
633 params.transferred_global_request_id);
634
635 switch (params.load_type) {
636 case LOAD_TYPE_DEFAULT:
637 break;
638 case LOAD_TYPE_BROWSER_INITIATED_HTTP_POST:
639 entry->SetHasPostData(true);
640 entry->SetBrowserInitiatedPostData(
641 params.browser_initiated_post_data);
642 break;
643 case LOAD_TYPE_DATA:
644 entry->SetBaseURLForDataURL(params.base_url_for_data_url);
645 entry->SetVirtualURL(params.virtual_url_for_data_url);
646 break;
647 default:
648 NOTREACHED();
649 break;
650 };
623 651
624 LoadEntry(entry); 652 LoadEntry(entry);
625 } 653 }
626
627 void NavigationControllerImpl::LoadDataWithBaseURL(
628 const GURL& data_url,
629 const content::Referrer& referrer,
630 const GURL& base_url,
631 const GURL& history_url,
632 bool is_overriding_user_agent) {
633 // Make sure we don't allow non-'data:' URLs.
634 if (!data_url.SchemeIs(chrome::kDataScheme)) {
635 NOTREACHED();
636 return;
637 }
638
639 needs_reload_ = false;
640
641 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
642 CreateNavigationEntry(
643 data_url,
644 referrer,
645 content::PAGE_TRANSITION_TYPED,
646 false,
647 std::string(),
648 browser_context_));
649 entry->SetIsOverridingUserAgent(is_overriding_user_agent);
650 entry->SetBaseURLForDataURL(base_url);
651 entry->SetVirtualURL(history_url);
652
653 LoadEntry(entry);
654 }
655
656 void NavigationControllerImpl::PostURL(
657 const GURL& url,
658 const content::Referrer& referrer,
659 const base::RefCountedMemory& http_body,
660 bool is_overriding_user_agent) {
661 // Must be http scheme for a post request.
662 if (!url.SchemeIs(chrome::kHttpScheme) &&
663 !url.SchemeIs(chrome::kHttpsScheme)) {
664 NOTREACHED();
665 return;
666 }
667
668 needs_reload_ = false;
669
670 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
671 CreateNavigationEntry(
672 url,
673 referrer,
674 content::PAGE_TRANSITION_TYPED,
675 false,
676 std::string(),
677 browser_context_));
678 entry->SetIsOverridingUserAgent(is_overriding_user_agent);
679 entry->SetHasPostData(true);
680 entry->SetBrowserInitiatedPostData(&http_body);
681
682 LoadEntry(entry);
683 }
684 654
685 void NavigationControllerImpl::DocumentLoadedInFrame() { 655 void NavigationControllerImpl::DocumentLoadedInFrame() {
686 last_document_loaded_ = base::TimeTicks::Now(); 656 last_document_loaded_ = base::TimeTicks::Now();
687 } 657 }
688 658
689 bool NavigationControllerImpl::RendererDidNavigate( 659 bool NavigationControllerImpl::RendererDidNavigate(
690 const ViewHostMsg_FrameNavigate_Params& params, 660 const ViewHostMsg_FrameNavigate_Params& params,
691 content::LoadCommittedDetails* details) { 661 content::LoadCommittedDetails* details) {
692 662
693 // Save the previous state before we clobber it. 663 // Save the previous state before we clobber it.
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 for (int i = 0; i < max_index; i++) { 1541 for (int i = 0; i < max_index; i++) {
1572 // When cloning a tab, copy all entries except interstitial pages 1542 // When cloning a tab, copy all entries except interstitial pages
1573 if (source.entries_[i].get()->GetPageType() != 1543 if (source.entries_[i].get()->GetPageType() !=
1574 content::PAGE_TYPE_INTERSTITIAL) { 1544 content::PAGE_TYPE_INTERSTITIAL) {
1575 entries_.insert(entries_.begin() + insert_index++, 1545 entries_.insert(entries_.begin() + insert_index++,
1576 linked_ptr<NavigationEntryImpl>( 1546 linked_ptr<NavigationEntryImpl>(
1577 new NavigationEntryImpl(*source.entries_[i]))); 1547 new NavigationEntryImpl(*source.entries_[i])));
1578 } 1548 }
1579 } 1549 }
1580 } 1550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698