Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: components/autofill/content/renderer/form_autofill_util.cc

Issue 2746033004: Add password form search using blink::WebNode reference comparison. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 bool ExtractFormData(const WebFormElement& form_element, FormData* data) { 1196 bool ExtractFormData(const WebFormElement& form_element, FormData* data) {
1197 return WebFormElementToFormData( 1197 return WebFormElementToFormData(
1198 form_element, WebFormControlElement(), nullptr, 1198 form_element, WebFormControlElement(), nullptr,
1199 static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE | 1199 static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE |
1200 form_util::EXTRACT_OPTION_TEXT | 1200 form_util::EXTRACT_OPTION_TEXT |
1201 form_util::EXTRACT_OPTIONS), 1201 form_util::EXTRACT_OPTIONS),
1202 data, NULL); 1202 data, NULL);
1203 } 1203 }
1204 1204
1205 bool IsFormVisible(blink::WebFrame* frame, 1205 bool IsFormVisible(blink::WebFrame* frame,
1206 const blink::WebFormElement& form_element,
1206 const GURL& canonical_action, 1207 const GURL& canonical_action,
1207 const GURL& canonical_origin, 1208 const GURL& canonical_origin,
1208 const FormData& form_data) { 1209 const FormData& form_data) {
1209 const GURL frame_origin = GetCanonicalOriginForDocument(frame->document()); 1210 const GURL frame_origin = GetCanonicalOriginForDocument(frame->document());
1210 blink::WebVector<WebFormElement> forms; 1211 blink::WebVector<WebFormElement> forms;
1211 frame->document().forms(forms); 1212 frame->document().forms(forms);
1212 1213
1213 // Omitting the action attribute would result in |canonical_origin| for 1214 // Omitting the action attribute would result in |canonical_origin| for
1214 // hierarchical schemes like http:, and in an empty URL for non-hierarchical 1215 // hierarchical schemes like http:, and in an empty URL for non-hierarchical
1215 // schemes like about: or data: etc. 1216 // schemes like about: or data: etc.
1216 const bool action_is_empty = canonical_action.is_empty() 1217 const bool action_is_empty = canonical_action.is_empty()
1217 || canonical_action == canonical_origin; 1218 || canonical_action == canonical_origin;
1218 1219
1219 // Since empty or unspecified action fields are automatically set to page URL, 1220 // Since empty or unspecified action fields are automatically set to page URL,
1220 // action field for forms cannot be used for comparing (all forms with 1221 // action field for forms cannot be used for comparing (all forms with
1221 // empty/unspecified actions have the same value). If an action field is set 1222 // empty/unspecified actions have the same value). If an action field is set
1222 // to the page URL, this method checks ALL fields of the form instead (using 1223 // to the page URL, this method checks ALL fields of the form instead (using
1223 // FormData.SameFormAs). This is also true if the action was set to the page 1224 // FormData.SameFormAs). This is also true if the action was set to the page
1224 // URL on purpose. 1225 // URL on purpose.
1225 for (const WebFormElement& form : forms) { 1226 for (const WebFormElement& form : forms) {
1226 if (!AreFormContentsVisible(form)) 1227 if (!AreFormContentsVisible(form))
1227 continue; 1228 continue;
1228 1229
1229 GURL iter_canonical_action = GetCanonicalActionForForm(form); 1230 GURL iter_canonical_action = GetCanonicalActionForForm(form);
1230 bool form_action_is_empty = iter_canonical_action.is_empty() || 1231 bool form_action_is_empty = iter_canonical_action.is_empty() ||
1231 iter_canonical_action == frame_origin; 1232 iter_canonical_action == frame_origin;
1232 if (action_is_empty != form_action_is_empty) 1233 if (action_is_empty != form_action_is_empty)
1233 continue; 1234 continue;
1234 1235
1236 // Try to match the WebFormElement reference first.
dvadym 2017/03/14 17:11:10 I think it's better to move up these lines before
sense (YandexTeam) 2017/03/15 04:51:24 Yes, I agree.
1237 if (!form_element.isNull() && form.equals(form_element)) {
dvadym 2017/03/14 17:11:10 Nit: you can use == operator (form == form_element
1238 return true; // Form still exists.
1239 }
1240
1235 if (action_is_empty) { // Both actions are empty, compare all fields. 1241 if (action_is_empty) { // Both actions are empty, compare all fields.
1236 FormData extracted_form_data; 1242 FormData extracted_form_data;
1237 WebFormElementToFormData(form, WebFormControlElement(), nullptr, 1243 WebFormElementToFormData(form, WebFormControlElement(), nullptr,
1238 EXTRACT_NONE, &extracted_form_data, nullptr); 1244 EXTRACT_NONE, &extracted_form_data, nullptr);
1239 if (form_data.SameFormAs(extracted_form_data)) { 1245 if (form_data.SameFormAs(extracted_form_data)) {
1240 return true; // Form still exists. 1246 return true; // Form still exists.
1241 } 1247 }
1242 } else { // Both actions are non-empty, compare actions only. 1248 } else { // Both actions are non-empty, compare actions only.
1243 if (canonical_action == iter_canonical_action) { 1249 if (canonical_action == iter_canonical_action) {
1244 return true; // Form still exists. 1250 return true; // Form still exists.
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 // Zero selection start is for password manager, which can show usernames 1816 // Zero selection start is for password manager, which can show usernames
1811 // that do not begin with the user input value. 1817 // that do not begin with the user input value.
1812 selection_start = (offset == base::string16::npos) ? 0 : offset; 1818 selection_start = (offset == base::string16::npos) ? 0 : offset;
1813 } 1819 }
1814 1820
1815 input_element->setSelectionRange(selection_start, suggestion.length()); 1821 input_element->setSelectionRange(selection_start, suggestion.length());
1816 } 1822 }
1817 1823
1818 } // namespace form_util 1824 } // namespace form_util
1819 } // namespace autofill 1825 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698