OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/browser/autofill/autofill_external_delegate.h" | 6 #include "chrome/browser/autofill/autofill_external_delegate.h" |
7 #include "chrome/browser/autofill/autofill_manager.h" | 7 #include "chrome/browser/autofill/autofill_manager.h" |
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
9 #include "chrome/common/autofill_messages.h" | 9 #include "chrome/common/autofill_messages.h" |
10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "grit/chromium_strings.h" | 13 #include "grit/chromium_strings.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 | 16 |
17 using content::RenderViewHost; | 17 using content::RenderViewHost; |
18 | 18 |
19 AutofillExternalDelegate::~AutofillExternalDelegate() { | 19 AutofillExternalDelegate::~AutofillExternalDelegate() { |
20 } | 20 } |
21 | 21 |
22 AutofillExternalDelegate::AutofillExternalDelegate( | 22 AutofillExternalDelegate::AutofillExternalDelegate( |
23 TabContentsWrapper* tab_contents_wrapper, | 23 TabContentsWrapper* tab_contents_wrapper, |
24 AutofillManager* autofill_manager) | 24 AutofillManager* autofill_manager) |
25 : tab_contents_wrapper_(tab_contents_wrapper), | 25 : tab_contents_wrapper_(tab_contents_wrapper), |
26 autofill_manager_(autofill_manager), | 26 autofill_manager_(autofill_manager), |
27 password_autofill_manager_( | |
28 tab_contents_wrapper->web_contents()->GetRenderViewHost()), | |
27 autofill_query_id_(0), | 29 autofill_query_id_(0), |
28 display_warning_if_disabled_(false), | 30 display_warning_if_disabled_(false), |
29 has_shown_autofill_popup_for_current_edit_(false), | 31 has_shown_autofill_popup_for_current_edit_(false), |
30 suggestions_clear_index_(-1), | 32 suggestions_clear_index_(-1), |
31 suggestions_options_index_(-1) { | 33 suggestions_options_index_(-1) { |
32 } | 34 } |
33 | 35 |
34 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, | 36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id, |
35 int list_index) { | 37 int list_index) { |
38 if (unique_id == kPasswordEntryIds) | |
39 return; | |
40 | |
36 if (list_index == suggestions_options_index_ || | 41 if (list_index == suggestions_options_index_ || |
37 list_index == suggestions_clear_index_ || | 42 list_index == suggestions_clear_index_ || |
38 unique_id == -1) | 43 unique_id == -1) |
39 return; | 44 return; |
40 | 45 |
41 FillAutofillFormData(unique_id, true); | 46 FillAutofillFormData(unique_id, true); |
42 } | 47 } |
43 | 48 |
44 void AutofillExternalDelegate::OnQuery(int query_id, | 49 void AutofillExternalDelegate::OnQuery(int query_id, |
45 const webkit::forms::FormData& form, | 50 const webkit::forms::FormData& form, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 | 134 |
130 // Send to display. | 135 // Send to display. |
131 if (!v.empty() && autofill_query_field_.is_focusable) | 136 if (!v.empty() && autofill_query_field_.is_focusable) |
132 ApplyAutofillSuggestions(v, l, i, ids, separator_index); | 137 ApplyAutofillSuggestions(v, l, i, ids, separator_index); |
133 | 138 |
134 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( | 139 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( |
135 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); | 140 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); |
136 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; | 141 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
137 } | 142 } |
138 | 143 |
144 void AutofillExternalDelegate::ShowPasswordSuggestions( | |
145 const std::vector<string16>& suggestions) { | |
146 if (suggestions.empty()) { | |
147 HideAutofillPopup(); | |
148 } | |
Ilya Sherman
2012/03/20 00:58:55
nit: No need for curly braces.
csharp
2012/03/21 14:10:31
Done.
| |
149 | |
150 std::vector<string16> empty; | |
151 std::vector<int> password_ids; | |
152 for (size_t i = 0; i < suggestions.size(); ++i) { | |
153 empty.push_back(string16()); | |
Ilya Sherman
2012/03/20 00:58:55
Hmm, why are the suggestions all empty?
csharp
2012/03/21 14:10:31
The suggestions still have values, it just the lab
Ilya Sherman
2012/03/22 01:20:06
Ah, sorry, misread the code. You could write this
| |
154 password_ids.push_back(kPasswordEntryIds); | |
155 } | |
156 | |
157 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids, -1); | |
158 } | |
159 | |
139 void AutofillExternalDelegate::DidEndTextFieldEditing() { | 160 void AutofillExternalDelegate::DidEndTextFieldEditing() { |
140 has_shown_autofill_popup_for_current_edit_ = false; | 161 has_shown_autofill_popup_for_current_edit_ = false; |
141 } | 162 } |
142 | 163 |
143 void AutofillExternalDelegate::DidAcceptAutofillSuggestions( | 164 void AutofillExternalDelegate::DidAcceptAutofillSuggestions( |
144 const string16& value, | 165 const string16& value, |
145 int unique_id, | 166 int unique_id, |
146 unsigned index) { | 167 unsigned index) { |
147 // If the selected element is a warning we don't want to do anything. | 168 // If the selected element is a warning we don't want to do anything. |
148 if (unique_id < 0) | 169 if (unique_id < 0 && unique_id != kPasswordEntryIds) |
149 return; | 170 return; |
150 | 171 |
151 // TODO(csharp): Add the password autofill manager. | 172 HideAutofillPopup(); |
152 // if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) | 173 |
153 // return; | 174 // TODO(csharp) Fix how password are handled so that FindLoginInfo works. |
csharp
2012/03/16 20:21:12
I think this will work in mostly cases right now.
Ilya Sherman
2012/03/20 00:58:55
It seems like this should work in all cases, but y
| |
175 if (unique_id == kPasswordEntryIds) { | |
176 // Accepting has been handled by the password manager. | |
177 return; | |
178 } | |
154 | 179 |
155 if (suggestions_options_index_ != -1 && | 180 if (suggestions_options_index_ != -1 && |
156 index == static_cast<unsigned>(suggestions_options_index_)) { | 181 index == static_cast<unsigned>(suggestions_options_index_)) { |
157 // User selected 'Autofill Options'. | 182 // User selected 'Autofill Options'. |
158 autofill_manager_->OnShowAutofillDialog(); | 183 autofill_manager_->OnShowAutofillDialog(); |
159 } else if (suggestions_clear_index_ != -1 && | 184 } else if (suggestions_clear_index_ != -1 && |
160 index == static_cast<unsigned>(suggestions_clear_index_)) { | 185 index == static_cast<unsigned>(suggestions_clear_index_)) { |
161 // User selected 'Clear form'. | 186 // User selected 'Clear form'. |
162 RenderViewHost* host = | 187 RenderViewHost* host = |
163 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 188 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
164 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); | 189 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); |
165 } else if (!unique_id) { | 190 } else if (!unique_id) { |
166 // User selected an Autocomplete entry, so we fill directly. | 191 // User selected an Autocomplete entry, so we fill directly. |
167 RenderViewHost* host = | 192 RenderViewHost* host = |
168 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 193 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
169 host->Send(new AutofillMsg_SetNodeText( | 194 host->Send(new AutofillMsg_SetNodeText( |
170 host->GetRoutingID(), | 195 host->GetRoutingID(), |
171 value)); | 196 value)); |
172 } else { | 197 } else { |
173 FillAutofillFormData(unique_id, false); | 198 FillAutofillFormData(unique_id, false); |
174 } | 199 } |
175 | |
176 HideAutofillPopup(); | |
177 } | 200 } |
178 | 201 |
179 void AutofillExternalDelegate::ClearPreviewedForm() { | 202 void AutofillExternalDelegate::ClearPreviewedForm() { |
203 if (password_autofill_manager_.DidClearAutofillSelection( | |
204 autofill_query_field_)) | |
205 return; | |
206 | |
180 RenderViewHost* host = | 207 RenderViewHost* host = |
181 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 208 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
182 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); | 209 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); |
183 } | 210 } |
184 | 211 |
185 void AutofillExternalDelegate::HideAutofillPopup() { | 212 void AutofillExternalDelegate::HideAutofillPopup() { |
186 suggestions_clear_index_ = -1; | 213 suggestions_clear_index_ = -1; |
187 suggestions_options_index_ = -1; | 214 suggestions_options_index_ = -1; |
188 | 215 |
189 HideAutofillPopupInternal(); | 216 HideAutofillPopupInternal(); |
190 } | 217 } |
191 | 218 |
219 void AutofillExternalDelegate::Reset() { | |
220 HideAutofillPopup(); | |
221 | |
222 password_autofill_manager_.Reset(); | |
223 } | |
224 | |
225 void AutofillExternalDelegate::AddPasswordFormMapping( | |
226 const webkit::forms::FormField& form, | |
227 const webkit::forms::PasswordFormFillData& fill_data) { | |
228 password_autofill_manager_.AddPasswordFormMapping(form, fill_data); | |
229 } | |
230 | |
192 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, | 231 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, |
193 bool is_preview) { | 232 bool is_preview) { |
194 RenderViewHost* host = | 233 RenderViewHost* host = |
195 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); | 234 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); |
196 | 235 |
197 if (is_preview) { | 236 if (is_preview) { |
198 host->Send(new AutofillMsg_SetAutofillActionPreview( | 237 host->Send(new AutofillMsg_SetAutofillActionPreview( |
199 host->GetRoutingID())); | 238 host->GetRoutingID())); |
200 } else { | 239 } else { |
201 host->Send(new AutofillMsg_SetAutofillActionFill( | 240 host->Send(new AutofillMsg_SetAutofillActionFill( |
(...skipping 12 matching lines...) Expand all Loading... | |
214 // none, so all platforms use the default. | 253 // none, so all platforms use the default. |
215 | 254 |
216 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) | 255 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) |
217 | 256 |
218 AutofillExternalDelegate* AutofillExternalDelegate::Create( | 257 AutofillExternalDelegate* AutofillExternalDelegate::Create( |
219 TabContentsWrapper*, AutofillManager*) { | 258 TabContentsWrapper*, AutofillManager*) { |
220 return NULL; | 259 return NULL; |
221 } | 260 } |
222 | 261 |
223 #endif | 262 #endif |
OLD | NEW |