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

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

Issue 2086423005: Using WebContents::UpdateTitleForEntry() instead of NavigationEntry::SetTitle() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improving comment and removing the NOTREACHED. Created 4 years, 5 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <utility> 10 #include <utility>
(...skipping 3875 matching lines...) Expand 10 before | Expand all | Expand 10 after
3886 // navigating (to avoid a race between the browser updating max_page_id and 3886 // navigating (to avoid a race between the browser updating max_page_id and
3887 // the renderer updating next_page_id_). Because of this, we only call this 3887 // the renderer updating next_page_id_). Because of this, we only call this
3888 // from CreateRenderView and allow that to notify the RenderView for us. 3888 // from CreateRenderView and allow that to notify the RenderView for us.
3889 int max_restored_page_id = controller_.GetMaxRestoredPageID(); 3889 int max_restored_page_id = controller_.GetMaxRestoredPageID();
3890 if (max_restored_page_id > 3890 if (max_restored_page_id >
3891 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance())) 3891 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3892 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(), 3892 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3893 max_restored_page_id); 3893 max_restored_page_id);
3894 } 3894 }
3895 3895
3896 bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry, 3896 void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry,
3897 const base::string16& title) { 3897 const base::string16& title) {
3898 // For file URLs without a title, use the pathname instead. In the case of a 3898 // For file URLs without a title, use the pathname instead. In the case of a
3899 // synthesized title, we don't want the update to count toward the "one set 3899 // synthesized title, we don't want the update to count toward the "one set
3900 // per page of the title to history." 3900 // per page of the title to history."
3901 base::string16 final_title; 3901 base::string16 final_title;
3902 bool explicit_set; 3902 bool explicit_set;
3903 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { 3903 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
3904 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName()); 3904 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
3905 explicit_set = false; // Don't count synthetic titles toward the set limit. 3905 explicit_set = false; // Don't count synthetic titles toward the set limit.
3906 } else { 3906 } else {
3907 base::TrimWhitespace(title, base::TRIM_ALL, &final_title); 3907 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
3908 explicit_set = true; 3908 explicit_set = true;
3909 } 3909 }
3910 3910
3911 // If a page is created via window.open and never navigated, 3911 // If a page is created via window.open and never navigated,
3912 // there will be no navigation entry. In this situation, 3912 // there will be no navigation entry. In this situation,
3913 // |page_title_when_no_navigation_entry_| will be used for page title. 3913 // |page_title_when_no_navigation_entry_| will be used for page title.
3914 if (entry) { 3914 if (entry) {
3915 if (final_title == entry->GetTitle()) 3915 if (final_title == entry->GetTitle())
3916 return false; // Nothing changed, don't bother. 3916 return; // Nothing changed, don't bother.
3917 3917
3918 entry->SetTitle(final_title); 3918 entry->SetTitle(final_title);
3919 } else { 3919 } else {
3920 if (page_title_when_no_navigation_entry_ == final_title) 3920 if (page_title_when_no_navigation_entry_ == final_title)
3921 return false; // Nothing changed, don't bother. 3921 return; // Nothing changed, don't bother.
3922 3922
3923 page_title_when_no_navigation_entry_ = final_title; 3923 page_title_when_no_navigation_entry_ = final_title;
3924 } 3924 }
3925 3925
3926 // Lastly, set the title for the view. 3926 // Lastly, set the title for the view.
3927 view_->SetPageTitle(final_title); 3927 view_->SetPageTitle(final_title);
3928 3928
3929 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3929 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3930 TitleWasSet(entry, explicit_set)); 3930 TitleWasSet(entry, explicit_set));
3931 3931
3932 return true; 3932 // Broadcast notifications when the UI should be updated.
3933 if (entry == controller_.GetEntryAtOffset(0))
3934 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3933 } 3935 }
3934 3936
3935 void WebContentsImpl::SendChangeLoadProgress() { 3937 void WebContentsImpl::SendChangeLoadProgress() {
3936 loading_last_progress_update_ = base::TimeTicks::Now(); 3938 loading_last_progress_update_ = base::TimeTicks::Now();
3937 if (delegate_) 3939 if (delegate_)
3938 delegate_->LoadProgressChanged(this, frame_tree_.load_progress()); 3940 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
3939 } 3941 }
3940 3942
3941 void WebContentsImpl::ResetLoadProgressState() { 3943 void WebContentsImpl::ResetLoadProgressState() {
3942 frame_tree_.ResetLoadProgress(); 3944 frame_tree_.ResetLoadProgress();
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
4528 } 4530 }
4529 4531
4530 // We can handle title updates when we don't have an entry in 4532 // We can handle title updates when we don't have an entry in
4531 // UpdateTitleForEntry, but only if the update is from the current RVH. 4533 // UpdateTitleForEntry, but only if the update is from the current RVH.
4532 // TODO(avi): Change to make decisions based on the RenderFrameHost. 4534 // TODO(avi): Change to make decisions based on the RenderFrameHost.
4533 if (!entry && render_frame_host != GetMainFrame()) 4535 if (!entry && render_frame_host != GetMainFrame())
4534 return; 4536 return;
4535 4537
4536 // TODO(evan): make use of title_direction. 4538 // TODO(evan): make use of title_direction.
4537 // http://code.google.com/p/chromium/issues/detail?id=27094 4539 // http://code.google.com/p/chromium/issues/detail?id=27094
4538 if (!UpdateTitleForEntry(entry, title)) 4540 UpdateTitleForEntry(entry, title);
4539 return;
4540
4541 // Broadcast notifications when the UI should be updated.
4542 if (entry == controller_.GetEntryAtOffset(0))
4543 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4544 } 4541 }
4545 4542
4546 void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host, 4543 void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4547 const std::string& encoding) { 4544 const std::string& encoding) {
4548 SetEncoding(encoding); 4545 SetEncoding(encoding);
4549 } 4546 }
4550 4547
4551 void WebContentsImpl::DocumentAvailableInMainFrame( 4548 void WebContentsImpl::DocumentAvailableInMainFrame(
4552 RenderViewHost* render_view_host) { 4549 RenderViewHost* render_view_host) {
4553 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 4550 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
5174 for (RenderViewHost* render_view_host : render_view_host_set) 5171 for (RenderViewHost* render_view_host : render_view_host_set)
5175 render_view_host->OnWebkitPreferencesChanged(); 5172 render_view_host->OnWebkitPreferencesChanged();
5176 } 5173 }
5177 5174
5178 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( 5175 void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
5179 JavaScriptDialogManager* dialog_manager) { 5176 JavaScriptDialogManager* dialog_manager) {
5180 dialog_manager_ = dialog_manager; 5177 dialog_manager_ = dialog_manager;
5181 } 5178 }
5182 5179
5183 } // namespace content 5180 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698