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

Side by Side Diff: components/autofill/content/renderer/password_form_conversion_utils.cc

Issue 1028163002: Processing USERNAME reply from Autofill server in Password Manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test and changed sending message Created 5 years, 9 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
OLDNEW
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_form_conversion_utils.h" 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
6 6
vabr (Chromium) 2015/03/25 10:12:33 Here you should #include <vector>.
vabr (Chromium) 2015/03/26 09:43:55 Ping.
dvadym 2015/03/26 12:29:12 Done.
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "components/autofill/content/renderer/form_autofill_util.h" 8 #include "components/autofill/content/renderer/form_autofill_util.h"
9 #include "components/autofill/core/common/form_data_predictions.h"
9 #include "components/autofill/core/common/password_form.h" 10 #include "components/autofill/core/common/password_form.h"
10 #include "third_party/WebKit/public/platform/WebString.h" 11 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/web/WebDocument.h" 12 #include "third_party/WebKit/public/web/WebDocument.h"
12 #include "third_party/WebKit/public/web/WebFormControlElement.h" 13 #include "third_party/WebKit/public/web/WebFormControlElement.h"
13 #include "third_party/WebKit/public/web/WebInputElement.h" 14 #include "third_party/WebKit/public/web/WebInputElement.h"
14 15
15 using blink::WebDocument; 16 using blink::WebDocument;
16 using blink::WebFormControlElement; 17 using blink::WebFormControlElement;
17 using blink::WebFormElement; 18 using blink::WebFormElement;
18 using blink::WebInputElement; 19 using blink::WebInputElement;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 *new_password = passwords[0]; 101 *new_password = passwords[0];
101 } else { 102 } else {
102 // Three different passwords, or first and last match with middle 103 // Three different passwords, or first and last match with middle
103 // different. No idea which is which, so no luck. 104 // different. No idea which is which, so no luck.
104 return false; 105 return false;
105 } 106 }
106 } 107 }
107 return true; 108 return true;
108 } 109 }
109 110
111 void FindPredictedUsernameElement(
112 const WebFormElement& form,
113 const std::map<autofill::FormData, autofill::FormFieldData>*
vabr (Chromium) 2015/03/25 10:12:33 I suggest changing this to a const reference, and
dvadym 2015/03/25 16:34:08 Done.
114 form_predictions,
115 WebVector<WebFormControlElement>* control_elements,
116 WebInputElement& predicted_username_element) {
117 if (!form_predictions)
118 return;
119
120 FormData form_data;
121 if (!WebFormElementToFormData(form, WebFormControlElement(), REQUIRE_NONE,
122 EXTRACT_NONE, &form_data, nullptr))
123 return;
124
125 // Prediction forms are not user submitted, but |form| can be user submitted.
126 // We don't care about this flag for finding predictions, so set it to false.
127 form_data.user_submitted = false;
128 auto predictions_iterator = form_predictions->find(form_data);
129 if (predictions_iterator == form_predictions->end())
130 return;
131
132 std::vector<blink::WebFormControlElement> autofillable_elements =
133 ExtractAutofillableElementsFromSet(*control_elements, REQUIRE_NONE);
134 if (autofillable_elements.size() != form_data.fields.size()) {
135 NOTREACHED();
vabr (Chromium) 2015/03/25 10:12:33 Did you mean DCHECK_EQ(autofillable_elements.size(
dvadym 2015/03/25 16:34:08 Thanks, I didn't know about DCHECK_EQ
136 }
137
138 const autofill::FormFieldData& username_field = predictions_iterator->second;
139 autofill::FormFieldData form_field;
140 for (size_t i = 0; i < autofillable_elements.size(); ++i) {
141 if (form_data.fields[i].SameFieldAs(username_field)) {
142 predicted_username_element =
143 *toWebInputElement(&autofillable_elements[i]);
144 break;
145 }
146 }
147 }
148
110 // Get information about a login form encapsulated in a PasswordForm struct. 149 // Get information about a login form encapsulated in a PasswordForm struct.
111 // If an element of |form| has an entry in |nonscript_modified_values|, the 150 // If an element of |form| has an entry in |nonscript_modified_values|, the
112 // associated string is used instead of the element's value to create 151 // associated string is used instead of the element's value to create
113 // the PasswordForm. 152 // the PasswordForm.
114 void GetPasswordForm( 153 void GetPasswordForm(
115 const WebFormElement& form, 154 const WebFormElement& form,
116 PasswordForm* password_form, 155 PasswordForm* password_form,
117 const std::map<const blink::WebInputElement, blink::WebString>* 156 const std::map<const blink::WebInputElement, blink::WebString>*
118 nonscript_modified_values) { 157 nonscript_modified_values,
158 const std::map<autofill::FormData, autofill::FormFieldData>*
159 form_predictions) {
119 WebInputElement latest_input_element; 160 WebInputElement latest_input_element;
120 WebInputElement username_element; 161 WebInputElement username_element;
121 password_form->username_marked_by_site = false; 162 password_form->username_marked_by_site = false;
122 std::vector<WebInputElement> passwords; 163 std::vector<WebInputElement> passwords;
123 std::vector<base::string16> other_possible_usernames; 164 std::vector<base::string16> other_possible_usernames;
124 165
125 WebVector<WebFormControlElement> control_elements; 166 WebVector<WebFormControlElement> control_elements;
126 form.getFormControlElements(control_elements); 167 form.getFormControlElements(control_elements);
127 168
128 for (size_t i = 0; i < control_elements.size(); ++i) { 169 for (size_t i = 0; i < control_elements.size(); ++i) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // alternative, at least for now. 229 // alternative, at least for now.
189 if (username_element.isNull()) 230 if (username_element.isNull())
190 latest_input_element = *input_element; 231 latest_input_element = *input_element;
191 if (!input_element->value().isEmpty()) 232 if (!input_element->value().isEmpty())
192 other_possible_usernames.push_back(input_element->value()); 233 other_possible_usernames.push_back(input_element->value());
193 } 234 }
194 } 235 }
195 } 236 }
196 } 237 }
197 238
239 WebInputElement predicted_username_element;
vabr (Chromium) 2015/03/25 10:12:33 For performance reasons, I would also recommend pu
dvadym 2015/03/25 16:34:07 After offline discussing, it was decided to leave
240 FindPredictedUsernameElement(form, form_predictions, &control_elements,
vabr (Chromium) 2015/03/25 10:12:33 Following up on my comment on line 113, I suggest
dvadym 2015/03/25 16:34:07 Done.
241 predicted_username_element);
242 if (!predicted_username_element.isNull()) {
243 username_element = predicted_username_element;
244 password_form->parsed_using_autofill_predictions = true;
245 }
246
198 if (!username_element.isNull()) { 247 if (!username_element.isNull()) {
199 password_form->username_element = username_element.nameForAutofill(); 248 password_form->username_element = username_element.nameForAutofill();
200 base::string16 username_value = username_element.value(); 249 base::string16 username_value = username_element.value();
201 if (nonscript_modified_values != nullptr) { 250 if (nonscript_modified_values != nullptr) {
202 auto username_iterator = 251 auto username_iterator =
203 nonscript_modified_values->find(username_element); 252 nonscript_modified_values->find(username_element);
204 if (username_iterator != nonscript_modified_values->end()) { 253 if (username_iterator != nonscript_modified_values->end()) {
205 base::string16 typed_username_value = username_iterator->second; 254 base::string16 typed_username_value = username_iterator->second;
206 if (!StartsWith(username_value, typed_username_value, false)) { 255 if (!StartsWith(username_value, typed_username_value, false)) {
207 // We check that |username_value| was not obtained by autofilling 256 // We check that |username_value| was not obtained by autofilling
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 password_form->preferred = false; 315 password_form->preferred = false;
267 password_form->blacklisted_by_user = false; 316 password_form->blacklisted_by_user = false;
268 password_form->type = PasswordForm::TYPE_MANUAL; 317 password_form->type = PasswordForm::TYPE_MANUAL;
269 } 318 }
270 319
271 } // namespace 320 } // namespace
272 321
273 scoped_ptr<PasswordForm> CreatePasswordForm( 322 scoped_ptr<PasswordForm> CreatePasswordForm(
274 const WebFormElement& web_form, 323 const WebFormElement& web_form,
275 const std::map<const blink::WebInputElement, blink::WebString>* 324 const std::map<const blink::WebInputElement, blink::WebString>*
276 nonscript_modified_values) { 325 nonscript_modified_values,
326 const std::map<autofill::FormData, autofill::FormFieldData>*
327 form_predictions) {
277 if (web_form.isNull()) 328 if (web_form.isNull())
278 return scoped_ptr<PasswordForm>(); 329 return scoped_ptr<PasswordForm>();
279 330
280 scoped_ptr<PasswordForm> password_form(new PasswordForm()); 331 scoped_ptr<PasswordForm> password_form(new PasswordForm());
281 GetPasswordForm(web_form, password_form.get(), nonscript_modified_values); 332 GetPasswordForm(web_form, password_form.get(), nonscript_modified_values,
333 form_predictions);
282 334
283 if (!password_form->action.is_valid()) 335 if (!password_form->action.is_valid())
284 return scoped_ptr<PasswordForm>(); 336 return scoped_ptr<PasswordForm>();
285 337
286 WebFormElementToFormData(web_form, 338 WebFormElementToFormData(web_form,
287 blink::WebFormControlElement(), 339 blink::WebFormControlElement(),
288 REQUIRE_NONE, 340 REQUIRE_NONE,
289 EXTRACT_NONE, 341 EXTRACT_NONE,
290 &password_form->form_data, 342 &password_form->form_data,
291 NULL /* FormFieldData */); 343 NULL /* FormFieldData */);
292 344
293 return password_form.Pass(); 345 return password_form.Pass();
294 } 346 }
295 347
296 } // namespace autofill 348 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698