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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 NULL)) { | 198 NULL)) { |
199 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, | 199 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, |
200 base::TimeTicks::Now())); | 200 base::TimeTicks::Now())); |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 void AutofillAgent::ZoomLevelChanged() { | 204 void AutofillAgent::ZoomLevelChanged() { |
205 // Any time the zoom level changes, the page's content moves, so any Autofill | 205 // Any time the zoom level changes, the page's content moves, so any Autofill |
206 // popups should be hidden. This is only needed for the new Autofill UI | 206 // popups should be hidden. This is only needed for the new Autofill UI |
207 // because WebKit already knows to hide the old UI when this occurs. | 207 // because WebKit already knows to hide the old UI when this occurs. |
208 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | 208 HideHostPopups(); |
209 } | 209 } |
210 | 210 |
211 void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) { | 211 void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) { |
212 // 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 |
213 // 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 |
214 // 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. |
215 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | 215 HideHostPopups(); |
216 } | 216 } |
217 | 217 |
218 void AutofillAgent::didRequestAutocomplete(WebKit::WebFrame* frame, | 218 void AutofillAgent::didRequestAutocomplete(WebKit::WebFrame* frame, |
219 const WebFormElement& form) { | 219 const WebFormElement& form) { |
220 if (has_requested_autocomplete_) | 220 if (has_requested_autocomplete_) |
221 return; | 221 return; |
222 | 222 |
223 // Cancel any pending Autofill requests. | 223 // Cancel any pending Autofill requests. |
224 ++autofill_query_id_; | 224 ++autofill_query_id_; |
225 | 225 |
226 // Any popup currently showing is obsolete. | 226 // Any popup currently showing is obsolete. |
227 HidePopups(); | 227 HidePopups(); |
228 HideHostPopups(); | |
228 | 229 |
229 FormData form_data; | 230 FormData form_data; |
230 if (WebFormElementToFormData(form, | 231 if (WebFormElementToFormData(form, |
231 WebFormControlElement(), | 232 WebFormControlElement(), |
232 REQUIRE_AUTOCOMPLETE, | 233 REQUIRE_AUTOCOMPLETE, |
233 EXTRACT_NONE, | 234 EXTRACT_NONE, |
234 &form_data, | 235 &form_data, |
235 NULL)) { | 236 NULL)) { |
236 form_ = form; | 237 form_ = form; |
237 has_requested_autocomplete_ = true; | 238 has_requested_autocomplete_ = true; |
238 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data)); | 239 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data)); |
239 } | 240 } |
240 } | 241 } |
241 | 242 |
242 bool AutofillAgent::InputElementClicked(const WebInputElement& element, | 243 bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
243 bool was_focused, | 244 bool was_focused, |
244 bool is_focused) { | 245 bool is_focused) { |
245 if (was_focused) | 246 if (was_focused) |
246 ShowSuggestions(element, true, false, true); | 247 ShowSuggestions(element, true, false, true); |
247 | 248 |
248 return false; | 249 return false; |
249 } | 250 } |
250 | 251 |
251 bool AutofillAgent::InputElementLostFocus() { | 252 bool AutofillAgent::InputElementLostFocus() { |
252 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | 253 HideHostPopups(); |
253 | 254 |
254 return false; | 255 return false; |
255 } | 256 } |
256 | 257 |
257 void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, | 258 void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, |
258 const WebString& value, | 259 const WebString& value, |
259 const WebString& label, | 260 const WebString& label, |
260 int item_id, | 261 int item_id, |
261 unsigned index) { | 262 unsigned index) { |
262 if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) | 263 if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 i.insert(i.end(), icons.begin(), icons.end()); | 492 i.insert(i.end(), icons.begin(), icons.end()); |
492 ids.insert(ids.end(), item_ids.begin(), item_ids.end()); | 493 ids.insert(ids.end(), item_ids.begin(), item_ids.end()); |
493 | 494 |
494 WebKit::WebView* web_view = render_view()->GetWebView(); | 495 WebKit::WebView* web_view = render_view()->GetWebView(); |
495 if (!web_view) | 496 if (!web_view) |
496 return; | 497 return; |
497 | 498 |
498 if (v.empty()) { | 499 if (v.empty()) { |
499 // No suggestions, any popup currently showing is obsolete. | 500 // No suggestions, any popup currently showing is obsolete. |
500 web_view->hidePopups(); | 501 web_view->hidePopups(); |
502 HideHostPopups(); | |
501 return; | 503 return; |
502 } | 504 } |
503 | 505 |
504 // Send to WebKit for display. | 506 // Send to WebKit for display. |
505 web_view->applyAutofillSuggestions(element, v, l, i, ids); | 507 web_view->applyAutofillSuggestions(element, v, l, i, ids); |
506 | 508 |
507 Send(new AutofillHostMsg_DidShowAutofillSuggestions( | 509 Send(new AutofillHostMsg_DidShowAutofillSuggestions( |
508 routing_id(), | 510 routing_id(), |
509 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); | 511 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); |
510 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; | 512 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 // Don't attempt to autofill with values that are too large or if filling | 625 // Don't attempt to autofill with values that are too large or if filling |
624 // criteria are not met. | 626 // criteria are not met. |
625 WebString value = element.editingValue(); | 627 WebString value = element.editingValue(); |
626 if (value.length() > kMaximumTextSizeForAutofill || | 628 if (value.length() > kMaximumTextSizeForAutofill || |
627 (!autofill_on_empty_values && value.isEmpty()) || | 629 (!autofill_on_empty_values && value.isEmpty()) || |
628 (requires_caret_at_end && | 630 (requires_caret_at_end && |
629 (element.selectionStart() != element.selectionEnd() || | 631 (element.selectionStart() != element.selectionEnd() || |
630 element.selectionEnd() != static_cast<int>(value.length())))) { | 632 element.selectionEnd() != static_cast<int>(value.length())))) { |
631 // Any popup currently showing is obsolete. | 633 // Any popup currently showing is obsolete. |
632 HidePopups(); | 634 HidePopups(); |
635 HideHostPopups(); | |
633 return; | 636 return; |
634 } | 637 } |
635 | 638 |
636 element_ = element; | 639 element_ = element; |
637 | 640 |
638 // If autocomplete is disabled at the form level, then we might want to show | 641 // If autocomplete is disabled at the form level, then we might want to show |
639 // a warning in place of suggestions. However, if autocomplete is disabled | 642 // a warning in place of suggestions. However, if autocomplete is disabled |
640 // specifically for this field, we never want to show a warning. Otherwise, | 643 // specifically for this field, we never want to show a warning. Otherwise, |
641 // we might interfere with custom popups (e.g. search suggestions) used by | 644 // we might interfere with custom popups (e.g. search suggestions) used by |
642 // the website. Also, if the field has no name, then we won't have values. | 645 // the website. Also, if the field has no name, then we won't have values. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 string16 substring = value; | 729 string16 substring = value; |
727 substring = substring.substr(0, node->maxLength()); | 730 substring = substring.substr(0, node->maxLength()); |
728 | 731 |
729 node->setEditingValue(substring); | 732 node->setEditingValue(substring); |
730 } | 733 } |
731 | 734 |
732 void AutofillAgent::HidePopups() { | 735 void AutofillAgent::HidePopups() { |
733 WebKit::WebView* web_view = render_view()->GetWebView(); | 736 WebKit::WebView* web_view = render_view()->GetWebView(); |
734 if (web_view) | 737 if (web_view) |
735 web_view->hidePopups(); | 738 web_view->hidePopups(); |
736 } | 739 } |
Ilya Sherman
2012/10/29 23:14:19
nit: I think this should also call HideHostPopups(
Dan Beam
2012/10/30 00:44:15
Done.
| |
737 | 740 |
741 void AutofillAgent::HideHostPopups() { | |
742 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | |
743 } | |
744 | |
738 } // namespace autofill | 745 } // namespace autofill |
OLD | NEW |