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 // 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 info->referrer_charset, | 179 info->referrer_charset, |
180 info->mime_type, | 180 info->mime_type, |
181 generated_name); | 181 generated_name); |
182 } | 182 } |
183 | 183 |
184 void GenerateFileName(const GURL& url, | 184 void GenerateFileName(const GURL& url, |
185 const std::string& content_disposition, | 185 const std::string& content_disposition, |
186 const std::string& referrer_charset, | 186 const std::string& referrer_charset, |
187 const std::string& mime_type, | 187 const std::string& mime_type, |
188 FilePath* generated_name) { | 188 FilePath* generated_name) { |
189 std::wstring default_name = | |
190 l10n_util::GetString(IDS_DEFAULT_DOWNLOAD_FILENAME); | |
191 #if defined(OS_WIN) | 189 #if defined(OS_WIN) |
192 FilePath default_file_path(default_name); | 190 FilePath default_file_path( |
| 191 l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
| 192 #elif defined(OS_MACOSX) |
| 193 FilePath default_file_path( |
| 194 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
193 #elif defined(OS_POSIX) | 195 #elif defined(OS_POSIX) |
194 FilePath default_file_path(base::SysWideToNativeMB(default_name)); | 196 std::string default_file = |
| 197 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 198 FilePath default_file_path(SysWideToNativeMB(SysUTF8ToWide(default_file))); |
195 #endif | 199 #endif |
196 | 200 |
197 *generated_name = net::GetSuggestedFilename(GURL(url), | 201 *generated_name = net::GetSuggestedFilename(GURL(url), |
198 content_disposition, | 202 content_disposition, |
199 referrer_charset, | 203 referrer_charset, |
200 default_file_path); | 204 default_file_path); |
201 | 205 |
202 DCHECK(!generated_name->empty()); | 206 DCHECK(!generated_name->empty()); |
203 | 207 |
204 GenerateSafeFileName(mime_type, generated_name); | 208 GenerateSafeFileName(mime_type, generated_name); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 if (download->state() == DownloadItem::IN_PROGRESS) { | 508 if (download->state() == DownloadItem::IN_PROGRESS) { |
505 if (download->safety_state() == DownloadItem::DANGEROUS) { | 509 if (download->safety_state() == DownloadItem::DANGEROUS) { |
506 file_value->SetString("state", "DANGEROUS"); | 510 file_value->SetString("state", "DANGEROUS"); |
507 } else if (download->is_paused()) { | 511 } else if (download->is_paused()) { |
508 file_value->SetString("state", "PAUSED"); | 512 file_value->SetString("state", "PAUSED"); |
509 } else { | 513 } else { |
510 file_value->SetString("state", "IN_PROGRESS"); | 514 file_value->SetString("state", "IN_PROGRESS"); |
511 } | 515 } |
512 | 516 |
513 file_value->SetString("progress_status_text", | 517 file_value->SetString("progress_status_text", |
514 WideToUTF16Hack(GetProgressStatusText(download))); | 518 GetProgressStatusText(download)); |
515 | 519 |
516 file_value->SetInteger("percent", | 520 file_value->SetInteger("percent", |
517 static_cast<int>(download->PercentComplete())); | 521 static_cast<int>(download->PercentComplete())); |
518 file_value->SetInteger("received", | 522 file_value->SetInteger("received", |
519 static_cast<int>(download->received_bytes())); | 523 static_cast<int>(download->received_bytes())); |
520 } else if (download->state() == DownloadItem::CANCELLED) { | 524 } else if (download->state() == DownloadItem::CANCELLED) { |
521 file_value->SetString("state", "CANCELLED"); | 525 file_value->SetString("state", "CANCELLED"); |
522 } else if (download->state() == DownloadItem::COMPLETE) { | 526 } else if (download->state() == DownloadItem::COMPLETE) { |
523 if (download->safety_state() == DownloadItem::DANGEROUS) { | 527 if (download->safety_state() == DownloadItem::DANGEROUS) { |
524 file_value->SetString("state", "DANGEROUS"); | 528 file_value->SetString("state", "DANGEROUS"); |
525 } else { | 529 } else { |
526 file_value->SetString("state", "COMPLETE"); | 530 file_value->SetString("state", "COMPLETE"); |
527 } | 531 } |
528 } | 532 } |
529 | 533 |
530 file_value->SetInteger("total", | 534 file_value->SetInteger("total", |
531 static_cast<int>(download->total_bytes())); | 535 static_cast<int>(download->total_bytes())); |
532 | 536 |
533 return file_value; | 537 return file_value; |
534 } | 538 } |
535 | 539 |
536 std::wstring GetProgressStatusText(DownloadItem* download) { | 540 string16 GetProgressStatusText(DownloadItem* download) { |
537 int64 total = download->total_bytes(); | 541 int64 total = download->total_bytes(); |
538 int64 size = download->received_bytes(); | 542 int64 size = download->received_bytes(); |
539 DataUnits amount_units = GetByteDisplayUnits(size); | 543 DataUnits amount_units = GetByteDisplayUnits(size); |
540 std::wstring received_size = UTF16ToWideHack(FormatBytes(size, amount_units, | 544 string16 received_size = FormatBytes(size, amount_units, true); |
541 true)); | 545 string16 amount = received_size; |
542 std::wstring amount = received_size; | |
543 | 546 |
544 // Adjust both strings for the locale direction since we don't yet know which | 547 // Adjust both strings for the locale direction since we don't yet know which |
545 // string we'll end up using for constructing the final progress string. | 548 // string we'll end up using for constructing the final progress string. |
546 base::i18n::AdjustStringForLocaleDirection(&amount); | 549 base::i18n::AdjustStringForLocaleDirection(&amount); |
547 | 550 |
548 if (total) { | 551 if (total) { |
549 amount_units = GetByteDisplayUnits(total); | 552 amount_units = GetByteDisplayUnits(total); |
550 std::wstring total_text = | 553 string16 total_text = FormatBytes(total, amount_units, true); |
551 UTF16ToWideHack(FormatBytes(total, amount_units, true)); | |
552 base::i18n::AdjustStringForLocaleDirection(&total_text); | 554 base::i18n::AdjustStringForLocaleDirection(&total_text); |
553 | 555 |
554 base::i18n::AdjustStringForLocaleDirection(&received_size); | 556 base::i18n::AdjustStringForLocaleDirection(&received_size); |
555 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, | 557 amount = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, |
556 received_size, | 558 received_size, |
557 total_text); | 559 total_text); |
558 } else { | 560 } else { |
559 amount.assign(received_size); | 561 amount.assign(received_size); |
560 } | 562 } |
561 int64 current_speed = download->CurrentSpeed(); | 563 int64 current_speed = download->CurrentSpeed(); |
562 amount_units = GetByteDisplayUnits(current_speed); | 564 amount_units = GetByteDisplayUnits(current_speed); |
563 std::wstring speed_text = UTF16ToWideHack(FormatSpeed(current_speed, | 565 string16 speed_text = FormatSpeed(current_speed, amount_units, true); |
564 amount_units, true)); | |
565 base::i18n::AdjustStringForLocaleDirection(&speed_text); | 566 base::i18n::AdjustStringForLocaleDirection(&speed_text); |
566 | 567 |
567 base::TimeDelta remaining; | 568 base::TimeDelta remaining; |
568 string16 time_remaining; | 569 string16 time_remaining; |
569 if (download->is_paused()) | 570 if (download->is_paused()) |
570 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); | 571 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); |
571 else if (download->TimeRemaining(&remaining)) | 572 else if (download->TimeRemaining(&remaining)) |
572 time_remaining = TimeFormat::TimeRemaining(remaining); | 573 time_remaining = TimeFormat::TimeRemaining(remaining); |
573 | 574 |
574 if (time_remaining.empty()) { | 575 if (time_remaining.empty()) { |
575 base::i18n::AdjustStringForLocaleDirection(&amount); | 576 base::i18n::AdjustStringForLocaleDirection(&amount); |
576 return l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, | 577 return l10n_util::GetStringFUTF16( |
577 speed_text, amount); | 578 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount); |
578 } | 579 } |
579 return l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text, | 580 return l10n_util::GetStringFUTF16(IDS_DOWNLOAD_TAB_PROGRESS_STATUS, |
580 amount, UTF16ToWideHack(time_remaining)); | 581 speed_text, amount, time_remaining); |
581 } | 582 } |
582 | 583 |
583 #if !defined(OS_MACOSX) | 584 #if !defined(OS_MACOSX) |
584 void UpdateAppIconDownloadProgress(int download_count, | 585 void UpdateAppIconDownloadProgress(int download_count, |
585 bool progress_known, | 586 bool progress_known, |
586 float progress) { | 587 float progress) { |
587 #if defined(OS_WIN) | 588 #if defined(OS_WIN) |
588 // Taskbar progress bar is only supported on Win7. | 589 // Taskbar progress bar is only supported on Win7. |
589 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 590 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
590 return; | 591 return; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { | 737 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { |
737 // Extensions that are not from the gallery are considered dangerous. | 738 // Extensions that are not from the gallery are considered dangerous. |
738 return true; | 739 return true; |
739 } | 740 } |
740 } | 741 } |
741 | 742 |
742 return false; | 743 return false; |
743 } | 744 } |
744 | 745 |
745 } // namespace download_util | 746 } // namespace download_util |
OLD | NEW |