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/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "components/autofill/core/common/password_form.h" | 13 #include "components/autofill/core/common/password_form.h" |
14 #include "components/password_manager/content/browser/content_password_manager_d
river.h" | 14 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
15 #include "components/password_manager/content/browser/content_password_manager_d
river_factory.h" | 15 #include "components/password_manager/content/browser/content_password_manager_d
river_factory.h" |
16 #include "components/password_manager/core/browser/affiliated_match_helper.h" | 16 #include "components/password_manager/core/browser/affiliated_match_helper.h" |
| 17 #include "components/password_manager/core/browser/credential_manager_logger.h" |
17 #include "components/password_manager/core/browser/password_manager_client.h" | 18 #include "components/password_manager/core/browser/password_manager_client.h" |
| 19 #include "components/password_manager/core/browser/password_manager_util.h" |
18 #include "components/password_manager/core/browser/password_store.h" | 20 #include "components/password_manager/core/browser/password_store.h" |
19 #include "components/password_manager/core/common/credential_manager_types.h" | 21 #include "components/password_manager/core/common/credential_manager_types.h" |
20 #include "components/password_manager/core/common/password_manager_pref_names.h" | 22 #include "components/password_manager/core/common/password_manager_pref_names.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 | 24 |
23 namespace password_manager { | 25 namespace password_manager { |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 void RunMojoGetCallback(const mojom::CredentialManager::GetCallback& callback, | 29 void RunMojoGetCallback(const mojom::CredentialManager::GetCallback& callback, |
(...skipping 17 matching lines...) Expand all Loading... |
45 | 47 |
46 void CredentialManagerImpl::BindRequest( | 48 void CredentialManagerImpl::BindRequest( |
47 mojom::CredentialManagerRequest request) { | 49 mojom::CredentialManagerRequest request) { |
48 bindings_.AddBinding(this, std::move(request)); | 50 bindings_.AddBinding(this, std::move(request)); |
49 } | 51 } |
50 | 52 |
51 void CredentialManagerImpl::Store(const CredentialInfo& credential, | 53 void CredentialManagerImpl::Store(const CredentialInfo& credential, |
52 const StoreCallback& callback) { | 54 const StoreCallback& callback) { |
53 DCHECK_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, credential.type); | 55 DCHECK_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, credential.type); |
54 | 56 |
| 57 if (password_manager_util::IsLoggingActive(client_)) { |
| 58 CredentialManagerLogger(client_->GetLogManager()) |
| 59 .LogStoreCredential(web_contents()->GetLastCommittedURL(), |
| 60 credential.type); |
| 61 } |
| 62 |
55 // Send acknowledge response back. | 63 // Send acknowledge response back. |
56 callback.Run(); | 64 callback.Run(); |
57 | 65 |
58 if (!client_->IsSavingAndFillingEnabledForCurrentPage()) | 66 if (!client_->IsSavingAndFillingEnabledForCurrentPage()) |
59 return; | 67 return; |
60 | 68 |
61 client_->NotifyStorePasswordCalled(); | 69 client_->NotifyStorePasswordCalled(); |
62 | 70 |
63 GURL origin = web_contents()->GetLastCommittedURL().GetOrigin(); | 71 GURL origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
64 std::unique_ptr<autofill::PasswordForm> form( | 72 std::unique_ptr<autofill::PasswordForm> form( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 105 } |
98 | 106 |
99 // Otherwise, this is a new form, so as the user if they'd like to save. | 107 // Otherwise, this is a new form, so as the user if they'd like to save. |
100 client_->PromptUserToSaveOrUpdatePassword( | 108 client_->PromptUserToSaveOrUpdatePassword( |
101 std::move(form_manager_), CredentialSourceType::CREDENTIAL_SOURCE_API, | 109 std::move(form_manager_), CredentialSourceType::CREDENTIAL_SOURCE_API, |
102 false); | 110 false); |
103 } | 111 } |
104 | 112 |
105 void CredentialManagerImpl::RequireUserMediation( | 113 void CredentialManagerImpl::RequireUserMediation( |
106 const RequireUserMediationCallback& callback) { | 114 const RequireUserMediationCallback& callback) { |
| 115 if (password_manager_util::IsLoggingActive(client_)) { |
| 116 CredentialManagerLogger(client_->GetLogManager()) |
| 117 .LogRequireUserMediation(web_contents()->GetLastCommittedURL()); |
| 118 } |
107 PasswordStore* store = GetPasswordStore(); | 119 PasswordStore* store = GetPasswordStore(); |
108 if (!store || !IsUpdatingCredentialAllowed()) { | 120 if (!store || !IsUpdatingCredentialAllowed()) { |
109 callback.Run(); | 121 callback.Run(); |
110 return; | 122 return; |
111 } | 123 } |
112 | 124 |
113 if (store->affiliated_match_helper()) { | 125 if (store->affiliated_match_helper()) { |
114 store->affiliated_match_helper()->GetAffiliatedAndroidRealms( | 126 store->affiliated_match_helper()->GetAffiliatedAndroidRealms( |
115 GetSynthesizedFormForOrigin(), | 127 GetSynthesizedFormForOrigin(), |
116 base::Bind(&CredentialManagerImpl::ScheduleRequireMediationTask, | 128 base::Bind(&CredentialManagerImpl::ScheduleRequireMediationTask, |
(...skipping 26 matching lines...) Expand all Loading... |
143 | 155 |
144 // Send acknowledge response back. | 156 // Send acknowledge response back. |
145 callback.Run(); | 157 callback.Run(); |
146 } | 158 } |
147 | 159 |
148 void CredentialManagerImpl::Get(bool zero_click_only, | 160 void CredentialManagerImpl::Get(bool zero_click_only, |
149 bool include_passwords, | 161 bool include_passwords, |
150 const std::vector<GURL>& federations, | 162 const std::vector<GURL>& federations, |
151 const GetCallback& callback) { | 163 const GetCallback& callback) { |
152 PasswordStore* store = GetPasswordStore(); | 164 PasswordStore* store = GetPasswordStore(); |
| 165 if (password_manager_util::IsLoggingActive(client_)) { |
| 166 CredentialManagerLogger(client_->GetLogManager()) |
| 167 .LogRequestCredential(web_contents()->GetLastCommittedURL(), |
| 168 zero_click_only, federations); |
| 169 } |
153 if (pending_request_ || !store) { | 170 if (pending_request_ || !store) { |
154 // Callback error. | 171 // Callback error. |
155 callback.Run(pending_request_ | 172 callback.Run(pending_request_ |
156 ? mojom::CredentialManagerError::PENDINGREQUEST | 173 ? mojom::CredentialManagerError::PENDINGREQUEST |
157 : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE, | 174 : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE, |
158 base::nullopt); | 175 base::nullopt); |
159 return; | 176 return; |
160 } | 177 } |
161 | 178 |
162 // Return an empty credential if zero-click is required but disabled, or if | 179 // Return an empty credential if zero-click is required but disabled, or if |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); | 235 driver_factory->GetDriverForFrame(web_contents()->GetMainFrame()); |
219 return driver->AsWeakPtr(); | 236 return driver->AsWeakPtr(); |
220 } | 237 } |
221 | 238 |
222 void CredentialManagerImpl::SendCredential( | 239 void CredentialManagerImpl::SendCredential( |
223 const SendCredentialCallback& send_callback, | 240 const SendCredentialCallback& send_callback, |
224 const CredentialInfo& info) { | 241 const CredentialInfo& info) { |
225 DCHECK(pending_request_); | 242 DCHECK(pending_request_); |
226 DCHECK(send_callback.Equals(pending_request_->send_callback())); | 243 DCHECK(send_callback.Equals(pending_request_->send_callback())); |
227 | 244 |
| 245 if (password_manager_util::IsLoggingActive(client_)) { |
| 246 CredentialManagerLogger(client_->GetLogManager()) |
| 247 .LogSendCredential(web_contents()->GetLastCommittedURL(), info.type); |
| 248 } |
228 send_callback.Run(info); | 249 send_callback.Run(info); |
229 pending_request_.reset(); | 250 pending_request_.reset(); |
230 } | 251 } |
231 | 252 |
232 void CredentialManagerImpl::SendPasswordForm( | 253 void CredentialManagerImpl::SendPasswordForm( |
233 const SendCredentialCallback& send_callback, | 254 const SendCredentialCallback& send_callback, |
234 const autofill::PasswordForm* form) { | 255 const autofill::PasswordForm* form) { |
235 CredentialInfo info; | 256 CredentialInfo info; |
236 if (form) { | 257 if (form) { |
237 password_manager::CredentialType type_to_return = | 258 password_manager::CredentialType type_to_return = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 DCHECK(pending_require_user_mediation_); | 294 DCHECK(pending_require_user_mediation_); |
274 pending_require_user_mediation_.reset(); | 295 pending_require_user_mediation_.reset(); |
275 } | 296 } |
276 | 297 |
277 bool CredentialManagerImpl::IsUpdatingCredentialAllowed() const { | 298 bool CredentialManagerImpl::IsUpdatingCredentialAllowed() const { |
278 return !client_->DidLastPageLoadEncounterSSLErrors() && | 299 return !client_->DidLastPageLoadEncounterSSLErrors() && |
279 !client_->IsOffTheRecord(); | 300 !client_->IsOffTheRecord(); |
280 } | 301 } |
281 | 302 |
282 } // namespace password_manager | 303 } // namespace password_manager |
OLD | NEW |