diff options
Diffstat (limited to 'content')
| -rw-r--r-- | content/browser/tab_contents/navigation_controller.cc | 11 | ||||
| -rw-r--r-- | content/browser/tab_contents/navigation_entry.cc | 8 | ||||
| -rw-r--r-- | content/browser/tab_contents/navigation_entry_unittest.cc | 5 |
3 files changed, 13 insertions, 11 deletions
diff --git a/content/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc index 7601d23..9eec1ad 100644 --- a/content/browser/tab_contents/navigation_controller.cc +++ b/content/browser/tab_contents/navigation_controller.cc @@ -243,17 +243,6 @@ NavigationEntry* NavigationController::CreateNavigationEntry( entry->set_virtual_url(url); entry->set_user_typed_url(url); entry->set_update_virtual_url_with_url(reverse_on_redirect); - if (url.SchemeIsFile()) { - // Use the filename as the title, not the full path. - // We need to call FormatUrl() to perform URL de-escaping; - // it's a bit ugly to grab the filename out of the resulting string. - std::string languages = - profile->GetPrefs()->GetString(prefs::kAcceptLanguages); - std::wstring formatted = UTF16ToWideHack(net::FormatUrl(url, languages)); - std::wstring filename = - FilePath::FromWStringHack(formatted).BaseName().ToWStringHack(); - entry->set_title(WideToUTF16Hack(filename)); - } return entry; } diff --git a/content/browser/tab_contents/navigation_entry.cc b/content/browser/tab_contents/navigation_entry.cc index ec35a9f..535f463 100644 --- a/content/browser/tab_contents/navigation_entry.cc +++ b/content/browser/tab_contents/navigation_entry.cc @@ -94,6 +94,14 @@ const string16& NavigationEntry::GetTitleForDisplay( } else if (!url_.is_empty()) { title = net::FormatUrl(url_, languages); } + + // For file:// URLs use the filename as the title, not the full path. + if (url_.SchemeIsFile()) { + string16::size_type slashpos = title.rfind('/'); + if (slashpos != string16::npos) + title = title.substr(slashpos + 1); + } + ui::ElideString(title, chrome::kMaxTitleChars, &cached_display_title_); return cached_display_title_; } diff --git a/content/browser/tab_contents/navigation_entry_unittest.cc b/content/browser/tab_contents/navigation_entry_unittest.cc index 4b5bfb0..9d5edc83 100644 --- a/content/browser/tab_contents/navigation_entry_unittest.cc +++ b/content/browser/tab_contents/navigation_entry_unittest.cc @@ -62,6 +62,11 @@ TEST_F(NavigationEntryTest, NavigationEntryURLs) { EXPECT_EQ(ASCIIToUTF16("www.google.com"), entry1_.get()->GetTitleForDisplay("")); + // file:/// URLs should only show the filename. + entry1_.get()->set_url(GURL("file:///foo/bar baz.txt")); + EXPECT_EQ(ASCIIToUTF16("bar baz.txt"), + entry1_.get()->GetTitleForDisplay("")); + // Title affects GetTitleForDisplay entry1_.get()->set_title(ASCIIToUTF16("Google")); EXPECT_EQ(ASCIIToUTF16("Google"), entry1_.get()->GetTitleForDisplay("")); |
