| 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 24 matching lines...) Expand all Loading... |
| 35 #include "components/autofill/core/common/form_data_predictions.h" | 35 #include "components/autofill/core/common/form_data_predictions.h" |
| 36 #include "components/autofill/core/common/form_field_data.h" | 36 #include "components/autofill/core/common/form_field_data.h" |
| 37 #include "components/autofill/core/common/password_form.h" | 37 #include "components/autofill/core/common/password_form.h" |
| 38 #include "components/autofill/core/common/password_form_fill_data.h" | 38 #include "components/autofill/core/common/password_form_fill_data.h" |
| 39 #include "components/autofill/core/common/save_password_progress_logger.h" | 39 #include "components/autofill/core/common/save_password_progress_logger.h" |
| 40 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/content_switches.h" |
| 41 #include "content/public/common/ssl_status.h" | 41 #include "content/public/common/ssl_status.h" |
| 42 #include "content/public/common/url_constants.h" | 42 #include "content/public/common/url_constants.h" |
| 43 #include "content/public/renderer/render_frame.h" | 43 #include "content/public/renderer/render_frame.h" |
| 44 #include "content/public/renderer/render_view.h" | 44 #include "content/public/renderer/render_view.h" |
| 45 #include "mojo/common/common_type_converters.h" | |
| 46 #include "net/cert/cert_status_flags.h" | 45 #include "net/cert/cert_status_flags.h" |
| 47 #include "services/shell/public/cpp/interface_provider.h" | 46 #include "services/shell/public/cpp/interface_provider.h" |
| 48 #include "services/shell/public/cpp/interface_registry.h" | 47 #include "services/shell/public/cpp/interface_registry.h" |
| 49 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 48 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 50 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 49 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 51 #include "third_party/WebKit/public/web/WebDataSource.h" | 50 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 52 #include "third_party/WebKit/public/web/WebDocument.h" | 51 #include "third_party/WebKit/public/web/WebDocument.h" |
| 53 #include "third_party/WebKit/public/web/WebElementCollection.h" | 52 #include "third_party/WebKit/public/web/WebElementCollection.h" |
| 54 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 53 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 55 #include "third_party/WebKit/public/web/WebFormElement.h" | 54 #include "third_party/WebKit/public/web/WebFormElement.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 form_util::PreviewForm(form, element_); | 506 form_util::PreviewForm(form, element_); |
| 508 | 507 |
| 509 GetAutofillDriver()->DidPreviewAutofillFormData(); | 508 GetAutofillDriver()->DidPreviewAutofillFormData(); |
| 510 } | 509 } |
| 511 | 510 |
| 512 void AutofillAgent::OnPing() { | 511 void AutofillAgent::OnPing() { |
| 513 GetAutofillDriver()->PingAck(); | 512 GetAutofillDriver()->PingAck(); |
| 514 } | 513 } |
| 515 | 514 |
| 516 void AutofillAgent::FieldTypePredictionsAvailable( | 515 void AutofillAgent::FieldTypePredictionsAvailable( |
| 517 mojo::Array<FormDataPredictions> forms) { | 516 const std::vector<FormDataPredictions>& forms) { |
| 518 for (const auto& form : forms) { | 517 for (const auto& form : forms) { |
| 519 form_cache_.ShowPredictions(form); | 518 form_cache_.ShowPredictions(form); |
| 520 } | 519 } |
| 521 } | 520 } |
| 522 | 521 |
| 523 void AutofillAgent::ClearForm() { | 522 void AutofillAgent::ClearForm() { |
| 524 form_cache_.ClearFormWithElement(element_); | 523 form_cache_.ClearFormWithElement(element_); |
| 525 } | 524 } |
| 526 | 525 |
| 527 void AutofillAgent::ClearPreviewedForm() { | 526 void AutofillAgent::ClearPreviewedForm() { |
| 528 if (!element_.isNull()) { | 527 if (!element_.isNull()) { |
| 529 if (password_autofill_agent_->DidClearAutofillSelection(element_)) | 528 if (password_autofill_agent_->DidClearAutofillSelection(element_)) |
| 530 return; | 529 return; |
| 531 | 530 |
| 532 form_util::ClearPreviewedFormWithElement(element_, | 531 form_util::ClearPreviewedFormWithElement(element_, |
| 533 was_query_node_autofilled_); | 532 was_query_node_autofilled_); |
| 534 } else { | 533 } else { |
| 535 // TODO(isherman): There seem to be rare cases where this code *is* | 534 // TODO(isherman): There seem to be rare cases where this code *is* |
| 536 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would | 535 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would |
| 537 // understand those cases and fix the code to avoid them. However, so far I | 536 // understand those cases and fix the code to avoid them. However, so far I |
| 538 // have been unable to reproduce such a case locally. If you hit this | 537 // have been unable to reproduce such a case locally. If you hit this |
| 539 // NOTREACHED(), please file a bug against me. | 538 // NOTREACHED(), please file a bug against me. |
| 540 NOTREACHED(); | 539 NOTREACHED(); |
| 541 } | 540 } |
| 542 } | 541 } |
| 543 | 542 |
| 544 void AutofillAgent::FillFieldWithValue(const mojo::String& value) { | 543 void AutofillAgent::FillFieldWithValue(const base::string16& value) { |
| 545 WebInputElement* input_element = toWebInputElement(&element_); | 544 WebInputElement* input_element = toWebInputElement(&element_); |
| 546 if (input_element) { | 545 if (input_element) { |
| 547 DoFillFieldWithValue(value.To<base::string16>(), input_element); | 546 DoFillFieldWithValue(value, input_element); |
| 548 input_element->setAutofilled(true); | 547 input_element->setAutofilled(true); |
| 549 } | 548 } |
| 550 } | 549 } |
| 551 | 550 |
| 552 void AutofillAgent::PreviewFieldWithValue(const mojo::String& value) { | 551 void AutofillAgent::PreviewFieldWithValue(const base::string16& value) { |
| 553 WebInputElement* input_element = toWebInputElement(&element_); | 552 WebInputElement* input_element = toWebInputElement(&element_); |
| 554 if (input_element) | 553 if (input_element) |
| 555 DoPreviewFieldWithValue(value.To<base::string16>(), input_element); | 554 DoPreviewFieldWithValue(value, input_element); |
| 556 } | 555 } |
| 557 | 556 |
| 558 void AutofillAgent::AcceptDataListSuggestion(const mojo::String& value) { | 557 void AutofillAgent::AcceptDataListSuggestion(const base::string16& value) { |
| 559 DoAcceptDataListSuggestion(value.To<base::string16>()); | 558 DoAcceptDataListSuggestion(value); |
| 560 } | 559 } |
| 561 | 560 |
| 562 void AutofillAgent::FillPasswordSuggestion(const mojo::String& username, | 561 void AutofillAgent::FillPasswordSuggestion(const base::string16& username, |
| 563 const mojo::String& password) { | 562 const base::string16& password) { |
| 564 bool handled = password_autofill_agent_->FillSuggestion( | 563 bool handled = |
| 565 element_, username.To<base::string16>(), password.To<base::string16>()); | 564 password_autofill_agent_->FillSuggestion(element_, username, password); |
| 566 DCHECK(handled); | 565 DCHECK(handled); |
| 567 } | 566 } |
| 568 | 567 |
| 569 void AutofillAgent::PreviewPasswordSuggestion(const mojo::String& username, | 568 void AutofillAgent::PreviewPasswordSuggestion(const base::string16& username, |
| 570 const mojo::String& password) { | 569 const base::string16& password) { |
| 571 bool handled = password_autofill_agent_->PreviewSuggestion( | 570 bool handled = |
| 572 element_, username.To<base::string16>(), password.To<base::string16>()); | 571 password_autofill_agent_->PreviewSuggestion(element_, username, password); |
| 573 DCHECK(handled); | 572 DCHECK(handled); |
| 574 } | 573 } |
| 575 | 574 |
| 576 void AutofillAgent::ShowInitialPasswordAccountSuggestions( | 575 void AutofillAgent::ShowInitialPasswordAccountSuggestions( |
| 577 int32_t key, | 576 int32_t key, |
| 578 const PasswordFormFillData& form_data) { | 577 const PasswordFormFillData& form_data) { |
| 579 std::vector<blink::WebInputElement> elements; | 578 std::vector<blink::WebInputElement> elements; |
| 580 std::unique_ptr<RendererSavePasswordProgressLogger> logger; | 579 std::unique_ptr<RendererSavePasswordProgressLogger> logger; |
| 581 if (password_autofill_agent_->logging_state_active()) { | 580 if (password_autofill_agent_->logging_state_active()) { |
| 582 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); | 581 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 // Find the datalist values and send them to the browser process. | 727 // Find the datalist values and send them to the browser process. |
| 729 GetDataListSuggestions(*input_element, | 728 GetDataListSuggestions(*input_element, |
| 730 &data_list_values, | 729 &data_list_values, |
| 731 &data_list_labels); | 730 &data_list_labels); |
| 732 TrimStringVectorForIPC(&data_list_values); | 731 TrimStringVectorForIPC(&data_list_values); |
| 733 TrimStringVectorForIPC(&data_list_labels); | 732 TrimStringVectorForIPC(&data_list_labels); |
| 734 } | 733 } |
| 735 | 734 |
| 736 is_popup_possibly_visible_ = true; | 735 is_popup_possibly_visible_ = true; |
| 737 | 736 |
| 738 GetAutofillDriver()->SetDataList( | 737 GetAutofillDriver()->SetDataList(data_list_values, data_list_labels); |
| 739 mojo::Array<mojo::String>::From(data_list_values), | |
| 740 mojo::Array<mojo::String>::From(data_list_labels)); | |
| 741 GetAutofillDriver()->QueryFormFieldAutofill( | 738 GetAutofillDriver()->QueryFormFieldAutofill( |
| 742 autofill_query_id_, form, field, | 739 autofill_query_id_, form, field, |
| 743 render_frame()->GetRenderView()->ElementBoundsInWindow(element_)); | 740 render_frame()->GetRenderView()->ElementBoundsInWindow(element_)); |
| 744 } | 741 } |
| 745 | 742 |
| 746 void AutofillAgent::DoFillFieldWithValue(const base::string16& value, | 743 void AutofillAgent::DoFillFieldWithValue(const base::string16& value, |
| 747 WebInputElement* node) { | 744 WebInputElement* node) { |
| 748 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true); | 745 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true); |
| 749 node->setEditingValue(value.substr(0, node->maxLength())); | 746 node->setEditingValue(value.substr(0, node->maxLength())); |
| 750 } | 747 } |
| 751 | 748 |
| 752 void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value, | 749 void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value, |
| 753 WebInputElement* node) { | 750 WebInputElement* node) { |
| 754 was_query_node_autofilled_ = element_.isAutofilled(); | 751 was_query_node_autofilled_ = element_.isAutofilled(); |
| 755 node->setSuggestedValue(value.substr(0, node->maxLength())); | 752 node->setSuggestedValue(value.substr(0, node->maxLength())); |
| 756 node->setAutofilled(true); | 753 node->setAutofilled(true); |
| 757 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node); | 754 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node); |
| 758 } | 755 } |
| 759 | 756 |
| 760 void AutofillAgent::ProcessForms() { | 757 void AutofillAgent::ProcessForms() { |
| 761 // Record timestamp of when the forms are first seen. This is used to | 758 // Record timestamp of when the forms are first seen. This is used to |
| 762 // measure the overhead of the Autofill feature. | 759 // measure the overhead of the Autofill feature. |
| 763 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); | 760 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); |
| 764 | 761 |
| 765 WebLocalFrame* frame = render_frame()->GetWebFrame(); | 762 WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 766 std::vector<FormData> forms = form_cache_.ExtractNewForms(); | 763 std::vector<FormData> forms = form_cache_.ExtractNewForms(); |
| 767 | 764 |
| 768 // Always communicate to browser process for topmost frame. | 765 // Always communicate to browser process for topmost frame. |
| 769 if (!forms.empty() || !frame->parent()) { | 766 if (!forms.empty() || !frame->parent()) { |
| 770 GetAutofillDriver()->FormsSeen(std::move(forms), forms_seen_timestamp); | 767 GetAutofillDriver()->FormsSeen(forms, forms_seen_timestamp); |
| 771 } | 768 } |
| 772 } | 769 } |
| 773 | 770 |
| 774 void AutofillAgent::HidePopup() { | 771 void AutofillAgent::HidePopup() { |
| 775 if (!is_popup_possibly_visible_) | 772 if (!is_popup_possibly_visible_) |
| 776 return; | 773 return; |
| 777 is_popup_possibly_visible_ = false; | 774 is_popup_possibly_visible_ = false; |
| 778 is_generation_popup_possibly_visible_ = false; | 775 is_generation_popup_possibly_visible_ = false; |
| 779 | 776 |
| 780 GetAutofillDriver()->HidePopup(); | 777 GetAutofillDriver()->HidePopup(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | 830 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 834 // No-op. Don't delete |this|. | 831 // No-op. Don't delete |this|. |
| 835 } | 832 } |
| 836 | 833 |
| 837 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | 834 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
| 838 if (agent_) | 835 if (agent_) |
| 839 agent_->FocusChangeComplete(); | 836 agent_->FocusChangeComplete(); |
| 840 } | 837 } |
| 841 | 838 |
| 842 } // namespace autofill | 839 } // namespace autofill |
| OLD | NEW |