Commit 3fb34c1e authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

Removing PasswordForm mojo definition in components/autofill.

This CL is a part of moving PasswordForm class to
components/password_manager/core/browser.

PasswordForm is used for Profile Import MOJO messages. Instead of
removed MOJO definition the IPC definition of PasswordForm is
introduced. It contains only needed fields (which is much smaller
subset fields).

Bug: 1067347
Change-Id: Ief5f302b7cd9500b401cf9ce9d4b022261e560b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2190490
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarVadym Doroshenko  <dvadym@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808858}
parent b024edc9
...@@ -48,17 +48,27 @@ mojom("interfaces") { ...@@ -48,17 +48,27 @@ mojom("interfaces") {
mojom = "chrome.mojom.ImportItem" mojom = "chrome.mojom.ImportItem"
cpp = "::importer::ImportItem" cpp = "::importer::ImportItem"
}, },
{
mojom = "chrome.mojom.ImportedPasswordForm"
cpp = "::autofill::PasswordForm"
},
] ]
traits_headers = [ traits_headers = [
"//chrome/common/importer/imported_bookmark_entry.h", "//chrome/common/importer/imported_bookmark_entry.h",
"//chrome/common/importer/importer_autofill_form_data_entry.h", "//chrome/common/importer/importer_autofill_form_data_entry.h",
"//chrome/common/importer/importer_data_types.h", "//chrome/common/importer/importer_data_types.h",
"//chrome/common/importer/importer_url_row.h", "//chrome/common/importer/importer_url_row.h",
"//components/autofill/core/common/password_form.h",
"//components/favicon_base/favicon_usage_data.h", "//components/favicon_base/favicon_usage_data.h",
] ]
traits_private_headers = [ "profile_import_process_param_traits.h" ] traits_private_headers = [
"profile_import_process_param_traits.h",
"profile_import_process_param_traits_macros.h",
]
traits_sources = [ "profile_import_process_param_traits.cc" ]
traits_public_deps = [ traits_public_deps = [
"//chrome/common", "//chrome/common",
"//components/autofill/core/common",
"//components/favicon_base", "//components/favicon_base",
"//ipc", "//ipc",
] ]
...@@ -90,9 +100,6 @@ source_set("importer") { ...@@ -90,9 +100,6 @@ source_set("importer") {
"importer_type.h", "importer_type.h",
"importer_url_row.cc", "importer_url_row.cc",
"importer_url_row.h", "importer_url_row.h",
"profile_import_process_param_traits.cc",
"profile_import_process_param_traits.h",
"profile_import_process_param_traits_macros.h",
"pstore_declarations.h", "pstore_declarations.h",
"safari_importer_utils.h", "safari_importer_utils.h",
"safari_importer_utils.mm", "safari_importer_utils.mm",
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
module chrome.mojom; module chrome.mojom;
import "components/autofill/core/common/mojom/autofill_types.mojom";
import "mojo/public/mojom/base/string16.mojom"; import "mojo/public/mojom/base/string16.mojom";
import "url/mojom/url.mojom"; import "url/mojom/url.mojom";
...@@ -32,6 +31,27 @@ struct ImporterIE7PasswordInfo; ...@@ -32,6 +31,27 @@ struct ImporterIE7PasswordInfo;
[Native] [Native]
enum ImportItem; enum ImportItem;
// Represents information about an imported password form. Typemapped to
// autofill::PasswordForm.
struct ImportedPasswordForm {
// Enum to differentiate between HTML form based authentication, and dialogs
// using basic or digest schemes. Default is kHtml.
enum Scheme {
kHtml,
kBasic,
};
Scheme scheme;
string signon_realm;
url.mojom.Url url;
url.mojom.Url action;
mojo_base.mojom.String16 username_element;
mojo_base.mojom.String16 username_value;
mojo_base.mojom.String16 password_element;
mojo_base.mojom.String16 password_value;
bool blocked_by_user;
};
// These are messages sent from the profile import process to the browser. // These are messages sent from the profile import process to the browser.
// These messages send information about the status of the import and individual // These messages send information about the status of the import and individual
// import tasks. // import tasks.
...@@ -54,7 +74,7 @@ interface ProfileImportObserver { ...@@ -54,7 +74,7 @@ interface ProfileImportObserver {
OnBookmarksImportGroup(array<ImportedBookmarkEntry> bookmarks_group); OnBookmarksImportGroup(array<ImportedBookmarkEntry> bookmarks_group);
OnFaviconsImportStart(uint32 total_favicons_count); OnFaviconsImportStart(uint32 total_favicons_count);
OnFaviconsImportGroup(FaviconUsageDataList favicons_group); OnFaviconsImportGroup(FaviconUsageDataList favicons_group);
OnPasswordFormImportReady(autofill.mojom.PasswordForm form); OnPasswordFormImportReady(ImportedPasswordForm form);
OnKeywordsImportReady( OnKeywordsImportReady(
array<SearchEngineInfo> search_engines, array<SearchEngineInfo> search_engines,
bool unique_on_host_and_path); bool unique_on_host_and_path);
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/common/importer/profile_import_process_param_traits.h"
// Get basic type definitions. // Get basic type definitions.
#define IPC_MESSAGE_IMPL #define IPC_MESSAGE_IMPL
#include "chrome/common/importer/profile_import_process_param_traits_macros.h" #include "chrome/common/importer/profile_import_process_param_traits_macros.h"
...@@ -31,3 +33,28 @@ namespace IPC { ...@@ -31,3 +33,28 @@ namespace IPC {
#undef CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_MACROS_H_ #undef CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_MACROS_H_
#include "chrome/common/importer/profile_import_process_param_traits_macros.h" #include "chrome/common/importer/profile_import_process_param_traits_macros.h"
} // namespace IPC } // namespace IPC
#include "mojo/public/cpp/base/string16_mojom_traits.h"
namespace mojo {
// static
bool StructTraits<chrome::mojom::ImportedPasswordFormDataView,
autofill::PasswordForm>::
Read(chrome::mojom::ImportedPasswordFormDataView data,
autofill::PasswordForm* out) {
if (!data.ReadScheme(&out->scheme) ||
!data.ReadSignonRealm(&out->signon_realm) || !data.ReadUrl(&out->url) ||
!data.ReadAction(&out->action) ||
!data.ReadUsernameElement(&out->username_element) ||
!data.ReadUsernameValue(&out->username_value) ||
!data.ReadPasswordElement(&out->password_element) ||
!data.ReadPasswordValue(&out->password_value)) {
return false;
}
out->blocked_by_user = data.blocked_by_user();
return true;
}
} // namespace mojo
...@@ -5,6 +5,90 @@ ...@@ -5,6 +5,90 @@
#ifndef CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_H_ #ifndef CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_H_
#define CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_H_ #define CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_H_
#include "base/strings/string16.h"
#include "chrome/common/importer/profile_import.mojom.h"
#include "chrome/common/importer/profile_import_process_param_traits_macros.h" #include "chrome/common/importer/profile_import_process_param_traits_macros.h"
#include "mojo/public/cpp/bindings/enum_traits.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
namespace mojo {
template <>
struct EnumTraits<chrome::mojom::ImportedPasswordForm::Scheme,
autofill::PasswordForm::Scheme> {
static chrome::mojom::ImportedPasswordForm::Scheme ToMojom(
autofill::PasswordForm::Scheme input) {
switch (input) {
case autofill::PasswordForm::Scheme::kHtml:
return chrome::mojom::ImportedPasswordForm::Scheme::kHtml;
case autofill::PasswordForm::Scheme::kBasic:
return chrome::mojom::ImportedPasswordForm::Scheme::kBasic;
default:
break;
}
NOTREACHED();
return chrome::mojom::ImportedPasswordForm::Scheme::kHtml;
}
static bool FromMojom(chrome::mojom::ImportedPasswordForm::Scheme input,
autofill::PasswordForm::Scheme* out) {
switch (input) {
case chrome::mojom::ImportedPasswordForm::Scheme::kHtml:
*out = autofill::PasswordForm::Scheme::kHtml;
return true;
case chrome::mojom::ImportedPasswordForm::Scheme::kBasic:
*out = autofill::PasswordForm::Scheme::kBasic;
return true;
}
NOTREACHED();
return false;
}
};
template <>
struct StructTraits<chrome::mojom::ImportedPasswordFormDataView,
autofill::PasswordForm> {
static autofill::PasswordForm::Scheme scheme(
const autofill::PasswordForm& r) {
return r.scheme;
}
static const std::string& signon_realm(const autofill::PasswordForm& r) {
return r.signon_realm;
}
static const GURL& url(const autofill::PasswordForm& r) { return r.url; }
static const GURL& action(const autofill::PasswordForm& r) {
return r.action;
}
static const base::string16& username_element(
const autofill::PasswordForm& r) {
return r.username_element;
}
static const base::string16& username_value(const autofill::PasswordForm& r) {
return r.username_value;
}
static const base::string16& password_element(
const autofill::PasswordForm& r) {
return r.password_element;
}
static const base::string16& password_value(const autofill::PasswordForm& r) {
return r.password_value;
}
static bool blocked_by_user(const autofill::PasswordForm& r) {
return r.blocked_by_user;
}
static bool Read(chrome::mojom::ImportedPasswordFormDataView data,
autofill::PasswordForm* out);
};
} // namespace mojo
#endif // CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_H_ #endif // CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_H_
...@@ -3208,6 +3208,7 @@ if (is_mac) { ...@@ -3208,6 +3208,7 @@ if (is_mac) {
sources = sources =
[ "../utility/importer/firefox_importer_unittest_utils_mac.mojom" ] [ "../utility/importer/firefox_importer_unittest_utils_mac.mojom" ]
public_deps = [ public_deps = [
"//chrome/common/importer:interfaces",
"//components/autofill/core/common/mojom:mojo_types", "//components/autofill/core/common/mojom:mojo_types",
"//mojo/public/mojom/base", "//mojo/public/mojom/base",
] ]
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
module firefox_importer_unittest_utils_mac.mojom; module firefox_importer_unittest_utils_mac.mojom;
import "components/autofill/core/common/mojom/autofill_types.mojom"; import "chrome/common/importer/profile_import.mojom";
import "mojo/public/mojom/base/file_path.mojom"; import "mojo/public/mojom/base/file_path.mojom";
import "mojo/public/mojom/base/string16.mojom"; import "mojo/public/mojom/base/string16.mojom";
...@@ -19,5 +19,5 @@ interface FirefoxDecryptor { ...@@ -19,5 +19,5 @@ interface FirefoxDecryptor {
// Parses the Firefox sqlite passwords database and returns the list of // Parses the Firefox sqlite passwords database and returns the list of
// credentials. // credentials.
ParseSignons(mojo_base.mojom.FilePath sqlite_file) => ParseSignons(mojo_base.mojom.FilePath sqlite_file) =>
(array<autofill.mojom.PasswordForm> parsed_vector); (array<chrome.mojom.ImportedPasswordForm> parsed_vector);
}; };
...@@ -33,6 +33,8 @@ enum SubmissionIndicatorEvent { ...@@ -33,6 +33,8 @@ enum SubmissionIndicatorEvent {
// essentially a digest of |autofill::ServerFieldType|. Note that we cannot // essentially a digest of |autofill::ServerFieldType|. Note that we cannot
// simply reuse |autofill::ServerFieldType| as it is defined in the browser, // simply reuse |autofill::ServerFieldType| as it is defined in the browser,
// while this enum will be used by both the browser and renderer. // while this enum will be used by both the browser and renderer.
// TODO(https://crbug.com/1067347): move this enum to browser code. It is not
// used in Mojo anymore.
enum PasswordFormFieldPredictionType { enum PasswordFormFieldPredictionType {
kUsername, kUsername,
kCurrentPassword, kCurrentPassword,
...@@ -236,81 +238,6 @@ struct PasswordGenerationUIData { ...@@ -236,81 +238,6 @@ struct PasswordGenerationUIData {
FormData form_data; FormData form_data;
}; };
// autofill::ValueElementPair
struct ValueElementPair {
mojo_base.mojom.String16 value;
mojo_base.mojom.String16 field_name;
};
// autofill::PasswordForm
struct PasswordForm {
// Enum to differentiate between HTML form based authentication, and dialogs
// using basic or digest schemes. Default is kHtml. Only PasswordForms of the
// same Scheme will be matched/autofilled against each other.
enum Scheme {
kHtml,
kBasic,
kDigest,
kOther,
kUsernameOnly,
};
// Enum to differentiate between manually filled forms, forms with auto-
// generated passwords, and forms generated from the DOM API.
//
// Always append new types at the end. This enum is converted to int and
// stored in password store backends, so it is important to keep each
// value assigned to the same integer.
enum Type {
kManual,
kGenerated,
kApi,
};
// Enum to keep track of what information has been sent to the server about
// this form regarding password generation.
enum GenerationUploadStatus {
kNoSignalSent,
kPositiveSignalSent,
kNegativeSignalSent,
// Reserve a few values for future use.
kUnknownStatus = 10,
};
Scheme scheme;
string signon_realm;
url.mojom.Url url;
url.mojom.Url action;
string affiliated_web_realm;
mojo_base.mojom.String16 submit_element;
mojo_base.mojom.String16 username_element;
mojo_base.mojom.String16 username_value;
array<ValueElementPair> all_possible_usernames;
array<ValueElementPair> all_possible_passwords;
bool form_has_autofilled_value;
mojo_base.mojom.String16 password_element;
mojo_base.mojom.String16 password_value;
mojo_base.mojom.String16 new_password_element;
mojo_base.mojom.String16 new_password_value;
mojo_base.mojom.String16 confirmation_password_element;
mojo_base.mojom.Time date_created;
mojo_base.mojom.Time date_synced;
bool blocked_by_user;
Type type;
int32 times_used;
FormData form_data;
GenerationUploadStatus generation_upload_status;
mojo_base.mojom.String16 display_name;
url.mojom.Url icon_url;
url.mojom.Origin federation_origin;
bool skip_zero_click;
bool was_parsed_using_autofill_predictions;
bool is_public_suffix_match;
bool is_affiliation_based_match;
SubmissionIndicatorEvent submission_event;
bool only_for_fallback;
};
// autofill::ParsingResult // autofill::ParsingResult
struct ParsingResult { struct ParsingResult {
FieldRendererId username_renderer_id; FieldRendererId username_renderer_id;
......
...@@ -265,76 +265,6 @@ bool StructTraits<autofill::mojom::PasswordGenerationUIDataDataView, ...@@ -265,76 +265,6 @@ bool StructTraits<autofill::mojom::PasswordGenerationUIDataDataView,
data.ReadFormData(&out->form_data); data.ReadFormData(&out->form_data);
} }
// static
bool StructTraits<
autofill::mojom::PasswordFormDataView,
autofill::PasswordForm>::Read(autofill::mojom::PasswordFormDataView data,
autofill::PasswordForm* out) {
if (!data.ReadScheme(&out->scheme) ||
!data.ReadSignonRealm(&out->signon_realm) || !data.ReadUrl(&out->url) ||
!data.ReadAction(&out->action) ||
!data.ReadAffiliatedWebRealm(&out->affiliated_web_realm) ||
!data.ReadSubmitElement(&out->submit_element) ||
!data.ReadUsernameElement(&out->username_element) ||
!data.ReadSubmissionEvent(&out->submission_event))
return false;
if (!data.ReadUsernameValue(&out->username_value) ||
!data.ReadAllPossibleUsernames(&out->all_possible_usernames) ||
!data.ReadAllPossiblePasswords(&out->all_possible_passwords) ||
!data.ReadPasswordElement(&out->password_element) ||
!data.ReadPasswordValue(&out->password_value))
return false;
out->form_has_autofilled_value = data.form_has_autofilled_value();
if (!data.ReadNewPasswordElement(&out->new_password_element) ||
!data.ReadNewPasswordValue(&out->new_password_value))
return false;
if (!data.ReadConfirmationPasswordElement(
&out->confirmation_password_element))
return false;
if (!data.ReadDateCreated(&out->date_created) ||
!data.ReadDateSynced(&out->date_synced))
return false;
out->blocked_by_user = data.blocked_by_user();
if (!data.ReadType(&out->type))
return false;
out->times_used = data.times_used();
if (!data.ReadFormData(&out->form_data) ||
!data.ReadGenerationUploadStatus(&out->generation_upload_status) ||
!data.ReadDisplayName(&out->display_name) ||
!data.ReadIconUrl(&out->icon_url) ||
!data.ReadFederationOrigin(&out->federation_origin))
return false;
out->skip_zero_click = data.skip_zero_click();
out->was_parsed_using_autofill_predictions =
data.was_parsed_using_autofill_predictions();
out->is_public_suffix_match = data.is_public_suffix_match();
out->is_affiliation_based_match = data.is_affiliation_based_match();
out->only_for_fallback = data.only_for_fallback();
return true;
}
// static
bool StructTraits<autofill::mojom::ValueElementPairDataView,
autofill::ValueElementPair>::
Read(autofill::mojom::ValueElementPairDataView data,
autofill::ValueElementPair* out) {
if (!data.ReadValue(&out->first) || !data.ReadFieldName(&out->second))
return false;
return true;
}
bool StructTraits< bool StructTraits<
autofill::mojom::ParsingResultDataView, autofill::mojom::ParsingResultDataView,
autofill::ParsingResult>::Read(autofill::mojom::ParsingResultDataView data, autofill::ParsingResult>::Read(autofill::mojom::ParsingResultDataView data,
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/form_field_data_predictions.h" #include "components/autofill/core/common/form_field_data_predictions.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom-shared.h" #include "components/autofill/core/common/mojom/autofill_types.mojom-shared.h"
#include "components/autofill/core/common/password_form.h"
#include "components/autofill/core/common/password_form_fill_data.h" #include "components/autofill/core/common/password_form_fill_data.h"
#include "components/autofill/core/common/password_form_generation_data.h" #include "components/autofill/core/common/password_form_generation_data.h"
#include "components/autofill/core/common/password_generation_util.h" #include "components/autofill/core/common/password_generation_util.h"
...@@ -473,166 +472,6 @@ struct StructTraits<autofill::mojom::PasswordGenerationUIDataDataView, ...@@ -473,166 +472,6 @@ struct StructTraits<autofill::mojom::PasswordGenerationUIDataDataView,
autofill::password_generation::PasswordGenerationUIData* out); autofill::password_generation::PasswordGenerationUIData* out);
}; };
template <>
struct StructTraits<autofill::mojom::PasswordFormDataView,
autofill::PasswordForm> {
static autofill::PasswordForm::Scheme scheme(
const autofill::PasswordForm& r) {
return r.scheme;
}
static const std::string& signon_realm(const autofill::PasswordForm& r) {
return r.signon_realm;
}
static const GURL& url(const autofill::PasswordForm& r) { return r.url; }
static const GURL& action(const autofill::PasswordForm& r) {
return r.action;
}
static const std::string& affiliated_web_realm(
const autofill::PasswordForm& r) {
return r.affiliated_web_realm;
}
static const base::string16& submit_element(const autofill::PasswordForm& r) {
return r.submit_element;
}
static const base::string16& username_element(
const autofill::PasswordForm& r) {
return r.username_element;
}
static const base::string16& username_value(const autofill::PasswordForm& r) {
return r.username_value;
}
static const std::vector<autofill::ValueElementPair>& all_possible_usernames(
const autofill::PasswordForm& r) {
return r.all_possible_usernames;
}
static const std::vector<autofill::ValueElementPair>& all_possible_passwords(
const autofill::PasswordForm& r) {
return r.all_possible_passwords;
}
static bool form_has_autofilled_value(const autofill::PasswordForm& r) {
return r.form_has_autofilled_value;
}
static const base::string16& password_element(
const autofill::PasswordForm& r) {
return r.password_element;
}
static const base::string16& password_value(const autofill::PasswordForm& r) {
return r.password_value;
}
static const base::string16& new_password_element(
const autofill::PasswordForm& r) {
return r.new_password_element;
}
static const base::string16& new_password_value(
const autofill::PasswordForm& r) {
return r.new_password_value;
}
static const base::string16& confirmation_password_element(
const autofill::PasswordForm& r) {
return r.confirmation_password_element;
}
static const base::Time& date_created(const autofill::PasswordForm& r) {
return r.date_created;
}
static const base::Time& date_synced(const autofill::PasswordForm& r) {
return r.date_synced;
}
static bool blocked_by_user(const autofill::PasswordForm& r) {
return r.blocked_by_user;
}
static autofill::PasswordForm::Type type(const autofill::PasswordForm& r) {
return r.type;
}
static int32_t times_used(const autofill::PasswordForm& r) {
return r.times_used;
}
static const autofill::FormData& form_data(const autofill::PasswordForm& r) {
return r.form_data;
}
static autofill::PasswordForm::GenerationUploadStatus
generation_upload_status(const autofill::PasswordForm& r) {
return r.generation_upload_status;
}
static const base::string16& display_name(const autofill::PasswordForm& r) {
return r.display_name;
}
static const GURL& icon_url(const autofill::PasswordForm& r) {
return r.icon_url;
}
static const url::Origin& federation_origin(const autofill::PasswordForm& r) {
return r.federation_origin;
}
static bool skip_zero_click(const autofill::PasswordForm& r) {
return r.skip_zero_click;
}
static bool was_parsed_using_autofill_predictions(
const autofill::PasswordForm& r) {
return r.was_parsed_using_autofill_predictions;
}
static bool is_public_suffix_match(const autofill::PasswordForm& r) {
return r.is_public_suffix_match;
}
static bool is_affiliation_based_match(const autofill::PasswordForm& r) {
return r.is_affiliation_based_match;
}
static autofill::mojom::SubmissionIndicatorEvent submission_event(
const autofill::PasswordForm& r) {
return r.submission_event;
}
static bool only_for_fallback(const autofill::PasswordForm& r) {
return r.only_for_fallback;
}
static bool Read(autofill::mojom::PasswordFormDataView data,
autofill::PasswordForm* out);
};
template <>
struct StructTraits<autofill::mojom::ValueElementPairDataView,
autofill::ValueElementPair> {
static base::string16 value(const autofill::ValueElementPair& r) {
return r.first;
}
static base::string16 field_name(const autofill::ValueElementPair& r) {
return r.second;
}
static bool Read(autofill::mojom::ValueElementPairDataView data,
autofill::ValueElementPair* out);
};
template <> template <>
struct StructTraits<autofill::mojom::ParsingResultDataView, struct StructTraits<autofill::mojom::ParsingResultDataView,
autofill::ParsingResult> { autofill::ParsingResult> {
......
...@@ -73,48 +73,6 @@ void CreateTestPasswordFormFillData(PasswordFormFillData* fill_data) { ...@@ -73,48 +73,6 @@ void CreateTestPasswordFormFillData(PasswordFormFillData* fill_data) {
fill_data->wait_for_username = true; fill_data->wait_for_username = true;
} }
void CreateTestPasswordForm(PasswordForm* form) {
form->scheme = PasswordForm::Scheme::kHtml;
form->signon_realm = "https://foo.com/";
form->url = GURL("https://foo.com/");
form->action = GURL("https://foo.com/login");
form->affiliated_web_realm = "https://foo.com/";
form->submit_element = base::ASCIIToUTF16("test_submit");
form->username_element = base::ASCIIToUTF16("username");
form->username_value = base::ASCIIToUTF16("test@gmail.com");
form->all_possible_usernames.push_back(ValueElementPair(
base::ASCIIToUTF16("Jerry_1"), base::ASCIIToUTF16("id1")));
form->all_possible_usernames.push_back(ValueElementPair(
base::ASCIIToUTF16("Jerry_2"), base::ASCIIToUTF16("id2")));
form->all_possible_passwords.push_back(
ValueElementPair(base::ASCIIToUTF16("pass1"), base::ASCIIToUTF16("el1")));
form->all_possible_passwords.push_back(
ValueElementPair(base::ASCIIToUTF16("pass2"), base::ASCIIToUTF16("el2")));
form->form_has_autofilled_value = true;
form->password_element = base::ASCIIToUTF16("password");
form->password_value = base::ASCIIToUTF16("test");
form->new_password_element = base::ASCIIToUTF16("new_password");
form->new_password_value = base::ASCIIToUTF16("new_password_value");
form->new_password_element = base::ASCIIToUTF16("confirmation_password");
form->date_created = AutofillClock::Now();
form->date_synced = AutofillClock::Now();
form->blocked_by_user = false;
form->type = PasswordForm::Type::kGenerated;
form->times_used = 999;
test::CreateTestAddressFormData(&form->form_data);
form->generation_upload_status =
PasswordForm::GenerationUploadStatus::kPositiveSignalSent;
form->display_name = base::ASCIIToUTF16("test display name");
form->icon_url = GURL("https://foo.com/icon.png");
form->federation_origin = url::Origin::Create(GURL("http://wwww.google.com"));
form->skip_zero_click = false;
form->was_parsed_using_autofill_predictions = false;
form->is_public_suffix_match = true;
form->is_affiliation_based_match = true;
form->submission_event =
mojom::SubmissionIndicatorEvent::SAME_DOCUMENT_NAVIGATION;
}
void CreatePasswordGenerationUIData( void CreatePasswordGenerationUIData(
password_generation::PasswordGenerationUIData* data) { password_generation::PasswordGenerationUIData* data) {
data->bounds = gfx::RectF(1, 1, 200, 100); data->bounds = gfx::RectF(1, 1, 200, 100);
...@@ -220,11 +178,6 @@ class AutofillTypeTraitsTestImpl : public testing::Test, ...@@ -220,11 +178,6 @@ class AutofillTypeTraitsTestImpl : public testing::Test,
std::move(callback).Run(s); std::move(callback).Run(s);
} }
void PassPasswordForm(const PasswordForm& s,
PassPasswordFormCallback callback) override {
std::move(callback).Run(s);
}
private: private:
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
...@@ -439,15 +392,4 @@ TEST_F(AutofillTypeTraitsTestImpl, PassPasswordGenerationUIData) { ...@@ -439,15 +392,4 @@ TEST_F(AutofillTypeTraitsTestImpl, PassPasswordGenerationUIData) {
loop.Run(); loop.Run();
} }
TEST_F(AutofillTypeTraitsTestImpl, PassPasswordForm) {
PasswordForm input;
CreateTestPasswordForm(&input);
base::RunLoop loop;
mojo::Remote<mojom::TypeTraitsTest> remote(GetTypeTraitsTestRemote());
remote->PassPasswordForm(
input, base::BindOnce(&ExpectPasswordForm, input, loop.QuitClosure()));
loop.Run();
}
} // namespace autofill } // namespace autofill
...@@ -13,7 +13,6 @@ interface TypeTraitsTest { ...@@ -13,7 +13,6 @@ interface TypeTraitsTest {
(FormDataPredictions passed); (FormDataPredictions passed);
PassFormFieldDataPredictions(FormFieldDataPredictions s) => PassFormFieldDataPredictions(FormFieldDataPredictions s) =>
(FormFieldDataPredictions passed); (FormFieldDataPredictions passed);
PassPasswordForm(PasswordForm s) => (PasswordForm passed);
PassPasswordFormFillData(PasswordFormFillData s) => PassPasswordFormFillData(PasswordFormFillData s) =>
(PasswordFormFillData passed); (PasswordFormFillData passed);
PassPasswordFormGenerationData(PasswordFormGenerationData s) => PassPasswordFormGenerationData(PasswordFormGenerationData s) =>
......
...@@ -18,16 +18,7 @@ namespace autofill { ...@@ -18,16 +18,7 @@ namespace autofill {
namespace { namespace {
// Utility function that creates a std::string from an object supporting the std::string ToString(PasswordForm::Store in_store) {
// ostream operator<<.
template <typename T>
std::string ToString(const T& obj) {
std::ostringstream ostream;
ostream << obj;
return ostream.str();
}
std::string StoreToString(PasswordForm::Store in_store) {
switch (in_store) { switch (in_store) {
case PasswordForm::Store::kNotSet: case PasswordForm::Store::kNotSet:
return "Not Set"; return "Not Set";
...@@ -38,6 +29,61 @@ std::string StoreToString(PasswordForm::Store in_store) { ...@@ -38,6 +29,61 @@ std::string StoreToString(PasswordForm::Store in_store) {
} }
} }
std::string ToString(PasswordForm::Scheme scheme) {
switch (scheme) {
case PasswordForm::Scheme::kHtml:
return "HTML";
case PasswordForm::Scheme::kBasic:
return "Basic";
case PasswordForm::Scheme::kDigest:
return "Digest";
case PasswordForm::Scheme::kOther:
return "Other";
case PasswordForm::Scheme::kUsernameOnly:
return "UsernameOnly";
}
NOTREACHED();
return std::string();
}
std::string ToString(PasswordForm::Type type) {
switch (type) {
case PasswordForm::Type::kManual:
return "Manual";
case PasswordForm::Type::kGenerated:
return "Generated";
case PasswordForm::Type::kApi:
return "API";
}
NOTREACHED();
return std::string();
}
std::string ToString(PasswordForm::GenerationUploadStatus status) {
switch (status) {
case PasswordForm::GenerationUploadStatus::kNoSignalSent:
return "No Signal Sent";
case PasswordForm::GenerationUploadStatus::kPositiveSignalSent:
return "Positive Signal Sent";
case PasswordForm::GenerationUploadStatus::kNegativeSignalSent:
return "Negative Signal Sent";
}
NOTREACHED();
return std::string();
}
// Utility function that creates a std::string from an object supporting the
// ostream operator<<.
template <typename T>
std::string ToString(const T& obj) {
std::ostringstream ostream;
ostream << obj;
return ostream.str();
}
// Serializes a PasswordForm to a JSON object. Used only for logging in tests. // Serializes a PasswordForm to a JSON object. Used only for logging in tests.
void PasswordFormToJSON(const PasswordForm& form, void PasswordFormToJSON(const PasswordForm& form,
base::DictionaryValue* target) { base::DictionaryValue* target) {
...@@ -92,7 +138,7 @@ void PasswordFormToJSON(const PasswordForm& form, ...@@ -92,7 +138,7 @@ void PasswordFormToJSON(const PasswordForm& form,
target->SetBoolean("is_gaia_with_skip_save_password_form", target->SetBoolean("is_gaia_with_skip_save_password_form",
form.form_data.is_gaia_with_skip_save_password_form); form.form_data.is_gaia_with_skip_save_password_form);
target->SetBoolean("is_new_password_reliable", form.is_new_password_reliable); target->SetBoolean("is_new_password_reliable", form.is_new_password_reliable);
target->SetString("in_store", StoreToString(form.in_store)); target->SetString("in_store", ToString(form.in_store));
std::vector<std::string> hashes; std::vector<std::string> hashes;
hashes.reserve(form.moving_blocked_for_list.size()); hashes.reserve(form.moving_blocked_for_list.size());
...@@ -220,6 +266,10 @@ base::string16 ValueElementVectorToString( ...@@ -220,6 +266,10 @@ base::string16 ValueElementVectorToString(
return base::JoinString(pairs, base::ASCIIToUTF16(", ")); return base::JoinString(pairs, base::ASCIIToUTF16(", "));
} }
std::ostream& operator<<(std::ostream& os, PasswordForm::Scheme scheme) {
return os << ToString(scheme);
}
std::ostream& operator<<(std::ostream& os, const PasswordForm& form) { std::ostream& operator<<(std::ostream& os, const PasswordForm& form) {
base::DictionaryValue form_json; base::DictionaryValue form_json;
PasswordFormToJSON(form, &form_json); PasswordFormToJSON(form, &form_json);
......
...@@ -50,9 +50,42 @@ using ValueElementVector = std::vector<ValueElementPair>; ...@@ -50,9 +50,42 @@ using ValueElementVector = std::vector<ValueElementPair>;
// entry to the database and how they can affect the matching process. // entry to the database and how they can affect the matching process.
struct PasswordForm { struct PasswordForm {
using Scheme = mojom::PasswordForm_Scheme; // Enum to differentiate between HTML form based authentication, and dialogs
using Type = mojom::PasswordForm_Type; // using basic or digest schemes. Default is kHtml. Only PasswordForms of the
using GenerationUploadStatus = mojom::PasswordForm_GenerationUploadStatus; // same Scheme will be matched/autofilled against each other.
enum class Scheme {
kHtml,
kBasic,
kDigest,
kOther,
kUsernameOnly,
kMinValue = kHtml,
kMaxValue = kUsernameOnly,
};
// Enum to differentiate between manually filled forms, forms with auto-
// generated passwords, and forms generated from the DOM API.
//
// Always append new types at the end. This enum is converted to int and
// stored in password store backends, so it is important to keep each
// value assigned to the same integer.
enum class Type {
kManual,
kGenerated,
kApi,
kMinValue = kManual,
kMaxValue = kApi,
};
// Enum to keep track of what information has been sent to the server about
// this form regarding password generation.
enum class GenerationUploadStatus {
kNoSignalSent,
kPositiveSignalSent,
kNegativeSignalSent,
kMinValue = kNoSignalSent,
kMaxValue = kNegativeSignalSent,
};
Scheme scheme = Scheme::kHtml; Scheme scheme = Scheme::kHtml;
...@@ -349,6 +382,7 @@ base::string16 ValueElementVectorToString( ...@@ -349,6 +382,7 @@ base::string16 ValueElementVectorToString(
const ValueElementVector& value_element_pairs); const ValueElementVector& value_element_pairs);
// For testing. // For testing.
std::ostream& operator<<(std::ostream& os, PasswordForm::Scheme scheme);
std::ostream& operator<<(std::ostream& os, const PasswordForm& form); std::ostream& operator<<(std::ostream& os, const PasswordForm& form);
std::ostream& operator<<(std::ostream& os, PasswordForm* form); std::ostream& operator<<(std::ostream& os, PasswordForm* form);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/check_op.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -594,6 +595,16 @@ PasswordForm GetFormForRemoval(const sql::Statement& statement) { ...@@ -594,6 +595,16 @@ PasswordForm GetFormForRemoval(const sql::Statement& statement) {
} }
#endif #endif
// This converts `i` to type `Enum`. Terminates in case `i` is outside the valid
// ranges for `Enum`. Requires `Enum::kMinValue` and `Enum::kMaxValue` to exist
// and have correct semantics.
template <typename Enum>
Enum ToEnumOrDie(int i) {
CHECK_LE(static_cast<int>(Enum::kMinValue), i);
CHECK_GE(static_cast<int>(Enum::kMaxValue), i);
return static_cast<Enum>(i);
}
} // namespace } // namespace
struct LoginDatabase::PrimaryKeyAndPassword { struct LoginDatabase::PrimaryKeyAndPassword {
...@@ -1422,12 +1433,9 @@ LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement( ...@@ -1422,12 +1433,9 @@ LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement(
form->date_created = form->date_created =
base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_CREATED)); base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_CREATED));
form->blocked_by_user = (s.ColumnInt(COLUMN_BLACKLISTED_BY_USER) > 0); form->blocked_by_user = (s.ColumnInt(COLUMN_BLACKLISTED_BY_USER) > 0);
int scheme_int = s.ColumnInt(COLUMN_SCHEME); form->scheme = ToEnumOrDie<PasswordForm::Scheme>(s.ColumnInt(COLUMN_SCHEME));
form->scheme = static_cast<PasswordForm::Scheme>(scheme_int); form->type =
DCHECK(autofill::mojom::IsKnownEnumValue(form->scheme)); ToEnumOrDie<PasswordForm::Type>(s.ColumnInt(COLUMN_PASSWORD_TYPE));
int type_int = s.ColumnInt(COLUMN_PASSWORD_TYPE);
form->type = static_cast<PasswordForm::Type>(type_int);
DCHECK(autofill::mojom::IsKnownEnumValue(form->type));
if (s.ColumnByteLength(COLUMN_POSSIBLE_USERNAME_PAIRS)) { if (s.ColumnByteLength(COLUMN_POSSIBLE_USERNAME_PAIRS)) {
base::Pickle pickle( base::Pickle pickle(
static_cast<const char*>(s.ColumnBlob(COLUMN_POSSIBLE_USERNAME_PAIRS)), static_cast<const char*>(s.ColumnBlob(COLUMN_POSSIBLE_USERNAME_PAIRS)),
...@@ -1454,11 +1462,9 @@ LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement( ...@@ -1454,11 +1462,9 @@ LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement(
form->federation_origin = form->federation_origin =
url::Origin::Create(GURL(s.ColumnString(COLUMN_FEDERATION_URL))); url::Origin::Create(GURL(s.ColumnString(COLUMN_FEDERATION_URL)));
form->skip_zero_click = (s.ColumnInt(COLUMN_SKIP_ZERO_CLICK) > 0); form->skip_zero_click = (s.ColumnInt(COLUMN_SKIP_ZERO_CLICK) > 0);
int generation_upload_status_int =
s.ColumnInt(COLUMN_GENERATION_UPLOAD_STATUS);
form->generation_upload_status = form->generation_upload_status =
static_cast<PasswordForm::GenerationUploadStatus>( ToEnumOrDie<PasswordForm::GenerationUploadStatus>(
generation_upload_status_int); s.ColumnInt(COLUMN_GENERATION_UPLOAD_STATUS));
form->date_last_used = base::Time::FromDeltaSinceWindowsEpoch( form->date_last_used = base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds(s.ColumnInt64(COLUMN_DATE_LAST_USED))); base::TimeDelta::FromMicroseconds(s.ColumnInt64(COLUMN_DATE_LAST_USED)));
if (s.ColumnByteLength(COLUMN_MOVING_BLOCKED_FOR)) { if (s.ColumnByteLength(COLUMN_MOVING_BLOCKED_FOR)) {
...@@ -1467,8 +1473,6 @@ LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement( ...@@ -1467,8 +1473,6 @@ LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement(
s.ColumnByteLength(COLUMN_MOVING_BLOCKED_FOR)); s.ColumnByteLength(COLUMN_MOVING_BLOCKED_FOR));
form->moving_blocked_for_list = DeserializeGaiaIdHashVector(pickle); form->moving_blocked_for_list = DeserializeGaiaIdHashVector(pickle);
} }
DCHECK(autofill::mojom::IsKnownEnumValue(form->generation_upload_status));
return ENCRYPTION_RESULT_SUCCESS; return ENCRYPTION_RESULT_SUCCESS;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment