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 "components/autofill/content/renderer/password_generation_manager.h" | 5 #include "components/autofill/content/renderer/password_generation_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "components/autofill/core/common/autofill_messages.h" | 8 #include "components/autofill/core/common/autofill_messages.h" |
9 #include "components/autofill/core/common/password_generation_util.h" | 9 #include "components/autofill/core/common/password_generation_util.h" |
10 #include "content/public/renderer/password_form_conversion_utils.h" | 10 #include "content/public/renderer/password_form_conversion_utils.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 void PasswordGenerationManager::DidFinishDocumentLoad(WebKit::WebFrame* frame) { | 78 void PasswordGenerationManager::DidFinishDocumentLoad(WebKit::WebFrame* frame) { |
79 // In every navigation, the IPC message sent by the password autofill manager | 79 // In every navigation, the IPC message sent by the password autofill manager |
80 // to query whether the current form is blacklisted or not happens when the | 80 // to query whether the current form is blacklisted or not happens when the |
81 // document load finishes, so we need to clear previous states here before we | 81 // document load finishes, so we need to clear previous states here before we |
82 // hear back from the browser. We only clear this state on main frame load | 82 // hear back from the browser. We only clear this state on main frame load |
83 // as we don't want subframe loads to clear state that we have recieved from | 83 // as we don't want subframe loads to clear state that we have recieved from |
84 // the main frame. Note that we assume there is only one account creation | 84 // the main frame. Note that we assume there is only one account creation |
85 // form, but there could be multiple password forms in each frame. | 85 // form, but there could be multiple password forms in each frame. |
86 if (!frame->parent()) { | 86 if (!frame->parent()) { |
87 not_blacklisted_password_form_origins_.clear(); | 87 not_blacklisted_password_form_origins_.clear(); |
88 autofill_account_creation_form_origins_.clear(); | |
88 // Initialize to an empty and invalid GURL. | 89 // Initialize to an empty and invalid GURL. |
89 account_creation_form_origin_ = GURL(); | 90 account_creation_form_origin_ = GURL(); |
90 passwords_.clear(); | 91 passwords_.clear(); |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 void PasswordGenerationManager::DidFinishLoad(WebKit::WebFrame* frame) { | 95 void PasswordGenerationManager::DidFinishLoad(WebKit::WebFrame* frame) { |
95 // We don't want to generate passwords if the browser won't store or sync | 96 // We don't want to generate passwords if the browser won't store or sync |
96 // them. | 97 // them. |
97 if (!enabled_) | 98 if (!enabled_) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 | 170 |
170 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { | 171 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { |
171 bool handled = true; | 172 bool handled = true; |
172 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) | 173 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) |
173 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, | 174 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, |
174 OnFormNotBlacklisted) | 175 OnFormNotBlacklisted) |
175 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, | 176 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, |
176 OnPasswordAccepted) | 177 OnPasswordAccepted) |
177 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, | 178 IPC_MESSAGE_HANDLER(AutofillMsg_PasswordGenerationEnabled, |
178 OnPasswordGenerationEnabled) | 179 OnPasswordGenerationEnabled) |
180 IPC_MESSAGE_HANDLER(AutofillMsg_AccountCreationFormsDetected, | |
181 OnAccountCreationFormsDetected) | |
179 IPC_MESSAGE_UNHANDLED(handled = false) | 182 IPC_MESSAGE_UNHANDLED(handled = false) |
180 IPC_END_MESSAGE_MAP() | 183 IPC_END_MESSAGE_MAP() |
181 return handled; | 184 return handled; |
182 } | 185 } |
183 | 186 |
184 void PasswordGenerationManager::OnFormNotBlacklisted( | 187 void PasswordGenerationManager::OnFormNotBlacklisted( |
185 const content::PasswordForm& form) { | 188 const content::PasswordForm& form) { |
186 not_blacklisted_password_form_origins_.push_back(form.origin); | 189 not_blacklisted_password_form_origins_.push_back(form.origin); |
187 MaybeShowIcon(); | 190 MaybeShowIcon(); |
188 } | 191 } |
189 | 192 |
190 void PasswordGenerationManager::OnPasswordAccepted( | 193 void PasswordGenerationManager::OnPasswordAccepted( |
191 const base::string16& password) { | 194 const base::string16& password) { |
192 for (std::vector<WebKit::WebInputElement>::iterator it = passwords_.begin(); | 195 for (std::vector<WebKit::WebInputElement>::iterator it = passwords_.begin(); |
193 it != passwords_.end(); ++it) { | 196 it != passwords_.end(); ++it) { |
194 it->setValue(password); | 197 it->setValue(password); |
195 it->setAutofilled(true); | 198 it->setAutofilled(true); |
196 // Advance focus to the next input field. We assume password fields in | 199 // Advance focus to the next input field. We assume password fields in |
197 // an account creation form are always adjacent. | 200 // an account creation form are always adjacent. |
198 render_view_->GetWebView()->advanceFocus(false); | 201 render_view_->GetWebView()->advanceFocus(false); |
199 } | 202 } |
200 } | 203 } |
201 | 204 |
202 void PasswordGenerationManager::OnPasswordGenerationEnabled(bool enabled) { | 205 void PasswordGenerationManager::OnPasswordGenerationEnabled(bool enabled) { |
203 enabled_ = enabled; | 206 enabled_ = enabled; |
204 } | 207 } |
205 | 208 |
209 void PasswordGenerationManager::OnAccountCreationFormsDetected( | |
210 const std::vector<GURL>& origins) { | |
211 autofill_account_creation_form_origins_.insert( | |
212 autofill_account_creation_form_origins_.begin(), | |
213 origins.begin(), | |
214 origins.end()); | |
Ilya Sherman
2013/08/29 23:08:13
Is it expected to be possible that autofill_acount
zysxqn
2013/09/03 23:00:20
I'm not 100% sure about the flow but account_creat
| |
215 MaybeShowIcon(); | |
216 } | |
217 | |
206 void PasswordGenerationManager::MaybeShowIcon() { | 218 void PasswordGenerationManager::MaybeShowIcon() { |
207 // We should show the password generation icon only when we have detected | 219 // We should show the password generation icon only when we have detected |
208 // account creation form and we have confirmed from browser that this form | 220 // account creation form, we have confirmed from browser that this form |
209 // is not blacklisted by the users. | 221 // is not blacklisted by the users, and the autofill server has marked one |
Ilya Sherman
2013/08/29 23:08:13
nit: "autofill" -> "Autofill"
zysxqn
2013/09/03 23:00:20
Done.
| |
222 // of its field as ACCOUNT_CREATION_PASSWORD. | |
210 if (!account_creation_form_origin_.is_valid() || | 223 if (!account_creation_form_origin_.is_valid() || |
211 passwords_.empty() || | 224 passwords_.empty() || |
212 not_blacklisted_password_form_origins_.empty()) { | 225 not_blacklisted_password_form_origins_.empty() || |
226 autofill_account_creation_form_origins_.empty()) { | |
213 return; | 227 return; |
214 } | 228 } |
215 | 229 |
230 bool not_blacklisted = false; | |
216 for (std::vector<GURL>::iterator it = | 231 for (std::vector<GURL>::iterator it = |
217 not_blacklisted_password_form_origins_.begin(); | 232 not_blacklisted_password_form_origins_.begin(); |
218 it != not_blacklisted_password_form_origins_.end(); ++it) { | 233 it != not_blacklisted_password_form_origins_.end(); ++it) { |
219 if (*it == account_creation_form_origin_) { | 234 if (*it == account_creation_form_origin_) { |
220 passwords_[0].passwordGeneratorButtonElement().setAttribute("style", | 235 not_blacklisted = true; |
221 "display:block"); | 236 break; |
222 password_generation::LogPasswordGenerationEvent( | |
223 password_generation::ICON_SHOWN); | |
224 return; | |
225 } | 237 } |
226 } | 238 } |
Ilya Sherman
2013/08/29 23:08:13
nit: I'd write this as an early return using a wra
zysxqn
2013/09/03 23:00:20
Done.
| |
239 | |
240 bool is_autofill_account_creation_form = false; | |
241 for (std::vector<GURL>::iterator it = | |
242 autofill_account_creation_form_origins_.begin(); | |
243 it != autofill_account_creation_form_origins_.end(); ++it) { | |
244 if (*it == account_creation_form_origin_) { | |
245 is_autofill_account_creation_form = true; | |
246 break; | |
247 } | |
248 } | |
249 | |
250 if (not_blacklisted && is_autofill_account_creation_form) { | |
251 passwords_[0].passwordGeneratorButtonElement().setAttribute( | |
252 "style", "display:block"); | |
253 password_generation::LogPasswordGenerationEvent( | |
254 password_generation::ICON_SHOWN); | |
255 } | |
227 } | 256 } |
228 | 257 |
229 } // namespace autofill | 258 } // namespace autofill |
OLD | NEW |