Commit 06638fa6 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] PasswordForm in //components/password_manager

This change drops remaining usages of autofill::PasswordForm in the
password_manager component in favor of password_manager::PasswordForm.

The usages in components/password_manager/core/common/ have been
inlined at the call sites, which live in //c/p_m/core/browser.

Bug: 1067347
Change-Id: I4902283af38b9b16589541c70d05b06ea26dfb27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436529
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813151}
parent 55441716
...@@ -118,7 +118,6 @@ test("components_unittests") { ...@@ -118,7 +118,6 @@ test("components_unittests") {
"//components/openscreen_platform:unittests", "//components/openscreen_platform:unittests",
"//components/os_crypt:unit_tests", "//components/os_crypt:unit_tests",
"//components/password_manager/core/browser:unit_tests", "//components/password_manager/core/browser:unit_tests",
"//components/password_manager/core/common:unit_tests",
"//components/payments/core:unit_tests", "//components/payments/core:unit_tests",
"//components/policy/core/browser:unit_tests", "//components/policy/core/browser:unit_tests",
"//components/policy/core/common:unit_tests", "//components/policy/core/common:unit_tests",
...@@ -212,6 +211,7 @@ test("components_unittests") { ...@@ -212,6 +211,7 @@ test("components_unittests") {
"//components/autofill/ios/form_util:unit_tests", "//components/autofill/ios/form_util:unit_tests",
"//components/image_fetcher/ios:unit_tests", "//components/image_fetcher/ios:unit_tests",
"//components/language/ios/browser:unit_tests", "//components/language/ios/browser:unit_tests",
"//components/password_manager/core/common:unit_tests",
"//components/password_manager/ios:unit_tests", "//components/password_manager/ios:unit_tests",
"//components/safe_browsing/ios:unit_tests", "//components/safe_browsing/ios:unit_tests",
"//components/security_state/ios:unit_tests", "//components/security_state/ios:unit_tests",
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/syslog_logging.h" #include "base/syslog_logging.h"
#include "components/autofill/core/common/password_form.h" #include "components/password_manager/core/browser/password_form.h"
#include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
...@@ -55,10 +55,9 @@ bool CheckChildProcessSecurityPolicyForURL(content::RenderFrameHost* frame, ...@@ -55,10 +55,9 @@ bool CheckChildProcessSecurityPolicyForURL(content::RenderFrameHost* frame,
return true; return true;
} }
bool CheckChildProcessSecurityPolicy( bool CheckChildProcessSecurityPolicy(content::RenderFrameHost* frame,
content::RenderFrameHost* frame, const PasswordForm& password_form,
const autofill::PasswordForm& password_form, BadMessageReason reason) {
BadMessageReason reason) {
return CheckChildProcessSecurityPolicyForURL(frame, password_form.url, return CheckChildProcessSecurityPolicyForURL(frame, password_form.url,
reason) && reason) &&
CheckChildProcessSecurityPolicyForURL( CheckChildProcessSecurityPolicyForURL(
...@@ -67,10 +66,9 @@ bool CheckChildProcessSecurityPolicy( ...@@ -67,10 +66,9 @@ bool CheckChildProcessSecurityPolicy(
frame, password_form.form_data.url, reason); frame, password_form.form_data.url, reason);
} }
bool CheckChildProcessSecurityPolicy( bool CheckChildProcessSecurityPolicy(content::RenderFrameHost* frame,
content::RenderFrameHost* frame, const std::vector<PasswordForm>& forms,
const std::vector<autofill::PasswordForm>& forms, BadMessageReason reason) {
BadMessageReason reason) {
for (const auto& form : forms) { for (const auto& form : forms) {
if (!bad_message::CheckChildProcessSecurityPolicy(frame, form, reason)) if (!bad_message::CheckChildProcessSecurityPolicy(frame, form, reason))
return false; return false;
......
...@@ -7,10 +7,7 @@ ...@@ -7,10 +7,7 @@
#include <vector> #include <vector>
#include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_data.h"
#include "components/password_manager/core/browser/password_form_forward.h"
namespace autofill {
struct PasswordForm;
}
namespace content { namespace content {
class RenderFrameHost; class RenderFrameHost;
...@@ -61,17 +58,15 @@ bool CheckChildProcessSecurityPolicyForURL(content::RenderFrameHost* frame, ...@@ -61,17 +58,15 @@ bool CheckChildProcessSecurityPolicyForURL(content::RenderFrameHost* frame,
// on |password_form|. If the origin mismatches, the process for |frame| is // on |password_form|. If the origin mismatches, the process for |frame| is
// terminated and the function returns false. // terminated and the function returns false.
// TODO: Delete this signature after transferring all driver calls to FormData // TODO: Delete this signature after transferring all driver calls to FormData
bool CheckChildProcessSecurityPolicy( bool CheckChildProcessSecurityPolicy(content::RenderFrameHost* frame,
content::RenderFrameHost* frame, const PasswordForm& password_form,
const autofill::PasswordForm& password_form, BadMessageReason reason);
BadMessageReason reason);
// Same as above but checks every form in |forms|. // Same as above but checks every form in |forms|.
// TODO: Delete this signature after transferring all driver calls to FormData // TODO: Delete this signature after transferring all driver calls to FormData
bool CheckChildProcessSecurityPolicy( bool CheckChildProcessSecurityPolicy(content::RenderFrameHost* frame,
content::RenderFrameHost* frame, const std::vector<PasswordForm>& forms,
const std::vector<autofill::PasswordForm>& forms, BadMessageReason reason);
BadMessageReason reason);
bool CheckChildProcessSecurityPolicy( bool CheckChildProcessSecurityPolicy(
content::RenderFrameHost* frame, content::RenderFrameHost* frame,
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "components/autofill/content/browser/content_autofill_driver.h" #include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/core/browser/logging/log_manager.h" #include "components/autofill/core/browser/logging/log_manager.h"
#include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/content/browser/bad_message.h" #include "components/password_manager/content/browser/bad_message.h"
#include "components/password_manager/content/browser/content_password_manager_driver_factory.h" #include "components/password_manager/content/browser/content_password_manager_driver_factory.h"
#include "components/password_manager/core/browser/password_manager.h" #include "components/password_manager/core/browser/password_manager.h"
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "components/autofill/content/browser/content_autofill_driver.h" #include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h" #include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/content/browser/content_password_manager_driver.h" #include "components/password_manager/content/browser/content_password_manager_driver.h"
#include "components/password_manager/content/browser/form_submission_tracker_util.h" #include "components/password_manager/content/browser/form_submission_tracker_util.h"
#include "components/password_manager/core/browser/password_manager_client.h" #include "components/password_manager/core/browser/password_manager_client.h"
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
using autofill::ParsingResult; using autofill::ParsingResult;
using autofill::PasswordForm;
using autofill::PasswordFormFillData; using autofill::PasswordFormFillData;
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
using testing::_; using testing::_;
......
...@@ -79,6 +79,8 @@ static_library("browser") { ...@@ -79,6 +79,8 @@ static_library("browser") {
"credential_manager_pending_prevent_silent_access_task.h", "credential_manager_pending_prevent_silent_access_task.h",
"credential_manager_pending_request_task.cc", "credential_manager_pending_request_task.cc",
"credential_manager_pending_request_task.h", "credential_manager_pending_request_task.h",
"credential_manager_utils.cc",
"credential_manager_utils.h",
"credentials_cleaner.cc", "credentials_cleaner.cc",
"credentials_cleaner.h", "credentials_cleaner.h",
"credentials_cleaner_runner.cc", "credentials_cleaner_runner.cc",
...@@ -598,6 +600,7 @@ source_set("unit_tests") { ...@@ -598,6 +600,7 @@ source_set("unit_tests") {
"credential_manager_password_form_manager_unittest.cc", "credential_manager_password_form_manager_unittest.cc",
"credential_manager_pending_prevent_silent_access_task_unittest.cc", "credential_manager_pending_prevent_silent_access_task_unittest.cc",
"credential_manager_pending_request_task_unittest.cc", "credential_manager_pending_request_task_unittest.cc",
"credential_manager_utils_unittest.cc",
"credentials_cleaner_runner_unittest.cc", "credentials_cleaner_runner_unittest.cc",
"credentials_cleaner_unittest.cc", "credentials_cleaner_unittest.cc",
"export/csv_writer_unittest.cc", "export/csv_writer_unittest.cc",
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "components/password_manager/core/browser/credential_manager_logger.h" #include "components/password_manager/core/browser/credential_manager_logger.h"
#include "components/password_manager/core/browser/credential_manager_pending_request_task.h"
#include "components/password_manager/core/browser/credential_manager_utils.h"
#include "components/password_manager/core/browser/form_fetcher_impl.h" #include "components/password_manager/core/browser/form_fetcher_impl.h"
#include "components/password_manager/core/browser/form_saver.h" #include "components/password_manager/core/browser/form_saver.h"
#include "components/password_manager/core/browser/password_manager_util.h" #include "components/password_manager/core/browser/password_manager_util.h"
...@@ -197,11 +199,7 @@ void CredentialManagerImpl::SendPasswordForm( ...@@ -197,11 +199,7 @@ void CredentialManagerImpl::SendPasswordForm(
const PasswordForm* form) { const PasswordForm* form) {
CredentialInfo info; CredentialInfo info;
if (form) { if (form) {
password_manager::CredentialType type_to_return = info = PasswordFormToCredentialInfo(*form);
form->federation_origin.opaque()
? CredentialType::CREDENTIAL_TYPE_PASSWORD
: CredentialType::CREDENTIAL_TYPE_FEDERATED;
info = CredentialInfo(*form, type_to_return);
PasswordStore* store = form->IsUsingAccountStore() PasswordStore* store = form->IsUsingAccountStore()
? GetAccountPasswordStore() ? GetAccountPasswordStore()
: GetProfilePasswordStore(); : GetProfilePasswordStore();
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/password_manager/core/browser/android_affiliation/mock_affiliated_match_helper.h" #include "components/password_manager/core/browser/android_affiliation/mock_affiliated_match_helper.h"
#include "components/password_manager/core/browser/credential_manager_pending_request_task.h"
#include "components/password_manager/core/browser/credential_manager_utils.h"
#include "components/password_manager/core/browser/leak_detection/leak_detection_check.h" #include "components/password_manager/core/browser/leak_detection/leak_detection_check.h"
#include "components/password_manager/core/browser/leak_detection/leak_detection_check_factory.h" #include "components/password_manager/core/browser/leak_detection/leak_detection_check_factory.h"
#include "components/password_manager/core/browser/leak_detection/mock_leak_detection_check_factory.h" #include "components/password_manager/core/browser/leak_detection/mock_leak_detection_check_factory.h"
...@@ -410,7 +412,7 @@ TEST_P(CredentialManagerImplTest, IsZeroClickAllowed) { ...@@ -410,7 +412,7 @@ TEST_P(CredentialManagerImplTest, IsZeroClickAllowed) {
} }
TEST_P(CredentialManagerImplTest, CredentialManagerOnStore) { TEST_P(CredentialManagerImplTest, CredentialManagerOnStore) {
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(1)); .Times(testing::Exactly(1));
EXPECT_CALL(*client_, NotifyStorePasswordCalled()); EXPECT_CALL(*client_, NotifyStorePasswordCalled());
...@@ -445,7 +447,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerOnStoreFederated) { ...@@ -445,7 +447,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerOnStoreFederated) {
form_.federation_origin = url::Origin::Create(GURL("https://google.com/")); form_.federation_origin = url::Origin::Create(GURL("https://google.com/"));
form_.password_value = base::string16(); form_.password_value = base::string16();
form_.signon_realm = "federation://example.com/google.com"; form_.signon_realm = "federation://example.com/google.com";
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); auto info = PasswordFormToCredentialInfo(form_);
CallStore(info, base::BindOnce(&RespondCallback, &called)); CallStore(info, base::BindOnce(&RespondCallback, &called));
// Allow the PasswordFormManager to talk to the password store, determine // Allow the PasswordFormManager to talk to the password store, determine
...@@ -476,7 +478,7 @@ TEST_P(CredentialManagerImplTest, StoreFederatedAfterPassword) { ...@@ -476,7 +478,7 @@ TEST_P(CredentialManagerImplTest, StoreFederatedAfterPassword) {
federated.federation_origin = federated.federation_origin =
url::Origin::Create(GURL("https://google.com/")); url::Origin::Create(GURL("https://google.com/"));
federated.signon_realm = "federation://example.com/google.com"; federated.signon_realm = "federation://example.com/google.com";
CredentialInfo info(federated, CredentialType::CREDENTIAL_TYPE_FEDERATED); auto info = PasswordFormToCredentialInfo(federated);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)); EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
EXPECT_CALL(*client_, NotifyStorePasswordCalled()); EXPECT_CALL(*client_, NotifyStorePasswordCalled());
...@@ -513,7 +515,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { ...@@ -513,7 +515,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerStoreOverwrite) {
// Calling 'Store' with a credential that matches |form_| should update // Calling 'Store' with a credential that matches |form_| should update
// the password without prompting the user. // the password without prompting the user.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
info.password = base::ASCIIToUTF16("Totally new password."); info.password = base::ASCIIToUTF16("Totally new password.");
info.name = base::ASCIIToUTF16("New Name"); info.name = base::ASCIIToUTF16("New Name");
info.icon = GURL("https://example.com/icon.png"); info.icon = GURL("https://example.com/icon.png");
...@@ -551,7 +553,7 @@ TEST_P(CredentialManagerImplTest, ...@@ -551,7 +553,7 @@ TEST_P(CredentialManagerImplTest,
// Calling 'Store' with a new credential that is a PSL match for an existing // Calling 'Store' with a new credential that is a PSL match for an existing
// credential with identical username and password should result in a silent // credential with identical username and password should result in a silent
// save without prompting the user. // save without prompting the user.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(0)); .Times(testing::Exactly(0));
EXPECT_CALL(*client_, NotifyStorePasswordCalled()); EXPECT_CALL(*client_, NotifyStorePasswordCalled());
...@@ -578,7 +580,7 @@ TEST_P(CredentialManagerImplTest, ...@@ -578,7 +580,7 @@ TEST_P(CredentialManagerImplTest,
// Calling 'Store' with a new credential that is a PSL match for an existing // Calling 'Store' with a new credential that is a PSL match for an existing
// credential but has a different username should prompt the user and not // credential but has a different username should prompt the user and not
// result in a silent save. // result in a silent save.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(1)); .Times(testing::Exactly(1));
EXPECT_CALL(*client_, NotifyStorePasswordCalled()); EXPECT_CALL(*client_, NotifyStorePasswordCalled());
...@@ -610,7 +612,7 @@ TEST_P(CredentialManagerImplTest, ...@@ -610,7 +612,7 @@ TEST_P(CredentialManagerImplTest,
// Calling 'Store' with a new credential that is a PSL match for an existing // Calling 'Store' with a new credential that is a PSL match for an existing
// credential but has a different password should prompt the user and not // credential but has a different password should prompt the user and not
// result in a silent save. // result in a silent save.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(1)); .Times(testing::Exactly(1));
EXPECT_CALL(*client_, NotifyStorePasswordCalled()); EXPECT_CALL(*client_, NotifyStorePasswordCalled());
...@@ -638,7 +640,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) { ...@@ -638,7 +640,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) {
// Calling 'Store' with a credential that matches |form_| should update // Calling 'Store' with a credential that matches |form_| should update
// the credential without prompting the user. // the credential without prompting the user.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
bool called = false; bool called = false;
EXPECT_CALL(*client_, NotifyStorePasswordCalled()); EXPECT_CALL(*client_, NotifyStorePasswordCalled());
CallStore(info, base::BindOnce(&RespondCallback, &called)); CallStore(info, base::BindOnce(&RespondCallback, &called));
...@@ -663,7 +665,7 @@ TEST_P(CredentialManagerImplTest, ...@@ -663,7 +665,7 @@ TEST_P(CredentialManagerImplTest,
// Calling 'Store' with a credential that matches |form_| should update // Calling 'Store' with a credential that matches |form_| should update
// the credential without prompting the user. // the credential without prompting the user.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); auto info = PasswordFormToCredentialInfo(form_);
bool called = false; bool called = false;
EXPECT_CALL(*client_, NotifyStorePasswordCalled()); EXPECT_CALL(*client_, NotifyStorePasswordCalled());
CallStore(info, base::BindOnce(&RespondCallback, &called)); CallStore(info, base::BindOnce(&RespondCallback, &called));
...@@ -712,7 +714,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) { ...@@ -712,7 +714,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) {
TEST_P(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerSignInWithSavingDisabledForCurrentPage) { CredentialManagerSignInWithSavingDisabledForCurrentPage) {
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, IsSavingAndFillingEnabled(form_.url)) EXPECT_CALL(*client_, IsSavingAndFillingEnabled(form_.url))
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
...@@ -1650,7 +1652,7 @@ TEST_P(CredentialManagerImplTest, GetBlockedPasswordCredential) { ...@@ -1650,7 +1652,7 @@ TEST_P(CredentialManagerImplTest, GetBlockedPasswordCredential) {
TEST_P(CredentialManagerImplTest, BlockedPasswordCredential) { TEST_P(CredentialManagerImplTest, BlockedPasswordCredential) {
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)); EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
bool called = false; bool called = false;
CallStore(info, base::BindOnce(&RespondCallback, &called)); CallStore(info, base::BindOnce(&RespondCallback, &called));
// Allow the PasswordFormManager to talk to the password store // Allow the PasswordFormManager to talk to the password store
...@@ -1678,7 +1680,7 @@ TEST_P(CredentialManagerImplTest, BlockedFederatedCredential) { ...@@ -1678,7 +1680,7 @@ TEST_P(CredentialManagerImplTest, BlockedFederatedCredential) {
form_.signon_realm = "federation://example.com/example.com"; form_.signon_realm = "federation://example.com/example.com";
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)); EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); auto info = PasswordFormToCredentialInfo(form_);
bool called = false; bool called = false;
CallStore(info, base::BindOnce(&RespondCallback, &called)); CallStore(info, base::BindOnce(&RespondCallback, &called));
// Allow the PasswordFormManager to talk to the password store // Allow the PasswordFormManager to talk to the password store
...@@ -1709,7 +1711,7 @@ TEST_P(CredentialManagerImplTest, RespecBlockedPasswordCredential) { ...@@ -1709,7 +1711,7 @@ TEST_P(CredentialManagerImplTest, RespecBlockedPasswordCredential) {
blocked_form.signon_realm = blocked_form.url.spec(); blocked_form.signon_realm = blocked_form.url.spec();
store_->AddLogin(blocked_form); store_->AddLogin(blocked_form);
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); auto info = PasswordFormToCredentialInfo(form_);
bool called = false; bool called = false;
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)); EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CallStore(info, base::BindOnce(&RespondCallback, &called)); CallStore(info, base::BindOnce(&RespondCallback, &called));
...@@ -1730,7 +1732,7 @@ TEST_P(CredentialManagerImplTest, RespectBlockedFederatedCredential) { ...@@ -1730,7 +1732,7 @@ TEST_P(CredentialManagerImplTest, RespectBlockedFederatedCredential) {
form_.federation_origin = url::Origin::Create(GURL("https://example.com/")); form_.federation_origin = url::Origin::Create(GURL("https://example.com/"));
form_.password_value = base::string16(); form_.password_value = base::string16();
form_.signon_realm = "federation://example.com/example.com"; form_.signon_realm = "federation://example.com/example.com";
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED); auto info = PasswordFormToCredentialInfo(form_);
bool called = false; bool called = false;
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)); EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CallStore(info, base::BindOnce(&RespondCallback, &called)); CallStore(info, base::BindOnce(&RespondCallback, &called));
...@@ -1783,8 +1785,7 @@ TEST_P(CredentialManagerImplTest, ...@@ -1783,8 +1785,7 @@ TEST_P(CredentialManagerImplTest,
form_.federation_origin = url::Origin::Create(GURL("https://example.com/")); form_.federation_origin = url::Origin::Create(GURL("https://example.com/"));
form_.password_value = base::string16(); form_.password_value = base::string16();
form_.signon_realm = "federation://example.com/example.com"; form_.signon_realm = "federation://example.com/example.com";
CallStore({form_, CredentialType::CREDENTIAL_TYPE_FEDERATED}, CallStore(PasswordFormToCredentialInfo(form_), base::DoNothing());
base::DoNothing());
RunAllPendingTasks(); RunAllPendingTasks();
} }
...@@ -1802,8 +1803,7 @@ TEST_P(CredentialManagerImplTest, StorePasswordCredentialStartsLeakDetection) { ...@@ -1802,8 +1803,7 @@ TEST_P(CredentialManagerImplTest, StorePasswordCredentialStartsLeakDetection) {
Start(form_.url, form_.username_value, form_.password_value)); Start(form_.url, form_.username_value, form_.password_value));
EXPECT_CALL(*weak_factory, TryCreateLeakCheck) EXPECT_CALL(*weak_factory, TryCreateLeakCheck)
.WillOnce(testing::Return(testing::ByMove(std::move(check_instance)))); .WillOnce(testing::Return(testing::ByMove(std::move(check_instance))));
CallStore({form_, CredentialType::CREDENTIAL_TYPE_PASSWORD}, CallStore(PasswordFormToCredentialInfo(form_), base::DoNothing());
base::DoNothing());
RunAllPendingTasks(); RunAllPendingTasks();
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "components/password_manager/core/browser/android_affiliation/affiliated_match_helper.h" #include "components/password_manager/core/browser/android_affiliation/affiliated_match_helper.h"
#include "components/password_manager/core/browser/credential_manager_utils.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h" #include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_form.h" #include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_manager_client.h" #include "components/password_manager/core/browser/password_manager_client.h"
...@@ -241,10 +242,7 @@ void CredentialManagerPendingRequestTask::ProcessForms( ...@@ -241,10 +242,7 @@ void CredentialManagerPendingRequestTask::ProcessForms(
if (can_use_autosignin && !local_results[0]->skip_zero_click && if (can_use_autosignin && !local_results[0]->skip_zero_click &&
!password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( !password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience(
delegate_->client()->GetPrefs())) { delegate_->client()->GetPrefs())) {
CredentialInfo info(*local_results[0], auto info = PasswordFormToCredentialInfo(*local_results[0]);
local_results[0]->federation_origin.opaque()
? CredentialType::CREDENTIAL_TYPE_PASSWORD
: CredentialType::CREDENTIAL_TYPE_FEDERATED);
delegate_->client()->NotifyUserAutoSignin(std::move(local_results), delegate_->client()->NotifyUserAutoSignin(std::move(local_results),
origin_); origin_);
base::RecordAction(base::UserMetricsAction("CredentialManager_Autosignin")); base::RecordAction(base::UserMetricsAction("CredentialManager_Autosignin"));
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/password_manager/core/browser/credential_manager_utils.h"
#include <memory>
#include "base/optional.h"
#include "base/strings/string16.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace password_manager {
std::unique_ptr<PasswordForm> CreatePasswordFormFromCredentialInfo(
const CredentialInfo& info,
const url::Origin& origin) {
std::unique_ptr<PasswordForm> form;
if (info.type == CredentialType::CREDENTIAL_TYPE_EMPTY)
return form;
form = std::make_unique<PasswordForm>();
form->icon_url = info.icon;
form->display_name = info.name.value_or(base::string16());
form->federation_origin = info.federation;
form->url = origin.GetURL();
form->password_value = info.password.value_or(base::string16());
form->username_value = info.id.value_or(base::string16());
form->scheme = PasswordForm::Scheme::kHtml;
form->type = PasswordForm::Type::kApi;
form->signon_realm =
info.type == CredentialType::CREDENTIAL_TYPE_PASSWORD
? form->url.spec()
: "federation://" + origin.host() + "/" + info.federation.host();
return form;
}
CredentialInfo PasswordFormToCredentialInfo(const PasswordForm& form) {
return CredentialInfo(form.federation_origin.opaque()
? CredentialType::CREDENTIAL_TYPE_PASSWORD
: CredentialType::CREDENTIAL_TYPE_FEDERATED,
form.username_value, form.display_name, form.icon_url,
form.password_value, form.federation_origin);
}
} // namespace password_manager
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_CREDENTIAL_MANAGER_UTILS_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_CREDENTIAL_MANAGER_UTILS_H_
#include <memory>
#include "components/password_manager/core/browser/password_form_forward.h"
namespace url {
class Origin;
} // namespace url
namespace password_manager {
struct CredentialInfo;
// Create a new PasswordForm object based on |info|, valid in the
// context of |origin|. Returns an empty std::unique_ptr for
// CREDENTIAL_TYPE_EMPTY.
std::unique_ptr<PasswordForm> CreatePasswordFormFromCredentialInfo(
const CredentialInfo& info,
const url::Origin& origin);
// Creates a CredentialInfo object from `form`.
CredentialInfo PasswordFormToCredentialInfo(const PasswordForm& form);
} // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_CREDENTIAL_MANAGER_UTILS_H_
// Copyright 2015 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// 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 "components/password_manager/core/common/credential_manager_types.h" #include "components/password_manager/core/browser/credential_manager_utils.h"
#include <memory>
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/common/password_form.h" #include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h" #include "url/origin.h"
namespace password_manager { namespace password_manager {
class CredentialManagerTypesTest : public testing::Test { class CredentialManagerUtilsTest : public testing::Test {
public:
CredentialManagerTypesTest()
: origin_(url::Origin::Create(GURL("https://example.test/"))),
icon_(GURL("https://fast-cdn.test/icon.png")),
federation_(url::Origin::Create(GURL("https://federation.test/"))) {}
protected: protected:
url::Origin origin_; url::Origin origin_{url::Origin::Create(GURL("https://example.test/"))};
GURL icon_; GURL icon_{"https://fast-cdn.test/icon.png"};
url::Origin federation_; url::Origin federation_{
url::Origin::Create(GURL("https://federation.test/"))};
}; };
TEST_F(CredentialManagerTypesTest, CreatePasswordFormEmpty) { TEST_F(CredentialManagerUtilsTest, CreatePasswordFormEmpty) {
CredentialInfo info; CredentialInfo info;
std::unique_ptr<autofill::PasswordForm> form; std::unique_ptr<PasswordForm> form;
// Empty CredentialInfo -> nullptr. // Empty CredentialInfo -> nullptr.
form = CreatePasswordFormFromCredentialInfo(info, origin_); form = CreatePasswordFormFromCredentialInfo(info, origin_);
EXPECT_EQ(nullptr, form.get()); EXPECT_EQ(nullptr, form.get());
} }
TEST_F(CredentialManagerTypesTest, CreatePasswordFormFederation) { TEST_F(CredentialManagerUtilsTest, CreatePasswordFormFederation) {
CredentialInfo info; CredentialInfo info;
std::unique_ptr<autofill::PasswordForm> form; std::unique_ptr<PasswordForm> form;
info.id = base::ASCIIToUTF16("id"); info.id = base::ASCIIToUTF16("id");
info.name = base::ASCIIToUTF16("name"); info.name = base::ASCIIToUTF16("name");
...@@ -48,11 +46,11 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormFederation) { ...@@ -48,11 +46,11 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormFederation) {
form = CreatePasswordFormFromCredentialInfo(info, origin_); form = CreatePasswordFormFromCredentialInfo(info, origin_);
ASSERT_NE(nullptr, form.get()); ASSERT_NE(nullptr, form.get());
EXPECT_EQ(autofill::PasswordForm::Type::kApi, form->type); EXPECT_EQ(PasswordForm::Type::kApi, form->type);
EXPECT_EQ(info.icon, form->icon_url); EXPECT_EQ(info.icon, form->icon_url);
EXPECT_EQ(info.name, form->display_name); EXPECT_EQ(info.name, form->display_name);
EXPECT_EQ(origin_.GetURL(), form->url); EXPECT_EQ(origin_.GetURL(), form->url);
EXPECT_EQ(autofill::PasswordForm::Scheme::kHtml, form->scheme); EXPECT_EQ(PasswordForm::Scheme::kHtml, form->scheme);
// Federated credentials have empty passwords, non-empty federation_origins, // Federated credentials have empty passwords, non-empty federation_origins,
// and funky signon realms. // and funky signon realms.
...@@ -61,9 +59,9 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormFederation) { ...@@ -61,9 +59,9 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormFederation) {
EXPECT_EQ("federation://example.test/federation.test", form->signon_realm); EXPECT_EQ("federation://example.test/federation.test", form->signon_realm);
} }
TEST_F(CredentialManagerTypesTest, CreatePasswordFormLocal) { TEST_F(CredentialManagerUtilsTest, CreatePasswordFormLocal) {
CredentialInfo info; CredentialInfo info;
std::unique_ptr<autofill::PasswordForm> form; std::unique_ptr<PasswordForm> form;
info.id = base::ASCIIToUTF16("id"); info.id = base::ASCIIToUTF16("id");
info.name = base::ASCIIToUTF16("name"); info.name = base::ASCIIToUTF16("name");
...@@ -77,7 +75,7 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormLocal) { ...@@ -77,7 +75,7 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormLocal) {
EXPECT_EQ(info.icon, form->icon_url); EXPECT_EQ(info.icon, form->icon_url);
EXPECT_EQ(info.name, form->display_name); EXPECT_EQ(info.name, form->display_name);
EXPECT_EQ(origin_.GetURL().spec(), form->url); EXPECT_EQ(origin_.GetURL().spec(), form->url);
EXPECT_EQ(autofill::PasswordForm::Scheme::kHtml, form->scheme); EXPECT_EQ(PasswordForm::Scheme::kHtml, form->scheme);
// Local credentials have empty federation_origins, non-empty passwords, and // Local credentials have empty federation_origins, non-empty passwords, and
// a signon realm that matches the origin. // a signon realm that matches the origin.
......
...@@ -28,21 +28,19 @@ static_library("common") { ...@@ -28,21 +28,19 @@ static_library("common") {
] ]
} }
source_set("unit_tests") { if (is_ios) {
testonly = true source_set("unit_tests") {
sources = [ "credential_manager_types_unittest.cc" ] testonly = true
sources = [ "passwords_directory_util_ios_unittest.cc" ]
if (is_ios) { deps = [
sources += [ "passwords_directory_util_ios_unittest.cc" ] ":common",
"//base",
"//base/test:test_support",
"//components/autofill/core/common",
"//sql",
"//testing/gtest",
"//url",
]
} }
deps = [
":common",
"//base",
"//base/test:test_support",
"//components/autofill/core/common",
"//sql",
"//testing/gtest",
"//url",
]
} }
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <memory> #include <memory>
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "components/autofill/core/common/password_form.h"
namespace password_manager { namespace password_manager {
...@@ -31,15 +30,19 @@ std::ostream& operator<<(std::ostream& os, CredentialType value) { ...@@ -31,15 +30,19 @@ std::ostream& operator<<(std::ostream& os, CredentialType value) {
CredentialInfo::CredentialInfo() : type(CredentialType::CREDENTIAL_TYPE_EMPTY) { CredentialInfo::CredentialInfo() : type(CredentialType::CREDENTIAL_TYPE_EMPTY) {
} }
CredentialInfo::CredentialInfo(const autofill::PasswordForm& form, CredentialInfo::CredentialInfo(CredentialType type,
CredentialType form_type) base::Optional<base::string16> id,
: type(form_type), base::Optional<base::string16> name,
id(form.username_value), GURL icon,
name(form.display_name), base::Optional<base::string16> password,
icon(form.icon_url), url::Origin federation)
password(form.password_value), : type(type),
federation(form.federation_origin) { id(std::move(id)),
switch (form_type) { name(std::move(name)),
icon(std::move(icon)),
password(std::move(password)),
federation(std::move(federation)) {
switch (type) {
case CredentialType::CREDENTIAL_TYPE_EMPTY: case CredentialType::CREDENTIAL_TYPE_EMPTY:
password = base::string16(); password = base::string16();
federation = url::Origin(); federation = url::Origin();
...@@ -63,28 +66,4 @@ bool CredentialInfo::operator==(const CredentialInfo& rhs) const { ...@@ -63,28 +66,4 @@ bool CredentialInfo::operator==(const CredentialInfo& rhs) const {
federation.Serialize() == rhs.federation.Serialize()); federation.Serialize() == rhs.federation.Serialize());
} }
std::unique_ptr<autofill::PasswordForm> CreatePasswordFormFromCredentialInfo(
const CredentialInfo& info,
const url::Origin& origin) {
std::unique_ptr<autofill::PasswordForm> form;
if (info.type == CredentialType::CREDENTIAL_TYPE_EMPTY)
return form;
form = std::make_unique<autofill::PasswordForm>();
form->icon_url = info.icon;
form->display_name = info.name.value_or(base::string16());
form->federation_origin = info.federation;
form->url = origin.GetURL();
form->password_value = info.password.value_or(base::string16());
form->username_value = info.id.value_or(base::string16());
form->scheme = autofill::PasswordForm::Scheme::kHtml;
form->type = autofill::PasswordForm::Type::kApi;
form->signon_realm =
info.type == CredentialType::CREDENTIAL_TYPE_PASSWORD
? form->url.spec()
: "federation://" + origin.host() + "/" + info.federation.host();
return form;
}
} // namespace password_manager } // namespace password_manager
...@@ -17,10 +17,6 @@ ...@@ -17,10 +17,6 @@
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h" #include "url/origin.h"
namespace autofill {
struct PasswordForm;
}
namespace password_manager { namespace password_manager {
// Limit the size of the federations array that we pass to the browser to // Limit the size of the federations array that we pass to the browser to
...@@ -48,7 +44,13 @@ std::ostream& operator<<(std::ostream& os, CredentialType value); ...@@ -48,7 +44,13 @@ std::ostream& operator<<(std::ostream& os, CredentialType value);
struct CredentialInfo { struct CredentialInfo {
CredentialInfo(); CredentialInfo();
CredentialInfo(const autofill::PasswordForm& form, CredentialType form_type); CredentialInfo(CredentialType type,
base::Optional<base::string16> id,
base::Optional<base::string16> name,
GURL icon,
base::Optional<base::string16> password,
url::Origin federation);
CredentialInfo(const CredentialInfo& other); CredentialInfo(const CredentialInfo& other);
~CredentialInfo(); ~CredentialInfo();
...@@ -75,13 +77,6 @@ struct CredentialInfo { ...@@ -75,13 +77,6 @@ struct CredentialInfo {
url::Origin federation; url::Origin federation;
}; };
// Create a new autofill::PasswordForm object based on |info|, valid in the
// context of |origin|. Returns an empty std::unique_ptr for
// CREDENTIAL_TYPE_EMPTY.
std::unique_ptr<autofill::PasswordForm> CreatePasswordFormFromCredentialInfo(
const CredentialInfo& info,
const url::Origin& origin);
} // namespace password_manager } // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_COMMON_CREDENTIAL_MANAGER_TYPES_H_ #endif // COMPONENTS_PASSWORD_MANAGER_CORE_COMMON_CREDENTIAL_MANAGER_TYPES_H_
...@@ -32,7 +32,6 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -32,7 +32,6 @@ NS_ASSUME_NONNULL_BEGIN
using autofill::FieldRendererId; using autofill::FieldRendererId;
using autofill::FormData; using autofill::FormData;
using autofill::FormRendererId; using autofill::FormRendererId;
using autofill::PasswordForm;
using autofill::PasswordFormFillData; using autofill::PasswordFormFillData;
using base::test::ios::kWaitForJSCompletionTimeout; using base::test::ios::kWaitForJSCompletionTimeout;
using base::test::ios::WaitUntilConditionOrTimeout; using base::test::ios::WaitUntilConditionOrTimeout;
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "components/autofill/core/browser/ui/popup_item_ids.h" #include "components/autofill/core/browser/ui/popup_item_ids.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_data.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/renderer_id.h" #include "components/autofill/core/common/renderer_id.h"
...@@ -56,7 +55,6 @@ ...@@ -56,7 +55,6 @@
using autofill::FormActivityObserverBridge; using autofill::FormActivityObserverBridge;
using autofill::FormData; using autofill::FormData;
using autofill::PasswordFormGenerationData; using autofill::PasswordFormGenerationData;
using autofill::PasswordForm;
using autofill::FormRendererId; using autofill::FormRendererId;
using autofill::FieldRendererId; using autofill::FieldRendererId;
using base::SysNSStringToUTF16; using base::SysNSStringToUTF16;
......
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