| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/autofill/autofill_text_field_mac.h" | 5 #import "chrome/browser/autofill/autofill_text_field_mac.h" |
| 6 | 6 |
| 7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 #include "chrome/browser/autofill/credit_card.h" | 8 #include "chrome/browser/autofill/credit_card.h" |
| 9 | 9 |
| 10 @implementation AutoFillTextField | 10 @implementation AutoFillTextField |
| 11 | 11 |
| 12 - (void)awakeFromNib { | 12 - (void)awakeFromNib { |
| 13 // Fields tagged with this value in the nib file will be treated as credit | 13 // Fields tagged with this value in the nib file will be treated as credit |
| 14 // card number fields. | 14 // card number fields. |
| 15 const int kAutoFillCreditCardTag = 22; | 15 const int kAutoFillCreditCardTag = 22; |
| 16 | 16 |
| 17 if ([self tag] == kAutoFillCreditCardTag) { | 17 if ([self tag] == kAutoFillCreditCardTag) { |
| 18 isCreditCardField_ = YES; | 18 isCreditCardField_ = YES; |
| 19 | 19 |
| 20 // KVO bindings initialize fields prior to |awakeFromNib|. In the credit | 20 // KVO bindings initialize fields prior to |awakeFromNib|. In the credit |
| 21 // card field case we need to re-initialize the value to the obfuscated | 21 // card field case we need to re-initialize the value to the obfuscated |
| 22 // version. | 22 // version. |
| 23 [self setObjectValue:[self objectValue]]; | 23 [self setObjectValue:[self objectValue]]; |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 - (void)setObjectValue:(id)object { | 27 - (void)setObjectValue:(id<NSCopying>)anObject { |
| 28 if (isCreditCardField_ && [object isKindOfClass:[NSString class]]) { | 28 // -[NSControl setObjectValue:] says that the passed-in object has type |
| 29 // |id<NSCopying>|, but this function needs to call the NSObject method |
| 30 // -isKindOfClass: on the parameter. In theory, this is not correct, but this |
| 31 // is probably a bug in the method signature. |
| 32 NSObject<NSCopying>* object = static_cast<NSObject<NSCopying>*>(anObject); |
| 33 if (isCreditCardField_ && |
| 34 [object isKindOfClass:[NSString class]]) { |
| 29 // Obfuscate the number. | 35 // Obfuscate the number. |
| 30 NSString* string = object; | 36 NSString* string = static_cast<NSString*>(object); |
| 31 CreditCard card; | 37 CreditCard card; |
| 32 card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), | 38 card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), |
| 33 base::SysNSStringToUTF16(string)); | 39 base::SysNSStringToUTF16(string)); |
| 34 NSString* starredString = base::SysUTF16ToNSString(card.ObfuscatedNumber()); | 40 NSString* starredString = base::SysUTF16ToNSString(card.ObfuscatedNumber()); |
| 35 | 41 |
| 36 [super setObjectValue:starredString]; | 42 [super setObjectValue:starredString]; |
| 37 isObfuscated_ = YES; | 43 isObfuscated_ = YES; |
| 38 obfuscatedValue_.reset([string copy]); | 44 obfuscatedValue_.reset([string copy]); |
| 39 } else { | 45 } else { |
| 40 [super setObjectValue:object]; | 46 [super setObjectValue:object]; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 71 - (BOOL)textShouldBeginEditing:(NSText*)textObject { | 77 - (BOOL)textShouldBeginEditing:(NSText*)textObject { |
| 72 BOOL should = [super textShouldBeginEditing:textObject]; | 78 BOOL should = [super textShouldBeginEditing:textObject]; |
| 73 // On editing, since everything is selected, the field is now clear. | 79 // On editing, since everything is selected, the field is now clear. |
| 74 isObfuscated_ = !should; | 80 isObfuscated_ = !should; |
| 75 if (!isObfuscated_) | 81 if (!isObfuscated_) |
| 76 obfuscatedValue_.reset(); | 82 obfuscatedValue_.reset(); |
| 77 return should; | 83 return should; |
| 78 } | 84 } |
| 79 | 85 |
| 80 @end | 86 @end |
| OLD | NEW |