OLD | NEW |
| (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 #include "chrome/browser/autofill/autofill_field.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/sha1.h" | |
9 #include "base/strings/string_number_conversions.h" | |
10 #include "base/utf_string_conversions.h" | |
11 | |
12 namespace { | |
13 | |
14 static std::string Hash32Bit(const std::string& str) { | |
15 std::string hash_bin = base::SHA1HashString(str); | |
16 DCHECK_EQ(20U, hash_bin.length()); | |
17 | |
18 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | | |
19 ((hash_bin[1] & 0xFF) << 16) | | |
20 ((hash_bin[2] & 0xFF) << 8) | | |
21 (hash_bin[3] & 0xFF); | |
22 | |
23 return base::UintToString(hash32); | |
24 } | |
25 | |
26 } // namespace | |
27 | |
28 AutofillField::AutofillField() | |
29 : server_type_(NO_SERVER_DATA), | |
30 heuristic_type_(UNKNOWN_TYPE), | |
31 phone_part_(IGNORED) { | |
32 } | |
33 | |
34 AutofillField::AutofillField(const FormFieldData& field, | |
35 const string16& unique_name) | |
36 : FormFieldData(field), | |
37 unique_name_(unique_name), | |
38 server_type_(NO_SERVER_DATA), | |
39 heuristic_type_(UNKNOWN_TYPE), | |
40 phone_part_(IGNORED) { | |
41 } | |
42 | |
43 AutofillField::~AutofillField() {} | |
44 | |
45 void AutofillField::set_heuristic_type(AutofillFieldType type) { | |
46 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && | |
47 type != FIELD_WITH_DEFAULT_VALUE) { | |
48 heuristic_type_ = type; | |
49 } else { | |
50 NOTREACHED(); | |
51 // This case should not be reachable; but since this has potential | |
52 // implications on data uploaded to the server, better safe than sorry. | |
53 heuristic_type_ = UNKNOWN_TYPE; | |
54 } | |
55 } | |
56 | |
57 void AutofillField::set_server_type(AutofillFieldType type) { | |
58 // Chrome no longer supports fax numbers, but the server still does. | |
59 if (type >= PHONE_FAX_NUMBER && type <= PHONE_FAX_WHOLE_NUMBER) | |
60 return; | |
61 | |
62 server_type_ = type; | |
63 } | |
64 | |
65 AutofillFieldType AutofillField::type() const { | |
66 if (server_type_ != NO_SERVER_DATA) | |
67 return server_type_; | |
68 | |
69 return heuristic_type_; | |
70 } | |
71 | |
72 bool AutofillField::IsEmpty() const { | |
73 return value.empty(); | |
74 } | |
75 | |
76 std::string AutofillField::FieldSignature() const { | |
77 std::string field_name = UTF16ToUTF8(name); | |
78 std::string field_string = field_name + "&" + form_control_type; | |
79 return Hash32Bit(field_string); | |
80 } | |
81 | |
82 bool AutofillField::IsFieldFillable() const { | |
83 return type() != UNKNOWN_TYPE; | |
84 } | |
OLD | NEW |