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

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: Created 5 years, 6 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 "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
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 if (!password_manager_sync_metrics::IsSyncAccountCredential(
Garrett Casto 2015/06/23 23:42:35 I think that we decided for now that we were going
xunlu 2015/06/25 17:12:15 Done.
135 password_view_->GetProfile(),
136 base::UTF16ToUTF8((*it).username_value), (*it).signon_realm)) {
137 store->AddLogin(*it);
138 }
139 }
140 return true;
141 }
142
143 bool PasswordManagerPresenter::RequestToExportPassword() {
144 if (IsAuthenticationRequired()) {
145 if (password_manager_util::AuthenticateUser(
146 password_view_->GetNativeWindow()))
147 last_authentication_time_ = base::TimeTicks::Now();
148 else
149 return false;
150 }
151 return true;
152 }
153
125 void PasswordManagerPresenter::RequestShowPassword(size_t index) { 154 void PasswordManagerPresenter::RequestShowPassword(size_t index) {
126 #if !defined(OS_ANDROID) // This is never called on Android. 155 #if !defined(OS_ANDROID) // This is never called on Android.
127 if (index >= password_list_.size()) { 156 if (index >= password_list_.size()) {
128 // |index| out of bounds might come from a compromised renderer, don't let 157 // |index| out of bounds might come from a compromised renderer, don't let
129 // it crash the browser. http://crbug.com/362054 158 // it crash the browser. http://crbug.com/362054
130 NOTREACHED(); 159 NOTREACHED();
131 return; 160 return;
132 } 161 }
133 if (IsAuthenticationRequired()) { 162 if (IsAuthenticationRequired()) {
134 if (password_manager_util::AuthenticateUser( 163 if (password_manager_util::AuthenticateUser(
(...skipping 15 matching lines...) Expand all
150 std::string origin_url = password_manager::GetHumanReadableOrigin( 179 std::string origin_url = password_manager::GetHumanReadableOrigin(
151 *password_list_[index], languages_); 180 *password_list_[index], languages_);
152 password_view_->ShowPassword( 181 password_view_->ShowPassword(
153 index, 182 index,
154 origin_url, 183 origin_url,
155 base::UTF16ToUTF8(password_list_[index]->username_value), 184 base::UTF16ToUTF8(password_list_[index]->username_value),
156 password_list_[index]->password_value); 185 password_list_[index]->password_value);
157 #endif 186 #endif
158 } 187 }
159 188
189 ScopedVector<autofill::PasswordForm>
190 PasswordManagerPresenter::GetAllPasswords() {
191 ScopedVector<autofill::PasswordForm> retVal = password_list_.Pass();
Garrett Casto 2015/06/23 23:42:35 Why aren't you just returning password_list_.Pass(
xunlu 2015/06/25 17:12:15 If I just return password_list_.Pass(), I will nee
Garrett Casto 2015/06/26 21:13:48 Got it. What I was actually thinking is that this
xunlu 2015/06/30 23:06:09 Done.
192 UpdatePasswordLists();
193 return retVal.Pass();
194 }
195
160 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword( 196 const autofill::PasswordForm* PasswordManagerPresenter::GetPassword(
161 size_t index) { 197 size_t index) {
162 if (index >= password_list_.size()) { 198 if (index >= password_list_.size()) {
163 // |index| out of bounds might come from a compromised renderer, don't let 199 // |index| out of bounds might come from a compromised renderer, don't let
164 // it crash the browser. http://crbug.com/362054 200 // it crash the browser. http://crbug.com/362054
165 NOTREACHED(); 201 NOTREACHED();
166 return NULL; 202 return NULL;
167 } 203 }
168 return password_list_[index]; 204 return password_list_[index];
169 } 205 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } else { 278 } else {
243 LOG(ERROR) << "No password store! Cannot display exceptions."; 279 LOG(ERROR) << "No password store! Cannot display exceptions.";
244 } 280 }
245 } 281 }
246 282
247 void PasswordManagerPresenter::PasswordExceptionListPopulater:: 283 void PasswordManagerPresenter::PasswordExceptionListPopulater::
248 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { 284 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) {
249 page_->password_exception_list_.swap(results); 285 page_->password_exception_list_.swap(results);
250 page_->SetPasswordExceptionList(); 286 page_->SetPasswordExceptionList();
251 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698