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

Side by Side Diff: chrome/browser/ui/passwords/password_manager_presenter.cc

Issue 1193143003: Enable import/export of passwords into/from Password Manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed import-complete dialog. Created 4 years, 9 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 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/metrics/user_metrics_action.h" 11 #include "base/metrics/user_metrics_action.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/password_manager/password_store_factory.h" 16 #include "chrome/browser/password_manager/password_store_factory.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/signin/signin_manager_factory.h" 18 #include "chrome/browser/signin/signin_manager_factory.h"
19 #include "chrome/browser/sync/profile_sync_service_factory.h" 19 #include "chrome/browser/sync/profile_sync_service_factory.h"
20 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" 20 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
21 #include "chrome/browser/ui/passwords/password_ui_view.h" 21 #include "chrome/browser/ui/passwords/password_ui_view.h"
22 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "components/autofill/core/common/password_form.h" 25 #include "components/autofill/core/common/password_form.h"
26 #include "components/browser_sync/browser/profile_sync_service.h" 26 #include "components/browser_sync/browser/profile_sync_service.h"
27 #include "components/password_manager/core/browser/affiliation_utils.h" 27 #include "components/password_manager/core/browser/affiliation_utils.h"
28 #include "components/password_manager/core/browser/import/password_importer.h"
28 #include "components/password_manager/core/browser/password_manager_util.h" 29 #include "components/password_manager/core/browser/password_manager_util.h"
29 #include "components/password_manager/core/common/password_manager_pref_names.h" 30 #include "components/password_manager/core/common/password_manager_pref_names.h"
30 #include "components/password_manager/sync/browser/password_sync_util.h" 31 #include "components/password_manager/sync/browser/password_sync_util.h"
31 #include "components/prefs/pref_service.h" 32 #include "components/prefs/pref_service.h"
33 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
33 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
34 36
35 #if defined(OS_WIN) 37 #if defined(OS_WIN)
36 #include "chrome/browser/password_manager/password_manager_util_win.h" 38 #include "chrome/browser/password_manager/password_manager_util_win.h"
37 #elif defined(OS_MACOSX) 39 #elif defined(OS_MACOSX)
38 #include "chrome/browser/password_manager/password_manager_util_mac.h" 40 #include "chrome/browser/password_manager/password_manager_util_mac.h"
39 #endif 41 #endif
40 42
41 using password_manager::PasswordStore; 43 using password_manager::PasswordStore;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 137 }
136 138
137 void PasswordManagerPresenter::RequestShowPassword(size_t index) { 139 void PasswordManagerPresenter::RequestShowPassword(size_t index) {
138 #if !defined(OS_ANDROID) // This is never called on Android. 140 #if !defined(OS_ANDROID) // This is never called on Android.
139 if (index >= password_list_.size()) { 141 if (index >= password_list_.size()) {
140 // |index| out of bounds might come from a compromised renderer, don't let 142 // |index| out of bounds might come from a compromised renderer, don't let
141 // it crash the browser. http://crbug.com/362054 143 // it crash the browser. http://crbug.com/362054
142 NOTREACHED(); 144 NOTREACHED();
143 return; 145 return;
144 } 146 }
145 if (require_reauthentication_ && 147
146 (base::TimeTicks::Now() - last_authentication_time_) > 148 if (!IsUserAuthenticated()) {
147 base::TimeDelta::FromSeconds(60)) { 149 return;
148 bool authenticated = true;
149 #if defined(OS_WIN)
150 authenticated = password_manager_util_win::AuthenticateUser(
151 password_view_->GetNativeWindow());
152 #elif defined(OS_MACOSX)
153 authenticated = password_manager_util_mac::AuthenticateUser();
154 #endif
155 if (authenticated)
156 last_authentication_time_ = base::TimeTicks::Now();
157 else
158 return;
159 } 150 }
160 151
161 sync_driver::SyncService* sync_service = nullptr; 152 sync_driver::SyncService* sync_service = nullptr;
162 if (ProfileSyncServiceFactory::HasProfileSyncService( 153 if (ProfileSyncServiceFactory::HasProfileSyncService(
163 password_view_->GetProfile())) { 154 password_view_->GetProfile())) {
164 sync_service = 155 sync_service =
165 ProfileSyncServiceFactory::GetForProfile(password_view_->GetProfile()); 156 ProfileSyncServiceFactory::GetForProfile(password_view_->GetProfile());
166 } 157 }
167 if (password_manager::sync_util::IsSyncAccountCredential( 158 if (password_manager::sync_util::IsSyncAccountCredential(
168 *password_list_[index], sync_service, 159 *password_list_[index], sync_service,
169 SigninManagerFactory::GetForProfile(password_view_->GetProfile()))) { 160 SigninManagerFactory::GetForProfile(password_view_->GetProfile()))) {
170 content::RecordAction( 161 content::RecordAction(
171 base::UserMetricsAction("PasswordManager_SyncCredentialShown")); 162 base::UserMetricsAction("PasswordManager_SyncCredentialShown"));
172 } 163 }
173 164
174 // Call back the front end to reveal the password. 165 // Call back the front end to reveal the password.
175 std::string origin_url = password_manager::GetHumanReadableOrigin( 166 std::string origin_url = password_manager::GetHumanReadableOrigin(
176 *password_list_[index], languages_); 167 *password_list_[index], languages_);
177 password_view_->ShowPassword( 168 password_view_->ShowPassword(
178 index, 169 index,
179 origin_url, 170 origin_url,
180 base::UTF16ToUTF8(password_list_[index]->username_value), 171 base::UTF16ToUTF8(password_list_[index]->username_value),
181 password_list_[index]->password_value); 172 password_list_[index]->password_value);
182 #endif 173 #endif
183 } 174 }
184 175
176 std::vector<scoped_ptr<autofill::PasswordForm>>
177 PasswordManagerPresenter::GetAllPasswords() {
178 std::vector<scoped_ptr<autofill::PasswordForm>> ret_val;
179
180 for (const auto& form : password_list_) {
181 scoped_ptr<autofill::PasswordForm> copyOfPassword(
182 new autofill::PasswordForm(*(form.get())));
183 ret_val.push_back(std::move(copyOfPassword));
vabr (Chromium) 2016/03/10 10:53:31 nit: A shorter way to write lines 181-183: ret_va
xunlu 2016/03/16 07:23:58 Done.
184 }
185
186 return ret_val;
187 }
188
185 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( 189 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword(
186 size_t index) { 190 size_t index) {
187 if (index >= password_list_.size()) { 191 if (index >= password_list_.size()) {
188 // |index| out of bounds might come from a compromised renderer, don't let 192 // |index| out of bounds might come from a compromised renderer, don't let
189 // it crash the browser. http://crbug.com/362054 193 // it crash the browser. http://crbug.com/362054
190 NOTREACHED(); 194 NOTREACHED();
191 return NULL; 195 return NULL;
192 } 196 }
193 return password_list_[index].get(); 197 return password_list_[index].get();
194 } 198 }
(...skipping 19 matching lines...) Expand all
214 Initialize(); 218 Initialize();
215 219
216 bool show_passwords = *show_passwords_ && !require_reauthentication_; 220 bool show_passwords = *show_passwords_ && !require_reauthentication_;
217 password_view_->SetPasswordList(password_list_, show_passwords); 221 password_view_->SetPasswordList(password_list_, show_passwords);
218 } 222 }
219 223
220 void PasswordManagerPresenter::SetPasswordExceptionList() { 224 void PasswordManagerPresenter::SetPasswordExceptionList() {
221 password_view_->SetPasswordExceptionList(password_exception_list_); 225 password_view_->SetPasswordExceptionList(password_exception_list_);
222 } 226 }
223 227
228 bool PasswordManagerPresenter::IsUserAuthenticated() {
229 #if defined(OS_ANDROID)
230 NOTREACHED();
231 #endif
232 if (require_reauthentication_ &&
233 (base::TimeTicks::Now() - last_authentication_time_) >
234 base::TimeDelta::FromSeconds(60)) {
235 bool authenticated = true;
236 #if defined(OS_WIN)
237 authenticated = password_manager_util_win::AuthenticateUser(
238 password_view_->GetNativeWindow());
239 #elif defined(OS_MACOSX)
240 authenticated = password_manager_util_mac::AuthenticateUser();
241 #endif
242 if (authenticated)
243 last_authentication_time_ = base::TimeTicks::Now();
244 return authenticated;
245 }
246 return true;
247 }
248
224 PasswordManagerPresenter::ListPopulater::ListPopulater( 249 PasswordManagerPresenter::ListPopulater::ListPopulater(
225 PasswordManagerPresenter* page) : page_(page) { 250 PasswordManagerPresenter* page) : page_(page) {
226 } 251 }
227 252
228 PasswordManagerPresenter::ListPopulater::~ListPopulater() { 253 PasswordManagerPresenter::ListPopulater::~ListPopulater() {
229 } 254 }
230 255
231 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater( 256 PasswordManagerPresenter::PasswordListPopulater::PasswordListPopulater(
232 PasswordManagerPresenter* page) : ListPopulater(page) { 257 PasswordManagerPresenter* page) : ListPopulater(page) {
233 } 258 }
(...skipping 29 matching lines...) Expand all
263 LOG(ERROR) << "No password store! Cannot display exceptions."; 288 LOG(ERROR) << "No password store! Cannot display exceptions.";
264 } 289 }
265 } 290 }
266 291
267 void PasswordManagerPresenter::PasswordExceptionListPopulater:: 292 void PasswordManagerPresenter::PasswordExceptionListPopulater::
268 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { 293 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) {
269 page_->password_exception_list_ = 294 page_->password_exception_list_ =
270 password_manager_util::ConvertScopedVector(std::move(results)); 295 password_manager_util::ConvertScopedVector(std::move(results));
271 page_->SetPasswordExceptionList(); 296 page_->SetPasswordExceptionList();
272 } 297 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698