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

Side by Side Diff: chrome/browser/autofill/autofill_text_field_mac.mm

Issue 6621076: [Mac] Remove native/Cocoa preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase switch removal Created 9 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/autofill/autofill_text_field_mac.h"
6
7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/autofill/credit_card.h"
9
10 @implementation AutoFillTextField
11
12 - (void)awakeFromNib {
13 // Fields tagged with this value in the nib file will be treated as credit
14 // card number fields.
15 const int kAutoFillCreditCardTag = 22;
16
17 if ([self tag] == kAutoFillCreditCardTag) {
18 isCreditCardField_ = YES;
19
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
22 // version.
23 [self setObjectValue:[self objectValue]];
24 }
25 }
26
27 - (void)setObjectValue:(id<NSCopying>)anObject {
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]]) {
35 // Obfuscate the number.
36 NSString* string = static_cast<NSString*>(object);
37 CreditCard card;
38 card.SetInfo(AutofillType(CREDIT_CARD_NUMBER),
39 base::SysNSStringToUTF16(string));
40 NSString* starredString = base::SysUTF16ToNSString(card.ObfuscatedNumber());
41
42 [super setObjectValue:starredString];
43 isObfuscated_ = YES;
44 obfuscatedValue_.reset([string copy]);
45 } else {
46 [super setObjectValue:object];
47 }
48 }
49
50 - (id)objectValue {
51 if (isObfuscated_) {
52 // This should not happen. This field is bound, and its value will only be
53 // fetched if it is changed, and since we force selection, that should clear
54 // the obfuscation. Nevertheless, we'll be paranoid here since we don't want
55 // the obfuscating ***s to end up in the database.
56 NOTREACHED();
57 return obfuscatedValue_.get();
58 } else {
59 return [super objectValue];
60 }
61 }
62
63 // |self| is automatically set to be the delegate of the field editor; this
64 // method is called by the field editor.
65 - (void)textViewDidChangeSelection:(NSNotification *)notification {
66 if (isCreditCardField_ && !isBeingSelected_ && isObfuscated_) {
67 // Can't edit obfuscated credit card info; force a select-all in that case.
68 isBeingSelected_ = YES;
69 NSText* editor = [notification object];
70 [editor selectAll:self];
71 isBeingSelected_ = NO;
72 }
73 }
74
75 // Docs aren't clear, but this is called on the first keypress, not when the
76 // field takes focus.
77 - (BOOL)textShouldBeginEditing:(NSText*)textObject {
78 BOOL should = [super textShouldBeginEditing:textObject];
79 // On editing, since everything is selected, the field is now clear.
80 isObfuscated_ = !should;
81 if (!isObfuscated_)
82 obfuscatedValue_.reset();
83 return should;
84 }
85
86 @end
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_text_field_mac.h ('k') | chrome/browser/ui/cocoa/browser_window_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698