| 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/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 : content::RenderFrameObserver(render_frame), | 149 : content::RenderFrameObserver(render_frame), |
| 150 form_cache_(*render_frame->GetWebFrame()), | 150 form_cache_(*render_frame->GetWebFrame()), |
| 151 password_autofill_agent_(password_autofill_agent), | 151 password_autofill_agent_(password_autofill_agent), |
| 152 password_generation_agent_(password_generation_agent), | 152 password_generation_agent_(password_generation_agent), |
| 153 legacy_(render_frame->GetRenderView(), this), | 153 legacy_(render_frame->GetRenderView(), this), |
| 154 autofill_query_id_(0), | 154 autofill_query_id_(0), |
| 155 was_query_node_autofilled_(false), | 155 was_query_node_autofilled_(false), |
| 156 has_shown_autofill_popup_for_current_edit_(false), | 156 has_shown_autofill_popup_for_current_edit_(false), |
| 157 ignore_text_changes_(false), | 157 ignore_text_changes_(false), |
| 158 is_popup_possibly_visible_(false), | 158 is_popup_possibly_visible_(false), |
| 159 is_generation_popup_possibly_visible_(false), |
| 159 weak_ptr_factory_(this) { | 160 weak_ptr_factory_(this) { |
| 160 render_frame->GetWebFrame()->setAutofillClient(this); | 161 render_frame->GetWebFrame()->setAutofillClient(this); |
| 161 | 162 |
| 162 // This owns itself, and will delete itself when |render_frame| is destructed | 163 // This owns itself, and will delete itself when |render_frame| is destructed |
| 163 // (same as AutofillAgent). | 164 // (same as AutofillAgent). This object must be constructed after |
| 165 // AutofillAgent so that password generation UI is shown before password |
| 166 // manager UI (see https://crbug.com/498545). |
| 164 new PageClickTracker(render_frame, this); | 167 new PageClickTracker(render_frame, this); |
| 165 } | 168 } |
| 166 | 169 |
| 167 AutofillAgent::~AutofillAgent() {} | 170 AutofillAgent::~AutofillAgent() {} |
| 168 | 171 |
| 169 bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs, | 172 bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs, |
| 170 const FormData& rhs) const { | 173 const FormData& rhs) const { |
| 171 if (lhs.name != rhs.name) | 174 if (lhs.name != rhs.name) |
| 172 return lhs.name < rhs.name; | 175 return lhs.name < rhs.name; |
| 173 if (lhs.origin != rhs.origin) | 176 if (lhs.origin != rhs.origin) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 276 } |
| 274 | 277 |
| 275 void AutofillAgent::FocusChangeComplete() { | 278 void AutofillAgent::FocusChangeComplete() { |
| 276 WebDocument doc = render_frame()->GetWebFrame()->document(); | 279 WebDocument doc = render_frame()->GetWebFrame()->document(); |
| 277 WebElement focused_element; | 280 WebElement focused_element; |
| 278 if (!doc.isNull()) | 281 if (!doc.isNull()) |
| 279 focused_element = doc.focusedElement(); | 282 focused_element = doc.focusedElement(); |
| 280 | 283 |
| 281 if (!focused_element.isNull() && password_generation_agent_ && | 284 if (!focused_element.isNull() && password_generation_agent_ && |
| 282 password_generation_agent_->FocusedNodeHasChanged(focused_element)) { | 285 password_generation_agent_->FocusedNodeHasChanged(focused_element)) { |
| 286 is_generation_popup_possibly_visible_ = true; |
| 283 is_popup_possibly_visible_ = true; | 287 is_popup_possibly_visible_ = true; |
| 284 } | 288 } |
| 285 } | 289 } |
| 286 | 290 |
| 287 void AutofillAgent::didRequestAutocomplete( | 291 void AutofillAgent::didRequestAutocomplete( |
| 288 const WebFormElement& form) { | 292 const WebFormElement& form) { |
| 289 DCHECK_EQ(form.document().frame(), render_frame()->GetWebFrame()); | 293 DCHECK_EQ(form.document().frame(), render_frame()->GetWebFrame()); |
| 290 | 294 |
| 291 // Disallow the dialog over non-https or broken https, except when the | 295 // Disallow the dialog over non-https or broken https, except when the |
| 292 // ignore SSL flag is passed. See http://crbug.com/272512. | 296 // ignore SSL flag is passed. See http://crbug.com/272512. |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 (options.requires_caret_at_end && | 654 (options.requires_caret_at_end && |
| 651 (element.selectionStart() != element.selectionEnd() || | 655 (element.selectionStart() != element.selectionEnd() || |
| 652 element.selectionEnd() != static_cast<int>(value.length()))))) { | 656 element.selectionEnd() != static_cast<int>(value.length()))))) { |
| 653 // Any popup currently showing is obsolete. | 657 // Any popup currently showing is obsolete. |
| 654 HidePopup(); | 658 HidePopup(); |
| 655 return; | 659 return; |
| 656 } | 660 } |
| 657 | 661 |
| 658 element_ = element; | 662 element_ = element; |
| 659 if (IsAutofillableInputElement(input_element) && | 663 if (IsAutofillableInputElement(input_element) && |
| 660 (password_autofill_agent_->ShowSuggestions( | 664 password_autofill_agent_->ShowSuggestions( |
| 661 *input_element, options.show_full_suggestion_list) || | 665 *input_element, options.show_full_suggestion_list, |
| 662 options.show_password_suggestions_only)) { | 666 is_generation_popup_possibly_visible_)) { |
| 663 is_popup_possibly_visible_ = true; | 667 is_popup_possibly_visible_ = true; |
| 664 return; | 668 return; |
| 665 } | 669 } |
| 666 | 670 |
| 671 if (is_generation_popup_possibly_visible_) |
| 672 return; |
| 673 |
| 674 if (options.show_password_suggestions_only) |
| 675 return; |
| 676 |
| 667 // Password field elements should only have suggestions shown by the password | 677 // Password field elements should only have suggestions shown by the password |
| 668 // autofill agent. | 678 // autofill agent. |
| 669 if (input_element && input_element->isPasswordField()) | 679 if (input_element && input_element->isPasswordField()) |
| 670 return; | 680 return; |
| 671 | 681 |
| 672 QueryAutofillSuggestions(element, options.datalist_only); | 682 QueryAutofillSuggestions(element, options.datalist_only); |
| 673 } | 683 } |
| 674 | 684 |
| 675 void AutofillAgent::QueryAutofillSuggestions( | 685 void AutofillAgent::QueryAutofillSuggestions( |
| 676 const WebFormControlElement& element, | 686 const WebFormControlElement& element, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 if (!forms.empty() || !frame->parent()) { | 756 if (!forms.empty() || !frame->parent()) { |
| 747 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 757 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
| 748 forms_seen_timestamp)); | 758 forms_seen_timestamp)); |
| 749 } | 759 } |
| 750 } | 760 } |
| 751 | 761 |
| 752 void AutofillAgent::HidePopup() { | 762 void AutofillAgent::HidePopup() { |
| 753 if (!is_popup_possibly_visible_) | 763 if (!is_popup_possibly_visible_) |
| 754 return; | 764 return; |
| 755 is_popup_possibly_visible_ = false; | 765 is_popup_possibly_visible_ = false; |
| 766 is_generation_popup_possibly_visible_ = false; |
| 756 Send(new AutofillHostMsg_HidePopup(routing_id())); | 767 Send(new AutofillHostMsg_HidePopup(routing_id())); |
| 757 } | 768 } |
| 758 | 769 |
| 759 bool AutofillAgent::IsUserGesture() const { | 770 bool AutofillAgent::IsUserGesture() const { |
| 760 return WebUserGestureIndicator::isProcessingUserGesture(); | 771 return WebUserGestureIndicator::isProcessingUserGesture(); |
| 761 } | 772 } |
| 762 | 773 |
| 763 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { | 774 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { |
| 764 for (size_t i = 0; i < nodes.size(); ++i) { | 775 for (size_t i = 0; i < nodes.size(); ++i) { |
| 765 WebLocalFrame* frame = nodes[i].document().frame(); | 776 WebLocalFrame* frame = nodes[i].document().frame(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 794 | 805 |
| 795 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | 806 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 796 // No-op. Don't delete |this|. | 807 // No-op. Don't delete |this|. |
| 797 } | 808 } |
| 798 | 809 |
| 799 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | 810 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
| 800 agent_->FocusChangeComplete(); | 811 agent_->FocusChangeComplete(); |
| 801 } | 812 } |
| 802 | 813 |
| 803 } // namespace autofill | 814 } // namespace autofill |
| OLD | NEW |