OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/content/renderer/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "url/gurl.h" | 41 #include "url/gurl.h" |
42 | 42 |
43 namespace autofill { | 43 namespace autofill { |
44 namespace { | 44 namespace { |
45 | 45 |
46 // The size above which we stop triggering autocomplete. | 46 // The size above which we stop triggering autocomplete. |
47 static const size_t kMaximumTextSizeForAutocomplete = 1000; | 47 static const size_t kMaximumTextSizeForAutocomplete = 1000; |
48 | 48 |
49 // Experiment information | 49 // Experiment information |
50 const char kFillOnAccountSelectFieldTrialName[] = "FillOnAccountSelect"; | 50 const char kFillOnAccountSelectFieldTrialName[] = "FillOnAccountSelect"; |
51 const char kFillOnAccountSelectFieldTrialEnabledGroup[] = "Enable"; | 51 const char kFillOnAccountSelectFieldTrialEnabledWithHighlightGroup[] = |
| 52 "EnableWithHighlight"; |
| 53 const char kFillOnAccountSelectFieldTrialEnabledWithNoHighlightGroup[] = |
| 54 "EnableWithNoHighlight"; |
52 | 55 |
53 // Maps element names to the actual elements to simplify form filling. | 56 // Maps element names to the actual elements to simplify form filling. |
54 typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; | 57 typedef std::map<base::string16, blink::WebInputElement> FormInputElementMap; |
55 | 58 |
56 // Use the shorter name when referencing SavePasswordProgressLogger::StringID | 59 // Use the shorter name when referencing SavePasswordProgressLogger::StringID |
57 // values to spare line breaks. The code provides enough context for that | 60 // values to spare line breaks. The code provides enough context for that |
58 // already. | 61 // already. |
59 typedef SavePasswordProgressLogger Logger; | 62 typedef SavePasswordProgressLogger Logger; |
60 | 63 |
61 // Utility struct for form lookup and autofill. When we parse the DOM to look up | 64 // Utility struct for form lookup and autofill. When we parse the DOM to look up |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 bool ShouldFillOnAccountSelect() { | 134 bool ShouldFillOnAccountSelect() { |
132 std::string group_name = | 135 std::string group_name = |
133 base::FieldTrialList::FindFullName(kFillOnAccountSelectFieldTrialName); | 136 base::FieldTrialList::FindFullName(kFillOnAccountSelectFieldTrialName); |
134 | 137 |
135 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 138 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
136 switches::kDisableFillOnAccountSelect)) { | 139 switches::kDisableFillOnAccountSelect)) { |
137 return false; | 140 return false; |
138 } | 141 } |
139 | 142 |
140 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 143 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 144 switches::kEnableFillOnAccountSelect) || |
| 145 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 146 switches::kEnableFillOnAccountSelectNoHighlighting)) { |
| 147 return true; |
| 148 } |
| 149 |
| 150 return group_name == |
| 151 kFillOnAccountSelectFieldTrialEnabledWithHighlightGroup || |
| 152 group_name == |
| 153 kFillOnAccountSelectFieldTrialEnabledWithNoHighlightGroup; |
| 154 } |
| 155 |
| 156 bool ShouldHighlightFields() { |
| 157 std::string group_name = |
| 158 base::FieldTrialList::FindFullName(kFillOnAccountSelectFieldTrialName); |
| 159 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 160 switches::kDisableFillOnAccountSelect) || |
| 161 base::CommandLine::ForCurrentProcess()->HasSwitch( |
141 switches::kEnableFillOnAccountSelect)) { | 162 switches::kEnableFillOnAccountSelect)) { |
142 return true; | 163 return true; |
143 } | 164 } |
144 | 165 |
145 return group_name == kFillOnAccountSelectFieldTrialEnabledGroup; | 166 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 167 switches::kEnableFillOnAccountSelectNoHighlighting)) { |
| 168 return false; |
| 169 } |
| 170 |
| 171 return group_name != |
| 172 kFillOnAccountSelectFieldTrialEnabledWithNoHighlightGroup; |
146 } | 173 } |
147 | 174 |
148 // Helper to search the given form element for the specified input elements in | 175 // Helper to search the given form element for the specified input elements in |
149 // |data|, and add results to |result|. | 176 // |data|, and add results to |result|. |
150 bool FindFormInputElements(blink::WebFormElement* form_element, | 177 bool FindFormInputElements(blink::WebFormElement* form_element, |
151 const PasswordFormFillData& data, | 178 const PasswordFormFillData& data, |
152 FormElements* result) { | 179 FormElements* result) { |
153 return FindFormInputElement(form_element, data.password_field, result) && | 180 return FindFormInputElement(form_element, data.password_field, result) && |
154 (!FillDataContainsUsername(data) || | 181 (!FillDataContainsUsername(data) || |
155 FindFormInputElement(form_element, data.username_field, result)); | 182 FindFormInputElement(form_element, data.username_field, result)); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 // If we can't modify the password, don't try to set the username | 441 // If we can't modify the password, don't try to set the username |
415 if (!IsElementAutocompletable(password_element)) | 442 if (!IsElementAutocompletable(password_element)) |
416 return false; | 443 return false; |
417 | 444 |
418 bool form_contains_username_field = FillDataContainsUsername(fill_data); | 445 bool form_contains_username_field = FillDataContainsUsername(fill_data); |
419 // If the form contains an autocompletable username field, try to set the | 446 // If the form contains an autocompletable username field, try to set the |
420 // username to the preferred name, but only if: | 447 // username to the preferred name, but only if: |
421 // (a) The fill-on-account-select flag is not set, and | 448 // (a) The fill-on-account-select flag is not set, and |
422 // (b) The username element isn't prefilled | 449 // (b) The username element isn't prefilled |
423 // | 450 // |
424 // If (a) is false, then just mark the username element as autofilled and | 451 // If (a) is false, then just mark the username element as autofilled if the |
425 // return so the fill step is skipped. | 452 // user is not in the "no highlighting" group and return so the fill step is |
| 453 // skipped. |
426 // | 454 // |
427 // If there is no autocompletable username field, and (a) is false, then the | 455 // If there is no autocompletable username field, and (a) is false, then the |
428 // username element cannot be autofilled, but the user should still be able to | 456 // username element cannot be autofilled, but the user should still be able to |
429 // select to fill the password element, so the password element must be marked | 457 // select to fill the password element, so the password element must be marked |
430 // as autofilled and the fill step should also be skipped. | 458 // as autofilled and the fill step should also be skipped if the user is not |
| 459 // in the "no highlighting" group. |
431 // | 460 // |
432 // In all other cases, do nothing. | 461 // In all other cases, do nothing. |
433 bool form_has_fillable_username = form_contains_username_field && | 462 bool form_has_fillable_username = form_contains_username_field && |
434 IsElementAutocompletable(username_element); | 463 IsElementAutocompletable(username_element); |
435 | 464 |
436 if (ShouldFillOnAccountSelect()) { | 465 if (ShouldFillOnAccountSelect()) { |
| 466 if (!ShouldHighlightFields()) { |
| 467 return false; |
| 468 } |
| 469 |
437 if (form_has_fillable_username) { | 470 if (form_has_fillable_username) { |
438 username_element.setAutofilled(true); | 471 username_element.setAutofilled(true); |
439 } else { | 472 } else { |
440 password_element.setAutofilled(true); | 473 password_element.setAutofilled(true); |
441 } | 474 } |
442 return false; | 475 return false; |
443 } | 476 } |
444 | 477 |
445 if (form_has_fillable_username && username_element.value().isEmpty()) { | 478 if (form_has_fillable_username && username_element.value().isEmpty()) { |
446 // TODO(tkent): Check maxlength and pattern. | 479 // TODO(tkent): Check maxlength and pattern. |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { | 1355 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { |
1323 agent_->LegacyDidStartProvisionalLoad(navigated_frame); | 1356 agent_->LegacyDidStartProvisionalLoad(navigated_frame); |
1324 } | 1357 } |
1325 | 1358 |
1326 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::FrameDetached( | 1359 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::FrameDetached( |
1327 blink::WebFrame* frame) { | 1360 blink::WebFrame* frame) { |
1328 agent_->FrameDetached(frame); | 1361 agent_->FrameDetached(frame); |
1329 } | 1362 } |
1330 | 1363 |
1331 } // namespace autofill | 1364 } // namespace autofill |
OLD | NEW |