[email protected] | 66f9052c | 2012-01-06 00:07:36 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 5 | #include "components/autofill/renderer/autofill_agent.h" |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 6 | |
[email protected] | a1cb57f | 2011-09-28 22:41:29 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 9 | #include "base/message_loop.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 10 | #include "base/string_util.h" |
[email protected] | 1988e1c | 2013-02-28 20:27:42 | [diff] [blame] | 11 | #include "base/strings/string_split.h" |
[email protected] | 1d14f58 | 2011-09-02 20:42:04 | [diff] [blame] | 12 | #include "base/time.h" |
[email protected] | 2377cafe | 2010-10-27 01:19:08 | [diff] [blame] | 13 | #include "base/utf_string_conversions.h" |
[email protected] | edf48d4 | 2013-03-07 05:44:43 | [diff] [blame] | 14 | #include "components/autofill/common/autocheckout_status.h" |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 15 | #include "components/autofill/common/autofill_constants.h" |
[email protected] | edf48d4 | 2013-03-07 05:44:43 | [diff] [blame] | 16 | #include "components/autofill/common/autofill_messages.h" |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 17 | #include "components/autofill/common/autofill_switches.h" |
[email protected] | edf48d4 | 2013-03-07 05:44:43 | [diff] [blame] | 18 | #include "components/autofill/common/form_data.h" |
| 19 | #include "components/autofill/common/form_data_predictions.h" |
| 20 | #include "components/autofill/common/form_field_data.h" |
| 21 | #include "components/autofill/common/web_element_descriptor.h" |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 22 | #include "components/autofill/renderer/form_autofill_util.h" |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 23 | #include "components/autofill/renderer/password_autofill_agent.h" |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 24 | #include "content/public/common/password_form.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 25 | #include "content/public/common/ssl_status.h" |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 26 | #include "content/public/renderer/render_view.h" |
[email protected] | ff73301 | 2012-01-30 17:44:36 | [diff] [blame] | 27 | #include "grit/chromium_strings.h" |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 28 | #include "grit/generated_resources.h" |
[email protected] | cff498e | 2013-01-10 01:03:02 | [diff] [blame] | 29 | #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 30 | #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 31 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 32 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 33 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 34 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 35 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
[email protected] | a22f7e0 | 2011-02-09 07:15:35 | [diff] [blame] | 36 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
[email protected] | aaa80c9 | 2011-09-16 00:23:54 | [diff] [blame] | 37 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 38 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeCollection.h" |
| 39 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebOptionElement.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 40 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 41 | #include "ui/base/keycodes/keyboard_codes.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 42 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 43 | |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 44 | using components::autofill::kRequiredAutofillFields; |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 45 | using WebKit::WebAutofillClient; |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 46 | using WebKit::WebFormControlElement; |
| 47 | using WebKit::WebFormElement; |
| 48 | using WebKit::WebFrame; |
| 49 | using WebKit::WebInputElement; |
[email protected] | 7aab84b | 2010-11-20 01:04:26 | [diff] [blame] | 50 | using WebKit::WebKeyboardEvent; |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 51 | using WebKit::WebNode; |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 52 | using WebKit::WebNodeCollection; |
| 53 | using WebKit::WebOptionElement; |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 54 | using WebKit::WebString; |
| 55 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 56 | namespace { |
| 57 | |
| 58 | // The size above which we stop triggering autofill for an input text field |
| 59 | // (so to avoid sending long strings through IPC). |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 60 | const size_t kMaximumTextSizeForAutofill = 1000; |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 61 | |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 62 | // The maximum number of data list elements to send to the browser process |
| 63 | // via IPC (to prevent long IPC messages). |
| 64 | const size_t kMaximumDataListSizeForAutofill = 30; |
| 65 | |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 66 | const int kAutocheckoutClickTimeout = 3; |
| 67 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 68 | void AppendDataListSuggestions(const WebKit::WebInputElement& element, |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 69 | std::vector<base::string16>* values, |
| 70 | std::vector<base::string16>* labels, |
| 71 | std::vector<base::string16>* icons, |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 72 | std::vector<int>* item_ids) { |
| 73 | WebNodeCollection options = element.dataListOptions(); |
| 74 | if (options.isNull()) |
| 75 | return; |
| 76 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 77 | base::string16 prefix = element.editingValue(); |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 78 | if (element.isMultiple() && |
| 79 | element.formControlType() == WebString::fromUTF8("email")) { |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 80 | std::vector<base::string16> parts; |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 81 | base::SplitStringDontTrim(prefix, ',', &parts); |
| 82 | if (parts.size() > 0) |
| 83 | TrimWhitespace(parts[parts.size() - 1], TRIM_LEADING, &prefix); |
| 84 | } |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 85 | for (WebOptionElement option = options.firstItem().to<WebOptionElement>(); |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 86 | !option.isNull(); option = options.nextItem().to<WebOptionElement>()) { |
| 87 | if (!StartsWith(option.value(), prefix, false) || |
| 88 | option.value() == prefix || |
[email protected] | 3f81263 | 2012-05-16 04:13:36 | [diff] [blame] | 89 | !element.isValidValue(option.value())) |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 90 | continue; |
| 91 | |
| 92 | values->push_back(option.value()); |
| 93 | if (option.value() != option.label()) |
| 94 | labels->push_back(option.label()); |
| 95 | else |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 96 | labels->push_back(base::string16()); |
| 97 | icons->push_back(base::string16()); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 98 | item_ids->push_back(WebAutofillClient::MenuItemIDDataListEntry); |
| 99 | } |
| 100 | } |
| 101 | |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 102 | // Trim the vectors before sending them to the browser process to ensure we |
| 103 | // don't send too much data through the IPC. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 104 | void TrimDataListsForIPC(std::vector<base::string16>* values, |
| 105 | std::vector<base::string16>* labels, |
| 106 | std::vector<base::string16>* icons, |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 107 | std::vector<int>* unique_ids) { |
| 108 | // Limit the size of the vectors. |
| 109 | if (values->size() > kMaximumDataListSizeForAutofill) { |
| 110 | values->resize(kMaximumDataListSizeForAutofill); |
| 111 | labels->resize(kMaximumDataListSizeForAutofill); |
| 112 | icons->resize(kMaximumDataListSizeForAutofill); |
| 113 | unique_ids->resize(kMaximumDataListSizeForAutofill); |
| 114 | } |
| 115 | |
| 116 | // Limit the size of the strings in the vectors |
| 117 | for (size_t i = 0; i < values->size(); ++i) { |
| 118 | if ((*values)[i].length() > kMaximumTextSizeForAutofill) |
| 119 | (*values)[i].resize(kMaximumTextSizeForAutofill); |
| 120 | |
| 121 | if ((*labels)[i].length() > kMaximumTextSizeForAutofill) |
| 122 | (*labels)[i].resize(kMaximumTextSizeForAutofill); |
| 123 | |
| 124 | if ((*icons)[i].length() > kMaximumTextSizeForAutofill) |
| 125 | (*icons)[i].resize(kMaximumTextSizeForAutofill); |
| 126 | } |
| 127 | } |
| 128 | |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 129 | gfx::RectF GetScaledBoundingBox(float scale, WebInputElement* element) { |
| 130 | gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 131 | return gfx::RectF(bounding_box.x() * scale, |
| 132 | bounding_box.y() * scale, |
| 133 | bounding_box.width() * scale, |
| 134 | bounding_box.height() * scale); |
| 135 | } |
| 136 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 137 | } // namespace |
| 138 | |
[email protected] | 7819208 | 2011-01-29 05:43:44 | [diff] [blame] | 139 | namespace autofill { |
| 140 | |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 141 | AutofillAgent::AutofillAgent(content::RenderView* render_view, |
| 142 | PasswordAutofillAgent* password_autofill_agent) |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 143 | : content::RenderViewObserver(render_view), |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 144 | password_autofill_agent_(password_autofill_agent), |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 145 | autofill_query_id_(0), |
| 146 | autofill_action_(AUTOFILL_NONE), |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 147 | topmost_frame_(NULL), |
[email protected] | 73a087f | 2013-02-06 07:02:06 | [diff] [blame] | 148 | web_view_(render_view->GetWebView()), |
[email protected] | 6bcd58a | 2010-11-25 02:31:20 | [diff] [blame] | 149 | display_warning_if_disabled_(false), |
[email protected] | d77ddc806 | 2010-11-24 01:14:06 | [diff] [blame] | 150 | was_query_node_autofilled_(false), |
[email protected] | e4dce0af | 2011-09-19 22:22:28 | [diff] [blame] | 151 | has_shown_autofill_popup_for_current_edit_(false), |
[email protected] | b37043c | 2012-05-31 17:08:12 | [diff] [blame] | 152 | did_set_node_text_(false), |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 153 | autocheckout_click_in_progress_(false), |
[email protected] | 8a5b3869 | 2013-03-27 07:03:56 | [diff] [blame] | 154 | is_whitelisted_for_autocheckout_(false), |
[email protected] | 90f2625 | 2013-02-15 19:48:32 | [diff] [blame] | 155 | ignore_text_changes_(false), |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 156 | ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 157 | render_view->GetWebView()->setAutofillClient(this); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 160 | AutofillAgent::~AutofillAgent() {} |
[email protected] | d2f05d0 | 2011-01-27 18:51:01 | [diff] [blame] | 161 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 162 | bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 163 | bool handled = true; |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 164 | IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message) |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 165 | IPC_MESSAGE_HANDLER(AutofillMsg_GetAllForms, OnGetAllForms) |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 166 | IPC_MESSAGE_HANDLER(AutofillMsg_SuggestionsReturned, OnSuggestionsReturned) |
| 167 | IPC_MESSAGE_HANDLER(AutofillMsg_FormDataFilled, OnFormDataFilled) |
[email protected] | 3eb5728c | 2011-06-20 22:32:24 | [diff] [blame] | 168 | IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable, |
| 169 | OnFieldTypePredictionsAvailable) |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 170 | IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionFill, |
| 171 | OnSetAutofillActionFill) |
| 172 | IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, |
| 173 | OnClearForm) |
| 174 | IPC_MESSAGE_HANDLER(AutofillMsg_SetAutofillActionPreview, |
| 175 | OnSetAutofillActionPreview) |
| 176 | IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, |
| 177 | OnClearPreviewedForm) |
| 178 | IPC_MESSAGE_HANDLER(AutofillMsg_SetNodeText, |
| 179 | OnSetNodeText) |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 180 | IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion, |
| 181 | OnAcceptDataListSuggestion) |
[email protected] | e7e8347 | 2012-04-05 02:56:26 | [diff] [blame] | 182 | IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, |
| 183 | OnAcceptPasswordAutofillSuggestion) |
[email protected] | 82fc1b1 | 2013-01-12 00:53:56 | [diff] [blame] | 184 | IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteResult, |
| 185 | OnRequestAutocompleteResult) |
[email protected] | d3ae9ed4 | 2013-01-14 23:31:01 | [diff] [blame] | 186 | IPC_MESSAGE_HANDLER(AutofillMsg_FillFormsAndClick, |
| 187 | OnFillFormsAndClick) |
[email protected] | 8a5b3869 | 2013-03-27 07:03:56 | [diff] [blame] | 188 | IPC_MESSAGE_HANDLER(AutofillMsg_WhitelistedForAutocheckout, |
| 189 | OnWhitelistedForAutocheckout) |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 190 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 191 | IPC_END_MESSAGE_MAP() |
| 192 | return handled; |
| 193 | } |
| 194 | |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 195 | void AutofillAgent::DidFinishDocumentLoad(WebFrame* frame) { |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 196 | // Record timestamp on document load. This is used to record overhead of |
| 197 | // Autofill feature. |
| 198 | forms_seen_timestamp_ = base::TimeTicks::Now(); |
| 199 | |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 200 | // The document has now been fully loaded. Scan for forms to be sent up to |
| 201 | // the browser. |
| 202 | std::vector<FormData> forms; |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 203 | bool has_more_forms = false; |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 204 | if (!frame->parent()) { |
| 205 | topmost_frame_ = frame; |
| 206 | form_elements_.clear(); |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 207 | has_more_forms = form_cache_.ExtractFormsAndFormElements( |
| 208 | *frame, kRequiredAutofillFields, &forms, &form_elements_); |
[email protected] | 8a5b3869 | 2013-03-27 07:03:56 | [diff] [blame] | 209 | is_whitelisted_for_autocheckout_ = false; |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 210 | } else { |
| 211 | form_cache_.ExtractForms(*frame, &forms); |
| 212 | } |
| 213 | |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 214 | // Always communicate to browser process for topmost frame. |
| 215 | if (!forms.empty() || !frame->parent()) { |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 216 | Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 217 | forms_seen_timestamp_, |
| 218 | has_more_forms)); |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 219 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 222 | void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { |
| 223 | if (!frame->parent()) { |
| 224 | topmost_frame_ = NULL; |
[email protected] | 6f99d221 | 2013-03-29 21:16:29 | [diff] [blame] | 225 | if (click_timer_.IsRunning()) { |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 226 | click_timer_.Stop(); |
| 227 | autocheckout_click_in_progress_ = true; |
| 228 | } |
| 229 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 230 | } |
| 231 | |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 232 | void AutofillAgent::DidFailProvisionalLoad(WebFrame* frame, |
| 233 | const WebKit::WebURLError& error) { |
[email protected] | 6f99d221 | 2013-03-29 21:16:29 | [diff] [blame] | 234 | if (!frame->parent() && autocheckout_click_in_progress_) { |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 235 | autocheckout_click_in_progress_ = false; |
| 236 | ClickFailed(); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | void AutofillAgent::DidCommitProvisionalLoad(WebFrame* frame, |
| 241 | bool is_new_navigation) { |
[email protected] | 364481b | 2013-01-29 01:52:28 | [diff] [blame] | 242 | in_flight_request_form_.reset(); |
[email protected] | 6f99d221 | 2013-03-29 21:16:29 | [diff] [blame] | 243 | if (!frame->parent()) |
| 244 | autocheckout_click_in_progress_ = false; |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void AutofillAgent::FrameDetached(WebFrame* frame) { |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 248 | form_cache_.ResetFrame(*frame); |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 249 | if (!frame->parent()) { |
| 250 | // |frame| is about to be destroyed so we need to clear |top_most_frame_|. |
| 251 | topmost_frame_ = NULL; |
| 252 | click_timer_.Stop(); |
| 253 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 254 | } |
| 255 | |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 256 | void AutofillAgent::WillSubmitForm(WebFrame* frame, |
| 257 | const WebFormElement& form) { |
| 258 | FormData form_data; |
[email protected] | aaa80c9 | 2011-09-16 00:23:54 | [diff] [blame] | 259 | if (WebFormElementToFormData(form, |
| 260 | WebFormControlElement(), |
| 261 | REQUIRE_AUTOCOMPLETE, |
| 262 | static_cast<ExtractMask>( |
| 263 | EXTRACT_VALUE | EXTRACT_OPTION_TEXT), |
| 264 | &form_data, |
| 265 | NULL)) { |
[email protected] | 1d14f58 | 2011-09-02 20:42:04 | [diff] [blame] | 266 | Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data, |
| 267 | base::TimeTicks::Now())); |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 271 | void AutofillAgent::ZoomLevelChanged() { |
| 272 | // Any time the zoom level changes, the page's content moves, so any Autofill |
| 273 | // popups should be hidden. This is only needed for the new Autofill UI |
| 274 | // because WebKit already knows to hide the old UI when this occurs. |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 275 | HideHostAutofillUi(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 276 | } |
| 277 | |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 278 | void AutofillAgent::FocusedNodeChanged(const WebKit::WebNode& node) { |
[email protected] | 8a5b3869 | 2013-03-27 07:03:56 | [diff] [blame] | 279 | if (!is_whitelisted_for_autocheckout_) |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 280 | return; |
| 281 | |
| 282 | if (node.isNull() || !node.isElementNode()) |
| 283 | return; |
| 284 | |
| 285 | WebKit::WebElement web_element = node.toConst<WebKit::WebElement>(); |
| 286 | |
| 287 | if (!web_element.document().frame()) |
| 288 | return; |
| 289 | |
| 290 | const WebInputElement* element = toWebInputElement(&web_element); |
| 291 | |
| 292 | if (!element || !element->isEnabled() || element->isReadOnly() || |
| 293 | !element->isTextField() || element->isPasswordField()) |
| 294 | return; |
| 295 | |
| 296 | FormData form; |
| 297 | FormFieldData field; |
| 298 | // This must be called to short circuit this method if it fails. |
| 299 | if (!FindFormAndFieldForInputElement(*element, &form, &field, REQUIRE_NONE)) |
| 300 | return; |
| 301 | |
| 302 | content::SSLStatus ssl_status = render_view()->GetSSLStatusOfFrame( |
| 303 | element->document().frame()); |
| 304 | |
| 305 | element_ = *element; |
| 306 | |
| 307 | Send(new AutofillHostMsg_MaybeShowAutocheckoutBubble( |
| 308 | routing_id(), |
| 309 | form.origin, |
| 310 | ssl_status, |
| 311 | GetScaledBoundingBox(web_view_->pageScaleFactor(), &element_))); |
| 312 | } |
| 313 | |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 314 | void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) { |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 315 | HideAutofillUi(); |
[email protected] | 2b942c33 | 2012-04-25 16:26:26 | [diff] [blame] | 316 | } |
| 317 | |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 318 | void AutofillAgent::didRequestAutocomplete(WebKit::WebFrame* frame, |
| 319 | const WebFormElement& form) { |
| 320 | FormData form_data; |
| 321 | if (!in_flight_request_form_.isNull() || |
| 322 | !WebFormElementToFormData(form, |
| 323 | WebFormControlElement(), |
| 324 | REQUIRE_AUTOCOMPLETE, |
[email protected] | b570fd4 | 2012-12-04 22:14:13 | [diff] [blame] | 325 | EXTRACT_OPTIONS, |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 326 | &form_data, |
| 327 | NULL)) { |
| 328 | WebFormElement(form).finishRequestAutocomplete( |
[email protected] | 82fc1b1 | 2013-01-12 00:53:56 | [diff] [blame] | 329 | WebFormElement::AutocompleteResultErrorDisabled); |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 330 | return; |
| 331 | } |
| 332 | |
| 333 | // Cancel any pending Autofill requests and hide any currently showing popups. |
| 334 | ++autofill_query_id_; |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 335 | HideAutofillUi(); |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 336 | |
| 337 | in_flight_request_form_ = form; |
[email protected] | fa17237d | 2013-03-21 12:58:03 | [diff] [blame] | 338 | // Add SSL Status in the formdata to let browser process alert user |
| 339 | // appropriately using browser UI. |
| 340 | form_data.ssl_status = render_view()->GetSSLStatusOfFrame(frame); |
[email protected] | e449521 | 2012-12-06 03:09:12 | [diff] [blame] | 341 | Send(new AutofillHostMsg_RequestAutocomplete( |
| 342 | routing_id(), |
| 343 | form_data, |
[email protected] | fa17237d | 2013-03-21 12:58:03 | [diff] [blame] | 344 | frame->document().url())); |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 345 | } |
| 346 | |
[email protected] | 90f2625 | 2013-02-15 19:48:32 | [diff] [blame] | 347 | void AutofillAgent::setIgnoreTextChanges(bool ignore) { |
| 348 | ignore_text_changes_ = ignore; |
| 349 | } |
| 350 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 351 | bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
[email protected] | 7819208 | 2011-01-29 05:43:44 | [diff] [blame] | 352 | bool was_focused, |
| 353 | bool is_focused) { |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 354 | if (was_focused) |
| 355 | ShowSuggestions(element, true, false, true); |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 356 | |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 357 | return false; |
| 358 | } |
| 359 | |
[email protected] | 65ec8db | 2011-11-04 14:50:44 | [diff] [blame] | 360 | bool AutofillAgent::InputElementLostFocus() { |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 361 | HideHostAutofillUi(); |
[email protected] | 9718305 | 2011-11-17 16:35:22 | [diff] [blame] | 362 | |
[email protected] | 65ec8db | 2011-11-04 14:50:44 | [diff] [blame] | 363 | return false; |
| 364 | } |
| 365 | |
[email protected] | 3d07d6b | 2011-07-13 00:25:00 | [diff] [blame] | 366 | void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 367 | const WebString& value, |
| 368 | const WebString& label, |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 369 | int item_id, |
[email protected] | 7819208 | 2011-01-29 05:43:44 | [diff] [blame] | 370 | unsigned index) { |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 371 | if (password_autofill_agent_->DidAcceptAutofillSuggestion(node, value)) |
[email protected] | b43c135 | 2011-03-04 23:55:34 | [diff] [blame] | 372 | return; |
| 373 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 374 | DCHECK(node == element_); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 375 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 376 | switch (item_id) { |
| 377 | case WebAutofillClient::MenuItemIDWarningMessage: |
| 378 | case WebAutofillClient::MenuItemIDSeparator: |
| 379 | NOTREACHED(); |
| 380 | break; |
| 381 | case WebAutofillClient::MenuItemIDAutofillOptions: |
| 382 | // User selected 'Autofill Options'. |
| 383 | Send(new AutofillHostMsg_ShowAutofillDialog(routing_id())); |
| 384 | break; |
| 385 | case WebAutofillClient::MenuItemIDClearForm: |
| 386 | // User selected 'Clear form'. |
| 387 | form_cache_.ClearFormWithElement(element_); |
| 388 | break; |
| 389 | case WebAutofillClient::MenuItemIDAutocompleteEntry: |
| 390 | case WebAutofillClient::MenuItemIDPasswordEntry: |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 391 | // User selected an Autocomplete or password entry, so we fill directly. |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 392 | SetNodeText(value, &element_); |
| 393 | break; |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 394 | case WebAutofillClient::MenuItemIDDataListEntry: |
| 395 | AcceptDataListSuggestion(value); |
| 396 | break; |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 397 | default: |
| 398 | // A positive item_id is a unique id for an autofill (vs. autocomplete) |
| 399 | // suggestion. |
| 400 | DCHECK_GT(item_id, 0); |
| 401 | // Fill the values for the whole form. |
| 402 | FillAutofillFormData(node, item_id, AUTOFILL_FILL); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 403 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 404 | } |
| 405 | |
[email protected] | 3d07d6b | 2011-07-13 00:25:00 | [diff] [blame] | 406 | void AutofillAgent::didSelectAutofillSuggestion(const WebNode& node, |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 407 | const WebString& value, |
| 408 | const WebString& label, |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 409 | int item_id) { |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 410 | if (password_autofill_agent_->DidSelectAutofillSuggestion(node)) |
[email protected] | fc1964a | 2011-01-20 19:33:07 | [diff] [blame] | 411 | return; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 412 | |
[email protected] | 3d07d6b | 2011-07-13 00:25:00 | [diff] [blame] | 413 | didClearAutofillSelection(node); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 414 | |
| 415 | if (item_id > 0) |
| 416 | FillAutofillFormData(node, item_id, AUTOFILL_PREVIEW); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 417 | } |
| 418 | |
[email protected] | 3d07d6b | 2011-07-13 00:25:00 | [diff] [blame] | 419 | void AutofillAgent::didClearAutofillSelection(const WebNode& node) { |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 420 | if (password_autofill_agent_->DidClearAutofillSelection(node)) |
[email protected] | 6075d050 | 2011-09-13 02:10:21 | [diff] [blame] | 421 | return; |
| 422 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 423 | if (!element_.isNull() && node == element_) { |
| 424 | ClearPreviewedFormWithElement(element_, was_query_node_autofilled_); |
[email protected] | 091b222 | 2011-09-14 02:52:55 | [diff] [blame] | 425 | } else { |
| 426 | // TODO(isherman): There seem to be rare cases where this code *is* |
| 427 | // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would |
| 428 | // understand those cases and fix the code to avoid them. However, so far I |
| 429 | // have been unable to reproduce such a case locally. If you hit this |
| 430 | // NOTREACHED(), please file a bug against me. |
| 431 | NOTREACHED(); |
| 432 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 433 | } |
| 434 | |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 435 | void AutofillAgent::removeAutocompleteSuggestion(const WebString& name, |
| 436 | const WebString& value) { |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 437 | Send(new AutofillHostMsg_RemoveAutocompleteEntry(routing_id(), name, value)); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 438 | } |
| 439 | |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 440 | void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 441 | password_autofill_agent_->TextFieldDidEndEditing(element); |
[email protected] | 7d24db7 | 2011-08-26 06:02:31 | [diff] [blame] | 442 | has_shown_autofill_popup_for_current_edit_ = false; |
[email protected] | 2739e0e | 2011-11-22 22:49:11 | [diff] [blame] | 443 | Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 444 | } |
| 445 | |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 446 | void AutofillAgent::textFieldDidChange(const WebInputElement& element) { |
[email protected] | 90f2625 | 2013-02-15 19:48:32 | [diff] [blame] | 447 | if (ignore_text_changes_) |
| 448 | return; |
| 449 | |
[email protected] | b37043c | 2012-05-31 17:08:12 | [diff] [blame] | 450 | if (did_set_node_text_) { |
[email protected] | b96a1d1 | 2012-11-30 22:44:32 | [diff] [blame] | 451 | did_set_node_text_ = false; |
| 452 | return; |
[email protected] | b37043c | 2012-05-31 17:08:12 | [diff] [blame] | 453 | } |
| 454 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 455 | // We post a task for doing the Autofill as the caret position is not set |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 456 | // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and |
| 457 | // it is needed to trigger autofill. |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 458 | weak_ptr_factory_.InvalidateWeakPtrs(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 459 | MessageLoop::current()->PostTask( |
| 460 | FROM_HERE, |
[email protected] | a1cb57f | 2011-09-28 22:41:29 | [diff] [blame] | 461 | base::Bind(&AutofillAgent::TextFieldDidChangeImpl, |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 462 | weak_ptr_factory_.GetWeakPtr(), element)); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 463 | } |
| 464 | |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 465 | void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { |
[email protected] | f9af283 | 2012-12-14 04:20:43 | [diff] [blame] | 466 | // If the element isn't focused then the changes don't matter. This check is |
| 467 | // required to properly handle IME interactions. |
| 468 | if (!element.focused()) |
| 469 | return; |
| 470 | |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 471 | if (password_autofill_agent_->TextDidChangeInTextField(element)) { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 472 | element_ = element; |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 473 | return; |
[email protected] | e7e8347 | 2012-04-05 02:56:26 | [diff] [blame] | 474 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 475 | |
| 476 | ShowSuggestions(element, false, true, false); |
[email protected] | 7d24db7 | 2011-08-26 06:02:31 | [diff] [blame] | 477 | |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 478 | FormData form; |
| 479 | FormFieldData field; |
[email protected] | 283ba4ca | 2011-09-22 05:25:08 | [diff] [blame] | 480 | if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { |
[email protected] | 1d14f58 | 2011-09-02 20:42:04 | [diff] [blame] | 481 | Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, |
| 482 | base::TimeTicks::Now())); |
| 483 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 484 | } |
| 485 | |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 486 | void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, |
| 487 | const WebKeyboardEvent& event) { |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 488 | if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 489 | element_ = element; |
[email protected] | fc1964a | 2011-01-20 19:33:07 | [diff] [blame] | 490 | return; |
[email protected] | e7e8347 | 2012-04-05 02:56:26 | [diff] [blame] | 491 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 492 | |
| 493 | if (event.windowsKeyCode == ui::VKEY_DOWN || |
| 494 | event.windowsKeyCode == ui::VKEY_UP) |
| 495 | ShowSuggestions(element, true, true, true); |
| 496 | } |
| 497 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 498 | void AutofillAgent::OnSuggestionsReturned( |
| 499 | int query_id, |
| 500 | const std::vector<base::string16>& values, |
| 501 | const std::vector<base::string16>& labels, |
| 502 | const std::vector<base::string16>& icons, |
| 503 | const std::vector<int>& unique_ids) { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 504 | if (query_id != autofill_query_id_) |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 505 | return; |
| 506 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 507 | if (element_.isNull() || !element_.isFocusable()) |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 508 | return; |
| 509 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 510 | std::vector<base::string16> v(values); |
| 511 | std::vector<base::string16> l(labels); |
| 512 | std::vector<base::string16> i(icons); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 513 | std::vector<int> ids(unique_ids); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 514 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 515 | if (!element_.autoComplete() && !v.empty()) { |
[email protected] | cd0a3b7 | 2011-08-02 06:16:19 | [diff] [blame] | 516 | // If autofill is disabled and we had suggestions, show a warning instead. |
| 517 | v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 518 | l.assign(1, base::string16()); |
| 519 | i.assign(1, base::string16()); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 520 | ids.assign(1, WebAutofillClient::MenuItemIDWarningMessage); |
| 521 | } else if (ids.size() > 1 && |
| 522 | ids[0] == WebAutofillClient::MenuItemIDWarningMessage) { |
| 523 | // If we received an autofill warning plus some autocomplete suggestions, |
| 524 | // remove the autofill warning. |
[email protected] | 1866d06 | 2010-11-16 06:19:56 | [diff] [blame] | 525 | v.erase(v.begin()); |
| 526 | l.erase(l.begin()); |
| 527 | i.erase(i.begin()); |
| 528 | ids.erase(ids.begin()); |
| 529 | } |
| 530 | |
[email protected] | 6bcd58a | 2010-11-25 02:31:20 | [diff] [blame] | 531 | // If we were about to show a warning and we shouldn't, don't. |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 532 | if (!display_warning_if_disabled_ && !v.empty() && |
| 533 | ids[0] == WebAutofillClient::MenuItemIDWarningMessage) { |
| 534 | v.clear(); |
| 535 | l.clear(); |
| 536 | i.clear(); |
| 537 | ids.clear(); |
| 538 | } |
[email protected] | 6bcd58a | 2010-11-25 02:31:20 | [diff] [blame] | 539 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 540 | // Only include "Autofill Options" special menu item if we have Autofill |
[email protected] | 4f03a2d3 | 2010-12-01 01:49:36 | [diff] [blame] | 541 | // items, identified by |unique_ids| having at least one valid value. |
| 542 | bool has_autofill_item = false; |
| 543 | for (size_t i = 0; i < ids.size(); ++i) { |
| 544 | if (ids[i] > 0) { |
| 545 | has_autofill_item = true; |
| 546 | break; |
| 547 | } |
| 548 | } |
| 549 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 550 | if (has_autofill_item) { |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 551 | v.push_back(base::string16()); |
| 552 | l.push_back(base::string16()); |
| 553 | i.push_back(base::string16()); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 554 | ids.push_back(WebAutofillClient::MenuItemIDSeparator); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 555 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 556 | if (FormWithElementIsAutofilled(element_)) { |
| 557 | // The form has been auto-filled, so give the user the chance to clear the |
| 558 | // form. Append the 'Clear form' menu item. |
| 559 | v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 560 | l.push_back(base::string16()); |
| 561 | i.push_back(base::string16()); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 562 | ids.push_back(WebAutofillClient::MenuItemIDClearForm); |
| 563 | } |
| 564 | |
[email protected] | 2377cafe | 2010-10-27 01:19:08 | [diff] [blame] | 565 | // Append the 'Chrome Autofill options' menu item; |
[email protected] | ff73301 | 2012-01-30 17:44:36 | [diff] [blame] | 566 | v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 567 | l.push_back(base::string16()); |
| 568 | i.push_back(base::string16()); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 569 | ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions); |
| 570 | } |
| 571 | |
| 572 | CombineDataListEntriesAndShow(element_, v, l, i, ids, has_autofill_item); |
| 573 | } |
| 574 | |
| 575 | void AutofillAgent::CombineDataListEntriesAndShow( |
| 576 | const WebKit::WebInputElement& element, |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 577 | const std::vector<base::string16>& values, |
| 578 | const std::vector<base::string16>& labels, |
| 579 | const std::vector<base::string16>& icons, |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 580 | const std::vector<int>& item_ids, |
| 581 | bool has_autofill_item) { |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 582 | std::vector<base::string16> v; |
| 583 | std::vector<base::string16> l; |
| 584 | std::vector<base::string16> i; |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 585 | std::vector<int> ids; |
| 586 | |
| 587 | AppendDataListSuggestions(element, &v, &l, &i, &ids); |
| 588 | |
| 589 | // If there are both <datalist> items and Autofill suggestions, add a |
| 590 | // separator between them. |
| 591 | if (!v.empty() && !values.empty()) { |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 592 | v.push_back(base::string16()); |
| 593 | l.push_back(base::string16()); |
| 594 | i.push_back(base::string16()); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 595 | ids.push_back(WebAutofillClient::MenuItemIDSeparator); |
| 596 | } |
| 597 | |
| 598 | // Append the Autofill suggestions. |
| 599 | v.insert(v.end(), values.begin(), values.end()); |
| 600 | l.insert(l.end(), labels.begin(), labels.end()); |
| 601 | i.insert(i.end(), icons.begin(), icons.end()); |
| 602 | ids.insert(ids.end(), item_ids.begin(), item_ids.end()); |
| 603 | |
[email protected] | ef47f9a | 2012-11-06 04:40:09 | [diff] [blame] | 604 | if (v.empty()) { |
| 605 | // No suggestions, any popup currently showing is obsolete. |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 606 | HideAutofillUi(); |
[email protected] | ef47f9a | 2012-11-06 04:40:09 | [diff] [blame] | 607 | return; |
| 608 | } |
| 609 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 610 | WebKit::WebView* web_view = render_view()->GetWebView(); |
| 611 | if (!web_view) |
| 612 | return; |
| 613 | |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 614 | // Send to WebKit for display. |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 615 | web_view->applyAutofillSuggestions(element, v, l, i, ids); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 616 | |
[email protected] | 7d24db7 | 2011-08-26 06:02:31 | [diff] [blame] | 617 | Send(new AutofillHostMsg_DidShowAutofillSuggestions( |
| 618 | routing_id(), |
| 619 | has_autofill_item && !has_shown_autofill_popup_for_current_edit_)); |
| 620 | has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 621 | } |
| 622 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 623 | void AutofillAgent::AcceptDataListSuggestion( |
| 624 | const base::string16& suggested_value) { |
| 625 | base::string16 new_value = suggested_value; |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 626 | // If this element takes multiple values then replace the last part with |
| 627 | // the suggestion. |
| 628 | if (element_.isMultiple() && |
| 629 | element_.formControlType() == WebString::fromUTF8("email")) { |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 630 | std::vector<base::string16> parts; |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 631 | |
| 632 | base::SplitStringDontTrim(element_.editingValue(), ',', &parts); |
| 633 | if (parts.size() == 0) |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 634 | parts.push_back(base::string16()); |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 635 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 636 | base::string16 last_part = parts.back(); |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 637 | // We want to keep just the leading whitespace. |
| 638 | for (size_t i = 0; i < last_part.size(); ++i) { |
| 639 | if (!IsWhitespace(last_part[i])) { |
| 640 | last_part = last_part.substr(0, i); |
| 641 | break; |
| 642 | } |
| 643 | } |
| 644 | last_part.append(suggested_value); |
| 645 | parts[parts.size() - 1] = last_part; |
| 646 | |
| 647 | new_value = JoinString(parts, ','); |
| 648 | } |
| 649 | SetNodeText(new_value, &element_); |
| 650 | } |
| 651 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 652 | void AutofillAgent::OnFormDataFilled(int query_id, |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 653 | const FormData& form) { |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 654 | if (!render_view()->GetWebView() || query_id != autofill_query_id_) |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 655 | return; |
| 656 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 657 | was_query_node_autofilled_ = element_.isAutofilled(); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 658 | |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 659 | switch (autofill_action_) { |
| 660 | case AUTOFILL_FILL: |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 661 | FillForm(form, element_); |
[email protected] | 1d14f58 | 2011-09-02 20:42:04 | [diff] [blame] | 662 | Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), |
| 663 | base::TimeTicks::Now())); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 664 | break; |
| 665 | case AUTOFILL_PREVIEW: |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 666 | PreviewForm(form, element_); |
[email protected] | 7d24db7 | 2011-08-26 06:02:31 | [diff] [blame] | 667 | Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 668 | break; |
| 669 | default: |
| 670 | NOTREACHED(); |
| 671 | } |
| 672 | autofill_action_ = AUTOFILL_NONE; |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 673 | } |
| 674 | |
[email protected] | 3eb5728c | 2011-06-20 22:32:24 | [diff] [blame] | 675 | void AutofillAgent::OnFieldTypePredictionsAvailable( |
| 676 | const std::vector<FormDataPredictions>& forms) { |
| 677 | for (size_t i = 0; i < forms.size(); ++i) { |
[email protected] | aaa80c9 | 2011-09-16 00:23:54 | [diff] [blame] | 678 | form_cache_.ShowPredictions(forms[i]); |
[email protected] | 3eb5728c | 2011-06-20 22:32:24 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 682 | void AutofillAgent::OnSetAutofillActionFill() { |
| 683 | autofill_action_ = AUTOFILL_FILL; |
| 684 | } |
| 685 | |
| 686 | void AutofillAgent::OnClearForm() { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 687 | form_cache_.ClearFormWithElement(element_); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | void AutofillAgent::OnSetAutofillActionPreview() { |
| 691 | autofill_action_ = AUTOFILL_PREVIEW; |
| 692 | } |
| 693 | |
| 694 | void AutofillAgent::OnClearPreviewedForm() { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 695 | didClearAutofillSelection(element_); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 696 | } |
| 697 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 698 | void AutofillAgent::OnSetNodeText(const base::string16& value) { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 699 | SetNodeText(value, &element_); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 700 | } |
| 701 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 702 | void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 703 | AcceptDataListSuggestion(value); |
| 704 | } |
| 705 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 706 | void AutofillAgent::OnAcceptPasswordAutofillSuggestion( |
| 707 | const base::string16& value) { |
[email protected] | e7e8347 | 2012-04-05 02:56:26 | [diff] [blame] | 708 | // We need to make sure this is handled here because the browser process |
| 709 | // skipped it handling because it believed it would be handled here. If it |
| 710 | // isn't handled here then the browser logic needs to be updated. |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 711 | bool handled = password_autofill_agent_->DidAcceptAutofillSuggestion( |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 712 | element_, |
[email protected] | e7e8347 | 2012-04-05 02:56:26 | [diff] [blame] | 713 | value); |
| 714 | DCHECK(handled); |
| 715 | } |
| 716 | |
[email protected] | 8acc196 | 2013-03-17 07:04:52 | [diff] [blame] | 717 | void AutofillAgent::OnGetAllForms() { |
| 718 | form_elements_.clear(); |
| 719 | |
| 720 | // Force fetch all non empty forms. |
| 721 | std::vector<FormData> forms; |
| 722 | form_cache_.ExtractFormsAndFormElements( |
| 723 | *topmost_frame_, 0, &forms, &form_elements_); |
| 724 | |
| 725 | // OnGetAllForms should only be called if AutofillAgent reported to |
| 726 | // AutofillManager that there are more forms |
| 727 | DCHECK(!forms.empty()); |
| 728 | |
| 729 | // Report to AutofillManager that all forms are being sent. |
| 730 | Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
| 731 | forms_seen_timestamp_, false)); |
| 732 | } |
| 733 | |
[email protected] | 82fc1b1 | 2013-01-12 00:53:56 | [diff] [blame] | 734 | void AutofillAgent::OnRequestAutocompleteResult( |
| 735 | WebFormElement::AutocompleteResult result, const FormData& form_data) { |
[email protected] | 364481b | 2013-01-29 01:52:28 | [diff] [blame] | 736 | if (in_flight_request_form_.isNull()) |
| 737 | return; |
| 738 | |
[email protected] | 82fc1b1 | 2013-01-12 00:53:56 | [diff] [blame] | 739 | if (result == WebFormElement::AutocompleteResultSuccess) |
| 740 | FillFormIncludingNonFocusableElements(form_data, in_flight_request_form_); |
[email protected] | 364481b | 2013-01-29 01:52:28 | [diff] [blame] | 741 | |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 742 | in_flight_request_form_.finishRequestAutocomplete(result); |
| 743 | in_flight_request_form_.reset(); |
| 744 | } |
| 745 | |
[email protected] | d3ae9ed4 | 2013-01-14 23:31:01 | [diff] [blame] | 746 | void AutofillAgent::OnFillFormsAndClick( |
[email protected] | 1469691 | 2013-02-04 05:37:02 | [diff] [blame] | 747 | const std::vector<FormData>& forms, |
[email protected] | d3ae9ed4 | 2013-01-14 23:31:01 | [diff] [blame] | 748 | const WebElementDescriptor& click_element_descriptor) { |
[email protected] | 1469691 | 2013-02-04 05:37:02 | [diff] [blame] | 749 | DCHECK_EQ(forms.size(), form_elements_.size()); |
| 750 | |
| 751 | // Fill the form. |
| 752 | for (size_t i = 0; i < forms.size(); ++i) |
| 753 | FillFormIncludingNonFocusableElements(forms[i], form_elements_[i]); |
[email protected] | d3ae9ed4 | 2013-01-14 23:31:01 | [diff] [blame] | 754 | |
[email protected] | 6f99d221 | 2013-03-29 21:16:29 | [diff] [blame] | 755 | // Exit early if there is nothing to click. |
| 756 | if (click_element_descriptor.retrieval_method == WebElementDescriptor::NONE) |
| 757 | return; |
| 758 | |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 759 | // It's possible that clicking the element to proceed in an Autocheckout |
| 760 | // flow will not actually proceed to the next step in the flow, e.g. there |
| 761 | // is a new required field that Autocheckout does not know how to fill. In |
| 762 | // order to capture this case and present the user with an error a timer is |
| 763 | // set that informs the browser of the error. |click_timer_| has to be started |
| 764 | // before clicking so it can start before DidStartProvisionalLoad started. |
| 765 | click_timer_.Start(FROM_HERE, |
| 766 | base::TimeDelta::FromSeconds(kAutocheckoutClickTimeout), |
| 767 | this, |
| 768 | &AutofillAgent::ClickFailed); |
| 769 | if (!ClickElement(topmost_frame_->document(), |
| 770 | click_element_descriptor)) { |
| 771 | click_timer_.Stop(); |
| 772 | Send(new AutofillHostMsg_ClickFailed(routing_id(), |
| 773 | MISSING_ADVANCE)); |
| 774 | } |
| 775 | } |
| 776 | |
[email protected] | 8a5b3869 | 2013-03-27 07:03:56 | [diff] [blame] | 777 | void AutofillAgent::OnWhitelistedForAutocheckout() { |
| 778 | is_whitelisted_for_autocheckout_ = true; |
| 779 | } |
| 780 | |
[email protected] | d7908be | 2013-01-22 16:50:18 | [diff] [blame] | 781 | void AutofillAgent::ClickFailed() { |
| 782 | Send(new AutofillHostMsg_ClickFailed(routing_id(), |
| 783 | CANNOT_PROCEED)); |
[email protected] | d3ae9ed4 | 2013-01-14 23:31:01 | [diff] [blame] | 784 | } |
| 785 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 786 | void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
[email protected] | 7819208 | 2011-01-29 05:43:44 | [diff] [blame] | 787 | bool autofill_on_empty_values, |
| 788 | bool requires_caret_at_end, |
| 789 | bool display_warning_if_disabled) { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 790 | if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || |
| 791 | element.isPasswordField() || !element.suggestedValue().isEmpty()) |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 792 | return; |
| 793 | |
[email protected] | 1c69f8b7 | 2012-03-14 03:18:50 | [diff] [blame] | 794 | // Don't attempt to autofill with values that are too large or if filling |
| 795 | // criteria are not met. |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 796 | WebString value = element.editingValue(); |
[email protected] | 1c69f8b7 | 2012-03-14 03:18:50 | [diff] [blame] | 797 | if (value.length() > kMaximumTextSizeForAutofill || |
| 798 | (!autofill_on_empty_values && value.isEmpty()) || |
| 799 | (requires_caret_at_end && |
| 800 | (element.selectionStart() != element.selectionEnd() || |
| 801 | element.selectionEnd() != static_cast<int>(value.length())))) { |
| 802 | // Any popup currently showing is obsolete. |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 803 | HideAutofillUi(); |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 804 | return; |
[email protected] | 1c69f8b7 | 2012-03-14 03:18:50 | [diff] [blame] | 805 | } |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 806 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 807 | element_ = element; |
[email protected] | c66ba98 | 2013-04-05 09:56:17 | [diff] [blame] | 808 | if (password_autofill_agent_->ShowSuggestions(element)) |
| 809 | return; |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 810 | |
[email protected] | 5af43c13 | 2012-11-06 07:03:44 | [diff] [blame] | 811 | // If autocomplete is disabled at the form level, then we might want to show a |
| 812 | // warning in place of suggestions. However, if autocomplete is disabled |
| 813 | // specifically for this field, we never want to show a warning. Otherwise, |
| 814 | // we might interfere with custom popups (e.g. search suggestions) used by the |
| 815 | // website. Note that we cannot use the WebKit method element.autoComplete() |
| 816 | // as it does not allow us to distinguish the case where autocomplete is |
| 817 | // disabled for *both* the element and for the form. |
| 818 | // Also, if the field has no name, then we won't have values. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 819 | const base::string16 autocomplete_attribute = |
| 820 | element.getAttribute("autocomplete"); |
[email protected] | 5af43c13 | 2012-11-06 07:03:44 | [diff] [blame] | 821 | if (LowerCaseEqualsASCII(autocomplete_attribute, "off") || |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 822 | element.nameForAutofill().isEmpty()) { |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 823 | CombineDataListEntriesAndShow(element, std::vector<base::string16>(), |
| 824 | std::vector<base::string16>(), |
| 825 | std::vector<base::string16>(), |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 826 | std::vector<int>(), false); |
| 827 | return; |
| 828 | } |
| 829 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 830 | QueryAutofillSuggestions(element, display_warning_if_disabled); |
[email protected] | 77bb0da | 2010-11-20 01:55:30 | [diff] [blame] | 831 | } |
| 832 | |
[email protected] | cd0a3b7 | 2011-08-02 06:16:19 | [diff] [blame] | 833 | void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, |
[email protected] | 7819208 | 2011-01-29 05:43:44 | [diff] [blame] | 834 | bool display_warning_if_disabled) { |
[email protected] | e69b5f7 | 2013-01-24 00:59:13 | [diff] [blame] | 835 | if (!element.document().frame()) |
| 836 | return; |
| 837 | |
[email protected] | 77bb0da | 2010-11-20 01:55:30 | [diff] [blame] | 838 | static int query_counter = 0; |
| 839 | autofill_query_id_ = query_counter++; |
[email protected] | 6bcd58a | 2010-11-25 02:31:20 | [diff] [blame] | 840 | display_warning_if_disabled_ = display_warning_if_disabled; |
[email protected] | 77bb0da | 2010-11-20 01:55:30 | [diff] [blame] | 841 | |
[email protected] | 5af43c13 | 2012-11-06 07:03:44 | [diff] [blame] | 842 | // If autocomplete is disabled at the form level, we want to see if there |
| 843 | // would have been any suggestions were it enabled, so that we can show a |
| 844 | // warning. Otherwise, we want to ignore fields that disable autocomplete, so |
| 845 | // that the suggestions list does not include suggestions for these form |
| 846 | // fields -- see comment 1 on http://crbug.com/69914 |
| 847 | // Rather than testing the form's autocomplete enabled state, we test the |
| 848 | // element's state. The DCHECK below ensures that this is equivalent. |
| 849 | DCHECK(element.autoComplete() || !element.form().autoComplete()); |
| 850 | const RequirementsMask requirements = |
| 851 | element.autoComplete() ? REQUIRE_AUTOCOMPLETE : REQUIRE_NONE; |
| 852 | |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 853 | FormData form; |
| 854 | FormFieldData field; |
[email protected] | 5af43c13 | 2012-11-06 07:03:44 | [diff] [blame] | 855 | if (!FindFormAndFieldForInputElement(element, &form, &field, requirements)) { |
[email protected] | 7837be6 | 2011-01-18 23:45:08 | [diff] [blame] | 856 | // If we didn't find the cached form, at least let autocomplete have a shot |
| 857 | // at providing suggestions. |
[email protected] | aaa80c9 | 2011-09-16 00:23:54 | [diff] [blame] | 858 | WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
[email protected] | 7837be6 | 2011-01-18 23:45:08 | [diff] [blame] | 859 | } |
[email protected] | 77bb0da | 2010-11-20 01:55:30 | [diff] [blame] | 860 | |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 861 | gfx::RectF bounding_box_scaled = |
| 862 | GetScaledBoundingBox(web_view_->pageScaleFactor(), &element_); |
[email protected] | 73a087f | 2013-02-06 07:02:06 | [diff] [blame] | 863 | |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 864 | // Find the datalist values and send them to the browser process. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 865 | std::vector<base::string16> data_list_values; |
| 866 | std::vector<base::string16> data_list_labels; |
| 867 | std::vector<base::string16> data_list_icons; |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 868 | std::vector<int> data_list_unique_ids; |
| 869 | AppendDataListSuggestions(element_, |
| 870 | &data_list_values, |
| 871 | &data_list_labels, |
| 872 | &data_list_icons, |
| 873 | &data_list_unique_ids); |
| 874 | |
| 875 | TrimDataListsForIPC(&data_list_values, |
| 876 | &data_list_labels, |
| 877 | &data_list_icons, |
| 878 | &data_list_unique_ids); |
| 879 | |
| 880 | Send(new AutofillHostMsg_SetDataList(routing_id(), |
| 881 | data_list_values, |
| 882 | data_list_labels, |
| 883 | data_list_icons, |
| 884 | data_list_unique_ids)); |
| 885 | |
[email protected] | e899b96 | 2013-01-18 20:52:08 | [diff] [blame] | 886 | // Add SSL Status in the formdata to let browser process alert user |
| 887 | // appropriately using browser UI. |
| 888 | form.ssl_status = render_view()->GetSSLStatusOfFrame( |
| 889 | element.document().frame()); |
[email protected] | 2739e0e | 2011-11-22 22:49:11 | [diff] [blame] | 890 | Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), |
| 891 | autofill_query_id_, |
| 892 | form, |
| 893 | field, |
[email protected] | 73a087f | 2013-02-06 07:02:06 | [diff] [blame] | 894 | bounding_box_scaled, |
[email protected] | 2739e0e | 2011-11-22 22:49:11 | [diff] [blame] | 895 | display_warning_if_disabled)); |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 896 | } |
| 897 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 898 | void AutofillAgent::FillAutofillFormData(const WebNode& node, |
[email protected] | 7819208 | 2011-01-29 05:43:44 | [diff] [blame] | 899 | int unique_id, |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 900 | AutofillAction action) { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 901 | DCHECK_GT(unique_id, 0); |
| 902 | |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 903 | static int query_counter = 0; |
| 904 | autofill_query_id_ = query_counter++; |
| 905 | |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 906 | FormData form; |
| 907 | FormFieldData field; |
[email protected] | 283ba4ca | 2011-09-22 05:25:08 | [diff] [blame] | 908 | if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form, |
| 909 | &field, REQUIRE_AUTOCOMPLETE)) { |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 910 | return; |
[email protected] | 283ba4ca | 2011-09-22 05:25:08 | [diff] [blame] | 911 | } |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 912 | |
| 913 | autofill_action_ = action; |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 914 | Send(new AutofillHostMsg_FillAutofillFormData( |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 915 | routing_id(), autofill_query_id_, form, field, unique_id)); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 916 | } |
| 917 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 918 | void AutofillAgent::SetNodeText(const base::string16& value, |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 919 | WebKit::WebInputElement* node) { |
[email protected] | b37043c | 2012-05-31 17:08:12 | [diff] [blame] | 920 | did_set_node_text_ = true; |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame^] | 921 | base::string16 substring = value; |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 922 | substring = substring.substr(0, node->maxLength()); |
| 923 | |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 924 | node->setEditingValue(substring); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 925 | } |
| 926 | |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 927 | void AutofillAgent::HideAutofillUi() { |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 928 | WebKit::WebView* web_view = render_view()->GetWebView(); |
| 929 | if (web_view) |
| 930 | web_view->hidePopups(); |
[email protected] | ef47f9a | 2012-11-06 04:40:09 | [diff] [blame] | 931 | |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 932 | HideHostAutofillUi(); |
[email protected] | ef47f9a | 2012-11-06 04:40:09 | [diff] [blame] | 933 | } |
| 934 | |
[email protected] | 136fc918 | 2013-03-11 22:11:34 | [diff] [blame] | 935 | void AutofillAgent::HideHostAutofillUi() { |
| 936 | Send(new AutofillHostMsg_HideAutofillUi(routing_id())); |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 937 | } |
| 938 | |
[email protected] | 7819208 | 2011-01-29 05:43:44 | [diff] [blame] | 939 | } // namespace autofill |