blob: f59cff9559a36337dcaaf4636c5d8935f04ddd60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// Copyright (c) 2010 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.
#import "chrome/browser/autofill/autofill_credit_card_model_mac.h"
#include "app/l10n_util.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/autofill/credit_card.h"
#include "grit/generated_resources.h"
@implementation AutoFillCreditCardModel
@dynamic summary;
@synthesize label = label_;
@synthesize nameOnCard = nameOnCard_;
@synthesize creditCardNumber = creditCardNumber_;
@synthesize expirationMonth = expirationMonth_;
@synthesize expirationYear = expirationYear_;
@synthesize cvcCode = cvcCode_;
@synthesize billingAddress = billingAddress_;
@synthesize shippingAddress = shippingAddress_;
// Sets up the KVO dependency between "summary" and dependent fields.
+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key {
NSSet* keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
if ([key isEqualToString:@"summary"]) {
NSSet* affectingKeys = [NSSet setWithObjects:@"creditCardNumber",
@"expirationMonth", @"expirationYear", nil];
keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKeys];
}
return keyPaths;
}
- (id)initWithCreditCard:(const CreditCard&)creditCard {
if ((self = [super init])) {
[self setLabel:SysUTF16ToNSString(creditCard.Label())];
[self setNameOnCard:SysUTF16ToNSString(
creditCard.GetFieldText(AutoFillType(CREDIT_CARD_NAME)))];
[self setCreditCardNumber:SysUTF16ToNSString(
creditCard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)))];
[self setExpirationMonth:SysUTF16ToNSString(
creditCard.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH)))];
[self setExpirationYear:SysUTF16ToNSString(
creditCard.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)))];
[self setCvcCode:SysUTF16ToNSString(
creditCard.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE)))];
}
return self;
}
- (void)dealloc {
[label_ release];
[nameOnCard_ release];
[creditCardNumber_ release];
[expirationMonth_ release];
[expirationYear_ release];
[cvcCode_ release];
[billingAddress_ release];
[shippingAddress_ release];
[super dealloc];
}
- (NSString*)summary {
// TODO(dhollowa): This has been pulled into cross platform code.
// Will hook up in separate CL. See http://crbug.com/33029.
return @"";
}
- (void)copyModelToCreditCard:(CreditCard*)creditCard {
DCHECK(creditCard);
creditCard->set_label(base::SysNSStringToUTF16([self label]));
creditCard->SetInfo(AutoFillType(CREDIT_CARD_NAME),
base::SysNSStringToUTF16([self nameOnCard]));
creditCard->SetInfo(AutoFillType(CREDIT_CARD_NUMBER),
base::SysNSStringToUTF16([self creditCardNumber]));
creditCard->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
base::SysNSStringToUTF16([self expirationMonth]));
creditCard->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
base::SysNSStringToUTF16([self expirationYear]));
creditCard->SetInfo(AutoFillType(CREDIT_CARD_VERIFICATION_CODE),
base::SysNSStringToUTF16([self cvcCode]));
}
@end
|