| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/autofill_agent.h" | 5 #include "components/autofill/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/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 if (!forms.empty() || !frame->parent()) { | 216 if (!forms.empty() || !frame->parent()) { |
| 217 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, | 217 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, |
| 218 forms_seen_timestamp_, | 218 forms_seen_timestamp_, |
| 219 has_more_forms)); | 219 has_more_forms)); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { | 223 void AutofillAgent::DidStartProvisionalLoad(WebFrame* frame) { |
| 224 if (!frame->parent()) { | 224 if (!frame->parent()) { |
| 225 topmost_frame_ = NULL; | 225 topmost_frame_ = NULL; |
| 226 WebKit::WebURL provisional_url = | 226 if (click_timer_.IsRunning()) { |
| 227 frame->provisionalDataSource()->request().url(); | |
| 228 WebKit::WebURL current_url = frame->dataSource()->request().url(); | |
| 229 // If the URL of the topmost frame is changing and the current page is part | |
| 230 // of an Autocheckout flow, the click was successful as long as the | |
| 231 // provisional load is committed. | |
| 232 if (provisional_url != current_url && click_timer_.IsRunning()) { | |
| 233 click_timer_.Stop(); | 227 click_timer_.Stop(); |
| 234 autocheckout_click_in_progress_ = true; | 228 autocheckout_click_in_progress_ = true; |
| 235 } | 229 } |
| 236 } | 230 } |
| 237 } | 231 } |
| 238 | 232 |
| 239 void AutofillAgent::DidFailProvisionalLoad(WebFrame* frame, | 233 void AutofillAgent::DidFailProvisionalLoad(WebFrame* frame, |
| 240 const WebKit::WebURLError& error) { | 234 const WebKit::WebURLError& error) { |
| 241 if (autocheckout_click_in_progress_) { | 235 if (!frame->parent() && autocheckout_click_in_progress_) { |
| 242 autocheckout_click_in_progress_ = false; | 236 autocheckout_click_in_progress_ = false; |
| 243 ClickFailed(); | 237 ClickFailed(); |
| 244 } | 238 } |
| 245 } | 239 } |
| 246 | 240 |
| 247 void AutofillAgent::DidCommitProvisionalLoad(WebFrame* frame, | 241 void AutofillAgent::DidCommitProvisionalLoad(WebFrame* frame, |
| 248 bool is_new_navigation) { | 242 bool is_new_navigation) { |
| 249 autocheckout_click_in_progress_ = false; | |
| 250 in_flight_request_form_.reset(); | 243 in_flight_request_form_.reset(); |
| 244 if (!frame->parent()) |
| 245 autocheckout_click_in_progress_ = false; |
| 251 } | 246 } |
| 252 | 247 |
| 253 void AutofillAgent::FrameDetached(WebFrame* frame) { | 248 void AutofillAgent::FrameDetached(WebFrame* frame) { |
| 254 form_cache_.ResetFrame(*frame); | 249 form_cache_.ResetFrame(*frame); |
| 255 if (!frame->parent()) { | 250 if (!frame->parent()) { |
| 256 // |frame| is about to be destroyed so we need to clear |top_most_frame_|. | 251 // |frame| is about to be destroyed so we need to clear |top_most_frame_|. |
| 257 topmost_frame_ = NULL; | 252 topmost_frame_ = NULL; |
| 258 click_timer_.Stop(); | 253 click_timer_.Stop(); |
| 259 } | 254 } |
| 260 } | 255 } |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 | 743 |
| 749 void AutofillAgent::OnFillFormsAndClick( | 744 void AutofillAgent::OnFillFormsAndClick( |
| 750 const std::vector<FormData>& forms, | 745 const std::vector<FormData>& forms, |
| 751 const WebElementDescriptor& click_element_descriptor) { | 746 const WebElementDescriptor& click_element_descriptor) { |
| 752 DCHECK_EQ(forms.size(), form_elements_.size()); | 747 DCHECK_EQ(forms.size(), form_elements_.size()); |
| 753 | 748 |
| 754 // Fill the form. | 749 // Fill the form. |
| 755 for (size_t i = 0; i < forms.size(); ++i) | 750 for (size_t i = 0; i < forms.size(); ++i) |
| 756 FillFormIncludingNonFocusableElements(forms[i], form_elements_[i]); | 751 FillFormIncludingNonFocusableElements(forms[i], form_elements_[i]); |
| 757 | 752 |
| 753 // Exit early if there is nothing to click. |
| 754 if (click_element_descriptor.retrieval_method == WebElementDescriptor::NONE) |
| 755 return; |
| 756 |
| 758 // It's possible that clicking the element to proceed in an Autocheckout | 757 // It's possible that clicking the element to proceed in an Autocheckout |
| 759 // flow will not actually proceed to the next step in the flow, e.g. there | 758 // flow will not actually proceed to the next step in the flow, e.g. there |
| 760 // is a new required field that Autocheckout does not know how to fill. In | 759 // is a new required field that Autocheckout does not know how to fill. In |
| 761 // order to capture this case and present the user with an error a timer is | 760 // order to capture this case and present the user with an error a timer is |
| 762 // set that informs the browser of the error. |click_timer_| has to be started | 761 // set that informs the browser of the error. |click_timer_| has to be started |
| 763 // before clicking so it can start before DidStartProvisionalLoad started. | 762 // before clicking so it can start before DidStartProvisionalLoad started. |
| 764 click_timer_.Start(FROM_HERE, | 763 click_timer_.Start(FROM_HERE, |
| 765 base::TimeDelta::FromSeconds(kAutocheckoutClickTimeout), | 764 base::TimeDelta::FromSeconds(kAutocheckoutClickTimeout), |
| 766 this, | 765 this, |
| 767 &AutofillAgent::ClickFailed); | 766 &AutofillAgent::ClickFailed); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 web_view->hidePopups(); | 925 web_view->hidePopups(); |
| 927 | 926 |
| 928 HideHostAutofillUi(); | 927 HideHostAutofillUi(); |
| 929 } | 928 } |
| 930 | 929 |
| 931 void AutofillAgent::HideHostAutofillUi() { | 930 void AutofillAgent::HideHostAutofillUi() { |
| 932 Send(new AutofillHostMsg_HideAutofillUi(routing_id())); | 931 Send(new AutofillHostMsg_HideAutofillUi(routing_id())); |
| 933 } | 932 } |
| 934 | 933 |
| 935 } // namespace autofill | 934 } // namespace autofill |
| OLD | NEW |