| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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()); |
| 304 string16 elided_filename = | 306 string16 elided_filename = |
| 305 ui::ElideFilename(download_->GetFileNameToReportUser(), font, base_width); | 307 ui::ElideFilename(download_->GetFileNameToReportUser(), font, base_width); |
| 306 switch (download_->GetDangerType()) { | 308 switch (download_->GetDangerType()) { |
| 307 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 309 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: { |
| 308 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); | 310 std::string trial_condition = |
| 309 | 311 base::FieldTrialList::FindFullName(download_util::kFinchTrialName); |
| 310 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: | 312 if (trial_condition.empty()) |
| 313 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); |
| 314 return download_util::AssembleMalwareFinchString(trial_condition, |
| 315 elided_filename); |
| 316 } |
| 317 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: { |
| 311 if (download_crx_util::IsExtensionDownload(*download_)) { | 318 if (download_crx_util::IsExtensionDownload(*download_)) { |
| 312 return l10n_util::GetStringUTF16( | 319 return l10n_util::GetStringUTF16( |
| 313 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); | 320 IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); |
| 314 } else { | 321 } else { |
| 315 return l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, | 322 return l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, |
| 316 elided_filename); | 323 elided_filename); |
| 317 } | 324 } |
| 318 | 325 } |
| 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 std::string trial_condition = |
| 322 elided_filename); | 329 base::FieldTrialList::FindFullName(download_util::kFinchTrialName); |
| 323 | 330 if (trial_condition.empty()) { |
| 324 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 331 return l10n_util::GetStringFUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT, |
| 332 elided_filename); |
| 333 } |
| 334 return download_util::AssembleMalwareFinchString(trial_condition, |
| 335 elided_filename); |
| 336 } |
| 337 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: { |
| 325 return l10n_util::GetStringFUTF16(IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, | 338 return l10n_util::GetStringFUTF16(IDS_PROMPT_UNCOMMON_DOWNLOAD_CONTENT, |
| 326 elided_filename); | 339 elided_filename); |
| 327 | 340 } |
| 328 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: | 341 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: { |
| 329 return l10n_util::GetStringFUTF16( | 342 return l10n_util::GetStringFUTF16( |
| 330 IDS_PROMPT_DOWNLOAD_CHANGES_SEARCH_SETTINGS, elided_filename); | 343 IDS_PROMPT_DOWNLOAD_CHANGES_SEARCH_SETTINGS, elided_filename); |
| 331 | 344 } |
| 332 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: | 345 case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS: |
| 333 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: | 346 case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT: |
| 334 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: | 347 case content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED: |
| 335 case content::DOWNLOAD_DANGER_TYPE_MAX: | 348 case content::DOWNLOAD_DANGER_TYPE_MAX: { |
| 336 break; | 349 break; |
| 350 } |
| 337 } | 351 } |
| 338 NOTREACHED(); | 352 NOTREACHED(); |
| 339 return string16(); | 353 return string16(); |
| 340 } | 354 } |
| 341 | 355 |
| 342 string16 DownloadItemModel::GetWarningConfirmButtonText() const { | 356 string16 DownloadItemModel::GetWarningConfirmButtonText() const { |
| 343 // Should only be called if IsDangerous() | 357 // Should only be called if IsDangerous() |
| 344 DCHECK(IsDangerous()); | 358 DCHECK(IsDangerous()); |
| 345 if (download_->GetDangerType() == | 359 if (download_->GetDangerType() == |
| 346 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE && | 360 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE && |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 544 } |
| 531 | 545 |
| 532 // In progress download with no known time left and non-zero completed bytes: | 546 // In progress download with no known time left and non-zero completed bytes: |
| 533 // "100/120 MB" or "100 MB" | 547 // "100/120 MB" or "100 MB" |
| 534 if (GetCompletedBytes() > 0) | 548 if (GetCompletedBytes() > 0) |
| 535 return size_ratio; | 549 return size_ratio; |
| 536 | 550 |
| 537 // Instead of displaying "0 B" we say "Starting..." | 551 // Instead of displaying "0 B" we say "Starting..." |
| 538 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); | 552 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); |
| 539 } | 553 } |
| OLD | NEW |