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

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

Issue 11348273: [autofill] Fill in values on a successful run of interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: isherman@ review Created 8 years 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 (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/autofill_agent.h" 5 #include "chrome/renderer/autofill/autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, 151 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview,
152 OnSetAutofillActionPreview) 152 OnSetAutofillActionPreview)
153 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, 153 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm,
154 OnClearPreviewedForm) 154 OnClearPreviewedForm)
155 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, 155 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText,
156 OnSetNodeText) 156 OnSetNodeText)
157 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, 157 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
158 OnAcceptDataListSuggestion) 158 OnAcceptDataListSuggestion)
159 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, 159 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion,
160 OnAcceptPasswordAutofillSuggestion) 160 OnAcceptPasswordAutofillSuggestion)
161 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteFinished, 161 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteSuccess,
162 OnRequestAutocompleteFinished) 162 OnRequestAutocompleteSuccess)
163 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteError,
164 OnRequestAutocompleteError)
163 IPC_MESSAGE_UNHANDLED(handled = false) 165 IPC_MESSAGE_UNHANDLED(handled = false)
164 IPC_END_MESSAGE_MAP() 166 IPC_END_MESSAGE_MAP()
165 return handled; 167 return handled;
166 } 168 }
167 169
168 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { 170 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) {
169 // The document has now been fully loaded. Scan for forms to be sent up to 171 // The document has now been fully loaded. Scan for forms to be sent up to
170 // the browser. 172 // the browser.
171 std::vector<FormData> forms; 173 std::vector<FormData> forms;
172 form_cache_.ExtractForms(*frame, &forms); 174 form_cache_.ExtractForms(*frame, &forms);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 326 }
325 327
326 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { 328 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
327 password_autofill_manager_->TextFieldDidEndEditing(element); 329 password_autofill_manager_->TextFieldDidEndEditing(element);
328 has_shown_autofill_popup_for_current_edit_ = false; 330 has_shown_autofill_popup_for_current_edit_ = false;
329 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); 331 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id()));
330 } 332 }
331 333
332 void AutofillAgent::textFieldDidChange(const WebInputElement& element) { 334 void AutofillAgent::textFieldDidChange(const WebInputElement& element) {
333 if (did_set_node_text_) { 335 if (did_set_node_text_) {
334 did_set_node_text_ = false; 336 did_set_node_text_ = false;
335 return; 337 return;
336 } 338 }
337 339
338 // We post a task for doing the Autofill as the caret position is not set 340 // We post a task for doing the Autofill as the caret position is not set
339 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and 341 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
340 // it is needed to trigger autofill. 342 // it is needed to trigger autofill.
341 weak_ptr_factory_.InvalidateWeakPtrs(); 343 weak_ptr_factory_.InvalidateWeakPtrs();
342 MessageLoop::current()->PostTask( 344 MessageLoop::current()->PostTask(
343 FROM_HERE, 345 FROM_HERE,
344 base::Bind(&AutofillAgent::TextFieldDidChangeImpl, 346 base::Bind(&AutofillAgent::TextFieldDidChangeImpl,
345 weak_ptr_factory_.GetWeakPtr(), element)); 347 weak_ptr_factory_.GetWeakPtr(), element));
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { 584 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) {
583 // We need to make sure this is handled here because the browser process 585 // We need to make sure this is handled here because the browser process
584 // skipped it handling because it believed it would be handled here. If it 586 // skipped it handling because it believed it would be handled here. If it
585 // isn't handled here then the browser logic needs to be updated. 587 // isn't handled here then the browser logic needs to be updated.
586 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion( 588 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion(
587 element_, 589 element_,
588 value); 590 value);
589 DCHECK(handled); 591 DCHECK(handled);
590 } 592 }
591 593
592 void AutofillAgent::OnRequestAutocompleteFinished( 594 void AutofillAgent::OnRequestAutocompleteSuccess(const FormData& form_data) {
593 WebFormElement::AutocompleteResult result) {
594 DCHECK(!in_flight_request_form_.isNull()); 595 DCHECK(!in_flight_request_form_.isNull());
595 596
596 in_flight_request_form_.finishRequestAutocomplete(result); 597 std::vector<WebKit::WebFormControlElement> elements;
598 autofill::ExtractAutofillableElements(in_flight_request_form_,
599 REQUIRE_AUTOCOMPLETE,
600 &elements);
601
602 for (size_t i = 0; i < form_data.fields.size(); ++i) {
603 const FormFieldData field = form_data.fields[i];
604
605 // TODO(dbeam): change to DCHECK() if values must be non-empty to confirm.
606 if (field.value.empty())
607 continue;
608
609 const std::string field_attr_lower =
610 StringToLowerASCII(field.autocomplete_attribute);
611 for (size_t j = 0; j < elements.size(); ++j) {
612 const std::string element_attr =
613 UTF16ToASCII(elements[j].getAttribute("autocomplete"));
614 if (field_attr_lower == StringToLowerASCII(element_attr)) {
615 autofill::FillFormField(&elements[j], &field, false);
616 break;
617 }
618 }
619 }
Ilya Sherman 2012/11/29 00:08:59 If we end up keeping this logic, I would recommend
620
621 in_flight_request_form_.finishRequestAutocomplete(
622 WebFormElement::AutocompleteResultSuccess);
597 in_flight_request_form_.reset(); 623 in_flight_request_form_.reset();
598 } 624 }
599 625
626 void AutofillAgent::OnRequestAutocompleteError() {
627 DCHECK(!in_flight_request_form_.isNull());
628 in_flight_request_form_.finishRequestAutocomplete(
629 WebFormElement::AutocompleteResultError);
630 in_flight_request_form_.reset();
631 }
632
600 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 633 void AutofillAgent::ShowSuggestions(const WebInputElement& element,
601 bool autofill_on_empty_values, 634 bool autofill_on_empty_values,
602 bool requires_caret_at_end, 635 bool requires_caret_at_end,
603 bool display_warning_if_disabled) { 636 bool display_warning_if_disabled) {
604 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || 637 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() ||
605 element.isPasswordField() || !element.suggestedValue().isEmpty()) 638 element.isPasswordField() || !element.suggestedValue().isEmpty())
606 return; 639 return;
607 640
608 // Don't attempt to autofill with values that are too large or if filling 641 // Don't attempt to autofill with values that are too large or if filling
609 // criteria are not met. 642 // criteria are not met.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 web_view->hidePopups(); 766 web_view->hidePopups();
734 767
735 HideHostPopups(); 768 HideHostPopups();
736 } 769 }
737 770
738 void AutofillAgent::HideHostPopups() { 771 void AutofillAgent::HideHostPopups() {
739 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); 772 Send(new AutofillHostMsg_HideAutofillPopup(routing_id()));
740 } 773 }
741 774
742 } // namespace autofill 775 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698