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