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; | |
28 } | |
29 | |
30 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( | |
31 const webkit::forms::FormField& field, | |
32 const string16& value) { | |
33 webkit::forms::FormField input; | |
34 PasswordInfo password; | |
35 if (!FindLoginInfo(field, &input, &password)) | |
36 return false; | |
37 | |
38 if (WillFillUserNameAndPassword(input, password.fill_data)) { | |
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 PasswordInfo 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 PasswordInfo password; | |
61 return FindLoginInfo(field, &input, &password); | |
62 } | |
63 | |
64 void PasswordAutofillManager::PasswordFormMapping( | |
65 const webkit::forms::FormField& username_element, | |
66 const webkit::forms::PasswordFormFillData& fill_data) { | |
67 PasswordInfo password_info; | |
68 password_info.fill_data = fill_data; | |
69 | |
70 login_to_password_info_[username_element] = password_info; | |
71 } | |
72 | |
73 void PasswordAutofillManager::FrameClosing() { | |
74 // When this function lived in the renderer only login info that was added | |
75 // with the same frame_id as this closing frame was removed instead of all | |
76 // the elements. | |
77 // If weird behaviour occurs with login info disappearing from a page, this | |
78 // could be the cause. | |
79 | |
80 login_to_password_info_.clear(); | |
81 } | |
Ilya Sherman
2012/03/09 22:00:26
I don't think this is safe, because the frame that
csharp
2012/03/12 15:11:56
Ah, that makes much more sense, sorry for misreadi
| |
82 | |
83 //////////////////////////////////////////////////////////////////////////////// | |
84 // PasswordAutofillManager, private: | |
85 | |
86 bool PasswordAutofillManager::WillFillUserNameAndPassword( | |
87 const webkit::forms::FormField& username_element, | |
88 const webkit::forms::PasswordFormFillData& fill_data) { | |
89 string16 current_username = username_element.value; | |
90 | |
91 // Look for any suitable matches to current field text. | |
92 if (fill_data.basic_data.fields[0].value == current_username) { | |
93 return true; | |
94 } else { | |
95 // Scan additional logins for a match. | |
96 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; | |
97 for (iter = fill_data.additional_logins.begin(); | |
98 iter != fill_data.additional_logins.end(); ++iter) { | |
99 if (iter->first == current_username) | |
100 return true; | |
101 } | |
102 } | |
103 | |
104 return false; | |
105 } | |
106 | |
107 bool PasswordAutofillManager::FindLoginInfo( | |
108 const webkit::forms::FormField& field, | |
109 webkit::forms::FormField* found_input, | |
110 PasswordInfo* found_password) { | |
111 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | |
112 if (iter == login_to_password_info_.end()) | |
113 return false; | |
114 | |
115 *found_input = field; | |
116 *found_password = iter->second; | |
117 return true; | |
118 } | |
OLD | NEW |