| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/password_manager/content/browser/credential_manager_impl.h" | 5 #include "components/password_manager/content/browser/credential_manager_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "components/password_manager/core/browser/password_manager_util.h" | 23 #include "components/password_manager/core/browser/password_manager_util.h" |
| 24 #include "components/password_manager/core/browser/password_store.h" | 24 #include "components/password_manager/core/browser/password_store.h" |
| 25 #include "components/password_manager/core/common/credential_manager_types.h" | 25 #include "components/password_manager/core/common/credential_manager_types.h" |
| 26 #include "components/password_manager/core/common/password_manager_pref_names.h" | 26 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 | 28 |
| 29 namespace password_manager { | 29 namespace password_manager { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 void RunMojoGetCallback(const mojom::CredentialManager::GetCallback& callback, | 33 void RunMojoGetCallback(mojom::CredentialManager::GetCallback callback, |
| 34 const CredentialInfo& info) { | 34 const CredentialInfo& info) { |
| 35 callback.Run(mojom::CredentialManagerError::SUCCESS, info); | 35 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, info); |
| 36 } | 36 } |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 // CredentialManagerImpl ------------------------------------------------- | 40 // CredentialManagerImpl ------------------------------------------------- |
| 41 | 41 |
| 42 CredentialManagerImpl::CredentialManagerImpl(content::WebContents* web_contents, | 42 CredentialManagerImpl::CredentialManagerImpl(content::WebContents* web_contents, |
| 43 PasswordManagerClient* client) | 43 PasswordManagerClient* client) |
| 44 : WebContentsObserver(web_contents), client_(client), weak_factory_(this) { | 44 : WebContentsObserver(web_contents), client_(client), weak_factory_(this) { |
| 45 DCHECK(web_contents); | 45 DCHECK(web_contents); |
| 46 auto_signin_enabled_.Init(prefs::kCredentialsEnableAutosignin, | 46 auto_signin_enabled_.Init(prefs::kCredentialsEnableAutosignin, |
| 47 client_->GetPrefs()); | 47 client_->GetPrefs()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 CredentialManagerImpl::~CredentialManagerImpl() {} | 50 CredentialManagerImpl::~CredentialManagerImpl() {} |
| 51 | 51 |
| 52 void CredentialManagerImpl::BindRequest( | 52 void CredentialManagerImpl::BindRequest( |
| 53 mojom::CredentialManagerRequest request) { | 53 mojom::CredentialManagerRequest request) { |
| 54 bindings_.AddBinding(this, std::move(request)); | 54 bindings_.AddBinding(this, std::move(request)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void CredentialManagerImpl::Store(const CredentialInfo& credential, | 57 void CredentialManagerImpl::Store(const CredentialInfo& credential, |
| 58 const StoreCallback& callback) { | 58 StoreCallback callback) { |
| 59 DCHECK_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, credential.type); | 59 DCHECK_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, credential.type); |
| 60 | 60 |
| 61 if (password_manager_util::IsLoggingActive(client_)) { | 61 if (password_manager_util::IsLoggingActive(client_)) { |
| 62 CredentialManagerLogger(client_->GetLogManager()) | 62 CredentialManagerLogger(client_->GetLogManager()) |
| 63 .LogStoreCredential(web_contents()->GetLastCommittedURL(), | 63 .LogStoreCredential(web_contents()->GetLastCommittedURL(), |
| 64 credential.type); | 64 credential.type); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Send acknowledge response back. | 67 // Send acknowledge response back. |
| 68 callback.Run(); | 68 std::move(callback).Run(); |
| 69 | 69 |
| 70 if (!client_->IsSavingAndFillingEnabledForCurrentPage() || | 70 if (!client_->IsSavingAndFillingEnabledForCurrentPage() || |
| 71 !client_->OnCredentialManagerUsed()) | 71 !client_->OnCredentialManagerUsed()) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 client_->NotifyStorePasswordCalled(); | 74 client_->NotifyStorePasswordCalled(); |
| 75 | 75 |
| 76 GURL origin = web_contents()->GetLastCommittedURL().GetOrigin(); | 76 GURL origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
| 77 std::unique_ptr<autofill::PasswordForm> form( | 77 std::unique_ptr<autofill::PasswordForm> form( |
| 78 CreatePasswordFormFromCredentialInfo(credential, origin)); | 78 CreatePasswordFormFromCredentialInfo(credential, origin)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // us when they sign the user out. | 119 // us when they sign the user out. |
| 120 form_manager_->Update(*form_manager_->preferred_match()); | 120 form_manager_->Update(*form_manager_->preferred_match()); |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Otherwise, this is a new form, so as the user if they'd like to save. | 124 // Otherwise, this is a new form, so as the user if they'd like to save. |
| 125 client_->PromptUserToSaveOrUpdatePassword(std::move(form_manager_), false); | 125 client_->PromptUserToSaveOrUpdatePassword(std::move(form_manager_), false); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void CredentialManagerImpl::RequireUserMediation( | 128 void CredentialManagerImpl::RequireUserMediation( |
| 129 const RequireUserMediationCallback& callback) { | 129 RequireUserMediationCallback callback) { |
| 130 if (password_manager_util::IsLoggingActive(client_)) { | 130 if (password_manager_util::IsLoggingActive(client_)) { |
| 131 CredentialManagerLogger(client_->GetLogManager()) | 131 CredentialManagerLogger(client_->GetLogManager()) |
| 132 .LogRequireUserMediation(web_contents()->GetLastCommittedURL()); | 132 .LogRequireUserMediation(web_contents()->GetLastCommittedURL()); |
| 133 } | 133 } |
| 134 // Send acknowledge response back. | 134 // Send acknowledge response back. |
| 135 callback.Run(); | 135 std::move(callback).Run(); |
| 136 | 136 |
| 137 PasswordStore* store = GetPasswordStore(); | 137 PasswordStore* store = GetPasswordStore(); |
| 138 if (!store || !client_->IsSavingAndFillingEnabledForCurrentPage() || | 138 if (!store || !client_->IsSavingAndFillingEnabledForCurrentPage() || |
| 139 !client_->OnCredentialManagerUsed()) | 139 !client_->OnCredentialManagerUsed()) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 if (!pending_require_user_mediation_) { | 142 if (!pending_require_user_mediation_) { |
| 143 pending_require_user_mediation_.reset( | 143 pending_require_user_mediation_.reset( |
| 144 new CredentialManagerPendingRequireUserMediationTask(this)); | 144 new CredentialManagerPendingRequireUserMediationTask(this)); |
| 145 } | 145 } |
| 146 pending_require_user_mediation_->AddOrigin(GetSynthesizedFormForOrigin()); | 146 pending_require_user_mediation_->AddOrigin(GetSynthesizedFormForOrigin()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void CredentialManagerImpl::Get(bool zero_click_only, | 149 void CredentialManagerImpl::Get(bool zero_click_only, |
| 150 bool include_passwords, | 150 bool include_passwords, |
| 151 const std::vector<GURL>& federations, | 151 const std::vector<GURL>& federations, |
| 152 const GetCallback& callback) { | 152 GetCallback callback) { |
| 153 using metrics_util::LogCredentialManagerGetResult; | 153 using metrics_util::LogCredentialManagerGetResult; |
| 154 metrics_util::CredentialManagerGetMediation mediation_status = | 154 metrics_util::CredentialManagerGetMediation mediation_status = |
| 155 zero_click_only ? metrics_util::CREDENTIAL_MANAGER_GET_UNMEDIATED | 155 zero_click_only ? metrics_util::CREDENTIAL_MANAGER_GET_UNMEDIATED |
| 156 : metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED; | 156 : metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED; |
| 157 PasswordStore* store = GetPasswordStore(); | 157 PasswordStore* store = GetPasswordStore(); |
| 158 if (password_manager_util::IsLoggingActive(client_)) { | 158 if (password_manager_util::IsLoggingActive(client_)) { |
| 159 CredentialManagerLogger(client_->GetLogManager()) | 159 CredentialManagerLogger(client_->GetLogManager()) |
| 160 .LogRequestCredential(web_contents()->GetLastCommittedURL(), | 160 .LogRequestCredential(web_contents()->GetLastCommittedURL(), |
| 161 zero_click_only, federations); | 161 zero_click_only, federations); |
| 162 } | 162 } |
| 163 if (pending_request_ || !store) { | 163 if (pending_request_ || !store) { |
| 164 // Callback error. | 164 // Callback error. |
| 165 callback.Run(pending_request_ | 165 std::move(callback).Run( |
| 166 ? mojom::CredentialManagerError::PENDINGREQUEST | 166 pending_request_ |
| 167 : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE, | 167 ? mojom::CredentialManagerError::PENDINGREQUEST |
| 168 base::nullopt); | 168 : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE, |
| 169 base::nullopt); |
| 169 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_REJECTED, | 170 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_REJECTED, |
| 170 mediation_status); | 171 mediation_status); |
| 171 return; | 172 return; |
| 172 } | 173 } |
| 173 | 174 |
| 174 // Return an empty credential if the current page has TLS errors, or if the | 175 // Return an empty credential if the current page has TLS errors, or if the |
| 175 // page is being prerendered. | 176 // page is being prerendered. |
| 176 if (!client_->IsFillingEnabledForCurrentPage() || | 177 if (!client_->IsFillingEnabledForCurrentPage() || |
| 177 !client_->OnCredentialManagerUsed()) { | 178 !client_->OnCredentialManagerUsed()) { |
| 178 callback.Run(mojom::CredentialManagerError::SUCCESS, CredentialInfo()); | 179 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, |
| 180 CredentialInfo()); |
| 179 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, | 181 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, |
| 180 mediation_status); | 182 mediation_status); |
| 181 return; | 183 return; |
| 182 } | 184 } |
| 183 // Return an empty credential if zero-click is required but disabled. | 185 // Return an empty credential if zero-click is required but disabled. |
| 184 if (zero_click_only && !IsZeroClickAllowed()) { | 186 if (zero_click_only && !IsZeroClickAllowed()) { |
| 185 // Callback with empty credential info. | 187 // Callback with empty credential info. |
| 186 callback.Run(mojom::CredentialManagerError::SUCCESS, CredentialInfo()); | 188 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, |
| 189 CredentialInfo()); |
| 187 LogCredentialManagerGetResult( | 190 LogCredentialManagerGetResult( |
| 188 metrics_util::CREDENTIAL_MANAGER_GET_NONE_ZERO_CLICK_OFF, | 191 metrics_util::CREDENTIAL_MANAGER_GET_NONE_ZERO_CLICK_OFF, |
| 189 mediation_status); | 192 mediation_status); |
| 190 return; | 193 return; |
| 191 } | 194 } |
| 192 | 195 |
| 193 pending_request_.reset(new CredentialManagerPendingRequestTask( | 196 pending_request_.reset(new CredentialManagerPendingRequestTask( |
| 194 this, base::Bind(&RunMojoGetCallback, callback), zero_click_only, | 197 this, base::Bind(&RunMojoGetCallback, base::Passed(&callback)), |
| 195 include_passwords, federations)); | 198 zero_click_only, include_passwords, federations)); |
| 196 // This will result in a callback to | 199 // This will result in a callback to |
| 197 // PendingRequestTask::OnGetPasswordStoreResults(). | 200 // PendingRequestTask::OnGetPasswordStoreResults(). |
| 198 GetPasswordStore()->GetLogins(GetSynthesizedFormForOrigin(), | 201 GetPasswordStore()->GetLogins(GetSynthesizedFormForOrigin(), |
| 199 pending_request_.get()); | 202 pending_request_.get()); |
| 200 } | 203 } |
| 201 | 204 |
| 202 bool CredentialManagerImpl::IsZeroClickAllowed() const { | 205 bool CredentialManagerImpl::IsZeroClickAllowed() const { |
| 203 return *auto_signin_enabled_ && !client_->IsIncognito(); | 206 return *auto_signin_enabled_ && !client_->IsIncognito(); |
| 204 } | 207 } |
| 205 | 208 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 PasswordStore::FormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin() | 281 PasswordStore::FormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin() |
| 279 const { | 282 const { |
| 280 PasswordStore::FormDigest digest = { | 283 PasswordStore::FormDigest digest = { |
| 281 autofill::PasswordForm::SCHEME_HTML, std::string(), | 284 autofill::PasswordForm::SCHEME_HTML, std::string(), |
| 282 web_contents()->GetLastCommittedURL().GetOrigin()}; | 285 web_contents()->GetLastCommittedURL().GetOrigin()}; |
| 283 digest.signon_realm = digest.origin.spec(); | 286 digest.signon_realm = digest.origin.spec(); |
| 284 return digest; | 287 return digest; |
| 285 } | 288 } |
| 286 | 289 |
| 287 } // namespace password_manager | 290 } // namespace password_manager |
| OLD | NEW |