OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download_item_model.h" | 5 #include "chrome/browser/download/download_item_model.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chrome/browser/download/download_crx_util.h" | 15 #include "chrome/browser/download/download_crx_util.h" |
16 #include "chrome/browser/download/download_field_trial.h" | 16 #include "chrome/browser/download/download_field_trial.h" |
17 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 17 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
18 #include "content/public/browser/download_danger_type.h" | 18 #include "content/public/browser/download_danger_type.h" |
19 #include "content/public/browser/download_interrupt_reasons.h" | 19 #include "content/public/browser/download_interrupt_reasons.h" |
20 #include "content/public/browser/download_item.h" | 20 #include "content/public/browser/download_item.h" |
21 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/l10n/time_format.h" | 24 #include "ui/base/l10n/time_format.h" |
25 #include "ui/base/text/bytes_formatting.h" | 25 #include "ui/base/text/bytes_formatting.h" |
26 #include "ui/base/text/text_elider.h" | 26 #include "ui/gfx/text_elider.h" |
27 | 27 |
28 using base::TimeDelta; | 28 using base::TimeDelta; |
29 using content::DownloadItem; | 29 using content::DownloadItem; |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // Per DownloadItem data used by DownloadItemModel. The model doesn't keep any | 33 // Per DownloadItem data used by DownloadItemModel. The model doesn't keep any |
34 // state since there could be multiple models associated with a single | 34 // state since there could be multiple models associated with a single |
35 // DownloadItem, and the lifetime of the model is shorter than the DownloadItem. | 35 // DownloadItem, and the lifetime of the model is shorter than the DownloadItem. |
36 class DownloadItemModelData : public base::SupportsUserData::Data { | 36 class DownloadItemModelData : public base::SupportsUserData::Data { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 base::i18n::AdjustStringForLocaleDirection(&amount); | 318 base::i18n::AdjustStringForLocaleDirection(&amount); |
319 return l10n_util::GetStringFUTF16( | 319 return l10n_util::GetStringFUTF16( |
320 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount); | 320 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount); |
321 } | 321 } |
322 return l10n_util::GetStringFUTF16( | 322 return l10n_util::GetStringFUTF16( |
323 IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text, amount, time_remaining); | 323 IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text, amount, time_remaining); |
324 } | 324 } |
325 | 325 |
326 string16 DownloadItemModel::GetTooltipText(const gfx::FontList& font_list, | 326 string16 DownloadItemModel::GetTooltipText(const gfx::FontList& font_list, |
327 int max_width) const { | 327 int max_width) const { |
328 string16 tooltip = ui::ElideFilename( | 328 string16 tooltip = gfx::ElideFilename( |
329 download_->GetFileNameToReportUser(), font_list, max_width); | 329 download_->GetFileNameToReportUser(), font_list, max_width); |
330 content::DownloadInterruptReason reason = download_->GetLastReason(); | 330 content::DownloadInterruptReason reason = download_->GetLastReason(); |
331 if (download_->GetState() == DownloadItem::INTERRUPTED && | 331 if (download_->GetState() == DownloadItem::INTERRUPTED && |
332 reason != content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED) { | 332 reason != content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED) { |
333 tooltip += ASCIIToUTF16("\n"); | 333 tooltip += ASCIIToUTF16("\n"); |
334 tooltip += ui::ElideText(InterruptReasonStatusMessage(reason), | 334 tooltip += gfx::ElideText(InterruptReasonStatusMessage(reason), |
335 font_list, max_width, ui::ELIDE_AT_END); | 335 font_list, max_width, gfx::ELIDE_AT_END); |
336 } | 336 } |
337 return tooltip; | 337 return tooltip; |
338 } | 338 } |
339 | 339 |
340 string16 DownloadItemModel::GetWarningText(const gfx::FontList& font_list, | 340 string16 DownloadItemModel::GetWarningText(const gfx::FontList& font_list, |
341 int base_width) const { | 341 int base_width) const { |
342 // Should only be called if IsDangerous(). | 342 // Should only be called if IsDangerous(). |
343 DCHECK(IsDangerous()); | 343 DCHECK(IsDangerous()); |
344 string16 elided_filename = | 344 string16 elided_filename = |
345 ui::ElideFilename(download_->GetFileNameToReportUser(), font_list, | 345 gfx::ElideFilename(download_->GetFileNameToReportUser(), font_list, |
346 base_width); | 346 base_width); |
347 switch (download_->GetDangerType()) { | 347 switch (download_->GetDangerType()) { |
348 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: { | 348 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: { |
349 std::string trial_condition = | 349 std::string trial_condition = |
350 base::FieldTrialList::FindFullName(kMalwareWarningFinchTrialName); | 350 base::FieldTrialList::FindFullName(kMalwareWarningFinchTrialName); |
351 if (trial_condition.empty()) | 351 if (trial_condition.empty()) |
352 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); | 352 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); |
353 return AssembleMalwareFinchString(trial_condition, elided_filename); | 353 return AssembleMalwareFinchString(trial_condition, elided_filename); |
354 } | 354 } |
355 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { | 355 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 581 } |
582 | 582 |
583 // In progress download with no known time left and non-zero completed bytes: | 583 // In progress download with no known time left and non-zero completed bytes: |
584 // "100/120 MB" or "100 MB" | 584 // "100/120 MB" or "100 MB" |
585 if (GetCompletedBytes() > 0) | 585 if (GetCompletedBytes() > 0) |
586 return size_ratio; | 586 return size_ratio; |
587 | 587 |
588 // Instead of displaying "0 B" we say "Starting..." | 588 // Instead of displaying "0 B" we say "Starting..." |
589 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); | 589 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); |
590 } | 590 } |
OLD | NEW |