OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/autofill/autofill_agent.h" | 5 #include "chrome/renderer/autofill/autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, | 152 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, |
153 OnSetAutofillActionPreview) | 153 OnSetAutofillActionPreview) |
154 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, | 154 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, |
155 OnClearPreviewedForm) | 155 OnClearPreviewedForm) |
156 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, | 156 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, |
157 OnSetNodeText) | 157 OnSetNodeText) |
158 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, | 158 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, |
159 OnAcceptDataListSuggestion) | 159 OnAcceptDataListSuggestion) |
160 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, | 160 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, |
161 OnAcceptPasswordAutofillSuggestion) | 161 OnAcceptPasswordAutofillSuggestion) |
162 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteFinished, | |
163 OnRequestAutocompleteFinished) | |
162 IPC_MESSAGE_UNHANDLED(handled = false) | 164 IPC_MESSAGE_UNHANDLED(handled = false) |
163 IPC_END_MESSAGE_MAP() | 165 IPC_END_MESSAGE_MAP() |
164 return handled; | 166 return handled; |
165 } | 167 } |
166 | 168 |
167 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { | 169 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { |
168 // The document has now been fully loaded. Scan for forms to be sent up to | 170 // The document has now been fully loaded. Scan for forms to be sent up to |
169 // the browser. | 171 // the browser. |
170 std::vector<FormData> forms; | 172 std::vector<FormData> forms; |
171 form_cache_.ExtractForms(*frame, &forms); | 173 form_cache_.ExtractForms(*frame, &forms); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | 208 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); |
207 } | 209 } |
208 | 210 |
209 void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) { | 211 void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) { |
210 // Any time the scroll offset changes, the page's content moves, so Autofill | 212 // Any time the scroll offset changes, the page's content moves, so Autofill |
211 // popups should be hidden. This is only needed for the new Autofill UI | 213 // popups should be hidden. This is only needed for the new Autofill UI |
212 // because WebKit already knows to hide the old UI when this occurs. | 214 // because WebKit already knows to hide the old UI when this occurs. |
213 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | 215 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); |
214 } | 216 } |
215 | 217 |
218 void AutofillAgent::RequestAutocomplete(WebKit::WebFrame* frame, | |
219 const WebFormElement& form) { | |
220 | |
221 // TODO(dbeam): should popups be hidden here? Maybe after a view message from | |
222 // the browser to say whether the interactive autocomplete UI will show? | |
Ilya Sherman
2012/10/26 03:30:52
Yes, we should hide popups and cancel any pending
Dan Beam
2012/10/26 05:51:44
creating separate counter for this request like we
| |
223 | |
224 FormData form_data; | |
225 if (WebFormElementToFormData(form, | |
226 WebFormControlElement(), | |
227 REQUIRE_AUTOCOMPLETE, | |
228 static_cast<ExtractMask>( | |
229 EXTRACT_VALUE | EXTRACT_OPTION_TEXT), | |
Ilya Sherman
2012/10/26 03:30:52
nit: I don't think we need to extract values or op
Dan Beam
2012/10/26 05:51:44
Done.
| |
230 &form_data, | |
231 NULL)) { | |
232 form_ = form; | |
233 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data)); | |
234 } | |
235 } | |
236 | |
216 bool AutofillAgent::InputElementClicked(const WebInputElement& element, | 237 bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
217 bool was_focused, | 238 bool was_focused, |
218 bool is_focused) { | 239 bool is_focused) { |
219 if (was_focused) | 240 if (was_focused) |
220 ShowSuggestions(element, true, false, true); | 241 ShowSuggestions(element, true, false, true); |
221 | 242 |
222 return false; | 243 return false; |
223 } | 244 } |
224 | 245 |
225 bool AutofillAgent::InputElementLostFocus() { | 246 bool AutofillAgent::InputElementLostFocus() { |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { | 596 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { |
576 // We need to make sure this is handled here because the browser process | 597 // We need to make sure this is handled here because the browser process |
577 // skipped it handling because it believed it would be handled here. If it | 598 // skipped it handling because it believed it would be handled here. If it |
578 // isn't handled here then the browser logic needs to be updated. | 599 // isn't handled here then the browser logic needs to be updated. |
579 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion( | 600 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion( |
580 element_, | 601 element_, |
581 value); | 602 value); |
582 DCHECK(handled); | 603 DCHECK(handled); |
583 } | 604 } |
584 | 605 |
606 void AutofillAgent::OnRequestAutocompleteFinished(bool success) { | |
607 form_.dispatchAutocompleteEvent(success); | |
Ilya Sherman
2012/10/26 03:30:52
We should do some sort of checking here to make su
Dan Beam
2012/10/26 05:51:44
why would it being removed from the DOM cause us t
| |
608 } | |
609 | |
585 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 610 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
586 bool autofill_on_empty_values, | 611 bool autofill_on_empty_values, |
587 bool requires_caret_at_end, | 612 bool requires_caret_at_end, |
588 bool display_warning_if_disabled) { | 613 bool display_warning_if_disabled) { |
589 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || | 614 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || |
590 element.isPasswordField() || !element.suggestedValue().isEmpty()) | 615 element.isPasswordField() || !element.suggestedValue().isEmpty()) |
591 return; | 616 return; |
592 | 617 |
593 // Don't attempt to autofill with values that are too large or if filling | 618 // Don't attempt to autofill with values that are too large or if filling |
594 // criteria are not met. | 619 // criteria are not met. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 void AutofillAgent::SetNodeText(const string16& value, | 721 void AutofillAgent::SetNodeText(const string16& value, |
697 WebKit::WebInputElement* node) { | 722 WebKit::WebInputElement* node) { |
698 did_set_node_text_ = true; | 723 did_set_node_text_ = true; |
699 string16 substring = value; | 724 string16 substring = value; |
700 substring = substring.substr(0, node->maxLength()); | 725 substring = substring.substr(0, node->maxLength()); |
701 | 726 |
702 node->setEditingValue(substring); | 727 node->setEditingValue(substring); |
703 } | 728 } |
704 | 729 |
705 } // namespace autofill | 730 } // namespace autofill |
OLD | NEW |