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

Unified Diff: chrome/browser/ui/cocoa/download/download_item_controller.mm

Issue 9569011: Refactor dangerous download warning text generation into DownloadItemModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Kill some more code. 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/cocoa/download/download_item_controller.mm
diff --git a/chrome/browser/ui/cocoa/download/download_item_controller.mm b/chrome/browser/ui/cocoa/download/download_item_controller.mm
index aa896e5c66d60e697de2316a03d5bf6587cbbad3..965934df27505909eb11dd40021b11f33caf8cb7 100644
--- a/chrome/browser/ui/cocoa/download/download_item_controller.mm
+++ b/chrome/browser/ui/cocoa/download/download_item_controller.mm
@@ -41,10 +41,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;
@@ -165,7 +161,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 +169,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(
+ gfx::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);
Nico 2012/03/02 18:11:39 It looks like this previously didn't have to creat
asanka 2012/03/02 19:14:10 Looking at PlatformFontMac, I now see how this can
asanka 2012/03/05 17:49:25 Added a persistent font_ member that is used for t
- 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);

Powered by Google App Engine
This is Rietveld 408576698