| 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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 username_element->isNull() ? element : *username_element, | 841 username_element->isNull() ? element : *username_element, |
| 842 show_all && !element.isPasswordField(), element.isPasswordField()); | 842 show_all && !element.isPasswordField(), element.isPasswordField()); |
| 843 } | 843 } |
| 844 | 844 |
| 845 bool PasswordAutofillAgent::OriginCanAccessPasswordManager( | 845 bool PasswordAutofillAgent::OriginCanAccessPasswordManager( |
| 846 const blink::WebSecurityOrigin& origin) { | 846 const blink::WebSecurityOrigin& origin) { |
| 847 return origin.canAccessPasswordManager(); | 847 return origin.canAccessPasswordManager(); |
| 848 } | 848 } |
| 849 | 849 |
| 850 void PasswordAutofillAgent::OnDynamicFormsSeen() { | 850 void PasswordAutofillAgent::OnDynamicFormsSeen() { |
| 851 //LOG(INFO) << this << "DynamicFormsSeen"; |
| 851 SendPasswordForms(false /* only_visible */); | 852 SendPasswordForms(false /* only_visible */); |
| 852 } | 853 } |
| 853 | 854 |
| 855 void PasswordAutofillAgent::OnFormElementsRemoved( |
| 856 const blink::WebVector<blink::WebNode>& nodes) { |
| 857 //LOG(INFO) << nodes.size(); |
| 858 std::set<blink::WebFormElement> form_elements; |
| 859 for (size_t i = 0; i < nodes.size(); ++i) { |
| 860 if (!nodes[i].isElementNode()) { |
| 861 //LOG(INFO) << "early exit"; |
| 862 continue; |
| 863 } |
| 864 |
| 865 blink::WebElement element = nodes[i].toConst<blink::WebElement>(); |
| 866 if (!element.hasHTMLTagName("input")) { |
| 867 //LOG(INFO) << "later exit"; |
| 868 continue; |
| 869 } |
| 870 |
| 871 blink::WebInputElement input_element = element.to<blink::WebInputElement>(); |
| 872 //LOG(INFO) << input_element.getAttribute("id").utf8(); |
| 873 if (!input_element.form().isNull()) { |
| 874 //LOG(INFO) << input_element.form().name().utf8(); |
| 875 form_elements.insert(input_element.form()); |
| 876 } else { |
| 877 //LOG(INFO) << "no form"; |
| 878 } |
| 879 } |
| 880 //LOG(INFO) << form_elements.size(); |
| 881 |
| 882 if (!provisionally_saved_form_ || |
| 883 provisionally_saved_form_->username_value.empty() || |
| 884 (provisionally_saved_form_->password_value.empty() && |
| 885 provisionally_saved_form_->new_password_value.empty())) { |
| 886 //LOG(INFO) << "no provisionally saved form"; |
| 887 return; |
| 888 } |
| 889 |
| 890 //LOG(INFO) << provisionally_saved_form_->action; |
| 891 for (std::set<blink::WebFormElement>::iterator it = form_elements.begin(); |
| 892 it != form_elements.end(); ++it) { |
| 893 GURL action(GetCanonicalActionURL(*it)); |
| 894 //LOG(INFO) << action.spec(); |
| 895 if (action == provisionally_saved_form_->action) { |
| 896 Send(new AutofillHostMsg_PasswordFormSubmitted( |
| 897 routing_id(), *provisionally_saved_form_)); |
| 898 provisionally_saved_form_.reset(); |
| 899 return; |
| 900 } |
| 901 } |
| 902 } |
| 903 |
| 854 void PasswordAutofillAgent::FirstUserGestureObserved() { | 904 void PasswordAutofillAgent::FirstUserGestureObserved() { |
| 855 gatekeeper_.OnUserGesture(); | 905 gatekeeper_.OnUserGesture(); |
| 856 } | 906 } |
| 857 | 907 |
| 858 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { | 908 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { |
| 859 scoped_ptr<RendererSavePasswordProgressLogger> logger; | 909 scoped_ptr<RendererSavePasswordProgressLogger> logger; |
| 860 if (logging_state_active_) { | 910 if (logging_state_active_) { |
| 861 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); | 911 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); |
| 862 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD); | 912 logger->LogMessage(Logger::STRING_SEND_PASSWORD_FORMS_METHOD); |
| 863 logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible); | 913 logger->LogBoolean(Logger::STRING_ONLY_VISIBLE, only_visible); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 usernames_usage_, OTHER_POSSIBLE_USERNAMES_MAX); | 1035 usernames_usage_, OTHER_POSSIBLE_USERNAMES_MAX); |
| 986 usernames_usage_ = NOTHING_TO_AUTOFILL; | 1036 usernames_usage_ = NOTHING_TO_AUTOFILL; |
| 987 } | 1037 } |
| 988 } | 1038 } |
| 989 | 1039 |
| 990 void PasswordAutofillAgent::DidStopLoading() { | 1040 void PasswordAutofillAgent::DidStopLoading() { |
| 991 did_stop_loading_ = true; | 1041 did_stop_loading_ = true; |
| 992 } | 1042 } |
| 993 | 1043 |
| 994 void PasswordAutofillAgent::FrameDetached() { | 1044 void PasswordAutofillAgent::FrameDetached() { |
| 1045 /* LOG(INFO) << this << "closing"; |
| 1046 if (!render_frame()->GetWebFrame()->parent()) |
| 1047 LOG(INFO) << "MainFrame"; |
| 1048 if (ProvisionallySavedPasswordIsValid()) |
| 1049 LOG(INFO) << "Password Valid";*/ |
| 1050 if (render_frame()->GetWebFrame()->parent() && |
| 1051 ProvisionallySavedPasswordIsValid()) { |
| 1052 //LOG(INFO) << "SENDING"; |
| 1053 Send(new AutofillHostMsg_PasswordFormSubmitted( |
| 1054 routing_id(), *provisionally_saved_form_)); |
| 1055 provisionally_saved_form_.reset(); |
| 1056 } |
| 995 FrameClosing(); | 1057 FrameClosing(); |
| 996 } | 1058 } |
| 997 | 1059 |
| 998 void PasswordAutofillAgent::WillSendSubmitEvent( | 1060 void PasswordAutofillAgent::WillSendSubmitEvent( |
| 999 const blink::WebFormElement& form) { | 1061 const blink::WebFormElement& form) { |
| 1062 LOG(INFO) << "Will send submit event"; |
| 1000 // Forms submitted via XHR are not seen by WillSubmitForm if the default | 1063 // Forms submitted via XHR are not seen by WillSubmitForm if the default |
| 1001 // onsubmit handler is overridden. Such submission first gets detected in | 1064 // onsubmit handler is overridden. Such submission first gets detected in |
| 1002 // DidStartProvisionalLoad, which no longer knows about the particular form, | 1065 // DidStartProvisionalLoad, which no longer knows about the particular form, |
| 1003 // and uses the candidate stored in |provisionally_saved_form_|. | 1066 // and uses the candidate stored in |provisionally_saved_form_|. |
| 1004 // | 1067 // |
| 1005 // User-typed password will get stored to |provisionally_saved_form_| in | 1068 // User-typed password will get stored to |provisionally_saved_form_| in |
| 1006 // TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to | 1069 // TextDidChangeInTextField. Autofilled or JavaScript-copied passwords need to |
| 1007 // be saved here. | 1070 // be saved here. |
| 1008 // | 1071 // |
| 1009 // Only non-empty passwords are saved here. Empty passwords were likely | 1072 // Only non-empty passwords are saved here. Empty passwords were likely |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 scoped_ptr<PasswordForm> password_form( | 1411 scoped_ptr<PasswordForm> password_form( |
| 1349 CreatePasswordForm(form, &user_modified_elements_)); | 1412 CreatePasswordForm(form, &user_modified_elements_)); |
| 1350 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && | 1413 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && |
| 1351 password_form->password_value.empty() && | 1414 password_form->password_value.empty() && |
| 1352 password_form->new_password_value.empty())) { | 1415 password_form->new_password_value.empty())) { |
| 1353 return; | 1416 return; |
| 1354 } | 1417 } |
| 1355 provisionally_saved_form_ = password_form.Pass(); | 1418 provisionally_saved_form_ = password_form.Pass(); |
| 1356 } | 1419 } |
| 1357 | 1420 |
| 1421 bool PasswordAutofillAgent::ProvisionallySavedPasswordIsValid() { |
| 1422 return provisionally_saved_form_ && |
| 1423 !provisionally_saved_form_->username_value.empty() && |
| 1424 (!provisionally_saved_form_->password_value.empty() || |
| 1425 provisionally_saved_form_->new_password_value.empty()); |
| 1426 } |
| 1427 |
| 1428 void PasswordAutofillAgent::XHRSucceeded() { |
| 1429 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 1430 blink::WebVector<blink::WebFormElement> forms; |
| 1431 frame->document().forms(forms); |
| 1432 |
| 1433 if (!provisionally_saved_form_ || |
| 1434 provisionally_saved_form_->username_value.empty() || |
| 1435 (provisionally_saved_form_->password_value.empty() && |
| 1436 provisionally_saved_form_->new_password_value.empty())) |
| 1437 return; |
| 1438 |
| 1439 bool matched = false; |
| 1440 std::vector<PasswordForm> password_forms; |
| 1441 for (size_t i = 0; i < forms.size(); ++i) { |
| 1442 const blink::WebFormElement& form = forms[i]; |
| 1443 bool is_form_visible = IsWebNodeVisible(form); |
| 1444 |
| 1445 // If requested, ignore non-rendered forms, e.g., those styled with |
| 1446 // display:none. |
| 1447 if (!is_form_visible) { |
| 1448 LOG(INFO) << "Form: " << form.action().utf8() << "is invisible"; |
| 1449 continue; |
| 1450 } |
| 1451 |
| 1452 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form, nullptr)); |
| 1453 if (password_form.get()) { |
| 1454 password_forms.push_back(*password_form); |
| 1455 if (provisionally_saved_form_->username_element == password_form->username
_element && |
| 1456 (provisionally_saved_form_->password_element == password_form->passwor
d_element || |
| 1457 provisionally_saved_form_->new_password_element == password_form->new
_password_element)) { |
| 1458 matched = true; |
| 1459 } |
| 1460 } |
| 1461 } |
| 1462 LOG(INFO) << password_forms.size(); |
| 1463 if (!matched) |
| 1464 LOG(INFO) << "Should Save"; |
| 1465 } |
| 1466 |
| 1358 // LegacyPasswordAutofillAgent ------------------------------------------------- | 1467 // LegacyPasswordAutofillAgent ------------------------------------------------- |
| 1359 | 1468 |
| 1360 PasswordAutofillAgent::LegacyPasswordAutofillAgent::LegacyPasswordAutofillAgent( | 1469 PasswordAutofillAgent::LegacyPasswordAutofillAgent::LegacyPasswordAutofillAgent( |
| 1361 content::RenderView* render_view, | 1470 content::RenderView* render_view, |
| 1362 PasswordAutofillAgent* agent) | 1471 PasswordAutofillAgent* agent) |
| 1363 : content::RenderViewObserver(render_view), agent_(agent) { | 1472 : content::RenderViewObserver(render_view), agent_(agent) { |
| 1364 } | 1473 } |
| 1365 | 1474 |
| 1366 PasswordAutofillAgent::LegacyPasswordAutofillAgent:: | 1475 PasswordAutofillAgent::LegacyPasswordAutofillAgent:: |
| 1367 ~LegacyPasswordAutofillAgent() { | 1476 ~LegacyPasswordAutofillAgent() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1378 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { | 1487 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { |
| 1379 agent_->DidStopLoading(); | 1488 agent_->DidStopLoading(); |
| 1380 } | 1489 } |
| 1381 | 1490 |
| 1382 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: | 1491 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: |
| 1383 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { | 1492 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { |
| 1384 agent_->LegacyDidStartProvisionalLoad(navigated_frame); | 1493 agent_->LegacyDidStartProvisionalLoad(navigated_frame); |
| 1385 } | 1494 } |
| 1386 | 1495 |
| 1387 } // namespace autofill | 1496 } // namespace autofill |
| OLD | NEW |