summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-21 00:22:01 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-21 00:22:01 +0000
commitdb262992779c3b3eb3afeba6380776e39c7d4aa0 (patch)
treeea59e75dee552525512a52d240b1539690f99619 /chrome
parentc554cc7d4cb6c2f150ef042d3fae22c4d54da741 (diff)
downloadchromium_src-db262992779c3b3eb3afeba6380776e39c7d4aa0.zip
chromium_src-db262992779c3b3eb3afeba6380776e39c7d4aa0.tar.gz
chromium_src-db262992779c3b3eb3afeba6380776e39c7d4aa0.tar.bz2
Implement AutoFillType, the high-level description of AutoFill types.
BUG=none TEST=none Review URL: http://codereview.chromium.org/418026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill/autofill_type.cc105
-rw-r--r--chrome/browser/autofill/autofill_type.h82
-rwxr-xr-xchrome/chrome.gyp2
3 files changed, 189 insertions, 0 deletions
diff --git a/chrome/browser/autofill/autofill_type.cc b/chrome/browser/autofill/autofill_type.cc
new file mode 100644
index 0000000..f97ab42
--- /dev/null
+++ b/chrome/browser/autofill/autofill_type.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2009 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.
+
+#include "chrome/browser/autofill/autofill_type.h"
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+
+// TODO(jhawkins) all of the Human Readable names will need to be added to a
+// resource file and localized because they are used in the confirmation
+// dialog.
+AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = {
+ { NO_SERVER_DATA, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "No Server Data" },
+ { UNKNOWN_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "Unknown Type" },
+ { EMPTY_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "Empty Type" },
+
+ { NAME_FIRST, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "First Name" },
+ { NAME_MIDDLE, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Middle Name" },
+ { NAME_LAST, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Last Name" },
+ { NAME_MIDDLE_INITIAL, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Middle Initial" },
+ { NAME_FULL, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Full Name" },
+ { NAME_SUFFIX, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Name Suffix" },
+
+ { EMAIL_ADDRESS, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Email Address" },
+ { COMPANY_NAME, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Company Name" },
+
+ { PHONE_HOME_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_NUMBER, "Home Phone Number" },
+ { PHONE_HOME_CITY_CODE, AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_CODE, "Home Area Code" },
+ { PHONE_HOME_COUNTRY_CODE, AutoFillType::PHONE_HOME, AutoFillType::PHONE_COUNTRY_CODE, "Home Country Code" },
+ { PHONE_HOME_CITY_AND_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_AND_NUMBER, "Home Phone Number" },
+ { PHONE_HOME_WHOLE_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_WHOLE_NUMBER, "Home Phone Number" },
+
+ { PHONE_FAX_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_NUMBER, "Fax Number" },
+ { PHONE_FAX_CITY_CODE, AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_CODE, "Fax Area Code" },
+ { PHONE_FAX_COUNTRY_CODE, AutoFillType::PHONE_FAX, AutoFillType::PHONE_COUNTRY_CODE, "Fax Country Code" },
+ { PHONE_FAX_CITY_AND_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_AND_NUMBER, "Fax Number" },
+ { PHONE_FAX_WHOLE_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_WHOLE_NUMBER, "Fax Number" },
+
+ { ADDRESS_HOME_LINE1, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE1, "Home Address Line 1" },
+ { ADDRESS_HOME_LINE2, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE2, "Home Address Line 2" },
+ { ADDRESS_HOME_APPT_NUM, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APPT_NUM, "Home Address Apartment Number" },
+ { ADDRESS_HOME_CITY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_CITY, "Home Address City" },
+ { ADDRESS_HOME_STATE, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_STATE, "Home Address State" },
+ { ADDRESS_HOME_ZIP, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_ZIP, "Home Address Zip Code" },
+ { ADDRESS_HOME_COUNTRY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_COUNTRY, "Home Address Country" },
+
+ { ADDRESS_BILLING_LINE1, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE1, "Billing Address Line 1" },
+ { ADDRESS_BILLING_LINE2, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE2, "Billing Address Line 2" },
+ { ADDRESS_BILLING_APPT_NUM, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_APPT_NUM, "Billing Address Apartment Number" },
+ { ADDRESS_BILLING_CITY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_CITY, "Billing Address City" },
+ { ADDRESS_BILLING_STATE, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_STATE, "Billing Address State" },
+ { ADDRESS_BILLING_ZIP, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_ZIP, "Billing Address Zip Code" },
+ { ADDRESS_BILLING_COUNTRY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_COUNTRY, "Billing Address Country" },
+
+ { CREDIT_CARD_NAME, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Name on Credit Card" },
+ { CREDIT_CARD_NUMBER, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Number" },
+ { CREDIT_CARD_EXP_MONTH, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Month" },
+ { CREDIT_CARD_EXP_2_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Year" },
+ { CREDIT_CARD_EXP_4_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Year" },
+ { CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Date" },
+ { CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Date" },
+ { CREDIT_CARD_TYPE, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Type" },
+ { CREDIT_CARD_VERIFICATION_CODE, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Verification Number" },
+
+ { MAX_VALID_FIELD_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "" },
+};
+
+bool AutoFillType::initialized_ = false;
+AutoFillType AutoFillType::types_[MAX_VALID_FIELD_TYPE + 1];
+
+AutoFillType::AutoFillType(AutoFillTypeDefinition* definition)
+ : autofill_type_definition_(definition) {
+ DCHECK(definition != NULL);
+}
+
+AutoFillType::AutoFillType(AutoFillFieldType field_type) {
+ StaticInitialize();
+ DCHECK(initialized_);
+
+ if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE ||
+ types_[field_type].autofill_type_definition_ == NULL) {
+ field_type = UNKNOWN_TYPE;
+ }
+
+ autofill_type_definition_ = types_[field_type].autofill_type_definition_;
+}
+
+// TODO(jhawkins): refactor this class to not require static initialization.
+void AutoFillType::StaticInitialize() {
+ // Can be called more than once (in unit tests for example).
+ if (initialized_)
+ return;
+
+ initialized_ = true;
+
+ InitializeFieldTypeMap();
+}
+
+void AutoFillType::InitializeFieldTypeMap() {
+ for (size_t i = 0; i < arraysize(kAutoFillTypeDefinitions); ++i) {
+ AutoFillType type(&kAutoFillTypeDefinitions[i]);
+ types_[type.field_type()] = type;
+ }
+}
diff --git a/chrome/browser/autofill/autofill_type.h b/chrome/browser/autofill/autofill_type.h
new file mode 100644
index 0000000..700f5ef
--- /dev/null
+++ b/chrome/browser/autofill/autofill_type.h
@@ -0,0 +1,82 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_TYPE_H_
+#define CHROME_BROWSER_AUTOFILL_AUTOFILL_TYPE_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/string16.h"
+#include "chrome/browser/autofill/field_types.h"
+
+// The high-level description of AutoFill types, used to categorize form fields
+// and for associating form fields with form values in the Web Database.
+class AutoFillType {
+ public:
+ enum FieldTypeGroup {
+ NO_GROUP,
+ CONTACT_INFO,
+ ADDRESS_HOME,
+ ADDRESS_BILLING,
+ PHONE_HOME,
+ PHONE_FAX,
+ CREDIT_CARD,
+ };
+
+ enum FieldTypeSubGroup {
+ NO_SUBGROUP,
+ // Address subgroups.
+ ADDRESS_LINE1,
+ ADDRESS_LINE2,
+ ADDRESS_APPT_NUM,
+ ADDRESS_CITY,
+ ADDRESS_STATE,
+ ADDRESS_ZIP,
+ ADDRESS_COUNTRY,
+
+ // Phone subgroups.
+ PHONE_NUMBER,
+ PHONE_CITY_CODE,
+ PHONE_COUNTRY_CODE,
+ PHONE_CITY_AND_NUMBER,
+ PHONE_WHOLE_NUMBER
+ };
+
+ struct AutoFillTypeDefinition {
+ AutoFillFieldType field_type;
+ FieldTypeGroup group;
+ FieldTypeSubGroup subgroup;
+ std::string name;
+ };
+
+ AutoFillType() {}
+ explicit AutoFillType(AutoFillTypeDefinition* definition);
+ explicit AutoFillType(AutoFillFieldType field_type);
+
+ AutoFillFieldType field_type() const {
+ return autofill_type_definition_->field_type;
+ }
+ FieldTypeGroup group() const { return autofill_type_definition_->group; }
+ FieldTypeSubGroup subgroup() const {
+ return autofill_type_definition_->subgroup;
+ }
+
+ private:
+ static void StaticInitialize();
+ static void InitializeFieldTypeMap();
+
+ static bool initialized_;
+ static AutoFillType types_[MAX_VALID_FIELD_TYPE + 1];
+
+ const AutoFillTypeDefinition* autofill_type_definition_;
+};
+
+typedef AutoFillType::FieldTypeGroup FieldTypeGroup;
+typedef AutoFillType::FieldTypeSubGroup FieldTypeSubGroup;
+typedef std::set<AutoFillFieldType> FieldTypeSet;
+typedef std::map<string16, AutoFillFieldType> FieldTypeMap;
+
+#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_TYPE_H_
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 8bdaf19..d151cba 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -855,6 +855,8 @@
'browser/autofill/autofill_infobar_delegate.h',
'browser/autofill/autofill_manager.cc',
'browser/autofill/autofill_manager.h',
+ 'browser/autofill/autofill_type.cc',
+ 'browser/autofill/autofill_type.h',
'browser/autofill/field_types.h',
'browser/autofill/form_structure.cc',
'browser/autofill/form_structure.h',