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