Chromium Code Reviews| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 if (!IsWhitespace(last_part[i])) { | 384 if (!IsWhitespace(last_part[i])) { |
| 383 last_part = last_part.substr(0, i); | 385 last_part = last_part.substr(0, i); |
| 384 break; | 386 break; |
| 385 } | 387 } |
| 386 } | 388 } |
| 387 last_part.append(suggested_value); | 389 last_part.append(suggested_value); |
| 388 parts[parts.size() - 1] = last_part; | 390 parts[parts.size() - 1] = last_part; |
| 389 | 391 |
| 390 new_value = JoinString(parts, ','); | 392 new_value = JoinString(parts, ','); |
| 391 } | 393 } |
| 392 SetNodeText(new_value, &element_); | 394 FillFieldWithValue(new_value, &element_); |
| 393 } | 395 } |
| 394 | 396 |
| 395 void AutofillAgent::OnFieldTypePredictionsAvailable( | 397 void AutofillAgent::OnFieldTypePredictionsAvailable( |
| 396 const std::vector<FormDataPredictions>& forms) { | 398 const std::vector<FormDataPredictions>& forms) { |
| 397 for (size_t i = 0; i < forms.size(); ++i) { | 399 for (size_t i = 0; i < forms.size(); ++i) { |
| 398 form_cache_.ShowPredictions(forms[i]); | 400 form_cache_.ShowPredictions(forms[i]); |
| 399 } | 401 } |
| 400 } | 402 } |
| 401 | 403 |
| 402 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { | 404 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 431 } else { | 433 } else { |
| 432 // TODO(isherman): There seem to be rare cases where this code *is* | 434 // TODO(isherman): There seem to be rare cases where this code *is* |
| 433 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would | 435 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would |
| 434 // understand those cases and fix the code to avoid them. However, so far I | 436 // understand those cases and fix the code to avoid them. However, so far I |
| 435 // have been unable to reproduce such a case locally. If you hit this | 437 // have been unable to reproduce such a case locally. If you hit this |
| 436 // NOTREACHED(), please file a bug against me. | 438 // NOTREACHED(), please file a bug against me. |
| 437 NOTREACHED(); | 439 NOTREACHED(); |
| 438 } | 440 } |
| 439 } | 441 } |
| 440 | 442 |
| 441 void AutofillAgent::OnSetNodeText(const base::string16& value) { | 443 void AutofillAgent::OnFillFieldWithValue(const base::string16& value) { |
| 442 SetNodeText(value, &element_); | 444 FillFieldWithValue(value, &element_); |
| 445 } | |
| 446 | |
| 447 void AutofillAgent::OnPreviewFieldWithValue(const base::string16& value) { | |
| 448 PreviewFieldWithValue(value, &element_); | |
| 443 } | 449 } |
| 444 | 450 |
| 445 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { | 451 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { |
| 446 AcceptDataListSuggestion(value); | 452 AcceptDataListSuggestion(value); |
| 447 } | 453 } |
| 448 | 454 |
| 449 void AutofillAgent::OnAcceptPasswordAutofillSuggestion( | 455 void AutofillAgent::OnAcceptPasswordAutofillSuggestion( |
| 450 const base::string16& username) { | 456 const base::string16& username) { |
| 451 // We need to make sure this is handled here because the browser process | 457 // We need to make sure this is handled here because the browser process |
| 452 // skipped it handling because it believed it would be handled here. If it | 458 // 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... | |
| 565 data_list_labels)); | 571 data_list_labels)); |
| 566 | 572 |
| 567 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), | 573 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), |
| 568 autofill_query_id_, | 574 autofill_query_id_, |
| 569 form, | 575 form, |
| 570 field, | 576 field, |
| 571 bounding_box_scaled, | 577 bounding_box_scaled, |
| 572 display_warning_if_disabled)); | 578 display_warning_if_disabled)); |
| 573 } | 579 } |
| 574 | 580 |
| 575 void AutofillAgent::SetNodeText(const base::string16& value, | 581 void AutofillAgent::FillFieldWithValue(const base::string16& value, |
| 576 blink::WebInputElement* node) { | 582 blink::WebInputElement* node) { |
| 577 did_set_node_text_ = true; | 583 did_set_node_text_ = true; |
| 578 node->setEditingValue(value.substr(0, node->maxLength())); | 584 node->setEditingValue(value.substr(0, node->maxLength())); |
|
Ilya Sherman
2014/03/14 07:17:05
Let's call setAutofilled() here too, so that the y
ziran.sun
2014/03/14 13:50:57
Done.
| |
| 579 } | 585 } |
| 580 | 586 |
| 587 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, | |
| 588 blink::WebInputElement* node) { | |
| 589 was_query_node_autofilled_ = element_.isAutofilled(); | |
| 590 node->setSuggestedValue(value.substr(0, node->maxLength())); | |
| 591 node->setAutofilled(true); | |
| 592 } | |
| 593 | |
| 581 void AutofillAgent::HidePopup() { | 594 void AutofillAgent::HidePopup() { |
| 582 if (!is_popup_possibly_visible_) | 595 if (!is_popup_possibly_visible_) |
| 583 return; | 596 return; |
| 584 | 597 |
| 585 if (!element_.isNull()) | 598 if (!element_.isNull()) |
| 586 OnClearPreviewedForm(); | 599 OnClearPreviewedForm(); |
| 587 | 600 |
| 588 is_popup_possibly_visible_ = false; | 601 is_popup_possibly_visible_ = false; |
| 589 Send(new AutofillHostMsg_HidePopup(routing_id())); | 602 Send(new AutofillHostMsg_HidePopup(routing_id())); |
| 590 } | 603 } |
| 591 | 604 |
| 592 // TODO(isherman): Decide if we want to support non-password autofill with AJAX. | 605 // TODO(isherman): Decide if we want to support non-password autofill with AJAX. |
| 593 void AutofillAgent::didAssociateFormControls( | 606 void AutofillAgent::didAssociateFormControls( |
| 594 const blink::WebVector<blink::WebNode>& nodes) { | 607 const blink::WebVector<blink::WebNode>& nodes) { |
| 595 for (size_t i = 0; i < nodes.size(); ++i) { | 608 for (size_t i = 0; i < nodes.size(); ++i) { |
| 596 blink::WebFrame* frame = nodes[i].document().frame(); | 609 blink::WebFrame* frame = nodes[i].document().frame(); |
| 597 // Only monitors dynamic forms created in the top frame. Dynamic forms | 610 // Only monitors dynamic forms created in the top frame. Dynamic forms |
| 598 // inserted in iframes are not captured yet. | 611 // inserted in iframes are not captured yet. |
| 599 if (!frame->parent()) { | 612 if (!frame->parent()) { |
| 600 password_autofill_agent_->OnDynamicFormsSeen(frame); | 613 password_autofill_agent_->OnDynamicFormsSeen(frame); |
| 601 return; | 614 return; |
| 602 } | 615 } |
| 603 } | 616 } |
| 604 } | 617 } |
| 605 | 618 |
| 606 } // namespace autofill | 619 } // namespace autofill |
| OLD | NEW |