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

Side by Side Diff: chrome/renderer/autofill/autofill_agent.cc

Issue 11270018: [autofill] Adding new API to request an interactive autocomplete UI flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 80 col Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/autofill/autofill_agent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/common/autofill_messages.h" 13 #include "chrome/common/autofill_messages.h"
14 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/form_data.h" 15 #include "chrome/common/form_data.h"
16 #include "chrome/common/form_data_predictions.h" 16 #include "chrome/common/form_data_predictions.h"
17 #include "chrome/common/form_field_data.h" 17 #include "chrome/common/form_field_data.h"
18 #include "chrome/renderer/autofill/form_autofill_util.h" 18 #include "chrome/renderer/autofill/form_autofill_util.h"
19 #include "chrome/renderer/autofill/password_autofill_manager.h" 19 #include "chrome/renderer/autofill/password_autofill_manager.h"
20 #include "content/public/common/password_form.h" 20 #include "content/public/common/password_form.h"
21 #include "content/public/renderer/render_view.h" 21 #include "content/public/renderer/render_view.h"
22 #include "grit/chromium_strings.h" 22 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeCollection.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeCollection.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebOptionElement.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebOptionElement.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
33 #include "ui/base/keycodes/keyboard_codes.h" 34 #include "ui/base/keycodes/keyboard_codes.h"
34 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
35 36
36 using WebKit::WebAutofillClient; 37 using WebKit::WebAutofillClient;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, 151 IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview,
151 OnSetAutofillActionPreview) 152 OnSetAutofillActionPreview)
152 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, 153 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm,
153 OnClearPreviewedForm) 154 OnClearPreviewedForm)
154 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, 155 IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText,
155 OnSetNodeText) 156 OnSetNodeText)
156 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, 157 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
157 OnAcceptDataListSuggestion) 158 OnAcceptDataListSuggestion)
158 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, 159 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion,
159 OnAcceptPasswordAutofillSuggestion) 160 OnAcceptPasswordAutofillSuggestion)
161 IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteFinished,
162 OnRequestAutocompleteFinished)
160 IPC_MESSAGE_UNHANDLED(handled = false) 163 IPC_MESSAGE_UNHANDLED(handled = false)
161 IPC_END_MESSAGE_MAP() 164 IPC_END_MESSAGE_MAP()
162 return handled; 165 return handled;
163 } 166 }
164 167
165 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { 168 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) {
166 // The document has now been fully loaded. Scan for forms to be sent up to 169 // The document has now been fully loaded. Scan for forms to be sent up to
167 // the browser. 170 // the browser.
168 std::vector<FormData> forms; 171 std::vector<FormData> forms;
169 form_cache_.ExtractForms(*frame, &forms); 172 form_cache_.ExtractForms(*frame, &forms);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); 207 Send(new AutofillHostMsg_HideAutofillPopup(routing_id()));
205 } 208 }
206 209
207 void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) { 210 void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) {
208 // Any time the scroll offset changes, the page's content moves, so Autofill 211 // Any time the scroll offset changes, the page's content moves, so Autofill
209 // popups should be hidden. This is only needed for the new Autofill UI 212 // popups should be hidden. This is only needed for the new Autofill UI
210 // because WebKit already knows to hide the old UI when this occurs. 213 // because WebKit already knows to hide the old UI when this occurs.
211 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); 214 Send(new AutofillHostMsg_HideAutofillPopup(routing_id()));
212 } 215 }
213 216
217 void AutofillAgent::didRequestAutocomplete(WebKit::WebFrame* frame,
218 const WebFormElement& form) {
219 FormData form_data;
220 if (!form_.isNull() ||
221 !WebFormElementToFormData(form,
222 WebFormControlElement(),
223 REQUIRE_AUTOCOMPLETE,
224 EXTRACT_NONE,
225 &form_data,
226 NULL)) {
227 WebFormElement non_const_form(form);
Ilya Sherman 2012/11/02 02:56:57 nit: Seems like we shouldn't be passing in a const
Dan Beam 2012/11/02 03:10:15 So I removed const but there were issues with this
Ilya Sherman 2012/11/02 03:24:45 What are the issues with removing const? I agree
Dan Beam 2012/11/02 22:37:55 So it looks like this is already being done every
Ilya Sherman 2012/11/02 22:47:36 No counter-examples that I'm aware of, no.
228 non_const_form.finishRequestAutocomplete(
229 WebFormElement::AutocompleteResultError);
230 return;
231 }
232
233 // Cancel any pending Autofill requests and hide any currently showing popups.
234 ++autofill_query_id_;
235 HidePopups();
236
237 form_ = form;
238 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data));
239 }
240
214 bool AutofillAgent::InputElementClicked(const WebInputElement& element, 241 bool AutofillAgent::InputElementClicked(const WebInputElement& element,
215 bool was_focused, 242 bool was_focused,
216 bool is_focused) { 243 bool is_focused) {
217 if (was_focused) 244 if (was_focused)
218 ShowSuggestions(element, true, false, true); 245 ShowSuggestions(element, true, false, true);
219 246
220 return false; 247 return false;
221 } 248 }
222 249
223 bool AutofillAgent::InputElementLostFocus() { 250 bool AutofillAgent::InputElementLostFocus() {
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { 594 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) {
568 // We need to make sure this is handled here because the browser process 595 // We need to make sure this is handled here because the browser process
569 // skipped it handling because it believed it would be handled here. If it 596 // skipped it handling because it believed it would be handled here. If it
570 // isn't handled here then the browser logic needs to be updated. 597 // isn't handled here then the browser logic needs to be updated.
571 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion( 598 bool handled = password_autofill_manager_->DidAcceptAutofillSuggestion(
572 element_, 599 element_,
573 value); 600 value);
574 DCHECK(handled); 601 DCHECK(handled);
575 } 602 }
576 603
604 void AutofillAgent::OnRequestAutocompleteFinished(
605 WebFormElement::AutocompleteResult result) {
606 if (form_.isNull())
607 return;
Ilya Sherman 2012/11/02 02:56:57 When can this happen?
Dan Beam 2012/11/02 03:10:15 I'd think it's possible that the form *could* be r
Ilya Sherman 2012/11/02 03:24:45 The form could be removed from the DOM, but I don'
Dan Beam 2012/11/02 21:06:08 True, I definitely think you're right here and res
608
609 form_.finishRequestAutocomplete(result);
610 form_.reset();
611 }
612
577 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 613 void AutofillAgent::ShowSuggestions(const WebInputElement& element,
578 bool autofill_on_empty_values, 614 bool autofill_on_empty_values,
579 bool requires_caret_at_end, 615 bool requires_caret_at_end,
580 bool display_warning_if_disabled) { 616 bool display_warning_if_disabled) {
581 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || 617 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() ||
582 element.isPasswordField() || !element.suggestedValue().isEmpty()) 618 element.isPasswordField() || !element.suggestedValue().isEmpty())
583 return; 619 return;
584 620
585 // Don't attempt to autofill with values that are too large or if filling 621 // Don't attempt to autofill with values that are too large or if filling
586 // criteria are not met. 622 // criteria are not met.
587 WebString value = element.editingValue(); 623 WebString value = element.editingValue();
588 if (value.length() > kMaximumTextSizeForAutofill || 624 if (value.length() > kMaximumTextSizeForAutofill ||
589 (!autofill_on_empty_values && value.isEmpty()) || 625 (!autofill_on_empty_values && value.isEmpty()) ||
590 (requires_caret_at_end && 626 (requires_caret_at_end &&
591 (element.selectionStart() != element.selectionEnd() || 627 (element.selectionStart() != element.selectionEnd() ||
592 element.selectionEnd() != static_cast<int>(value.length())))) { 628 element.selectionEnd() != static_cast<int>(value.length())))) {
593 // Any popup currently showing is obsolete. 629 // Any popup currently showing is obsolete.
594 WebKit::WebView* web_view = render_view()->GetWebView(); 630 HidePopups();
595 if (web_view)
596 web_view->hidePopups();
597
598 return; 631 return;
599 } 632 }
600 633
601 element_ = element; 634 element_ = element;
602 635
603 // If autocomplete is disabled at the form level, then we might want to show 636 // If autocomplete is disabled at the form level, then we might want to show
604 // a warning in place of suggestions. However, if autocomplete is disabled 637 // a warning in place of suggestions. However, if autocomplete is disabled
605 // specifically for this field, we never want to show a warning. Otherwise, 638 // specifically for this field, we never want to show a warning. Otherwise,
606 // we might interfere with custom popups (e.g. search suggestions) used by 639 // we might interfere with custom popups (e.g. search suggestions) used by
607 // the website. Also, if the field has no name, then we won't have values. 640 // the website. Also, if the field has no name, then we won't have values.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 720
688 void AutofillAgent::SetNodeText(const string16& value, 721 void AutofillAgent::SetNodeText(const string16& value,
689 WebKit::WebInputElement* node) { 722 WebKit::WebInputElement* node) {
690 did_set_node_text_ = true; 723 did_set_node_text_ = true;
691 string16 substring = value; 724 string16 substring = value;
692 substring = substring.substr(0, node->maxLength()); 725 substring = substring.substr(0, node->maxLength());
693 726
694 node->setEditingValue(substring); 727 node->setEditingValue(substring);
695 } 728 }
696 729
730 void AutofillAgent::HidePopups() {
731 WebKit::WebView* web_view = render_view()->GetWebView();
732 if (web_view)
733 web_view->hidePopups();
734 }
735
697 } // namespace autofill 736 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698