OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/renderer/autofill_agent.h" | 5 #include "components/autofill/content/renderer/autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { | 142 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { |
143 bool handled = true; | 143 bool handled = true; |
144 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) | 144 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) |
145 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm) | 145 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm) |
146 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm) | 146 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm) |
147 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, | 147 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, |
148 OnFieldTypePredictionsAvailable) | 148 OnFieldTypePredictionsAvailable) |
149 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm) | 149 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm) |
150 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) | 150 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) |
151 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, OnSetNodeText) | 151 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue) |
| 152 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue, |
| 153 OnPreviewFieldWithValue) |
152 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, | 154 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, |
153 OnAcceptDataListSuggestion) | 155 OnAcceptDataListSuggestion) |
154 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, | 156 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, |
155 OnAcceptPasswordAutofillSuggestion) | 157 OnAcceptPasswordAutofillSuggestion) |
156 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, | 158 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, |
157 OnRequestAutocompleteResult) | 159 OnRequestAutocompleteResult) |
158 IPC_MESSAGE_UNHANDLED(handled = false) | 160 IPC_MESSAGE_UNHANDLED(handled = false) |
159 IPC_END_MESSAGE_MAP() | 161 IPC_END_MESSAGE_MAP() |
160 return handled; | 162 return handled; |
161 } | 163 } |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 if (!IsWhitespace(last_part[i])) { | 379 if (!IsWhitespace(last_part[i])) { |
378 last_part = last_part.substr(0, i); | 380 last_part = last_part.substr(0, i); |
379 break; | 381 break; |
380 } | 382 } |
381 } | 383 } |
382 last_part.append(suggested_value); | 384 last_part.append(suggested_value); |
383 parts[parts.size() - 1] = last_part; | 385 parts[parts.size() - 1] = last_part; |
384 | 386 |
385 new_value = JoinString(parts, ','); | 387 new_value = JoinString(parts, ','); |
386 } | 388 } |
387 SetNodeText(new_value, &element_); | 389 FillFieldWithValue(new_value, &element_); |
388 } | 390 } |
389 | 391 |
390 void AutofillAgent::OnFieldTypePredictionsAvailable( | 392 void AutofillAgent::OnFieldTypePredictionsAvailable( |
391 const std::vector<FormDataPredictions>& forms) { | 393 const std::vector<FormDataPredictions>& forms) { |
392 for (size_t i = 0; i < forms.size(); ++i) { | 394 for (size_t i = 0; i < forms.size(); ++i) { |
393 form_cache_.ShowPredictions(forms[i]); | 395 form_cache_.ShowPredictions(forms[i]); |
394 } | 396 } |
395 } | 397 } |
396 | 398 |
397 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { | 399 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { |
(...skipping 28 matching lines...) Expand all Loading... |
426 } else { | 428 } else { |
427 // TODO(isherman): There seem to be rare cases where this code *is* | 429 // TODO(isherman): There seem to be rare cases where this code *is* |
428 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would | 430 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would |
429 // understand those cases and fix the code to avoid them. However, so far I | 431 // understand those cases and fix the code to avoid them. However, so far I |
430 // have been unable to reproduce such a case locally. If you hit this | 432 // have been unable to reproduce such a case locally. If you hit this |
431 // NOTREACHED(), please file a bug against me. | 433 // NOTREACHED(), please file a bug against me. |
432 NOTREACHED(); | 434 NOTREACHED(); |
433 } | 435 } |
434 } | 436 } |
435 | 437 |
436 void AutofillAgent::OnSetNodeText(const base::string16& value) { | 438 void AutofillAgent::OnFillFieldWithValue(const base::string16& value) { |
437 SetNodeText(value, &element_); | 439 FillFieldWithValue(value, &element_); |
| 440 } |
| 441 |
| 442 void AutofillAgent::OnPreviewFieldWithValue(const base::string16& value) { |
| 443 PreviewFieldWithValue(value, &element_); |
438 } | 444 } |
439 | 445 |
440 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { | 446 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { |
441 AcceptDataListSuggestion(value); | 447 AcceptDataListSuggestion(value); |
442 } | 448 } |
443 | 449 |
444 void AutofillAgent::OnAcceptPasswordAutofillSuggestion( | 450 void AutofillAgent::OnAcceptPasswordAutofillSuggestion( |
445 const base::string16& username) { | 451 const base::string16& username) { |
446 // We need to make sure this is handled here because the browser process | 452 // We need to make sure this is handled here because the browser process |
447 // skipped it handling because it believed it would be handled here. If it | 453 // skipped it handling because it believed it would be handled here. If it |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 data_list_labels)); | 566 data_list_labels)); |
561 | 567 |
562 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), | 568 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), |
563 autofill_query_id_, | 569 autofill_query_id_, |
564 form, | 570 form, |
565 field, | 571 field, |
566 bounding_box_scaled, | 572 bounding_box_scaled, |
567 display_warning_if_disabled)); | 573 display_warning_if_disabled)); |
568 } | 574 } |
569 | 575 |
570 void AutofillAgent::SetNodeText(const base::string16& value, | 576 void AutofillAgent::FillFieldWithValue(const base::string16& value, |
571 blink::WebInputElement* node) { | 577 blink::WebInputElement* node) { |
572 did_set_node_text_ = true; | 578 did_set_node_text_ = true; |
573 node->setEditingValue(value.substr(0, node->maxLength())); | 579 node->setEditingValue(value.substr(0, node->maxLength())); |
| 580 node->setAutofilled(true); |
| 581 } |
| 582 |
| 583 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, |
| 584 blink::WebInputElement* node) { |
| 585 was_query_node_autofilled_ = element_.isAutofilled(); |
| 586 node->setSuggestedValue(value.substr(0, node->maxLength())); |
| 587 node->setAutofilled(true); |
574 } | 588 } |
575 | 589 |
576 void AutofillAgent::HidePopup() { | 590 void AutofillAgent::HidePopup() { |
577 if (!is_popup_possibly_visible_) | 591 if (!is_popup_possibly_visible_) |
578 return; | 592 return; |
579 | 593 |
580 if (!element_.isNull()) | 594 if (!element_.isNull()) |
581 OnClearPreviewedForm(); | 595 OnClearPreviewedForm(); |
582 | 596 |
583 is_popup_possibly_visible_ = false; | 597 is_popup_possibly_visible_ = false; |
584 Send(new AutofillHostMsg_HidePopup(routing_id())); | 598 Send(new AutofillHostMsg_HidePopup(routing_id())); |
585 } | 599 } |
586 | 600 |
587 // TODO(isherman): Decide if we want to support non-password autofill with AJAX. | 601 // TODO(isherman): Decide if we want to support non-password autofill with AJAX. |
588 void AutofillAgent::didAssociateFormControls( | 602 void AutofillAgent::didAssociateFormControls( |
589 const blink::WebVector<blink::WebNode>& nodes) { | 603 const blink::WebVector<blink::WebNode>& nodes) { |
590 for (size_t i = 0; i < nodes.size(); ++i) { | 604 for (size_t i = 0; i < nodes.size(); ++i) { |
591 blink::WebFrame* frame = nodes[i].document().frame(); | 605 blink::WebFrame* frame = nodes[i].document().frame(); |
592 // Only monitors dynamic forms created in the top frame. Dynamic forms | 606 // Only monitors dynamic forms created in the top frame. Dynamic forms |
593 // inserted in iframes are not captured yet. | 607 // inserted in iframes are not captured yet. |
594 if (frame && !frame->parent()) { | 608 if (frame && !frame->parent()) { |
595 password_autofill_agent_->OnDynamicFormsSeen(frame); | 609 password_autofill_agent_->OnDynamicFormsSeen(frame); |
596 return; | 610 return; |
597 } | 611 } |
598 } | 612 } |
599 } | 613 } |
600 | 614 |
601 } // namespace autofill | 615 } // namespace autofill |
OLD | NEW |