| 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 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/autofill/content/renderer/form_autofill_util.h" | 15 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 15 #include "components/autofill/core/common/password_form.h" | 16 #include "components/autofill/core/common/password_form.h" |
| 16 #include "components/autofill/core/common/password_form_field_prediction_map.h" | 17 #include "components/autofill/core/common/password_form_field_prediction_map.h" |
| 17 #include "google_apis/gaia/gaia_urls.h" | 18 #include "google_apis/gaia/gaia_urls.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 20 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
| 21 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 22 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 22 #include "third_party/WebKit/public/web/WebFrame.h" | 23 #include "third_party/WebKit/public/web/WebFrame.h" |
| 23 #include "third_party/WebKit/public/web/WebInputElement.h" | 24 #include "third_party/WebKit/public/web/WebInputElement.h" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 struct PasswordSiteUrlLazyInstanceTraits | 299 struct PasswordSiteUrlLazyInstanceTraits |
| 299 : public base::DefaultLazyInstanceTraits<icu::RegexMatcher> { | 300 : public base::DefaultLazyInstanceTraits<icu::RegexMatcher> { |
| 300 static icu::RegexMatcher* New(void* instance) { | 301 static icu::RegexMatcher* New(void* instance) { |
| 301 return CreateMatcher(instance, kPasswordSiteUrlRegex); | 302 return CreateMatcher(instance, kPasswordSiteUrlRegex); |
| 302 } | 303 } |
| 303 }; | 304 }; |
| 304 | 305 |
| 305 base::LazyInstance<icu::RegexMatcher, PasswordSiteUrlLazyInstanceTraits> | 306 base::LazyInstance<icu::RegexMatcher, PasswordSiteUrlLazyInstanceTraits> |
| 306 password_site_matcher = LAZY_INSTANCE_INITIALIZER; | 307 password_site_matcher = LAZY_INSTANCE_INITIALIZER; |
| 307 | 308 |
| 309 // Returns the |input_field| name if its non-empty; otherwise a |dummy_name|. |
| 310 base::string16 FieldName(const WebInputElement& input_field, |
| 311 const char dummy_name[]) { |
| 312 base::string16 field_name = input_field.nameForAutofill(); |
| 313 return field_name.empty() ? base::ASCIIToUTF16(dummy_name) : field_name; |
| 314 } |
| 315 |
| 308 // Get information about a login form encapsulated in a PasswordForm struct. | 316 // Get information about a login form encapsulated in a PasswordForm struct. |
| 309 // If an element of |form| has an entry in |nonscript_modified_values|, the | 317 // If an element of |form| has an entry in |nonscript_modified_values|, the |
| 310 // associated string is used instead of the element's value to create | 318 // associated string is used instead of the element's value to create |
| 311 // the PasswordForm. | 319 // the PasswordForm. |
| 312 bool GetPasswordForm(const SyntheticForm& form, | 320 bool GetPasswordForm(const SyntheticForm& form, |
| 313 PasswordForm* password_form, | 321 PasswordForm* password_form, |
| 314 const ModifiedValues* nonscript_modified_values, | 322 const ModifiedValues* nonscript_modified_values, |
| 315 const FormsPredictionsMap* form_predictions) { | 323 const FormsPredictionsMap* form_predictions) { |
| 316 WebInputElement latest_input_element; | 324 WebInputElement latest_input_element; |
| 317 WebInputElement username_element; | 325 WebInputElement username_element; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 if (it != other_possible_usernames.end()) | 466 if (it != other_possible_usernames.end()) |
| 459 other_possible_usernames.erase(it); | 467 other_possible_usernames.erase(it); |
| 460 if (!username_element.isNull()) { | 468 if (!username_element.isNull()) { |
| 461 other_possible_usernames.push_back(username_element.value()); | 469 other_possible_usernames.push_back(username_element.value()); |
| 462 } | 470 } |
| 463 username_element = predicted_username_element; | 471 username_element = predicted_username_element; |
| 464 password_form->was_parsed_using_autofill_predictions = true; | 472 password_form->was_parsed_using_autofill_predictions = true; |
| 465 } | 473 } |
| 466 | 474 |
| 467 if (!username_element.isNull()) { | 475 if (!username_element.isNull()) { |
| 468 password_form->username_element = username_element.nameForAutofill(); | 476 password_form->username_element = |
| 477 FieldName(username_element, "anonymous_username"); |
| 469 base::string16 username_value = username_element.value(); | 478 base::string16 username_value = username_element.value(); |
| 470 if (nonscript_modified_values != nullptr) { | 479 if (nonscript_modified_values != nullptr) { |
| 471 auto username_iterator = | 480 auto username_iterator = |
| 472 nonscript_modified_values->find(username_element); | 481 nonscript_modified_values->find(username_element); |
| 473 if (username_iterator != nonscript_modified_values->end()) { | 482 if (username_iterator != nonscript_modified_values->end()) { |
| 474 base::string16 typed_username_value = username_iterator->second; | 483 base::string16 typed_username_value = username_iterator->second; |
| 475 if (!base::StartsWith( | 484 if (!base::StartsWith( |
| 476 base::i18n::ToLower(username_value), | 485 base::i18n::ToLower(username_value), |
| 477 base::i18n::ToLower(typed_username_value), | 486 base::i18n::ToLower(typed_username_value), |
| 478 base::CompareCase::SENSITIVE)) { | 487 base::CompareCase::SENSITIVE)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 492 return false; | 501 return false; |
| 493 | 502 |
| 494 password_form->origin = GetCanonicalOriginForDocument(form.document); | 503 password_form->origin = GetCanonicalOriginForDocument(form.document); |
| 495 GURL::Replacements rep; | 504 GURL::Replacements rep; |
| 496 rep.SetPathStr(""); | 505 rep.SetPathStr(""); |
| 497 password_form->signon_realm = | 506 password_form->signon_realm = |
| 498 password_form->origin.ReplaceComponents(rep).spec(); | 507 password_form->origin.ReplaceComponents(rep).spec(); |
| 499 password_form->other_possible_usernames.swap(other_possible_usernames); | 508 password_form->other_possible_usernames.swap(other_possible_usernames); |
| 500 | 509 |
| 501 if (!password.isNull()) { | 510 if (!password.isNull()) { |
| 502 password_form->password_element = password.nameForAutofill(); | 511 password_form->password_element = FieldName(password, "anonymous_password"); |
| 503 blink::WebString password_value = password.value(); | 512 blink::WebString password_value = password.value(); |
| 504 if (nonscript_modified_values != nullptr) { | 513 if (nonscript_modified_values != nullptr) { |
| 505 auto password_iterator = nonscript_modified_values->find(password); | 514 auto password_iterator = nonscript_modified_values->find(password); |
| 506 if (password_iterator != nonscript_modified_values->end()) | 515 if (password_iterator != nonscript_modified_values->end()) |
| 507 password_value = password_iterator->second; | 516 password_value = password_iterator->second; |
| 508 } | 517 } |
| 509 password_form->password_value = password_value; | 518 password_form->password_value = password_value; |
| 510 } | 519 } |
| 511 if (!new_password.isNull()) { | 520 if (!new_password.isNull()) { |
| 512 password_form->new_password_element = new_password.nameForAutofill(); | 521 password_form->new_password_element = |
| 522 FieldName(new_password, "anonymous_new_password"); |
| 513 password_form->new_password_value = new_password.value(); | 523 password_form->new_password_value = new_password.value(); |
| 514 password_form->new_password_value_is_default = | 524 password_form->new_password_value_is_default = |
| 515 new_password.getAttribute("value") == new_password.value(); | 525 new_password.getAttribute("value") == new_password.value(); |
| 516 if (HasAutocompleteAttributeValue(new_password, kAutocompleteNewPassword)) | 526 if (HasAutocompleteAttributeValue(new_password, kAutocompleteNewPassword)) |
| 517 password_form->new_password_marked_by_site = true; | 527 password_form->new_password_marked_by_site = true; |
| 518 } | 528 } |
| 519 | 529 |
| 520 if (username_element.isNull()) { | 530 if (username_element.isNull()) { |
| 521 // To get a better idea on how password forms without a username field | 531 // To get a better idea on how password forms without a username field |
| 522 // look like, report the total number of text and password fields. | 532 // look like, report the total number of text and password fields. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 nonscript_modified_values, form_predictions)) | 659 nonscript_modified_values, form_predictions)) |
| 650 return scoped_ptr<PasswordForm>(); | 660 return scoped_ptr<PasswordForm>(); |
| 651 | 661 |
| 652 // No actual action on the form, so use the the origin as the action. | 662 // No actual action on the form, so use the the origin as the action. |
| 653 password_form->action = password_form->origin; | 663 password_form->action = password_form->origin; |
| 654 | 664 |
| 655 return password_form.Pass(); | 665 return password_form.Pass(); |
| 656 } | 666 } |
| 657 | 667 |
| 658 } // namespace autofill | 668 } // namespace autofill |
| OLD | NEW |