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

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

Issue 166043006: Add password manager autocomplete suggestion when a username element in clicked. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated so first-click suggestions on password fields only shown if already autofilled Created 6 years, 10 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
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/autofill_agent.h" 5 #include "components/autofill/content/renderer/autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); 282 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url));
283 } 283 }
284 284
285 void AutofillAgent::setIgnoreTextChanges(bool ignore) { 285 void AutofillAgent::setIgnoreTextChanges(bool ignore) {
286 ignore_text_changes_ = ignore; 286 ignore_text_changes_ = ignore;
287 } 287 }
288 288
289 void AutofillAgent::InputElementClicked(const WebInputElement& element, 289 void AutofillAgent::InputElementClicked(const WebInputElement& element,
290 bool was_focused, 290 bool was_focused,
291 bool is_focused) { 291 bool is_focused) {
292 if (was_focused) 292 bool show_full_suggestion_list = element.isAutofilled();
293 ShowSuggestions(element, true, false, true, false); 293 bool show_password_suggestions_only = !was_focused;
294 ShowSuggestions(element,
295 true,
296 false,
297 true,
298 false,
299 show_full_suggestion_list,
300 show_password_suggestions_only);
294 } 301 }
295 302
296 void AutofillAgent::InputElementLostFocus() { 303 void AutofillAgent::InputElementLostFocus() {
297 HideAutofillUI(); 304 HideAutofillUI();
298 } 305 }
299 306
300 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { 307 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
301 password_autofill_agent_->TextFieldDidEndEditing(element); 308 password_autofill_agent_->TextFieldDidEndEditing(element);
302 has_shown_autofill_popup_for_current_edit_ = false; 309 has_shown_autofill_popup_for_current_edit_ = false;
303 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); 310 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id()));
(...skipping 28 matching lines...) Expand all
332 if (password_generation_agent_ && 339 if (password_generation_agent_ &&
333 password_generation_agent_->TextDidChangeInTextField(element)) { 340 password_generation_agent_->TextDidChangeInTextField(element)) {
334 return; 341 return;
335 } 342 }
336 343
337 if (password_autofill_agent_->TextDidChangeInTextField(element)) { 344 if (password_autofill_agent_->TextDidChangeInTextField(element)) {
338 element_ = element; 345 element_ = element;
339 return; 346 return;
340 } 347 }
341 348
342 ShowSuggestions(element, false, true, false, false); 349 ShowSuggestions(element, false, true, false, false, false, false);
343 350
344 FormData form; 351 FormData form;
345 FormFieldData field; 352 FormFieldData field;
346 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { 353 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) {
347 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, 354 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field,
348 base::TimeTicks::Now())); 355 base::TimeTicks::Now()));
349 } 356 }
350 } 357 }
351 358
352 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, 359 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element,
353 const WebKeyboardEvent& event) { 360 const WebKeyboardEvent& event) {
354 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { 361 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) {
355 element_ = element; 362 element_ = element;
356 return; 363 return;
357 } 364 }
358 365
359 if (event.windowsKeyCode == ui::VKEY_DOWN || 366 if (event.windowsKeyCode == ui::VKEY_DOWN ||
360 event.windowsKeyCode == ui::VKEY_UP) 367 event.windowsKeyCode == ui::VKEY_UP)
361 ShowSuggestions(element, true, true, true, false); 368 ShowSuggestions(element, true, true, true, false, false, false);
362 } 369 }
363 370
364 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { 371 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) {
365 ShowSuggestions(element, true, false, false, true); 372 ShowSuggestions(element, true, false, false, true, false, false);
366 } 373 }
367 374
368 void AutofillAgent::AcceptDataListSuggestion( 375 void AutofillAgent::AcceptDataListSuggestion(
369 const base::string16& suggested_value) { 376 const base::string16& suggested_value) {
370 base::string16 new_value = suggested_value; 377 base::string16 new_value = suggested_value;
371 // If this element takes multiple values then replace the last part with 378 // If this element takes multiple values then replace the last part with
372 // the suggestion. 379 // the suggestion.
373 if (element_.isMultiple() && 380 if (element_.isMultiple() &&
374 element_.formControlType() == WebString::fromUTF8("email")) { 381 element_.formControlType() == WebString::fromUTF8("email")) {
375 std::vector<base::string16> parts; 382 std::vector<base::string16> parts;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 in_flight_request_form_.reset(); 493 in_flight_request_form_.reset();
487 } 494 }
488 495
489 void AutofillAgent::OnPageShown() { 496 void AutofillAgent::OnPageShown() {
490 } 497 }
491 498
492 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 499 void AutofillAgent::ShowSuggestions(const WebInputElement& element,
493 bool autofill_on_empty_values, 500 bool autofill_on_empty_values,
494 bool requires_caret_at_end, 501 bool requires_caret_at_end,
495 bool display_warning_if_disabled, 502 bool display_warning_if_disabled,
496 bool datalist_only) { 503 bool datalist_only,
504 bool show_full_suggestion_list,
505 bool show_password_suggestions_only) {
497 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || 506 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() ||
498 element.isPasswordField()) 507 element.isPasswordField())
499 return; 508 return;
500 if (!datalist_only && !element.suggestedValue().isEmpty()) 509 if (!datalist_only && !element.suggestedValue().isEmpty())
501 return; 510 return;
502 511
503 // Don't attempt to autofill with values that are too large or if filling 512 // Don't attempt to autofill with values that are too large or if filling
504 // criteria are not met. 513 // criteria are not met.
505 WebString value = element.editingValue(); 514 WebString value = element.editingValue();
506 if (!datalist_only && 515 if (!datalist_only &&
507 (value.length() > kMaxDataLength || 516 (value.length() > kMaxDataLength ||
508 (!autofill_on_empty_values && value.isEmpty()) || 517 (!autofill_on_empty_values && value.isEmpty()) ||
509 (requires_caret_at_end && 518 (requires_caret_at_end &&
510 (element.selectionStart() != element.selectionEnd() || 519 (element.selectionStart() != element.selectionEnd() ||
511 element.selectionEnd() != static_cast<int>(value.length()))))) { 520 element.selectionEnd() != static_cast<int>(value.length()))))) {
512 // Any popup currently showing is obsolete. 521 // Any popup currently showing is obsolete.
513 HideAutofillUI(); 522 HideAutofillUI();
514 return; 523 return;
515 } 524 }
516 525
517 element_ = element; 526 element_ = element;
518 if (password_autofill_agent_->ShowSuggestions(element)) 527 if (password_autofill_agent_->ShowSuggestions(element,
528 show_full_suggestion_list) ||
529 show_password_suggestions_only)
519 return; 530 return;
520 531
521 // If autocomplete is disabled at the field level, ensure that the native 532 // If autocomplete is disabled at the field level, ensure that the native
522 // UI won't try to show a warning, since that may conflict with a custom 533 // UI won't try to show a warning, since that may conflict with a custom
523 // popup. Note that we cannot use the WebKit method element.autoComplete() 534 // popup. Note that we cannot use the WebKit method element.autoComplete()
524 // as it does not allow us to distinguish the case where autocomplete is 535 // as it does not allow us to distinguish the case where autocomplete is
525 // disabled for *both* the element and for the form. 536 // disabled for *both* the element and for the form.
526 const base::string16 autocomplete_attribute = 537 const base::string16 autocomplete_attribute =
527 element.getAttribute("autocomplete"); 538 element.getAttribute("autocomplete");
528 if (LowerCaseEqualsASCII(autocomplete_attribute, "off")) 539 if (LowerCaseEqualsASCII(autocomplete_attribute, "off"))
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // Only monitors dynamic forms created in the top frame. Dynamic forms 641 // Only monitors dynamic forms created in the top frame. Dynamic forms
631 // inserted in iframes are not captured yet. 642 // inserted in iframes are not captured yet.
632 if (!frame->parent()) { 643 if (!frame->parent()) {
633 password_autofill_agent_->OnDynamicFormsSeen(frame); 644 password_autofill_agent_->OnDynamicFormsSeen(frame);
634 return; 645 return;
635 } 646 }
636 } 647 }
637 } 648 }
638 649
639 } // namespace autofill 650 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698