| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "components/autofill/content/common/autofill_messages.h" | 15 #include "components/autofill/content/common/autofill_messages.h" |
| 16 #include "components/autofill/content/renderer/form_autofill_util.h" | 16 #include "components/autofill/content/renderer/form_autofill_util.h" |
| 17 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 17 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
| 18 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" | 18 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
| 19 #include "components/autofill/core/common/autofill_constants.h" | 19 #include "components/autofill/core/common/autofill_constants.h" |
| 20 #include "components/autofill/core/common/autofill_switches.h" | 20 #include "components/autofill/core/common/autofill_switches.h" |
| 21 #include "components/autofill/core/common/autofill_util.h" |
| 21 #include "components/autofill/core/common/form_field_data.h" | 22 #include "components/autofill/core/common/form_field_data.h" |
| 22 #include "components/autofill/core/common/password_form.h" | 23 #include "components/autofill/core/common/password_form.h" |
| 23 #include "components/autofill/core/common/password_form_fill_data.h" | 24 #include "components/autofill/core/common/password_form_fill_data.h" |
| 24 #include "content/public/renderer/document_state.h" | 25 #include "content/public/renderer/document_state.h" |
| 25 #include "content/public/renderer/navigation_state.h" | 26 #include "content/public/renderer/navigation_state.h" |
| 26 #include "content/public/renderer/render_frame.h" | 27 #include "content/public/renderer/render_frame.h" |
| 27 #include "content/public/renderer/render_view.h" | 28 #include "content/public/renderer/render_view.h" |
| 28 #include "third_party/WebKit/public/platform/WebVector.h" | 29 #include "third_party/WebKit/public/platform/WebVector.h" |
| 29 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 30 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
| 30 #include "third_party/WebKit/public/web/WebDocument.h" | 31 #include "third_party/WebKit/public/web/WebDocument.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 220 |
| 220 bool IsElementEditable(const blink::WebInputElement& element) { | 221 bool IsElementEditable(const blink::WebInputElement& element) { |
| 221 return element.isEnabled() && !element.isReadOnly(); | 222 return element.isEnabled() && !element.isReadOnly(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 bool DoUsernamesMatch(const base::string16& username1, | 225 bool DoUsernamesMatch(const base::string16& username1, |
| 225 const base::string16& username2, | 226 const base::string16& username2, |
| 226 bool exact_match) { | 227 bool exact_match) { |
| 227 if (exact_match) | 228 if (exact_match) |
| 228 return username1 == username2; | 229 return username1 == username2; |
| 229 return base::StartsWith(username1, username2, base::CompareCase::SENSITIVE); | 230 return base::StartsWith(username1, username2, base::CompareCase::SENSITIVE) || |
| 231 ContainsTokenThatStartsWith(username1, username2, true); |
| 230 } | 232 } |
| 231 | 233 |
| 232 // Returns |true| if the given element is editable. Otherwise, returns |false|. | 234 // Returns |true| if the given element is editable. Otherwise, returns |false|. |
| 233 bool IsElementAutocompletable(const blink::WebInputElement& element) { | 235 bool IsElementAutocompletable(const blink::WebInputElement& element) { |
| 234 return IsElementEditable(element); | 236 return IsElementEditable(element); |
| 235 } | 237 } |
| 236 | 238 |
| 237 // Returns true if the password specified in |form| is a default value. | 239 // Returns true if the password specified in |form| is a default value. |
| 238 bool PasswordValueIsDefault(const base::string16& password_element, | 240 bool PasswordValueIsDefault(const base::string16& password_element, |
| 239 const base::string16& password_value, | 241 const base::string16& password_value, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 416 |
| 415 // TODO(tkent): Check maxlength and pattern for both username and password | 417 // TODO(tkent): Check maxlength and pattern for both username and password |
| 416 // fields. | 418 // fields. |
| 417 | 419 |
| 418 // Input matches the username, fill in required values. | 420 // Input matches the username, fill in required values. |
| 419 if (!username_element->isNull() && | 421 if (!username_element->isNull() && |
| 420 IsElementAutocompletable(*username_element)) { | 422 IsElementAutocompletable(*username_element)) { |
| 421 username_element->setValue(username, true); | 423 username_element->setValue(username, true); |
| 422 nonscript_modified_values[*username_element] = username; | 424 nonscript_modified_values[*username_element] = username; |
| 423 username_element->setAutofilled(true); | 425 username_element->setAutofilled(true); |
| 424 | 426 if (set_selection) |
| 425 if (set_selection) { | 427 PreviewSuggestion(username, current_username, username_element); |
| 426 username_element->setSelectionRange(current_username.length(), | |
| 427 username.length()); | |
| 428 } | |
| 429 } else if (current_username != username) { | 428 } else if (current_username != username) { |
| 430 // If the username can't be filled and it doesn't match a saved password | 429 // If the username can't be filled and it doesn't match a saved password |
| 431 // as is, don't autofill a password. | 430 // as is, don't autofill a password. |
| 432 return other_possible_username_selected; | 431 return other_possible_username_selected; |
| 433 } | 432 } |
| 434 | 433 |
| 435 // Wait to fill in the password until a user gesture occurs. This is to make | 434 // Wait to fill in the password until a user gesture occurs. This is to make |
| 436 // sure that we do not fill in the DOM with a password until we believe the | 435 // sure that we do not fill in the DOM with a password until we believe the |
| 437 // user is intentionally interacting with the page. | 436 // user is intentionally interacting with the page. |
| 438 password_element->setSuggestedValue(password); | 437 password_element->setSuggestedValue(password); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 if (!FindLoginInfo(node, &username_element, &password_info) || | 795 if (!FindLoginInfo(node, &username_element, &password_info) || |
| 797 !IsElementAutocompletable(username_element) || | 796 !IsElementAutocompletable(username_element) || |
| 798 !IsElementAutocompletable(password_info->password_field)) { | 797 !IsElementAutocompletable(password_info->password_field)) { |
| 799 return false; | 798 return false; |
| 800 } | 799 } |
| 801 | 800 |
| 802 was_username_autofilled_ = username_element.isAutofilled(); | 801 was_username_autofilled_ = username_element.isAutofilled(); |
| 803 username_selection_start_ = username_element.selectionStart(); | 802 username_selection_start_ = username_element.selectionStart(); |
| 804 username_element.setSuggestedValue(username); | 803 username_element.setSuggestedValue(username); |
| 805 username_element.setAutofilled(true); | 804 username_element.setAutofilled(true); |
| 806 username_element.setSelectionRange( | 805 ::autofill::PreviewSuggestion(username_element.suggestedValue(), |
| 807 username_selection_start_, | 806 username_element.value(), &username_element); |
| 808 username_element.suggestedValue().length()); | |
| 809 | |
| 810 was_password_autofilled_ = password_info->password_field.isAutofilled(); | 807 was_password_autofilled_ = password_info->password_field.isAutofilled(); |
| 811 password_info->password_field.setSuggestedValue(password); | 808 password_info->password_field.setSuggestedValue(password); |
| 812 password_info->password_field.setAutofilled(true); | 809 password_info->password_field.setAutofilled(true); |
| 813 | 810 |
| 814 return true; | 811 return true; |
| 815 } | 812 } |
| 816 | 813 |
| 817 bool PasswordAutofillAgent::DidClearAutofillSelection( | 814 bool PasswordAutofillAgent::DidClearAutofillSelection( |
| 818 const blink::WebNode& node) { | 815 const blink::WebNode& node) { |
| 819 blink::WebInputElement username_element; | 816 blink::WebInputElement username_element; |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { | 1495 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { |
| 1499 agent_->DidStopLoading(); | 1496 agent_->DidStopLoading(); |
| 1500 } | 1497 } |
| 1501 | 1498 |
| 1502 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: | 1499 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: |
| 1503 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { | 1500 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { |
| 1504 agent_->LegacyDidStartProvisionalLoad(navigated_frame); | 1501 agent_->LegacyDidStartProvisionalLoad(navigated_frame); |
| 1505 } | 1502 } |
| 1506 | 1503 |
| 1507 } // namespace autofill | 1504 } // namespace autofill |
| OLD | NEW |