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) |
| 147 IPC_MESSAGE_HANDLER(AutofillMsg_FirstUserGestureObservedInTab, |
| 148 OnFirstUserGestureObservedInTab) |
150 IPC_MESSAGE_HANDLER(AutofillMsg_Ping, OnPing) | 149 IPC_MESSAGE_HANDLER(AutofillMsg_Ping, OnPing) |
151 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm) | 150 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm) |
152 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm) | 151 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm) |
153 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, | 152 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, |
154 OnFieldTypePredictionsAvailable) | 153 OnFieldTypePredictionsAvailable) |
155 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm) | 154 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm) |
156 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) | 155 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) |
157 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue) | 156 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue) |
158 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue, | 157 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue, |
159 OnPreviewFieldWithValue) | 158 OnPreviewFieldWithValue) |
160 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, | 159 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, |
161 OnAcceptDataListSuggestion) | 160 OnAcceptDataListSuggestion) |
162 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion, | 161 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion, |
163 OnFillPasswordSuggestion) | 162 OnFillPasswordSuggestion) |
164 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion, | 163 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion, |
165 OnPreviewPasswordSuggestion) | 164 OnPreviewPasswordSuggestion) |
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::DidCommitProvisionalLoad(bool is_new_navigation) { |
174 // If the main frame just finished loading, we should process it. | 173 // TODO(estade): |form_cache_| shouldn't track multiple frames. |
175 if (!frame->parent()) | 174 form_cache_.ResetFrame(*render_frame()->GetWebFrame()); |
176 main_frame_processed_ = false; | |
177 | |
178 ProcessForms(*frame); | |
179 } | 175 } |
180 | 176 |
181 void AutofillAgent::DidCommitProvisionalLoad(WebLocalFrame* frame, | 177 void AutofillAgent::DidFinishDocumentLoad() { |
182 bool is_new_navigation) { | 178 ProcessForms(); |
183 form_cache_.ResetFrame(*frame); | 179 } |
| 180 |
| 181 void AutofillAgent::FrameWillClose() { |
| 182 if (in_flight_request_form_.isNull()) |
| 183 return; |
| 184 |
| 185 Send(new AutofillHostMsg_CancelRequestAutocomplete(routing_id())); |
184 } | 186 } |
185 | 187 |
186 void AutofillAgent::FrameDetached(WebFrame* frame) { | 188 void AutofillAgent::FrameDetached(WebFrame* frame) { |
187 form_cache_.ResetFrame(*frame); | 189 if (frame != render_frame()->GetWebFrame()) |
188 } | |
189 | |
190 void AutofillAgent::FrameWillClose(WebFrame* frame) { | |
191 if (in_flight_request_form_.isNull()) | |
192 return; | 190 return; |
193 | 191 |
194 for (WebFrame* temp = in_flight_request_form_.document().frame(); | 192 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 } | 193 } |
202 | 194 |
203 void AutofillAgent::WillSubmitForm(WebLocalFrame* frame, | 195 void AutofillAgent::WillSubmitForm(WebLocalFrame* frame, |
204 const WebFormElement& form) { | 196 const WebFormElement& form) { |
| 197 if (frame != render_frame()->GetWebFrame()) |
| 198 return; |
| 199 |
205 FormData form_data; | 200 FormData form_data; |
206 if (WebFormElementToFormData(form, | 201 if (WebFormElementToFormData(form, |
207 WebFormControlElement(), | 202 WebFormControlElement(), |
208 REQUIRE_NONE, | 203 REQUIRE_NONE, |
209 static_cast<ExtractMask>( | 204 static_cast<ExtractMask>( |
210 EXTRACT_VALUE | EXTRACT_OPTION_TEXT), | 205 EXTRACT_VALUE | EXTRACT_OPTION_TEXT), |
211 &form_data, | 206 &form_data, |
212 NULL)) { | 207 NULL)) { |
213 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, | 208 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, |
214 base::TimeTicks::Now())); | 209 base::TimeTicks::Now())); |
215 } | 210 } |
216 } | 211 } |
217 | 212 |
| 213 void AutofillAgent::DidChangeScrollOffset(WebLocalFrame* frame) { |
| 214 if (frame != render_frame()->GetWebFrame()) |
| 215 return; |
| 216 |
| 217 HidePopup(); |
| 218 } |
| 219 |
218 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { | 220 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
219 HidePopup(); | 221 HidePopup(); |
220 | 222 |
| 223 if (node.isNull() || !node.isElementNode()) |
| 224 return; |
| 225 |
| 226 if (node.document().frame() != render_frame()->GetWebFrame()) |
| 227 return; |
| 228 |
221 if (password_generation_agent_ && | 229 if (password_generation_agent_ && |
222 password_generation_agent_->FocusedNodeHasChanged(node)) { | 230 password_generation_agent_->FocusedNodeHasChanged(node)) { |
223 is_popup_possibly_visible_ = true; | 231 is_popup_possibly_visible_ = true; |
224 return; | 232 return; |
225 } | 233 } |
226 | 234 |
227 if (node.isNull() || !node.isElementNode()) | |
228 return; | |
229 | |
230 WebElement web_element = node.toConst<WebElement>(); | 235 WebElement web_element = node.toConst<WebElement>(); |
231 | 236 |
232 if (!web_element.document().frame()) | 237 if (!web_element.document().frame()) |
233 return; | 238 return; |
234 | 239 |
235 const WebInputElement* element = toWebInputElement(&web_element); | 240 const WebInputElement* element = toWebInputElement(&web_element); |
236 | 241 |
237 if (!element || !element->isEnabled() || element->isReadOnly() || | 242 if (!element || !element->isEnabled() || element->isReadOnly() || |
238 !element->isTextField() || element->isPasswordField()) | 243 !element->isTextField() || element->isPasswordField()) |
239 return; | 244 return; |
240 | 245 |
241 element_ = *element; | 246 element_ = *element; |
242 } | 247 } |
243 | 248 |
244 void AutofillAgent::OrientationChangeEvent() { | 249 void AutofillAgent::OrientationChangeEvent() { |
245 HidePopup(); | 250 HidePopup(); |
246 } | 251 } |
247 | 252 |
248 void AutofillAgent::Resized() { | 253 void AutofillAgent::Resized() { |
249 HidePopup(); | 254 HidePopup(); |
250 } | 255 } |
251 | 256 |
252 void AutofillAgent::DidChangeScrollOffset(WebLocalFrame*) { | |
253 HidePopup(); | |
254 } | |
255 | |
256 void AutofillAgent::didRequestAutocomplete( | 257 void AutofillAgent::didRequestAutocomplete( |
257 const WebFormElement& form) { | 258 const WebFormElement& form) { |
| 259 DCHECK_EQ(form.document().frame(), render_frame()->GetWebFrame()); |
| 260 |
258 // Disallow the dialog over non-https or broken https, except when the | 261 // Disallow the dialog over non-https or broken https, except when the |
259 // ignore SSL flag is passed. See http://crbug.com/272512. | 262 // ignore SSL flag is passed. See http://crbug.com/272512. |
260 // TODO(palmer): this should be moved to the browser process after frames | 263 // TODO(palmer): this should be moved to the browser process after frames |
261 // get their own processes. | 264 // get their own processes. |
262 GURL url(form.document().url()); | 265 GURL url(form.document().url()); |
263 content::SSLStatus ssl_status = | 266 content::SSLStatus ssl_status = |
264 render_view()->GetSSLStatusOfFrame(form.document().frame()); | 267 render_frame()->GetRenderView()->GetSSLStatusOfFrame( |
| 268 form.document().frame()); |
265 bool is_safe = url.SchemeIs(url::kHttpsScheme) && | 269 bool is_safe = url.SchemeIs(url::kHttpsScheme) && |
266 !net::IsCertStatusError(ssl_status.cert_status); | 270 !net::IsCertStatusError(ssl_status.cert_status); |
267 bool allow_unsafe = CommandLine::ForCurrentProcess()->HasSwitch( | 271 bool allow_unsafe = CommandLine::ForCurrentProcess()->HasSwitch( |
268 ::switches::kReduceSecurityForTesting); | 272 ::switches::kReduceSecurityForTesting); |
269 | 273 |
270 FormData form_data; | 274 FormData form_data; |
271 std::string error_message; | 275 std::string error_message; |
272 if (!in_flight_request_form_.isNull()) { | 276 if (!in_flight_request_form_.isNull()) { |
273 error_message = "already active."; | 277 error_message = "already active."; |
274 } else if (!is_safe && !allow_unsafe) { | 278 } else if (!is_safe && !allow_unsafe) { |
(...skipping 30 matching lines...) Expand all Loading... |
305 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); | 309 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); |
306 } | 310 } |
307 | 311 |
308 void AutofillAgent::setIgnoreTextChanges(bool ignore) { | 312 void AutofillAgent::setIgnoreTextChanges(bool ignore) { |
309 ignore_text_changes_ = ignore; | 313 ignore_text_changes_ = ignore; |
310 } | 314 } |
311 | 315 |
312 void AutofillAgent::FormControlElementClicked( | 316 void AutofillAgent::FormControlElementClicked( |
313 const WebFormControlElement& element, | 317 const WebFormControlElement& element, |
314 bool was_focused) { | 318 bool was_focused) { |
| 319 // TODO(estade): Remove this check when PageClickTracker is per-frame. |
| 320 if (element.document().frame() != render_frame()->GetWebFrame()) |
| 321 return; |
| 322 |
315 const WebInputElement* input_element = toWebInputElement(&element); | 323 const WebInputElement* input_element = toWebInputElement(&element); |
316 if (!input_element && !IsTextAreaElement(element)) | 324 if (!input_element && !IsTextAreaElement(element)) |
317 return; | 325 return; |
318 | 326 |
319 bool show_full_suggestion_list = element.isAutofilled() || was_focused; | 327 bool show_full_suggestion_list = element.isAutofilled() || was_focused; |
320 bool show_password_suggestions_only = !was_focused; | 328 bool show_password_suggestions_only = !was_focused; |
321 | 329 |
322 // TODO(gcasto): Remove after crbug.com/430318 has been fixed. | 330 // TODO(gcasto): Remove after crbug.com/430318 has been fixed. |
323 bool show_suggestions = true; | 331 bool show_suggestions = true; |
324 #if defined(OS_ANDROID) | 332 #if defined(OS_ANDROID) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 if (event.windowsKeyCode == ui::VKEY_DOWN || | 416 if (event.windowsKeyCode == ui::VKEY_DOWN || |
409 event.windowsKeyCode == ui::VKEY_UP) | 417 event.windowsKeyCode == ui::VKEY_UP) |
410 ShowSuggestions(element, true, true, true, false, false, false); | 418 ShowSuggestions(element, true, true, true, false, false, false); |
411 } | 419 } |
412 | 420 |
413 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { | 421 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { |
414 ShowSuggestions(element, true, false, false, true, false, false); | 422 ShowSuggestions(element, true, false, false, true, false, false); |
415 } | 423 } |
416 | 424 |
417 void AutofillAgent::firstUserGestureObserved() { | 425 void AutofillAgent::firstUserGestureObserved() { |
418 password_autofill_agent_->FirstUserGestureObserved(); | 426 Send(new AutofillHostMsg_FirstUserGestureObserved(routing_id())); |
419 } | 427 } |
420 | 428 |
421 void AutofillAgent::AcceptDataListSuggestion( | 429 void AutofillAgent::AcceptDataListSuggestion( |
422 const base::string16& suggested_value) { | 430 const base::string16& suggested_value) { |
423 WebInputElement* input_element = toWebInputElement(&element_); | 431 WebInputElement* input_element = toWebInputElement(&element_); |
424 DCHECK(input_element); | 432 DCHECK(input_element); |
425 base::string16 new_value = suggested_value; | 433 base::string16 new_value = suggested_value; |
426 // If this element takes multiple values then replace the last part with | 434 // If this element takes multiple values then replace the last part with |
427 // the suggestion. | 435 // the suggestion. |
428 if (input_element->isMultiple() && input_element->isEmailField()) { | 436 if (input_element->isMultiple() && input_element->isEmailField()) { |
(...skipping 20 matching lines...) Expand all Loading... |
449 } | 457 } |
450 | 458 |
451 void AutofillAgent::OnFieldTypePredictionsAvailable( | 459 void AutofillAgent::OnFieldTypePredictionsAvailable( |
452 const std::vector<FormDataPredictions>& forms) { | 460 const std::vector<FormDataPredictions>& forms) { |
453 for (size_t i = 0; i < forms.size(); ++i) { | 461 for (size_t i = 0; i < forms.size(); ++i) { |
454 form_cache_.ShowPredictions(forms[i]); | 462 form_cache_.ShowPredictions(forms[i]); |
455 } | 463 } |
456 } | 464 } |
457 | 465 |
458 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { | 466 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { |
459 if (!render_view()->GetWebView() || query_id != autofill_query_id_) | 467 if (query_id != autofill_query_id_) |
460 return; | 468 return; |
461 | 469 |
462 was_query_node_autofilled_ = element_.isAutofilled(); | 470 was_query_node_autofilled_ = element_.isAutofilled(); |
463 FillForm(form, element_); | 471 FillForm(form, element_); |
464 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), | 472 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), |
465 base::TimeTicks::Now())); | 473 base::TimeTicks::Now())); |
466 } | 474 } |
467 | 475 |
| 476 void AutofillAgent::OnFirstUserGestureObservedInTab() { |
| 477 password_autofill_agent_->FirstUserGestureObserved(); |
| 478 } |
| 479 |
468 void AutofillAgent::OnPing() { | 480 void AutofillAgent::OnPing() { |
469 Send(new AutofillHostMsg_PingAck(routing_id())); | 481 Send(new AutofillHostMsg_PingAck(routing_id())); |
470 } | 482 } |
471 | 483 |
472 void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) { | 484 void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) { |
473 if (!render_view()->GetWebView() || query_id != autofill_query_id_) | 485 if (query_id != autofill_query_id_) |
474 return; | 486 return; |
475 | 487 |
476 was_query_node_autofilled_ = element_.isAutofilled(); | 488 was_query_node_autofilled_ = element_.isAutofilled(); |
477 PreviewForm(form, element_); | 489 PreviewForm(form, element_); |
478 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); | 490 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); |
479 } | 491 } |
480 | 492 |
481 void AutofillAgent::OnClearForm() { | 493 void AutofillAgent::OnClearForm() { |
482 form_cache_.ClearFormWithElement(element_); | 494 form_cache_.ClearFormWithElement(element_); |
483 } | 495 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 FormFieldData field; | 666 FormFieldData field; |
655 if (!FindFormAndFieldForFormControlElement(element, &form, &field, | 667 if (!FindFormAndFieldForFormControlElement(element, &form, &field, |
656 requirements)) { | 668 requirements)) { |
657 // If we didn't find the cached form, at least let autocomplete have a shot | 669 // If we didn't find the cached form, at least let autocomplete have a shot |
658 // at providing suggestions. | 670 // at providing suggestions. |
659 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 671 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
660 } | 672 } |
661 if (datalist_only) | 673 if (datalist_only) |
662 field.should_autocomplete = false; | 674 field.should_autocomplete = false; |
663 | 675 |
664 gfx::RectF bounding_box_scaled = | 676 gfx::RectF bounding_box_scaled = GetScaledBoundingBox( |
665 GetScaledBoundingBox(web_view_->pageScaleFactor(), &element_); | 677 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(), |
| 678 &element_); |
666 | 679 |
667 std::vector<base::string16> data_list_values; | 680 std::vector<base::string16> data_list_values; |
668 std::vector<base::string16> data_list_labels; | 681 std::vector<base::string16> data_list_labels; |
669 const WebInputElement* input_element = toWebInputElement(&element); | 682 const WebInputElement* input_element = toWebInputElement(&element); |
670 if (input_element) { | 683 if (input_element) { |
671 // Find the datalist values and send them to the browser process. | 684 // Find the datalist values and send them to the browser process. |
672 GetDataListSuggestions(*input_element, | 685 GetDataListSuggestions(*input_element, |
673 datalist_only, | 686 datalist_only, |
674 &data_list_values, | 687 &data_list_values, |
675 &data_list_labels); | 688 &data_list_labels); |
(...skipping 22 matching lines...) Expand all Loading... |
698 | 711 |
699 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, | 712 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, |
700 WebInputElement* node) { | 713 WebInputElement* node) { |
701 was_query_node_autofilled_ = element_.isAutofilled(); | 714 was_query_node_autofilled_ = element_.isAutofilled(); |
702 node->setSuggestedValue(value.substr(0, node->maxLength())); | 715 node->setSuggestedValue(value.substr(0, node->maxLength())); |
703 node->setAutofilled(true); | 716 node->setAutofilled(true); |
704 node->setSelectionRange(node->value().length(), | 717 node->setSelectionRange(node->value().length(), |
705 node->suggestedValue().length()); | 718 node->suggestedValue().length()); |
706 } | 719 } |
707 | 720 |
708 void AutofillAgent::ProcessForms(const WebLocalFrame& frame) { | 721 void AutofillAgent::ProcessForms() { |
709 // Record timestamp of when the forms are first seen. This is used to | 722 // Record timestamp of when the forms are first seen. This is used to |
710 // measure the overhead of the Autofill feature. | 723 // measure the overhead of the Autofill feature. |
711 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); | 724 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); |
712 | 725 |
713 std::vector<FormData> forms = form_cache_.ExtractNewForms(frame); | 726 WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 727 std::vector<FormData> forms = form_cache_.ExtractNewForms(*frame); |
714 | 728 |
715 // Always communicate to browser process for topmost frame. | 729 // Always communicate to browser process for topmost frame. |
716 if (!forms.empty() || | 730 if (!forms.empty() || !frame->parent()) { |
717 (!frame.parent() && !main_frame_processed_)) { | |
718 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 731 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
719 forms_seen_timestamp)); | 732 forms_seen_timestamp)); |
720 } | 733 } |
721 | |
722 if (!frame.parent()) | |
723 main_frame_processed_ = true; | |
724 } | 734 } |
725 | 735 |
726 void AutofillAgent::HidePopup() { | 736 void AutofillAgent::HidePopup() { |
727 if (!is_popup_possibly_visible_) | 737 if (!is_popup_possibly_visible_) |
728 return; | 738 return; |
729 | 739 |
730 if (!element_.isNull()) | 740 if (!element_.isNull()) |
731 OnClearPreviewedForm(); | 741 OnClearPreviewedForm(); |
732 | 742 |
733 is_popup_possibly_visible_ = false; | 743 is_popup_possibly_visible_ = false; |
734 Send(new AutofillHostMsg_HidePopup(routing_id())); | 744 Send(new AutofillHostMsg_HidePopup(routing_id())); |
735 } | 745 } |
736 | 746 |
737 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { | 747 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { |
738 for (size_t i = 0; i < nodes.size(); ++i) { | 748 for (size_t i = 0; i < nodes.size(); ++i) { |
739 WebLocalFrame* frame = nodes[i].document().frame(); | 749 WebLocalFrame* frame = nodes[i].document().frame(); |
| 750 DCHECK_EQ(frame, render_frame()->GetWebFrame()); |
740 // Only monitors dynamic forms created in the top frame. Dynamic forms | 751 // Only monitors dynamic forms created in the top frame. Dynamic forms |
741 // inserted in iframes are not captured yet. Frame is only processed | 752 // 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 | 753 // if it has finished loading, otherwise you can end up with a partially |
743 // parsed form. | 754 // parsed form. |
744 if (frame && !frame->parent() && !frame->isLoading()) { | 755 if (!frame->isLoading()) { |
745 ProcessForms(*frame); | 756 ProcessForms(); |
746 password_autofill_agent_->OnDynamicFormsSeen(frame); | 757 password_autofill_agent_->OnDynamicFormsSeen(); |
747 if (password_generation_agent_) | 758 if (password_generation_agent_) |
748 password_generation_agent_->OnDynamicFormsSeen(frame); | 759 password_generation_agent_->OnDynamicFormsSeen(); |
749 return; | 760 return; |
750 } | 761 } |
751 } | 762 } |
752 } | 763 } |
753 | 764 |
| 765 // LegacyAutofillAgent --------------------------------------------------------- |
| 766 |
| 767 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent( |
| 768 content::RenderView* render_view, |
| 769 AutofillAgent* agent) |
| 770 : content::RenderViewObserver(render_view), agent_(agent) { |
| 771 } |
| 772 |
| 773 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() { |
| 774 } |
| 775 |
| 776 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 777 // No-op. Don't delete |this|. |
| 778 } |
| 779 |
| 780 void AutofillAgent::LegacyAutofillAgent::FrameDetached(WebFrame* frame) { |
| 781 agent_->FrameDetached(frame); |
| 782 } |
| 783 |
| 784 void AutofillAgent::LegacyAutofillAgent::WillSubmitForm( |
| 785 WebLocalFrame* frame, |
| 786 const WebFormElement& form) { |
| 787 agent_->WillSubmitForm(frame, form); |
| 788 } |
| 789 |
| 790 void AutofillAgent::LegacyAutofillAgent::DidChangeScrollOffset( |
| 791 WebLocalFrame* frame) { |
| 792 agent_->DidChangeScrollOffset(frame); |
| 793 } |
| 794 |
| 795 void AutofillAgent::LegacyAutofillAgent::FocusedNodeChanged( |
| 796 const WebNode& node) { |
| 797 agent_->FocusedNodeChanged(node); |
| 798 } |
| 799 |
| 800 void AutofillAgent::LegacyAutofillAgent::OrientationChangeEvent() { |
| 801 agent_->OrientationChangeEvent(); |
| 802 } |
| 803 |
| 804 void AutofillAgent::LegacyAutofillAgent::Resized() { |
| 805 agent_->Resized(); |
| 806 } |
| 807 |
754 } // namespace autofill | 808 } // namespace autofill |
OLD | NEW |