| 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/command_line.h" | 10 #include "base/command_line.h" | 
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 222 | 222 | 
| 223 }  // namespace | 223 }  // namespace | 
| 224 | 224 | 
| 225 FormStructure::FormStructure(const FormData& form) | 225 FormStructure::FormStructure(const FormData& form) | 
| 226     : form_name_(form.name), | 226     : form_name_(form.name), | 
| 227       source_url_(form.origin), | 227       source_url_(form.origin), | 
| 228       target_url_(form.action), | 228       target_url_(form.action), | 
| 229       autofill_count_(0), | 229       autofill_count_(0), | 
| 230       upload_required_(USE_UPLOAD_RATES), | 230       upload_required_(USE_UPLOAD_RATES), | 
| 231       server_experiment_id_("no server response"), | 231       server_experiment_id_("no server response"), | 
|  | 232       page_number_(-1), | 
|  | 233       total_pages_(-1), | 
| 232       has_author_specified_types_(false) { | 234       has_author_specified_types_(false) { | 
| 233   // Copy the form fields. | 235   // Copy the form fields. | 
| 234   std::map<string16, size_t> unique_names; | 236   std::map<string16, size_t> unique_names; | 
| 235   for (std::vector<FormFieldData>::const_iterator field = | 237   for (std::vector<FormFieldData>::const_iterator field = | 
| 236            form.fields.begin(); | 238            form.fields.begin(); | 
| 237        field != form.fields.end(); field++) { | 239        field != form.fields.end(); field++) { | 
| 238     // Add all supported form fields (including with empty names) to the | 240     // Add all supported form fields (including with empty names) to the | 
| 239     // signature.  This is a requirement for Autofill servers. | 241     // signature.  This is a requirement for Autofill servers. | 
| 240     form_signature_field_names_.append("&"); | 242     form_signature_field_names_.append("&"); | 
| 241     form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 243     form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 257     method_ = POST; | 259     method_ = POST; | 
| 258   } else { | 260   } else { | 
| 259     // Either the method is 'get', or we don't know.  In this case we default | 261     // Either the method is 'get', or we don't know.  In this case we default | 
| 260     // to GET. | 262     // to GET. | 
| 261     method_ = GET; | 263     method_ = GET; | 
| 262   } | 264   } | 
| 263 } | 265 } | 
| 264 | 266 | 
| 265 FormStructure::~FormStructure() {} | 267 FormStructure::~FormStructure() {} | 
| 266 | 268 | 
|  | 269 bool FormStructure::IsStartOfAutofillableFlow() const { | 
|  | 270   return page_number_ == 0; | 
|  | 271 } | 
|  | 272 | 
|  | 273 bool FormStructure::IsInAutofillableFlow() const { | 
|  | 274   return page_number_ >=0 && page_number_ < total_pages_; | 
|  | 275 } | 
|  | 276 | 
| 267 void FormStructure::DetermineHeuristicTypes( | 277 void FormStructure::DetermineHeuristicTypes( | 
| 268     const AutofillMetrics& metric_logger) { | 278     const AutofillMetrics& metric_logger) { | 
| 269   // First, try to detect field types based on each field's |autocomplete| | 279   // First, try to detect field types based on each field's |autocomplete| | 
| 270   // attribute value.  If there is at least one form field that specifies an | 280   // attribute value.  If there is at least one form field that specifies an | 
| 271   // autocomplete type hint, don't try to apply other heuristics to match fields | 281   // autocomplete type hint, don't try to apply other heuristics to match fields | 
| 272   // in this form. | 282   // in this form. | 
| 273   bool has_author_specified_sections; | 283   bool has_author_specified_sections; | 
| 274   ParseFieldTypesFromAutocompleteAttributes(&has_author_specified_types_, | 284   ParseFieldTypesFromAutocompleteAttributes(&has_author_specified_types_, | 
| 275                                             &has_author_specified_sections); | 285                                             &has_author_specified_sections); | 
| 276 | 286 | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 422   bool heuristics_detected_fillable_field = false; | 432   bool heuristics_detected_fillable_field = false; | 
| 423   bool query_response_overrode_heuristics = false; | 433   bool query_response_overrode_heuristics = false; | 
| 424 | 434 | 
| 425   // Copy the field types into the actual form. | 435   // Copy the field types into the actual form. | 
| 426   std::vector<AutofillFieldType>::iterator current_type = field_types.begin(); | 436   std::vector<AutofillFieldType>::iterator current_type = field_types.begin(); | 
| 427   for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); | 437   for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); | 
| 428        iter != forms.end(); ++iter) { | 438        iter != forms.end(); ++iter) { | 
| 429     FormStructure* form = *iter; | 439     FormStructure* form = *iter; | 
| 430     form->upload_required_ = upload_required; | 440     form->upload_required_ = upload_required; | 
| 431     form->server_experiment_id_ = experiment_id; | 441     form->server_experiment_id_ = experiment_id; | 
|  | 442     form->page_number_ = parse_handler.page_number(); | 
|  | 443     form->total_pages_ = parse_handler.total_pages(); | 
| 432 | 444 | 
| 433     for (std::vector<AutofillField*>::iterator field = form->fields_.begin(); | 445     for (std::vector<AutofillField*>::iterator field = form->fields_.begin(); | 
| 434          field != form->fields_.end(); ++field, ++current_type) { | 446          field != form->fields_.end(); ++field, ++current_type) { | 
| 435       // In some cases *successful* response does not return all the fields. | 447       // In some cases *successful* response does not return all the fields. | 
| 436       // Quit the update of the types then. | 448       // Quit the update of the types then. | 
| 437       if (current_type == field_types.end()) | 449       if (current_type == field_types.end()) | 
| 438         break; | 450         break; | 
| 439 | 451 | 
| 440       // UNKNOWN_TYPE is reserved for use by the client. | 452       // UNKNOWN_TYPE is reserved for use by the client. | 
| 441       DCHECK_NE(*current_type, UNKNOWN_TYPE); | 453       DCHECK_NE(*current_type, UNKNOWN_TYPE); | 
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1071   for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1083   for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 
| 1072        field != fields_.end(); ++field) { | 1084        field != fields_.end(); ++field) { | 
| 1073     AutofillType::FieldTypeGroup field_type_group = | 1085     AutofillType::FieldTypeGroup field_type_group = | 
| 1074         AutofillType((*field)->type()).group(); | 1086         AutofillType((*field)->type()).group(); | 
| 1075     if (field_type_group == AutofillType::CREDIT_CARD) | 1087     if (field_type_group == AutofillType::CREDIT_CARD) | 
| 1076       (*field)->set_section((*field)->section() + "-cc"); | 1088       (*field)->set_section((*field)->section() + "-cc"); | 
| 1077     else | 1089     else | 
| 1078       (*field)->set_section((*field)->section() + "-default"); | 1090       (*field)->set_section((*field)->section() + "-default"); | 
| 1079   } | 1091   } | 
| 1080 } | 1092 } | 
| OLD | NEW | 
|---|