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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "content/public/renderer/render_view.h" | 37 #include "content/public/renderer/render_view.h" |
38 #include "services/service_manager/public/cpp/binder_registry.h" | 38 #include "services/service_manager/public/cpp/binder_registry.h" |
39 #include "services/service_manager/public/cpp/interface_provider.h" | 39 #include "services/service_manager/public/cpp/interface_provider.h" |
40 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 40 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
41 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 41 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
42 #include "third_party/WebKit/public/platform/WebVector.h" | 42 #include "third_party/WebKit/public/platform/WebVector.h" |
43 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 43 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
44 #include "third_party/WebKit/public/web/WebDocument.h" | 44 #include "third_party/WebKit/public/web/WebDocument.h" |
45 #include "third_party/WebKit/public/web/WebElement.h" | 45 #include "third_party/WebKit/public/web/WebElement.h" |
46 #include "third_party/WebKit/public/web/WebFormElement.h" | 46 #include "third_party/WebKit/public/web/WebFormElement.h" |
| 47 #include "third_party/WebKit/public/web/WebFormElementObserverCallback.h" |
47 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 48 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
48 #include "third_party/WebKit/public/web/WebNode.h" | 49 #include "third_party/WebKit/public/web/WebNode.h" |
49 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 50 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
50 #include "third_party/WebKit/public/web/WebView.h" | 51 #include "third_party/WebKit/public/web/WebView.h" |
51 #include "ui/base/page_transition_types.h" | 52 #include "ui/base/page_transition_types.h" |
52 #include "ui/events/keycodes/keyboard_codes.h" | 53 #include "ui/events/keycodes/keyboard_codes.h" |
53 #include "url/gurl.h" | 54 #include "url/gurl.h" |
54 | 55 |
55 namespace autofill { | 56 namespace autofill { |
56 namespace { | 57 namespace { |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 element.To<blink::WebFormControlElement>(); | 612 element.To<blink::WebFormControlElement>(); |
612 if (control.FormControlType() == kPassword) | 613 if (control.FormControlType() == kPassword) |
613 return true; | 614 return true; |
614 } | 615 } |
615 } | 616 } |
616 return false; | 617 return false; |
617 } | 618 } |
618 | 619 |
619 } // namespace | 620 } // namespace |
620 | 621 |
| 622 class PasswordAutofillAgent::FormElementObserver |
| 623 : public blink::WebFormElementObserverCallback { |
| 624 public: |
| 625 explicit FormElementObserver(PasswordAutofillAgent* agent) : agent_(agent) {} |
| 626 ~FormElementObserver() override { Detach(); } |
| 627 |
| 628 void Detach() { |
| 629 if (agent_) { |
| 630 DCHECK_EQ(agent_->form_element_observer_, this); |
| 631 agent_->form_element_observer_ = nullptr; |
| 632 } |
| 633 agent_ = nullptr; |
| 634 } |
| 635 |
| 636 bool ShouldStopObserving() override { |
| 637 if (!agent_) |
| 638 return true; |
| 639 agent_->OnSameDocumentNavigationCompleted(); |
| 640 // The above call will invoke Detach() if the form no longer needs to be |
| 641 // observed. |
| 642 return agent_ == nullptr; |
| 643 } |
| 644 |
| 645 private: |
| 646 PasswordAutofillAgent* agent_; |
| 647 |
| 648 DISALLOW_COPY_AND_ASSIGN(FormElementObserver); |
| 649 }; |
| 650 |
621 //////////////////////////////////////////////////////////////////////////////// | 651 //////////////////////////////////////////////////////////////////////////////// |
622 // PasswordAutofillAgent, public: | 652 // PasswordAutofillAgent, public: |
623 | 653 |
624 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) | 654 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) |
625 : content::RenderFrameObserver(render_frame), | 655 : content::RenderFrameObserver(render_frame), |
626 logging_state_active_(false), | 656 logging_state_active_(false), |
627 was_username_autofilled_(false), | 657 was_username_autofilled_(false), |
628 was_password_autofilled_(false), | 658 was_password_autofilled_(false), |
629 sent_request_to_store_(false), | 659 sent_request_to_store_(false), |
630 checked_safe_browsing_reputation_(false), | 660 checked_safe_browsing_reputation_(false), |
631 binding_(this) { | 661 binding_(this), |
| 662 form_element_observer_(nullptr) { |
632 // PasswordAutofillAgent is guaranteed to outlive |render_frame|. | 663 // PasswordAutofillAgent is guaranteed to outlive |render_frame|. |
633 render_frame->GetInterfaceRegistry()->AddInterface( | 664 render_frame->GetInterfaceRegistry()->AddInterface( |
634 base::Bind(&PasswordAutofillAgent::BindRequest, base::Unretained(this))); | 665 base::Bind(&PasswordAutofillAgent::BindRequest, base::Unretained(this))); |
635 } | 666 } |
636 | 667 |
637 PasswordAutofillAgent::~PasswordAutofillAgent() { | 668 PasswordAutofillAgent::~PasswordAutofillAgent() { |
| 669 if (form_element_observer_) |
| 670 form_element_observer_->Detach(); |
638 } | 671 } |
639 | 672 |
640 void PasswordAutofillAgent::BindRequest( | 673 void PasswordAutofillAgent::BindRequest( |
641 const service_manager::BindSourceInfo& source_info, | 674 const service_manager::BindSourceInfo& source_info, |
642 mojom::PasswordAutofillAgentRequest request) { | 675 mojom::PasswordAutofillAgentRequest request) { |
643 binding_.Bind(std::move(request)); | 676 binding_.Bind(std::move(request)); |
644 } | 677 } |
645 | 678 |
646 void PasswordAutofillAgent::SetAutofillAgent(AutofillAgent* autofill_agent) { | 679 void PasswordAutofillAgent::SetAutofillAgent(AutofillAgent* autofill_agent) { |
647 autofill_agent_ = autofill_agent; | 680 autofill_agent_ = autofill_agent; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 1077 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
1045 const auto& password_form = provisionally_saved_form_.password_form(); | 1078 const auto& password_form = provisionally_saved_form_.password_form(); |
1046 if (form_util::IsFormVisible(frame, provisionally_saved_form_.form_element(), | 1079 if (form_util::IsFormVisible(frame, provisionally_saved_form_.form_element(), |
1047 password_form.action, password_form.origin, | 1080 password_form.action, password_form.origin, |
1048 password_form.form_data) || | 1081 password_form.form_data) || |
1049 (provisionally_saved_form_.form_element().IsNull() && | 1082 (provisionally_saved_form_.form_element().IsNull() && |
1050 IsUnownedPasswordFormVisible( | 1083 IsUnownedPasswordFormVisible( |
1051 frame, provisionally_saved_form_.input_element(), | 1084 frame, provisionally_saved_form_.input_element(), |
1052 password_form.action, password_form.origin, password_form.form_data, | 1085 password_form.action, password_form.origin, password_form.form_data, |
1053 form_predictions_))) { | 1086 form_predictions_))) { |
| 1087 if (!form_element_observer_) { |
| 1088 std::unique_ptr<FormElementObserver> observer( |
| 1089 new FormElementObserver(this)); |
| 1090 form_element_observer_ = observer.get(); |
| 1091 if (provisionally_saved_form_.form_element().IsNull()) { |
| 1092 provisionally_saved_form_.input_element() |
| 1093 .GetDocument() |
| 1094 .ObserveFormElement(provisionally_saved_form_.input_element(), |
| 1095 std::move(observer)); |
| 1096 } else { |
| 1097 provisionally_saved_form_.form_element() |
| 1098 .GetDocument() |
| 1099 .ObserveFormElement(provisionally_saved_form_.form_element(), |
| 1100 std::move(observer)); |
| 1101 } |
| 1102 } |
1054 return; | 1103 return; |
1055 } | 1104 } |
1056 | 1105 |
1057 GetPasswordManagerDriver()->InPageNavigation(password_form); | 1106 GetPasswordManagerDriver()->InPageNavigation(password_form); |
| 1107 if (form_element_observer_) |
| 1108 form_element_observer_->Detach(); |
1058 provisionally_saved_form_.Reset(); | 1109 provisionally_saved_form_.Reset(); |
1059 } | 1110 } |
1060 | 1111 |
1061 void PasswordAutofillAgent::UserGestureObserved() { | 1112 void PasswordAutofillAgent::UserGestureObserved() { |
1062 gatekeeper_.OnUserGesture(); | 1113 gatekeeper_.OnUserGesture(); |
1063 } | 1114 } |
1064 | 1115 |
1065 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { | 1116 void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { |
1066 std::unique_ptr<RendererSavePasswordProgressLogger> logger; | 1117 std::unique_ptr<RendererSavePasswordProgressLogger> logger; |
1067 if (logging_state_active_) { | 1118 if (logging_state_active_) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 submitted_form->password_value = saved_form.password_value; | 1331 submitted_form->password_value = saved_form.password_value; |
1281 submitted_form->new_password_value = saved_form.new_password_value; | 1332 submitted_form->new_password_value = saved_form.new_password_value; |
1282 submitted_form->username_value = saved_form.username_value; | 1333 submitted_form->username_value = saved_form.username_value; |
1283 } | 1334 } |
1284 | 1335 |
1285 // Some observers depend on sending this information now instead of when | 1336 // Some observers depend on sending this information now instead of when |
1286 // the frame starts loading. If there are redirects that cause a new | 1337 // the frame starts loading. If there are redirects that cause a new |
1287 // RenderView to be instantiated (such as redirects to the WebStore) | 1338 // RenderView to be instantiated (such as redirects to the WebStore) |
1288 // we will never get to finish the load. | 1339 // we will never get to finish the load. |
1289 GetPasswordManagerDriver()->PasswordFormSubmitted(*submitted_form); | 1340 GetPasswordManagerDriver()->PasswordFormSubmitted(*submitted_form); |
| 1341 if (form_element_observer_) |
| 1342 form_element_observer_->Detach(); |
1290 provisionally_saved_form_.Reset(); | 1343 provisionally_saved_form_.Reset(); |
1291 } else if (logger) { | 1344 } else if (logger) { |
1292 logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD); | 1345 logger->LogMessage(Logger::STRING_FORM_IS_NOT_PASSWORD); |
1293 } | 1346 } |
1294 } | 1347 } |
1295 | 1348 |
1296 void PasswordAutofillAgent::OnDestruct() { | 1349 void PasswordAutofillAgent::OnDestruct() { |
1297 binding_.Close(); | 1350 binding_.Close(); |
1298 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 1351 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
1299 } | 1352 } |
(...skipping 27 matching lines...) Expand all Loading... |
1327 !blink::WebUserGestureIndicator::IsProcessingUserGesture()) { | 1380 !blink::WebUserGestureIndicator::IsProcessingUserGesture()) { |
1328 // If onsubmit has been called, try and save that form. | 1381 // If onsubmit has been called, try and save that form. |
1329 if (provisionally_saved_form_.IsSet()) { | 1382 if (provisionally_saved_form_.IsSet()) { |
1330 if (logger) { | 1383 if (logger) { |
1331 logger->LogPasswordForm( | 1384 logger->LogPasswordForm( |
1332 Logger::STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME, | 1385 Logger::STRING_PROVISIONALLY_SAVED_FORM_FOR_FRAME, |
1333 provisionally_saved_form_.password_form()); | 1386 provisionally_saved_form_.password_form()); |
1334 } | 1387 } |
1335 GetPasswordManagerDriver()->PasswordFormSubmitted( | 1388 GetPasswordManagerDriver()->PasswordFormSubmitted( |
1336 provisionally_saved_form_.password_form()); | 1389 provisionally_saved_form_.password_form()); |
| 1390 if (form_element_observer_) |
| 1391 form_element_observer_->Detach(); |
1337 provisionally_saved_form_.Reset(); | 1392 provisionally_saved_form_.Reset(); |
1338 } else { | 1393 } else { |
1339 std::vector<std::unique_ptr<PasswordForm>> possible_submitted_forms; | 1394 std::vector<std::unique_ptr<PasswordForm>> possible_submitted_forms; |
1340 // Loop through the forms on the page looking for one that has been | 1395 // Loop through the forms on the page looking for one that has been |
1341 // filled out. If one exists, try and save the credentials. | 1396 // filled out. If one exists, try and save the credentials. |
1342 blink::WebVector<blink::WebFormElement> forms; | 1397 blink::WebVector<blink::WebFormElement> forms; |
1343 render_frame()->GetWebFrame()->GetDocument().Forms(forms); | 1398 render_frame()->GetWebFrame()->GetDocument().Forms(forms); |
1344 | 1399 |
1345 bool password_forms_found = false; | 1400 bool password_forms_found = false; |
1346 for (size_t i = 0; i < forms.size(); ++i) { | 1401 for (size_t i = 0; i < forms.size(); ++i) { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 render_frame()->GetRenderView()->ElementBoundsInWindow(user_input)); | 1663 render_frame()->GetRenderView()->ElementBoundsInWindow(user_input)); |
1609 username_query_prefix_ = username_string; | 1664 username_query_prefix_ = username_string; |
1610 return CanShowSuggestion(password_info.fill_data, username_string, show_all); | 1665 return CanShowSuggestion(password_info.fill_data, username_string, show_all); |
1611 } | 1666 } |
1612 | 1667 |
1613 void PasswordAutofillAgent::FrameClosing() { | 1668 void PasswordAutofillAgent::FrameClosing() { |
1614 for (auto const& iter : web_input_to_password_info_) { | 1669 for (auto const& iter : web_input_to_password_info_) { |
1615 password_to_username_.erase(iter.second.password_field); | 1670 password_to_username_.erase(iter.second.password_field); |
1616 } | 1671 } |
1617 web_input_to_password_info_.clear(); | 1672 web_input_to_password_info_.clear(); |
| 1673 if (form_element_observer_) |
| 1674 form_element_observer_->Detach(); |
1618 provisionally_saved_form_.Reset(); | 1675 provisionally_saved_form_.Reset(); |
1619 field_value_and_properties_map_.clear(); | 1676 field_value_and_properties_map_.clear(); |
1620 sent_request_to_store_ = false; | 1677 sent_request_to_store_ = false; |
1621 checked_safe_browsing_reputation_ = false; | 1678 checked_safe_browsing_reputation_ = false; |
1622 } | 1679 } |
1623 | 1680 |
1624 void PasswordAutofillAgent::ClearPreview( | 1681 void PasswordAutofillAgent::ClearPreview( |
1625 blink::WebInputElement* username, | 1682 blink::WebInputElement* username, |
1626 blink::WebInputElement* password) { | 1683 blink::WebInputElement* password) { |
1627 if (!username->IsNull() && !username->SuggestedValue().IsEmpty()) { | 1684 if (!username->IsNull() && !username->SuggestedValue().IsEmpty()) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 PasswordAutofillAgent::GetPasswordManagerDriver() { | 1716 PasswordAutofillAgent::GetPasswordManagerDriver() { |
1660 if (!password_manager_driver_) { | 1717 if (!password_manager_driver_) { |
1661 render_frame()->GetRemoteInterfaces()->GetInterface( | 1718 render_frame()->GetRemoteInterfaces()->GetInterface( |
1662 mojo::MakeRequest(&password_manager_driver_)); | 1719 mojo::MakeRequest(&password_manager_driver_)); |
1663 } | 1720 } |
1664 | 1721 |
1665 return password_manager_driver_; | 1722 return password_manager_driver_; |
1666 } | 1723 } |
1667 | 1724 |
1668 } // namespace autofill | 1725 } // namespace autofill |
OLD | NEW |