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

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: Update code as per review comments Created 6 years, 10 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_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled) 143 IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled)
144 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, 144 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable,
145 OnFieldTypePredictionsAvailable) 145 OnFieldTypePredictionsAvailable)
146 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill, 146 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill,
147 OnSetAutofillActionFill) 147 OnSetAutofillActionFill)
148 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm) 148 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm)
149 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, 149 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview,
150 OnSetAutofillActionPreview) 150 OnSetAutofillActionPreview)
151 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm) 151 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm)
152 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, OnSetNodeText) 152 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, OnSetNodeText)
153 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewAutoCompleteNode,
154 OnPreviewAutoCompleteNode)
153 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, 155 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
154 OnAcceptDataListSuggestion) 156 OnAcceptDataListSuggestion)
155 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, 157 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion,
156 OnAcceptPasswordAutofillSuggestion) 158 OnAcceptPasswordAutofillSuggestion)
157 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, 159 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult,
158 OnRequestAutocompleteResult) 160 OnRequestAutocompleteResult)
159 IPC_MESSAGE_HANDLER(AutofillMsg_PageShown, OnPageShown) 161 IPC_MESSAGE_HANDLER(AutofillMsg_PageShown, OnPageShown)
160 IPC_MESSAGE_UNHANDLED(handled = false) 162 IPC_MESSAGE_UNHANDLED(handled = false)
161 IPC_END_MESSAGE_MAP() 163 IPC_END_MESSAGE_MAP()
162 return handled; 164 return handled;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 void AutofillAgent::OnSetAutofillActionPreview() { 437 void AutofillAgent::OnSetAutofillActionPreview() {
436 autofill_action_ = AUTOFILL_PREVIEW; 438 autofill_action_ = AUTOFILL_PREVIEW;
437 } 439 }
438 440
439 void AutofillAgent::OnClearPreviewedForm() { 441 void AutofillAgent::OnClearPreviewedForm() {
440 if (!element_.isNull()) { 442 if (!element_.isNull()) {
441 if (password_autofill_agent_->DidClearAutofillSelection(element_)) 443 if (password_autofill_agent_->DidClearAutofillSelection(element_))
442 return; 444 return;
443 445
444 ClearPreviewedFormWithElement(element_, was_query_node_autofilled_); 446 ClearPreviewedFormWithElement(element_, was_query_node_autofilled_);
447 element_.setSuggestedValue(WebString());
Ilya Sherman 2014/02/22 05:59:51 Hmm, is this line actually necessary? It seems li
ziran.sun 2014/02/27 15:38:11 Done.
445 } else { 448 } else {
446 // 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*
447 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would 450 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would
448 // 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
449 // 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
450 // NOTREACHED(), please file a bug against me. 453 // NOTREACHED(), please file a bug against me.
451 NOTREACHED(); 454 NOTREACHED();
452 } 455 }
453 } 456 }
454 457
455 void AutofillAgent::OnSetNodeText(const base::string16& value) { 458 void AutofillAgent::OnSetNodeText(const base::string16& value) {
456 SetNodeText(value, &element_); 459 SetNodeText(value, &element_);
457 } 460 }
458 461
462 void AutofillAgent::OnPreviewAutoCompleteNode(const base::string16& value) {
463 PreviewAutoCompleteNode(value, &element_);
Ilya Sherman 2014/02/22 05:59:51 nit: Why not just inline the implementation here?
ziran.sun 2014/02/27 15:38:11 Done.
464 }
465
459 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { 466 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) {
460 AcceptDataListSuggestion(value); 467 AcceptDataListSuggestion(value);
461 } 468 }
462 469
463 void AutofillAgent::OnAcceptPasswordAutofillSuggestion( 470 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(
464 const base::string16& username) { 471 const base::string16& username) {
465 // 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
466 // 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
467 // isn't handled here then the browser logic needs to be updated. 474 // isn't handled here then the browser logic needs to be updated.
468 bool handled = password_autofill_agent_->DidAcceptAutofillSuggestion( 475 bool handled = password_autofill_agent_->DidAcceptAutofillSuggestion(
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 615
609 void AutofillAgent::SetNodeText(const base::string16& value, 616 void AutofillAgent::SetNodeText(const base::string16& value,
610 blink::WebInputElement* node) { 617 blink::WebInputElement* node) {
611 did_set_node_text_ = true; 618 did_set_node_text_ = true;
612 base::string16 substring = value; 619 base::string16 substring = value;
613 substring = substring.substr(0, node->maxLength()); 620 substring = substring.substr(0, node->maxLength());
614 621
615 node->setEditingValue(substring); 622 node->setEditingValue(substring);
616 } 623 }
617 624
625 void AutofillAgent::PreviewAutoCompleteNode(const base::string16& value,
626 blink::WebInputElement* node) {
627 base::string16 substring = value;
628 substring = substring.substr(0, node->maxLength());
629
630 node->setSuggestedValue(substring);
Ilya Sherman 2014/02/22 05:59:51 You should also set was_query_node_autofilled_
Ilya Sherman 2014/02/22 05:59:51 Wow, the method you're cribbing from was needlessl
ziran.sun 2014/02/27 15:38:11 Done.
631 }
632
618 void AutofillAgent::HideAutofillUI() { 633 void AutofillAgent::HideAutofillUI() {
619 if (!element_.isNull()) 634 if (!element_.isNull())
620 OnClearPreviewedForm(); 635 OnClearPreviewedForm();
621 636
622 Send(new AutofillHostMsg_HideAutofillUI(routing_id())); 637 Send(new AutofillHostMsg_HideAutofillUI(routing_id()));
623 } 638 }
624 639
625 // TODO(isherman): Decide if we want to support non-password autofill with AJAX. 640 // TODO(isherman): Decide if we want to support non-password autofill with AJAX.
626 void AutofillAgent::didAssociateFormControls( 641 void AutofillAgent::didAssociateFormControls(
627 const blink::WebVector<blink::WebNode>& nodes) { 642 const blink::WebVector<blink::WebNode>& nodes) {
628 for (size_t i = 0; i < nodes.size(); ++i) { 643 for (size_t i = 0; i < nodes.size(); ++i) {
629 blink::WebFrame* frame = nodes[i].document().frame(); 644 blink::WebFrame* frame = nodes[i].document().frame();
630 // Only monitors dynamic forms created in the top frame. Dynamic forms 645 // Only monitors dynamic forms created in the top frame. Dynamic forms
631 // inserted in iframes are not captured yet. 646 // inserted in iframes are not captured yet.
632 if (!frame->parent()) { 647 if (!frame->parent()) {
633 password_autofill_agent_->OnDynamicFormsSeen(frame); 648 password_autofill_agent_->OnDynamicFormsSeen(frame);
634 return; 649 return;
635 } 650 }
636 } 651 }
637 } 652 }
638 653
639 } // namespace autofill 654 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698