summaryrefslogtreecommitdiffstats
path: root/net/base/net_util.cc
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-04 18:37:31 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-04 18:37:31 +0000
commit630947caffc803a4cc96e3754af45aeedc957c0c (patch)
tree3950c0a479831c51a008a4ef210829a041498f33 /net/base/net_util.cc
parent055aedeb2134e49c10c3b3a3593cb8df768d737c (diff)
downloadchromium_src-630947caffc803a4cc96e3754af45aeedc957c0c.zip
chromium_src-630947caffc803a4cc96e3754af45aeedc957c0c.tar.gz
chromium_src-630947caffc803a4cc96e3754af45aeedc957c0c.tar.bz2
Enable localization of default downloaded filename.
Instead of localizing "download" string in net_util.cc, make a caller, download_manger, provide a localized string. BUG=25289 TEST=NetUtilTest.GetSuggestedFilename,DownloadManagerTest.TestDownloadFilename Original patch by hayato@google.com at: http://codereview.chromium.org/343014/show Review URL: http://codereview.chromium.org/367003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30971 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util.cc')
-rw-r--r--net/base/net_util.cc59
1 files changed, 32 insertions, 27 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 9715aa0e..85151e9 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1042,69 +1042,74 @@ std::wstring StripWWW(const std::wstring& text) {
FilePath GetSuggestedFilename(const GURL& url,
const std::string& content_disposition,
const std::string& referrer_charset,
- const char* default_name) {
- // TODO(rolandsteiner): as pointed out by darin in the code review, this is
- // hardly ideal. "download" should be translated, or another solution found.
- // (cf. http://code.google.com/p/chromium/issues/detail?id=25289)
- const char kFinalFallbackName[] = "download";
+ const FilePath& default_name) {
+ // We don't translate this fallback string, "download". If localization is
+ // needed, the caller should provide localized fallback default_name.
+ static const FilePath::CharType kFinalFallbackName[] =
+ FILE_PATH_LITERAL("download");
// about: and data: URLs don't have file names, but esp. data: URLs may
// contain parts that look like ones (i.e., contain a slash).
// Therefore we don't attempt to divine a file name out of them.
if (url.SchemeIs("about") || url.SchemeIs("data")) {
- return FilePath(UTF8ToFilePathString(
- default_name && default_name[0] ? default_name : kFinalFallbackName));
+ return default_name.empty() ? FilePath(kFinalFallbackName) : default_name;
}
- std::string filename = GetFileNameFromCD(content_disposition,
- referrer_charset);
+ const std::string filename_from_cd = GetFileNameFromCD(content_disposition,
+ referrer_charset);
+#if defined(OS_WIN)
+ FilePath::StringType filename = UTF8ToWide(filename_from_cd);
+#elif defined(OS_POSIX)
+ FilePath::StringType filename = filename_from_cd;
+#endif
+
if (!filename.empty()) {
// Remove any path information the server may have sent, take the name
// only.
-#if defined(OS_WIN)
- filename = UTF16ToUTF8(FilePath(UTF8ToUTF16(filename)).BaseName().value());
-#else
filename = FilePath(filename).BaseName().value();
-#endif
// Next, remove "." from the beginning and end of the file name to avoid
// tricks with hidden files, "..", and "."
- TrimString(filename, ".", &filename);
+ TrimString(filename, FILE_PATH_LITERAL("."), &filename);
}
if (filename.empty()) {
if (url.is_valid()) {
- filename = UnescapeURLComponent(
+ const std::string unescaped_url_filename = UnescapeURLComponent(
url.ExtractFileName(),
UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
+#if defined(OS_WIN)
+ filename = UTF8ToWide(unescaped_url_filename);
+#elif defined(OS_POSIX)
+ filename = unescaped_url_filename;
+#endif
}
}
// Trim '.' once more.
- TrimString(filename, ".", &filename);
+ TrimString(filename, FILE_PATH_LITERAL("."), &filename);
// If there's no filename or it gets trimed to be empty, use
// the URL hostname or default_name
if (filename.empty()) {
- if (default_name && default_name[0]) {
- filename = default_name;
+ if (!default_name.empty()) {
+ filename = default_name.value();
} else if (url.is_valid()) {
// Some schemes (e.g. file) do not have a hostname. Even though it's
// not likely to reach here, let's hardcode the last fallback name.
// TODO(jungshik) : Decode a 'punycoded' IDN hostname. (bug 1264451)
- filename = url.host().empty() ? std::string(kFinalFallbackName)
- : url.host();
+ filename = url.host().empty() ? kFinalFallbackName :
+#if defined(OS_WIN)
+ UTF8ToWide(url.host());
+#elif defined(OS_POSIX)
+ url.host();
+#endif
} else {
NOTREACHED();
}
}
-#if defined(OS_WIN)
- FilePath::StringType file_path_string = UTF8ToWide(filename);
-#else
- std::string& file_path_string = filename;
-#endif
- file_util::ReplaceIllegalCharactersInPath(&file_path_string, '-');
- return FilePath(file_path_string);
+ file_util::ReplaceIllegalCharactersInPath(&filename, '-');
+ return FilePath(filename);
}
bool IsPortAllowedByDefault(int port) {