summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorhawk@chromium.org <hawk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-09 23:41:56 +0000
committerhawk@chromium.org <hawk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-09 23:41:56 +0000
commit3ed662c37a3d881feb5b6578eb2e0e44586b3f1a (patch)
tree196ba3d53a87ff7b5bdd75068fe5a8ad8135569b /chrome/browser
parent3552fa6183e31f36f102ca668955676a4e35516e (diff)
downloadchromium_src-3ed662c37a3d881feb5b6578eb2e0e44586b3f1a.zip
chromium_src-3ed662c37a3d881feb5b6578eb2e0e44586b3f1a.tar.gz
chromium_src-3ed662c37a3d881feb5b6578eb2e0e44586b3f1a.tar.bz2
Add EV certificate text to the Mac location bar
BUG=10910 TEST=EV sites (e.g., http://www.paypal.com and most bank sites) get a green text description next to the lock icon in the location bar, non-EV (and non-SSL) sites do not Review URL: http://codereview.chromium.org/216031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28627 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.h10
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.mm59
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm48
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_unittest.mm2
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm30
5 files changed, 132 insertions, 17 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.h b/chrome/browser/cocoa/autocomplete_text_field_cell.h
index 47fbb52..7715b4f 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.h
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.h
@@ -40,6 +40,11 @@
// Icon that represents the state of the SSL connection
scoped_nsobject<NSImage> hintIcon_;
+
+ // Optional text that appears to the right of the hint icon which
+ // appears only alongside the icon (i.e., it's possible to display a
+ // hintIcon without an hintIconLabel, but not vice-versa).
+ scoped_nsobject<NSAttributedString> hintIconLabel_;
}
@property BOOL fieldEditorNeedsReset;
@@ -59,7 +64,9 @@
- (void)setSearchHintString:(NSString*)aString;
- (void)clearKeywordAndHint;
-- (void)setHintIcon:(NSImage*)icon;
+// Sets the hint icon and optional icon label. If |icon| is nil, the current
+// icon is cleared. If |label| is provided, |color| must be provided as well.
+- (void)setHintIcon:(NSImage*)icon label:(NSString*)label color:(NSColor*)color;
// Return the portion of the cell to show the text cursor over.
- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame;
@@ -79,5 +86,6 @@
@property(readonly) NSAttributedString* keywordString;
@property(readonly) NSAttributedString* hintString;
@property(readonly) NSImage* hintIcon;
+@property(readonly) NSAttributedString* hintIconLabel;
@end
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
index 10ae6f4..edaf16d 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
@@ -4,6 +4,8 @@
#import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
+#include "app/gfx/font.h"
+#include "app/resource_bundle.h"
#import "base/logging.h"
#import "third_party/GTM/AppKit/GTMTheme.h"
@@ -40,7 +42,10 @@ const NSInteger kKeywordHintImageBaseline = -6;
const NSInteger kBaselineOffset = 4;
// The amount of padding on either side reserved for drawing the hint icon
-const NSInteger kHintIconHorizontalPad = 5;
+const NSInteger kHintIconHorizontalPad = 3;
+
+// How far to shift bounding box of hint icon label down from top of field.
+const NSInteger kHintIconLabelYOffset = 7;
} // namespace
@@ -159,10 +164,34 @@ const NSInteger kHintIconHorizontalPad = 5;
}
}
-- (void)setHintIcon:(NSImage*)icon {
- if (icon != hintIcon_) {
+- (void)setHintIcon:(NSImage*)icon
+ label:(NSString*)label
+ color:(NSColor*)color {
+ // Create an attributed string for the label, if a label was given.
+ NSAttributedString* as = nil;
+ if (label) {
+ DCHECK(color);
+ NSFont *baseFont = [self font];
+ NSFont *font = [NSFont fontWithDescriptor:[baseFont fontDescriptor]
+ size:[baseFont pointSize] - 2.0];
+ NSDictionary* attributes =
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ color, NSForegroundColorAttributeName,
+ font, NSFontAttributeName,
+ NULL];
+ as = [[[NSAttributedString alloc] initWithString:label
+ attributes:attributes] autorelease];
+ }
+
+ // Did the icon change? Is there a label now but there wasn't before,
+ // or vice-versa? Did the label change?
+ if (icon != hintIcon_.get() || (as && !hintIconLabel_.get()) ||
+ (!as && hintIconLabel_.get()) ||
+ (as && ![hintIconLabel_.get() isEqualToAttributedString:as])) {
+ hintIconLabel_.reset([as retain]);
hintIcon_.reset([icon retain]);
if (!keywordString_ && !hintString_) {
+ // Redraw if the icon is visible.
fieldEditorNeedsReset_ = YES;
}
}
@@ -239,6 +268,9 @@ const NSInteger kHintIconHorizontalPad = 5;
} else if (hintIcon_) {
CGFloat width = [hintIcon_ size].width;
width += kHintIconHorizontalPad * 2;
+ if (hintIconLabel_) {
+ width += ceil([hintIconLabel_ size].width) + kHintXOffset;
+ }
if (width < NSWidth(cellFrame)) {
textFrame.size.width -= width;
}
@@ -258,8 +290,15 @@ const NSInteger kHintIconHorizontalPad = 5;
// We'll draw the entire image
const NSSize imageRect([hintIcon_ size]);
- // Move the rect that we're drawing into to the far right
+ CGFloat labelWidth = 0;
+ if (hintIconLabel_) {
+ labelWidth = ceil([hintIconLabel_ size].width) + kHintXOffset;
+ }
+
+ // Move the rect that we're drawing into to the far right, minus
+ // enough space for the label (if present)
cellFrame.origin.x += cellFrame.size.width - imageRect.width;
+ cellFrame.origin.x -= labelWidth;
// Add back the padding
cellFrame.origin.x -= kHintIconHorizontalPad;
@@ -316,11 +355,21 @@ const NSInteger kHintIconHorizontalPad = 5;
- (void)drawHintIconWithFrame:(NSRect)cellFrame
inView:(NSView*)controlView {
+ // If there's a label, draw it to the right of the icon.
+ CGFloat labelWidth = 0;
+ if (hintIconLabel_) {
+ labelWidth = ceil([hintIconLabel_ size].width) + kHintXOffset;
+ NSRect textFrame(NSMakeRect(NSMaxX(cellFrame) - labelWidth,
+ cellFrame.origin.y + kHintIconLabelYOffset,
+ labelWidth,
+ cellFrame.size.height - kHintIconLabelYOffset));
+ [hintIconLabel_.get() drawInRect:textFrame];
+ }
+
// We'll draw the entire image
NSRect imageRect = NSZeroRect;
imageRect.size = [hintIcon_ size];
const NSRect hintFrame([self hintImageFrameForFrame:cellFrame]);
-
[hintIcon_ setFlipped:[controlView isFlipped]];
[hintIcon_ drawInRect:hintFrame
fromRect:imageRect
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
index ef8d415..e0d5cbb 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm
@@ -144,20 +144,54 @@ TEST_F(AutocompleteTextFieldCellTest, SecurityIcon) {
NSImage* image1 = [NSImage imageNamed:@"NSApplicationIcon"];
// Setting a security icon will need a reset.
- [cell setHintIcon:image1];
+ [cell setHintIcon:image1 label:nil color:nil];
EXPECT_TRUE([cell fieldEditorNeedsReset]);
[cell setFieldEditorNeedsReset:NO];
EXPECT_FALSE([cell fieldEditorNeedsReset]);
// Changing the security icon needs a reset.
NSImage* image2 = [NSImage imageNamed:@"NSComputer"];
- [cell setHintIcon:image2];
+ [cell setHintIcon:image2 label:nil color:nil];
EXPECT_TRUE([cell fieldEditorNeedsReset]);
[cell setFieldEditorNeedsReset:NO];
EXPECT_FALSE([cell fieldEditorNeedsReset]);
// Changing to an identical security icon doesn't need a reset.
- [cell setHintIcon:image2];
+ [cell setHintIcon:image2 label:nil color:nil];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Adding a label without changing the icon needs a reset.
+ NSColor *color = [NSColor blackColor];
+ [cell setHintIcon:image2 label:@"New Label" color:color];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+
+ // Removing the label without changing the icon needs a reset.
+ [cell setHintIcon:image2 label:nil color:nil];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+}
+
+TEST_F(AutocompleteTextFieldCellTest, SecurityIconLabel) {
+ AutocompleteTextFieldCell* cell =
+ static_cast<AutocompleteTextFieldCell*>([view_ cell]);
+ NSColor *color = [NSColor blackColor];
+
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
+ // Setting a security icon will need a reset.
+ [cell setHintIcon:image label:@"Hello, world" color:color];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing the label needs a reset.
+ [cell setHintIcon:image label:@"Hello, you" color:color];
+ EXPECT_TRUE([cell fieldEditorNeedsReset]);
+ [cell setFieldEditorNeedsReset:NO];
+ EXPECT_FALSE([cell fieldEditorNeedsReset]);
+
+ // Changing to an identical label doesn't need a reset
+ [cell setHintIcon:image label:@"Hello, you" color:color];
EXPECT_FALSE([cell fieldEditorNeedsReset]);
}
@@ -289,7 +323,7 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) {
EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame));
// Hint icon takes up space on the right
- [cell setHintIcon:[NSImage imageNamed:@"NSComputer"]];
+ [cell setHintIcon:[NSImage imageNamed:@"NSComputer"] label:nil color:nil];
textFrame = [cell textFrameForFrame:bounds];
EXPECT_FALSE(NSIsEmptyRect(textFrame));
EXPECT_TRUE(NSContainsRect(bounds, textFrame));
@@ -348,7 +382,7 @@ TEST_F(AutocompleteTextFieldCellTest, DrawingRectForBounds) {
EXPECT_TRUE(NSContainsRect(NSInsetRect(textFrame, 1, 1), drawingRect));
EXPECT_TRUE(NSEqualRects(drawingRect, originalDrawingRect));
- [cell setHintIcon:[NSImage imageNamed:@"NSComputer"]];
+ [cell setHintIcon:[NSImage imageNamed:@"NSComputer"] label:nil color:nil];
textFrame = [cell textFrameForFrame:bounds];
drawingRect = [cell drawingRectForBounds:bounds];
EXPECT_FALSE(NSIsEmptyRect(drawingRect));
@@ -369,7 +403,7 @@ TEST_F(AutocompleteTextFieldCellTest, HintImageFrame) {
// Save the starting frame for after clear.
const NSRect originalIconRect(iconRect);
- [cell setHintIcon:hintIcon];
+ [cell setHintIcon:hintIcon label:nil color:nil];
iconRect = [cell hintImageFrameForFrame:bounds];
EXPECT_FALSE(NSIsEmptyRect(iconRect));
EXPECT_TRUE(NSContainsRect(bounds, iconRect));
@@ -383,7 +417,7 @@ TEST_F(AutocompleteTextFieldCellTest, HintImageFrame) {
EXPECT_LE(NSMaxX(textFrame), NSMinX(iconRect));
// Make sure we clear correctly.
- [cell setHintIcon:nil];
+ [cell setHintIcon:nil label:nil color:nil];
iconRect = [cell hintImageFrameForFrame:bounds];
EXPECT_TRUE(NSEqualRects(iconRect, originalIconRect));
EXPECT_TRUE(NSIsEmptyRect(iconRect));
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
index be6c422..b6e5be5 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
@@ -528,7 +528,7 @@ TEST_F(AutocompleteTextFieldTest, SecurityIconMouseDown) {
AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
scoped_nsobject<NSImage> hintIcon(
[[NSImage alloc] initWithSize:NSMakeSize(20, 20)]);
- [cell setHintIcon:hintIcon.get()];
+ [cell setHintIcon:hintIcon.get() label:nil color:nil];
NSRect iconFrame([cell hintImageFrameForFrame:[field_ bounds]]);
NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)));
NSEvent* event(Event(field_, location, NSLeftMouseDown, 1));
diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm
index 0701752..f59d90d 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar_view_mac.mm
@@ -43,6 +43,12 @@ std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword) {
return std::wstring();
}
+// Values for the green text color displayed for EV certificates, based
+// on the values for kEvTextColor in location_bar_view_gtk.cc.
+static const CGFloat kEvTextColorRedComponent = 0.0;
+static const CGFloat kEvTextColorGreenComponent = 0.59;
+static const CGFloat kEvTextColorBlueComponent = 0.08;
+
} // namespace
LocationBarViewMac::LocationBarViewMac(
@@ -267,17 +273,35 @@ NSImage* LocationBarViewMac::GetTabButtonImage() {
}
void LocationBarViewMac::SetSecurityIcon(ToolbarModel::Icon security_icon) {
+ std::wstring info_text, info_tooltip;
+ ToolbarModel::InfoTextType info_text_type =
+ toolbar_model_->GetInfoText(&info_text, &info_tooltip);
+ NSColor* color = nil;
+ NSString* icon_label = nil;
+ if (info_text_type == ToolbarModel::INFO_EV_TEXT) {
+ icon_label = base::SysWideToNSString(info_text);
+ color =
+ [NSColor colorWithCalibratedRed:kEvTextColorRedComponent
+ green:kEvTextColorGreenComponent
+ blue:kEvTextColorBlueComponent
+ alpha:1.0];
+ }
+
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
switch (security_icon) {
case ToolbarModel::LOCK_ICON:
- [cell setHintIcon:rb.GetNSImageNamed(IDR_LOCK)];
+ [cell setHintIcon:rb.GetNSImageNamed(IDR_LOCK)
+ label:icon_label
+ color:color];
break;
case ToolbarModel::WARNING_ICON:
- [cell setHintIcon:rb.GetNSImageNamed(IDR_WARNING)];
+ [cell setHintIcon:rb.GetNSImageNamed(IDR_WARNING)
+ label:icon_label
+ color:color];
break;
case ToolbarModel::NO_ICON:
- [cell setHintIcon:nil];
+ [cell setHintIcon:nil label:nil color:nil];
break;
default:
NOTREACHED();