| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 if (suggestions_clear_index_ != -1) | 172 if (suggestions_clear_index_ != -1) |
| 173 suggestions_clear_index_--; | 173 suggestions_clear_index_--; |
| 174 if (suggestions_options_index_ != -1) | 174 if (suggestions_options_index_ != -1) |
| 175 suggestions_options_index_--; | 175 suggestions_options_index_--; |
| 176 | 176 |
| 177 Send(new AutofillHostMsg_RemoveAutocompleteEntry(routing_id(), name, value)); | 177 Send(new AutofillHostMsg_RemoveAutocompleteEntry(routing_id(), name, value)); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { | 180 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
| 181 password_autofill_manager_->TextFieldDidEndEditing(element); | 181 password_autofill_manager_->TextFieldDidEndEditing(element); |
| 182 has_shown_autofill_popup_for_current_edit_ = false; |
| 182 } | 183 } |
| 183 | 184 |
| 184 void AutofillAgent::textFieldDidChange(const WebInputElement& element) { | 185 void AutofillAgent::textFieldDidChange(const WebInputElement& element) { |
| 185 // 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 |
| 186 // 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 |
| 187 // it is needed to trigger autofill. | 188 // it is needed to trigger autofill. |
| 188 method_factory_.RevokeAll(); | 189 method_factory_.RevokeAll(); |
| 189 MessageLoop::current()->PostTask( | 190 MessageLoop::current()->PostTask( |
| 190 FROM_HERE, | 191 FROM_HERE, |
| 191 method_factory_.NewRunnableMethod( | 192 method_factory_.NewRunnableMethod( |
| 192 &AutofillAgent::TextFieldDidChangeImpl, element)); | 193 &AutofillAgent::TextFieldDidChangeImpl, element)); |
| 193 } | 194 } |
| 194 | 195 |
| 195 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { | 196 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { |
| 196 if (password_autofill_manager_->TextDidChangeInTextField(element)) | 197 if (password_autofill_manager_->TextDidChangeInTextField(element)) |
| 197 return; | 198 return; |
| 198 | 199 |
| 199 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)); |
| 200 } | 206 } |
| 201 | 207 |
| 202 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, | 208 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, |
| 203 const WebKeyboardEvent& event) { | 209 const WebKeyboardEvent& event) { |
| 204 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) | 210 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) |
| 205 return; | 211 return; |
| 206 | 212 |
| 207 if (event.windowsKeyCode == ui::VKEY_DOWN || | 213 if (event.windowsKeyCode == ui::VKEY_DOWN || |
| 208 event.windowsKeyCode == ui::VKEY_UP) | 214 event.windowsKeyCode == ui::VKEY_UP) |
| 209 ShowSuggestions(element, true, true, true); | 215 ShowSuggestions(element, true, true, true); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 223 web_view->hidePopups(); | 229 web_view->hidePopups(); |
| 224 return; | 230 return; |
| 225 } | 231 } |
| 226 | 232 |
| 227 std::vector<string16> v(values); | 233 std::vector<string16> v(values); |
| 228 std::vector<string16> l(labels); | 234 std::vector<string16> l(labels); |
| 229 std::vector<string16> i(icons); | 235 std::vector<string16> i(icons); |
| 230 std::vector<int> ids(unique_ids); | 236 std::vector<int> ids(unique_ids); |
| 231 int separator_index = -1; | 237 int separator_index = -1; |
| 232 | 238 |
| 239 DCHECK_GT(ids.size(), 0U); |
| 233 if (!autofill_query_element_.isNull() && | 240 if (!autofill_query_element_.isNull() && |
| 234 !autofill_query_element_.autoComplete()) { | 241 !autofill_query_element_.autoComplete()) { |
| 235 // 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. |
| 236 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); | 243 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); |
| 237 l.assign(1, string16()); | 244 l.assign(1, string16()); |
| 238 i.assign(1, string16()); | 245 i.assign(1, string16()); |
| 239 ids.assign(1, -1); | 246 ids.assign(1, -1); |
| 240 } else if (ids[0] < 0 && ids.size() > 1) { | 247 } else if (ids[0] < 0 && ids.size() > 1) { |
| 241 // 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 |
| 242 // 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... |
| 283 separator_index = values.size(); | 290 separator_index = values.size(); |
| 284 } | 291 } |
| 285 | 292 |
| 286 // Send to WebKit for display. | 293 // Send to WebKit for display. |
| 287 if (!v.empty() && !autofill_query_element_.isNull() && | 294 if (!v.empty() && !autofill_query_element_.isNull() && |
| 288 autofill_query_element_.isFocusable()) { | 295 autofill_query_element_.isFocusable()) { |
| 289 web_view->applyAutofillSuggestions( | 296 web_view->applyAutofillSuggestions( |
| 290 autofill_query_element_, v, l, i, ids, separator_index); | 297 autofill_query_element_, v, l, i, ids, separator_index); |
| 291 } | 298 } |
| 292 | 299 |
| 293 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; |
| 294 } | 304 } |
| 295 | 305 |
| 296 void AutofillAgent::OnFormDataFilled(int query_id, | 306 void AutofillAgent::OnFormDataFilled(int query_id, |
| 297 const webkit_glue::FormData& form) { | 307 const webkit_glue::FormData& form) { |
| 298 if (!render_view()->webview() || query_id != autofill_query_id_) | 308 if (!render_view()->webview() || query_id != autofill_query_id_) |
| 299 return; | 309 return; |
| 300 | 310 |
| 301 switch (autofill_action_) { | 311 switch (autofill_action_) { |
| 302 case AUTOFILL_FILL: | 312 case AUTOFILL_FILL: |
| 303 form_manager_.FillForm(form, autofill_query_element_); | 313 form_manager_.FillForm(form, autofill_query_element_); |
| 314 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id())); |
| 304 break; | 315 break; |
| 305 case AUTOFILL_PREVIEW: | 316 case AUTOFILL_PREVIEW: |
| 306 form_manager_.PreviewForm(form, autofill_query_element_); | 317 form_manager_.PreviewForm(form, autofill_query_element_); |
| 318 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); |
| 307 break; | 319 break; |
| 308 default: | 320 default: |
| 309 NOTREACHED(); | 321 NOTREACHED(); |
| 310 } | 322 } |
| 311 autofill_action_ = AUTOFILL_NONE; | 323 autofill_action_ = AUTOFILL_NONE; |
| 312 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id())); | |
| 313 } | 324 } |
| 314 | 325 |
| 315 void AutofillAgent::OnFieldTypePredictionsAvailable( | 326 void AutofillAgent::OnFieldTypePredictionsAvailable( |
| 316 const std::vector<FormDataPredictions>& forms) { | 327 const std::vector<FormDataPredictions>& forms) { |
| 317 for (size_t i = 0; i < forms.size(); ++i) { | 328 for (size_t i = 0; i < forms.size(); ++i) { |
| 318 form_manager_.ShowPredictions(forms[i]); | 329 form_manager_.ShowPredictions(forms[i]); |
| 319 } | 330 } |
| 320 } | 331 } |
| 321 | 332 |
| 322 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... |
| 407 // WebFormControlElementToFormField does not scrape the DOM for the field | 418 // WebFormControlElementToFormField does not scrape the DOM for the field |
| 408 // label, so find the label here. | 419 // label, so find the label here. |
| 409 // 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 |
| 410 // data in FormManager. | 421 // data in FormManager. |
| 411 field->label = FormManager::LabelForElement(element); | 422 field->label = FormManager::LabelForElement(element); |
| 412 | 423 |
| 413 return true; | 424 return true; |
| 414 } | 425 } |
| 415 | 426 |
| 416 } // namespace autofill | 427 } // namespace autofill |
| OLD | NEW |