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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "components/autofill/content/common/autofill_messages.h" | 14 #include "components/autofill/content/common/autofill_messages.h" |
15 #include "components/autofill/content/renderer/form_autofill_util.h" | 15 #include "components/autofill/content/renderer/form_autofill_util.h" |
16 #include "components/autofill/content/renderer/page_click_tracker.h" | 16 #include "components/autofill/content/renderer/page_click_tracker.h" |
17 #include "components/autofill/content/renderer/password_autofill_agent.h" | 17 #include "components/autofill/content/renderer/password_autofill_agent.h" |
18 #include "components/autofill/content/renderer/password_generation_agent.h" | 18 #include "components/autofill/content/renderer/password_generation_agent.h" |
19 #include "components/autofill/core/common/autofill_constants.h" | 19 #include "components/autofill/core/common/autofill_constants.h" |
20 #include "components/autofill/core/common/autofill_data_validation.h" | 20 #include "components/autofill/core/common/autofill_data_validation.h" |
21 #include "components/autofill/core/common/autofill_switches.h" | 21 #include "components/autofill/core/common/autofill_switches.h" |
22 #include "components/autofill/core/common/form_data.h" | 22 #include "components/autofill/core/common/form_data.h" |
23 #include "components/autofill/core/common/form_data_predictions.h" | 23 #include "components/autofill/core/common/form_data_predictions.h" |
24 #include "components/autofill/core/common/form_field_data.h" | 24 #include "components/autofill/core/common/form_field_data.h" |
25 #include "components/autofill/core/common/password_form.h" | 25 #include "components/autofill/core/common/password_form.h" |
26 #include "components/autofill/core/common/web_element_descriptor.h" | 26 #include "components/autofill/core/common/web_element_descriptor.h" |
27 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
28 #include "content/public/common/ssl_status.h" | 28 #include "content/public/common/ssl_status.h" |
29 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
| 30 #include "content/public/renderer/render_frame.h" |
30 #include "content/public/renderer/render_view.h" | 31 #include "content/public/renderer/render_view.h" |
31 #include "net/cert/cert_status_flags.h" | 32 #include "net/cert/cert_status_flags.h" |
32 #include "third_party/WebKit/public/platform/WebRect.h" | 33 #include "third_party/WebKit/public/platform/WebRect.h" |
33 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 34 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
34 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 35 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
35 #include "third_party/WebKit/public/web/WebDataSource.h" | 36 #include "third_party/WebKit/public/web/WebDataSource.h" |
36 #include "third_party/WebKit/public/web/WebDocument.h" | 37 #include "third_party/WebKit/public/web/WebDocument.h" |
37 #include "third_party/WebKit/public/web/WebElementCollection.h" | 38 #include "third_party/WebKit/public/web/WebElementCollection.h" |
38 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 39 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
39 #include "third_party/WebKit/public/web/WebFormElement.h" | 40 #include "third_party/WebKit/public/web/WebFormElement.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 113 |
113 // Limit the size of the strings in the vector. | 114 // Limit the size of the strings in the vector. |
114 for (size_t i = 0; i < strings->size(); ++i) { | 115 for (size_t i = 0; i < strings->size(); ++i) { |
115 if ((*strings)[i].length() > kMaxDataLength) | 116 if ((*strings)[i].length() > kMaxDataLength) |
116 (*strings)[i].resize(kMaxDataLength); | 117 (*strings)[i].resize(kMaxDataLength); |
117 } | 118 } |
118 } | 119 } |
119 | 120 |
120 } // namespace | 121 } // namespace |
121 | 122 |
122 AutofillAgent::AutofillAgent(content::RenderView* render_view, | 123 AutofillAgent::AutofillAgent(content::RenderFrame* render_frame, |
123 PasswordAutofillAgent* password_autofill_agent, | 124 PasswordAutofillAgent* password_autofill_agent, |
124 PasswordGenerationAgent* password_generation_agent) | 125 PasswordGenerationAgent* password_generation_agent) |
125 : content::RenderViewObserver(render_view), | 126 : content::RenderFrameObserver(render_frame), |
126 password_autofill_agent_(password_autofill_agent), | 127 password_autofill_agent_(password_autofill_agent), |
127 password_generation_agent_(password_generation_agent), | 128 password_generation_agent_(password_generation_agent), |
| 129 legacy_(render_frame->GetRenderView(), this), |
| 130 page_click_tracker_(render_frame->GetRenderView(), this), |
128 autofill_query_id_(0), | 131 autofill_query_id_(0), |
129 web_view_(render_view->GetWebView()), | |
130 display_warning_if_disabled_(false), | 132 display_warning_if_disabled_(false), |
131 was_query_node_autofilled_(false), | 133 was_query_node_autofilled_(false), |
132 has_shown_autofill_popup_for_current_edit_(false), | 134 has_shown_autofill_popup_for_current_edit_(false), |
133 did_set_node_text_(false), | 135 did_set_node_text_(false), |
134 ignore_text_changes_(false), | 136 ignore_text_changes_(false), |
135 is_popup_possibly_visible_(false), | 137 is_popup_possibly_visible_(false), |
136 main_frame_processed_(false), | |
137 weak_ptr_factory_(this) { | 138 weak_ptr_factory_(this) { |
138 render_view->GetWebView()->setAutofillClient(this); | 139 render_frame->GetWebFrame()->setAutofillClient(this); |
139 | |
140 // The PageClickTracker is a RenderViewObserver, and hence will be freed when | |
141 // the RenderView is destroyed. | |
142 new PageClickTracker(render_view, this); | |
143 } | 140 } |
144 | 141 |
145 AutofillAgent::~AutofillAgent() {} | 142 AutofillAgent::~AutofillAgent() {} |
146 | 143 |
147 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { | 144 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { |
148 bool handled = true; | 145 bool handled = true; |
149 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) | 146 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) |
150 IPC_MESSAGE_HANDLER(AutofillMsg_Ping, OnPing) | 147 IPC_MESSAGE_HANDLER(AutofillMsg_Ping, OnPing) |
151 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm) | 148 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm) |
152 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm) | 149 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm) |
(...skipping 10 matching lines...) Expand all Loading... |
163 OnFillPasswordSuggestion) | 160 OnFillPasswordSuggestion) |
164 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion, | 161 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion, |
165 OnPreviewPasswordSuggestion) | 162 OnPreviewPasswordSuggestion) |
166 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, | 163 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, |
167 OnRequestAutocompleteResult) | 164 OnRequestAutocompleteResult) |
168 IPC_MESSAGE_UNHANDLED(handled = false) | 165 IPC_MESSAGE_UNHANDLED(handled = false) |
169 IPC_END_MESSAGE_MAP() | 166 IPC_END_MESSAGE_MAP() |
170 return handled; | 167 return handled; |
171 } | 168 } |
172 | 169 |
173 void AutofillAgent::DidFinishDocumentLoad(WebLocalFrame* frame) { | 170 void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation) { |
174 // If the main frame just finished loading, we should process it. | 171 // TODO(estade): |form_cache_| shouldn't track multiple frames. |
175 if (!frame->parent()) | 172 form_cache_.ResetFrame(*render_frame()->GetWebFrame()); |
176 main_frame_processed_ = false; | |
177 | |
178 ProcessForms(*frame); | |
179 } | 173 } |
180 | 174 |
181 void AutofillAgent::DidCommitProvisionalLoad(WebLocalFrame* frame, | 175 void AutofillAgent::DidFinishDocumentLoad() { |
182 bool is_new_navigation) { | 176 ProcessForms(); |
183 form_cache_.ResetFrame(*frame); | 177 } |
| 178 |
| 179 void AutofillAgent::FrameWillClose() { |
| 180 if (in_flight_request_form_.isNull()) |
| 181 return; |
| 182 |
| 183 Send(new AutofillHostMsg_CancelRequestAutocomplete(routing_id())); |
184 } | 184 } |
185 | 185 |
186 void AutofillAgent::FrameDetached(WebFrame* frame) { | 186 void AutofillAgent::FrameDetached(WebFrame* frame) { |
187 form_cache_.ResetFrame(*frame); | 187 if (frame != render_frame()->GetWebFrame()) |
188 } | |
189 | |
190 void AutofillAgent::FrameWillClose(WebFrame* frame) { | |
191 if (in_flight_request_form_.isNull()) | |
192 return; | 188 return; |
193 | 189 |
194 for (WebFrame* temp = in_flight_request_form_.document().frame(); | 190 form_cache_.ResetFrame(*frame); |
195 temp; temp = temp->parent()) { | |
196 if (temp == frame) { | |
197 Send(new AutofillHostMsg_CancelRequestAutocomplete(routing_id())); | |
198 break; | |
199 } | |
200 } | |
201 } | 191 } |
202 | 192 |
203 void AutofillAgent::WillSubmitForm(WebLocalFrame* frame, | 193 void AutofillAgent::WillSubmitForm(WebLocalFrame* frame, |
204 const WebFormElement& form) { | 194 const WebFormElement& form) { |
| 195 if (frame != render_frame()->GetWebFrame()) |
| 196 return; |
| 197 |
205 FormData form_data; | 198 FormData form_data; |
206 if (WebFormElementToFormData(form, | 199 if (WebFormElementToFormData(form, |
207 WebFormControlElement(), | 200 WebFormControlElement(), |
208 REQUIRE_NONE, | 201 REQUIRE_NONE, |
209 static_cast<ExtractMask>( | 202 static_cast<ExtractMask>( |
210 EXTRACT_VALUE | EXTRACT_OPTION_TEXT), | 203 EXTRACT_VALUE | EXTRACT_OPTION_TEXT), |
211 &form_data, | 204 &form_data, |
212 NULL)) { | 205 NULL)) { |
213 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, | 206 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, |
214 base::TimeTicks::Now())); | 207 base::TimeTicks::Now())); |
215 } | 208 } |
216 } | 209 } |
217 | 210 |
| 211 void AutofillAgent::DidChangeScrollOffset(WebLocalFrame* frame) { |
| 212 if (frame != render_frame()->GetWebFrame()) |
| 213 return; |
| 214 |
| 215 HidePopup(); |
| 216 } |
| 217 |
218 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { | 218 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
219 HidePopup(); | 219 HidePopup(); |
220 | 220 |
| 221 if (node.isNull() || !node.isElementNode()) |
| 222 return; |
| 223 |
| 224 if (node.document().frame() != render_frame()->GetWebFrame()) |
| 225 return; |
| 226 |
221 if (password_generation_agent_ && | 227 if (password_generation_agent_ && |
222 password_generation_agent_->FocusedNodeHasChanged(node)) { | 228 password_generation_agent_->FocusedNodeHasChanged(node)) { |
223 is_popup_possibly_visible_ = true; | 229 is_popup_possibly_visible_ = true; |
224 return; | 230 return; |
225 } | 231 } |
226 | 232 |
227 if (node.isNull() || !node.isElementNode()) | |
228 return; | |
229 | |
230 WebElement web_element = node.toConst<WebElement>(); | 233 WebElement web_element = node.toConst<WebElement>(); |
231 | 234 |
232 if (!web_element.document().frame()) | 235 if (!web_element.document().frame()) |
233 return; | 236 return; |
234 | 237 |
235 const WebInputElement* element = toWebInputElement(&web_element); | 238 const WebInputElement* element = toWebInputElement(&web_element); |
236 | 239 |
237 if (!element || !element->isEnabled() || element->isReadOnly() || | 240 if (!element || !element->isEnabled() || element->isReadOnly() || |
238 !element->isTextField() || element->isPasswordField()) | 241 !element->isTextField() || element->isPasswordField()) |
239 return; | 242 return; |
240 | 243 |
241 element_ = *element; | 244 element_ = *element; |
242 } | 245 } |
243 | 246 |
244 void AutofillAgent::OrientationChangeEvent() { | 247 void AutofillAgent::OrientationChangeEvent() { |
245 HidePopup(); | 248 HidePopup(); |
246 } | 249 } |
247 | 250 |
248 void AutofillAgent::Resized() { | 251 void AutofillAgent::Resized() { |
249 HidePopup(); | 252 HidePopup(); |
250 } | 253 } |
251 | 254 |
252 void AutofillAgent::DidChangeScrollOffset(WebLocalFrame*) { | |
253 HidePopup(); | |
254 } | |
255 | |
256 void AutofillAgent::didRequestAutocomplete( | 255 void AutofillAgent::didRequestAutocomplete( |
257 const WebFormElement& form) { | 256 const WebFormElement& form) { |
| 257 DCHECK_EQ(form.document().frame(), render_frame()->GetWebFrame()); |
| 258 |
258 // Disallow the dialog over non-https or broken https, except when the | 259 // Disallow the dialog over non-https or broken https, except when the |
259 // ignore SSL flag is passed. See http://crbug.com/272512. | 260 // ignore SSL flag is passed. See http://crbug.com/272512. |
260 // TODO(palmer): this should be moved to the browser process after frames | 261 // TODO(palmer): this should be moved to the browser process after frames |
261 // get their own processes. | 262 // get their own processes. |
262 GURL url(form.document().url()); | 263 GURL url(form.document().url()); |
263 content::SSLStatus ssl_status = | 264 content::SSLStatus ssl_status = |
264 render_view()->GetSSLStatusOfFrame(form.document().frame()); | 265 render_frame()->GetRenderView()->GetSSLStatusOfFrame( |
| 266 form.document().frame()); |
265 bool is_safe = url.SchemeIs(url::kHttpsScheme) && | 267 bool is_safe = url.SchemeIs(url::kHttpsScheme) && |
266 !net::IsCertStatusError(ssl_status.cert_status); | 268 !net::IsCertStatusError(ssl_status.cert_status); |
267 bool allow_unsafe = CommandLine::ForCurrentProcess()->HasSwitch( | 269 bool allow_unsafe = CommandLine::ForCurrentProcess()->HasSwitch( |
268 ::switches::kReduceSecurityForTesting); | 270 ::switches::kReduceSecurityForTesting); |
269 | 271 |
270 FormData form_data; | 272 FormData form_data; |
271 std::string error_message; | 273 std::string error_message; |
272 if (!in_flight_request_form_.isNull()) { | 274 if (!in_flight_request_form_.isNull()) { |
273 error_message = "already active."; | 275 error_message = "already active."; |
274 } else if (!is_safe && !allow_unsafe) { | 276 } else if (!is_safe && !allow_unsafe) { |
(...skipping 30 matching lines...) Expand all Loading... |
305 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); | 307 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); |
306 } | 308 } |
307 | 309 |
308 void AutofillAgent::setIgnoreTextChanges(bool ignore) { | 310 void AutofillAgent::setIgnoreTextChanges(bool ignore) { |
309 ignore_text_changes_ = ignore; | 311 ignore_text_changes_ = ignore; |
310 } | 312 } |
311 | 313 |
312 void AutofillAgent::FormControlElementClicked( | 314 void AutofillAgent::FormControlElementClicked( |
313 const WebFormControlElement& element, | 315 const WebFormControlElement& element, |
314 bool was_focused) { | 316 bool was_focused) { |
| 317 // TODO(estade): Remove this check when PageClickTracker is per-frame. |
| 318 if (element.document().frame() != render_frame()->GetWebFrame()) |
| 319 return; |
| 320 |
315 const WebInputElement* input_element = toWebInputElement(&element); | 321 const WebInputElement* input_element = toWebInputElement(&element); |
316 if (!input_element && !IsTextAreaElement(element)) | 322 if (!input_element && !IsTextAreaElement(element)) |
317 return; | 323 return; |
318 | 324 |
319 bool show_full_suggestion_list = element.isAutofilled() || was_focused; | 325 bool show_full_suggestion_list = element.isAutofilled() || was_focused; |
320 bool show_password_suggestions_only = !was_focused; | 326 bool show_password_suggestions_only = !was_focused; |
321 | 327 |
322 // TODO(gcasto): Remove after crbug.com/430318 has been fixed. | 328 // TODO(gcasto): Remove after crbug.com/430318 has been fixed. |
323 bool show_suggestions = true; | 329 bool show_suggestions = true; |
324 #if defined(OS_ANDROID) | 330 #if defined(OS_ANDROID) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 455 } |
450 | 456 |
451 void AutofillAgent::OnFieldTypePredictionsAvailable( | 457 void AutofillAgent::OnFieldTypePredictionsAvailable( |
452 const std::vector<FormDataPredictions>& forms) { | 458 const std::vector<FormDataPredictions>& forms) { |
453 for (size_t i = 0; i < forms.size(); ++i) { | 459 for (size_t i = 0; i < forms.size(); ++i) { |
454 form_cache_.ShowPredictions(forms[i]); | 460 form_cache_.ShowPredictions(forms[i]); |
455 } | 461 } |
456 } | 462 } |
457 | 463 |
458 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { | 464 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { |
459 if (!render_view()->GetWebView() || query_id != autofill_query_id_) | 465 if (query_id != autofill_query_id_) |
460 return; | 466 return; |
461 | 467 |
462 was_query_node_autofilled_ = element_.isAutofilled(); | 468 was_query_node_autofilled_ = element_.isAutofilled(); |
463 FillForm(form, element_); | 469 FillForm(form, element_); |
464 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), | 470 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), |
465 base::TimeTicks::Now())); | 471 base::TimeTicks::Now())); |
466 } | 472 } |
467 | 473 |
468 void AutofillAgent::OnPing() { | 474 void AutofillAgent::OnPing() { |
469 Send(new AutofillHostMsg_PingAck(routing_id())); | 475 Send(new AutofillHostMsg_PingAck(routing_id())); |
470 } | 476 } |
471 | 477 |
472 void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) { | 478 void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) { |
473 if (!render_view()->GetWebView() || query_id != autofill_query_id_) | 479 if (query_id != autofill_query_id_) |
474 return; | 480 return; |
475 | 481 |
476 was_query_node_autofilled_ = element_.isAutofilled(); | 482 was_query_node_autofilled_ = element_.isAutofilled(); |
477 PreviewForm(form, element_); | 483 PreviewForm(form, element_); |
478 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); | 484 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); |
479 } | 485 } |
480 | 486 |
481 void AutofillAgent::OnClearForm() { | 487 void AutofillAgent::OnClearForm() { |
482 form_cache_.ClearFormWithElement(element_); | 488 form_cache_.ClearFormWithElement(element_); |
483 } | 489 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 FormFieldData field; | 660 FormFieldData field; |
655 if (!FindFormAndFieldForFormControlElement(element, &form, &field, | 661 if (!FindFormAndFieldForFormControlElement(element, &form, &field, |
656 requirements)) { | 662 requirements)) { |
657 // If we didn't find the cached form, at least let autocomplete have a shot | 663 // If we didn't find the cached form, at least let autocomplete have a shot |
658 // at providing suggestions. | 664 // at providing suggestions. |
659 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 665 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
660 } | 666 } |
661 if (datalist_only) | 667 if (datalist_only) |
662 field.should_autocomplete = false; | 668 field.should_autocomplete = false; |
663 | 669 |
664 gfx::RectF bounding_box_scaled = | 670 gfx::RectF bounding_box_scaled = GetScaledBoundingBox( |
665 GetScaledBoundingBox(web_view_->pageScaleFactor(), &element_); | 671 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(), |
| 672 &element_); |
666 | 673 |
667 std::vector<base::string16> data_list_values; | 674 std::vector<base::string16> data_list_values; |
668 std::vector<base::string16> data_list_labels; | 675 std::vector<base::string16> data_list_labels; |
669 const WebInputElement* input_element = toWebInputElement(&element); | 676 const WebInputElement* input_element = toWebInputElement(&element); |
670 if (input_element) { | 677 if (input_element) { |
671 // Find the datalist values and send them to the browser process. | 678 // Find the datalist values and send them to the browser process. |
672 GetDataListSuggestions(*input_element, | 679 GetDataListSuggestions(*input_element, |
673 datalist_only, | 680 datalist_only, |
674 &data_list_values, | 681 &data_list_values, |
675 &data_list_labels); | 682 &data_list_labels); |
(...skipping 22 matching lines...) Expand all Loading... |
698 | 705 |
699 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, | 706 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, |
700 WebInputElement* node) { | 707 WebInputElement* node) { |
701 was_query_node_autofilled_ = element_.isAutofilled(); | 708 was_query_node_autofilled_ = element_.isAutofilled(); |
702 node->setSuggestedValue(value.substr(0, node->maxLength())); | 709 node->setSuggestedValue(value.substr(0, node->maxLength())); |
703 node->setAutofilled(true); | 710 node->setAutofilled(true); |
704 node->setSelectionRange(node->value().length(), | 711 node->setSelectionRange(node->value().length(), |
705 node->suggestedValue().length()); | 712 node->suggestedValue().length()); |
706 } | 713 } |
707 | 714 |
708 void AutofillAgent::ProcessForms(const WebLocalFrame& frame) { | 715 void AutofillAgent::ProcessForms() { |
709 // Record timestamp of when the forms are first seen. This is used to | 716 // Record timestamp of when the forms are first seen. This is used to |
710 // measure the overhead of the Autofill feature. | 717 // measure the overhead of the Autofill feature. |
711 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); | 718 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); |
712 | 719 |
713 std::vector<FormData> forms = form_cache_.ExtractNewForms(frame); | 720 WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 721 std::vector<FormData> forms = form_cache_.ExtractNewForms(*frame); |
714 | 722 |
715 // Always communicate to browser process for topmost frame. | 723 // Always communicate to browser process for topmost frame. |
716 if (!forms.empty() || | 724 if (!forms.empty() || !frame->parent()) { |
717 (!frame.parent() && !main_frame_processed_)) { | |
718 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 725 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
719 forms_seen_timestamp)); | 726 forms_seen_timestamp)); |
720 } | 727 } |
721 | |
722 if (!frame.parent()) | |
723 main_frame_processed_ = true; | |
724 } | 728 } |
725 | 729 |
726 void AutofillAgent::HidePopup() { | 730 void AutofillAgent::HidePopup() { |
727 if (!is_popup_possibly_visible_) | 731 if (!is_popup_possibly_visible_) |
728 return; | 732 return; |
729 | 733 |
730 if (!element_.isNull()) | 734 if (!element_.isNull()) |
731 OnClearPreviewedForm(); | 735 OnClearPreviewedForm(); |
732 | 736 |
733 is_popup_possibly_visible_ = false; | 737 is_popup_possibly_visible_ = false; |
734 Send(new AutofillHostMsg_HidePopup(routing_id())); | 738 Send(new AutofillHostMsg_HidePopup(routing_id())); |
735 } | 739 } |
736 | 740 |
737 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { | 741 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { |
738 for (size_t i = 0; i < nodes.size(); ++i) { | 742 for (size_t i = 0; i < nodes.size(); ++i) { |
739 WebLocalFrame* frame = nodes[i].document().frame(); | 743 WebLocalFrame* frame = nodes[i].document().frame(); |
| 744 DCHECK_EQ(frame, render_frame()->GetWebFrame()); |
740 // Only monitors dynamic forms created in the top frame. Dynamic forms | 745 // Only monitors dynamic forms created in the top frame. Dynamic forms |
741 // inserted in iframes are not captured yet. Frame is only processed | 746 // inserted in iframes are not captured yet. Frame is only processed |
742 // if it has finished loading, otherwise you can end up with a partially | 747 // if it has finished loading, otherwise you can end up with a partially |
743 // parsed form. | 748 // parsed form. |
744 if (frame && !frame->parent() && !frame->isLoading()) { | 749 if (!frame->isLoading()) { |
745 ProcessForms(*frame); | 750 ProcessForms(); |
746 password_autofill_agent_->OnDynamicFormsSeen(frame); | 751 password_autofill_agent_->OnDynamicFormsSeen(); |
747 if (password_generation_agent_) | 752 if (password_generation_agent_) |
748 password_generation_agent_->OnDynamicFormsSeen(frame); | 753 password_generation_agent_->OnDynamicFormsSeen(); |
749 return; | 754 return; |
750 } | 755 } |
751 } | 756 } |
752 } | 757 } |
753 | 758 |
| 759 // LegacyAutofillAgent --------------------------------------------------------- |
| 760 |
| 761 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent( |
| 762 content::RenderView* render_view, |
| 763 AutofillAgent* agent) |
| 764 : content::RenderViewObserver(render_view), agent_(agent) { |
| 765 } |
| 766 |
| 767 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() { |
| 768 } |
| 769 |
| 770 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 771 // No-op. Don't delete |this|. |
| 772 } |
| 773 |
| 774 void AutofillAgent::LegacyAutofillAgent::FrameDetached(WebFrame* frame) { |
| 775 agent_->FrameDetached(frame); |
| 776 } |
| 777 |
| 778 void AutofillAgent::LegacyAutofillAgent::WillSubmitForm( |
| 779 WebLocalFrame* frame, |
| 780 const WebFormElement& form) { |
| 781 agent_->WillSubmitForm(frame, form); |
| 782 } |
| 783 |
| 784 void AutofillAgent::LegacyAutofillAgent::DidChangeScrollOffset( |
| 785 WebLocalFrame* frame) { |
| 786 agent_->DidChangeScrollOffset(frame); |
| 787 } |
| 788 |
| 789 void AutofillAgent::LegacyAutofillAgent::FocusedNodeChanged( |
| 790 const WebNode& node) { |
| 791 agent_->FocusedNodeChanged(node); |
| 792 } |
| 793 |
| 794 void AutofillAgent::LegacyAutofillAgent::OrientationChangeEvent() { |
| 795 agent_->OrientationChangeEvent(); |
| 796 } |
| 797 |
| 798 void AutofillAgent::LegacyAutofillAgent::Resized() { |
| 799 agent_->Resized(); |
| 800 } |
| 801 |
754 } // namespace autofill | 802 } // namespace autofill |
OLD | NEW |