Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1187)

Unified Diff: chrome/browser/download/download_item_model.cc

Issue 2219953004: Refactor download image-MIME-type-detection code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add more tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_item_model.cc
diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc
index 95eb7b78040f583635d8244c8e17da461217906c..51ff68dd164c68d76a968a693b490020031937d6 100644
--- a/chrome/browser/download/download_item_model.cc
+++ b/chrome/browser/download/download_item_model.cc
@@ -23,9 +23,11 @@
#include "chrome/common/safe_browsing/download_file_types.pb.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
+#include "components/mime_util/mime_util.h"
#include "content/public/browser/download_danger_type.h"
#include "content/public/browser/download_interrupt_reasons.h"
#include "content/public/browser/download_item.h"
+#include "net/base/mime_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/base/text/bytes_formatting.h"
@@ -513,6 +515,23 @@ bool DownloadItemModel::IsMalicious() const {
return false;
}
+bool DownloadItemModel::HasSupportedImageMimeType() const {
+ if (mime_util::IsSupportedImageMimeType(download_->GetMimeType())) {
+ return true;
+ }
+
+ std::string mime;
+ base::FilePath::StringType extension_with_dot =
+ download_->GetTargetFilePath().FinalExtension();
+ if (!extension_with_dot.empty() && net::GetWellKnownMimeTypeFromExtension(
+ extension_with_dot.substr(1), &mime) &&
+ mime_util::IsSupportedImageMimeType(mime)) {
+ return true;
+ }
+
+ return false;
+}
+
bool DownloadItemModel::ShouldAllowDownloadFeedback() const {
#if defined(FULL_SAFE_BROWSING)
if (!IsDangerous())
« no previous file with comments | « chrome/browser/download/download_item_model.h ('k') | chrome/browser/download/download_item_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698