| 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/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/common/autofill_messages.h" | 10 #include "chrome/common/autofill_messages.h" |
| 10 #include "chrome/common/chrome_constants.h" | 11 #include "chrome/common/chrome_constants.h" |
| 11 #include "chrome/renderer/autofill/password_autofill_manager.h" | 12 #include "chrome/renderer/autofill/password_autofill_manager.h" |
| 12 #include "content/renderer/render_view.h" | 13 #include "content/renderer/render_view.h" |
| 13 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement
.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement
.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 94 |
| 94 void AutofillAgent::WillSubmitForm(WebFrame* frame, | 95 void AutofillAgent::WillSubmitForm(WebFrame* frame, |
| 95 const WebFormElement& form) { | 96 const WebFormElement& form) { |
| 96 FormData form_data; | 97 FormData form_data; |
| 97 if (FormManager::WebFormElementToFormData( | 98 if (FormManager::WebFormElementToFormData( |
| 98 form, | 99 form, |
| 99 FormManager::REQUIRE_AUTOCOMPLETE, | 100 FormManager::REQUIRE_AUTOCOMPLETE, |
| 100 static_cast<FormManager::ExtractMask>( | 101 static_cast<FormManager::ExtractMask>( |
| 101 FormManager::EXTRACT_VALUE | FormManager::EXTRACT_OPTION_TEXT), | 102 FormManager::EXTRACT_VALUE | FormManager::EXTRACT_OPTION_TEXT), |
| 102 &form_data)) { | 103 &form_data)) { |
| 103 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data)); | 104 int64 timestamp = base::TimeTicks::Now().ToInternalValue(); |
| 105 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, timestamp)); |
| 104 } | 106 } |
| 105 } | 107 } |
| 106 | 108 |
| 107 void AutofillAgent::FrameTranslated(WebFrame* frame) { | 109 void AutofillAgent::FrameTranslated(WebFrame* frame) { |
| 108 // The page is translated, so try to extract the form data again. | 110 // The page is translated, so try to extract the form data again. |
| 109 DidFinishDocumentLoad(frame); | 111 DidFinishDocumentLoad(frame); |
| 110 } | 112 } |
| 111 | 113 |
| 112 bool AutofillAgent::InputElementClicked(const WebInputElement& element, | 114 bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
| 113 bool was_focused, | 115 bool was_focused, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } | 196 } |
| 195 | 197 |
| 196 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { | 198 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { |
| 197 if (password_autofill_manager_->TextDidChangeInTextField(element)) | 199 if (password_autofill_manager_->TextDidChangeInTextField(element)) |
| 198 return; | 200 return; |
| 199 | 201 |
| 200 ShowSuggestions(element, false, true, false); | 202 ShowSuggestions(element, false, true, false); |
| 201 | 203 |
| 202 webkit_glue::FormData form; | 204 webkit_glue::FormData form; |
| 203 webkit_glue::FormField field; | 205 webkit_glue::FormField field; |
| 204 if (FindFormAndFieldForNode(element, &form, &field)) | 206 if (FindFormAndFieldForNode(element, &form, &field)) { |
| 205 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field)); | 207 int64 timestamp = base::TimeTicks::Now().ToInternalValue(); |
| 208 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, |
| 209 timestamp)); |
| 210 } |
| 206 } | 211 } |
| 207 | 212 |
| 208 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, | 213 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, |
| 209 const WebKeyboardEvent& event) { | 214 const WebKeyboardEvent& event) { |
| 210 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) | 215 if (password_autofill_manager_->TextFieldHandlingKeyDown(element, event)) |
| 211 return; | 216 return; |
| 212 | 217 |
| 213 if (event.windowsKeyCode == ui::VKEY_DOWN || | 218 if (event.windowsKeyCode == ui::VKEY_DOWN || |
| 214 event.windowsKeyCode == ui::VKEY_UP) | 219 event.windowsKeyCode == ui::VKEY_UP) |
| 215 ShowSuggestions(element, true, true, true); | 220 ShowSuggestions(element, true, true, true); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); | 307 has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); |
| 303 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; | 308 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
| 304 } | 309 } |
| 305 | 310 |
| 306 void AutofillAgent::OnFormDataFilled(int query_id, | 311 void AutofillAgent::OnFormDataFilled(int query_id, |
| 307 const webkit_glue::FormData& form) { | 312 const webkit_glue::FormData& form) { |
| 308 if (!render_view()->webview() || query_id != autofill_query_id_) | 313 if (!render_view()->webview() || query_id != autofill_query_id_) |
| 309 return; | 314 return; |
| 310 | 315 |
| 311 switch (autofill_action_) { | 316 switch (autofill_action_) { |
| 312 case AUTOFILL_FILL: | 317 case AUTOFILL_FILL: { |
| 313 form_manager_.FillForm(form, autofill_query_element_); | 318 form_manager_.FillForm(form, autofill_query_element_); |
| 314 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id())); | 319 int64 timestamp = base::TimeTicks::Now().ToInternalValue(); |
| 320 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), |
| 321 timestamp)); |
| 315 break; | 322 break; |
| 323 } |
| 316 case AUTOFILL_PREVIEW: | 324 case AUTOFILL_PREVIEW: |
| 317 form_manager_.PreviewForm(form, autofill_query_element_); | 325 form_manager_.PreviewForm(form, autofill_query_element_); |
| 318 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); | 326 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); |
| 319 break; | 327 break; |
| 320 default: | 328 default: |
| 321 NOTREACHED(); | 329 NOTREACHED(); |
| 322 } | 330 } |
| 323 autofill_action_ = AUTOFILL_NONE; | 331 autofill_action_ = AUTOFILL_NONE; |
| 324 } | 332 } |
| 325 | 333 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // WebFormControlElementToFormField does not scrape the DOM for the field | 426 // WebFormControlElementToFormField does not scrape the DOM for the field |
| 419 // label, so find the label here. | 427 // label, so find the label here. |
| 420 // TODO(isherman): Add form and field identities so we can use the cached form | 428 // TODO(isherman): Add form and field identities so we can use the cached form |
| 421 // data in FormManager. | 429 // data in FormManager. |
| 422 field->label = FormManager::LabelForElement(element); | 430 field->label = FormManager::LabelForElement(element); |
| 423 | 431 |
| 424 return true; | 432 return true; |
| 425 } | 433 } |
| 426 | 434 |
| 427 } // namespace autofill | 435 } // namespace autofill |
| OLD | NEW |