OLD | NEW |
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 #include "content/browser/download/save_package.h" | 5 #include "content/browser/download/save_package.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 pure_file_name->clear(); | 358 pure_file_name->clear(); |
359 return false; | 359 return false; |
360 } | 360 } |
361 | 361 |
362 // Generate name for saving resource. | 362 // Generate name for saving resource. |
363 bool SavePackage::GenerateFileName(const std::string& disposition, | 363 bool SavePackage::GenerateFileName(const std::string& disposition, |
364 const GURL& url, | 364 const GURL& url, |
365 bool need_html_ext, | 365 bool need_html_ext, |
366 FilePath::StringType* generated_name) { | 366 FilePath::StringType* generated_name) { |
367 // TODO(jungshik): Figure out the referrer charset when having one | 367 // TODO(jungshik): Figure out the referrer charset when having one |
368 // makes sense and pass it to GetSuggestedFilename. | 368 // makes sense and pass it to GenerateFileName. |
369 string16 suggested_name = | 369 FilePath file_path = net::GenerateFileName(url, disposition, "", "", "", |
370 net::GetSuggestedFilename(url, disposition, "", "", | 370 ASCIIToUTF16(kDefaultSaveName)); |
371 ASCIIToUTF16(kDefaultSaveName)); | |
372 | |
373 // TODO(evan): this code is totally wrong -- we should just generate | |
374 // Unicode filenames and do all this encoding switching at the end. | |
375 // However, I'm just shuffling wrong code around, at least not adding | |
376 // to it. | |
377 #if defined(OS_WIN) | |
378 FilePath file_path = FilePath(suggested_name); | |
379 #else | |
380 FilePath file_path = FilePath( | |
381 base::SysWideToNativeMB(UTF16ToWide(suggested_name))); | |
382 #endif | |
383 | 371 |
384 DCHECK(!file_path.empty()); | 372 DCHECK(!file_path.empty()); |
385 FilePath::StringType pure_file_name = | 373 FilePath::StringType pure_file_name = |
386 file_path.RemoveExtension().BaseName().value(); | 374 file_path.RemoveExtension().BaseName().value(); |
387 FilePath::StringType file_name_ext = file_path.Extension(); | 375 FilePath::StringType file_name_ext = file_path.Extension(); |
388 | 376 |
389 // If it is HTML resource, use ".htm{l,}" as its extension. | 377 // If it is HTML resource, use ".htm{l,}" as its extension. |
390 if (need_html_ext) { | 378 if (need_html_ext) { |
391 file_name_ext = FILE_PATH_LITERAL("."); | 379 file_name_ext = FILE_PATH_LITERAL("."); |
392 file_name_ext.append(kDefaultHtmlExtension); | 380 file_name_ext.append(kDefaultHtmlExtension); |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 | 1215 |
1228 download_manager_->delegate()->ChooseSavePath( | 1216 download_manager_->delegate()->ChooseSavePath( |
1229 AsWeakPtr(), suggested_path, can_save_as_complete); | 1217 AsWeakPtr(), suggested_path, can_save_as_complete); |
1230 } | 1218 } |
1231 | 1219 |
1232 // Called after the save file dialog box returns. | 1220 // Called after the save file dialog box returns. |
1233 void SavePackage::OnPathPicked(const FilePath& final_name, | 1221 void SavePackage::OnPathPicked(const FilePath& final_name, |
1234 SavePackageType type) { | 1222 SavePackageType type) { |
1235 // Ensure the filename is safe. | 1223 // Ensure the filename is safe. |
1236 saved_main_file_path_ = final_name; | 1224 saved_main_file_path_ = final_name; |
1237 download_util::GenerateSafeFileName(tab_contents()->contents_mime_type(), | 1225 // TODO(asanka): This call may block on IO and shouldn't be made |
1238 &saved_main_file_path_); | 1226 // from the UI thread. See http://crbug.com/61827. |
| 1227 net::GenerateSafeFileName(tab_contents()->contents_mime_type(), |
| 1228 &saved_main_file_path_); |
1239 | 1229 |
1240 saved_main_directory_path_ = saved_main_file_path_.DirName(); | 1230 saved_main_directory_path_ = saved_main_file_path_.DirName(); |
1241 save_type_ = type; | 1231 save_type_ = type; |
1242 if (save_type_ == SavePackage::SAVE_AS_COMPLETE_HTML) { | 1232 if (save_type_ == SavePackage::SAVE_AS_COMPLETE_HTML) { |
1243 // Make new directory for saving complete file. | 1233 // Make new directory for saving complete file. |
1244 saved_main_directory_path_ = saved_main_directory_path_.Append( | 1234 saved_main_directory_path_ = saved_main_directory_path_.Append( |
1245 saved_main_file_path_.RemoveExtension().BaseName().value() + | 1235 saved_main_file_path_.RemoveExtension().BaseName().value() + |
1246 FILE_PATH_LITERAL("_files")); | 1236 FILE_PATH_LITERAL("_files")); |
1247 } | 1237 } |
1248 | 1238 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 StopObservation(); | 1280 StopObservation(); |
1291 } | 1281 } |
1292 | 1282 |
1293 void SavePackage::FinalizeDownloadEntry() { | 1283 void SavePackage::FinalizeDownloadEntry() { |
1294 DCHECK(download_); | 1284 DCHECK(download_); |
1295 DCHECK(download_manager_); | 1285 DCHECK(download_manager_); |
1296 | 1286 |
1297 download_manager_->SavePageDownloadFinished(download_); | 1287 download_manager_->SavePageDownloadFinished(download_); |
1298 StopObservation(); | 1288 StopObservation(); |
1299 } | 1289 } |
OLD | NEW |