diff options
Diffstat (limited to 'chrome/browser')
9 files changed, 154 insertions, 220 deletions
diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc index feb0c0b..c245449 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; +} diff --git a/chrome/browser/download/download_item_model.h b/chrome/browser/download/download_item_model.h index db81467..2eb9375 100644 --- a/chrome/browser/download/download_item_model.h +++ b/chrome/browser/download/download_item_model.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,8 +18,11 @@ namespace content { class DownloadItem; } -// This class provides an interface for functions which have different behaviors -// depending on the type of download. +namespace gfx { +class Font; +} + +// This class is an abstraction for common UI tasks associated with a download. class BaseDownloadItemModel { public: explicit BaseDownloadItemModel(content::DownloadItem* download) @@ -32,25 +35,42 @@ class BaseDownloadItemModel { // Get the status text to display. virtual string16 GetStatusText() = 0; + // Get the warning text to display for a dangerous download. The |base_width| + // is the maximum width of an embedded filename (if there is one). The metrics + // for the filename will be based on |font|. Should only be called if + // IsDangerous() is true. + virtual string16 GetWarningText(const gfx::Font& font, int base_width) = 0; + + // Get the caption text for a button for confirming a dangerous download + // warning. + virtual string16 GetWarningConfirmButtonText() = 0; + + // Is this considered a malicious download? Implies IsDangerous(). + virtual bool IsMalicious() = 0; + + // Is this considered a dangerous download? + virtual bool IsDangerous() = 0; + content::DownloadItem* download() { return download_; } protected: content::DownloadItem* download_; }; -// This class is a model class for DownloadItemView. It provides functionality -// for canceling the downloading, and also the text for displaying downloading -// status. +// Concrete implementation of BaseDownloadItemModel. class DownloadItemModel : public BaseDownloadItemModel { public: explicit DownloadItemModel(content::DownloadItem* download); virtual ~DownloadItemModel() { } - // Cancel the downloading. + // BaseDownloadItemModel virtual void CancelTask() OVERRIDE; - - // Get downloading status text. virtual string16 GetStatusText() OVERRIDE; + virtual string16 GetWarningText(const gfx::Font& font, + int base_width) OVERRIDE; + virtual string16 GetWarningConfirmButtonText() OVERRIDE; + virtual bool IsMalicious() OVERRIDE; + virtual bool IsDangerous() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(DownloadItemModel); diff --git a/chrome/browser/download/download_shelf_context_menu.cc b/chrome/browser/download/download_shelf_context_menu.cc index 7456b82..dd220f3 100644 --- a/chrome/browser/download/download_shelf_context_menu.cc +++ b/chrome/browser/download/download_shelf_context_menu.cc @@ -28,21 +28,16 @@ DownloadShelfContextMenu::DownloadShelfContextMenu( ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { ui::SimpleMenuModel* model = NULL; + // We shouldn't be opening a context menu for a dangerous download, unless it + // is a malicious download. + DCHECK(!download_model_->IsDangerous() || download_model_->IsMalicious()); - if (download_item_->GetSafetyState() == DownloadItem::DANGEROUS) { - if (download_item_->GetDangerType() == - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || - download_item_->GetDangerType() == - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT) { - model = GetMaliciousMenuModel(); - } else { - NOTREACHED(); - } - } else if (download_item_->IsComplete()) { + if (download_model_->IsMalicious()) + model = GetMaliciousMenuModel(); + else if (download_item_->IsComplete()) model = GetFinishedMenuModel(); - } else { + else model = GetInProgressMenuModel(); - } return model; } diff --git a/chrome/browser/ui/cocoa/download/download_item_controller.h b/chrome/browser/ui/cocoa/download/download_item_controller.h index d06cb14..1a64dcc 100644 --- a/chrome/browser/ui/cocoa/download/download_item_controller.h +++ b/chrome/browser/ui/cocoa/download/download_item_controller.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,6 +20,10 @@ namespace content { class DownloadItem; } +namespace gfx { +class Font; +} + // A controller class that manages one download item. @interface DownloadItemController : NSViewController { @@ -56,6 +60,9 @@ class DownloadItem; // The time at which this view was created. base::Time creationTime_; + // Default font to use for text metrics. + scoped_ptr<gfx::Font> font_; + // The state of this item. enum DownoadItemState { kNormal, diff --git a/chrome/browser/ui/cocoa/download/download_item_controller.mm b/chrome/browser/ui/cocoa/download/download_item_controller.mm index aa896e5..faac76d 100644 --- a/chrome/browser/ui/cocoa/download/download_item_controller.mm +++ b/chrome/browser/ui/cocoa/download/download_item_controller.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -29,6 +29,7 @@ #include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/text/text_elider.h" +#include "ui/gfx/font.h" #include "ui/gfx/image/image.h" using content::DownloadItem; @@ -41,10 +42,6 @@ namespace { // rules so all platforms can get inline in the future. const int kTextWidth = 140; // Pixels -// The maximum number of characters we show in a file name when displaying the -// dangerous download message. -const int kFileNameMaxLength = 20; - // The maximum width in pixels for the file name tooltip. const int kToolTipMaxWidth = 900; @@ -117,6 +114,7 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { shelf_ = shelf; state_ = kNormal; creationTime_ = base::Time::Now(); + font_.reset(new gfx::Font()); } return self; } @@ -165,7 +163,7 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { DCHECK_EQ(bridge_->download_model(), downloadModel); // Handle dangerous downloads. - if (downloadModel->download()->GetSafetyState() == DownloadItem::DANGEROUS) { + if (downloadModel->IsDangerous()) { [self setState:kDangerous]; ResourceBundle& rb = ResourceBundle::GetSharedInstance(); @@ -173,61 +171,15 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { NSString* confirmButtonTitle; NSImage* alertIcon; - // The dangerous download label, button text and icon are different under - // different cases. - if (downloadModel->download()->GetDangerType() == - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL) { - // TODO(noelutz): add support for malicious content. - // Safebrowsing shows the download URL leads to malicious file. + dangerousWarning = + base::SysUTF16ToNSString(downloadModel->GetWarningText( + *font_, kTextWidth)); + confirmButtonTitle = + base::SysUTF16ToNSString(downloadModel->GetWarningConfirmButtonText()); + if (downloadModel->IsMalicious()) alertIcon = rb.GetNativeImageNamed(IDR_SAFEBROWSING_WARNING); - dangerousWarning = l10n_util::GetNSStringWithFixup( - IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); - confirmButtonTitle = l10n_util::GetNSStringWithFixup( - IDS_CONFIRM_DOWNLOAD); - } else { - // It's a dangerous file type (e.g.: an executable). - DCHECK_EQ(downloadModel->download()->GetDangerType(), - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); + else alertIcon = rb.GetNativeImageNamed(IDR_WARNING); - if (ChromeDownloadManagerDelegate::IsExtensionDownload( - downloadModel->download())) { - dangerousWarning = l10n_util::GetNSStringWithFixup( - IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); - confirmButtonTitle = l10n_util::GetNSStringWithFixup( - IDS_CONTINUE_EXTENSION_DOWNLOAD); - } else { - // This basic fixup copies Windows DownloadItemView::DownloadItemView(). - - // Extract the file extension (if any). - FilePath filename(downloadModel->download()->GetTargetName()); - FilePath::StringType extension = filename.Extension(); - - // Remove leading '.' from the extension - if (extension.length() > 0) - extension = extension.substr(1); - - // Elide giant extensions. - if (extension.length() > kFileNameMaxLength / 2) { - string16 utf16_extension; - ui::ElideString(UTF8ToUTF16(extension), kFileNameMaxLength / 2, - &utf16_extension); - extension = UTF16ToUTF8(utf16_extension); - } - - // Rebuild the filename.extension. - string16 rootname = UTF8ToUTF16(filename.RemoveExtension().value()); - ui::ElideString(rootname, kFileNameMaxLength - extension.length(), - &rootname); - std::string new_filename = UTF16ToUTF8(rootname); - if (extension.length()) - new_filename += std::string(".") + extension; - - dangerousWarning = l10n_util::GetNSStringFWithFixup( - IDS_PROMPT_DANGEROUS_DOWNLOAD, UTF8ToUTF16(new_filename)); - confirmButtonTitle = - l10n_util::GetNSStringWithFixup(IDS_CONFIRM_DOWNLOAD); - } - } DCHECK(alertIcon); [image_ setImage:alertIcon]; DCHECK(dangerousWarning); @@ -294,8 +246,7 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu { - (void)updateToolTip { string16 elidedFilename = ui::ElideFilename( - [self download]->GetFileNameToReportUser(), - gfx::Font(), kToolTipMaxWidth); + [self download]->GetFileNameToReportUser(), *font_, kToolTipMaxWidth); [progressView_ setToolTip:base::SysUTF16ToNSString(elidedFilename)]; } diff --git a/chrome/browser/ui/cocoa/download/download_item_mac.mm b/chrome/browser/ui/cocoa/download/download_item_mac.mm index 8322196..ebe669cd 100644 --- a/chrome/browser/ui/cocoa/download/download_item_mac.mm +++ b/chrome/browser/ui/cocoa/download/download_item_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -30,8 +30,7 @@ DownloadItemMac::~DownloadItemMac() { void DownloadItemMac::OnDownloadUpdated(content::DownloadItem* download) { DCHECK_EQ(download, download_model_->download()); - if ([item_controller_ isDangerousMode] && - download->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED) { + if ([item_controller_ isDangerousMode] && !download_model_->IsDangerous()) { // We have been approved. [item_controller_ clearDangerousMode]; } diff --git a/chrome/browser/ui/gtk/download/download_item_gtk.cc b/chrome/browser/ui/gtk/download/download_item_gtk.cc index d360572..f69f5ae 100644 --- a/chrome/browser/ui/gtk/download/download_item_gtk.cc +++ b/chrome/browser/ui/gtk/download/download_item_gtk.cc @@ -193,7 +193,7 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); gtk_widget_show_all(hbox_.get()); - if (IsDangerous()) { + if (download_model_->IsDangerous()) { // Hide the download item components for now. gtk_widget_set_no_show_all(body_.get(), TRUE); gtk_widget_set_no_show_all(menu_button_, TRUE); @@ -233,11 +233,7 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, // Create the ok button. GtkWidget* dangerous_accept = gtk_button_new_with_label( - l10n_util::GetStringUTF8( - ChromeDownloadManagerDelegate::IsExtensionDownload( - download_model->download()) ? - IDS_CONTINUE_EXTENSION_DOWNLOAD : - IDS_CONFIRM_DOWNLOAD).c_str()); + UTF16ToUTF8(download_model_->GetWarningConfirmButtonText()).c_str()); g_signal_connect(dangerous_accept, "clicked", G_CALLBACK(OnDangerousAcceptThunk), this); gtk_util::CenterWidgetInHBox(dangerous_hbox_.get(), dangerous_accept, false, @@ -263,7 +259,7 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, theme_service_->InitThemesFor(this); // Set the initial width of the widget to be animated. - if (IsDangerous()) { + if (download_model_->IsDangerous()) { gtk_widget_set_size_request(dangerous_hbox_.get(), dangerous_hbox_start_width_, -1); } else { @@ -301,8 +297,7 @@ DownloadItemGtk::~DownloadItemGtk() { void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { DCHECK_EQ(download, get_download()); - if (dangerous_prompt_ != NULL && - download->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED) { + if (dangerous_prompt_ != NULL && !download_model_->IsDangerous()) { // We have been approved. gtk_widget_set_no_show_all(body_.get(), FALSE); gtk_widget_set_no_show_all(menu_button_, FALSE); @@ -375,7 +370,7 @@ void DownloadItemGtk::AnimationProgressed(const ui::Animation* animation) { gtk_widget_queue_draw(progress_area_.get()); } else { DCHECK(animation == new_item_animation_.get()); - if (IsDangerous()) { + if (download_model_->IsDangerous()) { int progress = static_cast<int>((dangerous_hbox_full_width_ - dangerous_hbox_start_width_) * animation->GetCurrentValue()); @@ -425,10 +420,6 @@ DownloadItem* DownloadItemGtk::get_download() { return download_model_->download(); } -bool DownloadItemGtk::IsDangerous() { - return get_download()->GetSafetyState() == DownloadItem::DANGEROUS; -} - // Download progress animation functions. void DownloadItemGtk::UpdateDownloadProgress() { @@ -566,31 +557,8 @@ void DownloadItemGtk::UpdateDangerWarning() { // We create |dangerous_warning| as a wide string so we can more easily // calculate its length in characters. - string16 dangerous_warning; - - // The dangerous download label text is different for different cases. - if (get_download()->GetDangerType() == - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL) { - // TODO(noelutz): handle malicious content warning. - // Safebrowsing shows the download URL leads to malicious file. - dangerous_warning = - l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); - } else { - // It's a dangerous file type (e.g.: an executable). - DCHECK(get_download()->GetDangerType() == - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); - if (ChromeDownloadManagerDelegate::IsExtensionDownload(get_download())) { - dangerous_warning = - l10n_util::GetStringUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD_EXTENSION); - } else { - string16 elided_filename = ui::ElideFilename( - get_download()->GetTargetName(), gfx::Font(), kTextWidth); - dangerous_warning = - l10n_util::GetStringFUTF16(IDS_PROMPT_DANGEROUS_DOWNLOAD, - elided_filename); - } - } - + string16 dangerous_warning = + download_model_->GetWarningText(gfx::Font(), kTextWidth); if (theme_service_->UsingNativeTheme()) { gtk_util::SetLabelColor(dangerous_label_, NULL); } else { @@ -637,17 +605,15 @@ void DownloadItemGtk::UpdateDangerWarning() { void DownloadItemGtk::UpdateDangerIcon() { if (theme_service_->UsingNativeTheme()) { - const char* stock = get_download()->GetDangerType() == - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ? - GTK_STOCK_DIALOG_ERROR : GTK_STOCK_DIALOG_WARNING; + const char* stock = download_model_->IsMalicious() ? + GTK_STOCK_DIALOG_ERROR : GTK_STOCK_DIALOG_WARNING; gtk_image_set_from_stock( GTK_IMAGE(dangerous_image_), stock, GTK_ICON_SIZE_SMALL_TOOLBAR); } else { // Set the warning icon. ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - int pixbuf_id = get_download()->GetDangerType() == - content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ? - IDR_SAFEBROWSING_WARNING : IDR_WARNING; + int pixbuf_id = download_model_->IsMalicious() ? + IDR_SAFEBROWSING_WARNING : IDR_WARNING; GdkPixbuf* download_pixbuf = rb.GetNativeImageNamed(pixbuf_id); gtk_image_set_from_pixbuf(GTK_IMAGE(dangerous_image_), download_pixbuf); } @@ -729,7 +695,7 @@ gboolean DownloadItemGtk::OnHboxExpose(GtkWidget* widget, GdkEventExpose* e) { int width = allocation.width - border_width * 2; int height = allocation.height - border_width * 2; - if (IsDangerous()) { + if (download_model_->IsDangerous()) { // Draw a simple frame around the area when we're displaying the warning. gtk_paint_shadow(gtk_widget_get_style(widget), gtk_widget_get_window(widget), diff --git a/chrome/browser/ui/gtk/download/download_item_gtk.h b/chrome/browser/ui/gtk/download/download_item_gtk.h index bc0cfd3..b9be8a3 100644 --- a/chrome/browser/ui/gtk/download/download_item_gtk.h +++ b/chrome/browser/ui/gtk/download/download_item_gtk.h @@ -73,9 +73,6 @@ class DownloadItemGtk : public content::DownloadItem::Observer, private: friend class DownloadShelfContextMenuGtk; - // Returns true IFF the download is dangerous and unconfirmed. - bool IsDangerous(); - // Functions for controlling the progress animation. // Repaint the download progress. void UpdateDownloadProgress(); diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc index 0f94520..2a41b5d 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. @@ -205,7 +201,7 @@ DownloadItemView::DownloadItemView(DownloadItem* download, UpdateDropDownButtonPosition(); - if (download->GetSafetyState() == DownloadItem::DANGEROUS) + if (model_->IsDangerous()) ShowWarningDialog(); UpdateAccessibleName(); @@ -255,12 +251,10 @@ void DownloadItemView::OnExtractIconComplete(IconManager::Handle handle, void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { DCHECK(download == download_); - if (IsShowingWarningDialog() && - download->GetSafetyState() == DownloadItem::DANGEROUS_BUT_VALIDATED) { + if (IsShowingWarningDialog() && !model_->IsDangerous()) { // We have been approved. ClearWarningDialog(); - } else if (!IsShowingWarningDialog() && - download->GetSafetyState() == DownloadItem::DANGEROUS) { + } else if (!IsShowingWarningDialog() && model_->IsDangerous()) { ShowWarningDialog(); // Force the shelf to layout again as our size has changed. parent_->Layout(); @@ -573,7 +567,7 @@ void DownloadItemView::ShowContextMenu(const gfx::Point& p, void DownloadItemView::GetAccessibleState(ui::AccessibleViewState* state) { state->name = accessible_name_; state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; - if (download_->GetSafetyState() == DownloadItem::DANGEROUS) { + if (model_->IsDangerous()) { state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE; } else { state->state = ui::AccessibilityTypes::STATE_HASPOPUP; @@ -1004,24 +998,14 @@ 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(); if (mode_ == DANGEROUS_MODE) { - save_button_ = new views::NativeTextButton(this, - l10n_util::GetStringUTF16( - ChromeDownloadManagerDelegate::IsExtensionDownload(download_) ? - IDS_CONTINUE_EXTENSION_DOWNLOAD : IDS_CONFIRM_DOWNLOAD)); + save_button_ = new views::NativeTextButton( + this, model_->GetWarningConfirmButtonText()); save_button_->set_ignore_minimum_size(true); AddChildView(save_button_); } @@ -1030,74 +1014,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); |