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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill, | 118 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill, |
119 OnSetAutofillActionFill) | 119 OnSetAutofillActionFill) |
120 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, | 120 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, |
121 OnClearForm) | 121 OnClearForm) |
122 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, | 122 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, |
123 OnSetAutofillActionPreview) | 123 OnSetAutofillActionPreview) |
124 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, | 124 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, |
125 OnClearPreviewedForm) | 125 OnClearPreviewedForm) |
126 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, | 126 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, |
127 OnSetNodeText) | 127 OnSetNodeText) |
| 128 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, |
| 129 OnAcceptDataListSuggestion) |
128 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, | 130 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, |
129 OnAcceptPasswordAutofillSuggestion) | 131 OnAcceptPasswordAutofillSuggestion) |
130 IPC_MESSAGE_UNHANDLED(handled = false) | 132 IPC_MESSAGE_UNHANDLED(handled = false) |
131 IPC_END_MESSAGE_MAP() | 133 IPC_END_MESSAGE_MAP() |
132 return handled; | 134 return handled; |
133 } | 135 } |
134 | 136 |
135 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { | 137 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { |
136 // The document has now been fully loaded. Scan for forms to be sent up to | 138 // The document has now been fully loaded. Scan for forms to be sent up to |
137 // the browser. | 139 // the browser. |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 } | 518 } |
517 | 519 |
518 void AutofillAgent::OnClearPreviewedForm() { | 520 void AutofillAgent::OnClearPreviewedForm() { |
519 didClearAutofillSelection(element_); | 521 didClearAutofillSelection(element_); |
520 } | 522 } |
521 | 523 |
522 void AutofillAgent::OnSetNodeText(const string16& value) { | 524 void AutofillAgent::OnSetNodeText(const string16& value) { |
523 SetNodeText(value, &element_); | 525 SetNodeText(value, &element_); |
524 } | 526 } |
525 | 527 |
| 528 void AutofillAgent::OnAcceptDataListSuggestion(const string16& value) { |
| 529 AcceptDataListSuggestion(value); |
| 530 } |
| 531 |
526 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { | 532 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { |
527 // We need to make sure this is handled here because the browser process | 533 // We need to make sure this is handled here because the browser process |
528 // skipped it handling because it believed it would be handled here. If it | 534 // skipped it handling because it believed it would be handled here. If it |
529 // isn't handled here then the browser logic needs to be updated. | 535 // isn't handled here then the browser logic needs to be updated. |
530 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion( | 536 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion( |
531 element_, | 537 element_, |
532 value); | 538 value); |
533 DCHECK(handled); | 539 DCHECK(handled); |
534 } | 540 } |
535 | 541 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 webkit::forms::FormField field; | 593 webkit::forms::FormField field; |
588 if (!FindFormAndFieldForInputElement(element, &form, &field, | 594 if (!FindFormAndFieldForInputElement(element, &form, &field, |
589 REQUIRE_AUTOCOMPLETE)) { | 595 REQUIRE_AUTOCOMPLETE)) { |
590 // If we didn't find the cached form, at least let autocomplete have a shot | 596 // If we didn't find the cached form, at least let autocomplete have a shot |
591 // at providing suggestions. | 597 // at providing suggestions. |
592 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 598 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
593 } | 599 } |
594 | 600 |
595 gfx::Rect bounding_box(element_.boundsInViewportSpace()); | 601 gfx::Rect bounding_box(element_.boundsInViewportSpace()); |
596 | 602 |
| 603 // Find the datalist values and send them to the the browser process. |
| 604 std::vector<string16> data_list_values; |
| 605 std::vector<string16> data_list_labels; |
| 606 std::vector<string16> data_list_icons; |
| 607 std::vector<int> data_list_unique_ids; |
| 608 AppendDataListSuggestions(element_, |
| 609 &data_list_values, |
| 610 &data_list_labels, |
| 611 &data_list_icons, |
| 612 &data_list_unique_ids); |
| 613 |
| 614 Send(new AutofillHostMsg_SetDataList(routing_id(), |
| 615 data_list_values, |
| 616 data_list_labels, |
| 617 data_list_icons, |
| 618 data_list_unique_ids)); |
| 619 |
597 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), | 620 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), |
598 autofill_query_id_, | 621 autofill_query_id_, |
599 form, | 622 form, |
600 field, | 623 field, |
601 bounding_box, | 624 bounding_box, |
602 display_warning_if_disabled)); | 625 display_warning_if_disabled)); |
603 } | 626 } |
604 | 627 |
605 void AutofillAgent::FillAutofillFormData(const WebNode& node, | 628 void AutofillAgent::FillAutofillFormData(const WebNode& node, |
606 int unique_id, | 629 int unique_id, |
(...skipping 17 matching lines...) Expand all Loading... |
624 | 647 |
625 void AutofillAgent::SetNodeText(const string16& value, | 648 void AutofillAgent::SetNodeText(const string16& value, |
626 WebKit::WebInputElement* node) { | 649 WebKit::WebInputElement* node) { |
627 string16 substring = value; | 650 string16 substring = value; |
628 substring = substring.substr(0, node->maxLength()); | 651 substring = substring.substr(0, node->maxLength()); |
629 | 652 |
630 node->setEditingValue(substring); | 653 node->setEditingValue(substring); |
631 } | 654 } |
632 | 655 |
633 } // namespace autofill | 656 } // namespace autofill |
OLD | NEW |