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/net/gaia/gaia_urls.h" | 9 #include "chrome/common/net/gaia/gaia_urls.h" |
| 10 #include "chrome/common/password_generation_util.h" | 10 #include "chrome/common/password_generation_util.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; | |
| 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. |
|
Ilya Sherman
2012/08/18 00:44:40
This is definitely too lenient. How bad are false
Garrett Casto
2012/08/18 01:23:27
Pretty bad, in the sense that it's going to be ver
| |
| 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 } | |
|
Ilya Sherman
2012/08/18 00:44:40
nit: No need for curly braces for a one-line if-st
Garrett Casto
2012/08/18 01:23:27
Done.
| |
| 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 23 matching lines...) Expand all Loading... | |
| 85 // them. | 95 // them. |
| 86 if (!enabled_) | 96 if (!enabled_) |
| 87 return; | 97 return; |
| 88 | 98 |
| 89 if (!ShouldAnalyzeDocument(frame->document())) | 99 if (!ShouldAnalyzeDocument(frame->document())) |
| 90 return; | 100 return; |
| 91 | 101 |
| 92 WebKit::WebVector<WebKit::WebFormElement> forms; | 102 WebKit::WebVector<WebKit::WebFormElement> forms; |
| 93 frame->document().forms(forms); | 103 frame->document().forms(forms); |
| 94 for (size_t i = 0; i < forms.size(); ++i) { | 104 for (size_t i = 0; i < forms.size(); ++i) { |
| 95 // Ignore forms with autocomplete turned off for now. We may remove this in | 105 if (forms[i].isNull()) |
| 96 // the future, as we only want to avoid creating passwords if the signin | |
| 97 // form has autocomplete turned off. | |
| 98 if (forms[i].isNull() || !forms[i].autoComplete()) | |
|
Ilya Sherman
2012/08/18 00:44:40
autocomplete="off" actually means "don't remember
Garrett Casto
2012/08/18 01:23:27
If this is the case, do you know why so many accou
Ilya Sherman
2012/08/18 01:31:56
I suspect that you're correct that many account cr
| |
| 99 continue; | 106 continue; |
| 100 | 107 |
| 101 // If we can't get a valid PasswordForm, we skip this form because the | 108 // 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. | 109 // the password won't get saved even if we generate it. |
| 103 scoped_ptr<webkit::forms::PasswordForm> password_form( | 110 scoped_ptr<webkit::forms::PasswordForm> password_form( |
| 104 webkit::forms::PasswordFormDomManager::CreatePasswordForm(forms[i])); | 111 webkit::forms::PasswordFormDomManager::CreatePasswordForm(forms[i])); |
| 105 if (!password_form.get()) { | 112 if (!password_form.get()) { |
| 106 DVLOG(2) << "Invalid action on form"; | 113 DVLOG(2) << "Skipping form as it would not be saved"; |
| 107 continue; | 114 continue; |
| 108 } | 115 } |
| 109 | 116 |
| 110 // Do not generate password for GAIA since it is used to retrieve the | 117 // Do not generate password for GAIA since it is used to retrieve the |
| 111 // generated paswords. | 118 // generated paswords. |
| 112 GURL realm(password_form->signon_realm); | 119 GURL realm(password_form->signon_realm); |
| 113 if (realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm())) | 120 if (realm == GURL(GaiaUrls::GetInstance()->gaia_login_form_realm())) |
| 114 continue; | 121 continue; |
| 115 | 122 |
| 116 std::vector<WebKit::WebInputElement> passwords; | 123 std::vector<WebKit::WebInputElement> passwords; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 WebKit::WebCString PasswordGenerationManager::imageNameForDisabledState() { | 165 WebKit::WebCString PasswordGenerationManager::imageNameForDisabledState() { |
| 159 return imageNameForNormalState(); | 166 return imageNameForNormalState(); |
| 160 } | 167 } |
| 161 | 168 |
| 162 WebKit::WebCString PasswordGenerationManager::imageNameForReadOnlyState() { | 169 WebKit::WebCString PasswordGenerationManager::imageNameForReadOnlyState() { |
| 163 return imageNameForNormalState(); | 170 return imageNameForNormalState(); |
| 164 } | 171 } |
| 165 | 172 |
| 166 void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) { | 173 void PasswordGenerationManager::handleClick(WebKit::WebInputElement& element) { |
| 167 gfx::Rect rect(element.decorationElementFor(this).boundsInViewportSpace()); | 174 gfx::Rect rect(element.decorationElementFor(this).boundsInViewportSpace()); |
| 168 webkit::forms::PasswordForm* password_form( | 175 scoped_ptr<webkit::forms::PasswordForm> password_form( |
| 169 webkit::forms::PasswordFormDomManager::CreatePasswordForm( | 176 webkit::forms::PasswordFormDomManager::CreatePasswordForm( |
| 170 element.form())); | 177 element.form())); |
| 171 if (password_form) { | 178 if (password_form.get()) { |
| 172 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), | 179 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(routing_id(), |
| 173 rect, | 180 rect, |
| 174 element.maxLength(), | 181 element.maxLength(), |
| 175 *password_form)); | 182 *password_form)); |
| 176 password_generation::LogPasswordGenerationEvent( | 183 password_generation::LogPasswordGenerationEvent( |
| 177 password_generation::BUBBLE_SHOWN); | 184 password_generation::BUBBLE_SHOWN); |
| 185 } else { | |
| 186 // We should not have shown the icon in this case. | |
| 187 NOTREACHED(); | |
|
Ilya Sherman
2012/08/18 00:44:40
Write this as DCHECK(password_form.get()) and skip
Garrett Casto
2012/08/18 01:23:27
Done.
| |
| 178 } | 188 } |
| 179 } | 189 } |
| 180 | 190 |
| 181 void PasswordGenerationManager::willDetach( | 191 void PasswordGenerationManager::willDetach( |
| 182 const WebKit::WebInputElement& element) { | 192 const WebKit::WebInputElement& element) { |
| 183 // No implementation | 193 // No implementation |
| 184 } | 194 } |
| 185 | 195 |
| 186 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { | 196 bool PasswordGenerationManager::OnMessageReceived(const IPC::Message& message) { |
| 187 bool handled = true; | 197 bool handled = true; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 passwords_[0].decorationElementFor(this).setAttribute("style", | 245 passwords_[0].decorationElementFor(this).setAttribute("style", |
| 236 "display:block"); | 246 "display:block"); |
| 237 password_generation::LogPasswordGenerationEvent( | 247 password_generation::LogPasswordGenerationEvent( |
| 238 password_generation::ICON_SHOWN); | 248 password_generation::ICON_SHOWN); |
| 239 return; | 249 return; |
| 240 } | 250 } |
| 241 } | 251 } |
| 242 } | 252 } |
| 243 | 253 |
| 244 } // namespace autofill | 254 } // namespace autofill |
| OLD | NEW |