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") {
"//components/openscreen_platform:unittests",
"//components/os_crypt:unit_tests",
"//components/password_manager/core/browser:unit_tests",
"//components/password_manager/core/common:unit_tests",
"//components/payments/core:unit_tests",
"//components/policy/core/browser:unit_tests",
"//components/policy/core/common:unit_tests",
......@@ -212,6 +211,7 @@ test("components_unittests") {
"//components/autofill/ios/form_util:unit_tests",
"//components/image_fetcher/ios:unit_tests",
"//components/language/ios/browser:unit_tests",
"//components/password_manager/core/common:unit_tests",
"//components/password_manager/ios:unit_tests",
"//components/safe_browsing/ios:unit_tests",
"//components/security_state/ios:unit_tests",
......
......@@ -7,7 +7,7 @@
#include "base/logging.h"
#include "base/metrics/histogram_functions.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/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
......@@ -55,10 +55,9 @@ bool CheckChildProcessSecurityPolicyForURL(content::RenderFrameHost* frame,
return true;
}
bool CheckChildProcessSecurityPolicy(
content::RenderFrameHost* frame,
const autofill::PasswordForm& password_form,
BadMessageReason reason) {
bool CheckChildProcessSecurityPolicy(content::RenderFrameHost* frame,
const PasswordForm& password_form,
BadMessageReason reason) {
return CheckChildProcessSecurityPolicyForURL(frame, password_form.url,
reason) &&
CheckChildProcessSecurityPolicyForURL(
......@@ -67,10 +66,9 @@ bool CheckChildProcessSecurityPolicy(
frame, password_form.form_data.url, reason);
}
bool CheckChildProcessSecurityPolicy(
content::RenderFrameHost* frame,
const std::vector<autofill::PasswordForm>& forms,
BadMessageReason reason) {
bool CheckChildProcessSecurityPolicy(content::RenderFrameHost* frame,
const std::vector<PasswordForm>& forms,
BadMessageReason reason) {
for (const auto& form : forms) {
if (!bad_message::CheckChildProcessSecurityPolicy(frame, form, reason))
return false;
......
......@@ -7,10 +7,7 @@
#include <vector>
#include "components/autofill/core/common/form_data.h"
namespace autofill {
struct PasswordForm;
}
#include "components/password_manager/core/browser/password_form_forward.h"
namespace content {
class RenderFrameHost;
......@@ -61,17 +58,15 @@ bool CheckChildProcessSecurityPolicyForURL(content::RenderFrameHost* frame,
// on |password_form|. If the origin mismatches, the process for |frame| is
// terminated and the function returns false.
// TODO: Delete this signature after transferring all driver calls to FormData
bool CheckChildProcessSecurityPolicy(
content::RenderFrameHost* frame,
const autofill::PasswordForm& password_form,
BadMessageReason reason);
bool CheckChildProcessSecurityPolicy(content::RenderFrameHost* frame,
const PasswordForm& password_form,
BadMessageReason reason);
// Same as above but checks every form in |forms|.
// TODO: Delete this signature after transferring all driver calls to FormData
bool CheckChildProcessSecurityPolicy(
content::RenderFrameHost* frame,
const std::vector<autofill::PasswordForm>& forms,
BadMessageReason reason);
bool CheckChildProcessSecurityPolicy(content::RenderFrameHost* frame,
const std::vector<PasswordForm>& forms,
BadMessageReason reason);
bool CheckChildProcessSecurityPolicy(
content::RenderFrameHost* frame,
......
......@@ -11,7 +11,6 @@
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/core/browser/logging/log_manager.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/content_password_manager_driver_factory.h"
#include "components/password_manager/core/browser/password_manager.h"
......
......@@ -12,7 +12,6 @@
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.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/form_submission_tracker_util.h"
#include "components/password_manager/core/browser/password_manager_client.h"
......
......@@ -29,7 +29,6 @@
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
using autofill::ParsingResult;
using autofill::PasswordForm;
using autofill::PasswordFormFillData;
using base::ASCIIToUTF16;
using testing::_;
......
......@@ -79,6 +79,8 @@ static_library("browser") {
"credential_manager_pending_prevent_silent_access_task.h",
"credential_manager_pending_request_task.cc",
"credential_manager_pending_request_task.h",
"credential_manager_utils.cc",
"credential_manager_utils.h",
"credentials_cleaner.cc",
"credentials_cleaner.h",
"credentials_cleaner_runner.cc",
......@@ -598,6 +600,7 @@ source_set("unit_tests") {
"credential_manager_password_form_manager_unittest.cc",
"credential_manager_pending_prevent_silent_access_task_unittest.cc",
"credential_manager_pending_request_task_unittest.cc",
"credential_manager_utils_unittest.cc",
"credentials_cleaner_runner_unittest.cc",
"credentials_cleaner_unittest.cc",
"export/csv_writer_unittest.cc",
......
......@@ -10,6 +10,8 @@
#include "base/bind.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_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_saver.h"
#include "components/password_manager/core/browser/password_manager_util.h"
......@@ -197,11 +199,7 @@ void CredentialManagerImpl::SendPasswordForm(
const PasswordForm* form) {
CredentialInfo info;
if (form) {
password_manager::CredentialType type_to_return =
form->federation_origin.opaque()
? CredentialType::CREDENTIAL_TYPE_PASSWORD
: CredentialType::CREDENTIAL_TYPE_FEDERATED;
info = CredentialInfo(*form, type_to_return);
info = PasswordFormToCredentialInfo(*form);
PasswordStore* store = form->IsUsingAccountStore()
? GetAccountPasswordStore()
: GetProfilePasswordStore();
......
......@@ -22,6 +22,8 @@
#include "base/test/task_environment.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/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_factory.h"
#include "components/password_manager/core/browser/leak_detection/mock_leak_detection_check_factory.h"
......@@ -410,7 +412,7 @@ TEST_P(CredentialManagerImplTest, IsZeroClickAllowed) {
}
TEST_P(CredentialManagerImplTest, CredentialManagerOnStore) {
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(1));
EXPECT_CALL(*client_, NotifyStorePasswordCalled());
......@@ -445,7 +447,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerOnStoreFederated) {
form_.federation_origin = url::Origin::Create(GURL("https://google.com/"));
form_.password_value = base::string16();
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));
// Allow the PasswordFormManager to talk to the password store, determine
......@@ -476,7 +478,7 @@ TEST_P(CredentialManagerImplTest, StoreFederatedAfterPassword) {
federated.federation_origin =
url::Origin::Create(GURL("https://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_, NotifyStorePasswordCalled());
......@@ -513,7 +515,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerStoreOverwrite) {
// Calling 'Store' with a credential that matches |form_| should update
// 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.name = base::ASCIIToUTF16("New Name");
info.icon = GURL("https://example.com/icon.png");
......@@ -551,7 +553,7 @@ TEST_P(CredentialManagerImplTest,
// 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
// save without prompting the user.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(0));
EXPECT_CALL(*client_, NotifyStorePasswordCalled());
......@@ -578,7 +580,7 @@ TEST_P(CredentialManagerImplTest,
// 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
// result in a silent save.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(1));
EXPECT_CALL(*client_, NotifyStorePasswordCalled());
......@@ -610,7 +612,7 @@ TEST_P(CredentialManagerImplTest,
// 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
// result in a silent save.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(1));
EXPECT_CALL(*client_, NotifyStorePasswordCalled());
......@@ -638,7 +640,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) {
// Calling 'Store' with a credential that matches |form_| should update
// the credential without prompting the user.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
auto info = PasswordFormToCredentialInfo(form_);
bool called = false;
EXPECT_CALL(*client_, NotifyStorePasswordCalled());
CallStore(info, base::BindOnce(&RespondCallback, &called));
......@@ -663,7 +665,7 @@ TEST_P(CredentialManagerImplTest,
// Calling 'Store' with a credential that matches |form_| should update
// the credential without prompting the user.
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
auto info = PasswordFormToCredentialInfo(form_);
bool called = false;
EXPECT_CALL(*client_, NotifyStorePasswordCalled());
CallStore(info, base::BindOnce(&RespondCallback, &called));
......@@ -712,7 +714,7 @@ TEST_P(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) {
TEST_P(CredentialManagerImplTest,
CredentialManagerSignInWithSavingDisabledForCurrentPage) {
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
auto info = PasswordFormToCredentialInfo(form_);
EXPECT_CALL(*client_, IsSavingAndFillingEnabled(form_.url))
.WillRepeatedly(testing::Return(false));
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
......@@ -1650,7 +1652,7 @@ TEST_P(CredentialManagerImplTest, GetBlockedPasswordCredential) {
TEST_P(CredentialManagerImplTest, BlockedPasswordCredential) {
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
auto info = PasswordFormToCredentialInfo(form_);
bool called = false;
CallStore(info, base::BindOnce(&RespondCallback, &called));
// Allow the PasswordFormManager to talk to the password store
......@@ -1678,7 +1680,7 @@ TEST_P(CredentialManagerImplTest, BlockedFederatedCredential) {
form_.signon_realm = "federation://example.com/example.com";
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
auto info = PasswordFormToCredentialInfo(form_);
bool called = false;
CallStore(info, base::BindOnce(&RespondCallback, &called));
// Allow the PasswordFormManager to talk to the password store
......@@ -1709,7 +1711,7 @@ TEST_P(CredentialManagerImplTest, RespecBlockedPasswordCredential) {
blocked_form.signon_realm = blocked_form.url.spec();
store_->AddLogin(blocked_form);
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
auto info = PasswordFormToCredentialInfo(form_);
bool called = false;
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CallStore(info, base::BindOnce(&RespondCallback, &called));
......@@ -1730,7 +1732,7 @@ TEST_P(CredentialManagerImplTest, RespectBlockedFederatedCredential) {
form_.federation_origin = url::Origin::Create(GURL("https://example.com/"));
form_.password_value = base::string16();
form_.signon_realm = "federation://example.com/example.com";
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_FEDERATED);
auto info = PasswordFormToCredentialInfo(form_);
bool called = false;
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CallStore(info, base::BindOnce(&RespondCallback, &called));
......@@ -1783,8 +1785,7 @@ TEST_P(CredentialManagerImplTest,
form_.federation_origin = url::Origin::Create(GURL("https://example.com/"));
form_.password_value = base::string16();
form_.signon_realm = "federation://example.com/example.com";
CallStore({form_, CredentialType::CREDENTIAL_TYPE_FEDERATED},
base::DoNothing());
CallStore(PasswordFormToCredentialInfo(form_), base::DoNothing());
RunAllPendingTasks();
}
......@@ -1802,8 +1803,7 @@ TEST_P(CredentialManagerImplTest, StorePasswordCredentialStartsLeakDetection) {
Start(form_.url, form_.username_value, form_.password_value));
EXPECT_CALL(*weak_factory, TryCreateLeakCheck)
.WillOnce(testing::Return(testing::ByMove(std::move(check_instance))));
CallStore({form_, CredentialType::CREDENTIAL_TYPE_PASSWORD},
base::DoNothing());
CallStore(PasswordFormToCredentialInfo(form_), base::DoNothing());
RunAllPendingTasks();
}
......
......@@ -17,6 +17,7 @@
#include "base/metrics/user_metrics.h"
#include "base/stl_util.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_form.h"
#include "components/password_manager/core/browser/password_manager_client.h"
......@@ -241,10 +242,7 @@ void CredentialManagerPendingRequestTask::ProcessForms(
if (can_use_autosignin && !local_results[0]->skip_zero_click &&
!password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience(
delegate_->client()->GetPrefs())) {
CredentialInfo info(*local_results[0],
local_results[0]->federation_origin.opaque()
? CredentialType::CREDENTIAL_TYPE_PASSWORD
: CredentialType::CREDENTIAL_TYPE_FEDERATED);
auto info = PasswordFormToCredentialInfo(*local_results[0]);
delegate_->client()->NotifyUserAutoSignin(std::move(local_results),
origin_);
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
// 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/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 "url/gurl.h"
#include "url/origin.h"
namespace password_manager {
class CredentialManagerTypesTest : 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/"))) {}
class CredentialManagerUtilsTest : public testing::Test {
protected:
url::Origin origin_;
GURL icon_;
url::Origin federation_;
url::Origin origin_{url::Origin::Create(GURL("https://example.test/"))};
GURL icon_{"https://fast-cdn.test/icon.png"};
url::Origin federation_{
url::Origin::Create(GURL("https://federation.test/"))};
};
TEST_F(CredentialManagerTypesTest, CreatePasswordFormEmpty) {
TEST_F(CredentialManagerUtilsTest, CreatePasswordFormEmpty) {
CredentialInfo info;
std::unique_ptr<autofill::PasswordForm> form;
std::unique_ptr<PasswordForm> form;
// Empty CredentialInfo -> nullptr.
form = CreatePasswordFormFromCredentialInfo(info, origin_);
EXPECT_EQ(nullptr, form.get());
}
TEST_F(CredentialManagerTypesTest, CreatePasswordFormFederation) {
TEST_F(CredentialManagerUtilsTest, CreatePasswordFormFederation) {
CredentialInfo info;
std::unique_ptr<autofill::PasswordForm> form;
std::unique_ptr<PasswordForm> form;
info.id = base::ASCIIToUTF16("id");
info.name = base::ASCIIToUTF16("name");
......@@ -48,11 +46,11 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormFederation) {
form = CreatePasswordFormFromCredentialInfo(info, origin_);
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.name, form->display_name);
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,
// and funky signon realms.
......@@ -61,9 +59,9 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormFederation) {
EXPECT_EQ("federation://example.test/federation.test", form->signon_realm);
}
TEST_F(CredentialManagerTypesTest, CreatePasswordFormLocal) {
TEST_F(CredentialManagerUtilsTest, CreatePasswordFormLocal) {
CredentialInfo info;
std::unique_ptr<autofill::PasswordForm> form;
std::unique_ptr<PasswordForm> form;
info.id = base::ASCIIToUTF16("id");
info.name = base::ASCIIToUTF16("name");
......@@ -77,7 +75,7 @@ TEST_F(CredentialManagerTypesTest, CreatePasswordFormLocal) {
EXPECT_EQ(info.icon, form->icon_url);
EXPECT_EQ(info.name, form->display_name);
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
// a signon realm that matches the origin.
......
......@@ -28,21 +28,19 @@ static_library("common") {
]
}
source_set("unit_tests") {
testonly = true
sources = [ "credential_manager_types_unittest.cc" ]
if (is_ios) {
source_set("unit_tests") {
testonly = true
sources = [ "passwords_directory_util_ios_unittest.cc" ]
if (is_ios) {
sources += [ "passwords_directory_util_ios_unittest.cc" ]
deps = [
":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 @@
#include <memory>
#include "base/strings/string_number_conversions.h"
#include "components/autofill/core/common/password_form.h"
namespace password_manager {
......@@ -31,15 +30,19 @@ std::ostream& operator<<(std::ostream& os, CredentialType value) {
CredentialInfo::CredentialInfo() : type(CredentialType::CREDENTIAL_TYPE_EMPTY) {
}
CredentialInfo::CredentialInfo(const autofill::PasswordForm& form,
CredentialType form_type)
: type(form_type),
id(form.username_value),
name(form.display_name),
icon(form.icon_url),
password(form.password_value),
federation(form.federation_origin) {
switch (form_type) {
CredentialInfo::CredentialInfo(CredentialType type,
base::Optional<base::string16> id,
base::Optional<base::string16> name,
GURL icon,
base::Optional<base::string16> password,
url::Origin federation)
: type(type),
id(std::move(id)),
name(std::move(name)),
icon(std::move(icon)),
password(std::move(password)),
federation(std::move(federation)) {
switch (type) {
case CredentialType::CREDENTIAL_TYPE_EMPTY:
password = base::string16();
federation = url::Origin();
......@@ -63,28 +66,4 @@ bool CredentialInfo::operator==(const CredentialInfo& rhs) const {
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
......@@ -17,10 +17,6 @@
#include "url/gurl.h"
#include "url/origin.h"
namespace autofill {
struct PasswordForm;
}
namespace password_manager {
// 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);
struct 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();
......@@ -75,13 +77,6 @@ struct CredentialInfo {
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
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_COMMON_CREDENTIAL_MANAGER_TYPES_H_
......@@ -32,7 +32,6 @@ NS_ASSUME_NONNULL_BEGIN
using autofill::FieldRendererId;
using autofill::FormData;
using autofill::FormRendererId;
using autofill::PasswordForm;
using autofill::PasswordFormFillData;
using base::test::ios::kWaitForJSCompletionTimeout;
using base::test::ios::WaitUntilConditionOrTimeout;
......
......@@ -22,7 +22,6 @@
#include "components/autofill/core/browser/ui/popup_item_ids.h"
#include "components/autofill/core/common/autofill_features.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_generation_data.h"
#include "components/autofill/core/common/renderer_id.h"
......@@ -56,7 +55,6 @@
using autofill::FormActivityObserverBridge;
using autofill::FormData;
using autofill::PasswordFormGenerationData;
using autofill::PasswordForm;
using autofill::FormRendererId;
using autofill::FieldRendererId;
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