Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Side by Side Diff: chrome/browser/download/download_util.cc

Issue 6241001: wstring: make net::GetSuggestedFilename return utf-16 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Download utility implementation 5 // Download utility implementation
6 6
7 #include "chrome/browser/download/download_util.h" 7 #include "chrome/browser/download/download_util.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <shobjidl.h> 10 #include <shobjidl.h>
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 info->referrer_charset, 210 info->referrer_charset,
211 info->mime_type, 211 info->mime_type,
212 generated_name); 212 generated_name);
213 } 213 }
214 214
215 void GenerateFileName(const GURL& url, 215 void GenerateFileName(const GURL& url,
216 const std::string& content_disposition, 216 const std::string& content_disposition,
217 const std::string& referrer_charset, 217 const std::string& referrer_charset,
218 const std::string& mime_type, 218 const std::string& mime_type,
219 FilePath* generated_name) { 219 FilePath* generated_name) {
220 string16 default_file_name(
221 l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME));
222
223 string16 new_name = net::GetSuggestedFilename(GURL(url),
224 content_disposition,
225 referrer_charset,
226 default_file_name);
227
228 // TODO(evan): this code is totally wrong -- we should just generate
229 // Unicode filenames and do all this encoding switching at the end.
230 // However, I'm just shuffling wrong code around, at least not adding
231 // to it.
220 #if defined(OS_WIN) 232 #if defined(OS_WIN)
221 FilePath default_file_path( 233 *generated_name = FilePath(new_name);
222 l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME)); 234 #else
223 #elif defined(OS_POSIX) 235 *generated_name = FilePath(
224 std::string default_file = 236 base::SysWideToNativeMB(UTF16ToWide(new_name)));
225 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
226 FilePath default_file_path(
227 base::SysWideToNativeMB(base::SysUTF8ToWide(default_file)));
228 #endif 237 #endif
229 238
230 *generated_name = net::GetSuggestedFilename(GURL(url),
231 content_disposition,
232 referrer_charset,
233 default_file_path);
234
235 DCHECK(!generated_name->empty()); 239 DCHECK(!generated_name->empty());
236 240
237 GenerateSafeFileName(mime_type, generated_name); 241 GenerateSafeFileName(mime_type, generated_name);
238 } 242 }
239 243
240 void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) { 244 void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) {
241 // Make sure we get the right file extension 245 // Make sure we get the right file extension
242 FilePath::StringType extension; 246 FilePath::StringType extension;
243 GenerateExtension(*file_name, mime_type, &extension); 247 GenerateExtension(*file_name, mime_type, &extension);
244 *file_name = file_name->ReplaceExtension(extension); 248 *file_name = file_name->ReplaceExtension(extension);
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { 776 !service->IsDownloadFromGallery(info->url, info->referrer_url)) {
773 // Extensions that are not from the gallery are considered dangerous. 777 // Extensions that are not from the gallery are considered dangerous.
774 return true; 778 return true;
775 } 779 }
776 } 780 }
777 781
778 return false; 782 return false;
779 } 783 }
780 784
781 } // namespace download_util 785 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.cc ('k') | chrome/browser/download/download_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698