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