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

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

Issue 1026493002: Allow only a user gesture to trigger autofill popup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keep IME behavior. Created 5 years, 8 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/auto_reset.h"
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "components/autofill/content/common/autofill_messages.h" 15 #include "components/autofill/content/common/autofill_messages.h"
15 #include "components/autofill/content/renderer/form_autofill_util.h" 16 #include "components/autofill/content/renderer/form_autofill_util.h"
16 #include "components/autofill/content/renderer/page_click_tracker.h" 17 #include "components/autofill/content/renderer/page_click_tracker.h"
(...skipping 19 matching lines...) Expand all
36 #include "third_party/WebKit/public/web/WebDataSource.h" 37 #include "third_party/WebKit/public/web/WebDataSource.h"
37 #include "third_party/WebKit/public/web/WebDocument.h" 38 #include "third_party/WebKit/public/web/WebDocument.h"
38 #include "third_party/WebKit/public/web/WebElementCollection.h" 39 #include "third_party/WebKit/public/web/WebElementCollection.h"
39 #include "third_party/WebKit/public/web/WebFormControlElement.h" 40 #include "third_party/WebKit/public/web/WebFormControlElement.h"
40 #include "third_party/WebKit/public/web/WebFormElement.h" 41 #include "third_party/WebKit/public/web/WebFormElement.h"
41 #include "third_party/WebKit/public/web/WebInputEvent.h" 42 #include "third_party/WebKit/public/web/WebInputEvent.h"
42 #include "third_party/WebKit/public/web/WebLocalFrame.h" 43 #include "third_party/WebKit/public/web/WebLocalFrame.h"
43 #include "third_party/WebKit/public/web/WebNode.h" 44 #include "third_party/WebKit/public/web/WebNode.h"
44 #include "third_party/WebKit/public/web/WebOptionElement.h" 45 #include "third_party/WebKit/public/web/WebOptionElement.h"
45 #include "third_party/WebKit/public/web/WebTextAreaElement.h" 46 #include "third_party/WebKit/public/web/WebTextAreaElement.h"
47 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
46 #include "third_party/WebKit/public/web/WebView.h" 48 #include "third_party/WebKit/public/web/WebView.h"
47 #include "ui/base/l10n/l10n_util.h" 49 #include "ui/base/l10n/l10n_util.h"
48 #include "ui/events/keycodes/keyboard_codes.h" 50 #include "ui/events/keycodes/keyboard_codes.h"
49 51
50 using blink::WebAutofillClient; 52 using blink::WebAutofillClient;
51 using blink::WebConsoleMessage; 53 using blink::WebConsoleMessage;
52 using blink::WebDocument; 54 using blink::WebDocument;
53 using blink::WebElement; 55 using blink::WebElement;
54 using blink::WebElementCollection; 56 using blink::WebElementCollection;
55 using blink::WebFormControlElement; 57 using blink::WebFormControlElement;
56 using blink::WebFormElement; 58 using blink::WebFormElement;
57 using blink::WebFrame; 59 using blink::WebFrame;
58 using blink::WebInputElement; 60 using blink::WebInputElement;
59 using blink::WebKeyboardEvent; 61 using blink::WebKeyboardEvent;
60 using blink::WebLocalFrame; 62 using blink::WebLocalFrame;
61 using blink::WebNode; 63 using blink::WebNode;
62 using blink::WebOptionElement; 64 using blink::WebOptionElement;
63 using blink::WebString; 65 using blink::WebString;
64 using blink::WebTextAreaElement; 66 using blink::WebTextAreaElement;
67 using blink::WebUserGestureIndicator;
65 using blink::WebVector; 68 using blink::WebVector;
66 69
67 namespace autofill { 70 namespace autofill {
68 71
69 namespace { 72 namespace {
70 73
71 // Gets all the data list values (with corresponding label) for the given 74 // Gets all the data list values (with corresponding label) for the given
72 // element. 75 // element.
73 void GetDataListSuggestions(const WebInputElement& element, 76 void GetDataListSuggestions(const WebInputElement& element,
74 bool ignore_current_value, 77 bool ignore_current_value,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 PasswordAutofillAgent* password_autofill_agent, 145 PasswordAutofillAgent* password_autofill_agent,
143 PasswordGenerationAgent* password_generation_agent) 146 PasswordGenerationAgent* password_generation_agent)
144 : content::RenderFrameObserver(render_frame), 147 : content::RenderFrameObserver(render_frame),
145 form_cache_(*render_frame->GetWebFrame()), 148 form_cache_(*render_frame->GetWebFrame()),
146 password_autofill_agent_(password_autofill_agent), 149 password_autofill_agent_(password_autofill_agent),
147 password_generation_agent_(password_generation_agent), 150 password_generation_agent_(password_generation_agent),
148 legacy_(render_frame->GetRenderView(), this), 151 legacy_(render_frame->GetRenderView(), this),
149 autofill_query_id_(0), 152 autofill_query_id_(0),
150 was_query_node_autofilled_(false), 153 was_query_node_autofilled_(false),
151 has_shown_autofill_popup_for_current_edit_(false), 154 has_shown_autofill_popup_for_current_edit_(false),
152 did_set_node_text_(false),
153 ignore_text_changes_(false), 155 ignore_text_changes_(false),
154 is_popup_possibly_visible_(false), 156 is_popup_possibly_visible_(false),
155 weak_ptr_factory_(this) { 157 weak_ptr_factory_(this) {
156 render_frame->GetWebFrame()->setAutofillClient(this); 158 render_frame->GetWebFrame()->setAutofillClient(this);
157 159
158 // This owns itself, and will delete itself when |render_frame| is destructed 160 // This owns itself, and will delete itself when |render_frame| is destructed
159 // (same as AutofillAgent). 161 // (same as AutofillAgent).
160 new PageClickTracker(render_frame, this); 162 new PageClickTracker(render_frame, this);
161 } 163 }
162 164
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 ShowSuggestions(element, options); 373 ShowSuggestions(element, options);
372 } 374 }
373 375
374 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { 376 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
375 password_autofill_agent_->TextFieldDidEndEditing(element); 377 password_autofill_agent_->TextFieldDidEndEditing(element);
376 has_shown_autofill_popup_for_current_edit_ = false; 378 has_shown_autofill_popup_for_current_edit_ = false;
377 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); 379 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id()));
378 } 380 }
379 381
380 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) { 382 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) {
383 DCHECK(toWebInputElement(&element) || IsTextAreaElement(element));
381 if (ignore_text_changes_) 384 if (ignore_text_changes_)
382 return; 385 return;
383 386
384 DCHECK(toWebInputElement(&element) || IsTextAreaElement(element)); 387 if (!WebUserGestureIndicator::isProcessingUserGesture())
385
386 if (did_set_node_text_) {
387 did_set_node_text_ = false;
388 return; 388 return;
389 }
390 389
391 // We post a task for doing the Autofill as the caret position is not set 390 // We post a task for doing the Autofill as the caret position is not set
392 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and 391 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
393 // it is needed to trigger autofill. 392 // it is needed to trigger autofill.
394 weak_ptr_factory_.InvalidateWeakPtrs(); 393 weak_ptr_factory_.InvalidateWeakPtrs();
395 base::MessageLoop::current()->PostTask( 394 base::MessageLoop::current()->PostTask(
396 FROM_HERE, 395 FROM_HERE,
397 base::Bind(&AutofillAgent::TextFieldDidChangeImpl, 396 base::Bind(&AutofillAgent::TextFieldDidChangeImpl,
398 weak_ptr_factory_.GetWeakPtr(), 397 weak_ptr_factory_.GetWeakPtr(),
399 element)); 398 element));
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 Send(new AutofillHostMsg_SetDataList(routing_id(), 706 Send(new AutofillHostMsg_SetDataList(routing_id(),
708 data_list_values, 707 data_list_values,
709 data_list_labels)); 708 data_list_labels));
710 709
711 Send(new AutofillHostMsg_QueryFormFieldAutofill( 710 Send(new AutofillHostMsg_QueryFormFieldAutofill(
712 routing_id(), autofill_query_id_, form, field, bounding_box_scaled)); 711 routing_id(), autofill_query_id_, form, field, bounding_box_scaled));
713 } 712 }
714 713
715 void AutofillAgent::FillFieldWithValue(const base::string16& value, 714 void AutofillAgent::FillFieldWithValue(const base::string16& value,
716 WebInputElement* node) { 715 WebInputElement* node) {
717 did_set_node_text_ = true; 716 base::AutoReset<bool> auto_ignore_text_changes(&ignore_text_changes_, true);
Evan Stade 2015/04/21 00:54:31 nit: s/auto_long_and_redundant_variable_name/auto
please use gerrit instead 2015/04/21 17:02:47 Renamed to auto_reset, because "auto" is a languag
718 node->setEditingValue(value.substr(0, node->maxLength())); 717 node->setEditingValue(value.substr(0, node->maxLength()));
719 } 718 }
720 719
721 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, 720 void AutofillAgent::PreviewFieldWithValue(const base::string16& value,
722 WebInputElement* node) { 721 WebInputElement* node) {
723 was_query_node_autofilled_ = element_.isAutofilled(); 722 was_query_node_autofilled_ = element_.isAutofilled();
724 node->setSuggestedValue(value.substr(0, node->maxLength())); 723 node->setSuggestedValue(value.substr(0, node->maxLength()));
725 node->setAutofilled(true); 724 node->setAutofilled(true);
726 node->setSelectionRange(node->value().length(), 725 node->setSelectionRange(node->value().length(),
727 node->suggestedValue().length()); 726 node->suggestedValue().length());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 782
784 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { 783 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
785 // No-op. Don't delete |this|. 784 // No-op. Don't delete |this|.
786 } 785 }
787 786
788 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { 787 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() {
789 agent_->FocusChangeComplete(); 788 agent_->FocusChangeComplete();
790 } 789 }
791 790
792 } // namespace autofill 791 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/autofill_agent.h ('k') | content/public/test/render_view_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698