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 "chrome/renderer/autofill/autofill_agent.h" | 5 #include "chrome/renderer/autofill/autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { | 69 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { |
70 bool handled = true; | 70 bool handled = true; |
71 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) | 71 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) |
72 IPC_MESSAGE_HANDLER(AutofillMsg_SuggestionsReturned, OnSuggestionsReturned) | 72 IPC_MESSAGE_HANDLER(AutofillMsg_SuggestionsReturned, OnSuggestionsReturned) |
73 IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled) | 73 IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled) |
74 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, | 74 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, |
75 OnFieldTypePredictionsAvailable) | 75 OnFieldTypePredictionsAvailable) |
76 IPC_MESSAGE_HANDLER(AutofillMsg_SelectAutofillSuggestionAtIndex, | 76 IPC_MESSAGE_HANDLER(AutofillMsg_SelectAutofillSuggestionAtIndex, |
77 OnSelectAutofillSuggestionAtIndex) | 77 OnSelectAutofillSuggestionAtIndex) |
| 78 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill, |
| 79 OnSetAutofillActionFill) |
| 80 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, |
| 81 OnSetAutofillActionPreview) |
| 82 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, |
| 83 OnClearForm) |
| 84 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, |
| 85 OnSetNodeText) |
78 IPC_MESSAGE_UNHANDLED(handled = false) | 86 IPC_MESSAGE_UNHANDLED(handled = false) |
79 IPC_END_MESSAGE_MAP() | 87 IPC_END_MESSAGE_MAP() |
80 return handled; | 88 return handled; |
81 } | 89 } |
82 | 90 |
83 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { | 91 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { |
84 // The document has now been fully loaded. Scan for forms to be sent up to | 92 // The document has now been fully loaded. Scan for forms to be sent up to |
85 // the browser. | 93 // the browser. |
86 std::vector<webkit::forms::FormData> forms; | 94 std::vector<webkit::forms::FormData> forms; |
87 form_cache_.ExtractForms(*frame, &forms); | 95 form_cache_.ExtractForms(*frame, &forms); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 form_cache_.ShowPredictions(forms[i]); | 367 form_cache_.ShowPredictions(forms[i]); |
360 } | 368 } |
361 } | 369 } |
362 | 370 |
363 void AutofillAgent::OnSelectAutofillSuggestionAtIndex(int listIndex) { | 371 void AutofillAgent::OnSelectAutofillSuggestionAtIndex(int listIndex) { |
364 NOTIMPLEMENTED(); | 372 NOTIMPLEMENTED(); |
365 // TODO(jrg): enable once changes land in WebKit | 373 // TODO(jrg): enable once changes land in WebKit |
366 // render_view()->webview()->selectAutofillSuggestionAtIndex(listIndex); | 374 // render_view()->webview()->selectAutofillSuggestionAtIndex(listIndex); |
367 } | 375 } |
368 | 376 |
| 377 void AutofillAgent::OnSetAutofillActionFill() { |
| 378 autofill_action_ = AUTOFILL_FILL; |
| 379 } |
| 380 |
| 381 void AutofillAgent::OnSetAutofillActionPreview() { |
| 382 didClearAutofillSelection(autofill_query_element_); |
| 383 |
| 384 autofill_action_ = AUTOFILL_PREVIEW; |
| 385 } |
| 386 |
| 387 void AutofillAgent::OnClearForm() { |
| 388 // TODO add a check that we are clearing the correct element |
| 389 form_cache_.ClearFormWithElement(autofill_query_element_); |
| 390 } |
| 391 |
| 392 void AutofillAgent::OnSetNodeText(string16 value) { |
| 393 // TODO add a check that we are setting the correct element |
| 394 string16 substring = value; |
| 395 substring = substring.substr(0, autofill_query_element_.maxLength()); |
| 396 |
| 397 autofill_query_element_.setValue(value, true); |
| 398 } |
| 399 |
369 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 400 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
370 bool autofill_on_empty_values, | 401 bool autofill_on_empty_values, |
371 bool requires_caret_at_end, | 402 bool requires_caret_at_end, |
372 bool display_warning_if_disabled) { | 403 bool display_warning_if_disabled) { |
373 // If autocomplete is disabled at the form level, then we might want to show | 404 // If autocomplete is disabled at the form level, then we might want to show |
374 // a warning in place of suggestions. However, if autocomplete is disabled | 405 // a warning in place of suggestions. However, if autocomplete is disabled |
375 // specifically for this field, we never want to show a warning. Otherwise, | 406 // specifically for this field, we never want to show a warning. Otherwise, |
376 // we might interfere with custom popups (e.g. search suggestions) used by | 407 // we might interfere with custom popups (e.g. search suggestions) used by |
377 // the website. | 408 // the website. |
378 const WebFormElement form = element.form(); | 409 const WebFormElement form = element.form(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 return; | 472 return; |
442 } | 473 } |
443 | 474 |
444 autofill_action_ = action; | 475 autofill_action_ = action; |
445 was_query_node_autofilled_ = field.is_autofilled; | 476 was_query_node_autofilled_ = field.is_autofilled; |
446 Send(new AutofillHostMsg_FillAutofillFormData( | 477 Send(new AutofillHostMsg_FillAutofillFormData( |
447 routing_id(), autofill_query_id_, form, field, unique_id)); | 478 routing_id(), autofill_query_id_, form, field, unique_id)); |
448 } | 479 } |
449 | 480 |
450 } // namespace autofill | 481 } // namespace autofill |
OLD | NEW |