diff options
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/interstitial_page.cc | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.cc | 14 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_controller.h | 3 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_entry.cc | 36 | ||||
-rw-r--r-- | chrome/browser/tab_contents/navigation_entry.h | 36 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 8 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.cc | 2 |
8 files changed, 67 insertions, 36 deletions
diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index 688c6f1..fad7d21 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -392,7 +392,7 @@ void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host, // If this interstitial is shown on an existing navigation entry, we'll need // to remember its title so we can revert to it when hidden. if (!new_navigation_ && !should_revert_tab_title_) { - original_tab_title_ = entry->title(); + original_tab_title_ = UTF16ToWideHack(entry->title()); should_revert_tab_title_ = true; } entry->set_title(title); diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index eb7b613..374b1804 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -476,12 +476,12 @@ NavigationEntry* NavigationController::CreateNavigationEntry( NavigationEntry* entry = new NavigationEntry(type, NULL, -1, real_url, referrer, - std::wstring(), transition); + string16(), transition); entry->set_display_url(url); entry->set_user_typed_url(url); if (url.SchemeIsFile()) { - entry->set_title(file_util::GetFilenameFromPath(UTF8ToWide(url.host() + - url.path()))); + entry->set_title(WideToUTF16Hack( + file_util::GetFilenameFromPath(UTF8ToWide(url.host() + url.path())))); } return entry; } @@ -514,7 +514,7 @@ void NavigationController::LoadURLLazily(const GURL& url, const std::wstring& title, SkBitmap* icon) { NavigationEntry* entry = CreateNavigationEntry(url, referrer, type); - entry->set_title(title); + entry->set_title(WideToUTF16Hack(title)); if (icon) entry->favicon().set_bitmap(*icon); @@ -527,11 +527,11 @@ bool NavigationController::LoadingURLLazily() { return load_pending_entry_when_active_; } -const std::wstring& NavigationController::GetLazyTitle() const { +const string16& NavigationController::GetLazyTitle() const { if (pending_entry_) - return pending_entry_->GetTitleForDisplay(); + return pending_entry_->GetTitleForDisplay(this); else - return EmptyWString(); + return EmptyString16(); } const SkBitmap& NavigationController::GetLazyFavIcon() const { diff --git a/chrome/browser/tab_contents/navigation_controller.h b/chrome/browser/tab_contents/navigation_controller.h index 00b6b0f..3de03e5 100644 --- a/chrome/browser/tab_contents/navigation_controller.h +++ b/chrome/browser/tab_contents/navigation_controller.h @@ -11,6 +11,7 @@ #include "base/linked_ptr.h" #include "base/ref_counted.h" +#include "base/string16.h" #include "googleurl/src/gurl.h" #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/ssl/ssl_manager.h" @@ -360,7 +361,7 @@ class NavigationController { // titles and favicons. Since no request was made, this is the only info // we have about this page. This feature is used by web application clusters. bool LoadingURLLazily(); - const std::wstring& GetLazyTitle() const; + const string16& GetLazyTitle() const; const SkBitmap& GetLazyFavIcon() const; // Returns the identifier used by session restore. 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 { 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. }; diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 39ea878..7905364 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -149,7 +149,7 @@ const GURL& TabContents::GetURL() const { return entry ? entry->display_url() : GURL::EmptyGURL(); } -const std::wstring& TabContents::GetTitle() const { +const string16& TabContents::GetTitle() const { // We use the title for the last committed entry rather than a pending // navigation entry. For example, when the user types in a URL, we want to // keep the old page's title until the new load has committed and we get a new @@ -158,14 +158,14 @@ const std::wstring& TabContents::GetTitle() const { // their title, as they are not committed. NavigationEntry* entry = controller_->GetTransientEntry(); if (entry) - return entry->GetTitleForDisplay(); + return entry->GetTitleForDisplay(controller_); entry = controller_->GetLastCommittedEntry(); if (entry) - return entry->GetTitleForDisplay(); + return entry->GetTitleForDisplay(controller_); else if (controller_->LoadingURLLazily()) return controller_->GetLazyTitle(); - return EmptyWString(); + return EmptyString16(); } int32 TabContents::GetMaxPageID() { diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 41b47bf..e0ea375 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -180,7 +180,7 @@ class TabContents : public PageNavigator, // pending may be provisional (e.g., the navigation could result in a // download, in which case the URL would revert to what it was previously). const GURL& GetURL() const; - virtual const std::wstring& GetTitle() const; + virtual const string16& GetTitle() const; // Overridden by DOMUIContents. // The max PageID of any page that this TabContents has loaded. PageIDs // increase with each new page that is loaded by a tab. If this is a diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 1337b51..15b55e4 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -523,7 +523,7 @@ void WebContents::CreateShortcut() { // effectively cancel the pending install request. pending_install_.page_id = entry->page_id(); pending_install_.icon = GetFavIcon(); - pending_install_.title = GetTitle(); + pending_install_.title = UTF16ToWideHack(GetTitle()); pending_install_.url = GetURL(); if (pending_install_.callback_functor) { pending_install_.callback_functor->Cancel(); |