| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/common/autofill_messages.h" | 11 #include "chrome/common/autofill_messages.h" |
| 12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/renderer/autofill/form_autofill_util.h" | 13 #include "chrome/renderer/autofill/form_autofill_util.h" |
| 14 #include "chrome/renderer/autofill/password_autofill_manager.h" | 14 #include "chrome/renderer/autofill/password_autofill_manager.h" |
| 15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement
.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement
.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 24 #include "ui/base/keycodes/keyboard_codes.h" | 24 #include "ui/base/keycodes/keyboard_codes.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "webkit/glue/form_data.h" | 26 #include "webkit/forms/form_data.h" |
| 27 #include "webkit/glue/form_data_predictions.h" | 27 #include "webkit/forms/form_data_predictions.h" |
| 28 #include "webkit/glue/form_field.h" | 28 #include "webkit/forms/form_field.h" |
| 29 #include "webkit/glue/password_form.h" | 29 #include "webkit/forms/password_form.h" |
| 30 | 30 |
| 31 using WebKit::WebFormControlElement; | 31 using WebKit::WebFormControlElement; |
| 32 using WebKit::WebFormElement; | 32 using WebKit::WebFormElement; |
| 33 using WebKit::WebFrame; | 33 using WebKit::WebFrame; |
| 34 using WebKit::WebInputElement; | 34 using WebKit::WebInputElement; |
| 35 using WebKit::WebKeyboardEvent; | 35 using WebKit::WebKeyboardEvent; |
| 36 using WebKit::WebNode; | 36 using WebKit::WebNode; |
| 37 using WebKit::WebString; | 37 using WebKit::WebString; |
| 38 using webkit_glue::FormData; | 38 using webkit::forms::FormData; |
| 39 using webkit_glue::FormDataPredictions; | 39 using webkit::forms::FormDataPredictions; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // The size above which we stop triggering autofill for an input text field | 43 // The size above which we stop triggering autofill for an input text field |
| 44 // (so to avoid sending long strings through IPC). | 44 // (so to avoid sending long strings through IPC). |
| 45 const size_t kMaximumTextSizeForAutofill = 1000; | 45 const size_t kMaximumTextSizeForAutofill = 1000; |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 namespace autofill { | 49 namespace autofill { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 76 IPC_MESSAGE_HANDLER(AutofillMsg_SelectAutofillSuggestionAtIndex, | 76 IPC_MESSAGE_HANDLER(AutofillMsg_SelectAutofillSuggestionAtIndex, |
| 77 OnSelectAutofillSuggestionAtIndex) | 77 OnSelectAutofillSuggestionAtIndex) |
| 78 IPC_MESSAGE_UNHANDLED(handled = false) | 78 IPC_MESSAGE_UNHANDLED(handled = false) |
| 79 IPC_END_MESSAGE_MAP() | 79 IPC_END_MESSAGE_MAP() |
| 80 return handled; | 80 return handled; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { | 83 void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { |
| 84 // The document has now been fully loaded. Scan for forms to be sent up to | 84 // The document has now been fully loaded. Scan for forms to be sent up to |
| 85 // the browser. | 85 // the browser. |
| 86 std::vector<webkit_glue::FormData> forms; | 86 std::vector<webkit::forms::FormData> forms; |
| 87 form_cache_.ExtractForms(*frame, &forms); | 87 form_cache_.ExtractForms(*frame, &forms); |
| 88 | 88 |
| 89 if (!forms.empty()) { | 89 if (!forms.empty()) { |
| 90 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 90 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
| 91 base::TimeTicks::Now())); | 91 base::TimeTicks::Now())); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 void AutofillAgent::FrameDetached(WebFrame* frame) { | 95 void AutofillAgent::FrameDetached(WebFrame* frame) { |
| 96 form_cache_.ResetFrame(*frame); | 96 form_cache_.ResetFrame(*frame); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 base::Bind(&AutofillAgent::TextFieldDidChangeImpl, | 219 base::Bind(&AutofillAgent::TextFieldDidChangeImpl, |
| 220 weak_ptr_factory_.GetWeakPtr(), element)); | 220 weak_ptr_factory_.GetWeakPtr(), element)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { | 223 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { |
| 224 if (password_autofill_manager_->TextDidChangeInTextField(element)) | 224 if (password_autofill_manager_->TextDidChangeInTextField(element)) |
| 225 return; | 225 return; |
| 226 | 226 |
| 227 ShowSuggestions(element, false, true, false); | 227 ShowSuggestions(element, false, true, false); |
| 228 | 228 |
| 229 webkit_glue::FormData form; | 229 webkit::forms::FormData form; |
| 230 webkit_glue::FormField field; | 230 webkit::forms::FormField field; |
| 231 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { | 231 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { |
| 232 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, | 232 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, |
| 233 base::TimeTicks::Now())); | 233 base::TimeTicks::Now())); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, | 237 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, |
| 238 const WebKeyboardEvent& event) { | 238 const WebKeyboardEvent& event) { |
| 239 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) | 239 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) |
| 240 return; | 240 return; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 autofill_query_element_, v, l, i, ids, separator_index); | 326 autofill_query_element_, v, l, i, ids, separator_index); |
| 327 } | 327 } |
| 328 | 328 |
| 329 Send(new AutofillHostMsg_DidShowAutofillSuggestions( | 329 Send(new AutofillHostMsg_DidShowAutofillSuggestions( |
| 330 routing_id(), | 330 routing_id(), |
| 331 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); | 331 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); |
| 332 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; | 332 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
| 333 } | 333 } |
| 334 | 334 |
| 335 void AutofillAgent::OnFormDataFilled(int query_id, | 335 void AutofillAgent::OnFormDataFilled(int query_id, |
| 336 const webkit_glue::FormData& form) { | 336 const webkit::forms::FormData& form) { |
| 337 if (!render_view()->GetWebView() || query_id != autofill_query_id_) | 337 if (!render_view()->GetWebView() || query_id != autofill_query_id_) |
| 338 return; | 338 return; |
| 339 | 339 |
| 340 switch (autofill_action_) { | 340 switch (autofill_action_) { |
| 341 case AUTOFILL_FILL: | 341 case AUTOFILL_FILL: |
| 342 FillForm(form, autofill_query_element_); | 342 FillForm(form, autofill_query_element_); |
| 343 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), | 343 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), |
| 344 base::TimeTicks::Now())); | 344 base::TimeTicks::Now())); |
| 345 break; | 345 break; |
| 346 case AUTOFILL_PREVIEW: | 346 case AUTOFILL_PREVIEW: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 QueryAutofillSuggestions(element, display_warning_if_disabled); | 402 QueryAutofillSuggestions(element, display_warning_if_disabled); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, | 405 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, |
| 406 bool display_warning_if_disabled) { | 406 bool display_warning_if_disabled) { |
| 407 static int query_counter = 0; | 407 static int query_counter = 0; |
| 408 autofill_query_id_ = query_counter++; | 408 autofill_query_id_ = query_counter++; |
| 409 autofill_query_element_ = element; | 409 autofill_query_element_ = element; |
| 410 display_warning_if_disabled_ = display_warning_if_disabled; | 410 display_warning_if_disabled_ = display_warning_if_disabled; |
| 411 | 411 |
| 412 webkit_glue::FormData form; | 412 webkit::forms::FormData form; |
| 413 webkit_glue::FormField field; | 413 webkit::forms::FormField field; |
| 414 if (!FindFormAndFieldForInputElement(element, &form, &field, | 414 if (!FindFormAndFieldForInputElement(element, &form, &field, |
| 415 REQUIRE_AUTOCOMPLETE)) { | 415 REQUIRE_AUTOCOMPLETE)) { |
| 416 // If we didn't find the cached form, at least let autocomplete have a shot | 416 // If we didn't find the cached form, at least let autocomplete have a shot |
| 417 // at providing suggestions. | 417 // at providing suggestions. |
| 418 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 418 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
| 419 } | 419 } |
| 420 | 420 |
| 421 // TODO(csharp): Stop using the hardcoded value once the WebKit change to | 421 // TODO(csharp): Stop using the hardcoded value once the WebKit change to |
| 422 // expose the position lands. | 422 // expose the position lands. |
| 423 // gfx::Rect bounding_box(autofill_query_element_.boundsInRootViewSpace()); | 423 // gfx::Rect bounding_box(autofill_query_element_.boundsInRootViewSpace()); |
| 424 gfx::Rect bounding_box(26, 51, 155, 22); | 424 gfx::Rect bounding_box(26, 51, 155, 22); |
| 425 | 425 |
| 426 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), | 426 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), |
| 427 autofill_query_id_, | 427 autofill_query_id_, |
| 428 form, | 428 form, |
| 429 field, | 429 field, |
| 430 bounding_box, | 430 bounding_box, |
| 431 display_warning_if_disabled)); | 431 display_warning_if_disabled)); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void AutofillAgent::FillAutofillFormData(const WebNode& node, | 434 void AutofillAgent::FillAutofillFormData(const WebNode& node, |
| 435 int unique_id, | 435 int unique_id, |
| 436 AutofillAction action) { | 436 AutofillAction action) { |
| 437 static int query_counter = 0; | 437 static int query_counter = 0; |
| 438 autofill_query_id_ = query_counter++; | 438 autofill_query_id_ = query_counter++; |
| 439 | 439 |
| 440 webkit_glue::FormData form; | 440 webkit::forms::FormData form; |
| 441 webkit_glue::FormField field; | 441 webkit::forms::FormField field; |
| 442 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form, | 442 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form, |
| 443 &field, REQUIRE_AUTOCOMPLETE)) { | 443 &field, REQUIRE_AUTOCOMPLETE)) { |
| 444 return; | 444 return; |
| 445 } | 445 } |
| 446 | 446 |
| 447 autofill_action_ = action; | 447 autofill_action_ = action; |
| 448 was_query_node_autofilled_ = field.is_autofilled; | 448 was_query_node_autofilled_ = field.is_autofilled; |
| 449 Send(new AutofillHostMsg_FillAutofillFormData( | 449 Send(new AutofillHostMsg_FillAutofillFormData( |
| 450 routing_id(), autofill_query_id_, form, field, unique_id)); | 450 routing_id(), autofill_query_id_, form, field, unique_id)); |
| 451 } | 451 } |
| 452 | 452 |
| 453 } // namespace autofill | 453 } // namespace autofill |
| OLD | NEW |