| 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/chrome_thread.h" | 18 #include "chrome/browser/chrome_thread.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 explicit SavePackageParam(const std::string& mime_type) | 61 explicit SavePackageParam(const std::string& mime_type) |
| 61 : current_tab_mime_type(mime_type), | 62 : current_tab_mime_type(mime_type), |
| 62 save_type(SavePackage::SAVE_TYPE_UNKNOWN) { | 63 save_type(SavePackage::SAVE_TYPE_UNKNOWN) { |
| 63 } | 64 } |
| 64 }; | 65 }; |
| 65 | 66 |
| 66 namespace { | 67 namespace { |
| 67 | 68 |
| 68 // Default name which will be used when we can not get proper name from | 69 // Default name which will be used when we can not get proper name from |
| 69 // resource URL. | 70 // resource URL. |
| 70 const char kDefaultSaveName[] = "saved_resource"; | 71 const FilePath::CharType kDefaultSaveName[] = |
| 72 FILE_PATH_LITERAL("saved_resource"); |
| 71 | 73 |
| 72 const FilePath::CharType kDefaultHtmlExtension[] = | 74 const FilePath::CharType kDefaultHtmlExtension[] = |
| 73 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
| 74 FILE_PATH_LITERAL("htm"); | 76 FILE_PATH_LITERAL("htm"); |
| 75 #else | 77 #else |
| 76 FILE_PATH_LITERAL("html"); | 78 FILE_PATH_LITERAL("html"); |
| 77 #endif | 79 #endif |
| 78 | 80 |
| 79 // Maximum number of file ordinal number. I think it's big enough for resolving | 81 // Maximum number of file ordinal number. I think it's big enough for resolving |
| 80 // name-conflict files which has same base file name. | 82 // name-conflict files which has same base file name. |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 334 } |
| 333 | 335 |
| 334 // Generate name for saving resource. | 336 // Generate name for saving resource. |
| 335 bool SavePackage::GenerateFilename(const std::string& disposition, | 337 bool SavePackage::GenerateFilename(const std::string& disposition, |
| 336 const GURL& url, | 338 const GURL& url, |
| 337 bool need_html_ext, | 339 bool need_html_ext, |
| 338 FilePath::StringType* generated_name) { | 340 FilePath::StringType* generated_name) { |
| 339 // TODO(jungshik): Figure out the referrer charset when having one | 341 // TODO(jungshik): Figure out the referrer charset when having one |
| 340 // makes sense and pass it to GetSuggestedFilename. | 342 // makes sense and pass it to GetSuggestedFilename. |
| 341 FilePath file_path = net::GetSuggestedFilename(url, disposition, "", | 343 FilePath file_path = net::GetSuggestedFilename(url, disposition, "", |
| 342 kDefaultSaveName); | 344 FilePath(kDefaultSaveName)); |
| 343 | 345 |
| 344 DCHECK(!file_path.empty()); | 346 DCHECK(!file_path.empty()); |
| 345 FilePath::StringType pure_file_name = | 347 FilePath::StringType pure_file_name = |
| 346 file_path.RemoveExtension().BaseName().value(); | 348 file_path.RemoveExtension().BaseName().value(); |
| 347 FilePath::StringType file_name_ext = file_path.Extension(); | 349 FilePath::StringType file_name_ext = file_path.Extension(); |
| 348 | 350 |
| 349 // If it is HTML resource, use ".htm{l,}" as its extension. | 351 // If it is HTML resource, use ".htm{l,}" as its extension. |
| 350 if (need_html_ext) { | 352 if (need_html_ext) { |
| 351 file_name_ext = FILE_PATH_LITERAL("."); | 353 file_name_ext = FILE_PATH_LITERAL("."); |
| 352 file_name_ext.append(kDefaultHtmlExtension); | 354 file_name_ext.append(kDefaultHtmlExtension); |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 int index, void* params) { | 1261 int index, void* params) { |
| 1260 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1262 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1261 ContinueSave(save_params, path, index); | 1263 ContinueSave(save_params, path, index); |
| 1262 delete save_params; | 1264 delete save_params; |
| 1263 } | 1265 } |
| 1264 | 1266 |
| 1265 void SavePackage::FileSelectionCanceled(void* params) { | 1267 void SavePackage::FileSelectionCanceled(void* params) { |
| 1266 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); | 1268 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); |
| 1267 delete save_params; | 1269 delete save_params; |
| 1268 } | 1270 } |
| OLD | NEW |