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

Side by Side Diff: components/password_manager/content/browser/credential_manager_impl.cc

Issue 2864493003: Deprecate CredentialRequestOptions.unmediated in favor mediation enum (Closed)
Patch Set: Rebase Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/metrics/user_metrics.h" 11 #include "base/metrics/user_metrics.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "components/autofill/core/common/password_form.h" 14 #include "components/autofill/core/common/password_form.h"
15 #include "components/password_manager/content/browser/content_password_manager_d river.h" 15 #include "components/password_manager/content/browser/content_password_manager_d river.h"
16 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" 16 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h"
17 #include "components/password_manager/core/browser/affiliated_match_helper.h" 17 #include "components/password_manager/core/browser/affiliated_match_helper.h"
18 #include "components/password_manager/core/browser/credential_manager_logger.h" 18 #include "components/password_manager/core/browser/credential_manager_logger.h"
19 #include "components/password_manager/core/browser/form_fetcher_impl.h" 19 #include "components/password_manager/core/browser/form_fetcher_impl.h"
20 #include "components/password_manager/core/browser/form_saver.h" 20 #include "components/password_manager/core/browser/form_saver.h"
21 #include "components/password_manager/core/browser/password_manager_client.h" 21 #include "components/password_manager/core/browser/password_manager_client.h"
22 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 22 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
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"
26 #include "components/password_manager/core/common/password_manager_pref_names.h" 25 #include "components/password_manager/core/common/password_manager_pref_names.h"
27 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
28 27
29 namespace password_manager { 28 namespace password_manager {
30 29
31 namespace { 30 namespace {
32 31
33 void RunMojoGetCallback(mojom::CredentialManager::GetCallback callback, 32 void RunMojoGetCallback(mojom::CredentialManager::GetCallback callback,
34 const CredentialInfo& info) { 33 const CredentialInfo& info) {
35 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, info); 34 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, info);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 !client_->OnCredentialManagerUsed()) 138 !client_->OnCredentialManagerUsed())
140 return; 139 return;
141 140
142 if (!pending_require_user_mediation_) { 141 if (!pending_require_user_mediation_) {
143 pending_require_user_mediation_.reset( 142 pending_require_user_mediation_.reset(
144 new CredentialManagerPendingRequireUserMediationTask(this)); 143 new CredentialManagerPendingRequireUserMediationTask(this));
145 } 144 }
146 pending_require_user_mediation_->AddOrigin(GetSynthesizedFormForOrigin()); 145 pending_require_user_mediation_->AddOrigin(GetSynthesizedFormForOrigin());
147 } 146 }
148 147
149 void CredentialManagerImpl::Get(bool zero_click_only, 148 void CredentialManagerImpl::Get(CredentialMediationRequirement mediation,
150 bool include_passwords, 149 bool include_passwords,
151 const std::vector<GURL>& federations, 150 const std::vector<GURL>& federations,
152 GetCallback callback) { 151 GetCallback callback) {
153 using metrics_util::LogCredentialManagerGetResult; 152 using metrics_util::LogCredentialManagerGetResult;
154 metrics_util::CredentialManagerGetMediation mediation_status = 153
155 zero_click_only ? metrics_util::CREDENTIAL_MANAGER_GET_UNMEDIATED
156 : metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED;
157 PasswordStore* store = GetPasswordStore(); 154 PasswordStore* store = GetPasswordStore();
158 if (password_manager_util::IsLoggingActive(client_)) { 155 if (password_manager_util::IsLoggingActive(client_)) {
159 CredentialManagerLogger(client_->GetLogManager()) 156 CredentialManagerLogger(client_->GetLogManager())
160 .LogRequestCredential(web_contents()->GetLastCommittedURL(), 157 .LogRequestCredential(web_contents()->GetLastCommittedURL(), mediation,
161 zero_click_only, federations); 158 federations);
162 } 159 }
163 if (pending_request_ || !store) { 160 if (pending_request_ || !store) {
164 // Callback error. 161 // Callback error.
165 std::move(callback).Run( 162 std::move(callback).Run(
166 pending_request_ 163 pending_request_
167 ? mojom::CredentialManagerError::PENDINGREQUEST 164 ? mojom::CredentialManagerError::PENDINGREQUEST
168 : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE, 165 : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE,
169 base::nullopt); 166 base::nullopt);
170 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_REJECTED, 167 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_REJECTED,
171 mediation_status); 168 mediation);
172 return; 169 return;
173 } 170 }
174 171
175 // Return an empty credential if the current page has TLS errors, or if the 172 // Return an empty credential if the current page has TLS errors, or if the
176 // page is being prerendered. 173 // page is being prerendered.
177 if (!client_->IsFillingEnabledForCurrentPage() || 174 if (!client_->IsFillingEnabledForCurrentPage() ||
178 !client_->OnCredentialManagerUsed()) { 175 !client_->OnCredentialManagerUsed()) {
179 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, 176 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS,
180 CredentialInfo()); 177 CredentialInfo());
181 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, 178 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE,
182 mediation_status); 179 mediation);
183 return; 180 return;
184 } 181 }
185 // Return an empty credential if zero-click is required but disabled. 182 // Return an empty credential if zero-click is required but disabled.
186 if (zero_click_only && !IsZeroClickAllowed()) { 183 if (mediation == CredentialMediationRequirement::kSilent &&
184 !IsZeroClickAllowed()) {
187 // Callback with empty credential info. 185 // Callback with empty credential info.
188 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, 186 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS,
189 CredentialInfo()); 187 CredentialInfo());
190 LogCredentialManagerGetResult( 188 LogCredentialManagerGetResult(
191 metrics_util::CREDENTIAL_MANAGER_GET_NONE_ZERO_CLICK_OFF, 189 metrics_util::CREDENTIAL_MANAGER_GET_NONE_ZERO_CLICK_OFF, mediation);
192 mediation_status);
193 return; 190 return;
194 } 191 }
195 192
196 pending_request_.reset(new CredentialManagerPendingRequestTask( 193 pending_request_.reset(new CredentialManagerPendingRequestTask(
197 this, base::Bind(&RunMojoGetCallback, base::Passed(&callback)), 194 this, base::Bind(&RunMojoGetCallback, base::Passed(&callback)), mediation,
198 zero_click_only, include_passwords, federations)); 195 include_passwords, federations));
199 // This will result in a callback to 196 // This will result in a callback to
200 // PendingRequestTask::OnGetPasswordStoreResults(). 197 // PendingRequestTask::OnGetPasswordStoreResults().
201 GetPasswordStore()->GetLogins(GetSynthesizedFormForOrigin(), 198 GetPasswordStore()->GetLogins(GetSynthesizedFormForOrigin(),
202 pending_request_.get()); 199 pending_request_.get());
203 } 200 }
204 201
205 bool CredentialManagerImpl::IsZeroClickAllowed() const { 202 bool CredentialManagerImpl::IsZeroClickAllowed() const {
206 return *auto_signin_enabled_ && !client_->IsIncognito(); 203 return *auto_signin_enabled_ && !client_->IsIncognito();
207 } 204 }
208 205
(...skipping 19 matching lines...) Expand all
228 if (password_manager_util::IsLoggingActive(client_)) { 225 if (password_manager_util::IsLoggingActive(client_)) {
229 CredentialManagerLogger(client_->GetLogManager()) 226 CredentialManagerLogger(client_->GetLogManager())
230 .LogSendCredential(web_contents()->GetLastCommittedURL(), info.type); 227 .LogSendCredential(web_contents()->GetLastCommittedURL(), info.type);
231 } 228 }
232 send_callback.Run(info); 229 send_callback.Run(info);
233 pending_request_.reset(); 230 pending_request_.reset();
234 } 231 }
235 232
236 void CredentialManagerImpl::SendPasswordForm( 233 void CredentialManagerImpl::SendPasswordForm(
237 const SendCredentialCallback& send_callback, 234 const SendCredentialCallback& send_callback,
235 CredentialMediationRequirement mediation,
238 const autofill::PasswordForm* form) { 236 const autofill::PasswordForm* form) {
239 CredentialInfo info; 237 CredentialInfo info;
240 if (form) { 238 if (form) {
241 password_manager::CredentialType type_to_return = 239 password_manager::CredentialType type_to_return =
242 form->federation_origin.unique() 240 form->federation_origin.unique()
243 ? CredentialType::CREDENTIAL_TYPE_PASSWORD 241 ? CredentialType::CREDENTIAL_TYPE_PASSWORD
244 : CredentialType::CREDENTIAL_TYPE_FEDERATED; 242 : CredentialType::CREDENTIAL_TYPE_FEDERATED;
245 info = CredentialInfo(*form, type_to_return); 243 info = CredentialInfo(*form, type_to_return);
246 if (PasswordStore* store = GetPasswordStore()) { 244 if (PasswordStore* store = GetPasswordStore()) {
247 if (form->skip_zero_click && IsZeroClickAllowed()) { 245 if (form->skip_zero_click && IsZeroClickAllowed()) {
248 autofill::PasswordForm update_form = *form; 246 autofill::PasswordForm update_form = *form;
249 update_form.skip_zero_click = false; 247 update_form.skip_zero_click = false;
250 store->UpdateLogin(update_form); 248 store->UpdateLogin(update_form);
251 } 249 }
252 } 250 }
253 base::RecordAction( 251 base::RecordAction(
254 base::UserMetricsAction("CredentialManager_AccountChooser_Accepted")); 252 base::UserMetricsAction("CredentialManager_AccountChooser_Accepted"));
255 metrics_util::LogCredentialManagerGetResult( 253 metrics_util::LogCredentialManagerGetResult(
256 metrics_util::CREDENTIAL_MANAGER_GET_ACCOUNT_CHOOSER, 254 metrics_util::CREDENTIAL_MANAGER_GET_ACCOUNT_CHOOSER, mediation);
257 metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED);
258 } else { 255 } else {
259 base::RecordAction( 256 base::RecordAction(
260 base::UserMetricsAction("CredentialManager_AccountChooser_Dismissed")); 257 base::UserMetricsAction("CredentialManager_AccountChooser_Dismissed"));
261 metrics_util::LogCredentialManagerGetResult( 258 metrics_util::LogCredentialManagerGetResult(
262 metrics_util::CREDENTIAL_MANAGER_GET_NONE, 259 metrics_util::CREDENTIAL_MANAGER_GET_NONE, mediation);
263 metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED);
264 } 260 }
265 SendCredential(send_callback, info); 261 SendCredential(send_callback, info);
266 } 262 }
267 263
268 PasswordManagerClient* CredentialManagerImpl::client() const { 264 PasswordManagerClient* CredentialManagerImpl::client() const {
269 return client_; 265 return client_;
270 } 266 }
271 267
272 PasswordStore* CredentialManagerImpl::GetPasswordStore() { 268 PasswordStore* CredentialManagerImpl::GetPasswordStore() {
273 return client_ ? client_->GetPasswordStore() : nullptr; 269 return client_ ? client_->GetPasswordStore() : nullptr;
274 } 270 }
275 271
276 void CredentialManagerImpl::DoneRequiringUserMediation() { 272 void CredentialManagerImpl::DoneRequiringUserMediation() {
277 DCHECK(pending_require_user_mediation_); 273 DCHECK(pending_require_user_mediation_);
278 pending_require_user_mediation_.reset(); 274 pending_require_user_mediation_.reset();
279 } 275 }
280 276
281 PasswordStore::FormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin() 277 PasswordStore::FormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin()
282 const { 278 const {
283 PasswordStore::FormDigest digest = { 279 PasswordStore::FormDigest digest = {
284 autofill::PasswordForm::SCHEME_HTML, std::string(), 280 autofill::PasswordForm::SCHEME_HTML, std::string(),
285 web_contents()->GetLastCommittedURL().GetOrigin()}; 281 web_contents()->GetLastCommittedURL().GetOrigin()};
286 digest.signon_realm = digest.origin.spec(); 282 digest.signon_realm = digest.origin.spec();
287 return digest; 283 return digest;
288 } 284 }
289 285
290 } // namespace password_manager 286 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698