Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: components/autofill/renderer/autofill_agent.cc

Issue 13264002: Requery the autofill server when forms and input fields are dynamically added. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename some things, move around others Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 autofill_query_id_(0), 145 autofill_query_id_(0),
146 autofill_action_(AUTOFILL_NONE), 146 autofill_action_(AUTOFILL_NONE),
147 topmost_frame_(NULL), 147 topmost_frame_(NULL),
148 web_view_(render_view->GetWebView()), 148 web_view_(render_view->GetWebView()),
149 display_warning_if_disabled_(false), 149 display_warning_if_disabled_(false),
150 was_query_node_autofilled_(false), 150 was_query_node_autofilled_(false),
151 has_shown_autofill_popup_for_current_edit_(false), 151 has_shown_autofill_popup_for_current_edit_(false),
152 did_set_node_text_(false), 152 did_set_node_text_(false),
153 autocheckout_click_in_progress_(false), 153 autocheckout_click_in_progress_(false),
154 is_whitelisted_for_autocheckout_(false), 154 is_whitelisted_for_autocheckout_(false),
155 has_new_forms_for_manager_(false),
155 ignore_text_changes_(false), 156 ignore_text_changes_(false),
156 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 157 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
157 render_view->GetWebView()->setAutofillClient(this); 158 render_view->GetWebView()->setAutofillClient(this);
158 } 159 }
159 160
160 AutofillAgent::~AutofillAgent() {} 161 AutofillAgent::~AutofillAgent() {}
161 162
162 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { 163 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
163 bool handled = true; 164 bool handled = true;
164 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) 165 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (!frame->parent()) { 205 if (!frame->parent()) {
205 topmost_frame_ = frame; 206 topmost_frame_ = frame;
206 form_elements_.clear(); 207 form_elements_.clear();
207 has_more_forms = form_cache_.ExtractFormsAndFormElements( 208 has_more_forms = form_cache_.ExtractFormsAndFormElements(
208 *frame, kRequiredAutofillFields, &forms, &form_elements_); 209 *frame, kRequiredAutofillFields, &forms, &form_elements_);
209 is_whitelisted_for_autocheckout_ = false; 210 is_whitelisted_for_autocheckout_ = false;
210 } else { 211 } else {
211 form_cache_.ExtractForms(*frame, &forms); 212 form_cache_.ExtractForms(*frame, &forms);
212 } 213 }
213 214
215 autofill::FormsSeenParam param = has_more_forms ?
216 autofill::PARTIAL_FORMS_SEEN : autofill::NO_SPECIAL_FORMS_SEEN;
217
214 // Always communicate to browser process for topmost frame. 218 // Always communicate to browser process for topmost frame.
215 if (!forms.empty() || !frame->parent()) { 219 if (!forms.empty() || !frame->parent()) {
216 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, 220 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
217 forms_seen_timestamp_, 221 forms_seen_timestamp_,
218 has_more_forms)); 222 param));
219 } 223 }
220 } 224 }
221 225
222 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { 226 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) {
223 if (!frame->parent()) { 227 if (!frame->parent()) {
224 topmost_frame_ = NULL; 228 topmost_frame_ = NULL;
225 if (click_timer_.IsRunning()) { 229 if (click_timer_.IsRunning()) {
226 click_timer_.Stop(); 230 click_timer_.Stop();
227 autocheckout_click_in_progress_ = true; 231 autocheckout_click_in_progress_ = true;
228 } 232 }
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 std::vector<FormData> forms; 722 std::vector<FormData> forms;
719 form_cache_.ExtractFormsAndFormElements( 723 form_cache_.ExtractFormsAndFormElements(
720 *topmost_frame_, 0, &forms, &form_elements_); 724 *topmost_frame_, 0, &forms, &form_elements_);
721 725
722 // OnGetAllForms should only be called if AutofillAgent reported to 726 // OnGetAllForms should only be called if AutofillAgent reported to
723 // AutofillManager that there are more forms 727 // AutofillManager that there are more forms
724 DCHECK(!forms.empty()); 728 DCHECK(!forms.empty());
725 729
726 // Report to AutofillManager that all forms are being sent. 730 // Report to AutofillManager that all forms are being sent.
727 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, 731 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
728 forms_seen_timestamp_, false)); 732 forms_seen_timestamp_,
733 NO_SPECIAL_FORMS_SEEN));
729 } 734 }
730 735
731 void AutofillAgent::OnRequestAutocompleteResult( 736 void AutofillAgent::OnRequestAutocompleteResult(
732 WebFormElement::AutocompleteResult result, const FormData& form_data) { 737 WebFormElement::AutocompleteResult result, const FormData& form_data) {
733 if (in_flight_request_form_.isNull()) 738 if (in_flight_request_form_.isNull())
734 return; 739 return;
735 740
736 if (result == WebFormElement::AutocompleteResultSuccess) 741 if (result == WebFormElement::AutocompleteResultSuccess)
737 FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_); 742 FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_);
738 743
(...skipping 27 matching lines...) Expand all
766 if (!ClickElement(topmost_frame_->document(), 771 if (!ClickElement(topmost_frame_->document(),
767 click_element_descriptor)) { 772 click_element_descriptor)) {
768 click_timer_.Stop(); 773 click_timer_.Stop();
769 Send(new AutofillHostMsg_ClickFailed(routing_id(), 774 Send(new AutofillHostMsg_ClickFailed(routing_id(),
770 MISSING_ADVANCE)); 775 MISSING_ADVANCE));
771 } 776 }
772 } 777 }
773 778
774 void AutofillAgent::OnWhitelistedForAutocheckout() { 779 void AutofillAgent::OnWhitelistedForAutocheckout() {
775 is_whitelisted_for_autocheckout_ = true; 780 is_whitelisted_for_autocheckout_ = true;
781 if (has_new_forms_for_manager_)
782 MaybeSendDynamicFormsSeen();
776 } 783 }
777 784
778 void AutofillAgent::ClickFailed() { 785 void AutofillAgent::ClickFailed() {
779 Send(new AutofillHostMsg_ClickFailed(routing_id(), 786 Send(new AutofillHostMsg_ClickFailed(routing_id(),
780 CANNOT_PROCEED)); 787 CANNOT_PROCEED));
781 } 788 }
782 789
783 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 790 void AutofillAgent::ShowSuggestions(const WebInputElement& element,
784 bool autofill_on_empty_values, 791 bool autofill_on_empty_values,
785 bool requires_caret_at_end, 792 bool requires_caret_at_end,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 if (web_view) 932 if (web_view)
926 web_view->hidePopups(); 933 web_view->hidePopups();
927 934
928 HideHostAutofillUi(); 935 HideHostAutofillUi();
929 } 936 }
930 937
931 void AutofillAgent::HideHostAutofillUi() { 938 void AutofillAgent::HideHostAutofillUi() {
932 Send(new AutofillHostMsg_HideAutofillUi(routing_id())); 939 Send(new AutofillHostMsg_HideAutofillUi(routing_id()));
933 } 940 }
934 941
942 void AutofillAgent::didAssociateFormControls(
943 const WebKit::WebVector<WebKit::WebNode>& nodes) {
944 for (size_t i = 0; i < nodes.size(); ++i) {
945 WebKit::WebNode node = nodes[i];
946 if (node.document().frame() == topmost_frame_) {
947 forms_seen_timestamp_ = base::TimeTicks::Now();
948 has_new_forms_for_manager_ = true;
949 break;
950 }
951 }
952
953 if (has_new_forms_for_manager_ && is_whitelisted_for_autocheckout_)
954 MaybeSendDynamicFormsSeen();
955 }
956
957 void AutofillAgent::MaybeSendDynamicFormsSeen() {
958 has_new_forms_for_manager_ = false;
959 form_elements_.clear();
960
961 std::vector<FormData> forms;
962 bool has_more_forms = form_cache_.ExtractFormsAndFormElements(
963 *topmost_frame_, kRequiredAutofillFields, &forms, &form_elements_);
964 autofill::FormsSeenParam param = has_more_forms ?
965 autofill::PARTIAL_AND_DYNAMIC_FORMS_SEEN : autofill::DYNAMIC_FORMS_SEEN;
966
967 if (!forms.empty()) {
968 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
969 forms_seen_timestamp_,
970 param));
971 }
972 }
973
935 } // namespace autofill 974 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698