Chromium Code Reviews| 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 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 242 bool AutofillAgent::InputElementClicked(const WebInputElement& element, | 242 bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
| 243 bool was_focused, | 243 bool was_focused, |
| 244 bool is_focused) { | 244 bool is_focused) { |
| 245 if (was_focused) | 245 if (was_focused) |
| 246 ShowSuggestions(element, true, false, true); | 246 ShowSuggestions(element, true, false, true); |
| 247 | 247 |
| 248 return false; | 248 return false; |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool AutofillAgent::InputElementLostFocus() { | 251 bool AutofillAgent::InputElementLostFocus() { |
| 252 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | 252 HideHostPopups(); |
| 253 | 253 |
| 254 return false; | 254 return false; |
| 255 } | 255 } |
| 256 | 256 |
| 257 void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, | 257 void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, |
| 258 const WebString& value, | 258 const WebString& value, |
| 259 const WebString& label, | 259 const WebString& label, |
| 260 int item_id, | 260 int item_id, |
| 261 unsigned index) { | 261 unsigned index) { |
| 262 if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) | 262 if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 i.push_back(string16()); | 484 i.push_back(string16()); |
| 485 ids.push_back(WebAutofillClient::MenuItemIDSeparator); | 485 ids.push_back(WebAutofillClient::MenuItemIDSeparator); |
| 486 } | 486 } |
| 487 | 487 |
| 488 // Append the Autofill suggestions. | 488 // Append the Autofill suggestions. |
| 489 v.insert(v.end(), values.begin(), values.end()); | 489 v.insert(v.end(), values.begin(), values.end()); |
| 490 l.insert(l.end(), labels.begin(), labels.end()); | 490 l.insert(l.end(), labels.begin(), labels.end()); |
| 491 i.insert(i.end(), icons.begin(), icons.end()); | 491 i.insert(i.end(), icons.begin(), icons.end()); |
| 492 ids.insert(ids.end(), item_ids.begin(), item_ids.end()); | 492 ids.insert(ids.end(), item_ids.begin(), item_ids.end()); |
| 493 | 493 |
| 494 if (v.empty()) { | |
| 495 // No suggestions, any popup currently showing is obsolete. | |
| 496 HidePopups(); | |
| 497 return; | |
| 498 } | |
| 499 | |
| 494 WebKit::WebView* web_view = render_view()->GetWebView(); | 500 WebKit::WebView* web_view = render_view()->GetWebView(); |
| 495 if (!web_view) | 501 if (!web_view) |
| 496 return; | 502 return; |
| 497 | 503 |
|
Dan Beam
2012/10/30 00:44:15
tell me if there's any problem with this ever-so-s
| |
| 498 if (v.empty()) { | |
| 499 // No suggestions, any popup currently showing is obsolete. | |
| 500 web_view->hidePopups(); | |
| 501 return; | |
| 502 } | |
| 503 | |
| 504 // Send to WebKit for display. | 504 // Send to WebKit for display. |
| 505 web_view->applyAutofillSuggestions(element, v, l, i, ids); | 505 web_view->applyAutofillSuggestions(element, v, l, i, ids); |
| 506 | 506 |
| 507 Send(new AutofillHostMsg_DidShowAutofillSuggestions( | 507 Send(new AutofillHostMsg_DidShowAutofillSuggestions( |
| 508 routing_id(), | 508 routing_id(), |
| 509 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); | 509 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); |
| 510 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; | 510 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
| 511 } | 511 } |
| 512 | 512 |
| 513 void AutofillAgent::AcceptDataListSuggestion(const string16& suggested_value) { | 513 void AutofillAgent::AcceptDataListSuggestion(const string16& suggested_value) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 string16 substring = value; | 724 string16 substring = value; |
| 725 substring = substring.substr(0, node->maxLength()); | 725 substring = substring.substr(0, node->maxLength()); |
| 726 | 726 |
| 727 node->setEditingValue(substring); | 727 node->setEditingValue(substring); |
| 728 } | 728 } |
| 729 | 729 |
| 730 void AutofillAgent::HidePopups() { | 730 void AutofillAgent::HidePopups() { |
| 731 WebKit::WebView* web_view = render_view()->GetWebView(); | 731 WebKit::WebView* web_view = render_view()->GetWebView(); |
| 732 if (web_view) | 732 if (web_view) |
| 733 web_view->hidePopups(); | 733 web_view->hidePopups(); |
| 734 | |
| 735 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); | |
| 734 } | 736 } |
| 735 | 737 |
| 736 } // namespace autofill | 738 } // namespace autofill |
| OLD | NEW |