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" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 last_authentication_time_ = base::TimeTicks(); | 76 last_authentication_time_ = base::TimeTicks(); |
77 | 77 |
78 // Reset the current lists. | 78 // Reset the current lists. |
79 password_list_.clear(); | 79 password_list_.clear(); |
80 password_exception_list_.clear(); | 80 password_exception_list_.clear(); |
81 | 81 |
82 populater_.Populate(); | 82 populater_.Populate(); |
83 exception_populater_.Populate(); | 83 exception_populater_.Populate(); |
84 } | 84 } |
85 | 85 |
86 // static | |
87 bool PasswordManagerPresenter::CheckOriginValidityForAdding( | |
88 const GURL& origin) { | |
89 // Restrict the URL scheme to http and https since a manually-added | |
90 // PasswordForm entry's |scheme| is assumed to be SCHEME_HTML. | |
91 return origin.is_valid() && (origin.SchemeIs(url::kHttpScheme) || | |
92 origin.SchemeIs(url::kHttpsScheme)); | |
93 } | |
94 | |
95 void PasswordManagerPresenter::AddPassword( | |
96 const GURL& origin, | |
97 const base::string16& username_value, | |
98 const base::string16& password_value) { | |
Dan Beam
2014/08/26 17:39:06
#if defined(OS_ANDROID)
NOTREACHED();
#else
..
jaekyeom
2014/08/27 12:28:54
Done.
| |
99 #if !defined(OS_ANDROID) // This is never called on Android. | |
100 if (!CheckOriginValidityForAdding(origin) || password_value.empty()) { | |
101 // Invalid |origin| or empty |password_value| can only come from a | |
102 // compromised renderer. | |
103 NOTREACHED(); | |
104 return; | |
105 } | |
106 PasswordStore* store = GetPasswordStore(); | |
Dan Beam
2014/08/26 17:39:07
when is |store| NULL?
jaekyeom
2014/08/27 12:28:54
I believe that it will be NULL during testing with
| |
107 if (!store) | |
108 return; | |
109 | |
110 GURL::Replacements replacements; | |
111 replacements.ClearUsername(); | |
112 replacements.ClearPassword(); | |
113 replacements.ClearQuery(); | |
114 replacements.ClearRef(); | |
115 autofill::PasswordForm form; | |
116 form.origin = origin.ReplaceComponents(replacements); | |
117 form.username_value = username_value; | |
118 form.password_value = password_value; | |
119 form.signon_realm = origin.GetOrigin().spec(); | |
120 form.ssl_valid = origin.SchemeIsSecure(); | |
121 form.date_created = base::Time::Now(); | |
122 | |
123 store->AddLogin(form); | |
124 #endif | |
125 } | |
126 | |
127 void PasswordManagerPresenter::UpdatePassword( | |
128 size_t index, | |
129 const base::string16& password_value) { | |
130 #if !defined(OS_ANDROID) // This is never called on Android. | |
Dan Beam
2014/08/26 17:39:06
same re: NOTREACHED()
jaekyeom
2014/08/27 12:28:53
Done.
| |
131 if (index >= password_list_.size() || password_value.empty()) { | |
132 // |index| out of bounds might come from a compromised renderer, don't let | |
133 // it crash the browser. http://crbug.com/362054 | |
134 // Similarly, empty |password_value| also might come from a compromised | |
135 // renderer. So use the same logic to prevent saving it. | |
136 NOTREACHED(); | |
137 return; | |
138 } | |
139 PasswordStore* store = GetPasswordStore(); | |
140 if (!store) | |
141 return; | |
142 autofill::PasswordForm form(*password_list_[index]); | |
143 form.password_value = password_value; | |
144 store->UpdateLogin(form); | |
145 #endif | |
146 } | |
147 | |
86 void PasswordManagerPresenter::RemoveSavedPassword(size_t index) { | 148 void PasswordManagerPresenter::RemoveSavedPassword(size_t index) { |
87 if (index >= password_list_.size()) { | 149 if (index >= password_list_.size()) { |
88 // |index| out of bounds might come from a compromised renderer, don't let | 150 // |index| out of bounds might come from a compromised renderer, don't let |
89 // it crash the browser. http://crbug.com/362054 | 151 // it crash the browser. http://crbug.com/362054 |
90 NOTREACHED(); | 152 NOTREACHED(); |
91 return; | 153 return; |
92 } | 154 } |
93 PasswordStore* store = GetPasswordStore(); | 155 PasswordStore* store = GetPasswordStore(); |
94 if (!store) | 156 if (!store) |
95 return; | 157 return; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 } | 294 } |
233 | 295 |
234 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 296 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
235 OnGetPasswordStoreResults( | 297 OnGetPasswordStoreResults( |
236 const std::vector<autofill::PasswordForm*>& results) { | 298 const std::vector<autofill::PasswordForm*>& results) { |
237 page_->password_exception_list_.clear(); | 299 page_->password_exception_list_.clear(); |
238 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 300 page_->password_exception_list_.insert(page_->password_exception_list_.end(), |
239 results.begin(), results.end()); | 301 results.begin(), results.end()); |
240 page_->SetPasswordExceptionList(); | 302 page_->SetPasswordExceptionList(); |
241 } | 303 } |
OLD | NEW |