Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/renderer/autofill/password_generation_manager.cc

Issue 10837324: Loosen up heuristics for detecting account creation forms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 size_t num_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 num_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() && num_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
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
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 we can't create a valid PasswordForm.
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698