OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/autofill/autocheckout_manager.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
| 10 #include "chrome/common/form_data.h" |
| 11 #include "chrome/common/form_field_data.h" |
| 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/common/ssl_status.h" |
| 14 #include "googleurl/src/gurl.h" |
| 15 |
| 16 using content::SSLStatus; |
| 17 using content::WebContents; |
| 18 |
| 19 namespace { |
| 20 |
| 21 // Build FormFieldData based on the supplied |autocomplete_attribute|. Will |
| 22 // fill rest of properties with default values. |
| 23 FormFieldData BuildField(const std::string& autocomplete_attribute) { |
| 24 FormFieldData field; |
| 25 field.name = string16(); |
| 26 field.value = string16(); |
| 27 field.autocomplete_attribute = autocomplete_attribute; |
| 28 field.form_control_type = "text"; |
| 29 return field; |
| 30 } |
| 31 |
| 32 // Build Autocheckout specific form data to be consumed by |
| 33 // AutofillDialogController to show the Autocheckout specific UI. |
| 34 FormData BuildAutocheckoutFormData() { |
| 35 FormData formdata; |
| 36 formdata.fields.push_back(BuildField("name")); |
| 37 formdata.fields.push_back(BuildField("email")); |
| 38 formdata.fields.push_back(BuildField("cc-name")); |
| 39 formdata.fields.push_back(BuildField("cc-number")); |
| 40 formdata.fields.push_back(BuildField("cc-exp")); |
| 41 formdata.fields.push_back(BuildField("cc-csc")); |
| 42 formdata.fields.push_back(BuildField("billing street-address")); |
| 43 formdata.fields.push_back(BuildField("billing locality")); |
| 44 formdata.fields.push_back(BuildField("billing region")); |
| 45 formdata.fields.push_back(BuildField("billing country")); |
| 46 formdata.fields.push_back(BuildField("billing postal-code")); |
| 47 formdata.fields.push_back(BuildField("shipping street-address")); |
| 48 formdata.fields.push_back(BuildField("shipping locality")); |
| 49 formdata.fields.push_back(BuildField("shipping region")); |
| 50 formdata.fields.push_back(BuildField("shipping country")); |
| 51 formdata.fields.push_back(BuildField("shipping postal-code")); |
| 52 return formdata; |
| 53 } |
| 54 |
| 55 } // namespace |
| 56 |
| 57 AutocheckoutManager::AutocheckoutManager() |
| 58 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 59 } |
| 60 |
| 61 AutocheckoutManager::~AutocheckoutManager() { |
| 62 } |
| 63 |
| 64 void AutocheckoutManager::ShowAutocheckoutDialog( |
| 65 const GURL& frame_url, |
| 66 const SSLStatus& ssl_status, |
| 67 WebContents* web_contents) { |
| 68 base::Callback<void(const FormStructure*)> callback = |
| 69 base::Bind(&AutocheckoutManager::ReturnAutocheckoutData, |
| 70 weak_ptr_factory_.GetWeakPtr()); |
| 71 autofill::AutofillDialogController* controller = |
| 72 new autofill::AutofillDialogController(web_contents, |
| 73 BuildAutocheckoutFormData(), |
| 74 frame_url, |
| 75 ssl_status, |
| 76 callback); |
| 77 controller->Show(); |
| 78 } |
| 79 |
| 80 void AutocheckoutManager::ReturnAutocheckoutData(const FormStructure* result) { |
| 81 // TODO(ramankk): Parse the response FormStructure. |
| 82 } |
OLD | NEW |