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) { | |
99 #if defined(OS_ANDROID) | |
100 NOTREACHED(); | |
101 #else | |
102 if (!CheckOriginValidityForAdding(origin) || password_value.empty()) { | |
103 // Invalid |origin| or empty |password_value| can only come from a | |
104 // compromised renderer. | |
105 NOTREACHED(); | |
106 return; | |
107 } | |
108 PasswordStore* store = GetPasswordStore(); | |
109 if (!store) | |
110 return; | |
111 | |
112 GURL::Replacements replacements; | |
113 replacements.ClearUsername(); | |
114 replacements.ClearPassword(); | |
115 replacements.ClearQuery(); | |
116 replacements.ClearRef(); | |
117 autofill::PasswordForm form; | |
118 form.origin = origin.ReplaceComponents(replacements); | |
119 form.username_value = username_value; | |
120 form.password_value = password_value; | |
121 form.signon_realm = origin.GetOrigin().spec(); | |
122 form.ssl_valid = origin.SchemeIsSecure(); | |
Dan Beam
2014/09/11 05:17:58
are all secure schemes SSL encrypted? does an HTT
jaekyeom
2014/09/12 10:35:58
Done.
I added the comment.
| |
123 form.date_created = base::Time::Now(); | |
124 | |
125 store->AddLogin(form); | |
126 #endif | |
127 } | |
128 | |
129 void PasswordManagerPresenter::UpdatePassword( | |
130 size_t index, | |
131 const base::string16& password_value) { | |
132 #if defined(OS_ANDROID) | |
133 NOTREACHED(); | |
134 #else | |
135 if (index >= password_list_.size() || password_value.empty()) { | |
136 // |index| out of bounds might come from a compromised renderer, don't let | |
137 // it crash the browser. http://crbug.com/362054 | |
138 // Similarly, empty |password_value| also might come from a compromised | |
139 // renderer. So use the same logic to prevent saving it. | |
140 NOTREACHED(); | |
141 return; | |
142 } | |
143 PasswordStore* store = GetPasswordStore(); | |
144 if (!store) | |
145 return; | |
146 autofill::PasswordForm form(*password_list_[index]); | |
147 form.password_value = password_value; | |
148 store->UpdateLogin(form); | |
149 #endif | |
150 } | |
151 | |
86 void PasswordManagerPresenter::RemoveSavedPassword(size_t index) { | 152 void PasswordManagerPresenter::RemoveSavedPassword(size_t index) { |
87 if (index >= password_list_.size()) { | 153 if (index >= password_list_.size()) { |
88 // |index| out of bounds might come from a compromised renderer, don't let | 154 // |index| out of bounds might come from a compromised renderer, don't let |
89 // it crash the browser. http://crbug.com/362054 | 155 // it crash the browser. http://crbug.com/362054 |
90 NOTREACHED(); | 156 NOTREACHED(); |
91 return; | 157 return; |
92 } | 158 } |
93 PasswordStore* store = GetPasswordStore(); | 159 PasswordStore* store = GetPasswordStore(); |
94 if (!store) | 160 if (!store) |
95 return; | 161 return; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 } | 298 } |
233 | 299 |
234 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 300 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
235 OnGetPasswordStoreResults( | 301 OnGetPasswordStoreResults( |
236 const std::vector<autofill::PasswordForm*>& results) { | 302 const std::vector<autofill::PasswordForm*>& results) { |
237 page_->password_exception_list_.clear(); | 303 page_->password_exception_list_.clear(); |
238 page_->password_exception_list_.insert(page_->password_exception_list_.end(), | 304 page_->password_exception_list_.insert(page_->password_exception_list_.end(), |
239 results.begin(), results.end()); | 305 results.begin(), results.end()); |
240 page_->SetPasswordExceptionList(); | 306 page_->SetPasswordExceptionList(); |
241 } | 307 } |
OLD | NEW |