OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/passwords/password_manager_presenter.h" | 5 #include "chrome/browser/ui/passwords/password_manager_presenter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/metrics/user_metrics_action.h" | 9 #include "base/metrics/user_metrics_action.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/password_manager/password_store_factory.h" | 14 #include "chrome/browser/password_manager/password_store_factory.h" |
15 #include "chrome/browser/password_manager/sync_metrics.h" | 15 #include "chrome/browser/password_manager/sync_metrics.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 17 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
18 #include "chrome/browser/ui/passwords/password_ui_view.h" | 18 #include "chrome/browser/ui/passwords/password_ui_view.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "components/autofill/core/common/password_form.h" | 22 #include "components/autofill/core/common/password_form.h" |
23 #include "components/password_manager/core/browser/affiliation_utils.h" | 23 #include "components/password_manager/core/browser/affiliation_utils.h" |
24 #include "components/password_manager/core/browser/import/password_importer.h" | |
24 #include "components/password_manager/core/browser/password_manager_util.h" | 25 #include "components/password_manager/core/browser/password_manager_util.h" |
25 #include "components/password_manager/core/common/password_manager_pref_names.h" | 26 #include "components/password_manager/core/common/password_manager_pref_names.h" |
26 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
28 | 29 |
29 using password_manager::PasswordStore; | 30 using password_manager::PasswordStore; |
30 | 31 |
31 PasswordManagerPresenter::PasswordManagerPresenter( | 32 PasswordManagerPresenter::PasswordManagerPresenter( |
32 PasswordUIView* password_view) | 33 PasswordUIView* password_view) |
33 : populater_(this), | 34 : populater_(this), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 return; | 116 return; |
116 } | 117 } |
117 PasswordStore* store = GetPasswordStore(); | 118 PasswordStore* store = GetPasswordStore(); |
118 if (!store) | 119 if (!store) |
119 return; | 120 return; |
120 store->RemoveLogin(*password_exception_list_[index]); | 121 store->RemoveLogin(*password_exception_list_[index]); |
121 content::RecordAction( | 122 content::RecordAction( |
122 base::UserMetricsAction("PasswordManager_RemovePasswordException")); | 123 base::UserMetricsAction("PasswordManager_RemovePasswordException")); |
123 } | 124 } |
124 | 125 |
126 bool PasswordManagerPresenter::AddPasswordsToStore( | |
127 const std::vector<autofill::PasswordForm>& forms) { | |
128 PasswordStore* store = GetPasswordStore(); | |
129 if (!store) | |
130 return false; | |
131 | |
132 for (std::vector<autofill::PasswordForm>::const_iterator it = forms.begin(); | |
vabr (Chromium)
2015/07/06 08:57:15
optional nit:
for (const autofill::PasswordForm* f
xunlu
2015/07/07 00:46:03
Done.
| |
133 it != forms.end(); ++it) { | |
134 store->AddLogin(*it); | |
135 } | |
136 return true; | |
137 } | |
138 | |
139 bool PasswordManagerPresenter::RequestToExportPassword() { | |
140 #if !defined(OS_ANDROID) // This is never called on Android. | |
vabr (Chromium)
2015/07/06 08:57:15
Instead of the comment, I suggest the self-documen
xunlu
2015/07/07 00:46:03
Done.
| |
141 if (IsAuthenticationRequired()) { | |
vabr (Chromium)
2015/07/06 08:57:15
I suggest to pull out lines 141-147 as a separate
xunlu
2015/07/07 00:46:03
Done.
| |
142 if (password_manager_util::AuthenticateUser( | |
143 password_view_->GetNativeWindow())) | |
144 last_authentication_time_ = base::TimeTicks::Now(); | |
145 else | |
146 return false; | |
147 } | |
148 #endif | |
149 return true; | |
vabr (Chromium)
2015/07/06 08:57:16
Please move the "return true;" to the !defined(OS_
xunlu
2015/07/07 00:46:03
Done.
| |
150 } | |
151 | |
125 void PasswordManagerPresenter::RequestShowPassword(size_t index) { | 152 void PasswordManagerPresenter::RequestShowPassword(size_t index) { |
126 #if !defined(OS_ANDROID) // This is never called on Android. | 153 #if !defined(OS_ANDROID) // This is never called on Android. |
127 if (index >= password_list_.size()) { | 154 if (index >= password_list_.size()) { |
128 // |index| out of bounds might come from a compromised renderer, don't let | 155 // |index| out of bounds might come from a compromised renderer, don't let |
129 // it crash the browser. http://crbug.com/362054 | 156 // it crash the browser. http://crbug.com/362054 |
130 NOTREACHED(); | 157 NOTREACHED(); |
131 return; | 158 return; |
132 } | 159 } |
133 if (IsAuthenticationRequired()) { | 160 if (IsAuthenticationRequired()) { |
134 if (password_manager_util::AuthenticateUser( | 161 if (password_manager_util::AuthenticateUser( |
(...skipping 15 matching lines...) Expand all Loading... | |
150 std::string origin_url = password_manager::GetHumanReadableOrigin( | 177 std::string origin_url = password_manager::GetHumanReadableOrigin( |
151 *password_list_[index], languages_); | 178 *password_list_[index], languages_); |
152 password_view_->ShowPassword( | 179 password_view_->ShowPassword( |
153 index, | 180 index, |
154 origin_url, | 181 origin_url, |
155 base::UTF16ToUTF8(password_list_[index]->username_value), | 182 base::UTF16ToUTF8(password_list_[index]->username_value), |
156 password_list_[index]->password_value); | 183 password_list_[index]->password_value); |
157 #endif | 184 #endif |
158 } | 185 } |
159 | 186 |
187 ScopedVector<autofill::PasswordForm> | |
188 PasswordManagerPresenter::GetAllPasswords() { | |
189 ScopedVector<autofill::PasswordForm> retVal; | |
vabr (Chromium)
2015/07/06 08:57:16
nit: ret_val, not retVal
(See http://google-styleg
xunlu
2015/07/07 00:46:03
Done.
| |
190 | |
191 for (ScopedVector<autofill::PasswordForm>::const_iterator it = | |
vabr (Chromium)
2015/07/06 08:57:15
optional nit:
for (const autofill::PasswordForm* e
xunlu
2015/07/07 00:46:03
Done.
| |
192 password_list_.begin(); | |
193 it != password_list_.end(); ++it) { | |
194 retVal.push_back(new autofill::PasswordForm(**it)); | |
195 } | |
196 | |
197 return retVal.Pass(); | |
198 } | |
199 | |
160 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( | 200 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( |
161 size_t index) { | 201 size_t index) { |
162 if (index >= password_list_.size()) { | 202 if (index >= password_list_.size()) { |
163 // |index| out of bounds might come from a compromised renderer, don't let | 203 // |index| out of bounds might come from a compromised renderer, don't let |
164 // it crash the browser. http://crbug.com/362054 | 204 // it crash the browser. http://crbug.com/362054 |
165 NOTREACHED(); | 205 NOTREACHED(); |
166 return NULL; | 206 return NULL; |
167 } | 207 } |
168 return password_list_[index]; | 208 return password_list_[index]; |
169 } | 209 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 } else { | 282 } else { |
243 LOG(ERROR) << "No password store! Cannot display exceptions."; | 283 LOG(ERROR) << "No password store! Cannot display exceptions."; |
244 } | 284 } |
245 } | 285 } |
246 | 286 |
247 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 287 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
248 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 288 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
249 page_->password_exception_list_.swap(results); | 289 page_->password_exception_list_.swap(results); |
250 page_->SetPasswordExceptionList(); | 290 page_->SetPasswordExceptionList(); |
251 } | 291 } |
OLD | NEW |