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

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

Issue 1099033004: Add a text/password field count metric for empty username forms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Superfluous include Created 5 years, 7 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/metrics/histogram.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "components/autofill/content/renderer/form_autofill_util.h" 13 #include "components/autofill/content/renderer/form_autofill_util.h"
13 #include "components/autofill/core/common/form_data_predictions.h" 14 #include "components/autofill/core/common/form_data_predictions.h"
14 #include "components/autofill/core/common/password_form.h" 15 #include "components/autofill/core/common/password_form.h"
15 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 17 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebFormControlElement.h" 18 #include "third_party/WebKit/public/web/WebFormControlElement.h"
18 #include "third_party/WebKit/public/web/WebInputElement.h" 19 #include "third_party/WebKit/public/web/WebInputElement.h"
19 #include "third_party/icu/source/i18n/unicode/regex.h" 20 #include "third_party/icu/source/i18n/unicode/regex.h"
20 21
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 PasswordForm* password_form, 233 PasswordForm* password_form,
233 const std::map<const blink::WebInputElement, blink::WebString>* 234 const std::map<const blink::WebInputElement, blink::WebString>*
234 nonscript_modified_values, 235 nonscript_modified_values,
235 const std::map<autofill::FormData, autofill::FormFieldData>* 236 const std::map<autofill::FormData, autofill::FormFieldData>*
236 form_predictions) { 237 form_predictions) {
237 WebInputElement latest_input_element; 238 WebInputElement latest_input_element;
238 WebInputElement username_element; 239 WebInputElement username_element;
239 password_form->username_marked_by_site = false; 240 password_form->username_marked_by_site = false;
240 std::vector<WebInputElement> passwords; 241 std::vector<WebInputElement> passwords;
241 std::vector<base::string16> other_possible_usernames; 242 std::vector<base::string16> other_possible_usernames;
243 int num_text_and_password_fields = 0;
242 244
243 WebVector<WebFormControlElement> control_elements; 245 WebVector<WebFormControlElement> control_elements;
244 form.getFormControlElements(control_elements); 246 form.getFormControlElements(control_elements);
245 247
246 std::string layout_sequence; 248 std::string layout_sequence;
247 layout_sequence.reserve(control_elements.size()); 249 layout_sequence.reserve(control_elements.size());
248 for (size_t i = 0; i < control_elements.size(); ++i) { 250 for (size_t i = 0; i < control_elements.size(); ++i) {
249 WebFormControlElement control_element = control_elements[i]; 251 WebFormControlElement control_element = control_elements[i];
250 if (control_element.isActivatedSubmit()) 252 if (control_element.isActivatedSubmit())
251 password_form->submit_element = control_element.formControlName(); 253 password_form->submit_element = control_element.formControlName();
252 254
253 WebInputElement* input_element = toWebInputElement(&control_element); 255 WebInputElement* input_element = toWebInputElement(&control_element);
254 if (!input_element || !input_element->isEnabled()) 256 if (!input_element || !input_element->isEnabled())
255 continue; 257 continue;
256 258
257 if (input_element->isTextField()) { 259 if (input_element->isTextField()) {
258 if (input_element->isPasswordField()) 260 if (input_element->isPasswordField())
259 layout_sequence.push_back('P'); 261 layout_sequence.push_back('P');
260 else 262 else
261 layout_sequence.push_back('N'); 263 layout_sequence.push_back('N');
264
265 // Count the total number of text and password fields. Note that
vabr (Chromium) 2015/05/12 10:26:02 nit: The comment is clear and correct, but probabl
msramek 2015/05/12 10:50:44 Acknowledged.
266 // in renderer, |PasswordInputType| is a subclass of |TextFieldInputType|,
267 // but for consistency with the rest of the code we use the term "text"
268 // to refer specifically to a non-password text field.
269 ++num_text_and_password_fields;
262 } 270 }
263 271
264 // If the password field is readonly, the page is likely using a virtual 272 // If the password field is readonly, the page is likely using a virtual
265 // keyboard and bypassing the password field value (see 273 // keyboard and bypassing the password field value (see
266 // http://crbug.com/475488). There is nothing Chrome can do to fill 274 // http://crbug.com/475488). There is nothing Chrome can do to fill
267 // passwords for now. 275 // passwords for now.
268 if (input_element->isPasswordField() && 276 if (input_element->isPasswordField() &&
269 (!input_element->isReadOnly() || 277 (!input_element->isReadOnly() ||
270 HasAutocompleteAttributeValue(*input_element, "current_password") || 278 HasAutocompleteAttributeValue(*input_element, "current_password") ||
271 HasAutocompleteAttributeValue(*input_element, "new-password"))) { 279 HasAutocompleteAttributeValue(*input_element, "new-password"))) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 base::string16 typed_username_value = username_iterator->second; 369 base::string16 typed_username_value = username_iterator->second;
362 if (!StartsWith(username_value, typed_username_value, false)) { 370 if (!StartsWith(username_value, typed_username_value, false)) {
363 // We check that |username_value| was not obtained by autofilling 371 // We check that |username_value| was not obtained by autofilling
364 // |typed_username_value|. In case when it was, |typed_username_value| 372 // |typed_username_value|. In case when it was, |typed_username_value|
365 // is incomplete, so we should leave autofilled value. 373 // is incomplete, so we should leave autofilled value.
366 username_value = typed_username_value; 374 username_value = typed_username_value;
367 } 375 }
368 } 376 }
369 } 377 }
370 password_form->username_value = username_value; 378 password_form->username_value = username_value;
379 } else {
vabr (Chromium) 2015/05/12 10:26:02 Do you want to report this even if there are not p
msramek 2015/05/12 10:50:44 Do you mean no password fields found? No. But if I
vabr (Chromium) 2015/05/12 11:06:11 Yes, sorry for the confusion, I meant password fie
msramek 2015/05/12 11:27:03 Interesting. I would expect none of this code to t
vabr (Chromium) 2015/05/12 11:33:58 This has the caveat that you won't get this count
msramek 2015/05/12 12:13:47 I know. But in this case the password manager will
380 // To get a better idea on how forms without a username field look like,
381 // report the total number of text and password fields.
382 UMA_HISTOGRAM_COUNTS_100(
383 "PasswordManager.EmptyUsernames.TextAndPasswordFieldCount",
384 num_text_and_password_fields);
vabr (Chromium) 2015/05/12 10:26:02 Alternatively, you can use layout_sequence.size().
msramek 2015/05/12 10:50:44 No, let's use layout_sequence.size(). I just reall
371 } 385 }
372 386
373 WebInputElement password; 387 WebInputElement password;
374 WebInputElement new_password; 388 WebInputElement new_password;
375 if (!LocateSpecificPasswords(passwords, &password, &new_password)) 389 if (!LocateSpecificPasswords(passwords, &password, &new_password))
376 return; 390 return;
377 391
378 password_form->action = GetCanonicalActionForForm(form); 392 password_form->action = GetCanonicalActionForForm(form);
379 if (!password_form->action.is_valid()) 393 if (!password_form->action.is_valid())
380 return; 394 return;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 WebFormElementToFormData(web_form, 470 WebFormElementToFormData(web_form,
457 blink::WebFormControlElement(), 471 blink::WebFormControlElement(),
458 EXTRACT_NONE, 472 EXTRACT_NONE,
459 &password_form->form_data, 473 &password_form->form_data,
460 NULL /* FormFieldData */); 474 NULL /* FormFieldData */);
461 475
462 return password_form.Pass(); 476 return password_form.Pass();
463 } 477 }
464 478
465 } // namespace autofill 479 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698