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

Unified Diff: chrome/browser/tab_contents/navigation_entry.cc

Issue 39022: Convert NavigationEntry title to string16. TabContents::GetTitle no longer ne... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/tab_contents/navigation_entry.h ('k') | chrome/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_contents/navigation_entry.cc
===================================================================
--- chrome/browser/tab_contents/navigation_entry.cc (revision 10809)
+++ chrome/browser/tab_contents/navigation_entry.cc (working copy)
@@ -4,6 +4,10 @@
#include "chrome/browser/tab_contents/navigation_entry.h"
+#include "chrome/browser/tab_contents/navigation_controller.h"
+#include "chrome/common/gfx/text_elider.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/resource_bundle.h"
@@ -43,7 +47,7 @@
int page_id,
const GURL& url,
const GURL& referrer,
- const std::wstring& title,
+ const string16& title,
PageTransition::Type transition_type)
: unique_id_(GetUniqueID()),
tab_type_(type),
@@ -58,10 +62,32 @@
restored_(false) {
}
-const std::wstring& NavigationEntry::GetTitleForDisplay() {
- if (title_.empty())
- return display_url_as_string_;
- return title_;
+const string16& NavigationEntry::GetTitleForDisplay(
+ const NavigationController* navigation_controller) {
+ // Most pages have real titles. Don't even bother caching anything if this is
+ // the case.
+ if (!title_.empty())
+ return title_;
+
+ // More complicated cases will use the URLs as the title. This result we will
+ // cache since it's more complicated to compute.
+ if (!cached_display_title_.empty())
+ return cached_display_title_;
+
+ // Use the display URL first if any, and fall back on using the real URL.
+ std::wstring languages;
+ if (navigation_controller) {
+ languages = navigation_controller->profile()->GetPrefs()->GetString(
+ prefs::kAcceptLanguages);
+ }
+ if (!display_url_.is_empty()) {
+ cached_display_title_ = WideToUTF16Hack(gfx::GetCleanStringFromUrl(
+ display_url_, languages, NULL, NULL));
+ } else if (!url_.is_empty()) {
+ cached_display_title_ = WideToUTF16Hack(gfx::GetCleanStringFromUrl(
+ display_url_, languages, NULL, NULL));
+ }
+ return cached_display_title_;
}
bool NavigationEntry::IsViewSourceMode() const {
« no previous file with comments | « chrome/browser/tab_contents/navigation_entry.h ('k') | chrome/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698