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.h | |
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.h')
-rw-r--r-- | chrome/browser/tab_contents/navigation_entry.h | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h index 20d3fd4..9cad672 100644 --- a/chrome/browser/tab_contents/navigation_entry.h +++ b/chrome/browser/tab_contents/navigation_entry.h @@ -16,6 +16,8 @@ #include "grit/theme_resources.h" #include "skia/include/SkBitmap.h" +class NavigationController; + //////////////////////////////////////////////////////////////////////////////// // // NavigationEntry class @@ -169,7 +171,7 @@ class NavigationEntry { int page_id, const GURL& url, const GURL& referrer, - const std::wstring& title, + const string16& title, PageTransition::Type transition_type); ~NavigationEntry() { } @@ -221,10 +223,7 @@ class NavigationEntry { // the user. void set_url(const GURL& url) { url_ = url; - if (display_url_.is_empty()) { - // If there is no explicit display URL, then we'll display this URL. - display_url_as_string_ = UTF8ToWide(url_.spec()); - } + cached_display_title_.clear(); } const GURL& url() const { return url_; @@ -247,7 +246,7 @@ class NavigationEntry { // if there is no overridden display URL, it will return the actual one. void set_display_url(const GURL& url) { display_url_ = (url == url_) ? GURL() : url; - display_url_as_string_ = UTF8ToWide(url.spec()); + cached_display_title_.clear(); } bool has_display_url() const { return !display_url_.is_empty(); @@ -260,10 +259,11 @@ class NavigationEntry { // The caller is responsible for detecting when there is no title and // displaying the appropriate "Untitled" label if this is being displayed to // the user. - void set_title(const std::wstring& title) { + void set_title(const string16& title) { title_ = title; + cached_display_title_.clear(); } - const std::wstring& title() const { + const string16& title() const { return title_; } @@ -313,7 +313,11 @@ class NavigationEntry { // Returns the title to be displayed on the tab. This could be the title of // the page if it is available or the URL. - const std::wstring& GetTitleForDisplay(); + // + // The NavigationController corresponding to this entry must be given so we + // can get the preferences so we can optionally format a URL for display. It + // may be NULL if you don't need proper URL formatting (e.g. unit tests). + const string16& GetTitleForDisplay(const NavigationController* controller); // Returns true if the current tab is in view source mode. This will be false // if there is no navigation. @@ -383,14 +387,8 @@ class NavigationEntry { PageType page_type_; GURL url_; GURL referrer_; - GURL display_url_; - - // We cache a copy of the display URL as a string so we don't have to - // convert the display URL to a wide string every time we paint. - std::wstring display_url_as_string_; - - std::wstring title_; + string16 title_; FaviconStatus favicon_; std::string content_state_; int32 page_id_; @@ -400,6 +398,12 @@ class NavigationEntry { bool has_post_data_; bool restored_; + // This is a cached version of the result of GetTitleForDisplay. It prevents + // us from having to do URL formatting on the URL evey time the title is + // displayed. When the URL, display URL, or title is set, this should be + // cleared to force a refresh. + string16 cached_display_title_; + // Copy and assignment is explicitly allowed for this class. }; |