Chromium Code Reviews| 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 "components/autofill/browser/autocheckout_manager.h" | 5 #include "components/autofill/browser/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 "components/autofill/browser/autocheckout_request_manager.h" | |
| 10 #include "components/autofill/browser/autofill_country.h" | 11 #include "components/autofill/browser/autofill_country.h" |
| 11 #include "components/autofill/browser/autofill_field.h" | 12 #include "components/autofill/browser/autofill_field.h" |
| 12 #include "components/autofill/browser/autofill_manager.h" | 13 #include "components/autofill/browser/autofill_manager.h" |
| 13 #include "components/autofill/browser/autofill_profile.h" | 14 #include "components/autofill/browser/autofill_profile.h" |
| 14 #include "components/autofill/browser/credit_card.h" | 15 #include "components/autofill/browser/credit_card.h" |
| 15 #include "components/autofill/browser/field_types.h" | 16 #include "components/autofill/browser/field_types.h" |
| 16 #include "components/autofill/browser/form_structure.h" | 17 #include "components/autofill/browser/form_structure.h" |
| 17 #include "components/autofill/common/autocheckout_status.h" | |
| 18 #include "components/autofill/common/autofill_messages.h" | 18 #include "components/autofill/common/autofill_messages.h" |
| 19 #include "components/autofill/common/form_data.h" | 19 #include "components/autofill/common/form_data.h" |
| 20 #include "components/autofill/common/form_field_data.h" | 20 #include "components/autofill/common/form_field_data.h" |
| 21 #include "components/autofill/common/web_element_descriptor.h" | 21 #include "components/autofill/common/web_element_descriptor.h" |
| 22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/common/ssl_status.h" | 24 #include "content/public/common/ssl_status.h" |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
| 27 | 27 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 namespace autofill { | 73 namespace autofill { |
| 74 | 74 |
| 75 AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager) | 75 AutocheckoutManager::AutocheckoutManager(AutofillManager* autofill_manager) |
| 76 : autofill_manager_(autofill_manager), | 76 : autofill_manager_(autofill_manager), |
| 77 autocheckout_offered_(false), | 77 autocheckout_offered_(false), |
| 78 is_autocheckout_bubble_showing_(false), | 78 is_autocheckout_bubble_showing_(false), |
| 79 in_autocheckout_flow_(false), | 79 in_autocheckout_flow_(false), |
| 80 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 80 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 81 AutocheckoutRequestManager::CreateFromBrowserContext( | |
| 82 autofill_manager_->GetWebContents()->GetBrowserContext()); | |
| 81 } | 83 } |
| 82 | 84 |
| 83 AutocheckoutManager::~AutocheckoutManager() { | 85 AutocheckoutManager::~AutocheckoutManager() { |
| 84 } | 86 } |
| 85 | 87 |
| 86 void AutocheckoutManager::FillForms() { | 88 void AutocheckoutManager::FillForms() { |
| 87 // |page_meta_data_| should have been set by OnLoadedPageMetaData. | 89 // |page_meta_data_| should have been set by OnLoadedPageMetaData. |
| 88 DCHECK(page_meta_data_); | 90 DCHECK(page_meta_data_); |
| 89 | 91 |
| 90 // Fill the forms on the page with data given by user. | 92 // Fill the forms on the page with data given by user. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 110 autofill_manager_->GetWebContents()->GetRenderViewHost(); | 112 autofill_manager_->GetWebContents()->GetRenderViewHost(); |
| 111 if (!host) | 113 if (!host) |
| 112 return; | 114 return; |
| 113 | 115 |
| 114 host->Send(new AutofillMsg_FillFormsAndClick( | 116 host->Send(new AutofillMsg_FillFormsAndClick( |
| 115 host->GetRoutingID(), | 117 host->GetRoutingID(), |
| 116 filled_forms, | 118 filled_forms, |
| 117 *page_meta_data_->proceed_element_descriptor)); | 119 *page_meta_data_->proceed_element_descriptor)); |
| 118 } | 120 } |
| 119 | 121 |
| 122 void AutocheckoutManager::OnClickFailed(AutocheckoutStatus status) { | |
| 123 AutocheckoutRequestManager* autocheckout_request_manager = | |
| 124 AutocheckoutRequestManager::FromBrowserContext( | |
| 125 autofill_manager_->GetWebContents()->GetBrowserContext()); | |
| 126 // It is assumed that the domain Autocheckout starts on does not change during | |
| 127 // the flow. If this proves to be incorrect, the |source_url| from | |
| 128 // AutofillDialogControllerImpl will need to be provided in its callback in | |
| 129 // addition to the Google transaction id. | |
| 130 autocheckout_request_manager->SendAutocheckoutStatus( | |
| 131 status, | |
| 132 autofill_manager_->GetWebContents()->GetURL(), | |
| 133 google_transaction_id_); | |
|
Ilya Sherman
2013/03/26 23:50:01
nit: DCHECK that the transaction_id_ is set?
ahutter
2013/03/27 01:23:33
By set do you mean non-empty? Because empty is ok.
Ilya Sherman
2013/03/27 01:36:55
Maybe you should initialize the transaction id to
ahutter
2013/03/27 19:30:49
Done.
| |
| 134 autofill_manager_->delegate()->OnAutocheckoutError(); | |
| 135 } | |
| 136 | |
| 137 | |
| 120 void AutocheckoutManager::OnLoadedPageMetaData( | 138 void AutocheckoutManager::OnLoadedPageMetaData( |
| 121 scoped_ptr<AutocheckoutPageMetaData> page_meta_data) { | 139 scoped_ptr<AutocheckoutPageMetaData> page_meta_data) { |
| 122 scoped_ptr<AutocheckoutPageMetaData> old_meta_data = | 140 scoped_ptr<AutocheckoutPageMetaData> old_meta_data = |
| 123 page_meta_data_.Pass(); | 141 page_meta_data_.Pass(); |
| 124 page_meta_data_ = page_meta_data.Pass(); | 142 page_meta_data_ = page_meta_data.Pass(); |
| 125 | 143 |
| 126 // On the first page of an Autocheckout flow, when this function is called the | 144 // On the first page of an Autocheckout flow, when this function is called the |
| 127 // user won't have opted into the flow yet. | 145 // user won't have opted into the flow yet. |
| 128 if (!in_autocheckout_flow_) | 146 if (!in_autocheckout_flow_) |
| 129 return; | 147 return; |
| 130 | 148 |
| 149 AutocheckoutStatus status = SUCCESS; | |
| 150 | |
| 131 // Missing Autofill server results. | 151 // Missing Autofill server results. |
| 132 if (!page_meta_data_) { | 152 if (!page_meta_data_) { |
| 133 in_autocheckout_flow_ = false; | 153 in_autocheckout_flow_ = false; |
| 154 status = MISSING_FIELDMAPPING; | |
| 134 } else if (page_meta_data_->IsStartOfAutofillableFlow()) { | 155 } else if (page_meta_data_->IsStartOfAutofillableFlow()) { |
| 135 // Not possible unless Autocheckout failed to proceed. | 156 // Not possible unless Autocheckout failed to proceed. |
| 136 in_autocheckout_flow_ = false; | 157 in_autocheckout_flow_ = false; |
| 158 status = CANNOT_PROCEED; | |
| 137 } else if (!page_meta_data_->IsInAutofillableFlow()) { | 159 } else if (!page_meta_data_->IsInAutofillableFlow()) { |
| 138 // Missing Autocheckout meta data in the Autofill server results. | 160 // Missing Autocheckout meta data in the Autofill server results. |
| 139 in_autocheckout_flow_ = false; | 161 in_autocheckout_flow_ = false; |
| 162 status = MISSING_FIELDMAPPING; | |
| 140 } else if (page_meta_data_->current_page_number <= | 163 } else if (page_meta_data_->current_page_number <= |
| 141 old_meta_data->current_page_number) { | 164 old_meta_data->current_page_number) { |
| 142 // Not possible unless Autocheckout failed to proceed. | 165 // Not possible unless Autocheckout failed to proceed. |
| 143 in_autocheckout_flow_ = false; | 166 in_autocheckout_flow_ = false; |
| 167 status = CANNOT_PROCEED; | |
| 144 } | 168 } |
| 145 | 169 |
| 146 // Encountered an error during the Autocheckout flow. | 170 // Encountered an error during the Autocheckout flow. |
| 147 if (!in_autocheckout_flow_) { | 171 if (!in_autocheckout_flow_) { |
| 148 // TODO(ahutter): SendAutocheckoutStatus of the error. | 172 AutocheckoutRequestManager* autocheckout_request_manager = |
| 173 AutocheckoutRequestManager::FromBrowserContext( | |
| 174 autofill_manager_->GetWebContents()->GetBrowserContext()); | |
| 175 // It is assumed that the domain Autocheckout starts on does not change | |
| 176 // during the flow. If this proves to be incorrect, the |source_url| from | |
| 177 // AutofillDialogControllerImpl will need to be provided in its callback in | |
| 178 // addition to the Google transaction id. | |
| 179 autocheckout_request_manager->SendAutocheckoutStatus( | |
| 180 status, | |
| 181 autofill_manager_->GetWebContents()->GetURL(), | |
| 182 google_transaction_id_); | |
|
Ilya Sherman
2013/03/26 23:50:01
nit: Decompose this code into a shared method rath
ahutter
2013/03/27 01:23:33
Done.
| |
| 149 autofill_manager_->delegate()->OnAutocheckoutError(); | 183 autofill_manager_->delegate()->OnAutocheckoutError(); |
| 150 return; | 184 return; |
| 151 } | 185 } |
| 152 | 186 |
| 153 // Add 1.0 since page numbers are 0-indexed. | 187 // Add 1.0 since page numbers are 0-indexed. |
| 154 autofill_manager_->delegate()->UpdateProgressBar( | 188 autofill_manager_->delegate()->UpdateProgressBar( |
| 155 (1.0 + page_meta_data_->current_page_number) / | 189 (1.0 + page_meta_data_->current_page_number) / |
| 156 page_meta_data_->total_pages); | 190 page_meta_data_->total_pages); |
| 157 FillForms(); | 191 FillForms(); |
| 158 // If the current page is the last page in the flow, close the dialog. | 192 // If the current page is the last page in the flow, close the dialog. |
| 159 if (page_meta_data_->IsEndOfAutofillableFlow()) { | 193 if (page_meta_data_->IsEndOfAutofillableFlow()) { |
| 160 // TODO(ahutter): SendAutocheckoutStatus of SUCCESS. | 194 AutocheckoutRequestManager* autocheckout_request_manager = |
| 195 AutocheckoutRequestManager::FromBrowserContext( | |
| 196 autofill_manager_->GetWebContents()->GetBrowserContext()); | |
| 197 // It is assumed that the domain Autocheckout starts on does not change | |
| 198 // during the flow. If this proves to be incorrect, the |source_url| from | |
| 199 // AutofillDialogControllerImpl will need to be provided in its callback in | |
| 200 // addition to the Google transaction id. | |
| 201 autocheckout_request_manager->SendAutocheckoutStatus( | |
| 202 status, | |
| 203 autofill_manager_->GetWebContents()->GetURL(), | |
| 204 google_transaction_id_); | |
|
Ilya Sherman
2013/03/26 23:50:01
Ditto.
ahutter
2013/03/27 01:23:33
Done.
| |
| 161 autofill_manager_->delegate()->HideRequestAutocompleteDialog(); | 205 autofill_manager_->delegate()->HideRequestAutocompleteDialog(); |
| 162 in_autocheckout_flow_ = false; | 206 in_autocheckout_flow_ = false; |
| 163 } | 207 } |
| 164 } | 208 } |
| 165 | 209 |
| 166 void AutocheckoutManager::OnFormsSeen() { | 210 void AutocheckoutManager::OnFormsSeen() { |
| 167 autocheckout_offered_ = false; | 211 autocheckout_offered_ = false; |
| 168 } | 212 } |
| 169 | 213 |
| 170 void AutocheckoutManager::MaybeShowAutocheckoutBubble( | 214 void AutocheckoutManager::MaybeShowAutocheckoutBubble( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 193 void AutocheckoutManager::MaybeShowAutocheckoutDialog( | 237 void AutocheckoutManager::MaybeShowAutocheckoutDialog( |
| 194 const GURL& frame_url, | 238 const GURL& frame_url, |
| 195 const SSLStatus& ssl_status, | 239 const SSLStatus& ssl_status, |
| 196 bool show_dialog) { | 240 bool show_dialog) { |
| 197 is_autocheckout_bubble_showing_ = false; | 241 is_autocheckout_bubble_showing_ = false; |
| 198 if (!show_dialog) | 242 if (!show_dialog) |
| 199 return; | 243 return; |
| 200 | 244 |
| 201 FormData form = BuildAutocheckoutFormData(); | 245 FormData form = BuildAutocheckoutFormData(); |
| 202 form.ssl_status = ssl_status; | 246 form.ssl_status = ssl_status; |
| 203 base::Callback<void(const FormStructure*)> callback = | 247 base::Callback<void(const FormStructure*, const std::string&)> callback = |
| 204 base::Bind(&AutocheckoutManager::ReturnAutocheckoutData, | 248 base::Bind(&AutocheckoutManager::ReturnAutocheckoutData, |
| 205 weak_ptr_factory_.GetWeakPtr()); | 249 weak_ptr_factory_.GetWeakPtr()); |
| 206 autofill_manager_->ShowRequestAutocompleteDialog( | 250 autofill_manager_->ShowRequestAutocompleteDialog( |
| 207 form, frame_url, DIALOG_TYPE_AUTOCHECKOUT, callback); | 251 form, frame_url, DIALOG_TYPE_AUTOCHECKOUT, callback); |
| 208 } | 252 } |
| 209 | 253 |
| 210 bool AutocheckoutManager::IsStartOfAutofillableFlow() const { | 254 bool AutocheckoutManager::IsStartOfAutofillableFlow() const { |
| 211 return page_meta_data_ && page_meta_data_->IsStartOfAutofillableFlow(); | 255 return page_meta_data_ && page_meta_data_->IsStartOfAutofillableFlow(); |
| 212 } | 256 } |
| 213 | 257 |
| 214 bool AutocheckoutManager::IsInAutofillableFlow() const { | 258 bool AutocheckoutManager::IsInAutofillableFlow() const { |
| 215 return page_meta_data_ && page_meta_data_->IsInAutofillableFlow(); | 259 return page_meta_data_ && page_meta_data_->IsInAutofillableFlow(); |
| 216 } | 260 } |
| 217 | 261 |
| 218 void AutocheckoutManager::ReturnAutocheckoutData(const FormStructure* result) { | 262 void AutocheckoutManager::ReturnAutocheckoutData( |
| 263 const FormStructure* result, | |
| 264 const std::string& google_transaction_id) { | |
| 219 if (!result) | 265 if (!result) |
| 220 return; | 266 return; |
| 221 | 267 |
| 268 google_transaction_id_ = google_transaction_id; | |
| 222 in_autocheckout_flow_ = true; | 269 in_autocheckout_flow_ = true; |
| 223 | 270 |
| 224 profile_.reset(new AutofillProfile()); | 271 profile_.reset(new AutofillProfile()); |
| 225 credit_card_.reset(new CreditCard()); | 272 credit_card_.reset(new CreditCard()); |
| 226 | 273 |
| 227 for (size_t i = 0; i < result->field_count(); ++i) { | 274 for (size_t i = 0; i < result->field_count(); ++i) { |
| 228 AutofillFieldType type = result->field(i)->type(); | 275 AutofillFieldType type = result->field(i)->type(); |
| 229 if (type == CREDIT_CARD_VERIFICATION_CODE) { | 276 if (type == CREDIT_CARD_VERIFICATION_CODE) { |
| 230 cvv_ = result->field(i)->value; | 277 cvv_ = result->field(i)->value; |
| 231 continue; | 278 continue; |
| 232 } | 279 } |
| 233 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) { | 280 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) { |
| 234 credit_card_->SetRawInfo(result->field(i)->type(), | 281 credit_card_->SetRawInfo(result->field(i)->type(), |
| 235 result->field(i)->value); | 282 result->field(i)->value); |
| 236 } else { | 283 } else { |
| 237 profile_->SetRawInfo(result->field(i)->type(), result->field(i)->value); | 284 profile_->SetRawInfo(result->field(i)->type(), result->field(i)->value); |
| 238 } | 285 } |
| 239 } | 286 } |
| 240 | 287 |
| 241 // Add 1.0 since page numbers are 0-indexed. | 288 // Add 1.0 since page numbers are 0-indexed. |
| 242 autofill_manager_->delegate()->UpdateProgressBar( | 289 autofill_manager_->delegate()->UpdateProgressBar( |
| 243 (1.0 + page_meta_data_->current_page_number) / | 290 (1.0 + page_meta_data_->current_page_number) / |
| 244 page_meta_data_->total_pages); | 291 page_meta_data_->total_pages); |
| 245 FillForms(); | 292 FillForms(); |
| 246 | 293 |
| 247 // If the current page is the last page in the flow, close the dialog. | 294 // If the current page is the last page in the flow, close the dialog. |
| 248 if (page_meta_data_->IsEndOfAutofillableFlow()) { | 295 if (page_meta_data_->IsEndOfAutofillableFlow()) { |
| 249 // TODO(ahutter): SendAutocheckoutStatus of SUCCESS. | 296 AutocheckoutRequestManager* autocheckout_request_manager = |
| 297 AutocheckoutRequestManager::FromBrowserContext( | |
| 298 autofill_manager_->GetWebContents()->GetBrowserContext()); | |
| 299 // It is assumed that the domain Autocheckout starts on does not change | |
| 300 // during the flow. If this proves to be incorrect, the |source_url| from | |
| 301 // AutofillDialogControllerImpl will need to be provided in its callback in | |
| 302 // addition to the Google transaction id. | |
| 303 autocheckout_request_manager->SendAutocheckoutStatus( | |
| 304 SUCCESS, | |
| 305 autofill_manager_->GetWebContents()->GetURL(), | |
| 306 google_transaction_id_); | |
|
Ilya Sherman
2013/03/26 23:50:01
Ditto
ahutter
2013/03/27 01:23:33
Done.
| |
| 250 autofill_manager_->delegate()->HideRequestAutocompleteDialog(); | 307 autofill_manager_->delegate()->HideRequestAutocompleteDialog(); |
| 251 in_autocheckout_flow_ = false; | 308 in_autocheckout_flow_ = false; |
| 252 } | 309 } |
| 253 } | 310 } |
| 254 | 311 |
| 255 void AutocheckoutManager::SetValue(const AutofillField& field, | 312 void AutocheckoutManager::SetValue(const AutofillField& field, |
| 256 FormFieldData* field_to_fill) { | 313 FormFieldData* field_to_fill) { |
| 257 AutofillFieldType type = field.type(); | 314 AutofillFieldType type = field.type(); |
| 258 | 315 |
| 259 if (type == FIELD_WITH_DEFAULT_VALUE) { | 316 if (type == FIELD_WITH_DEFAULT_VALUE) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 284 | 341 |
| 285 // TODO(ramankk): Handle variants in a better fashion, need to distinguish | 342 // TODO(ramankk): Handle variants in a better fashion, need to distinguish |
| 286 // between shipping and billing address. | 343 // between shipping and billing address. |
| 287 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) | 344 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) |
| 288 credit_card_->FillFormField(field, 0, field_to_fill); | 345 credit_card_->FillFormField(field, 0, field_to_fill); |
| 289 else | 346 else |
| 290 profile_->FillFormField(field, 0, field_to_fill); | 347 profile_->FillFormField(field, 0, field_to_fill); |
| 291 } | 348 } |
| 292 | 349 |
| 293 } // namespace autofill | 350 } // namespace autofill |
| OLD | NEW |