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

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: And a bit of cleanup 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
« no previous file with comments | « components/autofill/renderer/autofill_agent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_browser_(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 // The PageClickTracker is a RenderViewObserver, and hence will be freed when 160 // The PageClickTracker is a RenderViewObserver, and hence will be freed when
160 // the RenderView is destroyed. 161 // the RenderView is destroyed.
161 new PageClickTracker(render_view, this); 162 new PageClickTracker(render_view, this);
162 } 163 }
163 164
164 AutofillAgent::~AutofillAgent() {} 165 AutofillAgent::~AutofillAgent() {}
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 if (!frame->parent()) { 209 if (!frame->parent()) {
209 topmost_frame_ = frame; 210 topmost_frame_ = frame;
210 form_elements_.clear(); 211 form_elements_.clear();
211 has_more_forms = form_cache_.ExtractFormsAndFormElements( 212 has_more_forms = form_cache_.ExtractFormsAndFormElements(
212 *frame, kRequiredAutofillFields, &forms, &form_elements_); 213 *frame, kRequiredAutofillFields, &forms, &form_elements_);
213 is_whitelisted_for_autocheckout_ = false; 214 is_whitelisted_for_autocheckout_ = false;
214 } else { 215 } else {
215 form_cache_.ExtractForms(*frame, &forms); 216 form_cache_.ExtractForms(*frame, &forms);
216 } 217 }
217 218
219 autofill::FormsSeenState state = has_more_forms ?
220 autofill::PARTIAL_FORMS_SEEN : autofill::NO_SPECIAL_FORMS_SEEN;
221
218 // Always communicate to browser process for topmost frame. 222 // Always communicate to browser process for topmost frame.
219 if (!forms.empty() || !frame->parent()) { 223 if (!forms.empty() || !frame->parent()) {
220 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, 224 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
221 forms_seen_timestamp_, 225 forms_seen_timestamp_,
222 has_more_forms)); 226 state));
223 } 227 }
224 } 228 }
225 229
226 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { 230 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) {
227 if (!frame->parent()) { 231 if (!frame->parent()) {
228 topmost_frame_ = NULL; 232 topmost_frame_ = NULL;
229 if (click_timer_.IsRunning()) { 233 if (click_timer_.IsRunning()) {
230 click_timer_.Stop(); 234 click_timer_.Stop();
231 autocheckout_click_in_progress_ = true; 235 autocheckout_click_in_progress_ = true;
232 } 236 }
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 std::vector<FormData> forms; 725 std::vector<FormData> forms;
722 form_cache_.ExtractFormsAndFormElements( 726 form_cache_.ExtractFormsAndFormElements(
723 *topmost_frame_, 0, &forms, &form_elements_); 727 *topmost_frame_, 0, &forms, &form_elements_);
724 728
725 // OnGetAllForms should only be called if AutofillAgent reported to 729 // OnGetAllForms should only be called if AutofillAgent reported to
726 // AutofillManager that there are more forms 730 // AutofillManager that there are more forms
727 DCHECK(!forms.empty()); 731 DCHECK(!forms.empty());
728 732
729 // Report to AutofillManager that all forms are being sent. 733 // Report to AutofillManager that all forms are being sent.
730 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, 734 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
731 forms_seen_timestamp_, false)); 735 forms_seen_timestamp_,
736 NO_SPECIAL_FORMS_SEEN));
732 } 737 }
733 738
734 void AutofillAgent::OnRequestAutocompleteResult( 739 void AutofillAgent::OnRequestAutocompleteResult(
735 WebFormElement::AutocompleteResult result, const FormData& form_data) { 740 WebFormElement::AutocompleteResult result, const FormData& form_data) {
736 if (in_flight_request_form_.isNull()) 741 if (in_flight_request_form_.isNull())
737 return; 742 return;
738 743
739 if (result == WebFormElement::AutocompleteResultSuccess) 744 if (result == WebFormElement::AutocompleteResultSuccess)
740 FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_); 745 FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_);
741 746
(...skipping 27 matching lines...) Expand all
769 if (!ClickElement(topmost_frame_->document(), 774 if (!ClickElement(topmost_frame_->document(),
770 click_element_descriptor)) { 775 click_element_descriptor)) {
771 click_timer_.Stop(); 776 click_timer_.Stop();
772 Send(new AutofillHostMsg_ClickFailed(routing_id(), 777 Send(new AutofillHostMsg_ClickFailed(routing_id(),
773 MISSING_ADVANCE)); 778 MISSING_ADVANCE));
774 } 779 }
775 } 780 }
776 781
777 void AutofillAgent::OnWhitelistedForAutocheckout() { 782 void AutofillAgent::OnWhitelistedForAutocheckout() {
778 is_whitelisted_for_autocheckout_ = true; 783 is_whitelisted_for_autocheckout_ = true;
784 if (has_new_forms_for_browser_)
785 MaybeSendDynamicFormsSeen();
779 } 786 }
780 787
781 void AutofillAgent::ClickFailed() { 788 void AutofillAgent::ClickFailed() {
782 Send(new AutofillHostMsg_ClickFailed(routing_id(), 789 Send(new AutofillHostMsg_ClickFailed(routing_id(),
783 CANNOT_PROCEED)); 790 CANNOT_PROCEED));
784 } 791 }
785 792
786 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 793 void AutofillAgent::ShowSuggestions(const WebInputElement& element,
787 bool autofill_on_empty_values, 794 bool autofill_on_empty_values,
788 bool requires_caret_at_end, 795 bool requires_caret_at_end,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 if (web_view) 936 if (web_view)
930 web_view->hidePopups(); 937 web_view->hidePopups();
931 938
932 HideHostAutofillUi(); 939 HideHostAutofillUi();
933 } 940 }
934 941
935 void AutofillAgent::HideHostAutofillUi() { 942 void AutofillAgent::HideHostAutofillUi() {
936 Send(new AutofillHostMsg_HideAutofillUi(routing_id())); 943 Send(new AutofillHostMsg_HideAutofillUi(routing_id()));
937 } 944 }
938 945
946 void AutofillAgent::didAssociateFormControls(
947 const WebKit::WebVector<WebKit::WebNode>& nodes) {
948 for (size_t i = 0; i < nodes.size(); ++i) {
949 WebKit::WebNode node = nodes[i];
950 if (node.document().frame() == topmost_frame_) {
951 forms_seen_timestamp_ = base::TimeTicks::Now();
952 has_new_forms_for_browser_ = true;
953 break;
954 }
955 }
956
957 if (has_new_forms_for_browser_ && is_whitelisted_for_autocheckout_)
958 MaybeSendDynamicFormsSeen();
959 }
960
961 void AutofillAgent::MaybeSendDynamicFormsSeen() {
962 has_new_forms_for_browser_ = false;
963 form_elements_.clear();
964 std::vector<FormData> forms;
965 // This will only be called for Autocheckout flows, so send all forms to
966 // save an IPC
Ilya Sherman 2013/04/18 22:19:08 nit: Please end the sentence with a period.
Dane Wallinga 2013/04/18 23:56:44 Done.
967 bool has_more_forms = form_cache_.ExtractFormsAndFormElements(
968 *topmost_frame_, 0, &forms, &form_elements_);
Ilya Sherman 2013/04/18 22:19:08 Can calling this method with a threshold of 0 ever
Dane Wallinga 2013/04/18 23:56:44 gah, knew I missed something.
969 autofill::FormsSeenState state = has_more_forms ?
970 autofill::PARTIAL_AND_DYNAMIC_FORMS_SEEN : autofill::DYNAMIC_FORMS_SEEN;
Ilya Sherman 2013/04/19 01:38:42 Is the PARTIAL_AND_DYNAMIC_FORMS_SEEN case reachab
Dane Wallinga 2013/04/19 18:19:53 Not presently. It would be applicable if you ever
971
972 if (!forms.empty()) {
973 if (click_timer_.IsRunning())
974 click_timer_.Stop();
Ilya Sherman 2013/04/18 22:19:08 Why is this part MaybeSendDynamicFormsSeen() and n
Dane Wallinga 2013/04/18 23:56:44 I don't want to clear the timer until I know that
Ilya Sherman 2013/04/19 01:38:42 That doesn't match how the logic in DidStartProvis
Dane Wallinga 2013/04/19 18:19:53 If the provisional load fails, we'll call ClickFai
975 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
976 forms_seen_timestamp_,
977 state));
978 }
979 }
980
939 } // namespace autofill 981 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/renderer/autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698