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_dispatc
her.h" | 5 #include "components/password_manager/content/browser/credential_manager_dispatc
her.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // PasswordStoreConsumer implementation. | 46 // PasswordStoreConsumer implementation. |
47 void OnGetPasswordStoreResults( | 47 void OnGetPasswordStoreResults( |
48 const std::vector<autofill::PasswordForm*>& results) override { | 48 const std::vector<autofill::PasswordForm*>& results) override { |
49 // We own the PasswordForm instances, so we're responsible for cleaning | 49 // We own the PasswordForm instances, so we're responsible for cleaning |
50 // up the instances we don't add to |local_results| or |federated_results|. | 50 // up the instances we don't add to |local_results| or |federated_results|. |
51 // | 51 // |
52 // TODO(mkwst): Switch this and PromptUserToChooseCredentials() to use | 52 // TODO(mkwst): Switch this and PromptUserToChooseCredentials() to use |
53 // ScopedVector. | 53 // ScopedVector. |
54 std::vector<autofill::PasswordForm*> local_results; | 54 std::vector<autofill::PasswordForm*> local_results; |
55 std::vector<autofill::PasswordForm*> federated_results; | 55 std::vector<autofill::PasswordForm*> federated_results; |
| 56 autofill::PasswordForm* zero_click_form_to_return = nullptr; |
| 57 bool found_zero_clickable_credential = false; |
56 for (autofill::PasswordForm* form : results) { | 58 for (autofill::PasswordForm* form : results) { |
57 if (form->origin == origin_) | 59 if (form->origin == origin_) { |
58 local_results.push_back(form); | 60 local_results.push_back(form); |
59 else if (federations_.count(form->origin.spec())) | 61 |
| 62 // If this is a zero-clickable PasswordForm, and we haven't found any |
| 63 // other zero-clickable PasswordForms, then store this one for later. |
| 64 // If we have found other zero-clickable PasswordForms, then clear |
| 65 // the stored form (we return zero-click forms iff there is a single, |
| 66 // unambigious choice). |
| 67 if (!form->skip_zero_click) { |
| 68 zero_click_form_to_return = |
| 69 found_zero_clickable_credential ? nullptr : form; |
| 70 found_zero_clickable_credential = true; |
| 71 } |
| 72 } else if (federations_.count(form->origin.spec())) |
60 federated_results.push_back(form); | 73 federated_results.push_back(form); |
61 else | 74 else |
62 delete form; | 75 delete form; |
63 } | 76 } |
64 | 77 |
65 if ((local_results.empty() && federated_results.empty()) || | 78 if ((local_results.empty() && federated_results.empty()) || |
66 dispatcher_->web_contents()->GetLastCommittedURL().GetOrigin() != | 79 dispatcher_->web_contents()->GetLastCommittedURL().GetOrigin() != |
67 origin_) { | 80 origin_) { |
68 dispatcher_->SendCredential(id_, CredentialInfo()); | 81 dispatcher_->SendCredential(id_, CredentialInfo()); |
69 return; | 82 return; |
70 } | 83 } |
71 if (local_results.size() == 1 && dispatcher_->IsZeroClickAllowed()) { | 84 if (zero_click_form_to_return && dispatcher_->IsZeroClickAllowed()) { |
72 // TODO(mkwst): Use the `one_time_disable_zero_click` flag on the result | 85 CredentialInfo info(*zero_click_form_to_return, |
73 // to prevent auto-sign-in, once that flag is implemented. | 86 zero_click_form_to_return->federation_url.is_empty() |
74 CredentialInfo info(*local_results[0], | |
75 local_results[0]->federation_url.is_empty() | |
76 ? CredentialType::CREDENTIAL_TYPE_LOCAL | 87 ? CredentialType::CREDENTIAL_TYPE_LOCAL |
77 : CredentialType::CREDENTIAL_TYPE_FEDERATED); | 88 : CredentialType::CREDENTIAL_TYPE_FEDERATED); |
78 STLDeleteElements(&local_results); | 89 STLDeleteElements(&local_results); |
79 STLDeleteElements(&federated_results); | 90 STLDeleteElements(&federated_results); |
80 dispatcher_->SendCredential(id_, info); | 91 dispatcher_->SendCredential(id_, info); |
81 return; | 92 return; |
82 } | 93 } |
83 | 94 |
84 if (zero_click_only_ || | 95 if (zero_click_only_ || |
85 !dispatcher_->client()->PromptUserToChooseCredentials( | 96 !dispatcher_->client()->PromptUserToChooseCredentials( |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 pending_request_->id(), info)); | 326 pending_request_->id(), info)); |
316 pending_request_.reset(); | 327 pending_request_.reset(); |
317 } | 328 } |
318 | 329 |
319 void CredentialManagerDispatcher::DoneSigningOut() { | 330 void CredentialManagerDispatcher::DoneSigningOut() { |
320 DCHECK(pending_sign_out_); | 331 DCHECK(pending_sign_out_); |
321 pending_sign_out_.reset(); | 332 pending_sign_out_.reset(); |
322 } | 333 } |
323 | 334 |
324 } // namespace password_manager | 335 } // namespace password_manager |
OLD | NEW |