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/autofill_agent.h" | 5 #include "components/autofill/content/renderer/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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "components/autofill/content/renderer/form_autofill_util.h" | 14 #include "components/autofill/content/renderer/form_autofill_util.h" |
15 #include "components/autofill/content/renderer/page_click_tracker.h" | 15 #include "components/autofill/content/renderer/page_click_tracker.h" |
16 #include "components/autofill/content/renderer/password_autofill_agent.h" | 16 #include "components/autofill/content/renderer/password_autofill_agent.h" |
17 #include "components/autofill/core/common/autocheckout_status.h" | |
18 #include "components/autofill/core/common/autofill_constants.h" | 17 #include "components/autofill/core/common/autofill_constants.h" |
19 #include "components/autofill/core/common/autofill_messages.h" | 18 #include "components/autofill/core/common/autofill_messages.h" |
20 #include "components/autofill/core/common/autofill_switches.h" | 19 #include "components/autofill/core/common/autofill_switches.h" |
21 #include "components/autofill/core/common/form_data.h" | 20 #include "components/autofill/core/common/form_data.h" |
22 #include "components/autofill/core/common/form_data_predictions.h" | 21 #include "components/autofill/core/common/form_data_predictions.h" |
23 #include "components/autofill/core/common/form_field_data.h" | 22 #include "components/autofill/core/common/form_field_data.h" |
24 #include "components/autofill/core/common/web_element_descriptor.h" | 23 #include "components/autofill/core/common/web_element_descriptor.h" |
25 #include "content/public/common/password_form.h" | 24 #include "content/public/common/password_form.h" |
26 #include "content/public/common/ssl_status.h" | 25 #include "content/public/common/ssl_status.h" |
27 #include "content/public/common/url_constants.h" | 26 #include "content/public/common/url_constants.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 const WebKit::WebURLError& error) { | 240 const WebKit::WebURLError& error) { |
242 if (!frame->parent() && autocheckout_click_in_progress_) { | 241 if (!frame->parent() && autocheckout_click_in_progress_) { |
243 autocheckout_click_in_progress_ = false; | 242 autocheckout_click_in_progress_ = false; |
244 ClickFailed(); | 243 ClickFailed(); |
245 } | 244 } |
246 } | 245 } |
247 | 246 |
248 void AutofillAgent::DidCommitProvisionalLoad(WebFrame* frame, | 247 void AutofillAgent::DidCommitProvisionalLoad(WebFrame* frame, |
249 bool is_new_navigation) { | 248 bool is_new_navigation) { |
250 in_flight_request_form_.reset(); | 249 in_flight_request_form_.reset(); |
251 if (!frame->parent()) | 250 if (!frame->parent() && autocheckout_click_in_progress_) { |
252 autocheckout_click_in_progress_ = false; | 251 autocheckout_click_in_progress_ = false; |
| 252 CompleteAutocheckoutPage(SUCCESS); |
| 253 } |
253 } | 254 } |
254 | 255 |
255 void AutofillAgent::FrameDetached(WebFrame* frame) { | 256 void AutofillAgent::FrameDetached(WebFrame* frame) { |
256 form_cache_.ResetFrame(*frame); | 257 form_cache_.ResetFrame(*frame); |
257 if (!frame->parent()) { | 258 if (!frame->parent()) { |
258 // |frame| is about to be destroyed so we need to clear |top_most_frame_|. | 259 // |frame| is about to be destroyed so we need to clear |top_most_frame_|. |
259 topmost_frame_ = NULL; | 260 topmost_frame_ = NULL; |
260 click_timer_.Stop(); | 261 click_timer_.Stop(); |
261 } | 262 } |
262 } | 263 } |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 const std::vector<FormData>& forms, | 679 const std::vector<FormData>& forms, |
679 const std::vector<WebElementDescriptor>& click_elements_before_form_fill, | 680 const std::vector<WebElementDescriptor>& click_elements_before_form_fill, |
680 const std::vector<WebElementDescriptor>& click_elements_after_form_fill, | 681 const std::vector<WebElementDescriptor>& click_elements_after_form_fill, |
681 const WebElementDescriptor& click_element_descriptor) { | 682 const WebElementDescriptor& click_element_descriptor) { |
682 DCHECK_EQ(forms.size(), form_elements_.size()); | 683 DCHECK_EQ(forms.size(), form_elements_.size()); |
683 | 684 |
684 // Click elements in click_elements_before_form_fill. | 685 // Click elements in click_elements_before_form_fill. |
685 for (size_t i = 0; i < click_elements_before_form_fill.size(); ++i) { | 686 for (size_t i = 0; i < click_elements_before_form_fill.size(); ++i) { |
686 if (!ClickElement(topmost_frame_->document(), | 687 if (!ClickElement(topmost_frame_->document(), |
687 click_elements_before_form_fill[i])) { | 688 click_elements_before_form_fill[i])) { |
688 Send(new AutofillHostMsg_ClickFailed(routing_id(), | 689 CompleteAutocheckoutPage(MISSING_CLICK_ELEMENT_BEFORE_FORM_FILLING); |
689 MISSING_CLICK_ELEMENT_BEFORE_FORM_FILLING)); | |
690 return; | 690 return; |
691 } | 691 } |
692 } | 692 } |
693 | 693 |
694 // Fill the form. | 694 // Fill the form. |
695 for (size_t i = 0; i < forms.size(); ++i) | 695 for (size_t i = 0; i < forms.size(); ++i) |
696 FillFormIncludingNonFocusableElements(forms[i], form_elements_[i]); | 696 FillFormIncludingNonFocusableElements(forms[i], form_elements_[i]); |
697 | 697 |
698 // Click elements in click_elements_after_form_fill. | 698 // Click elements in click_elements_after_form_fill. |
699 for (size_t i = 0; i < click_elements_after_form_fill.size(); ++i) { | 699 for (size_t i = 0; i < click_elements_after_form_fill.size(); ++i) { |
700 if (!ClickElement(topmost_frame_->document(), | 700 if (!ClickElement(topmost_frame_->document(), |
701 click_elements_after_form_fill[i])) { | 701 click_elements_after_form_fill[i])) { |
702 Send(new AutofillHostMsg_ClickFailed(routing_id(), | 702 CompleteAutocheckoutPage(MISSING_CLICK_ELEMENT_AFTER_FORM_FILLING); |
703 MISSING_CLICK_ELEMENT_AFTER_FORM_FILLING)); | |
704 return; | 703 return; |
705 } | 704 } |
706 } | 705 } |
707 | 706 |
708 // Exit early if there is nothing to click. | 707 // Exit early if there is nothing to click. |
709 if (click_element_descriptor.retrieval_method == WebElementDescriptor::NONE) | 708 if (click_element_descriptor.retrieval_method == WebElementDescriptor::NONE) { |
| 709 CompleteAutocheckoutPage(SUCCESS); |
710 return; | 710 return; |
| 711 } |
711 | 712 |
712 // It's possible that clicking the element to proceed in an Autocheckout | 713 // It's possible that clicking the element to proceed in an Autocheckout |
713 // flow will not actually proceed to the next step in the flow, e.g. there | 714 // flow will not actually proceed to the next step in the flow, e.g. there |
714 // is a new required field that Autocheckout does not know how to fill. In | 715 // is a new required field that Autocheckout does not know how to fill. In |
715 // order to capture this case and present the user with an error a timer is | 716 // order to capture this case and present the user with an error a timer is |
716 // set that informs the browser of the error. |click_timer_| has to be started | 717 // set that informs the browser of the error. |click_timer_| has to be started |
717 // before clicking so it can start before DidStartProvisionalLoad started. | 718 // before clicking so it can start before DidStartProvisionalLoad started. |
718 click_timer_.Start(FROM_HERE, | 719 click_timer_.Start(FROM_HERE, |
719 base::TimeDelta::FromSeconds(kAutocheckoutClickTimeout), | 720 base::TimeDelta::FromSeconds(kAutocheckoutClickTimeout), |
720 this, | 721 this, |
721 &AutofillAgent::ClickFailed); | 722 &AutofillAgent::ClickFailed); |
722 if (!ClickElement(topmost_frame_->document(), | 723 if (!ClickElement(topmost_frame_->document(), |
723 click_element_descriptor)) { | 724 click_element_descriptor)) { |
724 click_timer_.Stop(); | 725 CompleteAutocheckoutPage(MISSING_ADVANCE); |
725 Send(new AutofillHostMsg_ClickFailed(routing_id(), | |
726 MISSING_ADVANCE)); | |
727 } | 726 } |
728 } | 727 } |
729 | 728 |
730 void AutofillAgent::OnAutocheckoutSupported() { | 729 void AutofillAgent::OnAutocheckoutSupported() { |
731 is_autocheckout_supported_ = true; | 730 is_autocheckout_supported_ = true; |
732 if (has_new_forms_for_browser_) | 731 if (has_new_forms_for_browser_) |
733 MaybeSendDynamicFormsSeen(); | 732 MaybeSendDynamicFormsSeen(); |
734 MaybeShowAutocheckoutBubble(); | 733 MaybeShowAutocheckoutBubble(); |
735 } | 734 } |
736 | 735 |
| 736 void AutofillAgent::CompleteAutocheckoutPage( |
| 737 autofill::AutocheckoutStatus status) { |
| 738 click_timer_.Stop(); |
| 739 Send(new AutofillHostMsg_AutocheckoutPageCompleted(routing_id(), status)); |
| 740 } |
| 741 |
737 void AutofillAgent::ClickFailed() { | 742 void AutofillAgent::ClickFailed() { |
738 Send(new AutofillHostMsg_ClickFailed(routing_id(), | 743 CompleteAutocheckoutPage(CANNOT_PROCEED); |
739 CANNOT_PROCEED)); | |
740 } | 744 } |
741 | 745 |
742 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 746 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
743 bool autofill_on_empty_values, | 747 bool autofill_on_empty_values, |
744 bool requires_caret_at_end, | 748 bool requires_caret_at_end, |
745 bool display_warning_if_disabled) { | 749 bool display_warning_if_disabled) { |
746 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || | 750 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || |
747 element.isPasswordField() || !element.suggestedValue().isEmpty()) | 751 element.isPasswordField() || !element.suggestedValue().isEmpty()) |
748 return; | 752 return; |
749 | 753 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 if (!forms.empty()) { | 908 if (!forms.empty()) { |
905 if (click_timer_.IsRunning()) | 909 if (click_timer_.IsRunning()) |
906 click_timer_.Stop(); | 910 click_timer_.Stop(); |
907 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 911 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
908 forms_seen_timestamp_, | 912 forms_seen_timestamp_, |
909 state)); | 913 state)); |
910 } | 914 } |
911 } | 915 } |
912 | 916 |
913 } // namespace autofill | 917 } // namespace autofill |
OLD | NEW |