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/browser/ui/tab_contents/tab_contents_wrapper.h" | |
7 #include "chrome/common/autofill_messages.h" | |
8 #include "content/browser/renderer_host/render_view_host.h" | |
9 #include "content/public/browser/web_contents.h" | |
10 #include "content/public/renderer/render_view.h" | |
11 #include "ui/base/keycodes/keyboard_codes.h" | |
12 | |
13 //////////////////////////////////////////////////////////////////////////////// | |
14 // PasswordAutofillManager, public: | |
15 | |
16 PasswordAutofillManager::PasswordAutofillManager( | |
17 TabContentsWrapper* tab_contents_wrapper) | |
18 : tab_contents_wrapper_(tab_contents_wrapper) { | |
19 } | |
20 | |
21 PasswordAutofillManager::~PasswordAutofillManager() { | |
22 } | |
23 | |
24 bool PasswordAutofillManager::TextFieldHandlingKeyDown( | |
25 const webkit::forms::FormField& field, | |
26 int key_code) { | |
27 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | |
28 if (iter == login_to_password_info_.end()) | |
29 return false; | |
30 | |
31 if (tab_contents_wrapper_ && tab_contents_wrapper_->web_contents() && | |
32 tab_contents_wrapper_->web_contents()->GetRenderViewHost()) { | |
Ilya Sherman
2012/03/06 20:32:44
Hmm, can any of these actually ever be NULL?
csharp
2012/03/07 15:49:16
I don't think so, but I since I only use this to s
Ilya Sherman
2012/03/07 22:33:18
If the RenderViewHost remains constant for a TabCo
csharp
2012/03/08 16:48:37
Done.
| |
33 RenderViewHost* host = | |
34 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | |
35 host->Send(new AutofillMsg_PasswordHandleKeyDown(host->GetRoutingID(), | |
36 key_code)); | |
37 } | |
38 | |
39 iter->second.backspace_pressed_last = | |
40 (key_code == ui::VKEY_BACK || key_code == ui::VKEY_DELETE); | |
Ilya Sherman
2012/03/06 20:32:44
It looks like you're also doing this work on the r
csharp
2012/03/07 15:49:16
I had thought I still had code here that looked at
| |
41 | |
42 return true; | |
43 } | |
44 | |
45 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( | |
46 const webkit::forms::FormField& field, | |
47 const string16& value) { | |
48 webkit::forms::FormField input; | |
49 PasswordInfo password; | |
50 if (!FindLoginInfo(field, &input, &password)) | |
51 return false; | |
52 | |
53 if (WillFillUserNameAndPassword(input, password.fill_data)) { | |
54 if (tab_contents_wrapper_ && tab_contents_wrapper_->web_contents() && | |
55 tab_contents_wrapper_->web_contents()->GetRenderViewHost()) { | |
56 RenderViewHost* host = | |
57 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | |
58 host->Send(new AutofillMsg_PasswordAcceptAutofillSuggestion( | |
59 host->GetRoutingID(), | |
60 value)); | |
Ilya Sherman
2012/03/06 20:32:44
Why not send the full fill data here, rather than
csharp
2012/03/07 15:49:16
We kinda get the full fill data for free in the re
Ilya Sherman
2012/03/07 22:33:18
Hmm, it seems a little wrong to have both the brow
csharp
2012/03/08 16:48:37
Ok, so I think we can removed the duplicated data.
Ilya Sherman
2012/03/08 23:22:14
Ok, I think I better understand now why it's hard
| |
61 } | |
62 return true; | |
63 } | |
64 | |
65 return false; | |
66 } | |
67 | |
68 bool PasswordAutofillManager::DidSelectAutofillSuggestion( | |
69 const webkit::forms::FormField& field) { | |
70 webkit::forms::FormField input; | |
71 PasswordInfo password; | |
72 return FindLoginInfo(field, &input, &password); | |
73 } | |
74 | |
75 bool PasswordAutofillManager::DidClearAutofillSelection( | |
76 const webkit::forms::FormField& field) { | |
77 webkit::forms::FormField input; | |
78 PasswordInfo password; | |
79 return FindLoginInfo(field, &input, &password); | |
80 } | |
81 | |
82 void PasswordAutofillManager::FillPasswordForm( | |
83 const webkit::forms::FormField& username_element, | |
84 const webkit::forms::PasswordFormFillData& fill_data, | |
85 int frame_id) { | |
86 PasswordInfo password_info; | |
87 password_info.frame_id = frame_id; | |
88 password_info.fill_data = fill_data; | |
89 | |
90 login_to_password_info_[username_element] = password_info; | |
91 } | |
92 | |
93 void PasswordAutofillManager::FrameClosing(long long frame_id) { | |
94 for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin(); | |
95 iter != login_to_password_info_.end();) { | |
96 if (iter->second.frame_id == frame_id) | |
97 login_to_password_info_.erase(iter++); | |
98 else | |
99 ++iter; | |
100 } | |
Ilya Sherman
2012/03/06 20:32:44
Does anything go wrong if we just empty the map wh
csharp
2012/03/07 15:49:16
From my understanding of this code, I don't think
| |
101 } | |
102 | |
103 //////////////////////////////////////////////////////////////////////////////// | |
104 // PasswordAutofillManager, private: | |
105 | |
106 bool PasswordAutofillManager::WillFillUserNameAndPassword( | |
107 const webkit::forms::FormField& username_element, | |
108 const webkit::forms::PasswordFormFillData& fill_data) { | |
109 string16 current_username = username_element.value; | |
110 | |
111 // Look for any suitable matches to current field text. | |
112 if (fill_data.basic_data.fields[0].value == current_username) { | |
113 return true; | |
114 } else { | |
115 // Scan additional logins for a match. | |
116 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; | |
117 for (iter = fill_data.additional_logins.begin(); | |
118 iter != fill_data.additional_logins.end(); ++iter) { | |
119 if (iter->first == current_username) { | |
120 return true; | |
121 } | |
Ilya Sherman
2012/03/06 20:32:44
nit: The if-stmt body is 1 line, so no need for cu
csharp
2012/03/07 15:49:16
Done.
| |
122 } | |
123 } | |
124 | |
125 return false; | |
126 } | |
127 | |
128 bool PasswordAutofillManager::FindLoginInfo( | |
129 const webkit::forms::FormField& field, | |
130 webkit::forms::FormField* found_input, | |
131 PasswordInfo* found_password) { | |
132 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | |
133 if (iter == login_to_password_info_.end()) | |
134 return false; | |
135 | |
136 *found_input = field; | |
137 *found_password = iter->second; | |
138 return true; | |
139 } | |
OLD | NEW |