OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/autofill/autofill_agent.h" | 5 #include "chrome/renderer/autofill/autofill_agent.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.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" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 index == static_cast<unsigned>(suggestions_clear_index_)) { | 134 index == static_cast<unsigned>(suggestions_clear_index_)) { |
135 // User selected 'Clear form'. | 135 // User selected 'Clear form'. |
136 form_manager_.ClearFormWithNode(node); | 136 form_manager_.ClearFormWithNode(node); |
137 } else if (!unique_id) { | 137 } else if (!unique_id) { |
138 // User selected an Autocomplete entry, so we fill directly. | 138 // User selected an Autocomplete entry, so we fill directly. |
139 WebInputElement element = node.toConst<WebInputElement>(); | 139 WebInputElement element = node.toConst<WebInputElement>(); |
140 | 140 |
141 string16 substring = value; | 141 string16 substring = value; |
142 substring = substring.substr(0, element.maxLength()); | 142 substring = substring.substr(0, element.maxLength()); |
143 element.setValue(substring, true); | 143 element.setValue(substring, true); |
144 | |
145 WebFrame* webframe = node.document().frame(); | |
146 if (webframe) | |
147 webframe->notifiyPasswordListenerOfAutocomplete(element); | |
148 } else { | 144 } else { |
149 // Fill the values for the whole form. | 145 // Fill the values for the whole form. |
150 FillAutofillFormData(node, unique_id, AUTOFILL_FILL); | 146 FillAutofillFormData(node, unique_id, AUTOFILL_FILL); |
151 } | 147 } |
152 | 148 |
153 suggestions_clear_index_ = -1; | 149 suggestions_clear_index_ = -1; |
154 suggestions_options_index_ = -1; | 150 suggestions_options_index_ = -1; |
155 } | 151 } |
156 | 152 |
157 void AutofillAgent::didSelectAutofillSuggestion(const WebNode& node, | 153 void AutofillAgent::didSelectAutofillSuggestion(const WebNode& node, |
(...skipping 18 matching lines...) Expand all Loading... |
176 if (suggestions_clear_index_ != -1) | 172 if (suggestions_clear_index_ != -1) |
177 suggestions_clear_index_--; | 173 suggestions_clear_index_--; |
178 if (suggestions_options_index_ != -1) | 174 if (suggestions_options_index_ != -1) |
179 suggestions_options_index_--; | 175 suggestions_options_index_--; |
180 | 176 |
181 Send(new AutofillHostMsg_RemoveAutocompleteEntry(routing_id(), name, value)); | 177 Send(new AutofillHostMsg_RemoveAutocompleteEntry(routing_id(), name, value)); |
182 } | 178 } |
183 | 179 |
184 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { | 180 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
185 password_autofill_manager_->TextFieldDidEndEditing(element); | 181 password_autofill_manager_->TextFieldDidEndEditing(element); |
| 182 has_shown_autofill_popup_for_current_edit_ = false; |
186 } | 183 } |
187 | 184 |
188 void AutofillAgent::textFieldDidChange(const WebInputElement& element) { | 185 void AutofillAgent::textFieldDidChange(const WebInputElement& element) { |
189 // We post a task for doing the Autofill as the caret position is not set | 186 // We post a task for doing the Autofill as the caret position is not set |
190 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and | 187 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and |
191 // it is needed to trigger autofill. | 188 // it is needed to trigger autofill. |
192 method_factory_.RevokeAll(); | 189 method_factory_.RevokeAll(); |
193 MessageLoop::current()->PostTask( | 190 MessageLoop::current()->PostTask( |
194 FROM_HERE, | 191 FROM_HERE, |
195 method_factory_.NewRunnableMethod( | 192 method_factory_.NewRunnableMethod( |
196 &AutofillAgent::TextFieldDidChangeImpl, element)); | 193 &AutofillAgent::TextFieldDidChangeImpl, element)); |
197 } | 194 } |
198 | 195 |
199 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { | 196 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { |
200 if (password_autofill_manager_->TextDidChangeInTextField(element)) | 197 if (password_autofill_manager_->TextDidChangeInTextField(element)) |
201 return; | 198 return; |
202 | 199 |
203 ShowSuggestions(element, false, true, false); | 200 ShowSuggestions(element, false, true, false); |
| 201 |
| 202 webkit_glue::FormData form; |
| 203 webkit_glue::FormField field; |
| 204 if (FindFormAndFieldForNode(element, &form, &field)) |
| 205 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field)); |
204 } | 206 } |
205 | 207 |
206 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, | 208 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, |
207 const WebKeyboardEvent& event) { | 209 const WebKeyboardEvent& event) { |
208 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) | 210 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) |
209 return; | 211 return; |
210 | 212 |
211 if (event.windowsKeyCode == ui::VKEY_DOWN || | 213 if (event.windowsKeyCode == ui::VKEY_DOWN || |
212 event.windowsKeyCode == ui::VKEY_UP) | 214 event.windowsKeyCode == ui::VKEY_UP) |
213 ShowSuggestions(element, true, true, true); | 215 ShowSuggestions(element, true, true, true); |
(...skipping 13 matching lines...) Expand all Loading... |
227 web_view->hidePopups(); | 229 web_view->hidePopups(); |
228 return; | 230 return; |
229 } | 231 } |
230 | 232 |
231 std::vector<string16> v(values); | 233 std::vector<string16> v(values); |
232 std::vector<string16> l(labels); | 234 std::vector<string16> l(labels); |
233 std::vector<string16> i(icons); | 235 std::vector<string16> i(icons); |
234 std::vector<int> ids(unique_ids); | 236 std::vector<int> ids(unique_ids); |
235 int separator_index = -1; | 237 int separator_index = -1; |
236 | 238 |
| 239 DCHECK_GT(ids.size(), 0U); |
237 if (!autofill_query_element_.isNull() && | 240 if (!autofill_query_element_.isNull() && |
238 !autofill_query_element_.autoComplete()) { | 241 !autofill_query_element_.autoComplete()) { |
239 // If autofill is disabled and we had suggestions, show a warning instead. | 242 // If autofill is disabled and we had suggestions, show a warning instead. |
240 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); | 243 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); |
241 l.assign(1, string16()); | 244 l.assign(1, string16()); |
242 i.assign(1, string16()); | 245 i.assign(1, string16()); |
243 ids.assign(1, -1); | 246 ids.assign(1, -1); |
244 } else if (ids[0] < 0 && ids.size() > 1) { | 247 } else if (ids[0] < 0 && ids.size() > 1) { |
245 // If we received a warning instead of suggestions from autofill but regular | 248 // If we received a warning instead of suggestions from autofill but regular |
246 // suggestions from autocomplete, don't show the autofill warning. | 249 // suggestions from autocomplete, don't show the autofill warning. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 separator_index = values.size(); | 290 separator_index = values.size(); |
288 } | 291 } |
289 | 292 |
290 // Send to WebKit for display. | 293 // Send to WebKit for display. |
291 if (!v.empty() && !autofill_query_element_.isNull() && | 294 if (!v.empty() && !autofill_query_element_.isNull() && |
292 autofill_query_element_.isFocusable()) { | 295 autofill_query_element_.isFocusable()) { |
293 web_view->applyAutofillSuggestions( | 296 web_view->applyAutofillSuggestions( |
294 autofill_query_element_, v, l, i, ids, separator_index); | 297 autofill_query_element_, v, l, i, ids, separator_index); |
295 } | 298 } |
296 | 299 |
297 Send(new AutofillHostMsg_DidShowAutofillSuggestions(routing_id())); | 300 Send(new AutofillHostMsg_DidShowAutofillSuggestions( |
| 301 routing_id(), |
| 302 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); |
| 303 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
298 } | 304 } |
299 | 305 |
300 void AutofillAgent::OnFormDataFilled(int query_id, | 306 void AutofillAgent::OnFormDataFilled(int query_id, |
301 const webkit_glue::FormData& form) { | 307 const webkit_glue::FormData& form) { |
302 if (!render_view()->webview() || query_id != autofill_query_id_) | 308 if (!render_view()->webview() || query_id != autofill_query_id_) |
303 return; | 309 return; |
304 | 310 |
305 switch (autofill_action_) { | 311 switch (autofill_action_) { |
306 case AUTOFILL_FILL: | 312 case AUTOFILL_FILL: |
307 form_manager_.FillForm(form, autofill_query_element_); | 313 form_manager_.FillForm(form, autofill_query_element_); |
| 314 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id())); |
308 break; | 315 break; |
309 case AUTOFILL_PREVIEW: | 316 case AUTOFILL_PREVIEW: |
310 form_manager_.PreviewForm(form, autofill_query_element_); | 317 form_manager_.PreviewForm(form, autofill_query_element_); |
| 318 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); |
311 break; | 319 break; |
312 default: | 320 default: |
313 NOTREACHED(); | 321 NOTREACHED(); |
314 } | 322 } |
315 autofill_action_ = AUTOFILL_NONE; | 323 autofill_action_ = AUTOFILL_NONE; |
316 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id())); | |
317 } | 324 } |
318 | 325 |
319 void AutofillAgent::OnFieldTypePredictionsAvailable( | 326 void AutofillAgent::OnFieldTypePredictionsAvailable( |
320 const std::vector<FormDataPredictions>& forms) { | 327 const std::vector<FormDataPredictions>& forms) { |
321 for (size_t i = 0; i < forms.size(); ++i) { | 328 for (size_t i = 0; i < forms.size(); ++i) { |
322 form_manager_.ShowPredictions(forms[i]); | 329 form_manager_.ShowPredictions(forms[i]); |
323 } | 330 } |
324 } | 331 } |
325 | 332 |
326 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 333 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 // WebFormControlElementToFormField does not scrape the DOM for the field | 418 // WebFormControlElementToFormField does not scrape the DOM for the field |
412 // label, so find the label here. | 419 // label, so find the label here. |
413 // TODO(isherman): Add form and field identities so we can use the cached form | 420 // TODO(isherman): Add form and field identities so we can use the cached form |
414 // data in FormManager. | 421 // data in FormManager. |
415 field->label = FormManager::LabelForElement(element); | 422 field->label = FormManager::LabelForElement(element); |
416 | 423 |
417 return true; | 424 return true; |
418 } | 425 } |
419 | 426 |
420 } // namespace autofill | 427 } // namespace autofill |
OLD | NEW |