| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/download/save_package.h" | 5 #include "chrome/browser/download/save_package.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 9 #include "base/i18n/file_util_icu.h" | 10 #include "base/i18n/file_util_icu.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
| 13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 14 #include "base/task.h" | 15 #include "base/task.h" |
| 15 #include "base/thread.h" | 16 #include "base/thread.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/download/download_item_model.h" | 18 #include "chrome/browser/download/download_item_model.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 explicit SavePackageParam(const std::string& mime_type) | 60 explicit SavePackageParam(const std::string& mime_type) |
| 60 : current_tab_mime_type(mime_type), | 61 : current_tab_mime_type(mime_type), |
| 61 save_type(SavePackage::SAVE_TYPE_UNKNOWN) { | 62 save_type(SavePackage::SAVE_TYPE_UNKNOWN) { |
| 62 } | 63 } |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 namespace { | 66 namespace { |
| 66 | 67 |
| 67 // Default name which will be used when we can not get proper name from | 68 // Default name which will be used when we can not get proper name from |
| 68 // resource URL. | 69 // resource URL. |
| 69 const char kDefaultSaveName[] = "saved_resource"; | 70 const FilePath::CharType kDefaultSaveName[] = |
| 71 FILE_PATH_LITERAL("saved_resource"); |
| 70 | 72 |
| 71 const FilePath::CharType kDefaultHtmlExtension[] = | 73 const FilePath::CharType kDefaultHtmlExtension[] = |
| 72 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
| 73 FILE_PATH_LITERAL("htm"); | 75 FILE_PATH_LITERAL("htm"); |
| 74 #else | 76 #else |
| 75 FILE_PATH_LITERAL("html"); | 77 FILE_PATH_LITERAL("html"); |
| 76 #endif | 78 #endif |
| 77 | 79 |
| 78 // Maximum number of file ordinal number. I think it's big enough for resolving | 80 // Maximum number of file ordinal number. I think it's big enough for resolving |
| 79 // name-conflict files which has same base file name. | 81 // name-conflict files which has same base file name. |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 333 } |
| 332 | 334 |
| 333 // Generate name for saving resource. | 335 // Generate name for saving resource. |
| 334 bool SavePackage::GenerateFilename(const std::string& disposition, | 336 bool SavePackage::GenerateFilename(const std::string& disposition, |
| 335 const GURL& url, | 337 const GURL& url, |
| 336 bool need_html_ext, | 338 bool need_html_ext, |
| 337 FilePath::StringType* generated_name) { | 339 FilePath::StringType* generated_name) { |
| 338 // TODO(jungshik): Figure out the referrer charset when having one | 340 // TODO(jungshik): Figure out the referrer charset when having one |
| 339 // makes sense and pass it to GetSuggestedFilename. | 341 // makes sense and pass it to GetSuggestedFilename. |
| 340 FilePath file_path = net::GetSuggestedFilename(url, disposition, "", | 342 FilePath file_path = net::GetSuggestedFilename(url, disposition, "", |
| 341 kDefaultSaveName); | 343 FilePath(kDefaultSaveName)); |
| 342 | 344 |
| 343 DCHECK(!file_path.empty()); | 345 DCHECK(!file_path.empty()); |
| 344 FilePath::StringType pure_file_name = | 346 FilePath::StringType pure_file_name = |
| 345 file_path.RemoveExtension().BaseName().value(); | 347 file_path.RemoveExtension().BaseName().value(); |
| 346 FilePath::StringType file_name_ext = file_path.Extension(); | 348 FilePath::StringType file_name_ext = file_path.Extension(); |
| 347 | 349 |
| 348 // If it is HTML resource, use ".htm{l,}" as its extension. | 350 // If it is HTML resource, use ".htm{l,}" as its extension. |
| 349 if (need_html_ext) { | 351 if (need_html_ext) { |
| 350 file_name_ext = FILE_PATH_LITERAL("."); | 352 file_name_ext = FILE_PATH_LITERAL("."); |
| 351 file_name_ext.append(kDefaultHtmlExtension); | 353 file_name_ext.append(kDefaultHtmlExtension); |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 int index, void* params) { | 1250 int index, void* params) { |
| 1249 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1251 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1250 ContinueSave(save_params, path, index); | 1252 ContinueSave(save_params, path, index); |
| 1251 delete save_params; | 1253 delete save_params; |
| 1252 } | 1254 } |
| 1253 | 1255 |
| 1254 void SavePackage::FileSelectionCanceled(void* params) { | 1256 void SavePackage::FileSelectionCanceled(void* params) { |
| 1255 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1257 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1256 delete save_params; | 1258 delete save_params; |
| 1257 } | 1259 } |
| OLD | NEW |