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 // TODO(dbeam): handle <select>s? |
Ilya Sherman
2012/11/29 08:24:01
What's part of the current code fails to handle <s
| |
598 std::vector<WebKit::WebFormControlElement> elements; | |
599 autofill::ExtractAutofillableElements(in_flight_request_form_, | |
600 REQUIRE_AUTOCOMPLETE, | |
601 &elements); | |
602 | |
603 for (size_t i = 0; i < form_data.fields.size(); ++i) { | |
604 // TODO(dbeam): change to DCHECK() if values must be non-empty to confirm. | |
605 const FormFieldData& form_field_data = form_data.fields[i]; | |
606 if (form_field_data.value.empty()) | |
607 continue; | |
608 | |
609 for (size_t j = 0; j < elements.size(); ++j) { | |
610 if (LowerCaseEqualsASCII( | |
611 elements[j].getAttribute("autocomplete"), | |
612 form_field_data.autocomplete_attribute.c_str())) { | |
Ilya Sherman
2012/11/29 08:24:01
Hmm, is form_field_data.autocomplete_attribute act
| |
613 autofill::FillFormField(form_field_data, false, &elements[j]); | |
614 break; | |
Ilya Sherman
2012/11/29 08:24:01
Why break out of the loop here?
| |
615 } | |
616 } | |
617 } | |
Ilya Sherman
2012/11/29 08:24:01
If you decide to keep this logic, please move it i
| |
618 | |
619 in_flight_request_form_.finishRequestAutocomplete( | |
620 WebFormElement::AutocompleteResultSuccess); | |
597 in_flight_request_form_.reset(); | 621 in_flight_request_form_.reset(); |
598 } | 622 } |
599 | 623 |
624 void AutofillAgent::OnRequestAutocompleteError() { | |
625 DCHECK(!in_flight_request_form_.isNull()); | |
626 in_flight_request_form_.finishRequestAutocomplete( | |
627 WebFormElement::AutocompleteResultError); | |
628 in_flight_request_form_.reset(); | |
629 } | |
630 | |
600 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 631 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
601 bool autofill_on_empty_values, | 632 bool autofill_on_empty_values, |
602 bool requires_caret_at_end, | 633 bool requires_caret_at_end, |
603 bool display_warning_if_disabled) { | 634 bool display_warning_if_disabled) { |
604 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || | 635 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || |
605 element.isPasswordField() || !element.suggestedValue().isEmpty()) | 636 element.isPasswordField() || !element.suggestedValue().isEmpty()) |
606 return; | 637 return; |
607 | 638 |
608 // Don't attempt to autofill with values that are too large or if filling | 639 // Don't attempt to autofill with values that are too large or if filling |
609 // criteria are not met. | 640 // criteria are not met. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 web_view->hidePopups(); | 764 web_view->hidePopups(); |
734 | 765 |
735 HideHostPopups(); | 766 HideHostPopups(); |
736 } | 767 } |
737 | 768 |
738 void AutofillAgent::HideHostPopups() { | 769 void AutofillAgent::HideHostPopups() { |
739 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | 770 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); |
740 } | 771 } |
741 | 772 |
742 } // namespace autofill | 773 } // namespace autofill |
OLD | NEW |