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 "components/autofill/renderer/autofill_agent.h" | 5 #include "components/autofill/renderer/autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 if (!frame->parent()) { | 205 if (!frame->parent()) { |
| 206 topmost_frame_ = frame; | 206 topmost_frame_ = frame; |
| 207 form_elements_.clear(); | 207 form_elements_.clear(); |
| 208 has_more_forms = form_cache_.ExtractFormsAndFormElements( | 208 has_more_forms = form_cache_.ExtractFormsAndFormElements( |
| 209 *frame, kRequiredAutofillFields, &forms, &form_elements_); | 209 *frame, kRequiredAutofillFields, &forms, &form_elements_); |
| 210 is_whitelisted_for_autocheckout_ = false; | 210 is_whitelisted_for_autocheckout_ = false; |
| 211 } else { | 211 } else { |
| 212 form_cache_.ExtractForms(*frame, &forms); | 212 form_cache_.ExtractForms(*frame, &forms); |
| 213 } | 213 } |
| 214 | 214 |
| 215 autofill::FormsSeenParam param = has_more_forms ? | |
| 216 autofill::PARTIAL_FORMS_SEEN : autofill::NO_SPECIAL_FORMS_SEEN; | |
| 217 | |
| 215 // Always communicate to browser process for topmost frame. | 218 // Always communicate to browser process for topmost frame. |
| 216 if (!forms.empty() || !frame->parent()) { | 219 if (!forms.empty() || !frame->parent()) { |
| 217 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 220 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
| 218 forms_seen_timestamp_, | 221 forms_seen_timestamp_, |
| 219 has_more_forms)); | 222 param)); |
| 220 } | 223 } |
| 221 } | 224 } |
| 222 | 225 |
| 223 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { | 226 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { |
| 224 if (!frame->parent()) { | 227 if (!frame->parent()) { |
| 225 topmost_frame_ = NULL; | 228 topmost_frame_ = NULL; |
| 226 if (click_timer_.IsRunning()) { | 229 if (click_timer_.IsRunning()) { |
| 227 click_timer_.Stop(); | 230 click_timer_.Stop(); |
| 228 autocheckout_click_in_progress_ = true; | 231 autocheckout_click_in_progress_ = true; |
| 229 } | 232 } |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 std::vector<FormData> forms; | 722 std::vector<FormData> forms; |
| 720 form_cache_.ExtractFormsAndFormElements( | 723 form_cache_.ExtractFormsAndFormElements( |
| 721 *topmost_frame_, 0, &forms, &form_elements_); | 724 *topmost_frame_, 0, &forms, &form_elements_); |
| 722 | 725 |
| 723 // OnGetAllForms should only be called if AutofillAgent reported to | 726 // OnGetAllForms should only be called if AutofillAgent reported to |
| 724 // AutofillManager that there are more forms | 727 // AutofillManager that there are more forms |
| 725 DCHECK(!forms.empty()); | 728 DCHECK(!forms.empty()); |
| 726 | 729 |
| 727 // Report to AutofillManager that all forms are being sent. | 730 // Report to AutofillManager that all forms are being sent. |
| 728 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 731 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
| 729 forms_seen_timestamp_, false)); | 732 forms_seen_timestamp_, |
| 733 NO_SPECIAL_FORMS_SEEN)); | |
| 730 } | 734 } |
| 731 | 735 |
| 732 void AutofillAgent::OnRequestAutocompleteResult( | 736 void AutofillAgent::OnRequestAutocompleteResult( |
| 733 WebFormElement::AutocompleteResult result, const FormData& form_data) { | 737 WebFormElement::AutocompleteResult result, const FormData& form_data) { |
| 734 if (in_flight_request_form_.isNull()) | 738 if (in_flight_request_form_.isNull()) |
| 735 return; | 739 return; |
| 736 | 740 |
| 737 if (result == WebFormElement::AutocompleteResultSuccess) | 741 if (result == WebFormElement::AutocompleteResultSuccess) |
| 738 FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_); | 742 FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_); |
| 739 | 743 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 767 if (!ClickElement(topmost_frame_->document(), | 771 if (!ClickElement(topmost_frame_->document(), |
| 768 click_element_descriptor)) { | 772 click_element_descriptor)) { |
| 769 click_timer_.Stop(); | 773 click_timer_.Stop(); |
| 770 Send(new AutofillHostMsg_ClickFailed(routing_id(), | 774 Send(new AutofillHostMsg_ClickFailed(routing_id(), |
| 771 MISSING_ADVANCE)); | 775 MISSING_ADVANCE)); |
| 772 } | 776 } |
| 773 } | 777 } |
| 774 | 778 |
| 775 void AutofillAgent::OnWhitelistedForAutocheckout() { | 779 void AutofillAgent::OnWhitelistedForAutocheckout() { |
| 776 is_whitelisted_for_autocheckout_ = true; | 780 is_whitelisted_for_autocheckout_ = true; |
| 781 if (forms_have_changed_since_load_) | |
| 782 SendDynamicFormsSeen(); | |
| 777 } | 783 } |
| 778 | 784 |
| 779 void AutofillAgent::ClickFailed() { | 785 void AutofillAgent::ClickFailed() { |
| 780 Send(new AutofillHostMsg_ClickFailed(routing_id(), | 786 Send(new AutofillHostMsg_ClickFailed(routing_id(), |
| 781 CANNOT_PROCEED)); | 787 CANNOT_PROCEED)); |
| 782 } | 788 } |
| 783 | 789 |
| 784 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 790 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
| 785 bool autofill_on_empty_values, | 791 bool autofill_on_empty_values, |
| 786 bool requires_caret_at_end, | 792 bool requires_caret_at_end, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 if (web_view) | 930 if (web_view) |
| 925 web_view->hidePopups(); | 931 web_view->hidePopups(); |
| 926 | 932 |
| 927 HideHostAutofillUi(); | 933 HideHostAutofillUi(); |
| 928 } | 934 } |
| 929 | 935 |
| 930 void AutofillAgent::HideHostAutofillUi() { | 936 void AutofillAgent::HideHostAutofillUi() { |
| 931 Send(new AutofillHostMsg_HideAutofillUi(routing_id())); | 937 Send(new AutofillHostMsg_HideAutofillUi(routing_id())); |
| 932 } | 938 } |
| 933 | 939 |
| 940 void AutofillAgent::didAssociateFormControls( | |
| 941 const WebKit::WebVector<WebKit::WebNode>& nodes) { | |
| 942 for (size_t i = 0; i < nodes.size(); ++i) { | |
| 943 WebKit::WebNode node = nodes[i]; | |
| 944 if (node.document().frame() == topmost_frame_) { | |
| 945 forms_seen_timestamp_ = base::TimeTicks::Now(); | |
| 946 forms_have_changed_since_load_ = true; | |
| 947 break; | |
| 948 } | |
| 949 } | |
| 950 | |
| 951 if (forms_have_changed_since_load_ && is_whitelisted_for_autocheckout_) | |
| 952 SendDynamicFormsSeen(); | |
| 953 } | |
| 954 | |
| 955 void AutofillAgent::SendDynamicFormsSeen() { | |
|
Ilya Sherman
2013/04/06 00:29:39
nit: Please name this MaybeSendDynamicFormsSeen(),
Dane Wallinga
2013/04/08 22:55:50
Done.
| |
| 956 forms_have_changed_since_load_ = false; | |
| 957 bool has_more_forms = false; | |
| 958 std::vector<FormData> forms; | |
| 959 form_elements_.clear(); | |
| 960 has_more_forms = form_cache_.ExtractFormsAndFormElements( | |
| 961 *topmost_frame_, kRequiredAutofillFields, &forms, &form_elements_); | |
|
Ilya Sherman
2013/04/06 00:29:39
nit: Write these six lines like so:
forms_have_
Dane Wallinga
2013/04/08 22:55:50
Done.
| |
| 962 autofill::FormsSeenParam param = has_more_forms ? | |
| 963 autofill::PARTIAL_AND_DYNAMIC_FORMS_SEEN : autofill::DYNAMIC_FORMS_SEEN; | |
| 964 | |
| 965 if (!forms.empty()) { | |
| 966 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | |
| 967 forms_seen_timestamp_, | |
| 968 param)); | |
| 969 } | |
| 970 } | |
| 971 | |
| 934 } // namespace autofill | 972 } // namespace autofill |
| OLD | NEW |