| 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" | |
| 27 #include "content/public/browser/download_danger_type.h" | 26 #include "content/public/browser/download_danger_type.h" |
| 28 #include "content/public/browser/download_interrupt_reasons.h" | 27 #include "content/public/browser/download_interrupt_reasons.h" |
| 29 #include "content/public/browser/download_item.h" | 28 #include "content/public/browser/download_item.h" |
| 30 #include "net/base/mime_util.h" | |
| 31 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/l10n/time_format.h" | 30 #include "ui/base/l10n/time_format.h" |
| 33 #include "ui/base/text/bytes_formatting.h" | 31 #include "ui/base/text/bytes_formatting.h" |
| 34 #include "ui/gfx/text_elider.h" | 32 #include "ui/gfx/text_elider.h" |
| 35 | 33 |
| 36 using base::TimeDelta; | 34 using base::TimeDelta; |
| 37 using content::DownloadItem; | 35 using content::DownloadItem; |
| 38 using safe_browsing::DownloadFileType; | 36 using safe_browsing::DownloadFileType; |
| 39 | 37 |
| 40 namespace { | 38 namespace { |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 // We shouldn't get any of these due to the MightBeMalicious() test above. | 506 // We shouldn't get any of these due to the MightBeMalicious() test above. |
| 509 NOTREACHED(); | 507 NOTREACHED(); |
| 510 // Fallthrough. | 508 // Fallthrough. |
| 511 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 509 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
| 512 return false; | 510 return false; |
| 513 } | 511 } |
| 514 NOTREACHED(); | 512 NOTREACHED(); |
| 515 return false; | 513 return false; |
| 516 } | 514 } |
| 517 | 515 |
| 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 | |
| 535 bool DownloadItemModel::ShouldAllowDownloadFeedback() const { | 516 bool DownloadItemModel::ShouldAllowDownloadFeedback() const { |
| 536 #if defined(FULL_SAFE_BROWSING) | 517 #if defined(FULL_SAFE_BROWSING) |
| 537 if (!IsDangerous()) | 518 if (!IsDangerous()) |
| 538 return false; | 519 return false; |
| 539 return safe_browsing::DownloadFeedbackService::IsEnabledForDownload( | 520 return safe_browsing::DownloadFeedbackService::IsEnabledForDownload( |
| 540 *download_); | 521 *download_); |
| 541 #else | 522 #else |
| 542 return false; | 523 return false; |
| 543 #endif | 524 #endif |
| 544 } | 525 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 if (!download_service) | 723 if (!download_service) |
| 743 return; | 724 return; |
| 744 | 725 |
| 745 ChromeDownloadManagerDelegate* delegate = | 726 ChromeDownloadManagerDelegate* delegate = |
| 746 download_service->GetDownloadManagerDelegate(); | 727 download_service->GetDownloadManagerDelegate(); |
| 747 if (!delegate) | 728 if (!delegate) |
| 748 return; | 729 return; |
| 749 delegate->OpenDownloadUsingPlatformHandler(download_); | 730 delegate->OpenDownloadUsingPlatformHandler(download_); |
| 750 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); | 731 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); |
| 751 } | 732 } |
| OLD | NEW |