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(); |
| 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. |
| 141 if (IsAuthenticationRequired()) { |
| 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; |
| 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 = password_list_.Pass(); |
| 190 UpdatePasswordLists(); |
| 191 return retVal.Pass(); |
| 192 } |
| 193 |
160 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( | 194 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( |
161 size_t index) { | 195 size_t index) { |
162 if (index >= password_list_.size()) { | 196 if (index >= password_list_.size()) { |
163 // |index| out of bounds might come from a compromised renderer, don't let | 197 // |index| out of bounds might come from a compromised renderer, don't let |
164 // it crash the browser. http://crbug.com/362054 | 198 // it crash the browser. http://crbug.com/362054 |
165 NOTREACHED(); | 199 NOTREACHED(); |
166 return NULL; | 200 return NULL; |
167 } | 201 } |
168 return password_list_[index]; | 202 return password_list_[index]; |
169 } | 203 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } else { | 276 } else { |
243 LOG(ERROR) << "No password store! Cannot display exceptions."; | 277 LOG(ERROR) << "No password store! Cannot display exceptions."; |
244 } | 278 } |
245 } | 279 } |
246 | 280 |
247 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 281 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
248 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { | 282 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { |
249 page_->password_exception_list_.swap(results); | 283 page_->password_exception_list_.swap(results); |
250 page_->SetPasswordExceptionList(); | 284 page_->SetPasswordExceptionList(); |
251 } | 285 } |
OLD | NEW |