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

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

Issue 9569011: Refactor dangerous download warning text generation into DownloadItemModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update copyright headers Created 8 years, 10 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 feb0c0b376b97998a462b537e500c62d938642ca..c2454492c35d51ea8759f1faa0ca005c232d473f 100644
--- a/chrome/browser/download/download_item_model.cc
+++ b/chrome/browser/download/download_item_model.cc
@@ -7,14 +7,17 @@
#include "base/i18n/number_formatting.h"
#include "base/i18n/rtl.h"
#include "base/string16.h"
+#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/common/time_format.h"
+#include "content/public/browser/download_danger_type.h"
#include "content/public/browser/download_item.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/bytes_formatting.h"
+#include "ui/base/text/text_elider.h"
using base::TimeDelta;
using content::DownloadItem;
@@ -109,3 +112,73 @@ string16 DownloadItemModel::GetStatusText() {
return status_text;
}
+
+string16 DownloadItemModel::GetWarningText(const gfx::Font& font,
+ int base_width) {
+ // Should only be called if IsDangerous().
+ DCHECK(IsDangerous());
+ switch (download_->GetDangerType()) {
+ case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
+ return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL);
+
+ case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
+ if (ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) {
+ return l10n_util::GetStringUTF16(
+ IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION);
+ } else {
+ return l10n_util::GetStringFUTF16(
+ IDS_PROMPT_DANGEROUS_DOWNLOAD,
+ ui::ElideFilename(download_->GetFileNameToReportUser(),
+ font, base_width));
+ }
+
+ case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
+ return l10n_util::GetStringFUTF16(
+ IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT,
+ ui::ElideFilename(download_->GetFileNameToReportUser(),
+ font, base_width));
+
+ case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS:
+ case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT:
+ case content::DOWNLOAD_DANGER_TYPE_MAX:
+ NOTREACHED();
+ }
+ return string16();
+}
+
+string16 DownloadItemModel::GetWarningConfirmButtonText() {
+ // Should only be called if IsDangerous()
+ DCHECK(IsDangerous());
+ if (download_->GetDangerType() ==
+ content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE &&
+ ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) {
+ return l10n_util::GetStringUTF16(IDS_CONTINUE_EXTENSION_DOWNLOAD);
+ } else {
+ return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD);
+ }
+}
+
+bool DownloadItemModel::IsMalicious() {
+ if (!IsDangerous())
+ return false;
+ switch (download_->GetDangerType()) {
+ case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
+ case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
+ return true;
+
+ case content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS:
+ case content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT:
+ case content::DOWNLOAD_DANGER_TYPE_MAX:
+ // We shouldn't get any of these due to the IsDangerous() test above.
+ NOTREACHED();
+ // Fallthrough.
+ case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
+ return false;
+ }
+ NOTREACHED();
+ return false;
+}
+
+bool DownloadItemModel::IsDangerous() {
+ return download_->GetSafetyState() == DownloadItem::DANGEROUS;
+}
« no previous file with comments | « chrome/browser/download/download_item_model.h ('k') | chrome/browser/download/download_shelf_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698