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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "components/autofill/content/common/autofill_messages.h" | 12 #include "components/autofill/content/common/autofill_messages.h" |
13 #include "components/autofill/content/renderer/form_autofill_util.h" | 13 #include "components/autofill/content/renderer/form_autofill_util.h" |
14 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 14 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
15 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" | 15 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
16 #include "components/autofill/core/common/form_field_data.h" | 16 #include "components/autofill/core/common/form_field_data.h" |
17 #include "components/autofill/core/common/password_autofill_util.h" | |
18 #include "components/autofill/core/common/password_form.h" | 17 #include "components/autofill/core/common/password_form.h" |
19 #include "components/autofill/core/common/password_form_fill_data.h" | 18 #include "components/autofill/core/common/password_form_fill_data.h" |
20 #include "content/public/renderer/document_state.h" | 19 #include "content/public/renderer/document_state.h" |
21 #include "content/public/renderer/navigation_state.h" | 20 #include "content/public/renderer/navigation_state.h" |
22 #include "content/public/renderer/render_view.h" | 21 #include "content/public/renderer/render_view.h" |
23 #include "third_party/WebKit/public/platform/WebVector.h" | 22 #include "third_party/WebKit/public/platform/WebVector.h" |
24 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 23 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
25 #include "third_party/WebKit/public/web/WebDocument.h" | 24 #include "third_party/WebKit/public/web/WebDocument.h" |
26 #include "third_party/WebKit/public/web/WebElement.h" | 25 #include "third_party/WebKit/public/web/WebElement.h" |
27 #include "third_party/WebKit/public/web/WebFormElement.h" | 26 #include "third_party/WebKit/public/web/WebFormElement.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 177 } |
179 | 178 |
180 bool DoUsernamesMatch(const base::string16& username1, | 179 bool DoUsernamesMatch(const base::string16& username1, |
181 const base::string16& username2, | 180 const base::string16& username2, |
182 bool exact_match) { | 181 bool exact_match) { |
183 if (exact_match) | 182 if (exact_match) |
184 return username1 == username2; | 183 return username1 == username2; |
185 return StartsWith(username1, username2, true); | 184 return StartsWith(username1, username2, true); |
186 } | 185 } |
187 | 186 |
188 // Returns |true| if the given element is both editable and has permission to be | 187 // Returns |true| if the given element is editable. Otherwise, returns |false|. |
189 // autocompleted. The latter can be either because there is no | |
190 // autocomplete='off' set for the element, or because the flag is set to ignore | |
191 // autocomplete='off'. Otherwise, returns |false|. | |
192 bool IsElementAutocompletable(const blink::WebInputElement& element) { | 188 bool IsElementAutocompletable(const blink::WebInputElement& element) { |
193 return IsElementEditable(element) && | 189 return IsElementEditable(element); |
194 (ShouldIgnoreAutocompleteOffForPasswordFields() || | |
195 element.autoComplete()); | |
196 } | 190 } |
197 | 191 |
198 // Returns true if the password specified in |form| is a default value. | 192 // Returns true if the password specified in |form| is a default value. |
199 bool PasswordValueIsDefault(const base::string16& password_element, | 193 bool PasswordValueIsDefault(const base::string16& password_element, |
200 const base::string16& password_value, | 194 const base::string16& password_value, |
201 blink::WebFormElement form_element) { | 195 blink::WebFormElement form_element) { |
202 blink::WebVector<blink::WebNode> temp_elements; | 196 blink::WebVector<blink::WebNode> temp_elements; |
203 form_element.getNamedElements(password_element, temp_elements); | 197 form_element.getNamedElements(password_element, temp_elements); |
204 | 198 |
205 // We are loose in our definition here and will return true if any of the | 199 // We are loose in our definition here and will return true if any of the |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 bool FillFormOnPasswordRecieved( | 384 bool FillFormOnPasswordRecieved( |
391 const PasswordFormFillData& fill_data, | 385 const PasswordFormFillData& fill_data, |
392 blink::WebInputElement username_element, | 386 blink::WebInputElement username_element, |
393 blink::WebInputElement password_element, | 387 blink::WebInputElement password_element, |
394 base::Callback<void(blink::WebInputElement*)> registration_callback) { | 388 base::Callback<void(blink::WebInputElement*)> registration_callback) { |
395 // Do not fill if the password field is in an iframe. | 389 // Do not fill if the password field is in an iframe. |
396 DCHECK(password_element.document().frame()); | 390 DCHECK(password_element.document().frame()); |
397 if (password_element.document().frame()->parent()) | 391 if (password_element.document().frame()->parent()) |
398 return false; | 392 return false; |
399 | 393 |
400 bool form_contains_username_field = FillDataContainsUsername(fill_data); | |
401 if (!ShouldIgnoreAutocompleteOffForPasswordFields() && | |
402 form_contains_username_field && !username_element.form().autoComplete()) | |
403 return false; | |
404 | |
405 // If we can't modify the password, don't try to set the username | 394 // If we can't modify the password, don't try to set the username |
406 if (!IsElementAutocompletable(password_element)) | 395 if (!IsElementAutocompletable(password_element)) |
407 return false; | 396 return false; |
408 | 397 |
| 398 bool form_contains_username_field = FillDataContainsUsername(fill_data); |
409 // Try to set the username to the preferred name, but only if the field | 399 // Try to set the username to the preferred name, but only if the field |
410 // can be set and isn't prefilled. | 400 // can be set and isn't prefilled. |
411 if (form_contains_username_field && | 401 if (form_contains_username_field && |
412 IsElementAutocompletable(username_element) && | 402 IsElementAutocompletable(username_element) && |
413 username_element.value().isEmpty()) { | 403 username_element.value().isEmpty()) { |
414 // TODO(tkent): Check maxlength and pattern. | 404 // TODO(tkent): Check maxlength and pattern. |
415 username_element.setValue(fill_data.basic_data.fields[0].value, true); | 405 username_element.setValue(fill_data.basic_data.fields[0].value, true); |
416 } | 406 } |
417 | 407 |
418 // Fill if we have an exact match for the username. Note that this sets | 408 // Fill if we have an exact match for the username. Note that this sets |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); | 1233 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); |
1244 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && | 1234 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && |
1245 password_form->password_value.empty() && | 1235 password_form->password_value.empty() && |
1246 password_form->new_password_value.empty())) { | 1236 password_form->new_password_value.empty())) { |
1247 return; | 1237 return; |
1248 } | 1238 } |
1249 provisionally_saved_forms_[frame].reset(password_form.release()); | 1239 provisionally_saved_forms_[frame].reset(password_form.release()); |
1250 } | 1240 } |
1251 | 1241 |
1252 } // namespace autofill | 1242 } // namespace autofill |
OLD | NEW |