| 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/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "chrome/browser/download/download_crx_util.h" | 15 #include "chrome/browser/download/download_crx_util.h" |
| 16 #include "chrome/browser/download/download_util.h" |
| 15 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 17 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
| 16 #include "content/public/browser/download_danger_type.h" | 18 #include "content/public/browser/download_danger_type.h" |
| 17 #include "content/public/browser/download_interrupt_reasons.h" | 19 #include "content/public/browser/download_interrupt_reasons.h" |
| 18 #include "content/public/browser/download_item.h" | 20 #include "content/public/browser/download_item.h" |
| 19 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/l10n/time_format.h" | 24 #include "ui/base/l10n/time_format.h" |
| 23 #include "ui/base/text/bytes_formatting.h" | 25 #include "ui/base/text/bytes_formatting.h" |
| 24 #include "ui/base/text/text_elider.h" | 26 #include "ui/base/text/text_elider.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 tooltip += ui::ElideText(InterruptReasonStatusMessage(reason), | 296 tooltip += ui::ElideText(InterruptReasonStatusMessage(reason), |
| 295 font, max_width, ui::ELIDE_AT_END); | 297 font, max_width, ui::ELIDE_AT_END); |
| 296 } | 298 } |
| 297 return tooltip; | 299 return tooltip; |
| 298 } | 300 } |
| 299 | 301 |
| 300 string16 DownloadItemModel::GetWarningText(const gfx::Font& font, | 302 string16 DownloadItemModel::GetWarningText(const gfx::Font& font, |
| 301 int base_width) const { | 303 int base_width) const { |
| 302 // Should only be called if IsDangerous(). | 304 // Should only be called if IsDangerous(). |
| 303 DCHECK(IsDangerous()); | 305 DCHECK(IsDangerous()); |
| 306 std::string trial_condition = |
| 307 base::FieldTrialList::FindFullName(download_util::kFinchTrialName); |
| 304 string16 elided_filename = | 308 string16 elided_filename = |
| 305 ui::ElideFilename(download_->GetFileNameToReportUser(), font, base_width); | 309 ui::ElideFilename(download_->GetFileNameToReportUser(), font, base_width); |
| 306 switch (download_->GetDangerType()) { | 310 switch (download_->GetDangerType()) { |
| 307 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 311 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
| 308 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); | 312 if (trial_condition.empty()) { |
| 309 | 313 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); |
| 314 } else { |
| 315 return download_util::AssembleMalwareFinchString(trial_condition, |
| 316 elided_filename); |
| 317 } |
| 310 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: | 318 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: |
| 311 if (download_crx_util::IsExtensionDownload(*download_)) { | 319 if (download_crx_util::IsExtensionDownload(*download_)) { |
| 312 return l10n_util::GetStringUTF16( | 320 return l10n_util::GetStringUTF16( |
| 313 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); | 321 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); |
| 314 } else { | 322 } else { |
| 315 return l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, | 323 return l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| 316 elided_filename); | 324 elided_filename); |
| 317 } | 325 } |
| 318 | |
| 319 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 326 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
| 320 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 327 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
| 321 return l10n_util::GetStringFUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, | 328 if (trial_condition.empty()) { |
| 322 elided_filename); | 329 return l10n_util::GetStringFUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, |
| 323 | 330 elided_filename); |
| 331 } else { |
| 332 return download_util::AssembleMalwareFinchString(trial_condition, |
| 333 elided_filename); |
| 334 } |
| 324 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 335 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
| 325 return l10n_util::GetStringFUTF16(IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, | 336 return l10n_util::GetStringFUTF16(IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, |
| 326 elided_filename); | 337 elided_filename); |
| 327 | 338 |
| 328 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: | 339 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
| 329 return l10n_util::GetStringFUTF16( | 340 return l10n_util::GetStringFUTF16( |
| 330 IDS_PROMPT_DOWNLOAD_CHANGES_SEARCH_SETTINGS, elided_filename); | 341 IDS_PROMPT_DOWNLOAD_CHANGES_SEARCH_SETTINGS, elided_filename); |
| 331 | 342 |
| 332 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: | 343 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: |
| 333 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: | 344 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 541 } |
| 531 | 542 |
| 532 // In progress download with no known time left and non-zero completed bytes: | 543 // In progress download with no known time left and non-zero completed bytes: |
| 533 // "100/120 MB" or "100 MB" | 544 // "100/120 MB" or "100 MB" |
| 534 if (GetCompletedBytes() > 0) | 545 if (GetCompletedBytes() > 0) |
| 535 return size_ratio; | 546 return size_ratio; |
| 536 | 547 |
| 537 // Instead of displaying "0 B" we say "Starting..." | 548 // Instead of displaying "0 B" we say "Starting..." |
| 538 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); | 549 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); |
| 539 } | 550 } |
| OLD | NEW |