| Index: components/autofill/core/common/password_form.cc
|
| diff --git a/components/autofill/core/common/password_form.cc b/components/autofill/core/common/password_form.cc
|
| index 066899e943b5a7bdc0e29c105b10933baeaa181f..1dc8bc34f88148748cb6374409e0bff8dd9fec68 100644
|
| --- a/components/autofill/core/common/password_form.cc
|
| +++ b/components/autofill/core/common/password_form.cc
|
| @@ -3,14 +3,59 @@
|
| // found in the LICENSE file.
|
|
|
| #include <ostream>
|
| +#include <sstream>
|
|
|
| +#include "base/json/json_writer.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/values.h"
|
| #include "components/autofill/core/common/password_form.h"
|
|
|
| namespace autofill {
|
|
|
| +namespace {
|
| +
|
| +// Serializes a PasswordForm to a JSON object. Used only for logging in tests.
|
| +void PasswordFormToJSON(const PasswordForm& form,
|
| + base::DictionaryValue* target) {
|
| + target->SetInteger("scheme", form.scheme);
|
| + target->SetString("signon_realm", form.signon_realm);
|
| + target->SetString("signon_realm", form.signon_realm);
|
| + target->SetString("original_signon_realm", form.original_signon_realm);
|
| + target->SetString("origin", form.origin.possibly_invalid_spec());
|
| + target->SetString("action", form.action.possibly_invalid_spec());
|
| + target->SetString("submit_element", form.submit_element);
|
| + target->SetString("username_elem", form.username_element);
|
| + target->SetBoolean("username_marked_by_site", form.username_marked_by_site);
|
| + target->SetString("username_value", form.username_value);
|
| + target->SetString("password_elem", form.password_element);
|
| + target->SetString("password_value", form.password_value);
|
| + target->SetString("new_password_element", form.new_password_element);
|
| + target->SetString("new_password_value", form.new_password_value);
|
| + target->SetString("other_possible_usernames",
|
| + JoinString(form.other_possible_usernames, '|'));
|
| + target->SetBoolean("autocomplete_set", form.password_autocomplete_set);
|
| + target->SetBoolean("blacklisted", form.blacklisted_by_user);
|
| + target->SetBoolean("preferred", form.preferred);
|
| + target->SetBoolean("ssl_valid", form.ssl_valid);
|
| + target->SetDouble("date_created", form.date_created.ToDoubleT());
|
| + target->SetDouble("date_synced", form.date_synced.ToDoubleT());
|
| + target->SetInteger("type", form.type);
|
| + target->SetInteger("times_used", form.times_used);
|
| + std::ostringstream form_data_string_stream;
|
| + form_data_string_stream << form.form_data;
|
| + target->SetString("form_data", form_data_string_stream.str());
|
| + target->SetInteger("generation_upload_status", form.generation_upload_status);
|
| + target->SetString("display_name", form.display_name);
|
| + target->SetString("avatar_url", form.avatar_url.possibly_invalid_spec());
|
| + target->SetString("federation_url",
|
| + form.federation_url.possibly_invalid_spec());
|
| + target->SetBoolean("skip_next_zero_click", form.skip_zero_click);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| PasswordForm::PasswordForm()
|
| : scheme(SCHEME_HTML),
|
| username_marked_by_site(false),
|
| @@ -67,37 +112,31 @@ bool PasswordForm::operator!=(const PasswordForm& form) const {
|
| }
|
|
|
| std::ostream& operator<<(std::ostream& os, const PasswordForm& form) {
|
| - return os << "scheme: " << form.scheme
|
| - << " signon_realm: " << form.signon_realm
|
| - << " original_signon_realm: " << form.original_signon_realm
|
| - << " origin: " << form.origin
|
| - << " action: " << form.action
|
| - << " submit_element: " << base::UTF16ToUTF8(form.submit_element)
|
| - << " username_elem: " << base::UTF16ToUTF8(form.username_element)
|
| - << " username_marked_by_site: " << form.username_marked_by_site
|
| - << " username_value: " << base::UTF16ToUTF8(form.username_value)
|
| - << " password_elem: " << base::UTF16ToUTF8(form.password_element)
|
| - << " password_value: " << base::UTF16ToUTF8(form.password_value)
|
| - << " new_password_element: "
|
| - << base::UTF16ToUTF8(form.new_password_element)
|
| - << " new_password_value: "
|
| - << base::UTF16ToUTF8(form.new_password_value)
|
| - << " other_possible_usernames: "
|
| - << JoinString(form.other_possible_usernames, '|')
|
| - << " autocomplete_set:" << form.password_autocomplete_set
|
| - << " blacklisted: " << form.blacklisted_by_user
|
| - << " preferred: " << form.preferred
|
| - << " ssl_valid: " << form.ssl_valid
|
| - << " date_created: " << form.date_created.ToDoubleT()
|
| - << " date_synced: " << form.date_synced.ToDoubleT()
|
| - << " type: " << form.type
|
| - << " times_used: " << form.times_used
|
| - << " form_data: " << form.form_data
|
| - << " generation_upload_status: " << form.generation_upload_status
|
| - << " display_name: " << base::UTF16ToUTF8(form.display_name)
|
| - << " avatar_url: " << form.avatar_url
|
| - << " federation_url: " << form.federation_url
|
| - << " skip_next_zero_click: " << form.skip_zero_click;
|
| + base::DictionaryValue form_json;
|
| + PasswordFormToJSON(form, &form_json);
|
| +
|
| + // Serialize the default PasswordForm, and remove values from the result that
|
| + // are equal to this to make the results more concise.
|
| + base::DictionaryValue default_form_json;
|
| + PasswordFormToJSON(PasswordForm(), &default_form_json);
|
| + for (base::DictionaryValue::Iterator it_default_key_values(default_form_json);
|
| + !it_default_key_values.IsAtEnd(); it_default_key_values.Advance()) {
|
| + const base::Value* actual_value;
|
| + if (form_json.Get(it_default_key_values.key(), &actual_value) &&
|
| + it_default_key_values.value().Equals(actual_value)) {
|
| + form_json.Remove(it_default_key_values.key(), nullptr);
|
| + }
|
| + }
|
| +
|
| + std::string form_as_string;
|
| + base::JSONWriter::WriteWithOptions(
|
| + &form_json, base::JSONWriter::OPTIONS_PRETTY_PRINT, &form_as_string);
|
| + base::TrimWhitespaceASCII(form_as_string, base::TRIM_ALL, &form_as_string);
|
| + return os << "PasswordForm(" << form_as_string << ")";
|
| +}
|
| +
|
| +std::ostream& operator<<(std::ostream& os, PasswordForm* form) {
|
| + return os << "&" << *form;
|
| }
|
|
|
| } // namespace autofill
|
|
|