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

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

Issue 11000016: Move forms/ out of webkit/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 8 years, 2 months 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
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"
16 #include "chrome/common/form_data_predictions.h"
17 #include "chrome/common/form_field_data.h"
15 #include "chrome/renderer/autofill/form_autofill_util.h" 18 #include "chrome/renderer/autofill/form_autofill_util.h"
16 #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"
17 #include "content/public/renderer/render_view.h" 21 #include "content/public/renderer/render_view.h"
18 #include "grit/chromium_strings.h" 22 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement .h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeCollection.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeCollection.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebOptionElement.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebOptionElement.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
29 #include "ui/base/keycodes/keyboard_codes.h" 33 #include "ui/base/keycodes/keyboard_codes.h"
30 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
31 #include "webkit/forms/form_data.h"
32 #include "webkit/forms/form_data_predictions.h"
33 #include "webkit/forms/form_field.h"
34 #include "webkit/forms/password_form.h"
35 35
36 using WebKit::WebAutofillClient; 36 using WebKit::WebAutofillClient;
37 using WebKit::WebFormControlElement; 37 using WebKit::WebFormControlElement;
38 using WebKit::WebFormElement; 38 using WebKit::WebFormElement;
39 using WebKit::WebFrame; 39 using WebKit::WebFrame;
40 using WebKit::WebInputElement; 40 using WebKit::WebInputElement;
41 using WebKit::WebKeyboardEvent; 41 using WebKit::WebKeyboardEvent;
42 using WebKit::WebNode; 42 using WebKit::WebNode;
43 using WebKit::WebNodeCollection; 43 using WebKit::WebNodeCollection;
44 using WebKit::WebOptionElement; 44 using WebKit::WebOptionElement;
45 using WebKit::WebString; 45 using WebKit::WebString;
46 using webkit::forms::FormData;
47 using webkit::forms::FormDataPredictions;
48 46
49 namespace { 47 namespace {
50 48
51 // The size above which we stop triggering autofill for an input text field 49 // The size above which we stop triggering autofill for an input text field
52 // (so to avoid sending long strings through IPC). 50 // (so to avoid sending long strings through IPC).
53 const size_t kMaximumTextSizeForAutofill = 1000; 51 const size_t kMaximumTextSizeForAutofill = 1000;
54 52
55 // The maximum number of data list elements to send to the browser process 53 // The maximum number of data list elements to send to the browser process
56 // via IPC (to prevent long IPC messages). 54 // via IPC (to prevent long IPC messages).
57 const size_t kMaximumDataListSizeForAutofill = 30; 55 const size_t kMaximumDataListSizeForAutofill = 30;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, 160 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion,
163 OnAcceptPasswordAutofillSuggestion) 161 OnAcceptPasswordAutofillSuggestion)
164 IPC_MESSAGE_UNHANDLED(handled = false) 162 IPC_MESSAGE_UNHANDLED(handled = false)
165 IPC_END_MESSAGE_MAP() 163 IPC_END_MESSAGE_MAP()
166 return handled; 164 return handled;
167 } 165 }
168 166
169 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { 167 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) {
170 // The document has now been fully loaded. Scan for forms to be sent up to 168 // The document has now been fully loaded. Scan for forms to be sent up to
171 // the browser. 169 // the browser.
172 std::vector<webkit::forms::FormData> forms; 170 std::vector<FormData> forms;
173 form_cache_.ExtractForms(*frame, &forms); 171 form_cache_.ExtractForms(*frame, &forms);
174 172
175 if (!forms.empty()) { 173 if (!forms.empty()) {
176 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, 174 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
177 base::TimeTicks::Now())); 175 base::TimeTicks::Now()));
178 } 176 }
179 } 177 }
180 178
181 void AutofillAgent::FrameDetached(WebFrame* frame) { 179 void AutofillAgent::FrameDetached(WebFrame* frame) {
182 form_cache_.ResetFrame(*frame); 180 form_cache_.ResetFrame(*frame);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 325 }
328 326
329 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { 327 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) {
330 if (password_autofill_manager_->TextDidChangeInTextField(element)) { 328 if (password_autofill_manager_->TextDidChangeInTextField(element)) {
331 element_ = element; 329 element_ = element;
332 return; 330 return;
333 } 331 }
334 332
335 ShowSuggestions(element, false, true, false); 333 ShowSuggestions(element, false, true, false);
336 334
337 webkit::forms::FormData form; 335 FormData form;
338 webkit::forms::FormField field; 336 FormFieldData field;
339 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { 337 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) {
340 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, 338 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field,
341 base::TimeTicks::Now())); 339 base::TimeTicks::Now()));
342 } 340 }
343 } 341 }
344 342
345 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, 343 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element,
346 const WebKeyboardEvent& event) { 344 const WebKeyboardEvent& event) {
347 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) { 345 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) {
348 element_ = element; 346 element_ = element;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 } 498 }
501 last_part.append(suggested_value); 499 last_part.append(suggested_value);
502 parts[parts.size() - 1] = last_part; 500 parts[parts.size() - 1] = last_part;
503 501
504 new_value = JoinString(parts, ','); 502 new_value = JoinString(parts, ',');
505 } 503 }
506 SetNodeText(new_value, &element_); 504 SetNodeText(new_value, &element_);
507 } 505 }
508 506
509 void AutofillAgent::OnFormDataFilled(int query_id, 507 void AutofillAgent::OnFormDataFilled(int query_id,
510 const webkit::forms::FormData& form) { 508 const FormData& form) {
511 if (!render_view()->GetWebView() || query_id != autofill_query_id_) 509 if (!render_view()->GetWebView() || query_id != autofill_query_id_)
512 return; 510 return;
513 511
514 was_query_node_autofilled_ = element_.isAutofilled(); 512 was_query_node_autofilled_ = element_.isAutofilled();
515 513
516 switch (autofill_action_) { 514 switch (autofill_action_) {
517 case AUTOFILL_FILL: 515 case AUTOFILL_FILL:
518 FillForm(form, element_); 516 FillForm(form, element_);
519 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), 517 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(),
520 base::TimeTicks::Now())); 518 base::TimeTicks::Now()));
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 617
620 QueryAutofillSuggestions(element, display_warning_if_disabled); 618 QueryAutofillSuggestions(element, display_warning_if_disabled);
621 } 619 }
622 620
623 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, 621 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element,
624 bool display_warning_if_disabled) { 622 bool display_warning_if_disabled) {
625 static int query_counter = 0; 623 static int query_counter = 0;
626 autofill_query_id_ = query_counter++; 624 autofill_query_id_ = query_counter++;
627 display_warning_if_disabled_ = display_warning_if_disabled; 625 display_warning_if_disabled_ = display_warning_if_disabled;
628 626
629 webkit::forms::FormData form; 627 FormData form;
630 webkit::forms::FormField field; 628 FormFieldData field;
631 if (!FindFormAndFieldForInputElement(element, &form, &field, 629 if (!FindFormAndFieldForInputElement(element, &form, &field,
632 REQUIRE_AUTOCOMPLETE)) { 630 REQUIRE_AUTOCOMPLETE)) {
633 // If we didn't find the cached form, at least let autocomplete have a shot 631 // If we didn't find the cached form, at least let autocomplete have a shot
634 // at providing suggestions. 632 // at providing suggestions.
635 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); 633 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field);
636 } 634 }
637 635
638 gfx::Rect bounding_box(element_.boundsInViewportSpace()); 636 gfx::Rect bounding_box(element_.boundsInViewportSpace());
639 637
640 // Find the datalist values and send them to the browser process. 638 // Find the datalist values and send them to the browser process.
(...skipping 27 matching lines...) Expand all
668 } 666 }
669 667
670 void AutofillAgent::FillAutofillFormData(const WebNode& node, 668 void AutofillAgent::FillAutofillFormData(const WebNode& node,
671 int unique_id, 669 int unique_id,
672 AutofillAction action) { 670 AutofillAction action) {
673 DCHECK_GT(unique_id, 0); 671 DCHECK_GT(unique_id, 0);
674 672
675 static int query_counter = 0; 673 static int query_counter = 0;
676 autofill_query_id_ = query_counter++; 674 autofill_query_id_ = query_counter++;
677 675
678 webkit::forms::FormData form; 676 FormData form;
679 webkit::forms::FormField field; 677 FormFieldData field;
680 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form, 678 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form,
681 &field, REQUIRE_AUTOCOMPLETE)) { 679 &field, REQUIRE_AUTOCOMPLETE)) {
682 return; 680 return;
683 } 681 }
684 682
685 autofill_action_ = action; 683 autofill_action_ = action;
686 Send(new AutofillHostMsg_FillAutofillFormData( 684 Send(new AutofillHostMsg_FillAutofillFormData(
687 routing_id(), autofill_query_id_, form, field, unique_id)); 685 routing_id(), autofill_query_id_, form, field, unique_id));
688 } 686 }
689 687
690 void AutofillAgent::SetNodeText(const string16& value, 688 void AutofillAgent::SetNodeText(const string16& value,
691 WebKit::WebInputElement* node) { 689 WebKit::WebInputElement* node) {
692 did_set_node_text_ = true; 690 did_set_node_text_ = true;
693 string16 substring = value; 691 string16 substring = value;
694 substring = substring.substr(0, node->maxLength()); 692 substring = substring.substr(0, node->maxLength());
695 693
696 node->setEditingValue(substring); 694 node->setEditingValue(substring);
697 } 695 }
698 696
699 } // namespace autofill 697 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/autofill_agent.h ('k') | chrome/renderer/autofill/autofill_renderer_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698