OLD | NEW |
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 Loading... |
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), | |
140 weak_ptr_factory_(this) { | 139 weak_ptr_factory_(this) { |
141 render_view->GetWebView()->setAutofillClient(this); | 140 render_view->GetWebView()->setAutofillClient(this); |
142 | 141 |
143 // The PageClickTracker is a RenderViewObserver, and hence will be freed when | 142 // The PageClickTracker is a RenderViewObserver, and hence will be freed when |
144 // the RenderView is destroyed. | 143 // the RenderView is destroyed. |
145 new PageClickTracker(render_view, this); | 144 new PageClickTracker(render_view, this); |
146 } | 145 } |
147 | 146 |
148 AutofillAgent::~AutofillAgent() {} | 147 AutofillAgent::~AutofillAgent() {} |
149 | 148 |
(...skipping 14 matching lines...) Expand all Loading... |
164 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, | 163 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, |
165 OnAcceptPasswordAutofillSuggestion) | 164 OnAcceptPasswordAutofillSuggestion) |
166 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, | 165 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, |
167 OnRequestAutocompleteResult) | 166 OnRequestAutocompleteResult) |
168 IPC_MESSAGE_UNHANDLED(handled = false) | 167 IPC_MESSAGE_UNHANDLED(handled = false) |
169 IPC_END_MESSAGE_MAP() | 168 IPC_END_MESSAGE_MAP() |
170 return handled; | 169 return handled; |
171 } | 170 } |
172 | 171 |
173 void AutofillAgent::DidFinishDocumentLoad(WebLocalFrame* frame) { | 172 void AutofillAgent::DidFinishDocumentLoad(WebLocalFrame* frame) { |
174 // If the main frame just finished loading, we should process it. | 173 // Record timestamp on document load. This is used to record overhead of |
175 if (!frame->parent()) | 174 // Autofill feature. |
176 main_frame_processed_ = false; | 175 forms_seen_timestamp_ = base::TimeTicks::Now(); |
177 | 176 |
178 ProcessForms(*frame); | 177 // The document has now been fully loaded. Scan for forms to be sent up to |
| 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 } |
179 } | 198 } |
180 | 199 |
181 void AutofillAgent::FrameDetached(WebFrame* frame) { | 200 void AutofillAgent::FrameDetached(WebFrame* frame) { |
182 form_cache_.ResetFrame(*frame); | 201 form_cache_.ResetFrame(*frame); |
183 } | 202 } |
184 | 203 |
185 void AutofillAgent::FrameWillClose(WebFrame* frame) { | 204 void AutofillAgent::FrameWillClose(WebFrame* frame) { |
186 if (in_flight_request_form_.isNull()) | 205 if (in_flight_request_form_.isNull()) |
187 return; | 206 return; |
188 | 207 |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 665 |
647 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, | 666 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, |
648 WebInputElement* node) { | 667 WebInputElement* node) { |
649 was_query_node_autofilled_ = element_.isAutofilled(); | 668 was_query_node_autofilled_ = element_.isAutofilled(); |
650 node->setSuggestedValue(value.substr(0, node->maxLength())); | 669 node->setSuggestedValue(value.substr(0, node->maxLength())); |
651 node->setAutofilled(true); | 670 node->setAutofilled(true); |
652 node->setSelectionRange(node->value().length(), | 671 node->setSelectionRange(node->value().length(), |
653 node->suggestedValue().length()); | 672 node->suggestedValue().length()); |
654 } | 673 } |
655 | 674 |
656 void AutofillAgent::ProcessForms(const WebLocalFrame& frame) { | |
657 // Record timestamp of when the forms are first seen. This is used to | |
658 // measure the overhead of the Autofill feature. | |
659 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); | |
660 | |
661 std::vector<FormData> forms; | |
662 form_cache_.ExtractNewForms(frame, &forms); | |
663 | |
664 // Always communicate to browser process for topmost frame. | |
665 if (!forms.empty() || | |
666 (!frame.parent() && !main_frame_processed_)) { | |
667 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | |
668 forms_seen_timestamp)); | |
669 } | |
670 | |
671 if (!frame.parent()) | |
672 main_frame_processed_ = true; | |
673 } | |
674 | |
675 void AutofillAgent::HidePopup() { | 675 void AutofillAgent::HidePopup() { |
676 if (!is_popup_possibly_visible_) | 676 if (!is_popup_possibly_visible_) |
677 return; | 677 return; |
678 | 678 |
679 if (!element_.isNull()) | 679 if (!element_.isNull()) |
680 OnClearPreviewedForm(); | 680 OnClearPreviewedForm(); |
681 | 681 |
682 is_popup_possibly_visible_ = false; | 682 is_popup_possibly_visible_ = false; |
683 Send(new AutofillHostMsg_HidePopup(routing_id())); | 683 Send(new AutofillHostMsg_HidePopup(routing_id())); |
684 } | 684 } |
685 | 685 |
| 686 // TODO(isherman): Decide if we want to support non-password autofill with AJAX. |
686 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { | 687 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { |
687 for (size_t i = 0; i < nodes.size(); ++i) { | 688 for (size_t i = 0; i < nodes.size(); ++i) { |
688 WebLocalFrame* frame = nodes[i].document().frame(); | 689 WebFrame* frame = nodes[i].document().frame(); |
689 // Only monitors dynamic forms created in the top frame. Dynamic forms | 690 // Only monitors dynamic forms created in the top frame. Dynamic forms |
690 // inserted in iframes are not captured yet. | 691 // inserted in iframes are not captured yet. |
691 if (frame && !frame->parent()) { | 692 if (frame && !frame->parent()) { |
692 ProcessForms(*frame); | |
693 password_autofill_agent_->OnDynamicFormsSeen(frame); | 693 password_autofill_agent_->OnDynamicFormsSeen(frame); |
694 return; | 694 return; |
695 } | 695 } |
696 } | 696 } |
697 } | 697 } |
698 | 698 |
699 } // namespace autofill | 699 } // namespace autofill |
OLD | NEW |