summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc3
-rw-r--r--chrome/browser/download/download_util.cc28
-rw-r--r--chrome/browser/download/download_util_unittest.cc7
-rw-r--r--chrome/browser/download/save_package.cc20
-rw-r--r--chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm5
-rw-r--r--chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc3
-rw-r--r--net/base/net_util.cc56
-rw-r--r--net/base/net_util.h4
-rw-r--r--net/base/net_util_unittest.cc19
-rw-r--r--ui/base/dragdrop/os_exchange_data_provider_win.cc4
-rw-r--r--webkit/glue/weburlloader_impl.cc4
11 files changed, 79 insertions, 74 deletions
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index 0117b65..e26f943 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -430,8 +430,7 @@ bool CanPasteFromClipboard(const BookmarkNode* node) {
string16 GetNameForURL(const GURL& url) {
if (url.is_valid()) {
- return WideToUTF16(net::GetSuggestedFilename(
- url, std::string(), std::string(), FilePath()).ToWStringHack());
+ return net::GetSuggestedFilename(url, "", "", string16());
} else {
return l10n_util::GetStringUTF16(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME);
}
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index c958213..9fa60b3 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -217,20 +217,24 @@ void GenerateFileName(const GURL& url,
const std::string& referrer_charset,
const std::string& mime_type,
FilePath* generated_name) {
-#if defined(OS_WIN)
- FilePath default_file_path(
+ string16 default_file_name(
l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME));
-#elif defined(OS_POSIX)
- std::string default_file =
- l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
- FilePath default_file_path(
- base::SysWideToNativeMB(base::SysUTF8ToWide(default_file)));
-#endif
- *generated_name = net::GetSuggestedFilename(GURL(url),
- content_disposition,
- referrer_charset,
- default_file_path);
+ string16 new_name = net::GetSuggestedFilename(GURL(url),
+ content_disposition,
+ referrer_charset,
+ default_file_name);
+
+ // TODO(evan): this code is totally wrong -- we should just generate
+ // Unicode filenames and do all this encoding switching at the end.
+ // However, I'm just shuffling wrong code around, at least not adding
+ // to it.
+#if defined(OS_WIN)
+ *generated_name = FilePath(new_name);
+#else
+ *generated_name = FilePath(
+ base::SysWideToNativeMB(UTF16ToWide(new_name)));
+#endif
DCHECK(!generated_name->empty());
diff --git a/chrome/browser/download/download_util_unittest.cc b/chrome/browser/download/download_util_unittest.cc
index 1a905b1..f778ea8 100644
--- a/chrome/browser/download/download_util_unittest.cc
+++ b/chrome/browser/download/download_util_unittest.cc
@@ -188,11 +188,7 @@ const struct {
{"filename=..\\foo.txt",
"http://www.evil.com/..\\foo.txt",
"text/plain",
-#if defined(OS_WIN)
L"foo.txt"
-#else
- L"\\foo.txt"
-#endif
},
{"filename=.hidden",
@@ -437,7 +433,8 @@ TEST(DownloadUtilTest, GenerateFileName) {
std::string locale = setlocale(LC_CTYPE, NULL);
StringToLowerASCII(&locale);
EXPECT_NE(std::string::npos, locale.find("utf-8"))
- << "Your locale must be set to UTF-8 for this test to pass!";
+ << "Your locale (" << locale << ") must be set to UTF-8 "
+ << "for this test to pass!";
#endif
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGenerateFileNameTestCases); ++i) {
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index e2cebcc..53fc1fe 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -14,6 +14,7 @@
#include "base/stl_util-inl.h"
#include "base/string_piece.h"
#include "base/string_split.h"
+#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "base/task.h"
#include "base/threading/thread.h"
@@ -62,8 +63,7 @@ int g_save_package_id = 0;
// Default name which will be used when we can not get proper name from
// resource URL.
-const FilePath::CharType kDefaultSaveName[] =
- FILE_PATH_LITERAL("saved_resource");
+const char kDefaultSaveName[] = "saved_resource";
const FilePath::CharType kDefaultHtmlExtension[] =
#if defined(OS_WIN)
@@ -375,8 +375,20 @@ bool SavePackage::GenerateFileName(const std::string& disposition,
FilePath::StringType* generated_name) {
// TODO(jungshik): Figure out the referrer charset when having one
// makes sense and pass it to GetSuggestedFilename.
- FilePath file_path = net::GetSuggestedFilename(url, disposition, "",
- FilePath(kDefaultSaveName));
+ string16 suggested_name =
+ net::GetSuggestedFilename(url, disposition, "",
+ ASCIIToUTF16(kDefaultSaveName));
+
+ // TODO(evan): this code is totally wrong -- we should just generate
+ // Unicode filenames and do all this encoding switching at the end.
+ // However, I'm just shuffling wrong code around, at least not adding
+ // to it.
+#if defined(OS_WIN)
+ FilePath file_path = FilePath(suggested_name);
+#else
+ FilePath file_path = FilePath(
+ base::SysWideToNativeMB(UTF16ToWide(suggested_name)));
+#endif
DCHECK(!file_path.empty());
FilePath::StringType pure_file_name =
diff --git a/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm b/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm
index 66c8f44..d33fddf 100644
--- a/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm
+++ b/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm
@@ -48,7 +48,10 @@ FilePath GetFileNameFromDragData(const WebDropData& drop_data) {
if (file_name.empty()) {
// Retrieve the name from the URL.
- file_name = net::GetSuggestedFilename(drop_data.url, "", "", FilePath());
+ string16 suggested_filename =
+ net::GetSuggestedFilename(drop_data.url, "", "", string16());
+ file_name = FilePath(
+ [SysUTF16ToNSString(suggested_filename) fileSystemRepresentation]);
}
file_name = file_name.ReplaceExtension([SysUTF16ToNSString(
diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc
index 64265e0..2590c69 100644
--- a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc
+++ b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc
@@ -231,7 +231,8 @@ void TabContentsDragWin::PrepareDragForFileContents(
file_name = file_name.BaseName().RemoveExtension();
if (file_name.value().empty()) {
// Retrieve the name from the URL.
- file_name = net::GetSuggestedFilename(drop_data.url, "", "", FilePath());
+ file_name = FilePath(
+ net::GetSuggestedFilename(drop_data.url, "", "", string16()));
if (file_name.value().size() + drop_data.file_extension.size() + 1 >
MAX_PATH) {
file_name = FilePath(file_name.value().substr(
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 99c6ea8..fff02a9 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1377,38 +1377,38 @@ string16 StripWWW(const string16& text) {
text.substr(www.length()) : text;
}
-FilePath GetSuggestedFilename(const GURL& url,
+string16 GetSuggestedFilename(const GURL& url,
const std::string& content_disposition,
const std::string& referrer_charset,
- const FilePath& default_name) {
+ const string16& default_name) {
+ // TODO: this function to be updated to match the httpbis recommendations.
+ // Talk to abarth for the latest news.
+
// 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");
+ static const char* kFinalFallbackName = "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 default_name.empty() ? FilePath(kFinalFallbackName) : default_name;
+ return default_name.empty() ? ASCIIToUTF16(kFinalFallbackName)
+ : default_name;
}
- 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
+ std::string filename = GetFileNameFromCD(content_disposition,
+ referrer_charset);
if (!filename.empty()) {
// Remove any path information the server may have sent, take the name
// only.
- filename = FilePath(filename).BaseName().value();
+ std::string::size_type slashpos = filename.find_last_of("/\\");
+ if (slashpos != std::string::npos)
+ filename = filename.substr(slashpos + 1);
// Next, remove "." from the beginning and end of the file name to avoid
// tricks with hidden files, "..", and "."
- TrimString(filename, FILE_PATH_LITERAL("."), &filename);
+ TrimString(filename, ".", &filename);
}
if (filename.empty()) {
if (url.is_valid()) {
@@ -1426,18 +1426,14 @@ FilePath GetSuggestedFilename(const GURL& url,
&decoded_filename);
}
-#if defined(OS_WIN)
- filename = UTF8ToWide(decoded_filename);
-#elif defined(OS_POSIX)
filename = decoded_filename;
-#endif
}
}
#if defined(OS_WIN)
{ // Handle CreateFile() stripping trailing dots and spaces on filenames
// http://support.microsoft.com/kb/115827
- std::string::size_type pos = filename.find_last_not_of(L" .");
+ std::string::size_type pos = filename.find_last_not_of(" .");
if (pos == std::string::npos)
filename.resize(0);
else
@@ -1445,30 +1441,32 @@ FilePath GetSuggestedFilename(const GURL& url,
}
#endif
// Trim '.' once more.
- TrimString(filename, FILE_PATH_LITERAL("."), &filename);
+ TrimString(filename, ".", &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.empty()) {
- filename = default_name.value();
+ return default_name;
} 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() ? kFinalFallbackName :
-#if defined(OS_WIN)
- UTF8ToWide(url.host());
-#elif defined(OS_POSIX)
- url.host();
-#endif
+ filename = url.host().empty() ? kFinalFallbackName : url.host();
} else {
NOTREACHED();
}
}
- file_util::ReplaceIllegalCharactersInPath(&filename, '-');
- return FilePath(filename);
+#if defined(OS_WIN)
+ string16 path = UTF8ToUTF16(filename);
+ file_util::ReplaceIllegalCharactersInPath(&path, '-');
+ return path;
+#else
+ std::string path = filename;
+ file_util::ReplaceIllegalCharactersInPath(&path, '-');
+ return UTF8ToUTF16(path);
+#endif
}
bool IsPortAllowedByDefault(int port) {
diff --git a/net/base/net_util.h b/net/base/net_util.h
index bb145e0..f53ee7e 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -259,10 +259,10 @@ string16 StripWWW(const string16& text);
// file:///). referrer_charset is used as one of charsets
// to interpret a raw 8bit string in C-D header (after interpreting
// as UTF-8 fails). See the comment for GetFilenameFromCD for more details.
-FilePath GetSuggestedFilename(const GURL& url,
+string16 GetSuggestedFilename(const GURL& url,
const std::string& content_disposition,
const std::string& referrer_charset,
- const FilePath& default_name);
+ const string16& default_name);
// Checks the given port against a list of ports which are restricted by
// default. Returns true if the port is allowed, false if it is restricted.
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 77d3a00..bf51f1c 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -1214,21 +1214,12 @@ TEST(NetUtilTest, GetSuggestedFilename) {
#endif
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
-#if defined(OS_WIN)
- FilePath default_name(test_cases[i].default_filename);
-#else
- FilePath default_name(
- base::SysWideToNativeMB(test_cases[i].default_filename));
-#endif
- FilePath filename = net::GetSuggestedFilename(
+ std::wstring default_name = test_cases[i].default_filename;
+ string16 filename = net::GetSuggestedFilename(
GURL(test_cases[i].url), test_cases[i].content_disp_header,
- test_cases[i].referrer_charset, default_name);
-#if defined(OS_WIN)
- EXPECT_EQ(std::wstring(test_cases[i].expected_filename), filename.value())
-#else
- EXPECT_EQ(base::SysWideToNativeMB(test_cases[i].expected_filename),
- filename.value())
-#endif
+ test_cases[i].referrer_charset, WideToUTF16(default_name));
+ EXPECT_EQ(std::wstring(test_cases[i].expected_filename),
+ UTF16ToWide(filename))
<< "Iteration " << i << ": " << test_cases[i].url;
}
}
diff --git a/ui/base/dragdrop/os_exchange_data_provider_win.cc b/ui/base/dragdrop/os_exchange_data_provider_win.cc
index 657a917..22a4e62 100644
--- a/ui/base/dragdrop/os_exchange_data_provider_win.cc
+++ b/ui/base/dragdrop/os_exchange_data_provider_win.cc
@@ -844,8 +844,8 @@ static void CreateValidFileNameFromTitle(const GURL& url,
std::wstring* validated) {
if (title.empty()) {
if (url.is_valid()) {
- *validated = net::GetSuggestedFilename(
- url, std::string(), std::string(), FilePath()).ToWStringHack();
+ *validated = UTF16ToWide(
+ net::GetSuggestedFilename(url, "", "", string16()));
} else {
// Nothing else can be done, just use a default.
*validated =
diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc
index d22b509..8904457 100644
--- a/webkit/glue/weburlloader_impl.cc
+++ b/webkit/glue/weburlloader_impl.cc
@@ -244,8 +244,8 @@ void PopulateURLResponse(
// pass it to GetSuggestedFilename.
std::string value;
if (headers->EnumerateHeader(NULL, "content-disposition", &value)) {
- response->setSuggestedFileName(FilePathToWebString(
- net::GetSuggestedFilename(url, value, "", FilePath())));
+ response->setSuggestedFileName(
+ net::GetSuggestedFilename(url, value, "", string16()));
}
Time time_val;