| 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/WebRect.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 23 #include "ui/base/keycodes/keyboard_codes.h" | 24 #include "ui/base/keycodes/keyboard_codes.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "webkit/glue/form_data.h" | 26 #include "webkit/glue/form_data.h" |
| 26 #include "webkit/glue/form_data_predictions.h" | 27 #include "webkit/glue/form_data_predictions.h" |
| 27 #include "webkit/glue/form_field.h" | 28 #include "webkit/glue/form_field.h" |
| 28 #include "webkit/glue/password_form.h" | 29 #include "webkit/glue/password_form.h" |
| 29 | 30 |
| 30 using WebKit::WebFormControlElement; | 31 using WebKit::WebFormControlElement; |
| 31 using WebKit::WebFormElement; | 32 using WebKit::WebFormElement; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 bool AutofillAgent::InputElementClicked(const WebInputElement& element, | 118 bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
| 118 bool was_focused, | 119 bool was_focused, |
| 119 bool is_focused) { | 120 bool is_focused) { |
| 120 if (was_focused) | 121 if (was_focused) |
| 121 ShowSuggestions(element, true, false, true); | 122 ShowSuggestions(element, true, false, true); |
| 122 | 123 |
| 123 return false; | 124 return false; |
| 124 } | 125 } |
| 125 | 126 |
| 126 bool AutofillAgent::InputElementLostFocus() { | 127 bool AutofillAgent::InputElementLostFocus() { |
| 128 Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); |
| 129 |
| 127 return false; | 130 return false; |
| 128 } | 131 } |
| 129 | 132 |
| 130 void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, | 133 void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, |
| 131 const WebString& value, | 134 const WebString& value, |
| 132 const WebString& label, | 135 const WebString& label, |
| 133 int unique_id, | 136 int unique_id, |
| 134 unsigned index) { | 137 unsigned index) { |
| 135 if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) | 138 if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value)) |
| 136 return; | 139 return; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // Append the 'Chrome Autofill options' menu item; | 311 // Append the 'Chrome Autofill options' menu item; |
| 309 v.push_back(l10n_util::GetStringFUTF16(IDS_AUTOFILL_OPTIONS_POPUP, | 312 v.push_back(l10n_util::GetStringFUTF16(IDS_AUTOFILL_OPTIONS_POPUP, |
| 310 WideToUTF16(chrome::kBrowserAppName))); | 313 WideToUTF16(chrome::kBrowserAppName))); |
| 311 l.push_back(string16()); | 314 l.push_back(string16()); |
| 312 i.push_back(string16()); | 315 i.push_back(string16()); |
| 313 ids.push_back(0); | 316 ids.push_back(0); |
| 314 suggestions_options_index_ = v.size() - 1; | 317 suggestions_options_index_ = v.size() - 1; |
| 315 separator_index = values.size(); | 318 separator_index = values.size(); |
| 316 } | 319 } |
| 317 | 320 |
| 318 // Send to WebKit for display. | |
| 319 if (!v.empty() && !autofill_query_element_.isNull() && | 321 if (!v.empty() && !autofill_query_element_.isNull() && |
| 320 autofill_query_element_.isFocusable()) { | 322 autofill_query_element_.isFocusable()) { |
| 323 // Send to WebKit for display. |
| 321 web_view->applyAutofillSuggestions( | 324 web_view->applyAutofillSuggestions( |
| 322 autofill_query_element_, v, l, i, ids, separator_index); | 325 autofill_query_element_, v, l, i, ids, separator_index); |
| 323 } | 326 } |
| 324 | 327 |
| 325 Send(new AutofillHostMsg_DidShowAutofillSuggestions( | 328 Send(new AutofillHostMsg_DidShowAutofillSuggestions( |
| 326 routing_id(), | 329 routing_id(), |
| 327 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); | 330 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); |
| 328 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; | 331 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
| 329 } | 332 } |
| 330 | 333 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 410 |
| 408 webkit_glue::FormData form; | 411 webkit_glue::FormData form; |
| 409 webkit_glue::FormField field; | 412 webkit_glue::FormField field; |
| 410 if (!FindFormAndFieldForInputElement(element, &form, &field, | 413 if (!FindFormAndFieldForInputElement(element, &form, &field, |
| 411 REQUIRE_AUTOCOMPLETE)) { | 414 REQUIRE_AUTOCOMPLETE)) { |
| 412 // If we didn't find the cached form, at least let autocomplete have a shot | 415 // If we didn't find the cached form, at least let autocomplete have a shot |
| 413 // at providing suggestions. | 416 // at providing suggestions. |
| 414 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 417 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
| 415 } | 418 } |
| 416 | 419 |
| 420 // TODO(csharp): This value is currently returned as a page-relative value, |
| 421 // which won't also convert easily to the correct viewport coordinates, so |
| 422 // this should be changed to be a viewport-relative value. |
| 423 gfx::Rect bounding_box(autofill_query_element_.absoluteBoundingBoxRect()); |
| 424 |
| 417 Send(new AutofillHostMsg_QueryFormFieldAutofill( | 425 Send(new AutofillHostMsg_QueryFormFieldAutofill( |
| 418 routing_id(), autofill_query_id_, form, field)); | 426 routing_id(), autofill_query_id_, form, field, bounding_box)); |
| 419 } | 427 } |
| 420 | 428 |
| 421 void AutofillAgent::FillAutofillFormData(const WebNode& node, | 429 void AutofillAgent::FillAutofillFormData(const WebNode& node, |
| 422 int unique_id, | 430 int unique_id, |
| 423 AutofillAction action) { | 431 AutofillAction action) { |
| 424 static int query_counter = 0; | 432 static int query_counter = 0; |
| 425 autofill_query_id_ = query_counter++; | 433 autofill_query_id_ = query_counter++; |
| 426 | 434 |
| 427 webkit_glue::FormData form; | 435 webkit_glue::FormData form; |
| 428 webkit_glue::FormField field; | 436 webkit_glue::FormField field; |
| 429 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form, | 437 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form, |
| 430 &field, REQUIRE_AUTOCOMPLETE)) { | 438 &field, REQUIRE_AUTOCOMPLETE)) { |
| 431 return; | 439 return; |
| 432 } | 440 } |
| 433 | 441 |
| 434 autofill_action_ = action; | 442 autofill_action_ = action; |
| 435 was_query_node_autofilled_ = field.is_autofilled; | 443 was_query_node_autofilled_ = field.is_autofilled; |
| 436 Send(new AutofillHostMsg_FillAutofillFormData( | 444 Send(new AutofillHostMsg_FillAutofillFormData( |
| 437 routing_id(), autofill_query_id_, form, field, unique_id)); | 445 routing_id(), autofill_query_id_, form, field, unique_id)); |
| 438 } | 446 } |
| 439 | 447 |
| 440 } // namespace autofill | 448 } // namespace autofill |
| OLD | NEW |