Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: components/autofill/content/renderer/autofill_agent.cc

Issue 148413002: Add "previewing on hover" support for single-field autocomplete input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Ilya's 2nd set comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) 143 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message)
144 IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled) 144 IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled)
145 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, 145 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable,
146 OnFieldTypePredictionsAvailable) 146 OnFieldTypePredictionsAvailable)
147 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill, 147 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill,
148 OnSetAutofillActionFill) 148 OnSetAutofillActionFill)
149 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm) 149 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm)
150 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, 150 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview,
151 OnSetAutofillActionPreview) 151 OnSetAutofillActionPreview)
152 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) 152 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm)
153 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, OnSetNodeText) 153 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue)
154 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue,
155 OnPreviewFieldWithValue)
154 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, 156 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
155 OnAcceptDataListSuggestion) 157 OnAcceptDataListSuggestion)
156 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, 158 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion,
157 OnAcceptPasswordAutofillSuggestion) 159 OnAcceptPasswordAutofillSuggestion)
158 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, 160 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult,
159 OnRequestAutocompleteResult) 161 OnRequestAutocompleteResult)
160 IPC_MESSAGE_HANDLER(AutofillMsg_PageShown, OnPageShown) 162 IPC_MESSAGE_HANDLER(AutofillMsg_PageShown, OnPageShown)
161 IPC_MESSAGE_UNHANDLED(handled = false) 163 IPC_MESSAGE_UNHANDLED(handled = false)
162 IPC_END_MESSAGE_MAP() 164 IPC_END_MESSAGE_MAP()
163 return handled; 165 return handled;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (!IsWhitespace(last_part[i])) { 387 if (!IsWhitespace(last_part[i])) {
386 last_part = last_part.substr(0, i); 388 last_part = last_part.substr(0, i);
387 break; 389 break;
388 } 390 }
389 } 391 }
390 last_part.append(suggested_value); 392 last_part.append(suggested_value);
391 parts[parts.size() - 1] = last_part; 393 parts[parts.size() - 1] = last_part;
392 394
393 new_value = JoinString(parts, ','); 395 new_value = JoinString(parts, ',');
394 } 396 }
395 SetNodeText(new_value, &element_); 397 FillFieldWithValue(new_value, &element_);
396 } 398 }
397 399
398 void AutofillAgent::OnFormDataFilled(int query_id, 400 void AutofillAgent::OnFormDataFilled(int query_id,
399 const FormData& form) { 401 const FormData& form) {
400 if (!render_view()->GetWebView() || query_id != autofill_query_id_) 402 if (!render_view()->GetWebView() || query_id != autofill_query_id_)
401 return; 403 return;
402 404
403 was_query_node_autofilled_ = element_.isAutofilled(); 405 was_query_node_autofilled_ = element_.isAutofilled();
404 406
405 switch (autofill_action_) { 407 switch (autofill_action_) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } else { 448 } else {
447 // TODO(isherman): There seem to be rare cases where this code *is* 449 // TODO(isherman): There seem to be rare cases where this code *is*
448 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would 450 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would
449 // understand those cases and fix the code to avoid them. However, so far I 451 // understand those cases and fix the code to avoid them. However, so far I
450 // have been unable to reproduce such a case locally. If you hit this 452 // have been unable to reproduce such a case locally. If you hit this
451 // NOTREACHED(), please file a bug against me. 453 // NOTREACHED(), please file a bug against me.
452 NOTREACHED(); 454 NOTREACHED();
453 } 455 }
454 } 456 }
455 457
456 void AutofillAgent::OnSetNodeText(const base::string16& value) { 458 void AutofillAgent::OnFillFieldWithValue(const base::string16& value) {
457 SetNodeText(value, &element_); 459 FillFieldWithValue(value, &element_);
460 }
461
462 void AutofillAgent::OnPreviewFieldWithValue(const base::string16& value) {
463 PreviewFieldWithValue(value, &element_);
Ilya Sherman 2014/03/01 02:57:37 nit: Why not just inline the code?
ziran.sun 2014/03/04 15:30:19 Sorry, which part code you are referring to?
458 } 464 }
459 465
460 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { 466 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) {
461 AcceptDataListSuggestion(value); 467 AcceptDataListSuggestion(value);
462 } 468 }
463 469
464 void AutofillAgent::OnAcceptPasswordAutofillSuggestion( 470 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(
465 const base::string16& username) { 471 const base::string16& username) {
466 // We need to make sure this is handled here because the browser process 472 // We need to make sure this is handled here because the browser process
467 // skipped it handling because it believed it would be handled here. If it 473 // skipped it handling because it believed it would be handled here. If it
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form, 609 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form,
604 &field, REQUIRE_AUTOCOMPLETE)) { 610 &field, REQUIRE_AUTOCOMPLETE)) {
605 return; 611 return;
606 } 612 }
607 613
608 autofill_action_ = action; 614 autofill_action_ = action;
609 Send(new AutofillHostMsg_FillAutofillFormData( 615 Send(new AutofillHostMsg_FillAutofillFormData(
610 routing_id(), autofill_query_id_, form, field, unique_id)); 616 routing_id(), autofill_query_id_, form, field, unique_id));
611 } 617 }
612 618
613 void AutofillAgent::SetNodeText(const base::string16& value, 619 void AutofillAgent::FillFieldWithValue(const base::string16& value,
614 blink::WebInputElement* node) { 620 blink::WebInputElement* node) {
615 did_set_node_text_ = true; 621 did_set_node_text_ = true;
616 node->setEditingValue(value.substr(0, node->maxLength())); 622 node->setEditingValue(value.substr(0, node->maxLength()));
617 } 623 }
618 624
625 void AutofillAgent::PreviewFieldWithValue(const base::string16& value,
626 blink::WebInputElement* node) {
627 was_query_node_autofilled_ = element_.isAutofilled();
628 node->setSuggestedValue(value.substr(0, node->maxLength()));
629 node->setAutofilled(true);
630 }
631
619 void AutofillAgent::HidePopup() { 632 void AutofillAgent::HidePopup() {
620 if (!is_popup_possibly_visible_) 633 if (!is_popup_possibly_visible_)
621 return; 634 return;
622 635
623 if (!element_.isNull()) 636 if (!element_.isNull())
624 OnClearPreviewedForm(); 637 OnClearPreviewedForm();
625 638
626 is_popup_possibly_visible_ = false; 639 is_popup_possibly_visible_ = false;
627 Send(new AutofillHostMsg_HidePopup(routing_id())); 640 Send(new AutofillHostMsg_HidePopup(routing_id()));
628 } 641 }
629 642
630 // TODO(isherman): Decide if we want to support non-password autofill with AJAX. 643 // TODO(isherman): Decide if we want to support non-password autofill with AJAX.
631 void AutofillAgent::didAssociateFormControls( 644 void AutofillAgent::didAssociateFormControls(
632 const blink::WebVector<blink::WebNode>& nodes) { 645 const blink::WebVector<blink::WebNode>& nodes) {
633 for (size_t i = 0; i < nodes.size(); ++i) { 646 for (size_t i = 0; i < nodes.size(); ++i) {
634 blink::WebFrame* frame = nodes[i].document().frame(); 647 blink::WebFrame* frame = nodes[i].document().frame();
635 // Only monitors dynamic forms created in the top frame. Dynamic forms 648 // Only monitors dynamic forms created in the top frame. Dynamic forms
636 // inserted in iframes are not captured yet. 649 // inserted in iframes are not captured yet.
637 if (!frame->parent()) { 650 if (!frame->parent()) {
638 password_autofill_agent_->OnDynamicFormsSeen(frame); 651 password_autofill_agent_->OnDynamicFormsSeen(frame);
639 return; 652 return;
640 } 653 }
641 } 654 }
642 } 655 }
643 656
644 } // namespace autofill 657 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698