| 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/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/extensions/shell_window_registry.h" | 20 #include "chrome/browser/extensions/shell_window_registry.h" |
| 21 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 23 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 23 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 24 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 26 #include "chrome/browser/ui/browser_navigator.h" | 27 #include "chrome/browser/ui/browser_navigator.h" |
| 27 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 28 #include "chrome/browser/ui/extensions/native_app_window.h" | 29 #include "chrome/browser/ui/extensions/native_app_window.h" |
| 29 #include "chrome/browser/ui/extensions/shell_window.h" | 30 #include "chrome/browser/ui/extensions/shell_window.h" |
| 30 #include "chrome/common/chrome_version_info.h" | 31 #include "chrome/common/chrome_version_info.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // special value to the server to just ask for the maximum so we don't need to | 84 // special value to the server to just ask for the maximum so we don't need to |
| 84 // hardcode it here (http://crbug.com/180731). TODO(dbeam): also maybe allow | 85 // hardcode it here (http://crbug.com/180731). TODO(dbeam): also maybe allow |
| 85 // users to give us this number via an <input> (http://crbug.com/180733). | 86 // users to give us this number via an <input> (http://crbug.com/180733). |
| 86 const int kCartMax = 1850; | 87 const int kCartMax = 1850; |
| 87 const char kCartCurrency[] = "USD"; | 88 const char kCartCurrency[] = "USD"; |
| 88 | 89 |
| 89 const char kAddNewItemKey[] = "add-new-item"; | 90 const char kAddNewItemKey[] = "add-new-item"; |
| 90 const char kManageItemsKey[] = "manage-items"; | 91 const char kManageItemsKey[] = "manage-items"; |
| 91 const char kSameAsBillingKey[] = "same-as-billing"; | 92 const char kSameAsBillingKey[] = "same-as-billing"; |
| 92 | 93 |
| 94 // Keys for the kAutofillDialogAutofillDefault pref dictionary (do not change |
| 95 // these values). |
| 96 const char kGuidPrefKey[] = "guid"; |
| 97 const char kVariantPrefKey[] = "variant"; |
| 98 |
| 93 // This string is stored along with saved addresses and credit cards in the | 99 // This string is stored along with saved addresses and credit cards in the |
| 94 // WebDB, and hence should not be modified, so that it remains consistent over | 100 // WebDB, and hence should not be modified, so that it remains consistent over |
| 95 // time. | 101 // time. |
| 96 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; | 102 const char kAutofillDialogOrigin[] = "Chrome Autofill dialog"; |
| 97 | 103 |
| 98 // HSL shift to gray out an image. | 104 // HSL shift to gray out an image. |
| 99 const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; | 105 const color_utils::HSL kGrayImageShift = {-1, 0, 0.8}; |
| 100 | 106 |
| 101 // Returns true if |input| should be shown when |field_type| has been requested. | 107 // Returns true if |input| should be shown when |field_type| has been requested. |
| 102 bool InputTypeMatchesFieldType(const DetailInput& input, | 108 bool InputTypeMatchesFieldType(const DetailInput& input, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 AutofillFieldType type) { | 238 AutofillFieldType type) { |
| 233 for (DetailOutputMap::const_iterator it = output.begin(); | 239 for (DetailOutputMap::const_iterator it = output.begin(); |
| 234 it != output.end(); ++it) { | 240 it != output.end(); ++it) { |
| 235 if (it->first->type == type) | 241 if (it->first->type == type) |
| 236 return it->second; | 242 return it->second; |
| 237 } | 243 } |
| 238 NOTREACHED(); | 244 NOTREACHED(); |
| 239 return string16(); | 245 return string16(); |
| 240 } | 246 } |
| 241 | 247 |
| 248 // Returns a string descriptor for a DialogSection, for use with prefs (do not |
| 249 // change these values). |
| 250 std::string SectionToPrefString(DialogSection section) { |
| 251 switch (section) { |
| 252 case SECTION_CC: |
| 253 return "cc"; |
| 254 |
| 255 case SECTION_BILLING: |
| 256 return "billing"; |
| 257 |
| 258 case SECTION_CC_BILLING: |
| 259 // The SECTION_CC_BILLING section isn't active when using Autofill. |
| 260 NOTREACHED(); |
| 261 return std::string(); |
| 262 |
| 263 case SECTION_SHIPPING: |
| 264 return "shipping"; |
| 265 |
| 266 case SECTION_EMAIL: |
| 267 return "email"; |
| 268 } |
| 269 |
| 270 NOTREACHED(); |
| 271 return std::string(); |
| 272 } |
| 273 |
| 242 // Check if a given MaskedInstrument is allowed for the purchase. | 274 // Check if a given MaskedInstrument is allowed for the purchase. |
| 243 bool IsInstrumentAllowed( | 275 bool IsInstrumentAllowed( |
| 244 const wallet::WalletItems::MaskedInstrument& instrument) { | 276 const wallet::WalletItems::MaskedInstrument& instrument) { |
| 245 return (instrument.status() == wallet::WalletItems::MaskedInstrument::VALID || | 277 return (instrument.status() == wallet::WalletItems::MaskedInstrument::VALID || |
| 246 instrument.status() == wallet::WalletItems::MaskedInstrument::PENDING) && | 278 instrument.status() == wallet::WalletItems::MaskedInstrument::PENDING) && |
| 247 instrument.type() != wallet::WalletItems::MaskedInstrument::AMEX && | 279 instrument.type() != wallet::WalletItems::MaskedInstrument::AMEX && |
| 248 instrument.type() != wallet::WalletItems::MaskedInstrument::UNKNOWN; | 280 instrument.type() != wallet::WalletItems::MaskedInstrument::UNKNOWN; |
| 249 } | 281 } |
| 250 | 282 |
| 251 // Signals that the user has opted in to geolocation services. Factored out | 283 // Signals that the user has opted in to geolocation services. Factored out |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); | 340 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); |
| 309 } | 341 } |
| 310 | 342 |
| 311 // static | 343 // static |
| 312 void AutofillDialogControllerImpl::RegisterUserPrefs( | 344 void AutofillDialogControllerImpl::RegisterUserPrefs( |
| 313 user_prefs::PrefRegistrySyncable* registry) { | 345 user_prefs::PrefRegistrySyncable* registry) { |
| 314 registry->RegisterBooleanPref( | 346 registry->RegisterBooleanPref( |
| 315 ::prefs::kAutofillDialogPayWithoutWallet, | 347 ::prefs::kAutofillDialogPayWithoutWallet, |
| 316 kPayWithoutWalletDefault, | 348 kPayWithoutWalletDefault, |
| 317 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 349 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 350 registry->RegisterDictionaryPref( |
| 351 ::prefs::kAutofillDialogAutofillDefault, |
| 352 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 318 } | 353 } |
| 319 | 354 |
| 320 void AutofillDialogControllerImpl::Show() { | 355 void AutofillDialogControllerImpl::Show() { |
| 321 dialog_shown_timestamp_ = base::Time::Now(); | 356 dialog_shown_timestamp_ = base::Time::Now(); |
| 322 | 357 |
| 323 content::NavigationEntry* entry = contents_->GetController().GetActiveEntry(); | 358 content::NavigationEntry* entry = contents_->GetController().GetActiveEntry(); |
| 324 const GURL& active_url = entry ? entry->GetURL() : contents_->GetURL(); | 359 const GURL& active_url = entry ? entry->GetURL() : contents_->GetURL(); |
| 325 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); | 360 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); |
| 326 | 361 |
| 327 // Log any relevant UI metrics and security exceptions. | 362 // Log any relevant UI metrics and security exceptions. |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 | 1013 |
| 979 return scoped_ptr<DataModelWrapper>(); | 1014 return scoped_ptr<DataModelWrapper>(); |
| 980 } | 1015 } |
| 981 | 1016 |
| 982 if (section == SECTION_CC) { | 1017 if (section == SECTION_CC) { |
| 983 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); | 1018 CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); |
| 984 DCHECK(card); | 1019 DCHECK(card); |
| 985 return scoped_ptr<DataModelWrapper>(new AutofillCreditCardWrapper(card)); | 1020 return scoped_ptr<DataModelWrapper>(new AutofillCreditCardWrapper(card)); |
| 986 } | 1021 } |
| 987 | 1022 |
| 988 // Calculate the variant by looking at how many items come from the same | |
| 989 // data model. | |
| 990 size_t variant = 0; | |
| 991 for (int i = model->checked_item() - 1; i >= 0; --i) { | |
| 992 if (model->GetItemKeyAt(i) == item_key) | |
| 993 variant++; | |
| 994 else | |
| 995 break; | |
| 996 } | |
| 997 | |
| 998 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); | 1023 AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); |
| 999 DCHECK(profile); | 1024 DCHECK(profile); |
| 1025 size_t variant = GetSelectedVariantForModel(*model); |
| 1000 return scoped_ptr<DataModelWrapper>( | 1026 return scoped_ptr<DataModelWrapper>( |
| 1001 new AutofillProfileWrapper(profile, variant)); | 1027 new AutofillProfileWrapper(profile, variant)); |
| 1002 } | 1028 } |
| 1003 | 1029 |
| 1004 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( | 1030 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( |
| 1005 DialogSection section) { | 1031 DialogSection section) { |
| 1006 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); | 1032 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
| 1007 if (!model.get()) | 1033 if (!model.get()) |
| 1008 return gfx::Image(); | 1034 return gfx::Image(); |
| 1009 | 1035 |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 1826 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 1801 params.disposition = NEW_FOREGROUND_TAB; | 1827 params.disposition = NEW_FOREGROUND_TAB; |
| 1802 chrome::Navigate(¶ms); | 1828 chrome::Navigate(¶ms); |
| 1803 #else | 1829 #else |
| 1804 // TODO(estade): use TabModelList? | 1830 // TODO(estade): use TabModelList? |
| 1805 #endif | 1831 #endif |
| 1806 } | 1832 } |
| 1807 | 1833 |
| 1808 void AutofillDialogControllerImpl::DisableWallet() { | 1834 void AutofillDialogControllerImpl::DisableWallet() { |
| 1809 signin_helper_.reset(); | 1835 signin_helper_.reset(); |
| 1836 wallet_items_.reset(); |
| 1837 GetWalletClient()->CancelRequests(); |
| 1838 SetIsSubmitting(false); |
| 1810 account_chooser_model_.SetHadWalletError(); | 1839 account_chooser_model_.SetHadWalletError(); |
| 1811 GetWalletClient()->CancelRequests(); | |
| 1812 wallet_items_.reset(); | |
| 1813 full_wallet_.reset(); | |
| 1814 SetIsSubmitting(false); | |
| 1815 } | 1840 } |
| 1816 | 1841 |
| 1817 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 1842 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| 1818 suggested_email_.Reset(); | 1843 suggested_email_.Reset(); |
| 1819 suggested_cc_.Reset(); | 1844 suggested_cc_.Reset(); |
| 1820 suggested_billing_.Reset(); | 1845 suggested_billing_.Reset(); |
| 1821 suggested_cc_billing_.Reset(); | 1846 suggested_cc_billing_.Reset(); |
| 1822 suggested_shipping_.Reset(); | 1847 suggested_shipping_.Reset(); |
| 1823 HidePopup(); | 1848 HidePopup(); |
| 1824 | 1849 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 } | 1984 } |
| 1960 | 1985 |
| 1961 suggested_shipping_.AddKeyedItem( | 1986 suggested_shipping_.AddKeyedItem( |
| 1962 kAddNewItemKey, | 1987 kAddNewItemKey, |
| 1963 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); | 1988 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); |
| 1964 suggested_shipping_.AddKeyedItem( | 1989 suggested_shipping_.AddKeyedItem( |
| 1965 kManageItemsKey, | 1990 kManageItemsKey, |
| 1966 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); | 1991 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); |
| 1967 | 1992 |
| 1968 if (!IsPayingWithWallet()) { | 1993 if (!IsPayingWithWallet()) { |
| 1969 // When using Autofill, the default option is the first suggestion, if | 1994 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 1970 // one exists. Otherwise it's the "Use shipping for billing" item. | 1995 DialogSection section = static_cast<DialogSection>(i); |
| 1971 const std::string& first_real_suggestion_item_key = | 1996 if (!SectionIsActive(section)) |
| 1972 suggested_shipping_.GetItemKeyAt(1); | 1997 continue; |
| 1973 if (IsASuggestionItemKey(first_real_suggestion_item_key)) | 1998 |
| 1974 suggested_shipping_.SetCheckedItem(first_real_suggestion_item_key); | 1999 // Set the starting choice for the menu. First set to the default in case |
| 2000 // the GUID saved in prefs refers to a profile that no longer exists. |
| 2001 std::string guid; |
| 2002 int variant; |
| 2003 GetDefaultAutofillChoice(section, &guid, &variant); |
| 2004 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 2005 model->SetCheckedItemNthWithKey(guid, variant + 1); |
| 2006 if (GetAutofillChoice(section, &guid, &variant)) |
| 2007 model->SetCheckedItemNthWithKey(guid, variant + 1); |
| 2008 } |
| 1975 } | 2009 } |
| 1976 | 2010 |
| 1977 if (view_) | 2011 if (view_) |
| 1978 view_->ModelChanged(); | 2012 view_->ModelChanged(); |
| 1979 | 2013 |
| 1980 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { | 2014 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { |
| 1981 PrepareDetailInputsForSection(static_cast<DialogSection>(section)); | 2015 PrepareDetailInputsForSection(static_cast<DialogSection>(section)); |
| 1982 } | 2016 } |
| 1983 } | 2017 } |
| 1984 | 2018 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2272 // switching payment methods, so only ask the view whether to save details | 2306 // switching payment methods, so only ask the view whether to save details |
| 2273 // locally if that checkbox is showing (currently if not paying with wallet). | 2307 // locally if that checkbox is showing (currently if not paying with wallet). |
| 2274 // Also, if the user isn't editing any sections, there's no data to save | 2308 // Also, if the user isn't editing any sections, there's no data to save |
| 2275 // locally. | 2309 // locally. |
| 2276 return ShouldOfferToSaveInChrome() && view_->SaveDetailsLocally(); | 2310 return ShouldOfferToSaveInChrome() && view_->SaveDetailsLocally(); |
| 2277 } | 2311 } |
| 2278 | 2312 |
| 2279 void AutofillDialogControllerImpl::SetIsSubmitting(bool submitting) { | 2313 void AutofillDialogControllerImpl::SetIsSubmitting(bool submitting) { |
| 2280 is_submitting_ = submitting; | 2314 is_submitting_ = submitting; |
| 2281 | 2315 |
| 2316 if (!submitting) |
| 2317 full_wallet_.reset(); |
| 2318 |
| 2282 if (view_) { | 2319 if (view_) { |
| 2283 view_->UpdateButtonStrip(); | 2320 view_->UpdateButtonStrip(); |
| 2284 view_->UpdateNotificationArea(); | 2321 view_->UpdateNotificationArea(); |
| 2285 } | 2322 } |
| 2286 } | 2323 } |
| 2287 | 2324 |
| 2288 void AutofillDialogControllerImpl::SubmitWithWallet() { | 2325 void AutofillDialogControllerImpl::SubmitWithWallet() { |
| 2289 // TODO(dbeam): disallow interacting with the dialog while submitting. | 2326 // TODO(dbeam): disallow interacting with the dialog while submitting. |
| 2290 // http://crbug.com/230932 | 2327 // http://crbug.com/230932 |
| 2291 | 2328 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 FillOutputForSectionWithComparator( | 2521 FillOutputForSectionWithComparator( |
| 2485 SECTION_CC, | 2522 SECTION_CC, |
| 2486 base::Bind(DetailInputMatchesShippingField)); | 2523 base::Bind(DetailInputMatchesShippingField)); |
| 2487 FillOutputForSectionWithComparator( | 2524 FillOutputForSectionWithComparator( |
| 2488 SECTION_CC_BILLING, | 2525 SECTION_CC_BILLING, |
| 2489 base::Bind(DetailInputMatchesShippingField)); | 2526 base::Bind(DetailInputMatchesShippingField)); |
| 2490 } else { | 2527 } else { |
| 2491 FillOutputForSection(SECTION_SHIPPING); | 2528 FillOutputForSection(SECTION_SHIPPING); |
| 2492 } | 2529 } |
| 2493 | 2530 |
| 2531 if (!IsPayingWithWallet()) { |
| 2532 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 2533 DialogSection section = static_cast<DialogSection>(i); |
| 2534 if (!SectionIsActive(section)) |
| 2535 continue; |
| 2536 |
| 2537 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 2538 std::string item_key = model->GetItemKeyForCheckedItem(); |
| 2539 if (IsASuggestionItemKey(item_key) || item_key == kSameAsBillingKey) { |
| 2540 int variant = GetSelectedVariantForModel(*model); |
| 2541 PersistAutofillChoice(section, item_key, variant); |
| 2542 } |
| 2543 } |
| 2544 } |
| 2545 |
| 2494 callback_.Run(&form_structure_, !wallet_items_ ? std::string() : | 2546 callback_.Run(&form_structure_, !wallet_items_ ? std::string() : |
| 2495 wallet_items_->google_transaction_id()); | 2547 wallet_items_->google_transaction_id()); |
| 2496 callback_ = base::Callback<void(const FormStructure*, const std::string&)>(); | 2548 callback_ = base::Callback<void(const FormStructure*, const std::string&)>(); |
| 2497 | 2549 |
| 2498 LogOnFinishSubmitMetrics(); | 2550 LogOnFinishSubmitMetrics(); |
| 2499 | 2551 |
| 2500 // On a successful submit, if the user manually selected "pay without wallet", | 2552 // On a successful submit, if the user manually selected "pay without wallet", |
| 2501 // stop trying to pay with Wallet on future runs of the dialog. | 2553 // stop trying to pay with Wallet on future runs of the dialog. |
| 2502 bool manually_selected_pay_without_wallet = | 2554 bool manually_selected_pay_without_wallet = |
| 2503 !account_chooser_model_.WalletIsSelected() && | 2555 !account_chooser_model_.WalletIsSelected() && |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2518 view_->UpdateNotificationArea(); | 2570 view_->UpdateNotificationArea(); |
| 2519 break; | 2571 break; |
| 2520 | 2572 |
| 2521 case DIALOG_TYPE_REQUEST_AUTOCOMPLETE: | 2573 case DIALOG_TYPE_REQUEST_AUTOCOMPLETE: |
| 2522 // This may delete us. | 2574 // This may delete us. |
| 2523 Hide(); | 2575 Hide(); |
| 2524 break; | 2576 break; |
| 2525 } | 2577 } |
| 2526 } | 2578 } |
| 2527 | 2579 |
| 2580 void AutofillDialogControllerImpl::PersistAutofillChoice( |
| 2581 DialogSection section, |
| 2582 const std::string& guid, |
| 2583 int variant) { |
| 2584 DCHECK(!IsPayingWithWallet()); |
| 2585 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 2586 value->SetString(kGuidPrefKey, guid); |
| 2587 value->SetInteger(kVariantPrefKey, variant); |
| 2588 |
| 2589 DictionaryPrefUpdate updater(profile()->GetPrefs(), |
| 2590 ::prefs::kAutofillDialogAutofillDefault); |
| 2591 base::DictionaryValue* autofill_choice = updater.Get(); |
| 2592 autofill_choice->Set(SectionToPrefString(section), value.release()); |
| 2593 } |
| 2594 |
| 2595 void AutofillDialogControllerImpl::GetDefaultAutofillChoice( |
| 2596 DialogSection section, |
| 2597 std::string* guid, |
| 2598 int* variant) { |
| 2599 DCHECK(!IsPayingWithWallet()); |
| 2600 // The default choice is the first thing in the menu that is a suggestion |
| 2601 // item. |
| 2602 *variant = 0; |
| 2603 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 2604 for (int i = 0; i < model->GetItemCount(); ++i) { |
| 2605 if (IsASuggestionItemKey(model->GetItemKeyAt(i))) { |
| 2606 *guid = model->GetItemKeyAt(i); |
| 2607 break; |
| 2608 } |
| 2609 } |
| 2610 } |
| 2611 |
| 2612 bool AutofillDialogControllerImpl::GetAutofillChoice(DialogSection section, |
| 2613 std::string* guid, |
| 2614 int* variant) { |
| 2615 DCHECK(!IsPayingWithWallet()); |
| 2616 const base::DictionaryValue* choices = profile()->GetPrefs()->GetDictionary( |
| 2617 ::prefs::kAutofillDialogAutofillDefault); |
| 2618 if (!choices) |
| 2619 return false; |
| 2620 |
| 2621 const base::DictionaryValue* choice = NULL; |
| 2622 if (!choices->GetDictionary(SectionToPrefString(section), &choice)) |
| 2623 return false; |
| 2624 |
| 2625 choice->GetString(kGuidPrefKey, guid); |
| 2626 choice->GetInteger(kVariantPrefKey, variant); |
| 2627 return true; |
| 2628 } |
| 2629 |
| 2630 size_t AutofillDialogControllerImpl::GetSelectedVariantForModel( |
| 2631 const SuggestionsMenuModel& model) { |
| 2632 size_t variant = 0; |
| 2633 // Calculate the variant by looking at how many items come from the same |
| 2634 // data model. |
| 2635 for (int i = model.checked_item() - 1; i >= 0; --i) { |
| 2636 if (model.GetItemKeyAt(i) == model.GetItemKeyForCheckedItem()) |
| 2637 variant++; |
| 2638 else |
| 2639 break; |
| 2640 } |
| 2641 return variant; |
| 2642 } |
| 2643 |
| 2528 void AutofillDialogControllerImpl::LogOnFinishSubmitMetrics() { | 2644 void AutofillDialogControllerImpl::LogOnFinishSubmitMetrics() { |
| 2529 GetMetricLogger().LogDialogUiDuration( | 2645 GetMetricLogger().LogDialogUiDuration( |
| 2530 base::Time::Now() - dialog_shown_timestamp_, | 2646 base::Time::Now() - dialog_shown_timestamp_, |
| 2531 GetDialogType(), | 2647 GetDialogType(), |
| 2532 AutofillMetrics::DIALOG_ACCEPTED); | 2648 AutofillMetrics::DIALOG_ACCEPTED); |
| 2533 | 2649 |
| 2534 GetMetricLogger().LogDialogUiEvent( | 2650 GetMetricLogger().LogDialogUiEvent( |
| 2535 GetDialogType(), AutofillMetrics::DIALOG_UI_ACCEPTED); | 2651 GetDialogType(), AutofillMetrics::DIALOG_UI_ACCEPTED); |
| 2536 | 2652 |
| 2537 AutofillMetrics::DialogDismissalState dismissal_state; | 2653 AutofillMetrics::DialogDismissalState dismissal_state; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2621 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 2737 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
| 2622 } | 2738 } |
| 2623 | 2739 |
| 2624 // Has Wallet items. | 2740 // Has Wallet items. |
| 2625 return has_autofill_profiles ? | 2741 return has_autofill_profiles ? |
| 2626 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 2742 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
| 2627 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 2743 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
| 2628 } | 2744 } |
| 2629 | 2745 |
| 2630 } // namespace autofill | 2746 } // namespace autofill |
| OLD | NEW |