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

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

Issue 277043002: Revert "Revert of [Autofill] Enable Autofill for dynamically created forms. (https://codereview.chr… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix form_structure_browsertests Created 6 years, 7 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 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 "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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 password_generation_agent_(password_generation_agent), 129 password_generation_agent_(password_generation_agent),
130 autofill_query_id_(0), 130 autofill_query_id_(0),
131 web_view_(render_view->GetWebView()), 131 web_view_(render_view->GetWebView()),
132 display_warning_if_disabled_(false), 132 display_warning_if_disabled_(false),
133 was_query_node_autofilled_(false), 133 was_query_node_autofilled_(false),
134 has_shown_autofill_popup_for_current_edit_(false), 134 has_shown_autofill_popup_for_current_edit_(false),
135 did_set_node_text_(false), 135 did_set_node_text_(false),
136 has_new_forms_for_browser_(false), 136 has_new_forms_for_browser_(false),
137 ignore_text_changes_(false), 137 ignore_text_changes_(false),
138 is_popup_possibly_visible_(false), 138 is_popup_possibly_visible_(false),
139 main_frame_processed_(false),
139 weak_ptr_factory_(this) { 140 weak_ptr_factory_(this) {
140 render_view->GetWebView()->setAutofillClient(this); 141 render_view->GetWebView()->setAutofillClient(this);
141 142
142 // The PageClickTracker is a RenderViewObserver, and hence will be freed when 143 // The PageClickTracker is a RenderViewObserver, and hence will be freed when
143 // the RenderView is destroyed. 144 // the RenderView is destroyed.
144 new PageClickTracker(render_view, this); 145 new PageClickTracker(render_view, this);
145 } 146 }
146 147
147 AutofillAgent::~AutofillAgent() {} 148 AutofillAgent::~AutofillAgent() {}
148 149
(...skipping 14 matching lines...) Expand all
163 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, 164 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion,
164 OnAcceptPasswordAutofillSuggestion) 165 OnAcceptPasswordAutofillSuggestion)
165 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, 166 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult,
166 OnRequestAutocompleteResult) 167 OnRequestAutocompleteResult)
167 IPC_MESSAGE_UNHANDLED(handled = false) 168 IPC_MESSAGE_UNHANDLED(handled = false)
168 IPC_END_MESSAGE_MAP() 169 IPC_END_MESSAGE_MAP()
169 return handled; 170 return handled;
170 } 171 }
171 172
172 void AutofillAgent::DidFinishDocumentLoad(WebLocalFrame* frame) { 173 void AutofillAgent::DidFinishDocumentLoad(WebLocalFrame* frame) {
173 // Record timestamp on document load. This is used to record overhead of 174 // If the main frame just finished loading, we should process it.
174 // Autofill feature. 175 if (!frame->parent())
175 forms_seen_timestamp_ = base::TimeTicks::Now(); 176 main_frame_processed_ = false;
176 177
177 // The document has now been fully loaded. Scan for forms to be sent up to 178 ProcessForms(*frame);
178 // the browser.
179 std::vector<FormData> forms;
180 bool has_more_forms = false;
181 if (!frame->parent()) {
182 form_elements_.clear();
183 has_more_forms = form_cache_.ExtractFormsAndFormElements(
184 *frame, kRequiredAutofillFields, &forms, &form_elements_);
185 } else {
186 form_cache_.ExtractForms(*frame, &forms);
187 }
188
189 autofill::FormsSeenState state = has_more_forms ?
190 autofill::PARTIAL_FORMS_SEEN : autofill::NO_SPECIAL_FORMS_SEEN;
191
192 // Always communicate to browser process for topmost frame.
193 if (!forms.empty() || !frame->parent()) {
194 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
195 forms_seen_timestamp_,
196 state));
197 }
198 } 179 }
199 180
200 void AutofillAgent::FrameDetached(WebFrame* frame) { 181 void AutofillAgent::FrameDetached(WebFrame* frame) {
201 form_cache_.ResetFrame(*frame); 182 form_cache_.ResetFrame(*frame);
202 } 183 }
203 184
204 void AutofillAgent::FrameWillClose(WebFrame* frame) { 185 void AutofillAgent::FrameWillClose(WebFrame* frame) {
205 if (in_flight_request_form_.isNull()) 186 if (in_flight_request_form_.isNull())
206 return; 187 return;
207 188
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 656
676 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, 657 void AutofillAgent::PreviewFieldWithValue(const base::string16& value,
677 WebInputElement* node) { 658 WebInputElement* node) {
678 was_query_node_autofilled_ = element_.isAutofilled(); 659 was_query_node_autofilled_ = element_.isAutofilled();
679 node->setSuggestedValue(value.substr(0, node->maxLength())); 660 node->setSuggestedValue(value.substr(0, node->maxLength()));
680 node->setAutofilled(true); 661 node->setAutofilled(true);
681 node->setSelectionRange(node->value().length(), 662 node->setSelectionRange(node->value().length(),
682 node->suggestedValue().length()); 663 node->suggestedValue().length());
683 } 664 }
684 665
666 void AutofillAgent::ProcessForms(const WebLocalFrame& frame) {
667 // Record timestamp of when the forms are first seen. This is used to
668 // measure the overhead of the Autofill feature.
669 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now();
670
671 std::vector<FormData> forms;
672 form_cache_.ExtractNewForms(frame, &forms);
673
674 // Always communicate to browser process for topmost frame.
675 if (!forms.empty() ||
676 (!frame.parent() && !main_frame_processed_)) {
677 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
678 forms_seen_timestamp));
679 }
680
681 if (!frame.parent())
682 main_frame_processed_ = true;
683 }
684
685 void AutofillAgent::HidePopup() { 685 void AutofillAgent::HidePopup() {
686 if (!is_popup_possibly_visible_) 686 if (!is_popup_possibly_visible_)
687 return; 687 return;
688 688
689 if (!element_.isNull()) 689 if (!element_.isNull())
690 OnClearPreviewedForm(); 690 OnClearPreviewedForm();
691 691
692 is_popup_possibly_visible_ = false; 692 is_popup_possibly_visible_ = false;
693 Send(new AutofillHostMsg_HidePopup(routing_id())); 693 Send(new AutofillHostMsg_HidePopup(routing_id()));
694 } 694 }
695 695
696 // TODO(isherman): Decide if we want to support non-password autofill with AJAX.
697 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { 696 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) {
698 for (size_t i = 0; i < nodes.size(); ++i) { 697 for (size_t i = 0; i < nodes.size(); ++i) {
699 WebFrame* frame = nodes[i].document().frame(); 698 WebLocalFrame* frame = nodes[i].document().frame();
700 // Only monitors dynamic forms created in the top frame. Dynamic forms 699 // Only monitors dynamic forms created in the top frame. Dynamic forms
701 // inserted in iframes are not captured yet. 700 // inserted in iframes are not captured yet. Frame is only processed
702 if (frame && !frame->parent()) { 701 // if it has finished loading, otherwise you can end up with a partially
702 // parsed form.
Ilya Sherman 2014/05/12 19:57:54 Is this method guaranteed to be called again once
Garrett Casto 2014/05/12 23:52:51 I don't think so, but if elements are inserted bef
703 if (frame && !frame->parent() && !frame->isLoading()) {
704 ProcessForms(*frame);
703 password_autofill_agent_->OnDynamicFormsSeen(frame); 705 password_autofill_agent_->OnDynamicFormsSeen(frame);
704 return; 706 return;
705 } 707 }
706 } 708 }
707 } 709 }
708 710
709 } // namespace autofill 711 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/autofill_agent.h ('k') | components/autofill/content/renderer/form_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698