| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/renderer/autofill_agent.h" | 5 #include "components/autofill/content/renderer/autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "components/autofill/content/common/autofill_messages.h" | 14 #include "components/autofill/content/common/autofill_messages.h" |
| 15 #include "components/autofill/content/renderer/form_autofill_util.h" | 15 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 16 #include "components/autofill/content/renderer/page_click_tracker.h" | 16 #include "components/autofill/content/renderer/page_click_tracker.h" |
| 17 #include "components/autofill/content/renderer/password_autofill_agent.h" | 17 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 18 #include "components/autofill/core/common/autofill_constants.h" | 18 #include "components/autofill/core/common/autofill_constants.h" |
| 19 #include "components/autofill/core/common/autofill_data_sanitizer.h" |
| 19 #include "components/autofill/core/common/autofill_switches.h" | 20 #include "components/autofill/core/common/autofill_switches.h" |
| 20 #include "components/autofill/core/common/form_data.h" | 21 #include "components/autofill/core/common/form_data.h" |
| 21 #include "components/autofill/core/common/form_data_predictions.h" | 22 #include "components/autofill/core/common/form_data_predictions.h" |
| 22 #include "components/autofill/core/common/form_field_data.h" | 23 #include "components/autofill/core/common/form_field_data.h" |
| 23 #include "components/autofill/core/common/password_form.h" | 24 #include "components/autofill/core/common/password_form.h" |
| 24 #include "components/autofill/core/common/web_element_descriptor.h" | 25 #include "components/autofill/core/common/web_element_descriptor.h" |
| 25 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/ssl_status.h" | 27 #include "content/public/common/ssl_status.h" |
| 27 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
| 28 #include "content/public/renderer/render_view.h" | 29 #include "content/public/renderer/render_view.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 47 using blink::WebFormControlElement; | 48 using blink::WebFormControlElement; |
| 48 using blink::WebFormElement; | 49 using blink::WebFormElement; |
| 49 using blink::WebFrame; | 50 using blink::WebFrame; |
| 50 using blink::WebInputElement; | 51 using blink::WebInputElement; |
| 51 using blink::WebKeyboardEvent; | 52 using blink::WebKeyboardEvent; |
| 52 using blink::WebNode; | 53 using blink::WebNode; |
| 53 using blink::WebNodeCollection; | 54 using blink::WebNodeCollection; |
| 54 using blink::WebOptionElement; | 55 using blink::WebOptionElement; |
| 55 using blink::WebString; | 56 using blink::WebString; |
| 56 | 57 |
| 58 namespace autofill { |
| 59 |
| 57 namespace { | 60 namespace { |
| 58 | 61 |
| 59 // The size above which we stop triggering autofill for an input text field | |
| 60 // (so to avoid sending long strings through IPC). | |
| 61 const size_t kMaximumTextSizeForAutofill = 1000; | |
| 62 | |
| 63 // The maximum number of data list elements to send to the browser process | |
| 64 // via IPC (to prevent long IPC messages). | |
| 65 const size_t kMaximumDataListSizeForAutofill = 30; | |
| 66 | |
| 67 | |
| 68 // Gets all the data list values (with corresponding label) for the given | 62 // Gets all the data list values (with corresponding label) for the given |
| 69 // element. | 63 // element. |
| 70 void GetDataListSuggestions(const blink::WebInputElement& element, | 64 void GetDataListSuggestions(const blink::WebInputElement& element, |
| 71 bool ignore_current_value, | 65 bool ignore_current_value, |
| 72 std::vector<base::string16>* values, | 66 std::vector<base::string16>* values, |
| 73 std::vector<base::string16>* labels) { | 67 std::vector<base::string16>* labels) { |
| 74 WebNodeCollection options = element.dataListOptions(); | 68 WebNodeCollection options = element.dataListOptions(); |
| 75 if (options.isNull()) | 69 if (options.isNull()) |
| 76 return; | 70 return; |
| 77 | 71 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 98 labels->push_back(option.label()); | 92 labels->push_back(option.label()); |
| 99 else | 93 else |
| 100 labels->push_back(base::string16()); | 94 labels->push_back(base::string16()); |
| 101 } | 95 } |
| 102 } | 96 } |
| 103 | 97 |
| 104 // Trim the vector before sending it to the browser process to ensure we | 98 // Trim the vector before sending it to the browser process to ensure we |
| 105 // don't send too much data through the IPC. | 99 // don't send too much data through the IPC. |
| 106 void TrimStringVectorForIPC(std::vector<base::string16>* strings) { | 100 void TrimStringVectorForIPC(std::vector<base::string16>* strings) { |
| 107 // Limit the size of the vector. | 101 // Limit the size of the vector. |
| 108 if (strings->size() > kMaximumDataListSizeForAutofill) | 102 if (strings->size() > kMaxListSize) |
| 109 strings->resize(kMaximumDataListSizeForAutofill); | 103 strings->resize(kMaxListSize); |
| 110 | 104 |
| 111 // Limit the size of the strings in the vector. | 105 // Limit the size of the strings in the vector. |
| 112 for (size_t i = 0; i < strings->size(); ++i) { | 106 for (size_t i = 0; i < strings->size(); ++i) { |
| 113 if ((*strings)[i].length() > kMaximumTextSizeForAutofill) | 107 if ((*strings)[i].length() > kMaxDataLength) |
| 114 (*strings)[i].resize(kMaximumTextSizeForAutofill); | 108 (*strings)[i].resize(kMaxDataLength); |
| 115 } | 109 } |
| 116 } | 110 } |
| 117 | 111 |
| 118 gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) { | 112 gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) { |
| 119 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 113 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 120 return gfx::RectF(bounding_box.x() * scale, | 114 return gfx::RectF(bounding_box.x() * scale, |
| 121 bounding_box.y() * scale, | 115 bounding_box.y() * scale, |
| 122 bounding_box.width() * scale, | 116 bounding_box.width() * scale, |
| 123 bounding_box.height() * scale); | 117 bounding_box.height() * scale); |
| 124 } | 118 } |
| 125 | 119 |
| 126 } // namespace | 120 } // namespace |
| 127 | 121 |
| 128 namespace autofill { | |
| 129 | |
| 130 AutofillAgent::AutofillAgent(content::RenderView* render_view, | 122 AutofillAgent::AutofillAgent(content::RenderView* render_view, |
| 131 PasswordAutofillAgent* password_autofill_agent) | 123 PasswordAutofillAgent* password_autofill_agent) |
| 132 : content::RenderViewObserver(render_view), | 124 : content::RenderViewObserver(render_view), |
| 133 password_autofill_agent_(password_autofill_agent), | 125 password_autofill_agent_(password_autofill_agent), |
| 134 autofill_query_id_(0), | 126 autofill_query_id_(0), |
| 135 autofill_action_(AUTOFILL_NONE), | 127 autofill_action_(AUTOFILL_NONE), |
| 136 web_view_(render_view->GetWebView()), | 128 web_view_(render_view->GetWebView()), |
| 137 display_warning_if_disabled_(false), | 129 display_warning_if_disabled_(false), |
| 138 was_query_node_autofilled_(false), | 130 was_query_node_autofilled_(false), |
| 139 has_shown_autofill_popup_for_current_edit_(false), | 131 has_shown_autofill_popup_for_current_edit_(false), |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || | 505 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || |
| 514 element.isPasswordField()) | 506 element.isPasswordField()) |
| 515 return; | 507 return; |
| 516 if (!datalist_only && !element.suggestedValue().isEmpty()) | 508 if (!datalist_only && !element.suggestedValue().isEmpty()) |
| 517 return; | 509 return; |
| 518 | 510 |
| 519 // Don't attempt to autofill with values that are too large or if filling | 511 // Don't attempt to autofill with values that are too large or if filling |
| 520 // criteria are not met. | 512 // criteria are not met. |
| 521 WebString value = element.editingValue(); | 513 WebString value = element.editingValue(); |
| 522 if (!datalist_only && | 514 if (!datalist_only && |
| 523 (value.length() > kMaximumTextSizeForAutofill || | 515 (value.length() > kMaxDataLength || |
| 524 (!autofill_on_empty_values && value.isEmpty()) || | 516 (!autofill_on_empty_values && value.isEmpty()) || |
| 525 (requires_caret_at_end && | 517 (requires_caret_at_end && |
| 526 (element.selectionStart() != element.selectionEnd() || | 518 (element.selectionStart() != element.selectionEnd() || |
| 527 element.selectionEnd() != static_cast<int>(value.length()))))) { | 519 element.selectionEnd() != static_cast<int>(value.length()))))) { |
| 528 // Any popup currently showing is obsolete. | 520 // Any popup currently showing is obsolete. |
| 529 HideAutofillUI(); | 521 HideAutofillUI(); |
| 530 return; | 522 return; |
| 531 } | 523 } |
| 532 | 524 |
| 533 element_ = element; | 525 element_ = element; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 // Only monitors dynamic forms created in the top frame. Dynamic forms | 635 // Only monitors dynamic forms created in the top frame. Dynamic forms |
| 644 // inserted in iframes are not captured yet. | 636 // inserted in iframes are not captured yet. |
| 645 if (!frame->parent()) { | 637 if (!frame->parent()) { |
| 646 password_autofill_agent_->OnDynamicFormsSeen(frame); | 638 password_autofill_agent_->OnDynamicFormsSeen(frame); |
| 647 return; | 639 return; |
| 648 } | 640 } |
| 649 } | 641 } |
| 650 } | 642 } |
| 651 | 643 |
| 652 } // namespace autofill | 644 } // namespace autofill |
| OLD | NEW |