Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/autofill/password_generation_manager.h" | 5 #include "chrome/renderer/autofill/password_generation_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/common/autofill_messages.h" | 8 #include "chrome/common/autofill_messages.h" |
| 9 #include "chrome/common/password_generation_util.h" | 9 #include "chrome/common/password_generation_util.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 // Returns true if we think that this form is for account creation. |passwords| | 27 // Returns true if we think that this form is for account creation. |passwords| |
| 28 // is filled with the password field(s) in the form. | 28 // is filled with the password field(s) in the form. |
| 29 bool GetAccountCreationPasswordFields( | 29 bool GetAccountCreationPasswordFields( |
| 30 const WebKit::WebFormElement& form, | 30 const WebKit::WebFormElement& form, |
| 31 std::vector<WebKit::WebInputElement>* passwords) { | 31 std::vector<WebKit::WebInputElement>* passwords) { |
| 32 // Grab all of the passwords for the form. | 32 // Grab all of the passwords for the form. |
| 33 WebKit::WebVector<WebKit::WebFormControlElement> control_elements; | 33 WebKit::WebVector<WebKit::WebFormControlElement> control_elements; |
| 34 form.getFormControlElements(control_elements); | 34 form.getFormControlElements(control_elements); |
| 35 | 35 |
| 36 int input_elements = 0; | |
|
Ilya Sherman
2012/09/10 21:23:49
nit: size_t
Ilya Sherman
2012/09/10 21:23:49
Optional nit: Perhaps |num_input_elements| or |inp
Garrett Casto
2012/09/10 21:44:23
Done.
Garrett Casto
2012/09/10 21:44:23
Done.
| |
| 36 for (size_t i = 0; i < control_elements.size(); i++) { | 37 for (size_t i = 0; i < control_elements.size(); i++) { |
| 37 WebKit::WebInputElement* input_element = | 38 WebKit::WebInputElement* input_element = |
| 38 toWebInputElement(&control_elements[i]); | 39 toWebInputElement(&control_elements[i]); |
| 39 // Only pay attention to visible password fields. | 40 // Only pay attention to visible password fields. |
| 40 if (input_element && | 41 if (input_element && |
| 41 input_element->isPasswordField() && | 42 input_element->isTextField() && |
| 42 input_element->hasNonEmptyBoundingBox()) { | 43 input_element->hasNonEmptyBoundingBox()) { |
| 43 passwords->push_back(*input_element); | 44 input_elements++; |
| 45 if (input_element->isPasswordField()) | |
| 46 passwords->push_back(*input_element); | |
| 44 } | 47 } |
| 45 } | 48 } |
| 46 | 49 |
| 47 // For now, just assume that if there are two password fields in the | 50 // This may be too lenient, but we assume that any form with at least three |
| 48 // form that this is meant for account creation. | 51 // input elements where at least one of them is a password is an account |
| 49 // TODO(gcasto): Determine better heauristics for this. | 52 // creation form. |
| 50 if (passwords->size() == 2) | 53 if (!passwords->empty() && input_elements >= 3) { |
| 54 // We trim |passwords| because occasionally there are forms where the | |
| 55 // security question answers are put in password fields and we don't want | |
| 56 // to fill those. | |
| 57 if (passwords->size() > 2) | |
| 58 passwords->resize(2); | |
| 59 | |
| 51 return true; | 60 return true; |
| 61 } | |
| 52 | 62 |
| 53 return false; | 63 return false; |
| 54 } | 64 } |
| 55 | 65 |
| 56 } // namespace | 66 } // namespace |
| 57 | 67 |
| 58 PasswordGenerationManager::PasswordGenerationManager( | 68 PasswordGenerationManager::PasswordGenerationManager( |
| 59 content::RenderView* render_view) | 69 content::RenderView* render_view) |
| 60 : content::RenderViewObserver(render_view), | 70 : content::RenderViewObserver(render_view), |
| 61 render_view_(render_view), | 71 render_view_(render_view), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 // the future, as we only want to avoid creating passwords if the signin | 106 // the future, as we only want to avoid creating passwords if the signin |
| 97 // form has autocomplete turned off. | 107 // form has autocomplete turned off. |
| 98 if (forms[i].isNull() || !forms[i].autoComplete()) | 108 if (forms[i].isNull() || !forms[i].autoComplete()) |
| 99 continue; | 109 continue; |
| 100 | 110 |
| 101 // If we can't get a valid PasswordForm, we skip this form because the | 111 // If we can't get a valid PasswordForm, we skip this form because the |
| 102 // the password won't get saved even if we generate it. | 112 // the password won't get saved even if we generate it. |
| 103 scoped_ptr<webkit::forms::PasswordForm> password_form( | 113 scoped_ptr<webkit::forms::PasswordForm> password_form( |
| 104 webkit::forms::PasswordFormDomManager::CreatePasswordForm(forms[i])); | 114 webkit::forms::PasswordFormDomManager::CreatePasswordForm(forms[i])); |
| 105 if (!password_form.get()) { | 115 if (!password_form.get()) { |
| 106 DVLOG(2) << "Invalid action on form"; | 116 DVLOG(2) << "Skipping form as it would not be saved"; |
| 107 continue; | 117 continue; |
| 108 } | 118 } |
| 109 | 119 |
| 110 // Do not generate password for GAIA since it is used to retrieve the | 120 // Do not generate password for GAIA since it is used to retrieve the |
| 111 // generated paswords. | 121 // generated paswords. |
| 112 GURL realm(password_form->signon_realm); | 122 GURL realm(password_form->signon_realm); |
| 113 if (realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm())) | 123 if (realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm())) |
| 114 continue; | 124 continue; |
| 115 | 125 |
| 116 std::vector<WebKit::WebInputElement> passwords; | 126 std::vector<WebKit::WebInputElement> passwords; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 | 171 |
| 162 WebKit::WebCString PasswordGenerationManager::imageNameForReadOnlyState() { | 172 WebKit::WebCString PasswordGenerationManager::imageNameForReadOnlyState() { |
| 163 return imageNameForNormalState(); | 173 return imageNameForNormalState(); |
| 164 } | 174 } |
| 165 | 175 |
| 166 void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) { | 176 void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) { |
| 167 gfx::Rect rect(element.decorationElementFor(this).boundsInViewportSpace()); | 177 gfx::Rect rect(element.decorationElementFor(this).boundsInViewportSpace()); |
| 168 scoped_ptr<webkit::forms::PasswordForm> password_form( | 178 scoped_ptr<webkit::forms::PasswordForm> password_form( |
| 169 webkit::forms::PasswordFormDomManager::CreatePasswordForm( | 179 webkit::forms::PasswordFormDomManager::CreatePasswordForm( |
| 170 element.form())); | 180 element.form())); |
| 171 if (password_form.get()) { | 181 // We should not have shown the icon in this case. |
|
Ilya Sherman
2012/09/10 21:23:49
nit: What case does "in this case" refer to? Coul
Garrett Casto
2012/09/10 21:44:23
Done.
| |
| 172 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), | 182 DCHECK(password_form.get()); |
| 173 rect, | 183 |
| 174 element.maxLength(), | 184 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), |
| 175 *password_form)); | 185 rect, |
| 176 password_generation::LogPasswordGenerationEvent( | 186 element.maxLength(), |
| 177 password_generation::BUBBLE_SHOWN); | 187 *password_form)); |
| 178 } | 188 password_generation::LogPasswordGenerationEvent( |
| 189 password_generation::BUBBLE_SHOWN); | |
| 179 } | 190 } |
| 180 | 191 |
| 181 void PasswordGenerationManager::willDetach( | 192 void PasswordGenerationManager::willDetach( |
| 182 const WebKit::WebInputElement& element) { | 193 const WebKit::WebInputElement& element) { |
| 183 // No implementation | 194 // No implementation |
| 184 } | 195 } |
| 185 | 196 |
| 186 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { | 197 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { |
| 187 bool handled = true; | 198 bool handled = true; |
| 188 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) | 199 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationManager, message) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 passwords_[0].decorationElementFor(this).setAttribute("style", | 246 passwords_[0].decorationElementFor(this).setAttribute("style", |
| 236 "display:block"); | 247 "display:block"); |
| 237 password_generation::LogPasswordGenerationEvent( | 248 password_generation::LogPasswordGenerationEvent( |
| 238 password_generation::ICON_SHOWN); | 249 password_generation::ICON_SHOWN); |
| 239 return; | 250 return; |
| 240 } | 251 } |
| 241 } | 252 } |
| 242 } | 253 } |
| 243 | 254 |
| 244 } // namespace autofill | 255 } // namespace autofill |
| OLD | NEW |