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

Side by Side Diff: components/password_manager/core/browser/credential_manager_pending_request_task.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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/core/browser/credential_manager_pending_re quest_task.h" 5 #include "components/password_manager/core/browser/credential_manager_pending_re quest_task.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "components/autofill/core/common/password_form.h" 9 #include "components/autofill/core/common/password_form.h"
10 #include "components/password_manager/core/browser/affiliated_match_helper.h" 10 #include "components/password_manager/core/browser/affiliated_match_helper.h"
11 #include "components/password_manager/core/browser/password_bubble_experiment.h" 11 #include "components/password_manager/core/browser/password_bubble_experiment.h"
12 #include "components/password_manager/core/browser/password_manager_client.h" 12 #include "components/password_manager/core/browser/password_manager_client.h"
13 #include "components/password_manager/core/browser/password_manager_util.h" 13 #include "components/password_manager/core/browser/password_manager_util.h"
14 #include "components/password_manager/core/common/credential_manager_types.h" 14 #include "components/password_manager/core/common/credential_manager_types.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 #include "url/origin.h" 16 #include "url/origin.h"
17 17
18 namespace password_manager { 18 namespace password_manager {
19 19
20 CredentialManagerPendingRequestTask::CredentialManagerPendingRequestTask( 20 CredentialManagerPendingRequestTask::CredentialManagerPendingRequestTask(
21 CredentialManagerPendingRequestTaskDelegate* delegate, 21 CredentialManagerPendingRequestTaskDelegate* delegate,
22 int request_id, 22 const SendCredentialCallback& callback,
23 bool request_zero_click_only, 23 bool request_zero_click_only,
24 const GURL& request_origin, 24 const GURL& request_origin,
25 bool include_passwords, 25 bool include_passwords,
26 const std::vector<GURL>& request_federations, 26 const std::vector<GURL>& request_federations,
27 const std::vector<std::string>& affiliated_realms) 27 const std::vector<std::string>& affiliated_realms)
28 : delegate_(delegate), 28 : delegate_(delegate),
29 id_(request_id), 29 send_callback_(callback),
30 zero_click_only_(request_zero_click_only), 30 zero_click_only_(request_zero_click_only),
31 origin_(request_origin), 31 origin_(request_origin),
32 include_passwords_(include_passwords), 32 include_passwords_(include_passwords),
33 affiliated_realms_(affiliated_realms.begin(), affiliated_realms.end()) { 33 affiliated_realms_(affiliated_realms.begin(), affiliated_realms.end()) {
34 CHECK(!delegate_->client()->DidLastPageLoadEncounterSSLErrors()); 34 CHECK(!delegate_->client()->DidLastPageLoadEncounterSSLErrors());
35 for (const GURL& federation : request_federations) 35 for (const GURL& federation : request_federations)
36 federations_.insert(url::Origin(federation.GetOrigin()).Serialize()); 36 federations_.insert(url::Origin(federation.GetOrigin()).Serialize());
37 } 37 }
38 38
39 CredentialManagerPendingRequestTask::~CredentialManagerPendingRequestTask() = 39 CredentialManagerPendingRequestTask::~CredentialManagerPendingRequestTask() =
40 default; 40 default;
41 41
42 void CredentialManagerPendingRequestTask::OnGetPasswordStoreResults( 42 void CredentialManagerPendingRequestTask::OnGetPasswordStoreResults(
43 ScopedVector<autofill::PasswordForm> results) { 43 ScopedVector<autofill::PasswordForm> results) {
44 if (delegate_->GetOrigin() != origin_) { 44 if (delegate_->GetOrigin() != origin_) {
45 delegate_->SendCredential(id_, CredentialInfo()); 45 delegate_->SendCredential(send_callback_, CredentialInfo());
46 return; 46 return;
47 } 47 }
48 48
49 ScopedVector<autofill::PasswordForm> local_results; 49 ScopedVector<autofill::PasswordForm> local_results;
50 ScopedVector<autofill::PasswordForm> affiliated_results; 50 ScopedVector<autofill::PasswordForm> affiliated_results;
51 ScopedVector<autofill::PasswordForm> federated_results; 51 ScopedVector<autofill::PasswordForm> federated_results;
52 for (auto& form : results) { 52 for (auto& form : results) {
53 // Ensure that the form we're looking at matches the password and 53 // Ensure that the form we're looking at matches the password and
54 // federation filters provided. 54 // federation filters provided.
55 if (!((form->federation_origin.unique() && include_passwords_) || 55 if (!((form->federation_origin.unique() && include_passwords_) ||
(...skipping 25 matching lines...) Expand all
81 } 81 }
82 82
83 if (!affiliated_results.empty()) { 83 if (!affiliated_results.empty()) {
84 password_manager_util::TrimUsernameOnlyCredentials(&affiliated_results); 84 password_manager_util::TrimUsernameOnlyCredentials(&affiliated_results);
85 local_results.insert(local_results.end(), affiliated_results.begin(), 85 local_results.insert(local_results.end(), affiliated_results.begin(),
86 affiliated_results.end()); 86 affiliated_results.end());
87 affiliated_results.weak_clear(); 87 affiliated_results.weak_clear();
88 } 88 }
89 89
90 if ((local_results.empty() && federated_results.empty())) { 90 if ((local_results.empty() && federated_results.empty())) {
91 delegate_->SendCredential(id_, CredentialInfo()); 91 delegate_->SendCredential(send_callback_, CredentialInfo());
92 return; 92 return;
93 } 93 }
94 94
95 // We only perform zero-click sign-in when the result is completely 95 // We only perform zero-click sign-in when the result is completely
96 // unambigious. If there is one and only one entry, and zero-click is 96 // unambigious. If there is one and only one entry, and zero-click is
97 // enabled for that entry, return it. 97 // enabled for that entry, return it.
98 // 98 //
99 // Moreover, we only return such a credential if the user has opted-in via the 99 // Moreover, we only return such a credential if the user has opted-in via the
100 // first-run experience. 100 // first-run experience.
101 bool can_use_autosignin = local_results.size() == 1u && 101 bool can_use_autosignin = local_results.size() == 1u &&
102 delegate_->IsZeroClickAllowed(); 102 delegate_->IsZeroClickAllowed();
103 if (can_use_autosignin && !local_results[0]->skip_zero_click && 103 if (can_use_autosignin && !local_results[0]->skip_zero_click &&
104 !password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience( 104 !password_bubble_experiment::ShouldShowAutoSignInPromptFirstRunExperience(
105 delegate_->client()->GetPrefs())) { 105 delegate_->client()->GetPrefs())) {
106 CredentialInfo info(*local_results[0], 106 CredentialInfo info(*local_results[0],
107 local_results[0]->federation_origin.unique() 107 local_results[0]->federation_origin.unique()
108 ? CredentialType::CREDENTIAL_TYPE_PASSWORD 108 ? CredentialType::CREDENTIAL_TYPE_PASSWORD
109 : CredentialType::CREDENTIAL_TYPE_FEDERATED); 109 : CredentialType::CREDENTIAL_TYPE_FEDERATED);
110 delegate_->client()->NotifyUserAutoSignin(std::move(local_results), 110 delegate_->client()->NotifyUserAutoSignin(std::move(local_results),
111 origin_); 111 origin_);
112 delegate_->SendCredential(id_, info); 112 delegate_->SendCredential(send_callback_, info);
113 return; 113 return;
114 } 114 }
115 115
116 // Otherwise, return an empty credential if we're in zero-click-only mode 116 // Otherwise, return an empty credential if we're in zero-click-only mode
117 // or if the user chooses not to return a credential, and the credential the 117 // or if the user chooses not to return a credential, and the credential the
118 // user chooses if they pick one. 118 // user chooses if they pick one.
119 std::unique_ptr<autofill::PasswordForm> potential_autosignin_form( 119 std::unique_ptr<autofill::PasswordForm> potential_autosignin_form(
120 new autofill::PasswordForm(*local_results[0])); 120 new autofill::PasswordForm(*local_results[0]));
121 if (zero_click_only_ || 121 if (zero_click_only_ ||
122 !delegate_->client()->PromptUserToChooseCredentials( 122 !delegate_->client()->PromptUserToChooseCredentials(
123 std::move(local_results), std::move(federated_results), origin_, 123 std::move(local_results), std::move(federated_results), origin_,
124 base::Bind( 124 base::Bind(
125 &CredentialManagerPendingRequestTaskDelegate::SendPasswordForm, 125 &CredentialManagerPendingRequestTaskDelegate::SendPasswordForm,
126 base::Unretained(delegate_), id_))) { 126 base::Unretained(delegate_), send_callback_))) {
127 if (can_use_autosignin) { 127 if (can_use_autosignin) {
128 // The user had credentials, but either chose not to share them with the 128 // The user had credentials, but either chose not to share them with the
129 // site, or was prevented from doing so by lack of zero-click (or the 129 // site, or was prevented from doing so by lack of zero-click (or the
130 // first-run experience). So, notify the client that we could potentially 130 // first-run experience). So, notify the client that we could potentially
131 // have used zero-click; if the user signs in with the same form via 131 // have used zero-click; if the user signs in with the same form via
132 // autofill, we'll toggle the flag for them. 132 // autofill, we'll toggle the flag for them.
133 delegate_->client()->NotifyUserCouldBeAutoSignedIn( 133 delegate_->client()->NotifyUserCouldBeAutoSignedIn(
134 std::move(potential_autosignin_form)); 134 std::move(potential_autosignin_form));
135 } 135 }
136 136
137 delegate_->SendCredential(id_, CredentialInfo()); 137 delegate_->SendCredential(send_callback_, CredentialInfo());
138 } 138 }
139 } 139 }
140 140
141 } // namespace password_manager 141 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698