| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/autofill/form_structure.h" | 5 #include "chrome/browser/autofill/form_structure.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/sha1.h" | 12 #include "base/sha1.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/autofill/autofill_metrics.h" | 18 #include "chrome/browser/autofill/autofill_metrics.h" |
| 19 #include "chrome/browser/autofill/autofill_type.h" | 19 #include "chrome/browser/autofill/autofill_type.h" |
| 20 #include "chrome/browser/autofill/autofill_xml_parser.h" | 20 #include "chrome/browser/autofill/autofill_xml_parser.h" |
| 21 #include "chrome/browser/autofill/field_types.h" | 21 #include "chrome/browser/autofill/field_types.h" |
| 22 #include "chrome/browser/autofill/form_field.h" | 22 #include "chrome/browser/autofill/form_field.h" |
| 23 #include "content/public/common/form_data.h" |
| 24 #include "content/public/common/form_data_predictions.h" |
| 25 #include "content/public/common/form_field.h" |
| 26 #include "content/public/common/form_field_predictions.h" |
| 23 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 27 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 24 #include "webkit/forms/form_data.h" | |
| 25 #include "webkit/forms/form_data_predictions.h" | |
| 26 #include "webkit/forms/form_field.h" | |
| 27 #include "webkit/forms/form_field_predictions.h" | |
| 28 | 28 |
| 29 using webkit::forms::FormData; | 29 using content::FormData; |
| 30 using webkit::forms::FormDataPredictions; | 30 using content::FormDataPredictions; |
| 31 using webkit::forms::FormFieldPredictions; | 31 using content::FormFieldPredictions; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const char kFormMethodPost[] = "post"; | 35 const char kFormMethodPost[] = "post"; |
| 36 | 36 |
| 37 // XML elements and attributes. | 37 // XML elements and attributes. |
| 38 const char kAttributeAcceptedFeatures[] = "accepts"; | 38 const char kAttributeAcceptedFeatures[] = "accepts"; |
| 39 const char kAttributeAutofillUsed[] = "autofillused"; | 39 const char kAttributeAutofillUsed[] = "autofillused"; |
| 40 const char kAttributeAutofillType[] = "autofilltype"; | 40 const char kAttributeAutofillType[] = "autofilltype"; |
| 41 const char kAttributeClientVersion[] = "clientversion"; | 41 const char kAttributeClientVersion[] = "clientversion"; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 FormStructure::FormStructure(const FormData& form) | 237 FormStructure::FormStructure(const FormData& form) |
| 238 : form_name_(form.name), | 238 : form_name_(form.name), |
| 239 source_url_(form.origin), | 239 source_url_(form.origin), |
| 240 target_url_(form.action), | 240 target_url_(form.action), |
| 241 autofill_count_(0), | 241 autofill_count_(0), |
| 242 upload_required_(USE_UPLOAD_RATES), | 242 upload_required_(USE_UPLOAD_RATES), |
| 243 server_experiment_id_("no server response"), | 243 server_experiment_id_("no server response"), |
| 244 has_author_specified_types_(false) { | 244 has_author_specified_types_(false) { |
| 245 // Copy the form fields. | 245 // Copy the form fields. |
| 246 std::map<string16, size_t> unique_names; | 246 std::map<string16, size_t> unique_names; |
| 247 for (std::vector<webkit::forms::FormField>::const_iterator field = | 247 for (std::vector<content::FormField>::const_iterator field = |
| 248 form.fields.begin(); | 248 form.fields.begin(); |
| 249 field != form.fields.end(); field++) { | 249 field != form.fields.end(); field++) { |
| 250 // Add all supported form fields (including with empty names) to the | 250 // Add all supported form fields (including with empty names) to the |
| 251 // signature. This is a requirement for Autofill servers. | 251 // signature. This is a requirement for Autofill servers. |
| 252 form_signature_field_names_.append("&"); | 252 form_signature_field_names_.append("&"); |
| 253 form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 253 form_signature_field_names_.append(UTF16ToUTF8(field->name)); |
| 254 | 254 |
| 255 // Generate a unique name for this field by appending a counter to the name. | 255 // Generate a unique name for this field by appending a counter to the name. |
| 256 // Make sure to prepend the counter with a non-numeric digit so that we are | 256 // Make sure to prepend the counter with a non-numeric digit so that we are |
| 257 // guaranteed to avoid collisions. | 257 // guaranteed to avoid collisions. |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 form.data.method = | 480 form.data.method = |
| 481 ASCIIToUTF16((form_structure->method_ == POST) ? "POST" : "GET"); | 481 ASCIIToUTF16((form_structure->method_ == POST) ? "POST" : "GET"); |
| 482 form.data.origin = form_structure->source_url_; | 482 form.data.origin = form_structure->source_url_; |
| 483 form.data.action = form_structure->target_url_; | 483 form.data.action = form_structure->target_url_; |
| 484 form.signature = form_structure->FormSignature(); | 484 form.signature = form_structure->FormSignature(); |
| 485 form.experiment_id = form_structure->server_experiment_id_; | 485 form.experiment_id = form_structure->server_experiment_id_; |
| 486 | 486 |
| 487 for (std::vector<AutofillField*>::const_iterator field = | 487 for (std::vector<AutofillField*>::const_iterator field = |
| 488 form_structure->fields_.begin(); | 488 form_structure->fields_.begin(); |
| 489 field != form_structure->fields_.end(); ++field) { | 489 field != form_structure->fields_.end(); ++field) { |
| 490 form.data.fields.push_back(webkit::forms::FormField(**field)); | 490 form.data.fields.push_back(content::FormField(**field)); |
| 491 | 491 |
| 492 FormFieldPredictions annotated_field; | 492 FormFieldPredictions annotated_field; |
| 493 annotated_field.signature = (*field)->FieldSignature(); | 493 annotated_field.signature = (*field)->FieldSignature(); |
| 494 annotated_field.heuristic_type = | 494 annotated_field.heuristic_type = |
| 495 AutofillType::FieldTypeToString((*field)->heuristic_type()); | 495 AutofillType::FieldTypeToString((*field)->heuristic_type()); |
| 496 annotated_field.server_type = | 496 annotated_field.server_type = |
| 497 AutofillType::FieldTypeToString((*field)->server_type()); | 497 AutofillType::FieldTypeToString((*field)->server_type()); |
| 498 annotated_field.overall_type = | 498 annotated_field.overall_type = |
| 499 AutofillType::FieldTypeToString((*field)->type()); | 499 AutofillType::FieldTypeToString((*field)->type()); |
| 500 form.fields.push_back(annotated_field); | 500 form.fields.push_back(annotated_field); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 966 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
| 967 field != fields_.end(); ++field) { | 967 field != fields_.end(); ++field) { |
| 968 AutofillType::FieldTypeGroup field_type_group = | 968 AutofillType::FieldTypeGroup field_type_group = |
| 969 AutofillType((*field)->type()).group(); | 969 AutofillType((*field)->type()).group(); |
| 970 if (field_type_group == AutofillType::CREDIT_CARD) | 970 if (field_type_group == AutofillType::CREDIT_CARD) |
| 971 (*field)->set_section((*field)->section() + ASCIIToUTF16("-cc")); | 971 (*field)->set_section((*field)->section() + ASCIIToUTF16("-cc")); |
| 972 else | 972 else |
| 973 (*field)->set_section((*field)->section() + ASCIIToUTF16("-default")); | 973 (*field)->set_section((*field)->section() + ASCIIToUTF16("-default")); |
| 974 } | 974 } |
| 975 } | 975 } |
| OLD | NEW |