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 25 matching lines...) Expand all Loading... | |
| 36 #include "third_party/WebKit/public/web/WebDataSource.h" | 36 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 37 #include "third_party/WebKit/public/web/WebDocument.h" | 37 #include "third_party/WebKit/public/web/WebDocument.h" |
| 38 #include "third_party/WebKit/public/web/WebElementCollection.h" | 38 #include "third_party/WebKit/public/web/WebElementCollection.h" |
| 39 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 39 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 40 #include "third_party/WebKit/public/web/WebFormElement.h" | 40 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 41 #include "third_party/WebKit/public/web/WebInputEvent.h" | 41 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 42 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 42 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 43 #include "third_party/WebKit/public/web/WebNode.h" | 43 #include "third_party/WebKit/public/web/WebNode.h" |
| 44 #include "third_party/WebKit/public/web/WebOptionElement.h" | 44 #include "third_party/WebKit/public/web/WebOptionElement.h" |
| 45 #include "third_party/WebKit/public/web/WebTextAreaElement.h" | 45 #include "third_party/WebKit/public/web/WebTextAreaElement.h" |
| 46 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | |
| 46 #include "third_party/WebKit/public/web/WebView.h" | 47 #include "third_party/WebKit/public/web/WebView.h" |
| 47 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
| 48 #include "ui/events/keycodes/keyboard_codes.h" | 49 #include "ui/events/keycodes/keyboard_codes.h" |
| 49 | 50 |
| 50 using blink::WebAutofillClient; | 51 using blink::WebAutofillClient; |
| 51 using blink::WebConsoleMessage; | 52 using blink::WebConsoleMessage; |
| 52 using blink::WebDocument; | 53 using blink::WebDocument; |
| 53 using blink::WebElement; | 54 using blink::WebElement; |
| 54 using blink::WebElementCollection; | 55 using blink::WebElementCollection; |
| 55 using blink::WebFormControlElement; | 56 using blink::WebFormControlElement; |
| 56 using blink::WebFormElement; | 57 using blink::WebFormElement; |
| 57 using blink::WebFrame; | 58 using blink::WebFrame; |
| 58 using blink::WebInputElement; | 59 using blink::WebInputElement; |
| 59 using blink::WebKeyboardEvent; | 60 using blink::WebKeyboardEvent; |
| 60 using blink::WebLocalFrame; | 61 using blink::WebLocalFrame; |
| 61 using blink::WebNode; | 62 using blink::WebNode; |
| 62 using blink::WebOptionElement; | 63 using blink::WebOptionElement; |
| 63 using blink::WebString; | 64 using blink::WebString; |
| 64 using blink::WebTextAreaElement; | 65 using blink::WebTextAreaElement; |
| 66 using blink::WebUserGestureIndicator; | |
| 65 using blink::WebVector; | 67 using blink::WebVector; |
| 66 | 68 |
| 67 namespace autofill { | 69 namespace autofill { |
| 68 | 70 |
| 69 namespace { | 71 namespace { |
| 70 | 72 |
| 71 // Gets all the data list values (with corresponding label) for the given | 73 // Gets all the data list values (with corresponding label) for the given |
| 72 // element. | 74 // element. |
| 73 void GetDataListSuggestions(const WebInputElement& element, | 75 void GetDataListSuggestions(const WebInputElement& element, |
| 74 bool ignore_current_value, | 76 bool ignore_current_value, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 PasswordAutofillAgent* password_autofill_agent, | 144 PasswordAutofillAgent* password_autofill_agent, |
| 143 PasswordGenerationAgent* password_generation_agent) | 145 PasswordGenerationAgent* password_generation_agent) |
| 144 : content::RenderFrameObserver(render_frame), | 146 : content::RenderFrameObserver(render_frame), |
| 145 form_cache_(*render_frame->GetWebFrame()), | 147 form_cache_(*render_frame->GetWebFrame()), |
| 146 password_autofill_agent_(password_autofill_agent), | 148 password_autofill_agent_(password_autofill_agent), |
| 147 password_generation_agent_(password_generation_agent), | 149 password_generation_agent_(password_generation_agent), |
| 148 legacy_(render_frame->GetRenderView(), this), | 150 legacy_(render_frame->GetRenderView(), this), |
| 149 autofill_query_id_(0), | 151 autofill_query_id_(0), |
| 150 was_query_node_autofilled_(false), | 152 was_query_node_autofilled_(false), |
| 151 has_shown_autofill_popup_for_current_edit_(false), | 153 has_shown_autofill_popup_for_current_edit_(false), |
| 152 did_set_node_text_(false), | |
| 153 ignore_text_changes_(false), | 154 ignore_text_changes_(false), |
| 154 is_popup_possibly_visible_(false), | 155 is_popup_possibly_visible_(false), |
| 155 weak_ptr_factory_(this) { | 156 weak_ptr_factory_(this) { |
| 156 render_frame->GetWebFrame()->setAutofillClient(this); | 157 render_frame->GetWebFrame()->setAutofillClient(this); |
| 157 | 158 |
| 158 // This owns itself, and will delete itself when |render_frame| is destructed | 159 // This owns itself, and will delete itself when |render_frame| is destructed |
| 159 // (same as AutofillAgent). | 160 // (same as AutofillAgent). |
| 160 new PageClickTracker(render_frame, this); | 161 new PageClickTracker(render_frame, this); |
| 161 } | 162 } |
| 162 | 163 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 ShowSuggestions(element, options); | 372 ShowSuggestions(element, options); |
| 372 } | 373 } |
| 373 | 374 |
| 374 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { | 375 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
| 375 password_autofill_agent_->TextFieldDidEndEditing(element); | 376 password_autofill_agent_->TextFieldDidEndEditing(element); |
| 376 has_shown_autofill_popup_for_current_edit_ = false; | 377 has_shown_autofill_popup_for_current_edit_ = false; |
| 377 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); | 378 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); |
| 378 } | 379 } |
| 379 | 380 |
| 380 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) { | 381 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) { |
| 382 DCHECK(toWebInputElement(&element) || IsTextAreaElement(element)); | |
| 381 if (ignore_text_changes_) | 383 if (ignore_text_changes_) |
| 382 return; | 384 return; |
| 383 | 385 |
| 384 DCHECK(toWebInputElement(&element) || IsTextAreaElement(element)); | 386 if (!WebUserGestureIndicator::isProcessingUserGesture()) |
| 387 return; | |
| 385 | 388 |
| 386 if (did_set_node_text_) { | 389 // We post a task for doing the Autofill as the caret position |
| 387 did_set_node_text_ = false; | 390 // (http://bugs.webkit.org/show_bug.cgi?id=16976) and IME composition are not |
| 388 return; | 391 // set properly at this point and this information is needed to trigger |
| 389 } | 392 // autofill. |
| 390 | |
| 391 // 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 | |
| 393 // 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)); |
| 400 } | 399 } |
| 401 | 400 |
| 402 void AutofillAgent::TextFieldDidChangeImpl( | 401 void AutofillAgent::TextFieldDidChangeImpl( |
| 403 const WebFormControlElement& element) { | 402 const WebFormControlElement& element) { |
| 404 // If the element isn't focused then the changes don't matter. This check is | 403 // If the element isn't focused then the changes don't matter. This check is |
| 405 // required to properly handle IME interactions. | 404 // required to properly handle IME interactions. |
| 406 if (!element.focused()) | 405 if (!element.focused()) |
| 407 return; | 406 return; |
| 408 | 407 |
| 408 #if !defined(OS_ANDROID) | |
| 409 // IME composition on desktop is used for CJK, which will overlap with | |
| 410 // autofill popup near the input field. | |
| 411 if (render_frame()->GetWebFrame()->hasMarkedText()) { | |
| 412 HidePopup(); | |
|
Evan Stade
2015/04/20 22:40:30
as per offline convo I think we should show autofi
please use gerrit instead
2015/04/20 23:51:27
Done.
| |
| 413 return; | |
| 414 } | |
| 415 #endif | |
| 416 | |
| 409 const WebInputElement* input_element = toWebInputElement(&element); | 417 const WebInputElement* input_element = toWebInputElement(&element); |
| 410 if (input_element) { | 418 if (input_element) { |
| 411 if (password_generation_agent_ && | 419 if (password_generation_agent_ && |
| 412 password_generation_agent_->TextDidChangeInTextField(*input_element)) { | 420 password_generation_agent_->TextDidChangeInTextField(*input_element)) { |
| 413 is_popup_possibly_visible_ = true; | 421 is_popup_possibly_visible_ = true; |
| 414 return; | 422 return; |
| 415 } | 423 } |
| 416 | 424 |
| 417 if (password_autofill_agent_->TextDidChangeInTextField(*input_element)) { | 425 if (password_autofill_agent_->TextDidChangeInTextField(*input_element)) { |
| 418 is_popup_possibly_visible_ = true; | 426 is_popup_possibly_visible_ = true; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 Send(new AutofillHostMsg_SetDataList(routing_id(), | 715 Send(new AutofillHostMsg_SetDataList(routing_id(), |
| 708 data_list_values, | 716 data_list_values, |
| 709 data_list_labels)); | 717 data_list_labels)); |
| 710 | 718 |
| 711 Send(new AutofillHostMsg_QueryFormFieldAutofill( | 719 Send(new AutofillHostMsg_QueryFormFieldAutofill( |
| 712 routing_id(), autofill_query_id_, form, field, bounding_box_scaled)); | 720 routing_id(), autofill_query_id_, form, field, bounding_box_scaled)); |
| 713 } | 721 } |
| 714 | 722 |
| 715 void AutofillAgent::FillFieldWithValue(const base::string16& value, | 723 void AutofillAgent::FillFieldWithValue(const base::string16& value, |
| 716 WebInputElement* node) { | 724 WebInputElement* node) { |
| 717 did_set_node_text_ = true; | 725 ignore_text_changes_ = true; |
| 718 node->setEditingValue(value.substr(0, node->maxLength())); | 726 node->setEditingValue(value.substr(0, node->maxLength())); |
| 727 ignore_text_changes_ = false; | |
|
Evan Stade
2015/04/20 22:40:30
use base::AutoReset for this
please use gerrit instead
2015/04/20 23:51:27
Done.
| |
| 719 } | 728 } |
| 720 | 729 |
| 721 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, | 730 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, |
| 722 WebInputElement* node) { | 731 WebInputElement* node) { |
| 723 was_query_node_autofilled_ = element_.isAutofilled(); | 732 was_query_node_autofilled_ = element_.isAutofilled(); |
| 724 node->setSuggestedValue(value.substr(0, node->maxLength())); | 733 node->setSuggestedValue(value.substr(0, node->maxLength())); |
| 725 node->setAutofilled(true); | 734 node->setAutofilled(true); |
| 726 node->setSelectionRange(node->value().length(), | 735 node->setSelectionRange(node->value().length(), |
| 727 node->suggestedValue().length()); | 736 node->suggestedValue().length()); |
| 728 } | 737 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 | 792 |
| 784 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | 793 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 785 // No-op. Don't delete |this|. | 794 // No-op. Don't delete |this|. |
| 786 } | 795 } |
| 787 | 796 |
| 788 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | 797 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
| 789 agent_->FocusChangeComplete(); | 798 agent_->FocusChangeComplete(); |
| 790 } | 799 } |
| 791 | 800 |
| 792 } // namespace autofill | 801 } // namespace autofill |
| OLD | NEW |