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

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

Issue 242613006: [Autofill] Enable Autofill for dynamically created forms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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.
Ilya Sherman 2014/04/23 05:51:36 nit: "finished loading we should" -> "finished loa
Garrett Casto 2014/04/23 21:51:14 Done.
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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 646
666 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, 647 void AutofillAgent::PreviewFieldWithValue(const base::string16& value,
667 WebInputElement* node) { 648 WebInputElement* node) {
668 was_query_node_autofilled_ = element_.isAutofilled(); 649 was_query_node_autofilled_ = element_.isAutofilled();
669 node->setSuggestedValue(value.substr(0, node->maxLength())); 650 node->setSuggestedValue(value.substr(0, node->maxLength()));
670 node->setAutofilled(true); 651 node->setAutofilled(true);
671 node->setSelectionRange(node->value().length(), 652 node->setSelectionRange(node->value().length(),
672 node->suggestedValue().length()); 653 node->suggestedValue().length());
673 } 654 }
674 655
656 void AutofillAgent::ProcessForms(const WebLocalFrame& frame) {
657 // Record timestamp on document load. This is used to record overhead of
Ilya Sherman 2014/04/23 05:51:36 nit: "record overhead of Autofill feature" -> "mea
Garrett Casto 2014/04/23 21:51:14 Done.
658 // Autofill feature.
659 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now();
660
661 // The document has now been fully loaded. Scan for forms to be sent up to
Ilya Sherman 2014/04/23 05:51:36 This comment is somewhat misleading, as the method
Garrett Casto 2014/04/23 21:51:14 Removed. I don't think that it adds much anymore.
662 // the browser.
663 std::vector<FormData> forms;
664 form_cache_.ExtractNewForms(frame, &forms);
665
666 // Always communicate to browser process for topmost frame.
667 if (!forms.empty() ||
668 (!frame.parent() && !main_frame_processed_)) {
669 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
670 forms_seen_timestamp));
671 }
672
673 if (!frame.parent())
674 main_frame_processed_ = true;
675 }
676
675 void AutofillAgent::HidePopup() { 677 void AutofillAgent::HidePopup() {
676 if (!is_popup_possibly_visible_) 678 if (!is_popup_possibly_visible_)
677 return; 679 return;
678 680
679 if (!element_.isNull()) 681 if (!element_.isNull())
680 OnClearPreviewedForm(); 682 OnClearPreviewedForm();
681 683
682 is_popup_possibly_visible_ = false; 684 is_popup_possibly_visible_ = false;
683 Send(new AutofillHostMsg_HidePopup(routing_id())); 685 Send(new AutofillHostMsg_HidePopup(routing_id()));
684 } 686 }
685 687
686 // TODO(isherman): Decide if we want to support non-password autofill with AJAX.
687 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { 688 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) {
688 for (size_t i = 0; i < nodes.size(); ++i) { 689 for (size_t i = 0; i < nodes.size(); ++i) {
689 WebFrame* frame = nodes[i].document().frame(); 690 WebLocalFrame* frame = nodes[i].document().frame();
690 // Only monitors dynamic forms created in the top frame. Dynamic forms 691 // Only monitors dynamic forms created in the top frame. Dynamic forms
691 // inserted in iframes are not captured yet. 692 // inserted in iframes are not captured yet.
692 if (frame && !frame->parent()) { 693 if (frame && !frame->parent()) {
694 ProcessForms(*frame);
693 password_autofill_agent_->OnDynamicFormsSeen(frame); 695 password_autofill_agent_->OnDynamicFormsSeen(frame);
694 return; 696 return;
695 } 697 }
696 } 698 }
697 } 699 }
698 700
699 } // namespace autofill 701 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698