OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/autofill/autocheckout_manager.h" | 5 #include "chrome/browser/autofill/autocheckout_manager.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autofill_country.h" | 10 #include "chrome/browser/autofill/autofill_country.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 formdata.fields.push_back(BuildField("shipping street-address")); | 60 formdata.fields.push_back(BuildField("shipping street-address")); |
61 formdata.fields.push_back(BuildField("shipping locality")); | 61 formdata.fields.push_back(BuildField("shipping locality")); |
62 formdata.fields.push_back(BuildField("shipping region")); | 62 formdata.fields.push_back(BuildField("shipping region")); |
63 formdata.fields.push_back(BuildField("shipping country")); | 63 formdata.fields.push_back(BuildField("shipping country")); |
64 formdata.fields.push_back(BuildField("shipping postal-code")); | 64 formdata.fields.push_back(BuildField("shipping postal-code")); |
65 return formdata; | 65 return formdata; |
66 } | 66 } |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
| 70 namespace autofill { |
| 71 |
70 AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager) | 72 AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager) |
71 : autofill_manager_(autofill_manager), | 73 : autofill_manager_(autofill_manager), |
72 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 74 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
73 } | 75 } |
74 | 76 |
75 AutocheckoutManager::~AutocheckoutManager() { | 77 AutocheckoutManager::~AutocheckoutManager() { |
76 } | 78 } |
77 | 79 |
78 void AutocheckoutManager::SetProceedElementDescriptor( | 80 void AutocheckoutManager::SetProceedElementDescriptor( |
79 const autofill::WebElementDescriptor& proceed) { | 81 const WebElementDescriptor& proceed) { |
80 // make a local copy. | 82 // make a local copy. |
81 proceed_descriptor_.reset(new autofill::WebElementDescriptor(proceed)); | 83 proceed_descriptor_.reset(new WebElementDescriptor(proceed)); |
82 } | 84 } |
83 | 85 |
84 void AutocheckoutManager::FillForms() { | 86 void AutocheckoutManager::FillForms() { |
85 // The proceed element should already have been set via a call to | 87 // The proceed element should already have been set via a call to |
86 // SetProceedElementDescriptor(). | 88 // SetProceedElementDescriptor(). |
87 DCHECK(proceed_descriptor_); | 89 DCHECK(proceed_descriptor_); |
88 | 90 |
89 // Fill the forms on the page with data given by user. | 91 // Fill the forms on the page with data given by user. |
90 std::vector<FormData> filled_forms; | 92 std::vector<FormData> filled_forms; |
91 const std::vector<FormStructure*>& form_structures = | 93 const std::vector<FormStructure*>& form_structures = |
(...skipping 23 matching lines...) Expand all Loading... |
115 *proceed_descriptor_)); | 117 *proceed_descriptor_)); |
116 } | 118 } |
117 | 119 |
118 void AutocheckoutManager::ShowAutocheckoutDialog( | 120 void AutocheckoutManager::ShowAutocheckoutDialog( |
119 const GURL& frame_url, | 121 const GURL& frame_url, |
120 const SSLStatus& ssl_status) { | 122 const SSLStatus& ssl_status) { |
121 base::Callback<void(const FormStructure*)> callback = | 123 base::Callback<void(const FormStructure*)> callback = |
122 base::Bind(&AutocheckoutManager::ReturnAutocheckoutData, | 124 base::Bind(&AutocheckoutManager::ReturnAutocheckoutData, |
123 weak_ptr_factory_.GetWeakPtr()); | 125 weak_ptr_factory_.GetWeakPtr()); |
124 autofill_manager_->ShowRequestAutocompleteDialog( | 126 autofill_manager_->ShowRequestAutocompleteDialog( |
125 BuildAutocheckoutFormData(), frame_url, ssl_status, callback); | 127 BuildAutocheckoutFormData(), frame_url, ssl_status, |
| 128 DIALOG_REQUESTER_AUTOCHECKOUT, callback); |
126 } | 129 } |
127 | 130 |
128 void AutocheckoutManager::ReturnAutocheckoutData(const FormStructure* result) { | 131 void AutocheckoutManager::ReturnAutocheckoutData(const FormStructure* result) { |
129 if (!result) | 132 if (!result) |
130 return; | 133 return; |
131 | 134 |
132 profile_.reset(new AutofillProfile()); | 135 profile_.reset(new AutofillProfile()); |
133 credit_card_.reset(new CreditCard()); | 136 credit_card_.reset(new CreditCard()); |
134 | 137 |
135 for (size_t i = 0; i < result->field_count(); ++i) { | 138 for (size_t i = 0; i < result->field_count(); ++i) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 return; | 170 return; |
168 } | 171 } |
169 | 172 |
170 // TODO(ramankk): Handle variants in a better fashion, need to distinguish | 173 // TODO(ramankk): Handle variants in a better fashion, need to distinguish |
171 // between shipping and billing address. | 174 // between shipping and billing address. |
172 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) | 175 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) |
173 credit_card_->FillFormField(field, 0, field_to_fill); | 176 credit_card_->FillFormField(field, 0, field_to_fill); |
174 else | 177 else |
175 profile_->FillFormField(field, 0, field_to_fill); | 178 profile_->FillFormField(field, 0, field_to_fill); |
176 } | 179 } |
| 180 |
| 181 } // namespace autofill |
OLD | NEW |