Chromium Code Reviews| 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 <ostream> | 5 #include <ostream> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 | 7 |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "components/autofill/core/common/password_form.h" | 13 #include "components/autofill/core/common/password_form.h" |
| 14 | 14 |
| 15 namespace autofill { | 15 namespace autofill { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Serializes a PasswordForm to a JSON object. Used only for logging in tests. | 19 // Serializes a PasswordForm to a JSON object. Used only for logging in tests. |
| 20 void PasswordFormToJSON(const PasswordForm& form, | 20 void PasswordFormToJSON(const PasswordForm& form, |
| 21 base::DictionaryValue* target) { | 21 base::DictionaryValue* target) { |
| 22 target->SetInteger("scheme", form.scheme); | 22 target->SetInteger("scheme", form.scheme); |
| 23 target->SetString("signon_realm", form.signon_realm); | 23 target->SetString("signon_realm", form.signon_realm); |
| 24 target->SetString("signon_realm", form.signon_realm); | 24 target->SetBoolean("is_public_suffix_match", form.is_public_suffix_match); |
|
engedy
2015/09/29 19:11:04
nit: Don't forget about |is_affiliated| either.
dvadym
2015/10/12 09:30:44
Done, in the following CL.
| |
| 25 target->SetString("original_signon_realm", form.original_signon_realm); | |
| 26 target->SetString("origin", form.origin.possibly_invalid_spec()); | 25 target->SetString("origin", form.origin.possibly_invalid_spec()); |
| 27 target->SetString("action", form.action.possibly_invalid_spec()); | 26 target->SetString("action", form.action.possibly_invalid_spec()); |
| 28 target->SetString("submit_element", form.submit_element); | 27 target->SetString("submit_element", form.submit_element); |
| 29 target->SetString("username_elem", form.username_element); | 28 target->SetString("username_elem", form.username_element); |
| 30 target->SetBoolean("username_marked_by_site", form.username_marked_by_site); | 29 target->SetBoolean("username_marked_by_site", form.username_marked_by_site); |
| 31 target->SetString("username_value", form.username_value); | 30 target->SetString("username_value", form.username_value); |
| 32 target->SetString("password_elem", form.password_element); | 31 target->SetString("password_elem", form.password_element); |
| 33 target->SetString("password_value", form.password_value); | 32 target->SetString("password_value", form.password_value); |
| 34 target->SetBoolean("password_value_is_default", | 33 target->SetBoolean("password_value_is_default", |
| 35 form.password_value_is_default); | 34 form.password_value_is_default); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 new_password_marked_by_site(false), | 74 new_password_marked_by_site(false), |
| 76 ssl_valid(false), | 75 ssl_valid(false), |
| 77 preferred(false), | 76 preferred(false), |
| 78 blacklisted_by_user(false), | 77 blacklisted_by_user(false), |
| 79 type(TYPE_MANUAL), | 78 type(TYPE_MANUAL), |
| 80 times_used(0), | 79 times_used(0), |
| 81 generation_upload_status(NO_SIGNAL_SENT), | 80 generation_upload_status(NO_SIGNAL_SENT), |
| 82 skip_zero_click(false), | 81 skip_zero_click(false), |
| 83 layout(Layout::LAYOUT_OTHER), | 82 layout(Layout::LAYOUT_OTHER), |
| 84 was_parsed_using_autofill_predictions(false), | 83 was_parsed_using_autofill_predictions(false), |
| 85 is_alive(true) { | 84 is_alive(true), |
| 86 } | 85 is_public_suffix_match(false), |
| 86 is_affiliated(false) {} | |
| 87 | 87 |
| 88 PasswordForm::~PasswordForm() { | 88 PasswordForm::~PasswordForm() { |
| 89 CHECK(is_alive); | 89 CHECK(is_alive); |
| 90 is_alive = false; | 90 is_alive = false; |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool PasswordForm::IsPublicSuffixMatch() const { | |
| 94 CHECK(is_alive); | |
| 95 return !original_signon_realm.empty(); | |
| 96 } | |
| 97 | |
| 98 bool PasswordForm::IsPossibleChangePasswordForm() const { | 93 bool PasswordForm::IsPossibleChangePasswordForm() const { |
| 99 return !new_password_element.empty() && | 94 return !new_password_element.empty() && |
| 100 layout != PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP; | 95 layout != PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP; |
| 101 } | 96 } |
| 102 | 97 |
| 103 bool PasswordForm::IsPossibleChangePasswordFormWithoutUsername() const { | 98 bool PasswordForm::IsPossibleChangePasswordFormWithoutUsername() const { |
| 104 return IsPossibleChangePasswordForm() && username_element.empty(); | 99 return IsPossibleChangePasswordForm() && username_element.empty(); |
| 105 } | 100 } |
| 106 | 101 |
| 107 bool PasswordForm::operator==(const PasswordForm& form) const { | 102 bool PasswordForm::operator==(const PasswordForm& form) const { |
| 108 return scheme == form.scheme && | 103 return scheme == form.scheme && signon_realm == form.signon_realm && |
| 109 signon_realm == form.signon_realm && | 104 origin == form.origin && action == form.action && |
| 110 original_signon_realm == form.original_signon_realm && | 105 submit_element == form.submit_element && |
| 111 origin == form.origin && | 106 username_element == form.username_element && |
| 112 action == form.action && | 107 username_marked_by_site == form.username_marked_by_site && |
| 113 submit_element == form.submit_element && | 108 username_value == form.username_value && |
| 114 username_element == form.username_element && | 109 other_possible_usernames == form.other_possible_usernames && |
| 115 username_marked_by_site == form.username_marked_by_site && | 110 password_element == form.password_element && |
| 116 username_value == form.username_value && | 111 password_value == form.password_value && |
| 117 other_possible_usernames == form.other_possible_usernames && | 112 new_password_element == form.new_password_element && |
| 118 password_element == form.password_element && | 113 new_password_marked_by_site == form.new_password_marked_by_site && |
| 119 password_value == form.password_value && | 114 new_password_value == form.new_password_value && |
| 120 new_password_element == form.new_password_element && | 115 ssl_valid == form.ssl_valid && preferred == form.preferred && |
| 121 new_password_marked_by_site == form.new_password_marked_by_site && | 116 date_created == form.date_created && date_synced == form.date_synced && |
| 122 new_password_value == form.new_password_value && | 117 blacklisted_by_user == form.blacklisted_by_user && type == form.type && |
| 123 ssl_valid == form.ssl_valid && | 118 times_used == form.times_used && |
| 124 preferred == form.preferred && | 119 form_data.SameFormAs(form.form_data) && |
| 125 date_created == form.date_created && | 120 generation_upload_status == form.generation_upload_status && |
| 126 date_synced == form.date_synced && | 121 display_name == form.display_name && icon_url == form.icon_url && |
| 127 blacklisted_by_user == form.blacklisted_by_user && | 122 federation_url == form.federation_url && |
| 128 type == form.type && | 123 skip_zero_click == form.skip_zero_click && layout == form.layout && |
| 129 times_used == form.times_used && | 124 was_parsed_using_autofill_predictions == |
| 130 form_data.SameFormAs(form.form_data) && | 125 form.was_parsed_using_autofill_predictions && |
| 131 generation_upload_status == form.generation_upload_status && | 126 is_public_suffix_match == form.is_public_suffix_match; |
|
engedy
2015/09/29 19:11:04
I think we might want to test |is_affiliated| here
dvadym
2015/10/12 09:30:44
Done, in the following CL.
| |
| 132 display_name == form.display_name && | |
| 133 icon_url == form.icon_url && | |
| 134 federation_url == form.federation_url && | |
| 135 skip_zero_click == form.skip_zero_click && | |
| 136 layout == form.layout && | |
| 137 was_parsed_using_autofill_predictions == | |
| 138 form.was_parsed_using_autofill_predictions; | |
| 139 } | 127 } |
| 140 | 128 |
| 141 bool PasswordForm::operator!=(const PasswordForm& form) const { | 129 bool PasswordForm::operator!=(const PasswordForm& form) const { |
| 142 return !operator==(form); | 130 return !operator==(form); |
| 143 } | 131 } |
| 144 | 132 |
| 145 bool ArePasswordFormUniqueKeyEqual(const PasswordForm& left, | 133 bool ArePasswordFormUniqueKeyEqual(const PasswordForm& left, |
| 146 const PasswordForm& right) { | 134 const PasswordForm& right) { |
| 147 return (left.signon_realm == right.signon_realm && | 135 return (left.signon_realm == right.signon_realm && |
| 148 left.origin == right.origin && | 136 left.origin == right.origin && |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 form_json, base::JSONWriter::OPTIONS_PRETTY_PRINT, &form_as_string); | 194 form_json, base::JSONWriter::OPTIONS_PRETTY_PRINT, &form_as_string); |
| 207 base::TrimWhitespaceASCII(form_as_string, base::TRIM_ALL, &form_as_string); | 195 base::TrimWhitespaceASCII(form_as_string, base::TRIM_ALL, &form_as_string); |
| 208 return os << "PasswordForm(" << form_as_string << ")"; | 196 return os << "PasswordForm(" << form_as_string << ")"; |
| 209 } | 197 } |
| 210 | 198 |
| 211 std::ostream& operator<<(std::ostream& os, PasswordForm* form) { | 199 std::ostream& operator<<(std::ostream& os, PasswordForm* form) { |
| 212 return os << "&" << *form; | 200 return os << "&" << *form; |
| 213 } | 201 } |
| 214 | 202 |
| 215 } // namespace autofill | 203 } // namespace autofill |
| OLD | NEW |