| 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/chrome_download_manager_delegate.h" | 15 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 16 #include "chrome/browser/download/download_crx_util.h" | 16 #include "chrome/browser/download/download_crx_util.h" |
| 17 #include "chrome/browser/download/download_history.h" | 17 #include "chrome/browser/download/download_history.h" |
| 18 #include "chrome/browser/download/download_service.h" | 18 #include "chrome/browser/download/download_service.h" |
| 19 #include "chrome/browser/download/download_service_factory.h" | 19 #include "chrome/browser/download/download_service_factory.h" |
| 20 #include "chrome/browser/download/download_stats.h" | 20 #include "chrome/browser/download/download_stats.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 22 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
| 23 #include "chrome/common/safe_browsing/download_file_types.pb.h" | 23 #include "chrome/common/safe_browsing/download_file_types.pb.h" |
| 24 #include "chrome/grit/chromium_strings.h" | 24 #include "chrome/grit/chromium_strings.h" |
| 25 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 26 #include "components/mime_util/mime_util.h" |
| 26 #include "content/public/browser/download_danger_type.h" | 27 #include "content/public/browser/download_danger_type.h" |
| 27 #include "content/public/browser/download_interrupt_reasons.h" | 28 #include "content/public/browser/download_interrupt_reasons.h" |
| 28 #include "content/public/browser/download_item.h" | 29 #include "content/public/browser/download_item.h" |
| 30 #include "net/base/mime_util.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/l10n/time_format.h" | 32 #include "ui/base/l10n/time_format.h" |
| 31 #include "ui/base/text/bytes_formatting.h" | 33 #include "ui/base/text/bytes_formatting.h" |
| 32 #include "ui/gfx/text_elider.h" | 34 #include "ui/gfx/text_elider.h" |
| 33 | 35 |
| 34 using base::TimeDelta; | 36 using base::TimeDelta; |
| 35 using content::DownloadItem; | 37 using content::DownloadItem; |
| 36 using safe_browsing::DownloadFileType; | 38 using safe_browsing::DownloadFileType; |
| 37 | 39 |
| 38 namespace { | 40 namespace { |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 // We shouldn't get any of these due to the MightBeMalicious() test above. | 508 // We shouldn't get any of these due to the MightBeMalicious() test above. |
| 507 NOTREACHED(); | 509 NOTREACHED(); |
| 508 // Fallthrough. | 510 // Fallthrough. |
| 509 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 511 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
| 510 return false; | 512 return false; |
| 511 } | 513 } |
| 512 NOTREACHED(); | 514 NOTREACHED(); |
| 513 return false; | 515 return false; |
| 514 } | 516 } |
| 515 | 517 |
| 518 bool DownloadItemModel::HasSupportedImageMimeType() const { |
| 519 if (mime_util::IsSupportedImageMimeType(download_->GetMimeType())) { |
| 520 return true; |
| 521 } |
| 522 |
| 523 std::string mime; |
| 524 base::FilePath::StringType extension_with_dot = |
| 525 download_->GetTargetFilePath().FinalExtension(); |
| 526 if (!extension_with_dot.empty() && net::GetWellKnownMimeTypeFromExtension( |
| 527 extension_with_dot.substr(1), &mime) && |
| 528 mime_util::IsSupportedImageMimeType(mime)) { |
| 529 return true; |
| 530 } |
| 531 |
| 532 return false; |
| 533 } |
| 534 |
| 516 bool DownloadItemModel::ShouldAllowDownloadFeedback() const { | 535 bool DownloadItemModel::ShouldAllowDownloadFeedback() const { |
| 517 #if defined(FULL_SAFE_BROWSING) | 536 #if defined(FULL_SAFE_BROWSING) |
| 518 if (!IsDangerous()) | 537 if (!IsDangerous()) |
| 519 return false; | 538 return false; |
| 520 return safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | 539 return safe_browsing::DownloadFeedbackService::IsEnabledForDownload( |
| 521 *download_); | 540 *download_); |
| 522 #else | 541 #else |
| 523 return false; | 542 return false; |
| 524 #endif | 543 #endif |
| 525 } | 544 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 if (!download_service) | 742 if (!download_service) |
| 724 return; | 743 return; |
| 725 | 744 |
| 726 ChromeDownloadManagerDelegate* delegate = | 745 ChromeDownloadManagerDelegate* delegate = |
| 727 download_service->GetDownloadManagerDelegate(); | 746 download_service->GetDownloadManagerDelegate(); |
| 728 if (!delegate) | 747 if (!delegate) |
| 729 return; | 748 return; |
| 730 delegate->OpenDownloadUsingPlatformHandler(download_); | 749 delegate->OpenDownloadUsingPlatformHandler(download_); |
| 731 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); | 750 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); |
| 732 } | 751 } |
| OLD | NEW |