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/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "components/autofill/content/renderer/form_autofill_util.h" | 12 #include "components/autofill/content/renderer/form_autofill_util.h" |
13 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 13 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
14 #include "components/autofill/core/common/autofill_messages.h" | 14 #include "components/autofill/core/common/autofill_messages.h" |
15 #include "components/autofill/core/common/form_field_data.h" | 15 #include "components/autofill/core/common/form_field_data.h" |
16 #include "components/autofill/core/common/password_form.h" | 16 #include "components/autofill/core/common/password_form.h" |
17 #include "components/autofill/core/common/password_form_fill_data.h" | 17 #include "components/autofill/core/common/password_form_fill_data.h" |
18 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
20 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 20 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
21 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
22 #include "third_party/WebKit/public/web/WebElement.h" | 22 #include "third_party/WebKit/public/web/WebElement.h" |
23 #include "third_party/WebKit/public/web/WebFormElement.h" | 23 #include "third_party/WebKit/public/web/WebFormElement.h" |
24 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
25 #include "third_party/WebKit/public/web/WebInputEvent.h" | 25 #include "third_party/WebKit/public/web/WebInputEvent.h" |
26 #include "third_party/WebKit/public/web/WebNode.h" | 26 #include "third_party/WebKit/public/web/WebNode.h" |
27 #include "third_party/WebKit/public/web/WebNodeList.h" | 27 #include "third_party/WebKit/public/web/WebNodeList.h" |
28 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 28 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
29 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 29 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
30 #include "third_party/WebKit/public/web/WebUserGestureToken.h" | |
Garrett Casto
2013/12/02 23:49:12
Is this leftover from a previous version? Doesn't
jww
2013/12/03 06:29:59
Done.
| |
30 #include "third_party/WebKit/public/web/WebView.h" | 31 #include "third_party/WebKit/public/web/WebView.h" |
31 #include "ui/events/keycodes/keyboard_codes.h" | 32 #include "ui/events/keycodes/keyboard_codes.h" |
32 | 33 |
33 namespace autofill { | 34 namespace autofill { |
34 namespace { | 35 namespace { |
35 | 36 |
36 // The size above which we stop triggering autocomplete. | 37 // The size above which we stop triggering autocomplete. |
37 static const size_t kMaximumTextSizeForAutocomplete = 1000; | 38 static const size_t kMaximumTextSizeForAutocomplete = 1000; |
38 | 39 |
39 // Maps element names to the actual elements to simplify form filling. | 40 // Maps element names to the actual elements to simplify form filling. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 | 183 |
183 } // namespace | 184 } // namespace |
184 | 185 |
185 //////////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////////// |
186 // PasswordAutofillAgent, public: | 187 // PasswordAutofillAgent, public: |
187 | 188 |
188 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) | 189 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view) |
189 : content::RenderViewObserver(render_view), | 190 : content::RenderViewObserver(render_view), |
190 usernames_usage_(NOTHING_TO_AUTOFILL), | 191 usernames_usage_(NOTHING_TO_AUTOFILL), |
191 web_view_(render_view->GetWebView()), | 192 web_view_(render_view->GetWebView()), |
192 weak_ptr_factory_(this) { | 193 weak_ptr_factory_(this), |
194 gestureHandler_(new AutofillWebUserGestureHandler(this)), | |
195 userGestureOccurred_(false) { | |
196 blink::WebUserGestureIndicator::setHandler(gestureHandler_); | |
193 } | 197 } |
194 | 198 |
195 PasswordAutofillAgent::~PasswordAutofillAgent() { | 199 PasswordAutofillAgent::~PasswordAutofillAgent() { |
200 DCHECK(gestureHandler_); | |
201 blink::WebUserGestureIndicator::setHandler(0); | |
Garrett Casto
2013/12/02 23:49:12
use NULL for this instead of 0, since we are talki
jww
2013/12/03 06:29:59
Done.
| |
202 delete gestureHandler_; | |
196 } | 203 } |
197 | 204 |
198 bool PasswordAutofillAgent::TextFieldDidEndEditing( | 205 bool PasswordAutofillAgent::TextFieldDidEndEditing( |
199 const blink::WebInputElement& element) { | 206 const blink::WebInputElement& element) { |
200 LoginToPasswordInfoMap::const_iterator iter = | 207 LoginToPasswordInfoMap::const_iterator iter = |
201 login_to_password_info_.find(element); | 208 login_to_password_info_.find(element); |
202 if (iter == login_to_password_info_.end()) | 209 if (iter == login_to_password_info_.end()) |
203 return false; | 210 return false; |
204 | 211 |
205 const PasswordFormFillData& fill_data = | 212 const PasswordFormFillData& fill_data = |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 if (set_selection) { | 728 if (set_selection) { |
722 username_element->setSelectionRange(current_username.length(), | 729 username_element->setSelectionRange(current_username.length(), |
723 username.length()); | 730 username.length()); |
724 } | 731 } |
725 } else if (current_username != username) { | 732 } else if (current_username != username) { |
726 // If the username can't be filled and it doesn't match a saved password | 733 // If the username can't be filled and it doesn't match a saved password |
727 // as is, don't autofill a password. | 734 // as is, don't autofill a password. |
728 return false; | 735 return false; |
729 } | 736 } |
730 | 737 |
731 password_element->setValue(password); | 738 // We do not autofill into the DOM until a user gesture has occurred to make |
739 // sure that the user is intentionally interacting with page. So if there | |
740 // isn't a user gesture occuring right now, we setup a handler here to wait | |
741 // for such a gesture to occur. | |
Garrett Casto
2013/12/02 23:49:12
Shouldn't this be "If a user gesture hasn't occurr
jww
2013/12/03 06:29:59
Done.
| |
742 if (!userGestureOccurred_) { | |
743 gestureHandler_->addElement(new blink::WebInputElement(*password_element)); | |
Garrett Casto
2013/12/02 23:49:12
I think that we can just keep a copy of the WebInp
jww
2013/12/03 06:29:59
Done.
| |
744 password_element->setSuggestedValue(password); | |
745 } else { | |
746 password_element->setValue(password); | |
747 } | |
732 SetElementAutofilled(password_element, true); | 748 SetElementAutofilled(password_element, true); |
733 return true; | 749 return true; |
734 } | 750 } |
735 | 751 |
736 void PasswordAutofillAgent::PerformInlineAutocomplete( | 752 void PasswordAutofillAgent::PerformInlineAutocomplete( |
737 const blink::WebInputElement& username_input, | 753 const blink::WebInputElement& username_input, |
738 const blink::WebInputElement& password_input, | 754 const blink::WebInputElement& password_input, |
739 const PasswordFormFillData& fill_data) { | 755 const PasswordFormFillData& fill_data) { |
740 DCHECK(!fill_data.wait_for_username); | 756 DCHECK(!fill_data.wait_for_username); |
741 | 757 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 blink::WebInputElement input = element.to<blink::WebInputElement>(); | 810 blink::WebInputElement input = element.to<blink::WebInputElement>(); |
795 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 811 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
796 if (iter == login_to_password_info_.end()) | 812 if (iter == login_to_password_info_.end()) |
797 return false; | 813 return false; |
798 | 814 |
799 *found_input = input; | 815 *found_input = input; |
800 *found_password = iter->second; | 816 *found_password = iter->second; |
801 return true; | 817 return true; |
802 } | 818 } |
803 | 819 |
820 void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() { | |
Garrett Casto
2013/12/02 23:49:12
To be clear, this gets called whenever there is a
jww
2013/12/03 06:29:59
Yup!
| |
821 agent_->setUserGestureOccurred(true); | |
822 | |
823 std::vector<blink::WebInputElement*>::iterator iter; | |
824 for (iter = elements_.begin(); iter != elements_.end(); ++iter) { | |
825 if (!(*iter)->isNull() && !(*iter)->suggestedValue().isNull()) { | |
826 DCHECK(!(*iter)->suggestedValue().isNull()); | |
Garrett Casto
2013/12/02 23:49:12
I don't think that there is much value to DCHECK o
jww
2013/12/03 06:29:59
Done.
| |
827 (*iter)->setValue((*iter)->suggestedValue()); | |
828 } | |
829 delete (*iter); | |
830 } | |
831 | |
832 elements_.clear(); | |
833 } | |
834 | |
835 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | |
836 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) | |
837 : agent_(agent) {} | |
838 | |
839 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | |
840 ~AutofillWebUserGestureHandler() { | |
841 std::vector<blink::WebInputElement*>::iterator iter; | |
Garrett Casto
2013/12/02 23:49:12
I don't think that this should be necessary to kee
jww
2013/12/03 06:29:59
Oh, awesome!
| |
842 for (iter = elements_.begin(); iter != elements_.end(); ++iter) { | |
843 delete (*iter); | |
844 } | |
845 | |
846 elements_.clear(); | |
847 } | |
848 | |
804 } // namespace autofill | 849 } // namespace autofill |
OLD | NEW |