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

Side by Side Diff: components/autofill/content/renderer/password_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: Readded inline autocomplete 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/password_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 if (!element.isText() || !IsElementAutocompletable(element) || 264 if (!element.isText() || !IsElementAutocompletable(element) ||
265 !IsElementAutocompletable(password)) { 265 !IsElementAutocompletable(password)) {
266 return false; 266 return false;
267 } 267 }
268 268
269 // Don't inline autocomplete if the user is deleting, that would be confusing. 269 // Don't inline autocomplete if the user is deleting, that would be confusing.
270 // But refresh the popup. Note, since this is ours, return true to signal 270 // But refresh the popup. Note, since this is ours, return true to signal
271 // no further processing is required. 271 // no further processing is required.
272 if (iter->second.backspace_pressed_last) { 272 if (iter->second.backspace_pressed_last) {
273 ShowSuggestionPopup(iter->second.fill_data, username); 273 ShowSuggestionPopup(iter->second.fill_data, username, false);
274 return true; 274 return true;
275 } 275 }
276 276
277 blink::WebString name = element.nameForAutofill(); 277 blink::WebString name = element.nameForAutofill();
278 if (name.isEmpty()) 278 if (name.isEmpty())
279 return false; // If the field has no name, then we won't have values. 279 return false; // If the field has no name, then we won't have values.
280 280
281 // Don't attempt to autofill with values that are too large. 281 // Don't attempt to autofill with values that are too large.
282 if (element.value().length() > kMaximumTextSizeForAutocomplete) 282 if (element.value().length() > kMaximumTextSizeForAutocomplete)
283 return false; 283 return false;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 322 }
323 323
324 bool PasswordAutofillAgent::DidClearAutofillSelection( 324 bool PasswordAutofillAgent::DidClearAutofillSelection(
325 const blink::WebNode& node) { 325 const blink::WebNode& node) {
326 blink::WebInputElement input; 326 blink::WebInputElement input;
327 PasswordInfo password; 327 PasswordInfo password;
328 return FindLoginInfo(node, &input, &password); 328 return FindLoginInfo(node, &input, &password);
329 } 329 }
330 330
331 bool PasswordAutofillAgent::ShowSuggestions( 331 bool PasswordAutofillAgent::ShowSuggestions(
332 const blink::WebInputElement& element) { 332 const blink::WebInputElement& element,
333 bool show_all) {
333 LoginToPasswordInfoMap::const_iterator iter = 334 LoginToPasswordInfoMap::const_iterator iter =
334 login_to_password_info_.find(element); 335 login_to_password_info_.find(element);
335 if (iter == login_to_password_info_.end()) 336 if (iter == login_to_password_info_.end())
336 return false; 337 return false;
337 338
338 // If autocomplete='off' is set on the form elements, no suggestion dialog 339 // If autocomplete='off' is set on the form elements, no suggestion dialog
339 // should be shown. However, return |true| to indicate that this is a known 340 // should be shown. However, return |true| to indicate that this is a known
340 // password form and that the request to show suggestions has been handled (as 341 // password form and that the request to show suggestions has been handled (as
341 // a no-op). 342 // a no-op).
342 if (!IsElementAutocompletable(element) || 343 if (!IsElementAutocompletable(element) ||
343 !IsElementAutocompletable(iter->second.password_field)) 344 !IsElementAutocompletable(iter->second.password_field))
344 return true; 345 return true;
345 346
346 return ShowSuggestionPopup(iter->second.fill_data, element); 347 return ShowSuggestionPopup(iter->second.fill_data, element, show_all);
347 } 348 }
348 349
349 bool PasswordAutofillAgent::OriginCanAccessPasswordManager( 350 bool PasswordAutofillAgent::OriginCanAccessPasswordManager(
350 const blink::WebSecurityOrigin& origin) { 351 const blink::WebSecurityOrigin& origin) {
351 return origin.canAccessPasswordManager(); 352 return origin.canAccessPasswordManager();
352 } 353 }
353 354
354 void PasswordAutofillAgent::OnDynamicFormsSeen(blink::WebFrame* frame) { 355 void PasswordAutofillAgent::OnDynamicFormsSeen(blink::WebFrame* frame) {
355 SendPasswordForms(frame, false /* only_visible */); 356 SendPasswordForms(frame, false /* only_visible */);
356 } 357 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 595 }
595 } 596 }
596 597
597 //////////////////////////////////////////////////////////////////////////////// 598 ////////////////////////////////////////////////////////////////////////////////
598 // PasswordAutofillAgent, private: 599 // PasswordAutofillAgent, private:
599 600
600 void PasswordAutofillAgent::GetSuggestions( 601 void PasswordAutofillAgent::GetSuggestions(
601 const PasswordFormFillData& fill_data, 602 const PasswordFormFillData& fill_data,
602 const base::string16& input, 603 const base::string16& input,
603 std::vector<base::string16>* suggestions, 604 std::vector<base::string16>* suggestions,
604 std::vector<base::string16>* realms) { 605 std::vector<base::string16>* realms,
605 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) { 606 bool show_all) {
607 if (show_all ||
608 StartsWith(fill_data.basic_data.fields[0].value, input, false)) {
606 suggestions->push_back(fill_data.basic_data.fields[0].value); 609 suggestions->push_back(fill_data.basic_data.fields[0].value);
607 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm)); 610 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm));
608 } 611 }
609 612
610 for (PasswordFormFillData::LoginCollection::const_iterator iter = 613 for (PasswordFormFillData::LoginCollection::const_iterator iter =
611 fill_data.additional_logins.begin(); 614 fill_data.additional_logins.begin();
612 iter != fill_data.additional_logins.end(); ++iter) { 615 iter != fill_data.additional_logins.end(); ++iter) {
613 if (StartsWith(iter->first, input, false)) { 616 if (show_all || StartsWith(iter->first, input, false)) {
614 suggestions->push_back(iter->first); 617 suggestions->push_back(iter->first);
615 realms->push_back(base::UTF8ToUTF16(iter->second.realm)); 618 realms->push_back(base::UTF8ToUTF16(iter->second.realm));
616 } 619 }
617 } 620 }
618 621
619 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = 622 for (PasswordFormFillData::UsernamesCollection::const_iterator iter =
620 fill_data.other_possible_usernames.begin(); 623 fill_data.other_possible_usernames.begin();
621 iter != fill_data.other_possible_usernames.end(); ++iter) { 624 iter != fill_data.other_possible_usernames.end(); ++iter) {
622 for (size_t i = 0; i < iter->second.size(); ++i) { 625 for (size_t i = 0; i < iter->second.size(); ++i) {
623 if (StartsWith(iter->second[i], input, false)) { 626 if (show_all || StartsWith(iter->second[i], input, false)) {
624 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; 627 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN;
625 suggestions->push_back(iter->second[i]); 628 suggestions->push_back(iter->second[i]);
626 realms->push_back(base::UTF8ToUTF16(iter->first.realm)); 629 realms->push_back(base::UTF8ToUTF16(iter->first.realm));
627 } 630 }
628 } 631 }
629 } 632 }
630 } 633 }
631 634
632 bool PasswordAutofillAgent::ShowSuggestionPopup( 635 bool PasswordAutofillAgent::ShowSuggestionPopup(
633 const PasswordFormFillData& fill_data, 636 const PasswordFormFillData& fill_data,
634 const blink::WebInputElement& user_input) { 637 const blink::WebInputElement& user_input,
638 bool show_all) {
635 blink::WebFrame* frame = user_input.document().frame(); 639 blink::WebFrame* frame = user_input.document().frame();
636 if (!frame) 640 if (!frame)
637 return false; 641 return false;
638 642
639 blink::WebView* webview = frame->view(); 643 blink::WebView* webview = frame->view();
640 if (!webview) 644 if (!webview)
641 return false; 645 return false;
642 646
643 std::vector<base::string16> suggestions; 647 std::vector<base::string16> suggestions;
644 std::vector<base::string16> realms; 648 std::vector<base::string16> realms;
645 GetSuggestions(fill_data, user_input.value(), &suggestions, &realms); 649 GetSuggestions(
650 fill_data, user_input.value(), &suggestions, &realms, show_all);
646 DCHECK_EQ(suggestions.size(), realms.size()); 651 DCHECK_EQ(suggestions.size(), realms.size());
647 652
648 FormData form; 653 FormData form;
649 FormFieldData field; 654 FormFieldData field;
650 FindFormAndFieldForInputElement( 655 FindFormAndFieldForInputElement(
651 user_input, &form, &field, REQUIRE_NONE); 656 user_input, &form, &field, REQUIRE_NONE);
652 657
653 blink::WebInputElement selected_element = user_input; 658 blink::WebInputElement selected_element = user_input;
654 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); 659 gfx::Rect bounding_box(selected_element.boundsInViewportSpace());
655 660
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 blink::WebInputElement password = password_input; 805 blink::WebInputElement password = password_input;
801 806
802 // Don't inline autocomplete if the caret is not at the end. 807 // Don't inline autocomplete if the caret is not at the end.
803 // TODO(jcivelli): is there a better way to test the caret location? 808 // TODO(jcivelli): is there a better way to test the caret location?
804 if (username.selectionStart() != username.selectionEnd() || 809 if (username.selectionStart() != username.selectionEnd() ||
805 username.selectionEnd() != static_cast<int>(username.value().length())) { 810 username.selectionEnd() != static_cast<int>(username.value().length())) {
806 return; 811 return;
807 } 812 }
808 813
809 // Show the popup with the list of available usernames. 814 // Show the popup with the list of available usernames.
810 ShowSuggestionPopup(fill_data, username); 815 ShowSuggestionPopup(fill_data, username, false);
811
812 816
813 #if !defined(OS_ANDROID) 817 #if !defined(OS_ANDROID)
814 // Fill the user and password field with the most relevant match. Android 818 // Fill the user and password field with the most relevant match. Android
815 // only fills in the fields after the user clicks on the suggestion popup. 819 // only fills in the fields after the user clicks on the suggestion popup.
816 FillUserNameAndPassword(&username, &password, fill_data, 820 FillUserNameAndPassword(&username, &password, fill_data,
817 false /* exact_username_match */, 821 false /* exact_username_match */,
818 true /* set_selection */); 822 true /* set_selection */);
819 #endif 823 #endif
820 } 824 }
821 825
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 } 874 }
871 875
872 PasswordAutofillAgent::AutofillWebUserGestureHandler:: 876 PasswordAutofillAgent::AutofillWebUserGestureHandler::
873 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) 877 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent)
874 : agent_(agent) {} 878 : agent_(agent) {}
875 879
876 PasswordAutofillAgent::AutofillWebUserGestureHandler:: 880 PasswordAutofillAgent::AutofillWebUserGestureHandler::
877 ~AutofillWebUserGestureHandler() {} 881 ~AutofillWebUserGestureHandler() {}
878 882
879 } // namespace autofill 883 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698