OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <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" |
11 #include "base/i18n/file_util_icu.h" | 11 #include "base/i18n/file_util_icu.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
16 #include "base/string_split.h" | 16 #include "base/string_split.h" |
| 17 #include "base/sys_string_conversions.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "base/task.h" | 19 #include "base/task.h" |
19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/browser_thread.h" | 22 #include "chrome/browser/browser_thread.h" |
22 #include "chrome/browser/download/download_item.h" | 23 #include "chrome/browser/download/download_item.h" |
23 #include "chrome/browser/download/download_item_model.h" | 24 #include "chrome/browser/download/download_item_model.h" |
24 #include "chrome/browser/download/download_manager.h" | 25 #include "chrome/browser/download/download_manager.h" |
25 #include "chrome/browser/download/download_shelf.h" | 26 #include "chrome/browser/download/download_shelf.h" |
26 #include "chrome/browser/download/download_util.h" | 27 #include "chrome/browser/download/download_util.h" |
(...skipping 28 matching lines...) Expand all Loading... |
55 using base::Time; | 56 using base::Time; |
56 using WebKit::WebPageSerializerClient; | 57 using WebKit::WebPageSerializerClient; |
57 | 58 |
58 namespace { | 59 namespace { |
59 | 60 |
60 // A counter for uniquely identifying each save package. | 61 // A counter for uniquely identifying each save package. |
61 int g_save_package_id = 0; | 62 int g_save_package_id = 0; |
62 | 63 |
63 // Default name which will be used when we can not get proper name from | 64 // Default name which will be used when we can not get proper name from |
64 // resource URL. | 65 // resource URL. |
65 const FilePath::CharType kDefaultSaveName[] = | 66 const char kDefaultSaveName[] = "saved_resource"; |
66 FILE_PATH_LITERAL("saved_resource"); | |
67 | 67 |
68 const FilePath::CharType kDefaultHtmlExtension[] = | 68 const FilePath::CharType kDefaultHtmlExtension[] = |
69 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
70 FILE_PATH_LITERAL("htm"); | 70 FILE_PATH_LITERAL("htm"); |
71 #else | 71 #else |
72 FILE_PATH_LITERAL("html"); | 72 FILE_PATH_LITERAL("html"); |
73 #endif | 73 #endif |
74 | 74 |
75 // Maximum number of file ordinal number. I think it's big enough for resolving | 75 // Maximum number of file ordinal number. I think it's big enough for resolving |
76 // name-conflict files which has same base file name. | 76 // name-conflict files which has same base file name. |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 return true; | 368 return true; |
369 } | 369 } |
370 | 370 |
371 // Generate name for saving resource. | 371 // Generate name for saving resource. |
372 bool SavePackage::GenerateFileName(const std::string& disposition, | 372 bool SavePackage::GenerateFileName(const std::string& disposition, |
373 const GURL& url, | 373 const GURL& url, |
374 bool need_html_ext, | 374 bool need_html_ext, |
375 FilePath::StringType* generated_name) { | 375 FilePath::StringType* generated_name) { |
376 // TODO(jungshik): Figure out the referrer charset when having one | 376 // TODO(jungshik): Figure out the referrer charset when having one |
377 // makes sense and pass it to GetSuggestedFilename. | 377 // makes sense and pass it to GetSuggestedFilename. |
378 FilePath file_path = net::GetSuggestedFilename(url, disposition, "", | 378 string16 suggested_name = |
379 FilePath(kDefaultSaveName)); | 379 net::GetSuggestedFilename(url, disposition, "", |
| 380 ASCIIToUTF16(kDefaultSaveName)); |
| 381 |
| 382 // TODO(evan): this code is totally wrong -- we should just generate |
| 383 // Unicode filenames and do all this encoding switching at the end. |
| 384 // However, I'm just shuffling wrong code around, at least not adding |
| 385 // to it. |
| 386 #if defined(OS_WIN) |
| 387 FilePath file_path = FilePath(suggested_name); |
| 388 #else |
| 389 FilePath file_path = FilePath( |
| 390 base::SysWideToNativeMB(UTF16ToWide(suggested_name))); |
| 391 #endif |
380 | 392 |
381 DCHECK(!file_path.empty()); | 393 DCHECK(!file_path.empty()); |
382 FilePath::StringType pure_file_name = | 394 FilePath::StringType pure_file_name = |
383 file_path.RemoveExtension().BaseName().value(); | 395 file_path.RemoveExtension().BaseName().value(); |
384 FilePath::StringType file_name_ext = file_path.Extension(); | 396 FilePath::StringType file_name_ext = file_path.Extension(); |
385 | 397 |
386 // If it is HTML resource, use ".htm{l,}" as its extension. | 398 // If it is HTML resource, use ".htm{l,}" as its extension. |
387 if (need_html_ext) { | 399 if (need_html_ext) { |
388 file_name_ext = FILE_PATH_LITERAL("."); | 400 file_name_ext = FILE_PATH_LITERAL("."); |
389 file_name_ext.append(kDefaultHtmlExtension); | 401 file_name_ext.append(kDefaultHtmlExtension); |
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 } | 1382 } |
1371 | 1383 |
1372 // SelectFileDialog::Listener interface. | 1384 // SelectFileDialog::Listener interface. |
1373 void SavePackage::FileSelected(const FilePath& path, | 1385 void SavePackage::FileSelected(const FilePath& path, |
1374 int index, void* params) { | 1386 int index, void* params) { |
1375 ContinueSave(path, index); | 1387 ContinueSave(path, index); |
1376 } | 1388 } |
1377 | 1389 |
1378 void SavePackage::FileSelectionCanceled(void* params) { | 1390 void SavePackage::FileSelectionCanceled(void* params) { |
1379 } | 1391 } |
OLD | NEW |