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 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 | 1098 |
1099 bool IsFormVisible(blink::WebFrame* frame, | 1099 bool IsFormVisible(blink::WebFrame* frame, |
1100 const GURL& canonical_action, | 1100 const GURL& canonical_action, |
1101 const GURL& canonical_origin, | 1101 const GURL& canonical_origin, |
1102 const FormData& form_data) { | 1102 const FormData& form_data) { |
1103 const GURL frame_url = GURL(frame->document().url().string().utf8()); | 1103 const GURL frame_url = GURL(frame->document().url().string().utf8()); |
1104 blink::WebVector<WebFormElement> forms; | 1104 blink::WebVector<WebFormElement> forms; |
1105 frame->document().forms(forms); | 1105 frame->document().forms(forms); |
1106 | 1106 |
1107 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 1107 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
1108 const bool action_is_empty = canonical_action == canonical_origin; | 1108 // Omitting the action attribute would result in |canonical_origin| for |
| 1109 // hierarchical schemes like http:, and in an empty URL for non-hierarchical |
| 1110 // schemes like about: or data: etc. |
| 1111 const bool action_is_empty = canonical_action.is_empty() |
| 1112 || canonical_action == canonical_origin; |
1109 #endif | 1113 #endif |
1110 | 1114 |
1111 // Since empty or unspecified action fields are automatically set to page URL, | 1115 // Since empty or unspecified action fields are automatically set to page URL, |
1112 // action field for forms cannot be used for comparing (all forms with | 1116 // action field for forms cannot be used for comparing (all forms with |
1113 // empty/unspecified actions have the same value). If an action field is set | 1117 // empty/unspecified actions have the same value). If an action field is set |
1114 // to the page URL, this method checks ALL fields of the form instead (using | 1118 // to the page URL, this method checks ALL fields of the form instead (using |
1115 // FormData.SameFormAs). This is also true if the action was set to the page | 1119 // FormData.SameFormAs). This is also true if the action was set to the page |
1116 // URL on purpose. | 1120 // URL on purpose. |
1117 for (const WebFormElement& form : forms) { | 1121 for (const WebFormElement& form : forms) { |
1118 if (!AreFormContentsVisible(form)) | 1122 if (!AreFormContentsVisible(form)) |
1119 continue; | 1123 continue; |
1120 | 1124 |
1121 GURL iter_canonical_action = GetCanonicalActionForForm(form); | 1125 GURL iter_canonical_action = GetCanonicalActionForForm(form); |
1122 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 1126 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
1123 bool form_action_is_empty = iter_canonical_action == frame_url; | 1127 bool form_action_is_empty = iter_canonical_action.is_empty() |
| 1128 || iter_canonical_action == frame_url; |
1124 | 1129 |
1125 if (action_is_empty != form_action_is_empty) | 1130 if (action_is_empty != form_action_is_empty) |
1126 continue; | 1131 continue; |
1127 | 1132 |
1128 if (action_is_empty) { // Both actions are empty, compare all fields. | 1133 if (action_is_empty) { // Both actions are empty, compare all fields. |
1129 FormData extracted_form_data; | 1134 FormData extracted_form_data; |
1130 WebFormElementToFormData(form, WebFormControlElement(), EXTRACT_NONE, | 1135 WebFormElementToFormData(form, WebFormControlElement(), EXTRACT_NONE, |
1131 &extracted_form_data, nullptr); | 1136 &extracted_form_data, nullptr); |
1132 if (form_data.SameFormAs(extracted_form_data)) { | 1137 if (form_data.SameFormAs(extracted_form_data)) { |
1133 return true; // Form still exists. | 1138 return true; // Form still exists. |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 // Zero selection start is for password manager, which can show usernames | 1653 // Zero selection start is for password manager, which can show usernames |
1649 // that do not begin with the user input value. | 1654 // that do not begin with the user input value. |
1650 selection_start = (offset == base::string16::npos) ? 0 : offset; | 1655 selection_start = (offset == base::string16::npos) ? 0 : offset; |
1651 } | 1656 } |
1652 | 1657 |
1653 input_element->setSelectionRange(selection_start, suggestion.length()); | 1658 input_element->setSelectionRange(selection_start, suggestion.length()); |
1654 } | 1659 } |
1655 | 1660 |
1656 } // namespace form_util | 1661 } // namespace form_util |
1657 } // namespace autofill | 1662 } // namespace autofill |
OLD | NEW |