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

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

Issue 1309323004: Create a NavigationEntry for the initial blank page. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GetEntryCount, more tests Created 5 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 (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/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 705
706 const NavigationControllerImpl& WebContentsImpl::GetController() const { 706 const NavigationControllerImpl& WebContentsImpl::GetController() const {
707 return controller_; 707 return controller_;
708 } 708 }
709 709
710 BrowserContext* WebContentsImpl::GetBrowserContext() const { 710 BrowserContext* WebContentsImpl::GetBrowserContext() const {
711 return controller_.GetBrowserContext(); 711 return controller_.GetBrowserContext();
712 } 712 }
713 713
714 const GURL& WebContentsImpl::GetURL() const { 714 const GURL& WebContentsImpl::GetURL() const {
715 // We may not have a navigation entry yet. 715 return controller_.GetVisibleEntry()->GetVirtualURL();
716 NavigationEntry* entry = controller_.GetVisibleEntry();
717 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
718 } 716 }
719 717
720 const GURL& WebContentsImpl::GetVisibleURL() const { 718 const GURL& WebContentsImpl::GetVisibleURL() const {
721 // We may not have a navigation entry yet. 719 return controller_.GetVisibleEntry()->GetVirtualURL();
722 NavigationEntry* entry = controller_.GetVisibleEntry();
723 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
724 } 720 }
725 721
726 const GURL& WebContentsImpl::GetLastCommittedURL() const { 722 const GURL& WebContentsImpl::GetLastCommittedURL() const {
727 // We may not have a navigation entry yet. 723 return controller_.GetLastCommittedEntry()->GetVirtualURL();
728 NavigationEntry* entry = controller_.GetLastCommittedEntry();
729 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
730 } 724 }
731 725
732 WebContentsDelegate* WebContentsImpl::GetDelegate() { 726 WebContentsDelegate* WebContentsImpl::GetDelegate() {
733 return delegate_; 727 return delegate_;
734 } 728 }
735 729
736 void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { 730 void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
737 // TODO(cbentzel): remove this debugging code? 731 // TODO(cbentzel): remove this debugging code?
738 if (delegate == delegate_) 732 if (delegate == delegate_)
739 return; 733 return;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 942
949 // We make an exception for initial navigations. We only want to use the title 943 // We make an exception for initial navigations. We only want to use the title
950 // from the visible entry if: 944 // from the visible entry if:
951 // 1. The pending entry has been explicitly assigned a title to display. 945 // 1. The pending entry has been explicitly assigned a title to display.
952 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back), 946 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
953 // which case there is a pending entry index other than -1. 947 // which case there is a pending entry index other than -1.
954 // 948 //
955 // Otherwise, we want to stick with the last committed entry's title during 949 // Otherwise, we want to stick with the last committed entry's title during
956 // new navigations, which have pending entries at index -1 with no title. 950 // new navigations, which have pending entries at index -1 with no title.
957 if (controller_.IsInitialNavigation() && 951 if (controller_.IsInitialNavigation() &&
958 ((controller_.GetVisibleEntry() && 952 (!controller_.GetVisibleEntry()->GetTitle().empty() ||
959 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
960 controller_.GetPendingEntryIndex() != -1)) { 953 controller_.GetPendingEntryIndex() != -1)) {
961 entry = controller_.GetVisibleEntry(); 954 entry = controller_.GetVisibleEntry();
962 } 955 }
963 956
964 if (entry) { 957 // Return the empty string (not about:blank) for the initial blank page.
965 return entry->GetTitleForDisplay(accept_languages); 958 if (controller_.IsInitialNavigation() &&
966 } 959 entry == controller_.GetLastCommittedEntry())
960 return entry->GetTitle();
967 961
968 // |page_title_when_no_navigation_entry_| is finally used 962 return entry->GetTitleForDisplay(accept_languages);
969 // if no title cannot be retrieved.
970 return page_title_when_no_navigation_entry_;
971 } 963 }
972 964
973 int32 WebContentsImpl::GetMaxPageID() { 965 int32 WebContentsImpl::GetMaxPageID() {
974 return GetMaxPageIDForSiteInstance(GetSiteInstance()); 966 return GetMaxPageIDForSiteInstance(GetSiteInstance());
975 } 967 }
976 968
977 int32 WebContentsImpl::GetMaxPageIDForSiteInstance( 969 int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
978 SiteInstance* site_instance) { 970 SiteInstance* site_instance) {
979 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end()) 971 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
980 max_page_ids_[site_instance->GetId()] = -1; 972 max_page_ids_[site_instance->GetId()] = -1;
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 1337
1346 // Either both routing ids can be given, or neither can be. 1338 // Either both routing ids can be given, or neither can be.
1347 DCHECK((params.routing_id == MSG_ROUTING_NONE && 1339 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
1348 params.main_frame_routing_id == MSG_ROUTING_NONE) || 1340 params.main_frame_routing_id == MSG_ROUTING_NONE) ||
1349 (params.routing_id != MSG_ROUTING_NONE && 1341 (params.routing_id != MSG_ROUTING_NONE &&
1350 params.main_frame_routing_id != MSG_ROUTING_NONE)); 1342 params.main_frame_routing_id != MSG_ROUTING_NONE));
1351 GetRenderManager()->Init(params.browser_context, params.site_instance, 1343 GetRenderManager()->Init(params.browser_context, params.site_instance,
1352 params.routing_id, params.main_frame_routing_id, 1344 params.routing_id, params.main_frame_routing_id,
1353 MSG_ROUTING_NONE); 1345 MSG_ROUTING_NONE);
1354 frame_tree_.root()->SetFrameName(params.main_frame_name); 1346 frame_tree_.root()->SetFrameName(params.main_frame_name);
1347 controller_.Init(params.site_instance);
1355 1348
1356 WebContentsViewDelegate* delegate = 1349 WebContentsViewDelegate* delegate =
1357 GetContentClient()->browser()->GetWebContentsViewDelegate(this); 1350 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1358 1351
1359 if (browser_plugin_guest_ && 1352 if (browser_plugin_guest_ &&
1360 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { 1353 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
1361 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( 1354 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1362 this, delegate, &render_view_host_delegate_view_)); 1355 this, delegate, &render_view_host_delegate_view_));
1363 1356
1364 WebContentsViewGuest* rv = new WebContentsViewGuest( 1357 WebContentsViewGuest* rv = new WebContentsViewGuest(
(...skipping 2148 matching lines...) Expand 10 before | Expand all | Expand 10 after
3513 // from CreateRenderView and allow that to notify the RenderView for us. 3506 // from CreateRenderView and allow that to notify the RenderView for us.
3514 int max_restored_page_id = controller_.GetMaxRestoredPageID(); 3507 int max_restored_page_id = controller_.GetMaxRestoredPageID();
3515 if (max_restored_page_id > 3508 if (max_restored_page_id >
3516 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance())) 3509 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3517 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(), 3510 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3518 max_restored_page_id); 3511 max_restored_page_id);
3519 } 3512 }
3520 3513
3521 bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry, 3514 bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
3522 const base::string16& title) { 3515 const base::string16& title) {
3516 DCHECK(entry);
3517
3523 // For file URLs without a title, use the pathname instead. In the case of a 3518 // For file URLs without a title, use the pathname instead. In the case of a
3524 // synthesized title, we don't want the update to count toward the "one set 3519 // synthesized title, we don't want the update to count toward the "one set
3525 // per page of the title to history." 3520 // per page of the title to history."
3526 base::string16 final_title; 3521 base::string16 final_title;
3527 bool explicit_set; 3522 bool explicit_set;
3528 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { 3523 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
3529 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName()); 3524 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
3530 explicit_set = false; // Don't count synthetic titles toward the set limit. 3525 explicit_set = false; // Don't count synthetic titles toward the set limit.
3531 } else { 3526 } else {
3532 base::TrimWhitespace(title, base::TRIM_ALL, &final_title); 3527 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
3533 explicit_set = true; 3528 explicit_set = true;
3534 } 3529 }
3535 3530
3536 // If a page is created via window.open and never navigated, 3531 if (final_title == entry->GetTitle())
3537 // there will be no navigation entry. In this situation, 3532 return false; // Nothing changed, don't bother.
3538 // |page_title_when_no_navigation_entry_| will be used for page title.
3539 if (entry) {
3540 if (final_title == entry->GetTitle())
3541 return false; // Nothing changed, don't bother.
3542 3533
3543 entry->SetTitle(final_title); 3534 entry->SetTitle(final_title);
3544 } else {
3545 if (page_title_when_no_navigation_entry_ == final_title)
3546 return false; // Nothing changed, don't bother.
3547
3548 page_title_when_no_navigation_entry_ = final_title;
3549 }
3550 3535
3551 // Lastly, set the title for the view. 3536 // Lastly, set the title for the view.
3552 view_->SetPageTitle(final_title); 3537 view_->SetPageTitle(final_title);
3553 3538
3554 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3539 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3555 TitleWasSet(entry, explicit_set)); 3540 TitleWasSet(entry, explicit_set));
3556 3541
3557 return true; 3542 return true;
3558 } 3543 }
3559 3544
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
4639 return NULL; 4624 return NULL;
4640 } 4625 }
4641 4626
4642 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4627 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4643 force_disable_overscroll_content_ = force_disable; 4628 force_disable_overscroll_content_ = force_disable;
4644 if (view_) 4629 if (view_)
4645 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4630 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4646 } 4631 }
4647 4632
4648 } // namespace content 4633 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/browser/web_contents/web_contents_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698