Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Unified Diff: components/password_manager/content/browser/credential_manager_impl.cc

Issue 1866643002: Reland: Switch components/password_manager code from IPC messages to Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase only Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/password_manager/content/browser/credential_manager_impl.cc
diff --git a/components/password_manager/content/browser/credential_manager_dispatcher.cc b/components/password_manager/content/browser/credential_manager_impl.cc
similarity index 59%
rename from components/password_manager/content/browser/credential_manager_dispatcher.cc
rename to components/password_manager/content/browser/credential_manager_impl.cc
index 6f6780cfb2e3beafcf5e7d759101f66b9acef537..0d5fa0d157a4a922783cee439c3e69248f53a4c9 100644
--- a/components/password_manager/content/browser/credential_manager_dispatcher.cc
+++ b/components/password_manager/content/browser/credential_manager_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/password_manager/content/browser/credential_manager_dispatcher.h"
+#include "components/password_manager/content/browser/credential_manager_impl.h"
#include <utility>
@@ -12,68 +12,65 @@
#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_factory.h"
-#include "components/password_manager/content/common/credential_manager_messages.h"
+#include "components/password_manager/content/public/cpp/type_converters.h"
#include "components/password_manager/core/browser/affiliated_match_helper.h"
#include "components/password_manager/core/browser/password_manager_client.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
-#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
-#include "ipc/ipc_message_macros.h"
+#include "mojo/common/url_type_converters.h"
namespace password_manager {
-// CredentialManagerDispatcher -------------------------------------------------
+namespace {
-CredentialManagerDispatcher::CredentialManagerDispatcher(
- content::WebContents* web_contents,
- PasswordManagerClient* client)
+void RunMojoGetCallback(const mojom::CredentialManager::GetCallback& callback,
+ const CredentialInfo& info) {
+ mojom::CredentialInfoPtr credential = mojom::CredentialInfo::From(info);
+ callback.Run(mojom::CredentialManagerError::SUCCESS, std::move(credential));
+}
+
+} // namespace
+
+// CredentialManagerImpl -------------------------------------------------
+
+CredentialManagerImpl::CredentialManagerImpl(content::WebContents* web_contents,
+ PasswordManagerClient* client)
: WebContentsObserver(web_contents), client_(client), weak_factory_(this) {
DCHECK(web_contents);
auto_signin_enabled_.Init(prefs::kCredentialsEnableAutosignin,
client_->GetPrefs());
}
-CredentialManagerDispatcher::~CredentialManagerDispatcher() {
-}
+CredentialManagerImpl::~CredentialManagerImpl() {}
-bool CredentialManagerDispatcher::OnMessageReceived(
- const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(CredentialManagerDispatcher, message)
- IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_Store, OnStore);
- IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_RequireUserMediation,
- OnRequireUserMediation);
- IPC_MESSAGE_HANDLER(CredentialManagerHostMsg_RequestCredential,
- OnRequestCredential);
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
+void CredentialManagerImpl::BindRequest(
+ mojom::CredentialManagerRequest request) {
+ bindings_.AddBinding(this, std::move(request));
}
-void CredentialManagerDispatcher::OnStore(
- int request_id,
- const password_manager::CredentialInfo& credential) {
- DCHECK(credential.type != CredentialType::CREDENTIAL_TYPE_EMPTY);
- DCHECK(request_id);
- web_contents()->GetRenderViewHost()->Send(
- new CredentialManagerMsg_AcknowledgeStore(
- web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
+void CredentialManagerImpl::Store(mojom::CredentialInfoPtr credential,
+ const StoreCallback& callback) {
+ CredentialInfo info = credential.To<CredentialInfo>();
+ DCHECK_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, info.type);
+
+ // Send acknowledge response back.
+ callback.Run();
if (!client_->IsSavingAndFillingEnabledForCurrentPage())
return;
std::unique_ptr<autofill::PasswordForm> form(
CreatePasswordFormFromCredentialInfo(
- credential, web_contents()->GetLastCommittedURL().GetOrigin()));
+ info, web_contents()->GetLastCommittedURL().GetOrigin()));
form->skip_zero_click = !IsZeroClickAllowed();
form_manager_.reset(new CredentialManagerPasswordFormManager(
client_, GetDriver(), *form, this));
}
-void CredentialManagerDispatcher::OnProvisionalSaveComplete() {
+void CredentialManagerImpl::OnProvisionalSaveComplete() {
DCHECK(form_manager_);
DCHECK(client_->IsSavingAndFillingEnabledForCurrentPage());
const autofill::PasswordForm& form = form_manager_->pending_credentials();
@@ -105,30 +102,27 @@ void CredentialManagerDispatcher::OnProvisionalSaveComplete() {
false);
}
-void CredentialManagerDispatcher::OnRequireUserMediation(int request_id) {
- DCHECK(request_id);
-
+void CredentialManagerImpl::RequireUserMediation(
+ const RequireUserMediationCallback& callback) {
PasswordStore* store = GetPasswordStore();
if (!store || !IsUpdatingCredentialAllowed()) {
- web_contents()->GetRenderViewHost()->Send(
- new CredentialManagerMsg_AcknowledgeRequireUserMediation(
- web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
+ callback.Run();
return;
}
if (store->affiliated_match_helper()) {
store->affiliated_match_helper()->GetAffiliatedAndroidRealms(
GetSynthesizedFormForOrigin(),
- base::Bind(&CredentialManagerDispatcher::ScheduleRequireMediationTask,
- weak_factory_.GetWeakPtr(), request_id));
+ base::Bind(&CredentialManagerImpl::ScheduleRequireMediationTask,
+ weak_factory_.GetWeakPtr(), callback));
} else {
std::vector<std::string> no_affiliated_realms;
- ScheduleRequireMediationTask(request_id, no_affiliated_realms);
+ ScheduleRequireMediationTask(callback, no_affiliated_realms);
}
}
-void CredentialManagerDispatcher::ScheduleRequireMediationTask(
- int request_id,
+void CredentialManagerImpl::ScheduleRequireMediationTask(
+ const RequireUserMediationCallback& callback,
const std::vector<std::string>& android_realms) {
DCHECK(GetPasswordStore());
if (!pending_require_user_mediation_) {
@@ -138,7 +132,8 @@ void CredentialManagerDispatcher::ScheduleRequireMediationTask(
android_realms));
// This will result in a callback to
- // CredentialManagerPendingRequireUserMediationTask::OnGetPasswordStoreResults().
+ // CredentialManagerPendingRequireUserMediationTask::
+ // OnGetPasswordStoreResults().
GetPasswordStore()->GetAutofillableLogins(
pending_require_user_mediation_.get());
} else {
@@ -146,25 +141,21 @@ void CredentialManagerDispatcher::ScheduleRequireMediationTask(
web_contents()->GetLastCommittedURL().GetOrigin());
}
- web_contents()->GetRenderViewHost()->Send(
- new CredentialManagerMsg_AcknowledgeRequireUserMediation(
- web_contents()->GetRenderViewHost()->GetRoutingID(), request_id));
+ // Send acknowledge response back.
+ callback.Run();
}
-void CredentialManagerDispatcher::OnRequestCredential(
- int request_id,
- bool zero_click_only,
- bool include_passwords,
- const std::vector<GURL>& federations) {
- DCHECK(request_id);
+void CredentialManagerImpl::Get(bool zero_click_only,
+ bool include_passwords,
+ mojo::Array<mojo::String> federations,
+ const GetCallback& callback) {
PasswordStore* store = GetPasswordStore();
if (pending_request_ || !store) {
- web_contents()->GetRenderViewHost()->Send(
- new CredentialManagerMsg_RejectCredentialRequest(
- web_contents()->GetRenderViewHost()->GetRoutingID(), request_id,
- pending_request_
- ? blink::WebCredentialManagerPendingRequestError
- : blink::WebCredentialManagerPasswordStoreUnavailableError));
+ // Callback error.
+ callback.Run(pending_request_
+ ? mojom::CredentialManagerError::PENDINGREQUEST
+ : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE,
+ nullptr);
return;
}
@@ -172,35 +163,35 @@ void CredentialManagerDispatcher::OnRequestCredential(
// the current page has TLS errors.
if ((zero_click_only && !IsZeroClickAllowed()) ||
client_->DidLastPageLoadEncounterSSLErrors()) {
- web_contents()->GetRenderViewHost()->Send(
- new CredentialManagerMsg_SendCredential(
- web_contents()->GetRenderViewHost()->GetRoutingID(), request_id,
- CredentialInfo()));
+ // Callback with empty credential info.
+ callback.Run(mojom::CredentialManagerError::SUCCESS,
+ mojom::CredentialInfo::New());
return;
}
if (store->affiliated_match_helper()) {
store->affiliated_match_helper()->GetAffiliatedAndroidRealms(
GetSynthesizedFormForOrigin(),
- base::Bind(&CredentialManagerDispatcher::ScheduleRequestTask,
- weak_factory_.GetWeakPtr(), request_id, zero_click_only,
- include_passwords, federations));
+ base::Bind(&CredentialManagerImpl::ScheduleRequestTask,
+ weak_factory_.GetWeakPtr(), callback, zero_click_only,
+ include_passwords, federations.To<std::vector<GURL>>()));
} else {
std::vector<std::string> no_affiliated_realms;
- ScheduleRequestTask(request_id, zero_click_only, include_passwords,
- federations, no_affiliated_realms);
+ ScheduleRequestTask(callback, zero_click_only, include_passwords,
+ federations.To<std::vector<GURL>>(),
+ no_affiliated_realms);
}
}
-void CredentialManagerDispatcher::ScheduleRequestTask(
- int request_id,
+void CredentialManagerImpl::ScheduleRequestTask(
+ const GetCallback& callback,
bool zero_click_only,
bool include_passwords,
const std::vector<GURL>& federations,
const std::vector<std::string>& android_realms) {
DCHECK(GetPasswordStore());
pending_request_.reset(new CredentialManagerPendingRequestTask(
- this, request_id, zero_click_only,
+ this, base::Bind(&RunMojoGetCallback, callback), zero_click_only,
web_contents()->GetLastCommittedURL().GetOrigin(), include_passwords,
federations, android_realms));
@@ -209,19 +200,19 @@ void CredentialManagerDispatcher::ScheduleRequestTask(
GetPasswordStore()->GetAutofillableLogins(pending_request_.get());
}
-PasswordStore* CredentialManagerDispatcher::GetPasswordStore() {
+PasswordStore* CredentialManagerImpl::GetPasswordStore() {
return client_ ? client_->GetPasswordStore() : nullptr;
}
-bool CredentialManagerDispatcher::IsZeroClickAllowed() const {
+bool CredentialManagerImpl::IsZeroClickAllowed() const {
return *auto_signin_enabled_ && !client_->IsOffTheRecord();
}
-GURL CredentialManagerDispatcher::GetOrigin() const {
+GURL CredentialManagerImpl::GetOrigin() const {
return web_contents()->GetLastCommittedURL().GetOrigin();
}
-base::WeakPtr<PasswordManagerDriver> CredentialManagerDispatcher::GetDriver() {
+base::WeakPtr<PasswordManagerDriver> CredentialManagerImpl::GetDriver() {
ContentPasswordManagerDriverFactory* driver_factory =
ContentPasswordManagerDriverFactory::FromWebContents(web_contents());
DCHECK(driver_factory);
@@ -230,20 +221,18 @@ base::WeakPtr<PasswordManagerDriver> CredentialManagerDispatcher::GetDriver() {
return driver->AsWeakPtr();
}
-void CredentialManagerDispatcher::SendCredential(int request_id,
- const CredentialInfo& info) {
+void CredentialManagerImpl::SendCredential(
+ const SendCredentialCallback& send_callback,
+ const CredentialInfo& info) {
DCHECK(pending_request_);
- DCHECK_EQ(pending_request_->id(), request_id);
+ DCHECK(send_callback.Equals(pending_request_->send_callback()));
- web_contents()->GetRenderViewHost()->Send(
- new CredentialManagerMsg_SendCredential(
- web_contents()->GetRenderViewHost()->GetRoutingID(),
- pending_request_->id(), info));
+ send_callback.Run(info);
pending_request_.reset();
}
-void CredentialManagerDispatcher::SendPasswordForm(
- int request_id,
+void CredentialManagerImpl::SendPasswordForm(
+ const SendCredentialCallback& send_callback,
const autofill::PasswordForm* form) {
CredentialInfo info;
if (form) {
@@ -261,15 +250,15 @@ void CredentialManagerDispatcher::SendPasswordForm(
}
}
}
- SendCredential(request_id, info);
+ SendCredential(send_callback, info);
}
-PasswordManagerClient* CredentialManagerDispatcher::client() const {
+PasswordManagerClient* CredentialManagerImpl::client() const {
return client_;
}
-autofill::PasswordForm
-CredentialManagerDispatcher::GetSynthesizedFormForOrigin() const {
+autofill::PasswordForm CredentialManagerImpl::GetSynthesizedFormForOrigin()
+ const {
autofill::PasswordForm synthetic_form;
synthetic_form.origin = web_contents()->GetLastCommittedURL().GetOrigin();
synthetic_form.signon_realm = synthetic_form.origin.spec();
@@ -279,12 +268,12 @@ CredentialManagerDispatcher::GetSynthesizedFormForOrigin() const {
return synthetic_form;
}
-void CredentialManagerDispatcher::DoneRequiringUserMediation() {
+void CredentialManagerImpl::DoneRequiringUserMediation() {
DCHECK(pending_require_user_mediation_);
pending_require_user_mediation_.reset();
}
-bool CredentialManagerDispatcher::IsUpdatingCredentialAllowed() const {
+bool CredentialManagerImpl::IsUpdatingCredentialAllowed() const {
return !client_->DidLastPageLoadEncounterSSLErrors() &&
!client_->IsOffTheRecord();
}

Powered by Google App Engine
This is Rietveld 408576698