| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/renderer/autofill_agent.h" | 5 #include "components/autofill/content/renderer/autofill_agent.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); | 103 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Gets all the data list values (with corresponding label) for the given | 106 // Gets all the data list values (with corresponding label) for the given |
| 107 // element. | 107 // element. |
| 108 void GetDataListSuggestions(const WebInputElement& element, | 108 void GetDataListSuggestions(const WebInputElement& element, |
| 109 std::vector<base::string16>* values, | 109 std::vector<base::string16>* values, |
| 110 std::vector<base::string16>* labels) { | 110 std::vector<base::string16>* labels) { |
| 111 for (const auto& option : element.filteredDataListOptions()) { | 111 for (const auto& option : element.filteredDataListOptions()) { |
| 112 values->push_back(option.value()); | 112 values->push_back(option.value().utf16()); |
| 113 if (option.value() != option.label()) | 113 if (option.value() != option.label()) |
| 114 labels->push_back(option.label()); | 114 labels->push_back(option.label().utf16()); |
| 115 else | 115 else |
| 116 labels->push_back(base::string16()); | 116 labels->push_back(base::string16()); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Trim the vector before sending it to the browser process to ensure we | 120 // Trim the vector before sending it to the browser process to ensure we |
| 121 // don't send too much data through the IPC. | 121 // don't send too much data through the IPC. |
| 122 void TrimStringVectorForIPC(std::vector<base::string16>* strings) { | 122 void TrimStringVectorForIPC(std::vector<base::string16>* strings) { |
| 123 // Limit the size of the vector. | 123 // Limit the size of the vector. |
| 124 if (strings->size() > kMaxListSize) | 124 if (strings->size() > kMaxListSize) |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 432 |
| 433 void AutofillAgent::DoAcceptDataListSuggestion( | 433 void AutofillAgent::DoAcceptDataListSuggestion( |
| 434 const base::string16& suggested_value) { | 434 const base::string16& suggested_value) { |
| 435 WebInputElement* input_element = toWebInputElement(&element_); | 435 WebInputElement* input_element = toWebInputElement(&element_); |
| 436 DCHECK(input_element); | 436 DCHECK(input_element); |
| 437 base::string16 new_value = suggested_value; | 437 base::string16 new_value = suggested_value; |
| 438 // If this element takes multiple values then replace the last part with | 438 // If this element takes multiple values then replace the last part with |
| 439 // the suggestion. | 439 // the suggestion. |
| 440 if (input_element->isMultiple() && input_element->isEmailField()) { | 440 if (input_element->isMultiple() && input_element->isEmailField()) { |
| 441 std::vector<base::string16> parts = base::SplitString( | 441 std::vector<base::string16> parts = base::SplitString( |
| 442 base::StringPiece16(input_element->editingValue()), | 442 input_element->editingValue().utf16(), base::ASCIIToUTF16(","), |
| 443 base::ASCIIToUTF16(","), base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | 443 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 444 if (parts.size() == 0) | 444 if (parts.size() == 0) |
| 445 parts.push_back(base::string16()); | 445 parts.push_back(base::string16()); |
| 446 | 446 |
| 447 base::string16 last_part = parts.back(); | 447 base::string16 last_part = parts.back(); |
| 448 // We want to keep just the leading whitespace. | 448 // We want to keep just the leading whitespace. |
| 449 for (size_t i = 0; i < last_part.size(); ++i) { | 449 for (size_t i = 0; i < last_part.size(); ++i) { |
| 450 if (!base::IsUnicodeWhitespace(last_part[i])) { | 450 if (!base::IsUnicodeWhitespace(last_part[i])) { |
| 451 last_part = last_part.substr(0, i); | 451 last_part = last_part.substr(0, i); |
| 452 break; | 452 break; |
| 453 } | 453 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 | 535 |
| 536 void AutofillAgent::FillPasswordSuggestion(const base::string16& username, | 536 void AutofillAgent::FillPasswordSuggestion(const base::string16& username, |
| 537 const base::string16& password) { | 537 const base::string16& password) { |
| 538 bool handled = | 538 bool handled = |
| 539 password_autofill_agent_->FillSuggestion(element_, username, password); | 539 password_autofill_agent_->FillSuggestion(element_, username, password); |
| 540 DCHECK(handled); | 540 DCHECK(handled); |
| 541 } | 541 } |
| 542 | 542 |
| 543 void AutofillAgent::PreviewPasswordSuggestion(const base::string16& username, | 543 void AutofillAgent::PreviewPasswordSuggestion(const base::string16& username, |
| 544 const base::string16& password) { | 544 const base::string16& password) { |
| 545 bool handled = | 545 bool handled = password_autofill_agent_->PreviewSuggestion( |
| 546 password_autofill_agent_->PreviewSuggestion(element_, username, password); | 546 element_, blink::WebString::fromUTF16(username), |
| 547 blink::WebString::fromUTF16(password)); |
| 547 DCHECK(handled); | 548 DCHECK(handled); |
| 548 } | 549 } |
| 549 | 550 |
| 550 void AutofillAgent::ShowInitialPasswordAccountSuggestions( | 551 void AutofillAgent::ShowInitialPasswordAccountSuggestions( |
| 551 int32_t key, | 552 int32_t key, |
| 552 const PasswordFormFillData& form_data) { | 553 const PasswordFormFillData& form_data) { |
| 553 std::vector<blink::WebInputElement> elements; | 554 std::vector<blink::WebInputElement> elements; |
| 554 std::unique_ptr<RendererSavePasswordProgressLogger> logger; | 555 std::unique_ptr<RendererSavePasswordProgressLogger> logger; |
| 555 if (password_autofill_agent_->logging_state_active()) { | 556 if (password_autofill_agent_->logging_state_active()) { |
| 556 logger.reset(new RendererSavePasswordProgressLogger( | 557 logger.reset(new RendererSavePasswordProgressLogger( |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 723 |
| 723 GetAutofillDriver()->SetDataList(data_list_values, data_list_labels); | 724 GetAutofillDriver()->SetDataList(data_list_values, data_list_labels); |
| 724 GetAutofillDriver()->QueryFormFieldAutofill( | 725 GetAutofillDriver()->QueryFormFieldAutofill( |
| 725 autofill_query_id_, form, field, | 726 autofill_query_id_, form, field, |
| 726 render_frame()->GetRenderView()->ElementBoundsInWindow(element_)); | 727 render_frame()->GetRenderView()->ElementBoundsInWindow(element_)); |
| 727 } | 728 } |
| 728 | 729 |
| 729 void AutofillAgent::DoFillFieldWithValue(const base::string16& value, | 730 void AutofillAgent::DoFillFieldWithValue(const base::string16& value, |
| 730 WebInputElement* node) { | 731 WebInputElement* node) { |
| 731 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true); | 732 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true); |
| 732 node->setEditingValue(value.substr(0, node->maxLength())); | 733 node->setEditingValue( |
| 734 blink::WebString::fromUTF16(value.substr(0, node->maxLength()))); |
| 733 } | 735 } |
| 734 | 736 |
| 735 void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value, | 737 void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value, |
| 736 WebInputElement* node) { | 738 WebInputElement* node) { |
| 737 was_query_node_autofilled_ = element_.isAutofilled(); | 739 was_query_node_autofilled_ = element_.isAutofilled(); |
| 738 node->setSuggestedValue(value.substr(0, node->maxLength())); | 740 node->setSuggestedValue( |
| 741 blink::WebString::fromUTF16(value.substr(0, node->maxLength()))); |
| 739 node->setAutofilled(true); | 742 node->setAutofilled(true); |
| 740 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node); | 743 form_util::PreviewSuggestion(node->suggestedValue().utf16(), |
| 744 node->value().utf16(), node); |
| 741 } | 745 } |
| 742 | 746 |
| 743 void AutofillAgent::ProcessForms() { | 747 void AutofillAgent::ProcessForms() { |
| 744 // Record timestamp of when the forms are first seen. This is used to | 748 // Record timestamp of when the forms are first seen. This is used to |
| 745 // measure the overhead of the Autofill feature. | 749 // measure the overhead of the Autofill feature. |
| 746 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); | 750 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); |
| 747 | 751 |
| 748 WebLocalFrame* frame = render_frame()->GetWebFrame(); | 752 WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 749 std::vector<FormData> forms = form_cache_.ExtractNewForms(); | 753 std::vector<FormData> forms = form_cache_.ExtractNewForms(); |
| 750 | 754 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | 822 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 819 // No-op. Don't delete |this|. | 823 // No-op. Don't delete |this|. |
| 820 } | 824 } |
| 821 | 825 |
| 822 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | 826 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
| 823 if (agent_) | 827 if (agent_) |
| 824 agent_->FocusChangeComplete(); | 828 agent_->FocusChangeComplete(); |
| 825 } | 829 } |
| 826 | 830 |
| 827 } // namespace autofill | 831 } // namespace autofill |
| OLD | NEW |