Chromium Code Reviews| Index: chrome/browser/download/download_util.cc |
| =================================================================== |
| --- chrome/browser/download/download_util.cc (revision 85116) |
| +++ chrome/browser/download/download_util.cc (working copy) |
| @@ -167,6 +167,38 @@ |
| } |
| #endif // OS_WIN |
| +void GenerateFileNameInternal(const GURL& url, |
|
asanka
2011/05/13 13:32:24
Can you also change GenerateFileNameFromInfo() to
jianli
2011/05/17 00:10:44
Done.
|
| + const std::string& content_disposition, |
| + const std::string& referrer_charset, |
| + const std::string& suggested_name, |
| + const std::string& mime_type, |
| + FilePath* generated_name) { |
| + |
| + string16 default_file_name( |
| + l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
| + |
| + string16 new_name = net::GetSuggestedFilename(GURL(url), |
| + content_disposition, |
| + referrer_charset, |
| + suggested_name, |
| + 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()); |
| + |
| + GenerateSafeFileName(mime_type, generated_name); |
| +} |
| + |
| } // namespace |
| // Download temporary file creation -------------------------------------------- |
| @@ -258,33 +290,21 @@ |
| generated_name); |
| } |
| +void GenerateFileNameFromSuggestedName(const GURL& url, |
| + const std::string& suggested_name, |
| + const std::string& mime_type, |
| + FilePath* generated_name) { |
| + GenerateFileNameInternal(url, std::string(), std::string(), |
| + suggested_name, mime_type, generated_name); |
| +} |
| + |
| void GenerateFileName(const GURL& url, |
| const std::string& content_disposition, |
| const std::string& referrer_charset, |
| const std::string& mime_type, |
| FilePath* generated_name) { |
| - string16 default_file_name( |
| - l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
| - |
| - 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()); |
| - |
| - GenerateSafeFileName(mime_type, generated_name); |
| + GenerateFileNameInternal(url, content_disposition, referrer_charset, |
| + std::string(), mime_type, generated_name); |
| } |
| void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) { |