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

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

Issue 7005011: Fix bug 79905: Drag and drop of "DownloadURL" type ignores specified filename for data URLs. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 for (int i = 0; i < arraysize(magic_names); ++i) { 161 for (int i = 0; i < arraysize(magic_names); ++i) {
162 if (filename_lower == magic_names[i]) 162 if (filename_lower == magic_names[i])
163 return true; 163 return true;
164 } 164 }
165 165
166 return false; 166 return false;
167 } 167 }
168 #endif // OS_WIN 168 #endif // OS_WIN
169 169
170 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.
171 const std::string& content_disposition,
172 const std::string& referrer_charset,
173 const std::string& suggested_name,
174 const std::string& mime_type,
175 FilePath* generated_name) {
176
177 string16 default_file_name(
178 l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME));
179
180 string16 new_name = net::GetSuggestedFilename(GURL(url),
181 content_disposition,
182 referrer_charset,
183 suggested_name,
184 default_file_name);
185
186 // TODO(evan): this code is totally wrong -- we should just generate
187 // Unicode filenames and do all this encoding switching at the end.
188 // However, I'm just shuffling wrong code around, at least not adding
189 // to it.
190 #if defined(OS_WIN)
191 *generated_name = FilePath(new_name);
192 #else
193 *generated_name = FilePath(
194 base::SysWideToNativeMB(UTF16ToWide(new_name)));
195 #endif
196
197 DCHECK(!generated_name->empty());
198
199 GenerateSafeFileName(mime_type, generated_name);
200 }
201
170 } // namespace 202 } // namespace
171 203
172 // Download temporary file creation -------------------------------------------- 204 // Download temporary file creation --------------------------------------------
173 205
174 class DefaultDownloadDirectory { 206 class DefaultDownloadDirectory {
175 public: 207 public:
176 const FilePath& path() const { return path_; } 208 const FilePath& path() const { return path_; }
177 private: 209 private:
178 DefaultDownloadDirectory() { 210 DefaultDownloadDirectory() {
179 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { 211 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 283
252 void GenerateFileNameFromInfo(DownloadCreateInfo* info, 284 void GenerateFileNameFromInfo(DownloadCreateInfo* info,
253 FilePath* generated_name) { 285 FilePath* generated_name) {
254 GenerateFileName(GURL(info->url()), 286 GenerateFileName(GURL(info->url()),
255 info->content_disposition, 287 info->content_disposition,
256 info->referrer_charset, 288 info->referrer_charset,
257 info->mime_type, 289 info->mime_type,
258 generated_name); 290 generated_name);
259 } 291 }
260 292
293 void GenerateFileNameFromSuggestedName(const GURL& url,
294 const std::string& suggested_name,
295 const std::string& mime_type,
296 FilePath* generated_name) {
297 GenerateFileNameInternal(url, std::string(), std::string(),
298 suggested_name, mime_type, generated_name);
299 }
300
261 void GenerateFileName(const GURL& url, 301 void GenerateFileName(const GURL& url,
262 const std::string& content_disposition, 302 const std::string& content_disposition,
263 const std::string& referrer_charset, 303 const std::string& referrer_charset,
264 const std::string& mime_type, 304 const std::string& mime_type,
265 FilePath* generated_name) { 305 FilePath* generated_name) {
266 string16 default_file_name( 306 GenerateFileNameInternal(url, content_disposition, referrer_charset,
267 l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME)); 307 std::string(), mime_type, generated_name);
268
269 string16 new_name = net::GetSuggestedFilename(GURL(url),
270 content_disposition,
271 referrer_charset,
272 default_file_name);
273
274 // TODO(evan): this code is totally wrong -- we should just generate
275 // Unicode filenames and do all this encoding switching at the end.
276 // However, I'm just shuffling wrong code around, at least not adding
277 // to it.
278 #if defined(OS_WIN)
279 *generated_name = FilePath(new_name);
280 #else
281 *generated_name = FilePath(
282 base::SysWideToNativeMB(UTF16ToWide(new_name)));
283 #endif
284
285 DCHECK(!generated_name->empty());
286
287 GenerateSafeFileName(mime_type, generated_name);
288 } 308 }
289 309
290 void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) { 310 void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) {
291 // Make sure we get the right file extension 311 // Make sure we get the right file extension
292 FilePath::StringType extension; 312 FilePath::StringType extension;
293 GenerateExtension(*file_name, mime_type, &extension); 313 GenerateExtension(*file_name, mime_type, &extension);
294 *file_name = file_name->ReplaceExtension(extension); 314 *file_name = file_name->ReplaceExtension(extension);
295 315
296 #if defined(OS_WIN) 316 #if defined(OS_WIN)
297 // Prepend "_" to the file name if it's a reserved name 317 // Prepend "_" to the file name if it's a reserved name
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // Extensions that are not from the gallery are considered dangerous. 921 // Extensions that are not from the gallery are considered dangerous.
902 ExtensionService* service = profile->GetExtensionService(); 922 ExtensionService* service = profile->GetExtensionService();
903 if (!service || 923 if (!service ||
904 !service->IsDownloadFromGallery(info->url(), info->referrer_url)) 924 !service->IsDownloadFromGallery(info->url(), info->referrer_url))
905 return true; 925 return true;
906 } 926 }
907 return false; 927 return false;
908 } 928 }
909 929
910 } // namespace download_util 930 } // namespace download_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698