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" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "components/autofill/common/autocheckout_status.h" | 14 #include "components/autofill/common/autocheckout_status.h" |
| 15 #include "components/autofill/common/autofill_constants.h" | 15 #include "components/autofill/common/autofill_constants.h" |
| 16 #include "components/autofill/common/autofill_messages.h" | 16 #include "components/autofill/common/autofill_messages.h" |
| 17 #include "components/autofill/common/autofill_switches.h" | 17 #include "components/autofill/common/autofill_switches.h" |
| 18 #include "components/autofill/common/form_data.h" | 18 #include "components/autofill/common/form_data.h" |
| 19 #include "components/autofill/common/form_data_predictions.h" | 19 #include "components/autofill/common/form_data_predictions.h" |
| 20 #include "components/autofill/common/form_field_data.h" | 20 #include "components/autofill/common/form_field_data.h" |
| 21 #include "components/autofill/common/forms_seen_param.h" | |
| 21 #include "components/autofill/common/web_element_descriptor.h" | 22 #include "components/autofill/common/web_element_descriptor.h" |
| 22 #include "components/autofill/renderer/form_autofill_util.h" | 23 #include "components/autofill/renderer/form_autofill_util.h" |
| 23 #include "components/autofill/renderer/password_autofill_manager.h" | 24 #include "components/autofill/renderer/password_autofill_manager.h" |
| 24 #include "content/public/common/password_form.h" | 25 #include "content/public/common/password_form.h" |
| 25 #include "content/public/common/ssl_status.h" | 26 #include "content/public/common/ssl_status.h" |
| 26 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
| 27 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 29 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
| 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" | 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 if (!frame->parent()) { | 206 if (!frame->parent()) { |
| 206 topmost_frame_ = frame; | 207 topmost_frame_ = frame; |
| 207 form_elements_.clear(); | 208 form_elements_.clear(); |
| 208 has_more_forms = form_cache_.ExtractFormsAndFormElements( | 209 has_more_forms = form_cache_.ExtractFormsAndFormElements( |
| 209 *frame, kRequiredAutofillFields, &forms, &form_elements_); | 210 *frame, kRequiredAutofillFields, &forms, &form_elements_); |
| 210 is_whitelisted_for_autocheckout_ = false; | 211 is_whitelisted_for_autocheckout_ = false; |
| 211 } else { | 212 } else { |
| 212 form_cache_.ExtractForms(*frame, &forms); | 213 form_cache_.ExtractForms(*frame, &forms); |
| 213 } | 214 } |
| 214 | 215 |
| 216 FormsSeenParam param = has_more_forms ? | |
| 217 autofill::NO_SPECIAL_FORMS_SEEN : autofill::PARTIAL_FORMS_SEEN; | |
|
ahutter
2013/04/02 20:11:47
Is this logic right?
Dane Wallinga
2013/04/02 21:29:30
nope
| |
| 218 | |
| 215 // Always communicate to browser process for topmost frame. | 219 // Always communicate to browser process for topmost frame. |
| 216 if (!forms.empty() || !frame->parent()) { | 220 if (!forms.empty() || !frame->parent()) { |
| 217 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 221 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
| 218 forms_seen_timestamp_, | 222 forms_seen_timestamp_, |
| 219 has_more_forms)); | 223 param)); |
| 220 } | 224 } |
| 221 } | 225 } |
| 222 | 226 |
| 223 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { | 227 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { |
| 224 if (!frame->parent()) { | 228 if (!frame->parent()) { |
| 225 topmost_frame_ = NULL; | 229 topmost_frame_ = NULL; |
| 226 if (click_timer_.IsRunning()) { | 230 if (click_timer_.IsRunning()) { |
| 227 click_timer_.Stop(); | 231 click_timer_.Stop(); |
| 228 autocheckout_click_in_progress_ = true; | 232 autocheckout_click_in_progress_ = true; |
| 229 } | 233 } |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 std::vector<FormData> forms; | 723 std::vector<FormData> forms; |
| 720 form_cache_.ExtractFormsAndFormElements( | 724 form_cache_.ExtractFormsAndFormElements( |
| 721 *topmost_frame_, 0, &forms, &form_elements_); | 725 *topmost_frame_, 0, &forms, &form_elements_); |
| 722 | 726 |
| 723 // OnGetAllForms should only be called if AutofillAgent reported to | 727 // OnGetAllForms should only be called if AutofillAgent reported to |
| 724 // AutofillManager that there are more forms | 728 // AutofillManager that there are more forms |
| 725 DCHECK(!forms.empty()); | 729 DCHECK(!forms.empty()); |
| 726 | 730 |
| 727 // Report to AutofillManager that all forms are being sent. | 731 // Report to AutofillManager that all forms are being sent. |
| 728 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 732 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
| 729 forms_seen_timestamp_, false)); | 733 forms_seen_timestamp_, |
| 734 NO_SPECIAL_FORMS_SEEN)); | |
| 730 } | 735 } |
| 731 | 736 |
| 732 void AutofillAgent::OnRequestAutocompleteResult( | 737 void AutofillAgent::OnRequestAutocompleteResult( |
| 733 WebFormElement::AutocompleteResult result, const FormData& form_data) { | 738 WebFormElement::AutocompleteResult result, const FormData& form_data) { |
| 734 if (in_flight_request_form_.isNull()) | 739 if (in_flight_request_form_.isNull()) |
| 735 return; | 740 return; |
| 736 | 741 |
| 737 if (result == WebFormElement::AutocompleteResultSuccess) | 742 if (result == WebFormElement::AutocompleteResultSuccess) |
| 738 FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_); | 743 FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_); |
| 739 | 744 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 767 if (!ClickElement(topmost_frame_->document(), | 772 if (!ClickElement(topmost_frame_->document(), |
| 768 click_element_descriptor)) { | 773 click_element_descriptor)) { |
| 769 click_timer_.Stop(); | 774 click_timer_.Stop(); |
| 770 Send(new AutofillHostMsg_ClickFailed(routing_id(), | 775 Send(new AutofillHostMsg_ClickFailed(routing_id(), |
| 771 MISSING_ADVANCE)); | 776 MISSING_ADVANCE)); |
| 772 } | 777 } |
| 773 } | 778 } |
| 774 | 779 |
| 775 void AutofillAgent::OnWhitelistedForAutocheckout() { | 780 void AutofillAgent::OnWhitelistedForAutocheckout() { |
| 776 is_whitelisted_for_autocheckout_ = true; | 781 is_whitelisted_for_autocheckout_ = true; |
| 782 if (forms_have_changed_since_load_) { | |
| 783 forms_have_changed_since_load_ = false; | |
| 784 bool has_more_forms = false; | |
| 785 std::vector<FormData> forms; | |
| 786 form_elements_.clear(); | |
| 787 has_more_forms = form_cache_.ExtractFormsAndFormElements( | |
| 788 *topmost_frame_, kRequiredAutofillFields, &forms, &form_elements_); | |
| 789 FormsSeenParam param = has_more_forms ? | |
| 790 autofill::DYNAMIC_FORMS_SEEN : autofill::PARTIAL_AND_DYNAMIC_FORMS_SEEN; | |
|
ahutter
2013/04/02 20:11:47
Is this backwards?
Dane Wallinga
2013/04/02 21:29:30
most certainly
| |
| 791 if (!forms.empty()) { | |
| 792 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | |
| 793 base::TimeTicks::Now(), | |
|
Raman Kakilate
2013/04/02 20:30:19
timestamp should be the one at which this form is
Dane Wallinga
2013/04/02 21:29:30
Done.
| |
| 794 param)); | |
| 795 } | |
| 796 } | |
| 777 } | 797 } |
| 778 | 798 |
| 779 void AutofillAgent::ClickFailed() { | 799 void AutofillAgent::ClickFailed() { |
| 780 Send(new AutofillHostMsg_ClickFailed(routing_id(), | 800 Send(new AutofillHostMsg_ClickFailed(routing_id(), |
| 781 CANNOT_PROCEED)); | 801 CANNOT_PROCEED)); |
| 782 } | 802 } |
| 783 | 803 |
| 784 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 804 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
| 785 bool autofill_on_empty_values, | 805 bool autofill_on_empty_values, |
| 786 bool requires_caret_at_end, | 806 bool requires_caret_at_end, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 924 if (web_view) | 944 if (web_view) |
| 925 web_view->hidePopups(); | 945 web_view->hidePopups(); |
| 926 | 946 |
| 927 HideHostAutofillUi(); | 947 HideHostAutofillUi(); |
| 928 } | 948 } |
| 929 | 949 |
| 930 void AutofillAgent::HideHostAutofillUi() { | 950 void AutofillAgent::HideHostAutofillUi() { |
| 931 Send(new AutofillHostMsg_HideAutofillUi(routing_id())); | 951 Send(new AutofillHostMsg_HideAutofillUi(routing_id())); |
| 932 } | 952 } |
| 933 | 953 |
| 954 void AutofillAgent::didAssociateFormControls( | |
| 955 const WebKit::WebVector<WebKit::WebNode>& nodes) { | |
| 956 for (size_t i = 0; i < nodes.size(); ++i) { | |
| 957 WebKit::WebNode node = nodes[i]; | |
| 958 if (node.document().frame() == topmost_frame_) { | |
| 959 forms_have_changed_since_load_ = true; | |
| 960 break; | |
| 961 } | |
| 962 } | |
|
ahutter
2013/04/02 20:11:47
new line.
Dane Wallinga
2013/04/02 21:29:30
Done.
| |
| 963 if (forms_have_changed_since_load_ && is_whitelisted_for_autocheckout_) { | |
| 964 forms_have_changed_since_load_ = false; | |
|
ahutter
2013/04/02 20:11:47
Extract into a function maybe?
| |
| 965 bool has_more_forms = false; | |
| 966 std::vector<FormData> forms; | |
| 967 form_elements_.clear(); | |
| 968 has_more_forms = form_cache_.ExtractFormsAndFormElements( | |
| 969 *topmost_frame_, kRequiredAutofillFields, &forms, &form_elements_); | |
| 970 FormsSeenParam param = has_more_forms ? | |
| 971 autofill::DYNAMIC_FORMS_SEEN : autofill::PARTIAL_AND_DYNAMIC_FORMS_SEEN; | |
| 972 if (!forms.empty()) { | |
| 973 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | |
| 974 base::TimeTicks::Now(), | |
|
Raman Kakilate
2013/04/02 20:30:19
record the timestamp at the start of the function.
Dane Wallinga
2013/04/02 21:29:30
Done.
| |
| 975 param)); | |
| 976 } | |
| 977 } | |
| 978 } | |
| 979 | |
| 934 } // namespace autofill | 980 } // namespace autofill |
| OLD | NEW |