OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/autofill/password_autofill_manager.h" | |
6 #include "chrome/common/autofill_messages.h" | |
7 #include "content/public/browser/render_view_host.h" | |
8 #include "ui/base/keycodes/keyboard_codes.h" | |
9 | |
10 //////////////////////////////////////////////////////////////////////////////// | |
11 // PasswordAutofillManager, public: | |
12 | |
13 PasswordAutofillManager::PasswordAutofillManager( | |
14 content::RenderViewHost* render_view_host) | |
15 : render_view_host_(render_view_host) { | |
16 } | |
17 | |
18 PasswordAutofillManager::~PasswordAutofillManager() { | |
19 } | |
20 | |
21 bool PasswordAutofillManager::WouldHandleKeyDown( | |
22 const webkit::forms::FormField& field) { | |
23 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | |
24 if (iter == login_to_password_info_.end()) | |
25 return false; | |
26 | |
27 return true; | |
Ilya Sherman
2012/03/15 18:27:41
nit: You can combine lines 24-27 as """return iter
csharp
2012/03/16 20:21:12
Done.
| |
28 } | |
29 | |
30 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( | |
31 const webkit::forms::FormField& field, | |
32 const string16& value) { | |
33 webkit::forms::FormField input; | |
34 webkit::forms::PasswordFormFillData password; | |
35 if (!FindLoginInfo(field, &input, &password)) | |
36 return false; | |
37 | |
38 if (WillFillUserNameAndPassword(input, password)) { | |
39 if (render_view_host_) { | |
40 render_view_host_->Send(new AutofillMsg_PasswordAcceptAutofillSuggestion( | |
41 render_view_host_->GetRoutingID(), | |
42 value)); | |
43 } | |
44 return true; | |
45 } | |
46 | |
47 return false; | |
48 } | |
49 | |
50 bool PasswordAutofillManager::DidSelectAutofillSuggestion( | |
51 const webkit::forms::FormField& field) { | |
52 webkit::forms::FormField input; | |
53 webkit::forms::PasswordFormFillData password; | |
54 return FindLoginInfo(field, &input, &password); | |
55 } | |
56 | |
57 bool PasswordAutofillManager::DidClearAutofillSelection( | |
58 const webkit::forms::FormField& field) { | |
59 webkit::forms::FormField input; | |
60 webkit::forms::PasswordFormFillData password; | |
61 return FindLoginInfo(field, &input, &password); | |
62 } | |
63 | |
64 void PasswordAutofillManager::AddPasswordFormMapping( | |
65 const webkit::forms::FormField& username_element, | |
66 const webkit::forms::PasswordFormFillData& password) { | |
67 login_to_password_info_[username_element] = password; | |
68 } | |
69 | |
70 void PasswordAutofillManager::Reset() { | |
71 login_to_password_info_.clear(); | |
72 } | |
73 | |
74 //////////////////////////////////////////////////////////////////////////////// | |
75 // PasswordAutofillManager, private: | |
76 | |
77 bool PasswordAutofillManager::WillFillUserNameAndPassword( | |
78 const webkit::forms::FormField& username_element, | |
79 const webkit::forms::PasswordFormFillData& fill_data) { | |
80 string16 current_username = username_element.value; | |
Ilya Sherman
2012/03/15 18:27:41
Hmm, is this always going to be the empty string,
csharp
2012/03/16 20:21:12
It is. I failed to copy over an assignment stateme
| |
81 | |
82 // Look for any suitable matches to current field text. | |
83 if (fill_data.basic_data.fields[0].value == current_username) { | |
Ilya Sherman
2012/03/15 18:27:41
Why is this a full string equality check, rather t
csharp
2012/03/16 20:21:12
If you've selected isherman then current_username
Ilya Sherman
2012/03/20 00:58:55
What happens if I type "ish" and click on the sugg
Ilya Sherman
2012/03/22 01:20:06
Bump.
csharp
2012/03/29 16:28:17
current_username will be equal to what you selecte
| |
84 return true; | |
85 } else { | |
86 // Scan additional logins for a match. | |
87 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; | |
88 for (iter = fill_data.additional_logins.begin(); | |
89 iter != fill_data.additional_logins.end(); ++iter) { | |
90 if (iter->first == current_username) | |
91 return true; | |
92 } | |
93 } | |
94 | |
95 return false; | |
96 } | |
97 | |
98 bool PasswordAutofillManager::FindLoginInfo( | |
99 const webkit::forms::FormField& field, | |
100 webkit::forms::FormField* found_input, | |
101 webkit::forms::PasswordFormFillData* found_password) { | |
102 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | |
103 if (iter == login_to_password_info_.end()) | |
104 return false; | |
105 | |
106 *found_input = field; | |
107 *found_password = iter->second; | |
108 return true; | |
109 } | |
OLD | NEW |