| 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/form_autofill_util.h" | 5 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 bool IsFormVisible(blink::WebFrame* frame, | 1114 bool IsFormVisible(blink::WebFrame* frame, |
| 1115 const GURL& canonical_action, | 1115 const GURL& canonical_action, |
| 1116 const GURL& canonical_origin, | 1116 const GURL& canonical_origin, |
| 1117 const FormData& form_data, | 1117 const FormData& form_data, |
| 1118 const FormsPredictionsMap& form_predictions) { | 1118 const FormsPredictionsMap& form_predictions) { |
| 1119 const GURL frame_url = GURL(frame->document().url().string().utf8()); | 1119 const GURL frame_url = GURL(frame->document().url().string().utf8()); |
| 1120 blink::WebVector<blink::WebFormElement> forms; | 1120 blink::WebVector<blink::WebFormElement> forms; |
| 1121 frame->document().forms(forms); | 1121 frame->document().forms(forms); |
| 1122 | 1122 |
| 1123 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 1123 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 1124 const bool action_is_empty = canonical_action == canonical_origin; | 1124 // Omitting the action attribute would result in |canonical_origin| for |
| 1125 // hierarchical schemes like http:, and in an empty URL for non-hierarchical |
| 1126 // schemes like about: or data: etc. |
| 1127 const bool action_is_empty = canonical_action.is_empty() |
| 1128 || canonical_action == canonical_origin; |
| 1125 #endif | 1129 #endif |
| 1126 | 1130 |
| 1127 // Since empty or unspecified action fields are automatically set to page URL, | 1131 // Since empty or unspecified action fields are automatically set to page URL, |
| 1128 // action field for forms cannot be used for comparing (all forms with | 1132 // action field for forms cannot be used for comparing (all forms with |
| 1129 // empty/unspecified actions have the same value). If an action field is set | 1133 // empty/unspecified actions have the same value). If an action field is set |
| 1130 // to the page URL, this method checks ALL fields of the form instead (using | 1134 // to the page URL, this method checks ALL fields of the form instead (using |
| 1131 // FormData.SameFormAs). This is also true if the action was set to the page | 1135 // FormData.SameFormAs). This is also true if the action was set to the page |
| 1132 // URL on purpose. | 1136 // URL on purpose. |
| 1133 for (size_t i = 0; i < forms.size(); ++i) { | 1137 for (size_t i = 0; i < forms.size(); ++i) { |
| 1134 const blink::WebFormElement& form = forms[i]; | 1138 const blink::WebFormElement& form = forms[i]; |
| 1135 if (!IsWebNodeVisible(form)) | 1139 if (!IsWebNodeVisible(form)) |
| 1136 continue; | 1140 continue; |
| 1137 | 1141 |
| 1138 GURL iter_canonical_action = GetCanonicalActionForForm(form); | 1142 GURL iter_canonical_action = GetCanonicalActionForForm(form); |
| 1139 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 1143 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 1140 bool form_action_is_empty = iter_canonical_action == frame_url; | 1144 bool form_action_is_empty = iter_canonical_action.is_empty() |
| 1145 || iter_canonical_action == frame_url; |
| 1141 | 1146 |
| 1142 if (action_is_empty != form_action_is_empty) | 1147 if (action_is_empty != form_action_is_empty) |
| 1143 continue; | 1148 continue; |
| 1144 | 1149 |
| 1145 if (action_is_empty) { // Both actions are empty, compare all fields. | 1150 if (action_is_empty) { // Both actions are empty, compare all fields. |
| 1146 FormData extracted_form_data; | 1151 FormData extracted_form_data; |
| 1147 WebFormElementToFormData(form, blink::WebFormControlElement(), | 1152 WebFormElementToFormData(form, blink::WebFormControlElement(), |
| 1148 EXTRACT_NONE, &extracted_form_data, nullptr); | 1153 EXTRACT_NONE, &extracted_form_data, nullptr); |
| 1149 if (form_data.SameFormAs(extracted_form_data)) { | 1154 if (form_data.SameFormAs(extracted_form_data)) { |
| 1150 return true; // Form still exists. | 1155 return true; // Form still exists. |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 // Zero selection start is for password manager, which can show usernames | 1648 // Zero selection start is for password manager, which can show usernames |
| 1644 // that do not begin with the user input value. | 1649 // that do not begin with the user input value. |
| 1645 selection_start = (offset == base::string16::npos) ? 0 : offset; | 1650 selection_start = (offset == base::string16::npos) ? 0 : offset; |
| 1646 } | 1651 } |
| 1647 | 1652 |
| 1648 input_element->setSelectionRange(selection_start, suggestion.length()); | 1653 input_element->setSelectionRange(selection_start, suggestion.length()); |
| 1649 } | 1654 } |
| 1650 | 1655 |
| 1651 } // namespace form_util | 1656 } // namespace form_util |
| 1652 } // namespace autofill | 1657 } // namespace autofill |
| OLD | NEW |