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

Unified Diff: chrome/browser/ui/views/download/download_item_view.cc

Issue 9569011: Refactor dangerous download warning text generation into DownloadItemModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use ui::ElideText() 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/ui/views/download/download_item_view.cc
diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc
index 0f94520a67d387c5db7c0c0c3f8ac36f56eed355..e04cb07d222ccfc750d618f9432ba3ab1c9abada 100644
--- a/chrome/browser/ui/views/download/download_item_view.cc
+++ b/chrome/browser/ui/views/download/download_item_view.cc
@@ -49,10 +49,6 @@ static const int kVerticalPadding = 3; // Pixels
static const int kVerticalTextSpacer = 2; // Pixels
static const int kVerticalTextPadding = 2; // Pixels
-// The maximum number of characters we show in a file name when displaying the
-// dangerous download message.
-static const int kFileNameMaxLength = 20;
-
// We add some padding before the left image so that the progress animation icon
// hides the corners of the left image.
static const int kLeftPadding = 0; // Pixels.
@@ -1004,16 +1000,8 @@ void DownloadItemView::ClearWarningDialog() {
void DownloadItemView::ShowWarningDialog() {
DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE);
- if (download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ||
- download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT) {
- mode_ = MALICIOUS_MODE;
- } else {
- DCHECK(download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
- mode_ = DANGEROUS_MODE;
- }
+ mode_ = ((model_->IsMalicious()) ? MALICIOUS_MODE : DANGEROUS_MODE);
+
body_state_ = NORMAL;
drop_down_state_ = NORMAL;
tooltip_text_.clear();
@@ -1030,74 +1018,16 @@ void DownloadItemView::ShowWarningDialog() {
discard_button_->set_ignore_minimum_size(true);
AddChildView(discard_button_);
- // Ensure the file name is not too long.
-
- // Extract the file extension (if any).
- FilePath filename(download_->GetTargetName());
-#if defined(OS_POSIX)
- string16 extension = WideToUTF16(base::SysNativeMBToWide(
- filename.Extension()));
-#else
- string16 extension = filename.Extension();
-#endif
-
- // Remove leading '.'
- if (extension.length() > 0)
- extension = extension.substr(1);
-#if defined(OS_POSIX)
- string16 rootname = WideToUTF16(base::SysNativeMBToWide(
- filename.RemoveExtension().value()));
-#else
- string16 rootname = filename.RemoveExtension().value();
-#endif
-
- // Elide giant extensions (this shouldn't currently be hit, but might
- // in future, should we ever notice unsafe giant extensions).
- if (extension.length() > kFileNameMaxLength / 2)
- ui::ElideString(extension, kFileNameMaxLength / 2, &extension);
-
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- // The dangerous download label text and icon are different
- // under different cases.
+ // The dangerous download label text and icon are different under
+ // different cases.
if (mode_ == MALICIOUS_MODE) {
warning_icon_ = rb.GetBitmapNamed(IDR_SAFEBROWSING_WARNING);
} else {
- DCHECK(download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
// The download file has dangerous file type (e.g.: an executable).
warning_icon_ = rb.GetBitmapNamed(IDR_WARNING);
}
- string16 dangerous_label;
- if (download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL) {
- // Safebrowsing shows the download URL or content leads to malicious file.
- dangerous_label = l10n_util::GetStringUTF16(
- IDS_PROMPT_MALICIOUS_DOWNLOAD_URL);
- } else if (download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE &&
- ChromeDownloadManagerDelegate::IsExtensionDownload(download_)) {
- dangerous_label =
- l10n_util::GetStringUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION);
- } else {
- // The download file has dangerous file type (e.g.: an executable) or the
- // file content is known to be malicious.
- DCHECK(download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ||
- download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT);
- ui::ElideString(rootname,
- kFileNameMaxLength - extension.length(),
- &rootname);
- string16 filename = rootname + ASCIIToUTF16(".") + extension;
- filename = base::i18n::GetDisplayStringInLTRDirectionality(filename);
- dangerous_label = l10n_util::GetStringFUTF16(
- download_->GetDangerType() ==
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ?
- IDS_PROMPT_DANGEROUS_DOWNLOAD :
- IDS_PROMPT_MALICIOUS_DOWNLOAD_CONTENT,
- filename);
- }
-
+ string16 dangerous_label = model_->GetWarningText(font_, kTextWidth);
dangerous_download_label_ = new views::Label(dangerous_label);
dangerous_download_label_->SetMultiLine(true);
dangerous_download_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);

Powered by Google App Engine
This is Rietveld 408576698