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" |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 if (!IsElementAutocompletable(element) || | 851 if (!IsElementAutocompletable(element) || |
852 !IsElementAutocompletable(password_info->password_field)) | 852 !IsElementAutocompletable(password_info->password_field)) |
853 return true; | 853 return true; |
854 | 854 |
855 bool username_is_available = | 855 bool username_is_available = |
856 !username_element->isNull() && IsElementEditable(*username_element); | 856 !username_element->isNull() && IsElementEditable(*username_element); |
857 // If the element is a password field, a popup should only be shown if there | 857 // If the element is a password field, a popup should only be shown if there |
858 // is no username or the corresponding username element is not editable since | 858 // is no username or the corresponding username element is not editable since |
859 // it is only in that case that the username element does not have a | 859 // it is only in that case that the username element does not have a |
860 // suggestions popup. | 860 // suggestions popup. |
861 if (element.isPasswordField() && username_is_available) | 861 if (element.isPasswordField() && username_is_available && |
862 (!password_info->fill_data.is_change_password_form || | |
Garrett Casto
2015/06/12 00:09:09
Instead of keeping an additional structure, how ab
dvadym
2015/06/12 17:22:37
I agree, that it's better to be simpler, so I've r
| |
863 (password_info->fill_data.is_change_password_form && | |
864 had_focus_username_fields_.find(*username_element) != | |
865 had_focus_username_fields_.end()))) | |
862 return true; | 866 return true; |
863 | 867 |
864 // Chrome should never show more than one account for a password element since | 868 // Chrome should never show more than one account for a password element since |
865 // this implies that the username element cannot be modified. Thus even if | 869 // this implies that the username element cannot be modified. Thus even if |
866 // |show_all| is true, check if the element in question is a password element | 870 // |show_all| is true, check if the element in question is a password element |
867 // for the call to ShowSuggestionPopup. | 871 // for the call to ShowSuggestionPopup. |
868 return ShowSuggestionPopup( | 872 return ShowSuggestionPopup( |
869 password_info->fill_data, | 873 password_info->fill_data, |
870 username_element->isNull() ? element : *username_element, | 874 username_element->isNull() ? element : *username_element, |
871 show_all && !element.isPasswordField(), element.isPasswordField()); | 875 show_all && !element.isPasswordField(), element.isPasswordField()); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1389 } | 1393 } |
1390 | 1394 |
1391 void PasswordAutofillAgent::FrameClosing() { | 1395 void PasswordAutofillAgent::FrameClosing() { |
1392 for (auto const& iter : login_to_password_info_) { | 1396 for (auto const& iter : login_to_password_info_) { |
1393 login_to_password_info_key_.erase(iter.first); | 1397 login_to_password_info_key_.erase(iter.first); |
1394 password_to_username_.erase(iter.second.password_field); | 1398 password_to_username_.erase(iter.second.password_field); |
1395 } | 1399 } |
1396 login_to_password_info_.clear(); | 1400 login_to_password_info_.clear(); |
1397 provisionally_saved_form_.reset(); | 1401 provisionally_saved_form_.reset(); |
1398 nonscript_modified_values_.clear(); | 1402 nonscript_modified_values_.clear(); |
1403 had_focus_username_fields_.clear(); | |
1399 } | 1404 } |
1400 | 1405 |
1401 bool PasswordAutofillAgent::FindLoginInfo(const blink::WebNode& node, | 1406 bool PasswordAutofillAgent::FindLoginInfo(const blink::WebNode& node, |
1402 blink::WebInputElement* found_input, | 1407 blink::WebInputElement* found_input, |
1403 PasswordInfo** found_password) { | 1408 PasswordInfo** found_password) { |
1404 if (!node.isElementNode()) | 1409 if (!node.isElementNode()) |
1405 return false; | 1410 return false; |
1406 | 1411 |
1407 blink::WebElement element = node.toConst<blink::WebElement>(); | 1412 blink::WebElement element = node.toConst<blink::WebElement>(); |
1408 if (!element.hasHTMLTagName("input")) | 1413 if (!element.hasHTMLTagName("input")) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1442 provisionally_saved_form_ = password_form.Pass(); | 1447 provisionally_saved_form_ = password_form.Pass(); |
1443 } | 1448 } |
1444 | 1449 |
1445 bool PasswordAutofillAgent::ProvisionallySavedPasswordIsValid() { | 1450 bool PasswordAutofillAgent::ProvisionallySavedPasswordIsValid() { |
1446 return provisionally_saved_form_ && | 1451 return provisionally_saved_form_ && |
1447 !provisionally_saved_form_->username_value.empty() && | 1452 !provisionally_saved_form_->username_value.empty() && |
1448 !(provisionally_saved_form_->password_value.empty() && | 1453 !(provisionally_saved_form_->password_value.empty() && |
1449 provisionally_saved_form_->new_password_value.empty()); | 1454 provisionally_saved_form_->new_password_value.empty()); |
1450 } | 1455 } |
1451 | 1456 |
1457 void PasswordAutofillAgent::FocusedNodeChanged(const blink::WebNode& node) { | |
1458 if (node.isNull() || !node.isElementNode()) | |
1459 return; | |
1460 | |
1461 blink::WebElement web_element = node.toConst<blink::WebElement>(); | |
1462 const blink::WebInputElement* element = toWebInputElement(&web_element); | |
1463 | |
1464 // If |element| is a username element then add it to username elements that | |
1465 // had focus. | |
1466 if (element && element->isTextField() && | |
1467 login_to_password_info_.find(*element) != login_to_password_info_.end()) { | |
1468 had_focus_username_fields_.insert(*element); | |
1469 } | |
1470 } | |
1471 | |
1452 // LegacyPasswordAutofillAgent ------------------------------------------------- | 1472 // LegacyPasswordAutofillAgent ------------------------------------------------- |
1453 | 1473 |
1454 PasswordAutofillAgent::LegacyPasswordAutofillAgent::LegacyPasswordAutofillAgent( | 1474 PasswordAutofillAgent::LegacyPasswordAutofillAgent::LegacyPasswordAutofillAgent( |
1455 content::RenderView* render_view, | 1475 content::RenderView* render_view, |
1456 PasswordAutofillAgent* agent) | 1476 PasswordAutofillAgent* agent) |
1457 : content::RenderViewObserver(render_view), agent_(agent) { | 1477 : content::RenderViewObserver(render_view), agent_(agent) { |
1458 } | 1478 } |
1459 | 1479 |
1460 PasswordAutofillAgent::LegacyPasswordAutofillAgent:: | 1480 PasswordAutofillAgent::LegacyPasswordAutofillAgent:: |
1461 ~LegacyPasswordAutofillAgent() { | 1481 ~LegacyPasswordAutofillAgent() { |
(...skipping 10 matching lines...) Expand all Loading... | |
1472 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { | 1492 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { |
1473 agent_->DidStopLoading(); | 1493 agent_->DidStopLoading(); |
1474 } | 1494 } |
1475 | 1495 |
1476 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: | 1496 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: |
1477 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { | 1497 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { |
1478 agent_->LegacyDidStartProvisionalLoad(navigated_frame); | 1498 agent_->LegacyDidStartProvisionalLoad(navigated_frame); |
1479 } | 1499 } |
1480 | 1500 |
1481 } // namespace autofill | 1501 } // namespace autofill |
OLD | NEW |