| 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 "chrome/browser/ui/android/autofill/autofill_dialog_controller_android.
     h" |    5 #include "chrome/browser/ui/android/autofill/autofill_dialog_controller_android.
     h" | 
|    6  |    6  | 
|    7 #include "base/android/jni_android.h" |    7 #include "base/android/jni_android.h" | 
|    8 #include "base/android/jni_array.h" |    8 #include "base/android/jni_array.h" | 
|    9 #include "base/android/jni_string.h" |    9 #include "base/android/jni_string.h" | 
|   10 #include "base/android/scoped_java_ref.h" |   10 #include "base/android/scoped_java_ref.h" | 
|   11 #include "base/bind.h" |   11 #include "base/bind.h" | 
|   12 #include "base/logging.h" |   12 #include "base/logging.h" | 
|   13 #include "base/prefs/pref_service.h" |   13 #include "base/prefs/pref_service.h" | 
|   14 #include "base/prefs/scoped_user_pref_update.h" |   14 #include "base/prefs/scoped_user_pref_update.h" | 
|   15 #include "base/strings/utf_string_conversions.h" |   15 #include "base/strings/utf_string_conversions.h" | 
|   16 #include "chrome/browser/autofill/personal_data_manager_factory.h" |   16 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 
|   17 #include "chrome/browser/browser_process.h" |   17 #include "chrome/browser/browser_process.h" | 
|   18 #include "chrome/browser/profiles/profile.h" |   18 #include "chrome/browser/profiles/profile.h" | 
|   19 #include "chrome/browser/profiles/profile_manager.h" |   19 #include "chrome/browser/profiles/profile_manager.h" | 
|   20 #include "chrome/browser/ui/android/autofill/autofill_dialog_result.h" |   20 #include "chrome/browser/ui/android/autofill/autofill_dialog_result.h" | 
|   21 #include "chrome/browser/ui/android/window_android_helper.h" |   21 #include "chrome/browser/ui/android/window_android_helper.h" | 
|   22 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |   22 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" | 
|   23 #include "chrome/common/pref_names.h" |   23 #include "chrome/common/pref_names.h" | 
|   24 #include "chrome/common/url_constants.h" |   24 #include "chrome/common/url_constants.h" | 
|   25 #include "components/autofill/content/browser/wallet/full_wallet.h" |   25 #include "components/autofill/content/browser/wallet/full_wallet.h" | 
|   26 #include "components/autofill/core/browser/autofill_metrics.h" |   26 #include "components/autofill/core/browser/autofill_metrics.h" | 
|   27 #include "components/autofill/core/browser/autofill_profile.h" |   27 #include "components/autofill/core/browser/autofill_profile.h" | 
|   28 #include "components/autofill/core/browser/autofill_type.h" |   28 #include "components/autofill/core/browser/autofill_type.h" | 
|   29 #include "components/autofill/core/browser/credit_card.h" |   29 #include "components/autofill/core/browser/credit_card.h" | 
 |   30 #include "components/autofill/core/browser/detail_input.h" | 
 |   31 #include "components/autofill/core/browser/dialog_section.h" | 
 |   32 #include "components/autofill/core/browser/field_types.h" | 
|   30 #include "components/autofill/core/browser/personal_data_manager.h" |   33 #include "components/autofill/core/browser/personal_data_manager.h" | 
 |   34 #include "components/autofill/core/browser/server_field_types_util.h" | 
|   31 #include "components/autofill/core/common/form_data.h" |   35 #include "components/autofill/core/common/form_data.h" | 
|   32 #include "components/pref_registry/pref_registry_syncable.h" |   36 #include "components/pref_registry/pref_registry_syncable.h" | 
|   33 #include "content/public/browser/navigation_controller.h" |   37 #include "content/public/browser/navigation_controller.h" | 
|   34 #include "content/public/browser/navigation_details.h" |   38 #include "content/public/browser/navigation_details.h" | 
|   35 #include "content/public/browser/navigation_entry.h" |   39 #include "content/public/browser/navigation_entry.h" | 
|   36 #include "content/public/browser/web_contents.h" |   40 #include "content/public/browser/web_contents.h" | 
|   37 #include "jni/AutofillDialogControllerAndroid_jni.h" |   41 #include "jni/AutofillDialogControllerAndroid_jni.h" | 
|   38 #include "ui/android/window_android.h" |   42 #include "ui/android/window_android.h" | 
|   39 #include "ui/base/models/combobox_model.h" |   43 #include "ui/base/models/combobox_model.h" | 
|   40 #include "ui/base/models/menu_model.h" |   44 #include "ui/base/models/menu_model.h" | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|   65     { DetailInput::LONG, ADDRESS_BILLING_STATE }, |   69     { DetailInput::LONG, ADDRESS_BILLING_STATE }, | 
|   66     { DetailInput::LONG, ADDRESS_BILLING_ZIP }, |   70     { DetailInput::LONG, ADDRESS_BILLING_ZIP }, | 
|   67     { DetailInput::LONG, ADDRESS_BILLING_SORTING_CODE }, |   71     { DetailInput::LONG, ADDRESS_BILLING_SORTING_CODE }, | 
|   68     { DetailInput::LONG, ADDRESS_BILLING_COUNTRY }, |   72     { DetailInput::LONG, ADDRESS_BILLING_COUNTRY }, | 
|   69     { DetailInput::LONG, PHONE_BILLING_WHOLE_NUMBER }, |   73     { DetailInput::LONG, PHONE_BILLING_WHOLE_NUMBER }, | 
|   70     { DetailInput::LONG, CREDIT_CARD_NUMBER }, |   74     { DetailInput::LONG, CREDIT_CARD_NUMBER }, | 
|   71     { DetailInput::LONG, CREDIT_CARD_EXP_MONTH }, |   75     { DetailInput::LONG, CREDIT_CARD_EXP_MONTH }, | 
|   72     { DetailInput::LONG, CREDIT_CARD_EXP_4_DIGIT_YEAR }, |   76     { DetailInput::LONG, CREDIT_CARD_EXP_4_DIGIT_YEAR }, | 
|   73     { DetailInput::LONG, CREDIT_CARD_VERIFICATION_CODE }, |   77     { DetailInput::LONG, CREDIT_CARD_VERIFICATION_CODE }, | 
|   74   }; |   78   }; | 
|   75   common::BuildInputs(kCcBillingInputs, arraysize(kCcBillingInputs), inputs); |   79   BuildInputs(kCcBillingInputs, arraysize(kCcBillingInputs), inputs); | 
|   76 } |   80 } | 
|   77  |   81  | 
|   78 // Constructs |inputs| for the SECTION_SHIPPING section. |   82 // Constructs |inputs| for the SECTION_SHIPPING section. | 
|   79 void BuildShippingInputs(DetailInputs* inputs) { |   83 void BuildShippingInputs(DetailInputs* inputs) { | 
|   80   const DetailInput kShippingInputs[] = { |   84   const DetailInput kShippingInputs[] = { | 
|   81     { DetailInput::LONG, NAME_FULL }, |   85     { DetailInput::LONG, NAME_FULL }, | 
|   82     { DetailInput::LONG, ADDRESS_HOME_STREET_ADDRESS }, |   86     { DetailInput::LONG, ADDRESS_HOME_STREET_ADDRESS }, | 
|   83     { DetailInput::LONG, ADDRESS_HOME_CITY }, |   87     { DetailInput::LONG, ADDRESS_HOME_CITY }, | 
|   84     { DetailInput::LONG, ADDRESS_HOME_DEPENDENT_LOCALITY }, |   88     { DetailInput::LONG, ADDRESS_HOME_DEPENDENT_LOCALITY }, | 
|   85     { DetailInput::LONG, ADDRESS_HOME_STATE }, |   89     { DetailInput::LONG, ADDRESS_HOME_STATE }, | 
|   86     { DetailInput::LONG, ADDRESS_HOME_ZIP }, |   90     { DetailInput::LONG, ADDRESS_HOME_ZIP }, | 
|   87     { DetailInput::LONG, ADDRESS_HOME_SORTING_CODE }, |   91     { DetailInput::LONG, ADDRESS_HOME_SORTING_CODE }, | 
|   88     { DetailInput::LONG, ADDRESS_HOME_COUNTRY }, |   92     { DetailInput::LONG, ADDRESS_HOME_COUNTRY }, | 
|   89     { DetailInput::LONG, PHONE_HOME_WHOLE_NUMBER }, |   93     { DetailInput::LONG, PHONE_HOME_WHOLE_NUMBER }, | 
|   90   }; |   94   }; | 
|   91   common::BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |   95   BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | 
|   92 } |   96 } | 
|   93  |   97  | 
|   94 base::string16 NullGetInfo(const AutofillType& type) { |   98 base::string16 NullGetInfo(const AutofillType& type) { | 
|   95   return base::string16(); |   99   return base::string16(); | 
|   96 } |  100 } | 
|   97  |  101  | 
|   98 void FillOutputForSectionWithComparator( |  102 void FillOutputForSectionWithComparator( | 
|   99     DialogSection section, |  103     DialogSection section, | 
|  100     const DetailInputs& inputs, |  104     const DetailInputs& inputs, | 
|  101     const FormStructure::InputFieldComparator& compare, |  105     const FormStructure::InputFieldComparator& compare, | 
|  102     FormStructure& form_structure, |  106     FormStructure& form_structure, | 
|  103     FullWallet* full_wallet, |  107     FullWallet* full_wallet, | 
|  104     const base::string16& email_address) { |  108     const base::string16& email_address) { | 
|  105   if ((section == SECTION_CC_BILLING && !full_wallet->billing_address()) || |  109   if ((section == SECTION_CC_BILLING && !full_wallet->billing_address()) || | 
|  106       (section == SECTION_SHIPPING && !full_wallet->shipping_address())) { |  110       (section == SECTION_SHIPPING && !full_wallet->shipping_address())) { | 
|  107     return; |  111     return; | 
|  108   } |  112   } | 
|  109  |  113  | 
|  110   base::Callback<base::string16(const AutofillType&)> get_info = |  114   base::Callback<base::string16(const AutofillType&)> get_info = | 
|  111       base::Bind(&FullWallet::GetInfo, |  115       base::Bind(&FullWallet::GetInfo, | 
|  112                  base::Unretained(full_wallet), |  116                  base::Unretained(full_wallet), | 
|  113                  g_browser_process->GetApplicationLocale()); |  117                  g_browser_process->GetApplicationLocale()); | 
|  114  |  118  | 
|  115   std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); |  119   std::vector<ServerFieldType> types = TypesFromInputs(inputs); | 
|  116   form_structure.FillFields( |  120   form_structure.FillFields( | 
|  117       types, |  121       types, | 
|  118       compare, |  122       compare, | 
|  119       get_info, |  123       get_info, | 
|  120       section == SECTION_CC_BILLING |  124       section == SECTION_CC_BILLING | 
|  121           ? full_wallet->billing_address()->language_code() |  125           ? full_wallet->billing_address()->language_code() | 
|  122           : full_wallet->shipping_address()->language_code(), |  126           : full_wallet->shipping_address()->language_code(), | 
|  123       g_browser_process->GetApplicationLocale()); |  127       g_browser_process->GetApplicationLocale()); | 
|  124 } |  128 } | 
|  125  |  129  | 
|  126 void FillOutputForSection( |  130 void FillOutputForSection( | 
|  127     DialogSection section, |  131     DialogSection section, | 
|  128     FormStructure& form_structure, |  132     FormStructure& form_structure, | 
|  129     FullWallet* full_wallet, |  133     FullWallet* full_wallet, | 
|  130     const base::string16& email_address) { |  134     const base::string16& email_address) { | 
|  131   DCHECK(section == SECTION_CC_BILLING || section == SECTION_SHIPPING); |  135   DCHECK(section == SECTION_CC_BILLING || section == SECTION_SHIPPING); | 
|  132   DetailInputs inputs; |  136   DetailInputs inputs; | 
|  133   if (section == SECTION_CC_BILLING) |  137   if (section == SECTION_CC_BILLING) | 
|  134     BuildCcBillingInputs(&inputs); |  138     BuildCcBillingInputs(&inputs); | 
|  135   else |  139   else | 
|  136     BuildShippingInputs(&inputs); |  140     BuildShippingInputs(&inputs); | 
|  137  |  141  | 
|  138   FillOutputForSectionWithComparator( |  142   FillOutputForSectionWithComparator( | 
|  139       section, inputs, |  143       section, inputs, base::Bind(ServerTypeMatchesField, section), | 
|  140       base::Bind(common::ServerTypeMatchesField, section), |  | 
|  141       form_structure, full_wallet, email_address); |  144       form_structure, full_wallet, email_address); | 
|  142  |  145  | 
|  143   if (section == SECTION_CC_BILLING) { |  146   if (section == SECTION_CC_BILLING) { | 
|  144     // Email is hidden while using Wallet, special case it. |  147     // Email is hidden while using Wallet, special case it. | 
|  145     for (size_t i = 0; i < form_structure.field_count(); ++i) { |  148     for (size_t i = 0; i < form_structure.field_count(); ++i) { | 
|  146       AutofillField* field = form_structure.field(i); |  149       AutofillField* field = form_structure.field(i); | 
|  147       if (field->Type().GetStorableType() == EMAIL_ADDRESS) |  150       if (field->Type().GetStorableType() == EMAIL_ADDRESS) | 
|  148         field->value = email_address; |  151         field->value = email_address; | 
|  149     } |  152     } | 
|  150   } |  153   } | 
|  151 } |  154 } | 
|  152  |  155  | 
|  153 // Returns true if |input_type| in |section| is needed for |form_structure|. |  156 // Returns true if |input_type| in |section| is needed for |form_structure|. | 
|  154 bool IsSectionInputUsedInFormStructure(DialogSection section, |  157 bool IsSectionInputUsedInFormStructure(DialogSection section, | 
|  155                                        ServerFieldType input_type, |  158                                        ServerFieldType input_type, | 
|  156                                        const FormStructure& form_structure) { |  159                                        const FormStructure& form_structure) { | 
|  157   for (size_t i = 0; i < form_structure.field_count(); ++i) { |  160   for (size_t i = 0; i < form_structure.field_count(); ++i) { | 
|  158     const AutofillField* field = form_structure.field(i); |  161     const AutofillField* field = form_structure.field(i); | 
|  159     if (field && common::ServerTypeMatchesField(section, input_type, *field)) |  162     if (field && ServerTypeMatchesField(section, input_type, *field)) | 
|  160       return true; |  163       return true; | 
|  161   } |  164   } | 
|  162   return false; |  165   return false; | 
|  163 } |  166 } | 
|  164  |  167  | 
|  165 // Returns true if one of |inputs| in |section| is needed for |form_structure|. |  168 // Returns true if one of |inputs| in |section| is needed for |form_structure|. | 
|  166 bool IsSectionInputsUsedInFormStructure(DialogSection section, |  169 bool IsSectionInputsUsedInFormStructure(DialogSection section, | 
|  167                                         const ServerFieldType* input_types, |  170                                         const ServerFieldType* input_types, | 
|  168                                         const size_t input_types_size, |  171                                         const size_t input_types_size, | 
|  169                                         const FormStructure& form_structure) { |  172                                         const FormStructure& form_structure) { | 
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  337           SECTION_SHIPPING, |  340           SECTION_SHIPPING, | 
|  338           shipping_phone_number_is_necessary_if, |  341           shipping_phone_number_is_necessary_if, | 
|  339           arraysize(shipping_phone_number_is_necessary_if), |  342           arraysize(shipping_phone_number_is_necessary_if), | 
|  340           form_structure_); |  343           form_structure_); | 
|  341  |  344  | 
|  342   bool request_shipping_address = false; |  345   bool request_shipping_address = false; | 
|  343   { |  346   { | 
|  344     DetailInputs inputs; |  347     DetailInputs inputs; | 
|  345     BuildShippingInputs(&inputs); |  348     BuildShippingInputs(&inputs); | 
|  346     request_shipping_address = form_structure_.FillFields( |  349     request_shipping_address = form_structure_.FillFields( | 
|  347         common::TypesFromInputs(inputs), |  350         TypesFromInputs(inputs), | 
|  348         base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), |  351         base::Bind(ServerTypeMatchesField, SECTION_SHIPPING), | 
|  349         base::Bind(NullGetInfo), |  352         base::Bind(NullGetInfo), std::string(), | 
|  350         std::string(), |  | 
|  351         g_browser_process->GetApplicationLocale()); |  353         g_browser_process->GetApplicationLocale()); | 
|  352   } |  354   } | 
|  353  |  355  | 
|  354   bool last_used_choice_is_autofill = false; |  356   bool last_used_choice_is_autofill = false; | 
|  355   base::string16 last_used_account_name; |  357   base::string16 last_used_account_name; | 
|  356   std::string last_used_billing; |  358   std::string last_used_billing; | 
|  357   std::string last_used_shipping; |  359   std::string last_used_shipping; | 
|  358   std::string last_used_credit_card; |  360   std::string last_used_credit_card; | 
|  359   { |  361   { | 
|  360     const base::DictionaryValue* defaults = |  362     const base::DictionaryValue* defaults = | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  529  |  531  | 
|  530 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { |  532 void AutofillDialogControllerAndroid::LogOnCancelMetrics() { | 
|  531   AutofillMetrics::LogDialogUiDuration( |  533   AutofillMetrics::LogDialogUiDuration( | 
|  532       base::Time::Now() - dialog_shown_timestamp_, |  534       base::Time::Now() - dialog_shown_timestamp_, | 
|  533       AutofillMetrics::DIALOG_CANCELED); |  535       AutofillMetrics::DIALOG_CANCELED); | 
|  534  |  536  | 
|  535   AutofillMetrics::LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); |  537   AutofillMetrics::LogDialogUiEvent(AutofillMetrics::DIALOG_UI_CANCELED); | 
|  536 } |  538 } | 
|  537  |  539  | 
|  538 }  // namespace autofill |  540 }  // namespace autofill | 
| OLD | NEW |