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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 using WebKit::WebString; | 45 using WebKit::WebString; |
| 46 using webkit::forms::FormData; | 46 using webkit::forms::FormData; |
| 47 using webkit::forms::FormDataPredictions; | 47 using webkit::forms::FormDataPredictions; |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // The size above which we stop triggering autofill for an input text field | 51 // The size above which we stop triggering autofill for an input text field |
| 52 // (so to avoid sending long strings through IPC). | 52 // (so to avoid sending long strings through IPC). |
| 53 const size_t kMaximumTextSizeForAutofill = 1000; | 53 const size_t kMaximumTextSizeForAutofill = 1000; |
| 54 | 54 |
| 55 // The maximum number of data list elements to send to the browser process | |
| 56 // via IPC (to prevent long IPC messages). | |
| 57 const size_t kMaximumDataListSizeForAutofill = 30; | |
| 58 | |
| 55 void AppendDataListSuggestions(const WebKit::WebInputElement& element, | 59 void AppendDataListSuggestions(const WebKit::WebInputElement& element, |
| 56 std::vector<string16>* values, | 60 std::vector<string16>* values, |
| 57 std::vector<string16>* labels, | 61 std::vector<string16>* labels, |
| 58 std::vector<string16>* icons, | 62 std::vector<string16>* icons, |
| 59 std::vector<int>* item_ids) { | 63 std::vector<int>* item_ids) { |
| 60 WebNodeCollection options = element.dataListOptions(); | 64 WebNodeCollection options = element.dataListOptions(); |
| 61 if (options.isNull()) | 65 if (options.isNull()) |
| 62 return; | 66 return; |
| 63 | 67 |
| 64 string16 prefix = element.editingValue(); | 68 string16 prefix = element.editingValue(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill, | 123 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill, |
| 120 OnSetAutofillActionFill) | 124 OnSetAutofillActionFill) |
| 121 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, | 125 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, |
| 122 OnClearForm) | 126 OnClearForm) |
| 123 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, | 127 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, |
| 124 OnSetAutofillActionPreview) | 128 OnSetAutofillActionPreview) |
| 125 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, | 129 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, |
| 126 OnClearPreviewedForm) | 130 OnClearPreviewedForm) |
| 127 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, | 131 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, |
| 128 OnSetNodeText) | 132 OnSetNodeText) |
| 133 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, | |
| 134 OnAcceptDataListSuggestion) | |
| 129 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, | 135 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, |
| 130 OnAcceptPasswordAutofillSuggestion) | 136 OnAcceptPasswordAutofillSuggestion) |
| 131 IPC_MESSAGE_UNHANDLED(handled = false) | 137 IPC_MESSAGE_UNHANDLED(handled = false) |
| 132 IPC_END_MESSAGE_MAP() | 138 IPC_END_MESSAGE_MAP() |
| 133 return handled; | 139 return handled; |
| 134 } | 140 } |
| 135 | 141 |
| 136 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { | 142 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { |
| 137 // The document has now been fully loaded. Scan for forms to be sent up to | 143 // The document has now been fully loaded. Scan for forms to be sent up to |
| 138 // the browser. | 144 // the browser. |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 } | 528 } |
| 523 | 529 |
| 524 void AutofillAgent::OnClearPreviewedForm() { | 530 void AutofillAgent::OnClearPreviewedForm() { |
| 525 didClearAutofillSelection(element_); | 531 didClearAutofillSelection(element_); |
| 526 } | 532 } |
| 527 | 533 |
| 528 void AutofillAgent::OnSetNodeText(const string16& value) { | 534 void AutofillAgent::OnSetNodeText(const string16& value) { |
| 529 SetNodeText(value, &element_); | 535 SetNodeText(value, &element_); |
| 530 } | 536 } |
| 531 | 537 |
| 538 void AutofillAgent::OnAcceptDataListSuggestion(const string16& value) { | |
| 539 AcceptDataListSuggestion(value); | |
| 540 } | |
| 541 | |
| 532 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { | 542 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { |
| 533 // We need to make sure this is handled here because the browser process | 543 // We need to make sure this is handled here because the browser process |
| 534 // skipped it handling because it believed it would be handled here. If it | 544 // skipped it handling because it believed it would be handled here. If it |
| 535 // isn't handled here then the browser logic needs to be updated. | 545 // isn't handled here then the browser logic needs to be updated. |
| 536 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion( | 546 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion( |
| 537 element_, | 547 element_, |
| 538 value); | 548 value); |
| 539 DCHECK(handled); | 549 DCHECK(handled); |
| 540 } | 550 } |
| 541 | 551 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 webkit::forms::FormField field; | 603 webkit::forms::FormField field; |
| 594 if (!FindFormAndFieldForInputElement(element, &form, &field, | 604 if (!FindFormAndFieldForInputElement(element, &form, &field, |
| 595 REQUIRE_AUTOCOMPLETE)) { | 605 REQUIRE_AUTOCOMPLETE)) { |
| 596 // If we didn't find the cached form, at least let autocomplete have a shot | 606 // If we didn't find the cached form, at least let autocomplete have a shot |
| 597 // at providing suggestions. | 607 // at providing suggestions. |
| 598 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 608 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
| 599 } | 609 } |
| 600 | 610 |
| 601 gfx::Rect bounding_box(element_.boundsInViewportSpace()); | 611 gfx::Rect bounding_box(element_.boundsInViewportSpace()); |
| 602 | 612 |
| 613 // Find the datalist values and send them to the browser process. | |
| 614 std::vector<string16> data_list_values; | |
| 615 std::vector<string16> data_list_labels; | |
| 616 std::vector<string16> data_list_icons; | |
| 617 std::vector<int> data_list_unique_ids; | |
| 618 AppendDataListSuggestions(element_, | |
| 619 &data_list_values, | |
| 620 &data_list_labels, | |
| 621 &data_list_icons, | |
| 622 &data_list_unique_ids); | |
| 623 | |
| 624 if (data_list_values.size() > kMaximumDataListSizeForAutofill) { | |
| 625 data_list_values.resize(kMaximumDataListSizeForAutofill); | |
| 626 data_list_labels.resize(kMaximumDataListSizeForAutofill); | |
| 627 data_list_icons.resize(kMaximumDataListSizeForAutofill); | |
| 628 data_list_unique_ids.resize(kMaximumDataListSizeForAutofill); | |
| 629 } | |
|
Ilya Sherman
2012/06/07 22:56:05
nit: You should probably also trim each entry of t
csharp
2012/06/08 14:44:54
Done.
| |
| 630 | |
| 631 | |
|
Ilya Sherman
2012/06/07 22:56:05
nit: Extra blank line
csharp
2012/06/08 14:44:54
Done.
| |
| 632 Send(new AutofillHostMsg_SetDataList(routing_id(), | |
| 633 data_list_values, | |
| 634 data_list_labels, | |
| 635 data_list_icons, | |
| 636 data_list_unique_ids)); | |
| 637 | |
| 603 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), | 638 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), |
| 604 autofill_query_id_, | 639 autofill_query_id_, |
| 605 form, | 640 form, |
| 606 field, | 641 field, |
| 607 bounding_box, | 642 bounding_box, |
| 608 display_warning_if_disabled)); | 643 display_warning_if_disabled)); |
| 609 } | 644 } |
| 610 | 645 |
| 611 void AutofillAgent::FillAutofillFormData(const WebNode& node, | 646 void AutofillAgent::FillAutofillFormData(const WebNode& node, |
| 612 int unique_id, | 647 int unique_id, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 631 void AutofillAgent::SetNodeText(const string16& value, | 666 void AutofillAgent::SetNodeText(const string16& value, |
| 632 WebKit::WebInputElement* node) { | 667 WebKit::WebInputElement* node) { |
| 633 did_set_node_text_ = true; | 668 did_set_node_text_ = true; |
| 634 string16 substring = value; | 669 string16 substring = value; |
| 635 substring = substring.substr(0, node->maxLength()); | 670 substring = substring.substr(0, node->maxLength()); |
| 636 | 671 |
| 637 node->setEditingValue(substring); | 672 node->setEditingValue(substring); |
| 638 } | 673 } |
| 639 | 674 |
| 640 } // namespace autofill | 675 } // namespace autofill |
| OLD | NEW |