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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, | 214 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, |
215 base::TimeTicks::Now())); | 215 base::TimeTicks::Now())); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { | 219 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
220 HidePopup(); | 220 HidePopup(); |
221 | 221 |
222 if (password_generation_agent_ && | 222 if (password_generation_agent_ && |
223 password_generation_agent_->FocusedNodeHasChanged(node)) { | 223 password_generation_agent_->FocusedNodeHasChanged(node)) { |
224 is_popup_possibly_visible_ = true; | |
225 return; | 224 return; |
226 } | 225 } |
227 | 226 |
228 if (node.isNull() || !node.isElementNode()) | 227 if (node.isNull() || !node.isElementNode()) |
229 return; | 228 return; |
230 | 229 |
231 WebElement web_element = node.toConst<WebElement>(); | 230 WebElement web_element = node.toConst<WebElement>(); |
232 | 231 |
233 if (!web_element.document().frame()) | 232 if (!web_element.document().frame()) |
234 return; | 233 return; |
235 | 234 |
236 const WebInputElement* element = toWebInputElement(&web_element); | 235 const WebInputElement* element = toWebInputElement(&web_element); |
237 | 236 |
238 if (!element || !element->isEnabled() || element->isReadOnly() || | 237 if (!element || !element->isEnabled() || element->isReadOnly() || |
239 !element->isTextField() || element->isPasswordField()) | 238 !element->isTextField() || element->isPasswordField()) |
240 return; | 239 return; |
241 | 240 |
242 element_ = *element; | 241 element_ = *element; |
243 } | 242 } |
244 | 243 |
245 void AutofillAgent::OrientationChangeEvent() { | 244 void AutofillAgent::OrientationChangeEvent() { |
246 HidePopup(); | 245 HidePopup(); |
247 } | 246 } |
248 | 247 |
| 248 void AutofillAgent::Resized() { |
| 249 HidePopup(); |
| 250 } |
| 251 |
249 void AutofillAgent::DidChangeScrollOffset(WebLocalFrame*) { | 252 void AutofillAgent::DidChangeScrollOffset(WebLocalFrame*) { |
250 HidePopup(); | 253 HidePopup(); |
251 } | 254 } |
252 | 255 |
253 void AutofillAgent::didRequestAutocomplete( | 256 void AutofillAgent::didRequestAutocomplete( |
254 const WebFormElement& form) { | 257 const WebFormElement& form) { |
255 // Disallow the dialog over non-https or broken https, except when the | 258 // Disallow the dialog over non-https or broken https, except when the |
256 // ignore SSL flag is passed. See http://crbug.com/272512. | 259 // ignore SSL flag is passed. See http://crbug.com/272512. |
257 // TODO(palmer): this should be moved to the browser process after frames | 260 // TODO(palmer): this should be moved to the browser process after frames |
258 // get their own processes. | 261 // get their own processes. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 const WebFormControlElement& element) { | 359 const WebFormControlElement& element) { |
357 // If the element isn't focused then the changes don't matter. This check is | 360 // If the element isn't focused then the changes don't matter. This check is |
358 // required to properly handle IME interactions. | 361 // required to properly handle IME interactions. |
359 if (!element.focused()) | 362 if (!element.focused()) |
360 return; | 363 return; |
361 | 364 |
362 const WebInputElement* input_element = toWebInputElement(&element); | 365 const WebInputElement* input_element = toWebInputElement(&element); |
363 if (input_element) { | 366 if (input_element) { |
364 if (password_generation_agent_ && | 367 if (password_generation_agent_ && |
365 password_generation_agent_->TextDidChangeInTextField(*input_element)) { | 368 password_generation_agent_->TextDidChangeInTextField(*input_element)) { |
366 is_popup_possibly_visible_ = true; | |
367 return; | 369 return; |
368 } | 370 } |
369 | 371 |
370 if (password_autofill_agent_->TextDidChangeInTextField(*input_element)) { | 372 if (password_autofill_agent_->TextDidChangeInTextField(*input_element)) { |
371 element_ = element; | 373 element_ = element; |
372 return; | 374 return; |
373 } | 375 } |
374 } | 376 } |
375 | 377 |
376 ShowSuggestions(element, false, true, false, false, false, false); | 378 ShowSuggestions(element, false, true, false, false, false, false); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 if (!input_element->isTextField() || input_element->isPasswordField()) | 566 if (!input_element->isTextField() || input_element->isPasswordField()) |
565 return; | 567 return; |
566 if (!datalist_only && !input_element->suggestedValue().isEmpty()) | 568 if (!datalist_only && !input_element->suggestedValue().isEmpty()) |
567 return; | 569 return; |
568 } else { | 570 } else { |
569 DCHECK(IsTextAreaElement(element)); | 571 DCHECK(IsTextAreaElement(element)); |
570 if (!element.toConst<WebTextAreaElement>().suggestedValue().isEmpty()) | 572 if (!element.toConst<WebTextAreaElement>().suggestedValue().isEmpty()) |
571 return; | 573 return; |
572 } | 574 } |
573 | 575 |
| 576 is_popup_possibly_visible_ = true; |
| 577 |
574 // Don't attempt to autofill with values that are too large or if filling | 578 // Don't attempt to autofill with values that are too large or if filling |
575 // criteria are not met. | 579 // criteria are not met. |
576 WebString value = element.editingValue(); | 580 WebString value = element.editingValue(); |
577 if (!datalist_only && | 581 if (!datalist_only && |
578 (value.length() > kMaxDataLength || | 582 (value.length() > kMaxDataLength || |
579 (!autofill_on_empty_values && value.isEmpty()) || | 583 (!autofill_on_empty_values && value.isEmpty()) || |
580 (requires_caret_at_end && | 584 (requires_caret_at_end && |
581 (element.selectionStart() != element.selectionEnd() || | 585 (element.selectionStart() != element.selectionEnd() || |
582 element.selectionEnd() != static_cast<int>(value.length()))))) { | 586 element.selectionEnd() != static_cast<int>(value.length()))))) { |
583 // Any popup currently showing is obsolete. | 587 // Any popup currently showing is obsolete. |
584 HidePopup(); | 588 HidePopup(); |
585 return; | 589 return; |
586 } | 590 } |
587 | 591 |
588 element_ = element; | 592 element_ = element; |
589 if (IsAutofillableInputElement(input_element) && | 593 if (IsAutofillableInputElement(input_element) && |
590 (password_autofill_agent_->ShowSuggestions(*input_element, | 594 (password_autofill_agent_->ShowSuggestions(*input_element, |
591 show_full_suggestion_list) || | 595 show_full_suggestion_list) || |
592 show_password_suggestions_only)) { | 596 show_password_suggestions_only)) { |
593 is_popup_possibly_visible_ = true; | |
594 return; | 597 return; |
595 } | 598 } |
596 | 599 |
597 // If autocomplete is disabled at the field level, ensure that the native | 600 // If autocomplete is disabled at the field level, ensure that the native |
598 // UI won't try to show a warning, since that may conflict with a custom | 601 // UI won't try to show a warning, since that may conflict with a custom |
599 // popup. Note that we cannot use the WebKit method element.autoComplete() | 602 // popup. Note that we cannot use the WebKit method element.autoComplete() |
600 // as it does not allow us to distinguish the case where autocomplete is | 603 // as it does not allow us to distinguish the case where autocomplete is |
601 // disabled for *both* the element and for the form. | 604 // disabled for *both* the element and for the form. |
602 const base::string16 autocomplete_attribute = | 605 const base::string16 autocomplete_attribute = |
603 element.getAttribute("autocomplete"); | 606 element.getAttribute("autocomplete"); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 if (input_element) { | 653 if (input_element) { |
651 // Find the datalist values and send them to the browser process. | 654 // Find the datalist values and send them to the browser process. |
652 GetDataListSuggestions(*input_element, | 655 GetDataListSuggestions(*input_element, |
653 datalist_only, | 656 datalist_only, |
654 &data_list_values, | 657 &data_list_values, |
655 &data_list_labels); | 658 &data_list_labels); |
656 TrimStringVectorForIPC(&data_list_values); | 659 TrimStringVectorForIPC(&data_list_values); |
657 TrimStringVectorForIPC(&data_list_labels); | 660 TrimStringVectorForIPC(&data_list_labels); |
658 } | 661 } |
659 | 662 |
660 is_popup_possibly_visible_ = true; | |
661 Send(new AutofillHostMsg_SetDataList(routing_id(), | 663 Send(new AutofillHostMsg_SetDataList(routing_id(), |
662 data_list_values, | 664 data_list_values, |
663 data_list_labels)); | 665 data_list_labels)); |
664 | 666 |
665 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), | 667 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), |
666 autofill_query_id_, | 668 autofill_query_id_, |
667 form, | 669 form, |
668 field, | 670 field, |
669 bounding_box_scaled, | 671 bounding_box_scaled, |
670 display_warning_if_disabled)); | 672 display_warning_if_disabled)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 // parsed form. | 727 // parsed form. |
726 if (frame && !frame->parent() && !frame->isLoading()) { | 728 if (frame && !frame->parent() && !frame->isLoading()) { |
727 ProcessForms(*frame); | 729 ProcessForms(*frame); |
728 password_autofill_agent_->OnDynamicFormsSeen(frame); | 730 password_autofill_agent_->OnDynamicFormsSeen(frame); |
729 return; | 731 return; |
730 } | 732 } |
731 } | 733 } |
732 } | 734 } |
733 | 735 |
734 } // namespace autofill | 736 } // namespace autofill |
OLD | NEW |