Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 WebInputElement element = elements[j].to<WebInputElement>(); | |
| 613 std::string element_attr = | |
| 614 UTF16ToASCII(element.getAttribute("autocomplete")); | |
| 615 if (field_attr_lower == StringToLowerASCII(element_attr)) { | |
| 616 element.setValue(field.value, true); | |
| 617 element.setAutofilled(true); | |
| 618 break; | |
| 619 } | |
| 620 } | |
| 621 } | |
|
Ilya Sherman
2012/11/28 06:16:39
Any reason not to just re-use FillForm() from form
Dan Beam
2012/11/28 19:59:10
That's really similar, but
a) how does this handle
Ilya Sherman
2012/11/29 00:08:59
FillForm() would fill all of them. What's the rea
Dan Beam
2012/11/29 00:51:13
ForEachMatchingFormField also ignores select[autoc
Ilya Sherman
2012/11/29 08:24:01
I think you're misreading that code -- it ignores
| |
| 622 | |
| 623 in_flight_request_form_.finishRequestAutocomplete( | |
| 624 WebFormElement::AutocompleteResultSuccess); | |
| 597 in_flight_request_form_.reset(); | 625 in_flight_request_form_.reset(); |
| 598 } | 626 } |
| 599 | 627 |
| 628 void AutofillAgent::OnRequestAutocompleteError() { | |
| 629 DCHECK(!in_flight_request_form_.isNull()); | |
| 630 in_flight_request_form_.finishRequestAutocomplete( | |
| 631 WebFormElement::AutocompleteResultError); | |
| 632 in_flight_request_form_.reset(); | |
| 633 } | |
| 634 | |
| 600 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 635 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
| 601 bool autofill_on_empty_values, | 636 bool autofill_on_empty_values, |
| 602 bool requires_caret_at_end, | 637 bool requires_caret_at_end, |
| 603 bool display_warning_if_disabled) { | 638 bool display_warning_if_disabled) { |
| 604 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || | 639 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || |
| 605 element.isPasswordField() || !element.suggestedValue().isEmpty()) | 640 element.isPasswordField() || !element.suggestedValue().isEmpty()) |
| 606 return; | 641 return; |
| 607 | 642 |
| 608 // Don't attempt to autofill with values that are too large or if filling | 643 // Don't attempt to autofill with values that are too large or if filling |
| 609 // criteria are not met. | 644 // criteria are not met. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 web_view->hidePopups(); | 768 web_view->hidePopups(); |
| 734 | 769 |
| 735 HideHostPopups(); | 770 HideHostPopups(); |
| 736 } | 771 } |
| 737 | 772 |
| 738 void AutofillAgent::HideHostPopups() { | 773 void AutofillAgent::HideHostPopups() { |
| 739 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | 774 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); |
| 740 } | 775 } |
| 741 | 776 |
| 742 } // namespace autofill | 777 } // namespace autofill |
| OLD | NEW |