diff options
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_item_model.cc | 73 | ||||
-rw-r--r-- | chrome/browser/download/download_item_model.h | 38 | ||||
-rw-r--r-- | chrome/browser/download/download_shelf_context_menu.cc | 19 |
3 files changed, 109 insertions, 21 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; } |