| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_STRUCTURE_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_STRUCTURE_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_STRUCTURE_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_STRUCTURE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 rappor::RapporService* rappor_service); | 84 rappor::RapporService* rappor_service); |
| 85 | 85 |
| 86 // Returns predictions using the details from the given |form_structures| and | 86 // Returns predictions using the details from the given |form_structures| and |
| 87 // their fields' predicted types. | 87 // their fields' predicted types. |
| 88 static std::vector<FormDataPredictions> GetFieldTypePredictions( | 88 static std::vector<FormDataPredictions> GetFieldTypePredictions( |
| 89 const std::vector<FormStructure*>& form_structures); | 89 const std::vector<FormStructure*>& form_structures); |
| 90 | 90 |
| 91 // Returns whether sending autofill field metadata to the server is enabled. | 91 // Returns whether sending autofill field metadata to the server is enabled. |
| 92 static bool IsAutofillFieldMetadataEnabled(); | 92 static bool IsAutofillFieldMetadataEnabled(); |
| 93 | 93 |
| 94 // The unique signature for this form, composed of the target url domain, | 94 // Return the form signature as string. |
| 95 // the form name, and the form field names in a 64-bit hash. | 95 std::string FormSignatureAsStr() const; |
| 96 std::string FormSignature() const; | |
| 97 | 96 |
| 98 // Runs a quick heuristic to rule out forms that are obviously not | 97 // Runs a quick heuristic to rule out forms that are obviously not |
| 99 // auto-fillable, like google/yahoo/msn search, etc. | 98 // auto-fillable, like google/yahoo/msn search, etc. |
| 100 bool IsAutofillable() const; | 99 bool IsAutofillable() const; |
| 101 | 100 |
| 102 // Returns whether |this| form represents a complete Credit Card form, which | 101 // Returns whether |this| form represents a complete Credit Card form, which |
| 103 // consists in having at least a credit card number field and an expiration | 102 // consists in having at least a credit card number field and an expiration |
| 104 // field. | 103 // field. |
| 105 bool IsCompleteCreditCardForm() const; | 104 bool IsCompleteCreditCardForm() const; |
| 106 | 105 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return has_author_specified_sections_; | 213 return has_author_specified_sections_; |
| 215 } | 214 } |
| 216 | 215 |
| 217 void set_upload_required(UploadRequired required) { | 216 void set_upload_required(UploadRequired required) { |
| 218 upload_required_ = required; | 217 upload_required_ = required; |
| 219 } | 218 } |
| 220 UploadRequired upload_required() const { return upload_required_; } | 219 UploadRequired upload_required() const { return upload_required_; } |
| 221 | 220 |
| 222 bool all_fields_are_passwords() const { return all_fields_are_passwords_; } | 221 bool all_fields_are_passwords() const { return all_fields_are_passwords_; } |
| 223 | 222 |
| 223 // The unique signature for this form, composed of the target url domain, |
| 224 // the form name, and the form field names in a 64-bit hash. |
| 225 FormSignature form_signature() const { return form_signature_; } |
| 226 |
| 224 // Returns a FormData containing the data this form structure knows about. | 227 // Returns a FormData containing the data this form structure knows about. |
| 225 FormData ToFormData() const; | 228 FormData ToFormData() const; |
| 226 | 229 |
| 227 bool operator==(const FormData& form) const; | 230 bool operator==(const FormData& form) const; |
| 228 bool operator!=(const FormData& form) const; | 231 bool operator!=(const FormData& form) const; |
| 229 | 232 |
| 230 private: | 233 private: |
| 231 friend class AutofillMergeTest; | 234 friend class AutofillMergeTest; |
| 232 friend class FormStructureTest; | 235 friend class FormStructureTest; |
| 233 FRIEND_TEST_ALL_PREFIXES(AutofillDownloadTest, QueryAndUploadTest); | 236 FRIEND_TEST_ALL_PREFIXES(AutofillDownloadTest, QueryAndUploadTest); |
| 234 FRIEND_TEST_ALL_PREFIXES(FormStructureTest, FindLongestCommonPrefix); | 237 FRIEND_TEST_ALL_PREFIXES(FormStructureTest, FindLongestCommonPrefix); |
| 235 | 238 |
| 236 // Encodes information about this form and its fields into |query_form|. | 239 // Encodes information about this form and its fields into |query_form|. |
| 237 void EncodeFormForQuery( | 240 void EncodeFormForQuery( |
| 238 autofill::AutofillQueryContents::Form* query_form) const; | 241 autofill::AutofillQueryContents::Form* query_form) const; |
| 239 | 242 |
| 240 // Encodes information about this form and its fields into |upload|. | 243 // Encodes information about this form and its fields into |upload|. |
| 241 void EncodeFormForUpload(autofill::AutofillUploadContents* upload) const; | 244 void EncodeFormForUpload(autofill::AutofillUploadContents* upload) const; |
| 242 | 245 |
| 243 // 64-bit hash of the string - used in FormSignature and unit-tests. | |
| 244 static uint64_t Hash64Bit(const std::string& str); | |
| 245 | |
| 246 uint64_t FormSignature64Bit() const; | |
| 247 | |
| 248 // Returns true if the form has no fields, or too many. | 246 // Returns true if the form has no fields, or too many. |
| 249 bool IsMalformed() const; | 247 bool IsMalformed() const; |
| 250 | 248 |
| 251 // Classifies each field in |fields_| into a logical section. | 249 // Classifies each field in |fields_| into a logical section. |
| 252 // Sections are identified by the heuristic that a logical section should not | 250 // Sections are identified by the heuristic that a logical section should not |
| 253 // include multiple fields of the same autofill type (with some exceptions, as | 251 // include multiple fields of the same autofill type (with some exceptions, as |
| 254 // described in the implementation). Sections are furthermore distinguished | 252 // described in the implementation). Sections are furthermore distinguished |
| 255 // as either credit card or non-credit card sections. | 253 // as either credit card or non-credit card sections. |
| 256 // If |has_author_specified_sections| is true, only the second pass -- | 254 // If |has_author_specified_sections| is true, only the second pass -- |
| 257 // distinguishing credit card sections from non-credit card ones -- is made. | 255 // distinguishing credit card sections from non-credit card ones -- is made. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 283 // The number of fields able to be auto-filled. | 281 // The number of fields able to be auto-filled. |
| 284 size_t autofill_count_; | 282 size_t autofill_count_; |
| 285 | 283 |
| 286 // A vector of all the input fields in the form. | 284 // A vector of all the input fields in the form. |
| 287 ScopedVector<AutofillField> fields_; | 285 ScopedVector<AutofillField> fields_; |
| 288 | 286 |
| 289 // The number of fields that are part of the form signature and that are | 287 // The number of fields that are part of the form signature and that are |
| 290 // included in queries to the Autofill server. | 288 // included in queries to the Autofill server. |
| 291 size_t active_field_count_; | 289 size_t active_field_count_; |
| 292 | 290 |
| 293 // The names of the form input elements, that are part of the form signature. | |
| 294 // The string starts with "&" and the names are also separated by the "&" | |
| 295 // character. E.g.: "&form_input1_name&form_input2_name&...&form_inputN_name" | |
| 296 std::string form_signature_field_names_; | |
| 297 | |
| 298 // Whether the server expects us to always upload, never upload, or default | 291 // Whether the server expects us to always upload, never upload, or default |
| 299 // to the stored upload rates. | 292 // to the stored upload rates. |
| 300 UploadRequired upload_required_; | 293 UploadRequired upload_required_; |
| 301 | 294 |
| 302 // Whether the form includes any field types explicitly specified by the site | 295 // Whether the form includes any field types explicitly specified by the site |
| 303 // author, via the |autocompletetype| attribute. | 296 // author, via the |autocompletetype| attribute. |
| 304 bool has_author_specified_types_; | 297 bool has_author_specified_types_; |
| 305 | 298 |
| 306 // Whether the form includes any sections explicitly specified by the site | 299 // Whether the form includes any sections explicitly specified by the site |
| 307 // author, via the autocomplete attribute. | 300 // author, via the autocomplete attribute. |
| 308 bool has_author_specified_sections_; | 301 bool has_author_specified_sections_; |
| 309 | 302 |
| 310 // Whether the form was parsed for autocomplete attribute, thus assigning | 303 // Whether the form was parsed for autocomplete attribute, thus assigning |
| 311 // the real values of |has_author_specified_types_| and | 304 // the real values of |has_author_specified_types_| and |
| 312 // |has_author_specified_sections_|. | 305 // |has_author_specified_sections_|. |
| 313 bool was_parsed_for_autocomplete_attributes_; | 306 bool was_parsed_for_autocomplete_attributes_; |
| 314 | 307 |
| 315 // True if the form contains at least one password field. | 308 // True if the form contains at least one password field. |
| 316 bool has_password_field_; | 309 bool has_password_field_; |
| 317 | 310 |
| 318 // True if the form is a <form>. | 311 // True if the form is a <form>. |
| 319 bool is_form_tag_; | 312 bool is_form_tag_; |
| 320 | 313 |
| 321 // True if the form is made of unowned fields in a non checkout flow. | 314 // True if the form is made of unowned fields in a non checkout flow. |
| 322 bool is_formless_checkout_; | 315 bool is_formless_checkout_; |
| 323 | 316 |
| 324 // True if all form fields are password fields. | 317 // True if all form fields are password fields. |
| 325 bool all_fields_are_passwords_; | 318 bool all_fields_are_passwords_; |
| 326 | 319 |
| 320 FormSignature form_signature_; |
| 321 |
| 327 DISALLOW_COPY_AND_ASSIGN(FormStructure); | 322 DISALLOW_COPY_AND_ASSIGN(FormStructure); |
| 328 }; | 323 }; |
| 329 | 324 |
| 330 } // namespace autofill | 325 } // namespace autofill |
| 331 | 326 |
| 332 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_STRUCTURE_H_ | 327 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_STRUCTURE_H_ |
| OLD | NEW |