diff options
Diffstat (limited to 'chrome/browser/ui/cocoa')
3 files changed, 22 insertions, 65 deletions
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]; } |