diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-04 05:29:27 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-04 05:29:27 +0000 |
commit | 4c4d8d2b8aa8ae394d0f933700ddd9e682b141af (patch) | |
tree | 6e3e10e71c29bb9cc8d221d4de38d9dc603e32cd /chrome/browser/tab_contents/navigation_entry.cc | |
parent | 39d74d8b3c05faf98935927b68eaebb9a23a76a4 (diff) | |
download | chromium_src-4c4d8d2b8aa8ae394d0f933700ddd9e682b141af.zip chromium_src-4c4d8d2b8aa8ae394d0f933700ddd9e682b141af.tar.gz chromium_src-4c4d8d2b8aa8ae394d0f933700ddd9e682b141af.tar.bz2 |
Convert NavigationEntry title to string16. TabContents::GetTitle no longer needs
to be virtual, either.
This also changes how the display URL is computed. Instead of doing it
preemptively, we now do so lazily. This allows us to do the URL formatting
correctly using the elider so that we can do IDN and unescaping.
I changed string_util's singleton functions. I was worried that other code
might make a singleton of string, which would give you this same value as a
non-const string. This would mean our empty strings might no longer be empty.
Review URL: http://codereview.chromium.org/39022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents/navigation_entry.cc')
-rw-r--r-- | chrome/browser/tab_contents/navigation_entry.cc | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/chrome/browser/tab_contents/navigation_entry.cc b/chrome/browser/tab_contents/navigation_entry.cc index e243f8a..010c94a 100644 --- a/chrome/browser/tab_contents/navigation_entry.cc +++ b/chrome/browser/tab_contents/navigation_entry.cc @@ -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 @@ NavigationEntry::NavigationEntry(TabContentsType type, 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 @@ NavigationEntry::NavigationEntry(TabContentsType type, 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 { |