[email protected] | f07e444 | 2013-06-06 23:03:48 | [diff] [blame] | 1 | // Copyright 2013 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] | f07e444 | 2013-06-06 23:03:48 | [diff] [blame] | 5 | #include "components/autofill/content/renderer/autofill_agent.h" |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 6 | |
avi | 4310d52 | 2015-12-25 19:37:59 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
brettw | 9c68c51 | 2015-11-20 23:26:38 | [diff] [blame] | 9 | #include <tuple> |
| 10 | |
rouslan | 6a3f8d9 | 2015-04-28 01:00:01 | [diff] [blame] | 11 | #include "base/auto_reset.h" |
[email protected] | a1cb57f | 2011-09-28 22:41:29 | [diff] [blame] | 12 | #include "base/bind.h" |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 13 | #include "base/command_line.h" |
brettw | 94a2cc2 | 2015-07-01 19:26:54 | [diff] [blame] | 14 | #include "base/i18n/case_conversion.h" |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 15 | #include "base/location.h" |
mathp | 4f6b038 | 2016-04-12 20:41:12 | [diff] [blame] | 16 | #include "base/metrics/field_trial.h" |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 17 | #include "base/single_thread_task_runner.h" |
mgiuca | 30f7588 | 2017-03-28 02:07:19 | [diff] [blame] | 18 | #include "base/strings/string_piece.h" |
[email protected] | 1988e1c | 2013-02-28 20:27:42 | [diff] [blame] | 19 | #include "base/strings/string_split.h" |
[email protected] | c72674b | 2013-06-11 04:16:43 | [diff] [blame] | 20 | #include "base/strings/string_util.h" |
[email protected] | d2d79d5 | 2013-06-07 22:23:48 | [diff] [blame] | 21 | #include "base/strings/utf_string_conversions.h" |
gab | 7966d31 | 2016-05-11 20:35:01 | [diff] [blame] | 22 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | bbd8da9 | 2013-06-28 02:12:20 | [diff] [blame] | 23 | #include "base/time/time.h" |
avi | 4310d52 | 2015-12-25 19:37:59 | [diff] [blame] | 24 | #include "build/build_config.h" |
[email protected] | f07e444 | 2013-06-06 23:03:48 | [diff] [blame] | 25 | #include "components/autofill/content/renderer/form_autofill_util.h" |
[email protected] | f07e444 | 2013-06-06 23:03:48 | [diff] [blame] | 26 | #include "components/autofill/content/renderer/password_autofill_agent.h" |
[email protected] | 3cbdf936 | 2014-01-31 23:12:23 | [diff] [blame] | 27 | #include "components/autofill/content/renderer/password_generation_agent.h" |
jww | fb2a143 | 2016-06-13 22:44:15 | [diff] [blame] | 28 | #include "components/autofill/content/renderer/renderer_save_password_progress_logger.h" |
[email protected] | d04f8191 | 2013-06-18 14:52:13 | [diff] [blame] | 29 | #include "components/autofill/core/common/autofill_constants.h" |
[email protected] | d86263dcd | 2014-01-09 10:35:21 | [diff] [blame] | 30 | #include "components/autofill/core/common/autofill_data_validation.h" |
[email protected] | d04f8191 | 2013-06-18 14:52:13 | [diff] [blame] | 31 | #include "components/autofill/core/common/autofill_switches.h" |
rouslan | c31f81d | 2015-08-24 17:33:52 | [diff] [blame] | 32 | #include "components/autofill/core/common/autofill_util.h" |
[email protected] | d04f8191 | 2013-06-18 14:52:13 | [diff] [blame] | 33 | #include "components/autofill/core/common/form_data.h" |
| 34 | #include "components/autofill/core/common/form_data_predictions.h" |
| 35 | #include "components/autofill/core/common/form_field_data.h" |
[email protected] | e620d36 | 2013-09-09 08:01:53 | [diff] [blame] | 36 | #include "components/autofill/core/common/password_form.h" |
jww | fb2a143 | 2016-06-13 22:44:15 | [diff] [blame] | 37 | #include "components/autofill/core/common/password_form_fill_data.h" |
| 38 | #include "components/autofill/core/common/save_password_progress_logger.h" |
[email protected] | fed9d4f | 2013-12-17 21:32:47 | [diff] [blame] | 39 | #include "content/public/common/content_switches.h" |
[email protected] | ca5190f | 2013-07-08 11:10:31 | [diff] [blame] | 40 | #include "content/public/common/url_constants.h" |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 41 | #include "content/public/renderer/render_frame.h" |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 42 | #include "content/public/renderer/render_view.h" |
[email protected] | ca5190f | 2013-07-08 11:10:31 | [diff] [blame] | 43 | #include "net/cert/cert_status_flags.h" |
ben | 803dba30 | 2017-04-27 20:41:49 | [diff] [blame] | 44 | #include "services/service_manager/public/cpp/binder_registry.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 45 | #include "services/service_manager/public/cpp/interface_provider.h" |
dtapuska | a64845d | 2017-01-20 21:20:45 | [diff] [blame] | 46 | #include "third_party/WebKit/public/platform/WebKeyboardEvent.h" |
[email protected] | f07e444 | 2013-06-06 23:03:48 | [diff] [blame] | 47 | #include "third_party/WebKit/public/platform/WebURLRequest.h" |
[email protected] | dbdd6027 | 2014-04-14 22:48:40 | [diff] [blame] | 48 | #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
[email protected] | a0962a9 | 2013-06-20 18:27:34 | [diff] [blame] | 49 | #include "third_party/WebKit/public/web/WebDataSource.h" |
| 50 | #include "third_party/WebKit/public/web/WebDocument.h" |
[email protected] | 961783a | 2014-02-07 18:38:05 | [diff] [blame] | 51 | #include "third_party/WebKit/public/web/WebElementCollection.h" |
[email protected] | a0962a9 | 2013-06-20 18:27:34 | [diff] [blame] | 52 | #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 53 | #include "third_party/WebKit/public/web/WebFormElement.h" |
[email protected] | 8050465 | 2014-04-18 04:41:50 | [diff] [blame] | 54 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
[email protected] | a0962a9 | 2013-06-20 18:27:34 | [diff] [blame] | 55 | #include "third_party/WebKit/public/web/WebNode.h" |
[email protected] | a0962a9 | 2013-06-20 18:27:34 | [diff] [blame] | 56 | #include "third_party/WebKit/public/web/WebOptionElement.h" |
rouslan | 6a3f8d9 | 2015-04-28 01:00:01 | [diff] [blame] | 57 | #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
[email protected] | a0962a9 | 2013-06-20 18:27:34 | [diff] [blame] | 58 | #include "third_party/WebKit/public/web/WebView.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 59 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 7e9acd08 | 2013-09-17 23:31:16 | [diff] [blame] | 60 | #include "ui/events/keycodes/keyboard_codes.h" |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 61 | |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 62 | using blink::WebAutofillClient; |
[email protected] | dbdd6027 | 2014-04-14 22:48:40 | [diff] [blame] | 63 | using blink::WebConsoleMessage; |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 64 | using blink::WebDocument; |
[email protected] | 5e7e861 | 2014-03-20 14:43:19 | [diff] [blame] | 65 | using blink::WebElement; |
| 66 | using blink::WebElementCollection; |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 67 | using blink::WebFormControlElement; |
| 68 | using blink::WebFormElement; |
| 69 | using blink::WebFrame; |
| 70 | using blink::WebInputElement; |
| 71 | using blink::WebKeyboardEvent; |
[email protected] | c5041c32 | 2014-04-08 05:06:47 | [diff] [blame] | 72 | using blink::WebLocalFrame; |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 73 | using blink::WebNode; |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 74 | using blink::WebOptionElement; |
| 75 | using blink::WebString; |
rouslan | 6a3f8d9 | 2015-04-28 01:00:01 | [diff] [blame] | 76 | using blink::WebUserGestureIndicator; |
[email protected] | 5e7e861 | 2014-03-20 14:43:19 | [diff] [blame] | 77 | using blink::WebVector; |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 78 | |
[email protected] | d86263dcd | 2014-01-09 10:35:21 | [diff] [blame] | 79 | namespace autofill { |
| 80 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 81 | namespace { |
| 82 | |
mathp | 4f6b038 | 2016-04-12 20:41:12 | [diff] [blame] | 83 | // Whether the "single click" autofill feature is enabled, through command-line |
| 84 | // or field trial. |
| 85 | bool IsSingleClickEnabled() { |
| 86 | // On Android, default to showing the dropdown on field focus. |
| 87 | // On desktop, require an extra click after field focus by default, unless the |
| 88 | // experiment is active. |
| 89 | #if defined(OS_ANDROID) |
| 90 | return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 91 | switches::kDisableSingleClickAutofill); |
| 92 | #endif |
| 93 | const std::string group_name = |
| 94 | base::FieldTrialList::FindFullName("AutofillSingleClick"); |
| 95 | |
| 96 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 97 | switches::kEnableSingleClickAutofill)) |
| 98 | return true; |
| 99 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 100 | switches::kDisableSingleClickAutofill)) |
| 101 | return false; |
| 102 | |
| 103 | return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); |
| 104 | } |
| 105 | |
[email protected] | 45a0794 | 2013-07-26 08:28:21 | [diff] [blame] | 106 | // Gets all the data list values (with corresponding label) for the given |
| 107 | // element. |
[email protected] | 5e7e861 | 2014-03-20 14:43:19 | [diff] [blame] | 108 | void GetDataListSuggestions(const WebInputElement& element, |
[email protected] | 45a0794 | 2013-07-26 08:28:21 | [diff] [blame] | 109 | std::vector<base::string16>* values, |
| 110 | std::vector<base::string16>* labels) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 111 | for (const auto& option : element.FilteredDataListOptions()) { |
| 112 | values->push_back(option.Value().Utf16()); |
| 113 | if (option.Value() != option.Label()) |
| 114 | labels->push_back(option.Label().Utf16()); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 115 | else |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 116 | labels->push_back(base::string16()); |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
[email protected] | ead7fb0 | 2013-07-18 18:50:12 | [diff] [blame] | 120 | // Trim the vector before sending it to the browser process to ensure we |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 121 | // don't send too much data through the IPC. |
[email protected] | ead7fb0 | 2013-07-18 18:50:12 | [diff] [blame] | 122 | void TrimStringVectorForIPC(std::vector<base::string16>* strings) { |
| 123 | // Limit the size of the vector. |
[email protected] | d86263dcd | 2014-01-09 10:35:21 | [diff] [blame] | 124 | if (strings->size() > kMaxListSize) |
| 125 | strings->resize(kMaxListSize); |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 126 | |
[email protected] | ead7fb0 | 2013-07-18 18:50:12 | [diff] [blame] | 127 | // Limit the size of the strings in the vector. |
| 128 | for (size_t i = 0; i < strings->size(); ++i) { |
[email protected] | d86263dcd | 2014-01-09 10:35:21 | [diff] [blame] | 129 | if ((*strings)[i].length() > kMaxDataLength) |
| 130 | (*strings)[i].resize(kMaxDataLength); |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 134 | } // namespace |
| 135 | |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 136 | AutofillAgent::ShowSuggestionsOptions::ShowSuggestionsOptions() |
| 137 | : autofill_on_empty_values(false), |
| 138 | requires_caret_at_end(false), |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 139 | show_full_suggestion_list(false), |
| 140 | show_password_suggestions_only(false) { |
| 141 | } |
| 142 | |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 143 | AutofillAgent::AutofillAgent(content::RenderFrame* render_frame, |
[email protected] | 3cbdf936 | 2014-01-31 23:12:23 | [diff] [blame] | 144 | PasswordAutofillAgent* password_autofill_agent, |
| 145 | PasswordGenerationAgent* password_generation_agent) |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 146 | : content::RenderFrameObserver(render_frame), |
estade | ff02e6d | 2014-12-15 21:18:31 | [diff] [blame] | 147 | form_cache_(*render_frame->GetWebFrame()), |
[email protected] | ad19b30 | 2013-04-03 07:42:19 | [diff] [blame] | 148 | password_autofill_agent_(password_autofill_agent), |
[email protected] | 3cbdf936 | 2014-01-31 23:12:23 | [diff] [blame] | 149 | password_generation_agent_(password_generation_agent), |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 150 | autofill_query_id_(0), |
[email protected] | d77ddc806 | 2010-11-24 01:14:06 | [diff] [blame] | 151 | was_query_node_autofilled_(false), |
[email protected] | 90f2625 | 2013-02-15 19:48:32 | [diff] [blame] | 152 | ignore_text_changes_(false), |
[email protected] | b648f24 | 2014-02-25 13:49:06 | [diff] [blame] | 153 | is_popup_possibly_visible_(false), |
gcasto | cdd33e0d | 2015-06-17 22:10:05 | [diff] [blame] | 154 | is_generation_popup_possibly_visible_(false), |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 155 | page_click_tracker_(new PageClickTracker(render_frame, this)), |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 156 | binding_(this), |
[email protected] | 2c30525 | 2013-04-26 19:57:05 | [diff] [blame] | 157 | weak_ptr_factory_(this) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 158 | render_frame->GetWebFrame()->SetAutofillClient(this); |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 159 | password_autofill_agent->SetAutofillAgent(this); |
estade | 78d655f8 | 2015-01-30 01:55:08 | [diff] [blame] | 160 | |
leon.han | de85290 | 2016-05-04 09:16:38 | [diff] [blame] | 161 | // AutofillAgent is guaranteed to outlive |render_frame|. |
ben | 155ecf8 | 2016-06-21 22:43:26 | [diff] [blame] | 162 | render_frame->GetInterfaceRegistry()->AddInterface( |
leon.han | de85290 | 2016-05-04 09:16:38 | [diff] [blame] | 163 | base::Bind(&AutofillAgent::BindRequest, base::Unretained(this))); |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 164 | } |
| 165 | |
[email protected] | a64fdc3 | 2013-07-31 09:21:13 | [diff] [blame] | 166 | AutofillAgent::~AutofillAgent() {} |
[email protected] | d2f05d0 | 2011-01-27 18:51:01 | [diff] [blame] | 167 | |
leon.han | de85290 | 2016-05-04 09:16:38 | [diff] [blame] | 168 | void AutofillAgent::BindRequest(mojom::AutofillAgentRequest request) { |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 169 | binding_.Bind(std::move(request)); |
leon.han | de85290 | 2016-05-04 09:16:38 | [diff] [blame] | 170 | } |
| 171 | |
mathp | 692aba8 | 2015-03-06 20:55:02 | [diff] [blame] | 172 | bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs, |
| 173 | const FormData& rhs) const { |
brettw | 9c68c51 | 2015-11-20 23:26:38 | [diff] [blame] | 174 | return std::tie(lhs.name, lhs.origin, lhs.action, lhs.is_form_tag) < |
| 175 | std::tie(rhs.name, rhs.origin, rhs.action, rhs.is_form_tag); |
mathp | 692aba8 | 2015-03-06 20:55:02 | [diff] [blame] | 176 | } |
| 177 | |
mlamouri | 9ef14c2 | 2015-02-27 13:30:54 | [diff] [blame] | 178 | void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation, |
eugenebut | 5ae751e | 2017-03-28 17:10:37 | [diff] [blame] | 179 | bool is_same_document_navigation) { |
mathp | ffc78e2 | 2015-09-01 14:10:50 | [diff] [blame] | 180 | blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 181 | // TODO(dvadym): check if we need to check if it is main frame navigation |
| 182 | // http://crbug.com/443155 |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 183 | if (frame->Parent()) |
mathp | ffc78e2 | 2015-09-01 14:10:50 | [diff] [blame] | 184 | return; // Not a top-level navigation. |
| 185 | |
eugenebut | 5ae751e | 2017-03-28 17:10:37 | [diff] [blame] | 186 | if (is_same_document_navigation) { |
| 187 | OnSameDocumentNavigationCompleted(); |
rouslan | 6f1f93c | 2015-10-07 22:17:30 | [diff] [blame] | 188 | } else { |
| 189 | // Navigation to a new page or a page refresh. |
mathp | ffc78e2 | 2015-09-01 14:10:50 | [diff] [blame] | 190 | form_cache_.Reset(); |
| 191 | submitted_forms_.clear(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 192 | last_interacted_form_.Reset(); |
tmartino | 283dda1 | 2016-06-23 21:43:54 | [diff] [blame] | 193 | formless_elements_user_edited_.clear(); |
mathp | ffc78e2 | 2015-09-01 14:10:50 | [diff] [blame] | 194 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 195 | } |
| 196 | |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 197 | void AutofillAgent::DidFinishDocumentLoad() { |
| 198 | ProcessForms(); |
[email protected] | 3609c96 | 2014-07-11 03:18:25 | [diff] [blame] | 199 | } |
| 200 | |
mathp | 692aba8 | 2015-03-06 20:55:02 | [diff] [blame] | 201 | void AutofillAgent::WillSendSubmitEvent(const WebFormElement& form) { |
tmartino | 1c5348c9 | 2016-05-26 18:50:56 | [diff] [blame] | 202 | FireHostSubmitEvents(form, /*form_submitted=*/false); |
mathp | 692aba8 | 2015-03-06 20:55:02 | [diff] [blame] | 203 | } |
| 204 | |
estade | 13da3e4 | 2014-12-18 02:10:24 | [diff] [blame] | 205 | void AutofillAgent::WillSubmitForm(const WebFormElement& form) { |
tmartino | 1c5348c9 | 2016-05-26 18:50:56 | [diff] [blame] | 206 | FireHostSubmitEvents(form, /*form_submitted=*/true); |
[email protected] | 2a5b173 | 2011-04-01 23:55:55 | [diff] [blame] | 207 | } |
| 208 | |
estade | 279252707 | 2014-12-17 00:41:47 | [diff] [blame] | 209 | void AutofillAgent::DidChangeScrollOffset() { |
rouslan | c31f81d | 2015-08-24 17:33:52 | [diff] [blame] | 210 | if (IsKeyboardAccessoryEnabled()) |
estade | b5efbab6 | 2015-04-28 18:07:42 | [diff] [blame] | 211 | return; |
rouslan | c31f81d | 2015-08-24 17:33:52 | [diff] [blame] | 212 | |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 213 | HidePopup(); |
| 214 | } |
| 215 | |
[email protected] | 5e7e861 | 2014-03-20 14:43:19 | [diff] [blame] | 216 | void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 217 | page_click_tracker_->FocusedNodeChanged(node); |
| 218 | |
[email protected] | 91dcc6d3 | 2014-07-30 00:01:33 | [diff] [blame] | 219 | HidePopup(); |
| 220 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 221 | if (node.IsNull() || !node.IsElementNode()) { |
| 222 | if (!last_interacted_form_.IsNull()) { |
mathp | 8ac68ce | 2015-12-08 21:49:06 | [diff] [blame] | 223 | // Focus moved away from the last interacted form to somewhere else on |
| 224 | // the page. |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 225 | GetAutofillDriver()->FocusNoLongerOnForm(); |
mathp | 8ac68ce | 2015-12-08 21:49:06 | [diff] [blame] | 226 | } |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 227 | return; |
mathp | 8ac68ce | 2015-12-08 21:49:06 | [diff] [blame] | 228 | } |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 229 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 230 | WebElement web_element = node.ToConst<WebElement>(); |
| 231 | const WebInputElement* element = ToWebInputElement(&web_element); |
mathp | b4cf7b8 | 2015-12-11 16:42:24 | [diff] [blame] | 232 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 233 | if (!last_interacted_form_.IsNull() && |
| 234 | (!element || last_interacted_form_ != element->Form())) { |
mathp | 8ac68ce | 2015-12-08 21:49:06 | [diff] [blame] | 235 | // The focused element is not part of the last interacted form (could be |
| 236 | // in a different form). |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 237 | GetAutofillDriver()->FocusNoLongerOnForm(); |
mathp | 8ac68ce | 2015-12-08 21:49:06 | [diff] [blame] | 238 | return; |
| 239 | } |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 240 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 241 | if (!element || !element->IsEnabled() || element->IsReadOnly() || |
| 242 | !element->IsTextField()) |
[email protected] | f920d6e | 2013-03-12 20:20:50 | [diff] [blame] | 243 | return; |
| 244 | |
[email protected] | e5057a2 | 2013-04-22 12:41:39 | [diff] [blame] | 245 | element_ = *element; |
[email protected] | e5057a2 | 2013-04-22 12:41:39 | [diff] [blame] | 246 | } |
| 247 | |
vabr | d62bc3e | 2016-05-04 15:58:52 | [diff] [blame] | 248 | void AutofillAgent::OnDestruct() { |
| 249 | Shutdown(); |
| 250 | base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 251 | } |
| 252 | |
tmartino | 1c5348c9 | 2016-05-26 18:50:56 | [diff] [blame] | 253 | void AutofillAgent::FireHostSubmitEvents(const WebFormElement& form, |
| 254 | bool form_submitted) { |
| 255 | FormData form_data; |
| 256 | if (!form_util::ExtractFormData(form, &form_data)) |
| 257 | return; |
| 258 | |
| 259 | FireHostSubmitEvents(form_data, form_submitted); |
| 260 | } |
| 261 | |
| 262 | void AutofillAgent::FireHostSubmitEvents(const FormData& form_data, |
| 263 | bool form_submitted) { |
| 264 | // We remember when we have fired this IPC for this form in this frame load, |
| 265 | // because forms with a submit handler may fire both WillSendSubmitEvent |
| 266 | // and WillSubmitForm, and we don't want duplicate messages. |
| 267 | if (!submitted_forms_.count(form_data)) { |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 268 | GetAutofillDriver()->WillSubmitForm(form_data, base::TimeTicks::Now()); |
tmartino | 1c5348c9 | 2016-05-26 18:50:56 | [diff] [blame] | 269 | submitted_forms_.insert(form_data); |
| 270 | } |
| 271 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 272 | if (form_submitted) { |
| 273 | GetAutofillDriver()->FormSubmitted(form_data); |
| 274 | } |
tmartino | 1c5348c9 | 2016-05-26 18:50:56 | [diff] [blame] | 275 | } |
| 276 | |
vabr | d62bc3e | 2016-05-04 15:58:52 | [diff] [blame] | 277 | void AutofillAgent::Shutdown() { |
leon.han | 7e8c85b | 2016-09-08 14:24:42 | [diff] [blame] | 278 | binding_.Close(); |
vabr | d62bc3e | 2016-05-04 15:58:52 | [diff] [blame] | 279 | weak_ptr_factory_.InvalidateWeakPtrs(); |
| 280 | } |
| 281 | |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 282 | |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 283 | void AutofillAgent::FormControlElementClicked( |
| 284 | const WebFormControlElement& element, |
| 285 | bool was_focused) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 286 | const WebInputElement* input_element = ToWebInputElement(&element); |
mathp | 9172c62a | 2015-10-08 18:51:14 | [diff] [blame] | 287 | if (!input_element && !form_util::IsTextAreaElement(element)) |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 288 | return; |
| 289 | |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 290 | ShowSuggestionsOptions options; |
| 291 | options.autofill_on_empty_values = true; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 292 | options.show_full_suggestion_list = element.IsAutofilled(); |
gcasto | 2c646227 | 2014-11-04 01:14:11 | [diff] [blame] | 293 | |
mathp | 4f6b038 | 2016-04-12 20:41:12 | [diff] [blame] | 294 | if (!IsSingleClickEnabled()) { |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 295 | // Show full suggestions when clicking on an already-focused form field. On |
| 296 | // the initial click (not focused yet), only show password suggestions. |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 297 | options.show_full_suggestion_list = |
| 298 | options.show_full_suggestion_list || was_focused; |
| 299 | options.show_password_suggestions_only = !was_focused; |
gcasto | 2c646227 | 2014-11-04 01:14:11 | [diff] [blame] | 300 | } |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 301 | ShowSuggestions(element, options); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 302 | } |
| 303 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 304 | void AutofillAgent::TextFieldDidEndEditing(const WebInputElement& element) { |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 305 | GetAutofillDriver()->DidEndTextFieldEditing(); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 306 | } |
| 307 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 308 | void AutofillAgent::TextFieldDidChange(const WebFormControlElement& element) { |
| 309 | DCHECK(ToWebInputElement(&element) || form_util::IsTextAreaElement(element)); |
ellyjones | db20fae1 | 2015-12-04 16:47:55 | [diff] [blame] | 310 | |
[email protected] | 90f2625 | 2013-02-15 19:48:32 | [diff] [blame] | 311 | if (ignore_text_changes_) |
| 312 | return; |
| 313 | |
ellyjones | db20fae1 | 2015-12-04 16:47:55 | [diff] [blame] | 314 | // Disregard text changes that aren't caused by user gestures or pastes. Note |
| 315 | // that pastes aren't necessarily user gestures because Blink's conception of |
| 316 | // user gestures is centered around creating new windows/tabs. |
| 317 | if (!IsUserGesture() && !render_frame()->IsPasting()) |
[email protected] | b96a1d1 | 2012-11-30 22:44:32 | [diff] [blame] | 318 | return; |
[email protected] | b37043c | 2012-05-31 17:08:12 | [diff] [blame] | 319 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 320 | // 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] | 321 | // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and |
| 322 | // it is needed to trigger autofill. |
[email protected] | 5219146e | 2013-02-28 11:42:30 | [diff] [blame] | 323 | weak_ptr_factory_.InvalidateWeakPtrs(); |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 324 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 325 | FROM_HERE, base::Bind(&AutofillAgent::TextFieldDidChangeImpl, |
| 326 | weak_ptr_factory_.GetWeakPtr(), element)); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 327 | } |
| 328 | |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 329 | void AutofillAgent::TextFieldDidChangeImpl( |
| 330 | const WebFormControlElement& element) { |
[email protected] | f9af283 | 2012-12-14 04:20:43 | [diff] [blame] | 331 | // If the element isn't focused then the changes don't matter. This check is |
| 332 | // required to properly handle IME interactions. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 333 | if (!element.Focused()) |
[email protected] | f9af283 | 2012-12-14 04:20:43 | [diff] [blame] | 334 | return; |
| 335 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 336 | const WebInputElement* input_element = ToWebInputElement(&element); |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 337 | if (input_element) { |
mathp | ffc78e2 | 2015-09-01 14:10:50 | [diff] [blame] | 338 | // Remember the last form the user interacted with. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 339 | if (element.Form().IsNull()) { |
tmartino | 283dda1 | 2016-06-23 21:43:54 | [diff] [blame] | 340 | formless_elements_user_edited_.insert(element); |
| 341 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 342 | last_interacted_form_ = element.Form(); |
tmartino | 283dda1 | 2016-06-23 21:43:54 | [diff] [blame] | 343 | } |
mathp | ffc78e2 | 2015-09-01 14:10:50 | [diff] [blame] | 344 | |
gcasto | 5c13d76 | 2015-06-03 23:44:45 | [diff] [blame] | 345 | // |password_autofill_agent_| keeps track of all text changes even if |
| 346 | // it isn't displaying UI. |
| 347 | password_autofill_agent_->UpdateStateForTextChange(*input_element); |
| 348 | |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 349 | if (password_generation_agent_ && |
| 350 | password_generation_agent_->TextDidChangeInTextField(*input_element)) { |
[email protected] | 7e04827 | 2014-04-17 03:38:52 | [diff] [blame] | 351 | is_popup_possibly_visible_ = true; |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 352 | return; |
| 353 | } |
[email protected] | 3cbdf936 | 2014-01-31 23:12:23 | [diff] [blame] | 354 | |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 355 | if (password_autofill_agent_->TextDidChangeInTextField(*input_element)) { |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 356 | is_popup_possibly_visible_ = true; |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 357 | element_ = element; |
| 358 | return; |
| 359 | } |
[email protected] | e7e8347 | 2012-04-05 02:56:26 | [diff] [blame] | 360 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 361 | |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 362 | ShowSuggestionsOptions options; |
| 363 | options.requires_caret_at_end = true; |
| 364 | ShowSuggestions(element, options); |
[email protected] | 7d24db7 | 2011-08-26 06:02:31 | [diff] [blame] | 365 | |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 366 | FormData form; |
| 367 | FormFieldData field; |
mathp | 9172c62a | 2015-10-08 18:51:14 | [diff] [blame] | 368 | if (form_util::FindFormAndFieldForFormControlElement(element, &form, |
| 369 | &field)) { |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 370 | GetAutofillDriver()->TextFieldDidChange(form, field, |
| 371 | base::TimeTicks::Now()); |
[email protected] | 1d14f58 | 2011-09-02 20:42:04 | [diff] [blame] | 372 | } |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 373 | } |
| 374 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 375 | void AutofillAgent::TextFieldDidReceiveKeyDown(const WebInputElement& element, |
[email protected] | 2fa18c2 | 2011-06-14 23:40:43 | [diff] [blame] | 376 | const WebKeyboardEvent& event) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 377 | if (event.windows_key_code == ui::VKEY_DOWN || |
| 378 | event.windows_key_code == ui::VKEY_UP) { |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 379 | ShowSuggestionsOptions options; |
| 380 | options.autofill_on_empty_values = true; |
| 381 | options.requires_caret_at_end = true; |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 382 | ShowSuggestions(element, options); |
| 383 | } |
[email protected] | efeb565f | 2013-12-12 17:16:41 | [diff] [blame] | 384 | } |
| 385 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 386 | void AutofillAgent::OpenTextDataListChooser(const WebInputElement& element) { |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 387 | ShowSuggestionsOptions options; |
| 388 | options.autofill_on_empty_values = true; |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 389 | ShowSuggestions(element, options); |
[email protected] | 676126f7 | 2011-01-15 00:03:51 | [diff] [blame] | 390 | } |
| 391 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 392 | void AutofillAgent::DataListOptionsChanged(const WebInputElement& element) { |
| 393 | if (!is_popup_possibly_visible_ || !element.Focused()) |
estade | df5088a | 2014-12-15 02:04:07 | [diff] [blame] | 394 | return; |
| 395 | |
| 396 | TextFieldDidChangeImpl(element); |
| 397 | } |
| 398 | |
vasilii | fd0e8ca | 2017-04-12 11:11:22 | [diff] [blame] | 399 | void AutofillAgent::UserGestureObserved() { |
| 400 | password_autofill_agent_->UserGestureObserved(); |
[email protected] | fc22ae5 | 2014-04-23 13:48:04 | [diff] [blame] | 401 | } |
| 402 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 403 | void AutofillAgent::DoAcceptDataListSuggestion( |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 404 | const base::string16& suggested_value) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 405 | WebInputElement* input_element = ToWebInputElement(&element_); |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 406 | DCHECK(input_element); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 407 | base::string16 new_value = suggested_value; |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 408 | // If this element takes multiple values then replace the last part with |
| 409 | // the suggestion. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 410 | if (input_element->IsMultiple() && input_element->IsEmailField()) { |
mgiuca | 30f7588 | 2017-03-28 02:07:19 | [diff] [blame] | 411 | std::vector<base::StringPiece16> parts = base::SplitStringPiece( |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 412 | input_element->EditingValue().Utf16(), base::ASCIIToUTF16(","), |
kinuko | 0073e7c8 | 2017-01-24 00:42:40 | [diff] [blame] | 413 | base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 414 | if (parts.size() == 0) |
mgiuca | 30f7588 | 2017-03-28 02:07:19 | [diff] [blame] | 415 | parts.push_back(base::StringPiece16()); |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 416 | |
mgiuca | 30f7588 | 2017-03-28 02:07:19 | [diff] [blame] | 417 | base::string16 last_part = parts.back().as_string(); |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 418 | // We want to keep just the leading whitespace. |
| 419 | for (size_t i = 0; i < last_part.size(); ++i) { |
brettw | b341306 | 2015-06-24 00:39:02 | [diff] [blame] | 420 | if (!base::IsUnicodeWhitespace(last_part[i])) { |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 421 | last_part = last_part.substr(0, i); |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | last_part.append(suggested_value); |
thestig | ee1440b | 2016-07-08 01:06:55 | [diff] [blame] | 426 | parts.back() = last_part; |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 427 | |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 428 | new_value = base::JoinString(parts, base::ASCIIToUTF16(",")); |
[email protected] | 71a90b3 | 2012-05-18 09:16:53 | [diff] [blame] | 429 | } |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 430 | DoFillFieldWithValue(new_value, input_element); |
[email protected] | 63560b3 | 2014-03-04 07:06:26 | [diff] [blame] | 431 | } |
| 432 | |
leon.han | de85290 | 2016-05-04 09:16:38 | [diff] [blame] | 433 | // mojom::AutofillAgent: |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 434 | void AutofillAgent::FillForm(int32_t id, const FormData& form) { |
mathp | f43ced4 | 2016-08-04 18:28:23 | [diff] [blame] | 435 | if (id != autofill_query_id_ && id != kNoQueryId) |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 436 | return; |
| 437 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 438 | was_query_node_autofilled_ = element_.IsAutofilled(); |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 439 | form_util::FillForm(form, element_); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 440 | if (!element_.Form().IsNull()) |
| 441 | last_interacted_form_ = element_.Form(); |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 442 | |
| 443 | GetAutofillDriver()->DidFillAutofillFormData(form, base::TimeTicks::Now()); |
[email protected] | 8527a78f | 2014-06-12 12:49:15 | [diff] [blame] | 444 | } |
| 445 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 446 | void AutofillAgent::PreviewForm(int32_t id, const FormData& form) { |
| 447 | if (id != autofill_query_id_) |
[email protected] | 63560b3 | 2014-03-04 07:06:26 | [diff] [blame] | 448 | return; |
| 449 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 450 | was_query_node_autofilled_ = element_.IsAutofilled(); |
mathp | 9172c62a | 2015-10-08 18:51:14 | [diff] [blame] | 451 | form_util::PreviewForm(form, element_); |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 452 | |
| 453 | GetAutofillDriver()->DidPreviewAutofillFormData(); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 454 | } |
| 455 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 456 | void AutofillAgent::FieldTypePredictionsAvailable( |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 457 | const std::vector<FormDataPredictions>& forms) { |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 458 | for (const auto& form : forms) { |
| 459 | form_cache_.ShowPredictions(form); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | void AutofillAgent::ClearForm() { |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 464 | form_cache_.ClearFormWithElement(element_); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 465 | } |
| 466 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 467 | void AutofillAgent::ClearPreviewedForm() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 468 | if (!element_.IsNull()) { |
[email protected] | b5b1d69f | 2014-01-23 23:49:32 | [diff] [blame] | 469 | if (password_autofill_agent_->DidClearAutofillSelection(element_)) |
| 470 | return; |
| 471 | |
mathp | 9172c62a | 2015-10-08 18:51:14 | [diff] [blame] | 472 | form_util::ClearPreviewedFormWithElement(element_, |
| 473 | was_query_node_autofilled_); |
[email protected] | 93f2e50 | 2013-12-20 09:47:25 | [diff] [blame] | 474 | } else { |
| 475 | // TODO(isherman): There seem to be rare cases where this code *is* |
| 476 | // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would |
| 477 | // understand those cases and fix the code to avoid them. However, so far I |
| 478 | // have been unable to reproduce such a case locally. If you hit this |
| 479 | // NOTREACHED(), please file a bug against me. |
| 480 | NOTREACHED(); |
| 481 | } |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 482 | } |
| 483 | |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 484 | void AutofillAgent::FillFieldWithValue(const base::string16& value) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 485 | WebInputElement* input_element = ToWebInputElement(&element_); |
ziran.sun | ee0fd443 | 2014-08-27 10:10:49 | [diff] [blame] | 486 | if (input_element) { |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 487 | DoFillFieldWithValue(value, input_element); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 488 | input_element->SetAutofilled(true); |
ziran.sun | ee0fd443 | 2014-08-27 10:10:49 | [diff] [blame] | 489 | } |
[email protected] | ac9b92f | 2014-03-15 00:48:32 | [diff] [blame] | 490 | } |
| 491 | |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 492 | void AutofillAgent::PreviewFieldWithValue(const base::string16& value) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 493 | WebInputElement* input_element = ToWebInputElement(&element_); |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 494 | if (input_element) |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 495 | DoPreviewFieldWithValue(value, input_element); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 496 | } |
| 497 | |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 498 | void AutofillAgent::AcceptDataListSuggestion(const base::string16& value) { |
| 499 | DoAcceptDataListSuggestion(value); |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 500 | } |
| 501 | |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 502 | void AutofillAgent::FillPasswordSuggestion(const base::string16& username, |
| 503 | const base::string16& password) { |
| 504 | bool handled = |
| 505 | password_autofill_agent_->FillSuggestion(element_, username, password); |
[email protected] | 126b1ad | 2014-05-21 22:37:33 | [diff] [blame] | 506 | DCHECK(handled); |
| 507 | } |
| 508 | |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 509 | void AutofillAgent::PreviewPasswordSuggestion(const base::string16& username, |
| 510 | const base::string16& password) { |
kinuko | 0073e7c8 | 2017-01-24 00:42:40 | [diff] [blame] | 511 | bool handled = password_autofill_agent_->PreviewSuggestion( |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 512 | element_, blink::WebString::FromUTF16(username), |
| 513 | blink::WebString::FromUTF16(password)); |
[email protected] | e7e8347 | 2012-04-05 02:56:26 | [diff] [blame] | 514 | DCHECK(handled); |
| 515 | } |
| 516 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 517 | void AutofillAgent::ShowInitialPasswordAccountSuggestions( |
| 518 | int32_t key, |
jww | fb2a143 | 2016-06-13 22:44:15 | [diff] [blame] | 519 | const PasswordFormFillData& form_data) { |
| 520 | std::vector<blink::WebInputElement> elements; |
| 521 | std::unique_ptr<RendererSavePasswordProgressLogger> logger; |
| 522 | if (password_autofill_agent_->logging_state_active()) { |
leon.han | 97e8f75 | 2016-09-06 06:13:20 | [diff] [blame] | 523 | logger.reset(new RendererSavePasswordProgressLogger( |
| 524 | GetPasswordManagerDriver().get())); |
jww | fb2a143 | 2016-06-13 22:44:15 | [diff] [blame] | 525 | logger->LogMessage(SavePasswordProgressLogger:: |
| 526 | STRING_ON_SHOW_INITIAL_PASSWORD_ACCOUNT_SUGGESTIONS); |
| 527 | } |
| 528 | password_autofill_agent_->GetFillableElementFromFormData( |
| 529 | key, form_data, logger.get(), &elements); |
| 530 | |
| 531 | // If wait_for_username is true, we don't want to initially show form options |
| 532 | // until the user types in a valid username. |
| 533 | if (form_data.wait_for_username) |
| 534 | return; |
| 535 | |
| 536 | ShowSuggestionsOptions options; |
| 537 | options.autofill_on_empty_values = true; |
| 538 | options.show_full_suggestion_list = true; |
| 539 | for (auto element : elements) |
| 540 | ShowSuggestions(element, options); |
| 541 | } |
| 542 | |
estark | 50592c0 | 2017-01-04 01:52:40 | [diff] [blame] | 543 | void AutofillAgent::ShowNotSecureWarning( |
| 544 | const blink::WebInputElement& element) { |
| 545 | if (is_generation_popup_possibly_visible_) |
| 546 | return; |
estark | 50592c0 | 2017-01-04 01:52:40 | [diff] [blame] | 547 | password_autofill_agent_->ShowNotSecureWarning(element); |
| 548 | is_popup_possibly_visible_ = true; |
| 549 | } |
| 550 | |
eugenebut | 5ae751e | 2017-03-28 17:10:37 | [diff] [blame] | 551 | void AutofillAgent::OnSameDocumentNavigationCompleted() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 552 | if (last_interacted_form_.IsNull()) { |
tmartino | 283dda1 | 2016-06-23 21:43:54 | [diff] [blame] | 553 | // If no last interacted form is available (i.e., there is no form tag), |
| 554 | // we check if all the elements the user has interacted with are gone, |
| 555 | // to decide if submission has occurred. |
| 556 | if (formless_elements_user_edited_.size() == 0 || |
| 557 | form_util::IsSomeControlElementVisible(formless_elements_user_edited_)) |
| 558 | return; |
| 559 | |
| 560 | FormData constructed_form; |
| 561 | if (CollectFormlessElements(&constructed_form)) |
| 562 | FireHostSubmitEvents(constructed_form, /*form_submitted=*/true); |
| 563 | } else { |
| 564 | // Otherwise, assume form submission only if the form is now gone, either |
| 565 | // invisible or removed from the DOM. |
tmartino | 1c5348c9 | 2016-05-26 18:50:56 | [diff] [blame] | 566 | if (form_util::AreFormContentsVisible(last_interacted_form_)) |
| 567 | return; |
mathp | ffc78e2 | 2015-09-01 14:10:50 | [diff] [blame] | 568 | |
tmartino | 1c5348c9 | 2016-05-26 18:50:56 | [diff] [blame] | 569 | FireHostSubmitEvents(last_interacted_form_, /*form_submitted=*/true); |
tmartino | 1c5348c9 | 2016-05-26 18:50:56 | [diff] [blame] | 570 | } |
tmartino | 283dda1 | 2016-06-23 21:43:54 | [diff] [blame] | 571 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 572 | last_interacted_form_.Reset(); |
tmartino | 283dda1 | 2016-06-23 21:43:54 | [diff] [blame] | 573 | formless_elements_user_edited_.clear(); |
| 574 | } |
| 575 | |
| 576 | bool AutofillAgent::CollectFormlessElements(FormData* output) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 577 | WebDocument document = render_frame()->GetWebFrame()->GetDocument(); |
tmartino | 283dda1 | 2016-06-23 21:43:54 | [diff] [blame] | 578 | |
| 579 | // Build up the FormData from the unowned elements. This logic mostly |
| 580 | // mirrors the construction of the synthetic form in form_cache.cc, but |
| 581 | // happens at submit-time so we can capture the modifications the user |
| 582 | // has made, and doesn't depend on form_cache's internal state. |
| 583 | std::vector<WebElement> fieldsets; |
| 584 | std::vector<WebFormControlElement> control_elements = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 585 | form_util::GetUnownedAutofillableFormFieldElements(document.All(), |
tmartino | 283dda1 | 2016-06-23 21:43:54 | [diff] [blame] | 586 | &fieldsets); |
| 587 | |
| 588 | if (control_elements.size() > form_util::kMaxParseableFields) |
| 589 | return false; |
| 590 | |
| 591 | const form_util::ExtractMask extract_mask = |
| 592 | static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE | |
| 593 | form_util::EXTRACT_OPTIONS); |
| 594 | |
| 595 | return form_util::UnownedCheckoutFormElementsAndFieldSetsToFormData( |
| 596 | fieldsets, control_elements, nullptr, document, extract_mask, output, |
| 597 | nullptr); |
mathp | ffc78e2 | 2015-09-01 14:10:50 | [diff] [blame] | 598 | } |
| 599 | |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 600 | void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, |
brettw | b505b7a | 2014-11-26 22:05:32 | [diff] [blame] | 601 | const ShowSuggestionsOptions& options) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 602 | if (!element.IsEnabled() || element.IsReadOnly()) |
[email protected] | efeb565f | 2013-12-12 17:16:41 | [diff] [blame] | 603 | return; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 604 | if (!element.SuggestedValue().IsEmpty()) |
[email protected] | 580c3805 | 2014-07-16 07:28:09 | [diff] [blame] | 605 | return; |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 606 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 607 | const WebInputElement* input_element = ToWebInputElement(&element); |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 608 | if (input_element) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 609 | if (!input_element->IsTextField()) |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 610 | return; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 611 | if (!input_element->SuggestedValue().IsEmpty()) |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 612 | return; |
| 613 | } else { |
mathp | 9172c62a | 2015-10-08 18:51:14 | [diff] [blame] | 614 | DCHECK(form_util::IsTextAreaElement(element)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 615 | if (!element.ToConst<WebFormControlElement>().SuggestedValue().IsEmpty()) |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 616 | return; |
| 617 | } |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 618 | |
[email protected] | 1c69f8b7 | 2012-03-14 03:18:50 | [diff] [blame] | 619 | // Don't attempt to autofill with values that are too large or if filling |
| 620 | // criteria are not met. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 621 | WebString value = element.EditingValue(); |
mathp | 5f90bce2 | 2015-11-22 20:16:58 | [diff] [blame] | 622 | if (value.length() > kMaxDataLength || |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 623 | (!options.autofill_on_empty_values && value.IsEmpty()) || |
mathp | 5f90bce2 | 2015-11-22 20:16:58 | [diff] [blame] | 624 | (options.requires_caret_at_end && |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 625 | (element.SelectionStart() != element.SelectionEnd() || |
| 626 | element.SelectionEnd() != static_cast<int>(value.length())))) { |
[email protected] | 1c69f8b7 | 2012-03-14 03:18:50 | [diff] [blame] | 627 | // Any popup currently showing is obsolete. |
[email protected] | b648f24 | 2014-02-25 13:49:06 | [diff] [blame] | 628 | HidePopup(); |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 629 | return; |
[email protected] | 1c69f8b7 | 2012-03-14 03:18:50 | [diff] [blame] | 630 | } |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 631 | |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 632 | element_ = element; |
mathp | 9172c62a | 2015-10-08 18:51:14 | [diff] [blame] | 633 | if (form_util::IsAutofillableInputElement(input_element) && |
gcasto | cdd33e0d | 2015-06-17 22:10:05 | [diff] [blame] | 634 | password_autofill_agent_->ShowSuggestions( |
| 635 | *input_element, options.show_full_suggestion_list, |
| 636 | is_generation_popup_possibly_visible_)) { |
[email protected] | b648f24 | 2014-02-25 13:49:06 | [diff] [blame] | 637 | is_popup_possibly_visible_ = true; |
[email protected] | c66ba98 | 2013-04-05 09:56:17 | [diff] [blame] | 638 | return; |
[email protected] | b648f24 | 2014-02-25 13:49:06 | [diff] [blame] | 639 | } |
[email protected] | bef7f927 | 2012-04-17 10:47:49 | [diff] [blame] | 640 | |
gcasto | cdd33e0d | 2015-06-17 22:10:05 | [diff] [blame] | 641 | if (is_generation_popup_possibly_visible_) |
| 642 | return; |
| 643 | |
| 644 | if (options.show_password_suggestions_only) |
| 645 | return; |
| 646 | |
jww | 2035507 | 2014-12-12 21:00:55 | [diff] [blame] | 647 | // Password field elements should only have suggestions shown by the password |
| 648 | // autofill agent. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 649 | if (input_element && input_element->IsPasswordField()) |
jww | 2035507 | 2014-12-12 21:00:55 | [diff] [blame] | 650 | return; |
| 651 | |
mathp | 5f90bce2 | 2015-11-22 20:16:58 | [diff] [blame] | 652 | QueryAutofillSuggestions(element); |
[email protected] | 77bb0da | 2010-11-20 01:55:30 | [diff] [blame] | 653 | } |
| 654 | |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 655 | void AutofillAgent::QueryAutofillSuggestions( |
mathp | 5f90bce2 | 2015-11-22 20:16:58 | [diff] [blame] | 656 | const WebFormControlElement& element) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 657 | if (!element.GetDocument().GetFrame()) |
[email protected] | e69b5f7 | 2013-01-24 00:59:13 | [diff] [blame] | 658 | return; |
| 659 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 660 | DCHECK(ToWebInputElement(&element) || form_util::IsTextAreaElement(element)); |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 661 | |
[email protected] | 77bb0da | 2010-11-20 01:55:30 | [diff] [blame] | 662 | static int query_counter = 0; |
| 663 | autofill_query_id_ = query_counter++; |
estade | 0ee9126 | 2014-10-23 19:29:19 | [diff] [blame] | 664 | |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 665 | FormData form; |
| 666 | FormFieldData field; |
mathp | 9172c62a | 2015-10-08 18:51:14 | [diff] [blame] | 667 | if (!form_util::FindFormAndFieldForFormControlElement(element, &form, |
| 668 | &field)) { |
[email protected] | 7837be6 | 2011-01-18 23:45:08 | [diff] [blame] | 669 | // If we didn't find the cached form, at least let autocomplete have a shot |
| 670 | // at providing suggestions. |
kolos | 66b4c29 | 2016-07-29 17:54:53 | [diff] [blame] | 671 | WebFormControlElementToFormField(element, nullptr, form_util::EXTRACT_VALUE, |
| 672 | &field); |
[email protected] | 7837be6 | 2011-01-18 23:45:08 | [diff] [blame] | 673 | } |
[email protected] | 77bb0da | 2010-11-20 01:55:30 | [diff] [blame] | 674 | |
[email protected] | 7d0ea536 | 2014-05-01 23:39:43 | [diff] [blame] | 675 | std::vector<base::string16> data_list_values; |
| 676 | std::vector<base::string16> data_list_labels; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 677 | const WebInputElement* input_element = ToWebInputElement(&element); |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 678 | if (input_element) { |
| 679 | // Find the datalist values and send them to the browser process. |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 680 | GetDataListSuggestions(*input_element, |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 681 | &data_list_values, |
| 682 | &data_list_labels); |
| 683 | TrimStringVectorForIPC(&data_list_values); |
| 684 | TrimStringVectorForIPC(&data_list_labels); |
[email protected] | e9d29d39 | 2014-03-25 01:15:15 | [diff] [blame] | 685 | } |
[email protected] | 5c8de6b9 | 2012-06-08 21:24:08 | [diff] [blame] | 686 | |
[email protected] | b648f24 | 2014-02-25 13:49:06 | [diff] [blame] | 687 | is_popup_possibly_visible_ = true; |
[email protected] | 7d0ea536 | 2014-05-01 23:39:43 | [diff] [blame] | 688 | |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 689 | GetAutofillDriver()->SetDataList(data_list_values, data_list_labels); |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 690 | GetAutofillDriver()->QueryFormFieldAutofill( |
| 691 | autofill_query_id_, form, field, |
| 692 | render_frame()->GetRenderView()->ElementBoundsInWindow(element_)); |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 693 | } |
| 694 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 695 | void AutofillAgent::DoFillFieldWithValue(const base::string16& value, |
| 696 | WebInputElement* node) { |
rouslan | 6a3f8d9 | 2015-04-28 01:00:01 | [diff] [blame] | 697 | base::AutoReset<bool> auto_reset(&ignore_text_changes_, true); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 698 | node->SetEditingValue( |
| 699 | blink::WebString::FromUTF16(value.substr(0, node->MaxLength()))); |
[email protected] | ac9b92f | 2014-03-15 00:48:32 | [diff] [blame] | 700 | } |
| 701 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 702 | void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value, |
| 703 | WebInputElement* node) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 704 | was_query_node_autofilled_ = element_.IsAutofilled(); |
| 705 | node->SetSuggestedValue( |
| 706 | blink::WebString::FromUTF16(value.substr(0, node->MaxLength()))); |
| 707 | node->SetAutofilled(true); |
| 708 | form_util::PreviewSuggestion(node->SuggestedValue().Utf16(), |
| 709 | node->Value().Utf16(), node); |
[email protected] | 6f001a6cf | 2012-02-09 15:21:53 | [diff] [blame] | 710 | } |
| 711 | |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 712 | void AutofillAgent::ProcessForms() { |
[email protected] | 5193ea5 | 2014-05-14 01:10:02 | [diff] [blame] | 713 | // Record timestamp of when the forms are first seen. This is used to |
| 714 | // measure the overhead of the Autofill feature. |
| 715 | base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); |
| 716 | |
estade | b1bc9bd | 2014-12-02 22:44:11 | [diff] [blame] | 717 | WebLocalFrame* frame = render_frame()->GetWebFrame(); |
estade | ff02e6d | 2014-12-15 21:18:31 | [diff] [blame] | 718 | std::vector<FormData> forms = form_cache_.ExtractNewForms(); |
[email protected] | 5193ea5 | 2014-05-14 01:10:02 | [diff] [blame] | 719 | |
| 720 | // Always communicate to browser process for topmost frame. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 721 | if (!forms.empty() || !frame->Parent()) { |
leon.han | 35ae41c | 2016-07-29 03:30:58 | [diff] [blame] | 722 | GetAutofillDriver()->FormsSeen(forms, forms_seen_timestamp); |
[email protected] | 5193ea5 | 2014-05-14 01:10:02 | [diff] [blame] | 723 | } |
[email protected] | 5193ea5 | 2014-05-14 01:10:02 | [diff] [blame] | 724 | } |
| 725 | |
[email protected] | b648f24 | 2014-02-25 13:49:06 | [diff] [blame] | 726 | void AutofillAgent::HidePopup() { |
| 727 | if (!is_popup_possibly_visible_) |
| 728 | return; |
[email protected] | b648f24 | 2014-02-25 13:49:06 | [diff] [blame] | 729 | is_popup_possibly_visible_ = false; |
gcasto | cdd33e0d | 2015-06-17 22:10:05 | [diff] [blame] | 730 | is_generation_popup_possibly_visible_ = false; |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 731 | |
| 732 | GetAutofillDriver()->HidePopup(); |
[email protected] | 81cd5233 | 2012-11-05 20:36:07 | [diff] [blame] | 733 | } |
| 734 | |
rouslan | 42b09087 | 2015-05-17 05:04:33 | [diff] [blame] | 735 | bool AutofillAgent::IsUserGesture() const { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 736 | return WebUserGestureIndicator::IsProcessingUserGesture(); |
rouslan | 42b09087 | 2015-05-17 05:04:33 | [diff] [blame] | 737 | } |
| 738 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 739 | void AutofillAgent::DidAssociateFormControlsDynamically() { |
vasilii | 31ba8c6c | 2017-04-28 21:35:08 | [diff] [blame^] | 740 | // If the control flow is here than the document was at least loaded. The |
| 741 | // whole page doesn't have to be loaded. |
| 742 | ProcessForms(); |
| 743 | password_autofill_agent_->OnDynamicFormsSeen(); |
| 744 | if (password_generation_agent_) |
| 745 | password_generation_agent_->OnDynamicFormsSeen(); |
[email protected] | 17b6be7 | 2013-04-30 21:33:08 | [diff] [blame] | 746 | } |
| 747 | |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 748 | void AutofillAgent::DidCompleteFocusChangeInFrame() { |
| 749 | WebDocument doc = render_frame()->GetWebFrame()->GetDocument(); |
| 750 | WebElement focused_element; |
| 751 | if (!doc.IsNull()) |
| 752 | focused_element = doc.FocusedElement(); |
| 753 | // PasswordGenerationAgent needs to know about focus changes, even if there is |
| 754 | // no focused element. |
| 755 | if (password_generation_agent_ && |
| 756 | password_generation_agent_->FocusedNodeHasChanged(focused_element)) { |
| 757 | is_generation_popup_possibly_visible_ = true; |
| 758 | is_popup_possibly_visible_ = true; |
| 759 | } |
| 760 | if (!focused_element.IsNull() && password_autofill_agent_) |
| 761 | password_autofill_agent_->FocusedNodeHasChanged(focused_element); |
| 762 | |
| 763 | // PageClickTracker needs to be notified after |
| 764 | // |is_generation_popup_possibly_visible_| has been updated. |
| 765 | page_click_tracker_->DidCompleteFocusChangeInFrame(); |
| 766 | } |
| 767 | |
| 768 | void AutofillAgent::DidReceiveLeftMouseDownOrGestureTapInNode( |
| 769 | const WebNode& node) { |
| 770 | page_click_tracker_->DidReceiveLeftMouseDownOrGestureTapInNode(node); |
| 771 | } |
| 772 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 773 | void AutofillAgent::AjaxSucceeded() { |
eugenebut | 5ae751e | 2017-03-28 17:10:37 | [diff] [blame] | 774 | OnSameDocumentNavigationCompleted(); |
xunlu | 23ca2b57 | 2015-07-10 16:58:26 | [diff] [blame] | 775 | password_autofill_agent_->AJAXSucceeded(); |
gcasto | c21f1c4c | 2015-03-19 21:57:03 | [diff] [blame] | 776 | } |
| 777 | |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 778 | const mojom::AutofillDriverPtr& AutofillAgent::GetAutofillDriver() { |
leon.han | 97e8f75 | 2016-09-06 06:13:20 | [diff] [blame] | 779 | if (!autofill_driver_) { |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 780 | render_frame()->GetRemoteInterfaces()->GetInterface( |
blundell | e0a9f158 | 2016-12-20 11:23:32 | [diff] [blame] | 781 | mojo::MakeRequest(&autofill_driver_)); |
leon.han | 90fd63b | 2016-07-26 01:23:55 | [diff] [blame] | 782 | } |
leon.han | de85290 | 2016-05-04 09:16:38 | [diff] [blame] | 783 | |
leon.han | 97e8f75 | 2016-09-06 06:13:20 | [diff] [blame] | 784 | return autofill_driver_; |
| 785 | } |
| 786 | |
| 787 | const mojom::PasswordManagerDriverPtr& |
| 788 | AutofillAgent::GetPasswordManagerDriver() { |
| 789 | DCHECK(password_autofill_agent_); |
| 790 | return password_autofill_agent_->GetPasswordManagerDriver(); |
leon.han | de85290 | 2016-05-04 09:16:38 | [diff] [blame] | 791 | } |
| 792 | |
[email protected] | 7819208 | 2011-01-29 05:43:44 | [diff] [blame] | 793 | } // namespace autofill |