summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 21:27:43 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 21:27:43 +0000
commit9bfcfd2b2bc2f39b7606f1c9afa44227e738cb79 (patch)
treeb066cda80ee79034a31ee33b62ac1d5c19d45715 /content
parent5c458e1a5d1bb1b48ad8a60e4e3c541467ba5a20 (diff)
downloadchromium_src-9bfcfd2b2bc2f39b7606f1c9afa44227e738cb79.zip
chromium_src-9bfcfd2b2bc2f39b7606f1c9afa44227e738cb79.tar.gz
chromium_src-9bfcfd2b2bc2f39b7606f1c9afa44227e738cb79.tar.bz2
Revert 76792 - fix display of filenames in file:/// URLs
It breaks the following tests: BrowserTest.NoTitle and AutomationProxyTest2.GetTabTitle The code attempted to shorten file:/// URLs to just the filename when displayed as the title of a page. But that appears to have regressed sometime in the past. This shortening is consistent with how we display the title of images (which are like "foo.png (123x456)".) Chrome does a poor job of displaying longer titles (most of the tab title ends up being "file:///C:/" anyway). In any case, using a FilePath to get the filename from a URL may not have even worked on Windows, where the path separator is a backslash. It appears Glen wrote the original code, Brett may be the one to have regressed it in a refactor, and I probably broke it worse in a FilePath refactor. BUG=69467 TEST=load a text file via a file: URL; tab title is just the file name Review URL: http://codereview.chromium.org/6591127 TBR=evan@chromium.org Review URL: http://codereview.chromium.org/6614025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76809 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/tab_contents/navigation_controller.cc11
-rw-r--r--content/browser/tab_contents/navigation_entry.cc8
-rw-r--r--content/browser/tab_contents/navigation_entry_unittest.cc5
3 files changed, 11 insertions, 13 deletions
diff --git a/content/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc
index 9eec1ad..7601d23 100644
--- a/content/browser/tab_contents/navigation_controller.cc
+++ b/content/browser/tab_contents/navigation_controller.cc
@@ -243,6 +243,17 @@ 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 535f463..ec35a9f 100644
--- a/content/browser/tab_contents/navigation_entry.cc
+++ b/content/browser/tab_contents/navigation_entry.cc
@@ -94,14 +94,6 @@ 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 9d5edc83..4b5bfb0 100644
--- a/content/browser/tab_contents/navigation_entry_unittest.cc
+++ b/content/browser/tab_contents/navigation_entry_unittest.cc
@@ -62,11 +62,6 @@ 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(""));