Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/form_autofill_util.h" | 5 #include "components/autofill/renderer/form_autofill_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/metrics/field_trial.h" | |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "components/autofill/common/autofill_switches.h" | 15 #include "components/autofill/common/autofill_switches.h" |
| 15 #include "components/autofill/common/form_data.h" | 16 #include "components/autofill/common/form_data.h" |
| 16 #include "components/autofill/common/form_field_data.h" | 17 #include "components/autofill/common/form_field_data.h" |
| 17 #include "components/autofill/common/web_element_descriptor.h" | 18 #include "components/autofill/common/web_element_descriptor.h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 74 |
| 74 bool HasTagName(const WebNode& node, const WebKit::WebString& tag) { | 75 bool HasTagName(const WebNode& node, const WebKit::WebString& tag) { |
| 75 return node.isElementNode() && node.toConst<WebElement>().hasTagName(tag); | 76 return node.isElementNode() && node.toConst<WebElement>().hasTagName(tag); |
| 76 } | 77 } |
| 77 | 78 |
| 78 bool IsAutofillableElement(const WebFormControlElement& element) { | 79 bool IsAutofillableElement(const WebFormControlElement& element) { |
| 79 const WebInputElement* input_element = toWebInputElement(&element); | 80 const WebInputElement* input_element = toWebInputElement(&element); |
| 80 return IsAutofillableInputElement(input_element) || IsSelectElement(element); | 81 return IsAutofillableInputElement(input_element) || IsSelectElement(element); |
| 81 } | 82 } |
| 82 | 83 |
| 84 bool IsAutocheckoutEnabled() { | |
| 85 return base::FieldTrialList::FindFullName("Autocheckout") == "Yes" || | |
|
Ilya Sherman
2013/04/13 01:12:09
I'm not sure that all field trials are automatical
Alexei Svitkine (slow)
2013/04/15 15:24:13
I believe we only tell the renderer of studies tha
Raman Kakilate
2013/04/15 15:49:52
Done. Verified that Autocheckout field trial is in
| |
| 86 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 87 switches::kEnableExperimentalFormFilling); | |
| 88 } | |
| 89 | |
| 83 // Check whether the given field satisfies the REQUIRE_AUTOCOMPLETE requirement. | 90 // Check whether the given field satisfies the REQUIRE_AUTOCOMPLETE requirement. |
| 84 // When Autocheckout is enabled, this requirement is enforced in the browser | 91 // When Autocheckout is enabled, this requirement is enforced in the browser |
| 85 // process rather than in the renderer process, and hence all fields are | 92 // process rather than in the renderer process, and hence all fields are |
| 86 // considered to satisfy this requirement. | 93 // considered to satisfy this requirement. |
| 87 bool SatisfiesRequireAutocomplete(const WebInputElement& input_element) { | 94 bool SatisfiesRequireAutocomplete(const WebInputElement& input_element) { |
| 88 return input_element.autoComplete() || | 95 return input_element.autoComplete() || IsAutocheckoutEnabled(); |
| 89 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 90 switches::kEnableExperimentalFormFilling); | |
| 91 } | 96 } |
| 92 | 97 |
| 93 // Appends |suffix| to |prefix| so that any intermediary whitespace is collapsed | 98 // Appends |suffix| to |prefix| so that any intermediary whitespace is collapsed |
| 94 // to a single space. If |force_whitespace| is true, then the resulting string | 99 // to a single space. If |force_whitespace| is true, then the resulting string |
| 95 // is guaranteed to have a space between |prefix| and |suffix|. Otherwise, the | 100 // is guaranteed to have a space between |prefix| and |suffix|. Otherwise, the |
| 96 // result includes a space only if |prefix| has trailing whitespace or |suffix| | 101 // result includes a space only if |prefix| has trailing whitespace or |suffix| |
| 97 // has leading whitespace. | 102 // has leading whitespace. |
| 98 // A few examples: | 103 // A few examples: |
| 99 // * CombineAndCollapseWhitespace("foo", "bar", false) -> "foobar" | 104 // * CombineAndCollapseWhitespace("foo", "bar", false) -> "foobar" |
| 100 // * CombineAndCollapseWhitespace("foo", "bar", true) -> "foo bar" | 105 // * CombineAndCollapseWhitespace("foo", "bar", true) -> "foo bar" |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 continue; | 1027 continue; |
| 1023 | 1028 |
| 1024 if (input_element->isAutofilled()) | 1029 if (input_element->isAutofilled()) |
| 1025 return true; | 1030 return true; |
| 1026 } | 1031 } |
| 1027 | 1032 |
| 1028 return false; | 1033 return false; |
| 1029 } | 1034 } |
| 1030 | 1035 |
| 1031 } // namespace autofill | 1036 } // namespace autofill |
| OLD | NEW |