Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
index 23480c548f1f9c5b16126412ba0087166a2f1c6c..1c92cefb34f96b1a769ef340a1432d0864efa1d5 100644 |
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
@@ -26,6 +26,7 @@ |
#include "chrome/browser/prefs/scoped_user_pref_update.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/autofill/autofill_credit_card_bubble_controller.h" |
+#include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
#include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
#include "chrome/browser/ui/autofill/data_model_wrapper.h" |
#include "chrome/browser/ui/browser.h" |
@@ -110,50 +111,6 @@ bool IsWalletSupportedCard(const std::string& card_type) { |
card_type == autofill::kDiscoverCard; |
} |
-// Returns true if |input| should be shown when |field_type| has been requested. |
-bool InputTypeMatchesFieldType(const DetailInput& input, |
- const AutofillType& field_type) { |
- // If any credit card expiration info is asked for, show both month and year |
- // inputs. |
- ServerFieldType server_type = field_type.GetStorableType(); |
- if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
- server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
- server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || |
- server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
- server_type == CREDIT_CARD_EXP_MONTH) { |
- return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
- input.type == CREDIT_CARD_EXP_MONTH; |
- } |
- |
- if (server_type == CREDIT_CARD_TYPE) |
- return input.type == CREDIT_CARD_NUMBER; |
- |
- // Check the groups to distinguish billing types from shipping ones. |
- AutofillType input_type = AutofillType(input.type); |
- return input_type.GetStorableType() == server_type && |
- input_type.group() == field_type.group(); |
-} |
- |
-// Returns true if |input| in the given |section| should be used for a |
-// site-requested |field|. |
-bool DetailInputMatchesField(DialogSection section, |
- const DetailInput& input, |
- const AutofillField& field) { |
- AutofillType field_type = field.Type(); |
- |
- // The credit card name is filled from the billing section's data. |
- if (field_type.GetStorableType() == CREDIT_CARD_NAME && |
- (section == SECTION_BILLING || section == SECTION_CC_BILLING)) { |
- return input.type == NAME_BILLING_FULL; |
- } |
- |
- return InputTypeMatchesFieldType(input, field_type); |
-} |
- |
-bool IsCreditCardType(ServerFieldType type) { |
- return AutofillType(type).group() == CREDIT_CARD; |
-} |
- |
// Returns true if |input| should be used to fill a site-requested |field| which |
// is notated with a "shipping" tag, for use when the user has decided to use |
// the billing address as the shipping address. |
@@ -165,17 +122,7 @@ bool DetailInputMatchesShippingField(const DetailInput& input, |
AutofillType::GetEquivalentBillingFieldType( |
field.Type().GetStorableType()); |
- return InputTypeMatchesFieldType(input, AutofillType(field_type)); |
-} |
- |
-// Constructs |inputs| from template data. |
-void BuildInputs(const DetailInput* input_template, |
- size_t template_size, |
- DetailInputs* inputs) { |
- for (size_t i = 0; i < template_size; ++i) { |
- const DetailInput* input = &input_template[i]; |
- inputs->push_back(*input); |
- } |
+ return common::InputTypeMatchesFieldType(input, AutofillType(field_type)); |
} |
// Initializes |form_group| from user-entered data. |
@@ -225,7 +172,7 @@ void GetBillingInfoFromOutputs(const DetailOutputMap& output, |
if (card && it->first->type == NAME_FULL) |
card->SetRawInfo(CREDIT_CARD_NAME, trimmed); |
- if (IsCreditCardType(it->first->type)) { |
+ if (common::IsCreditCardType(it->first->type)) { |
if (card) |
card->SetRawInfo(it->first->type, trimmed); |
} else if (profile) { |
@@ -444,7 +391,6 @@ gfx::Image GetGeneratedCardImage(const string16& card_number) { |
gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); |
canvas.DrawImageInt(*card, 0, 0); |
-#if !defined(OS_ANDROID) |
gfx::Rect display_rect(gfx::Point(), card->size()); |
display_rect.Inset(14, 0, 14, 0); |
// TODO(estade): fallback font for systems that don't have Helvetica? |
@@ -458,7 +404,6 @@ gfx::Image GetGeneratedCardImage(const string16& card_number) { |
helvetica, |
SK_ColorWHITE, |
display_rect, 0, 0, shadows); |
-#endif |
gfx::ImageSkia skia(canvas.ExtractImageRep()); |
return gfx::Image(skia); |
@@ -482,7 +427,6 @@ AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { |
} |
} |
-#if !defined(OS_ANDROID) |
// static |
base::WeakPtr<AutofillDialogControllerImpl> |
AutofillDialogControllerImpl::Create( |
@@ -501,7 +445,6 @@ base::WeakPtr<AutofillDialogControllerImpl> |
callback); |
return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); |
} |
-#endif // !defined(OS_ANDROID) |
// static |
void AutofillDialogControllerImpl::RegisterProfilePrefs( |
@@ -523,6 +466,27 @@ void AutofillDialogControllerImpl::RegisterProfilePrefs( |
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
} |
+// static |
+base::WeakPtr<AutofillDialogController> AutofillDialogController::Create( |
+ content::WebContents* contents, |
+ const FormData& form_structure, |
+ const GURL& source_url, |
+ const DialogType dialog_type, |
+ const base::Callback<void(const FormStructure*, |
+ const std::string&)>& callback) { |
+ return AutofillDialogControllerImpl::Create(contents, |
+ form_structure, |
+ source_url, |
+ dialog_type, |
+ callback); |
+} |
+ |
+// static |
+void AutofillDialogController::RegisterProfilePrefs( |
+ user_prefs::PrefRegistrySyncable* registry) { |
+ AutofillDialogControllerImpl::RegisterProfilePrefs(registry); |
+} |
+ |
void AutofillDialogControllerImpl::Show() { |
dialog_shown_timestamp_ = base::Time::Now(); |
@@ -563,71 +527,16 @@ void AutofillDialogControllerImpl::Show() { |
return; |
} |
- const DetailInput kEmailInputs[] = { |
- { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
- }; |
- |
- const DetailInput kCCInputs[] = { |
- { 2, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, |
- { 3, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, |
- { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR, |
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, |
- { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, |
- 1.5 }, |
- }; |
- |
- const DetailInput kBillingInputs[] = { |
- { 4, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, |
- { 5, ADDRESS_BILLING_LINE1, |
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
- { 6, ADDRESS_BILLING_LINE2, |
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
- { 7, ADDRESS_BILLING_CITY, |
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
- // TODO(estade): state placeholder should depend on locale. |
- { 8, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
- { 8, ADDRESS_BILLING_ZIP, |
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
- // We don't allow the user to change the country: http://crbug.com/247518 |
- { -1, ADDRESS_BILLING_COUNTRY, 0 }, |
- { 10, PHONE_BILLING_WHOLE_NUMBER, |
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
- }; |
- |
- const DetailInput kShippingInputs[] = { |
- { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, |
- { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
- { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
- { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
- { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
- { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
- { -1, ADDRESS_HOME_COUNTRY, 0 }, |
- { 17, PHONE_HOME_WHOLE_NUMBER, |
- IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
- }; |
- |
- BuildInputs(kEmailInputs, |
- arraysize(kEmailInputs), |
- &requested_email_fields_); |
- |
- BuildInputs(kCCInputs, |
- arraysize(kCCInputs), |
- &requested_cc_fields_); |
- |
- BuildInputs(kBillingInputs, |
- arraysize(kBillingInputs), |
- &requested_billing_fields_); |
- |
- BuildInputs(kCCInputs, |
- arraysize(kCCInputs), |
- &requested_cc_billing_fields_); |
- BuildInputs(kBillingInputs, |
- arraysize(kBillingInputs), |
- &requested_cc_billing_fields_); |
- |
- BuildInputs(kShippingInputs, |
- arraysize(kShippingInputs), |
- &requested_shipping_fields_); |
+ common::BuildInputsForSection(SECTION_EMAIL, |
+ &requested_email_fields_); |
+ common::BuildInputsForSection(SECTION_CC, |
+ &requested_cc_fields_); |
+ common::BuildInputsForSection(SECTION_BILLING, |
+ &requested_billing_fields_); |
+ common::BuildInputsForSection(SECTION_CC_BILLING, |
+ &requested_cc_billing_fields_); |
+ common::BuildInputsForSection(SECTION_SHIPPING, |
+ &requested_shipping_fields_); |
// Test whether we need to show the shipping section. If filling that section |
// would be a no-op, don't show it. |
@@ -635,7 +544,7 @@ void AutofillDialogControllerImpl::Show() { |
EmptyDataModelWrapper empty_wrapper; |
cares_about_shipping_ = empty_wrapper.FillFormStructure( |
inputs, |
- base::Bind(DetailInputMatchesField, SECTION_SHIPPING), |
+ base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), |
&form_structure_); |
SuggestionsUpdated(); |
@@ -867,10 +776,7 @@ DialogOverlayState AutofillDialogControllerImpl::GetDialogOverlay() const { |
state.strings.push_back(DialogOverlayString()); |
DialogOverlayString& string = state.strings.back(); |
-#if !defined(OS_ANDROID) |
- // gfx::Font isn't implemented on Android; DeriveFont() causes a null deref. |
string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); |
-#endif |
// First-run, post-submit, Wallet expository page. |
if (full_wallet_ && full_wallet_->required_actions().empty()) { |
@@ -1521,7 +1427,7 @@ void AutofillDialogControllerImpl::EditClickedForSection( |
UpdateSection(section); |
GetMetricLogger().LogDialogUiEvent( |
- GetDialogType(), DialogSectionToUiEditEvent(section)); |
+ GetDialogType(), common::DialogSectionToUiEditEvent(section)); |
} |
void AutofillDialogControllerImpl::EditCancelledForSection( |
@@ -1794,7 +1700,7 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput( |
} |
std::vector<string16> popup_values, popup_labels, popup_icons; |
- if (IsCreditCardType(input->type)) { |
+ if (common::IsCreditCardType(input->type)) { |
GetManager()->GetCreditCardSuggestions(AutofillType(input->type), |
field_contents, |
&popup_values, |
@@ -2096,7 +2002,7 @@ void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, |
const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; |
scoped_ptr<DataModelWrapper> wrapper; |
- if (IsCreditCardType(input_showing_popup_->type)) { |
+ if (common::IsCreditCardType(input_showing_popup_->type)) { |
wrapper.reset(new AutofillCreditCardWrapper( |
GetManager()->GetCreditCardByGUID(pair.first))); |
} else { |
@@ -2371,7 +2277,7 @@ bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
AutofillType type = form_structure_.field(i)->Type(); |
- if (IsCreditCardType(type.GetStorableType())) |
+ if (common::IsCreditCardType(type.GetStorableType())) |
return true; |
} |
@@ -2449,9 +2355,7 @@ void AutofillDialogControllerImpl::LoadRiskFingerprintData() { |
DCHECK(success); |
gfx::Rect window_bounds; |
-#if !defined(OS_ANDROID) |
window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds(); |
-#endif |
PrefService* user_prefs = profile_->GetPrefs(); |
std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); |
@@ -2481,14 +2385,12 @@ void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( |
} |
void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { |
-#if !defined(OS_ANDROID) |
chrome::NavigateParams params( |
chrome::FindBrowserWithWebContents(web_contents()), |
url, |
content::PAGE_TRANSITION_AUTO_BOOKMARK); |
params.disposition = NEW_FOREGROUND_TAB; |
chrome::Navigate(¶ms); |
-#endif |
} |
bool AutofillDialogControllerImpl::IsEditingExistingData( |
@@ -2815,7 +2717,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
FillOutputForSectionWithComparator( |
- section, base::Bind(DetailInputMatchesField, section)); |
+ section, base::Bind(common::DetailInputMatchesField, section)); |
} |
bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( |
@@ -3417,10 +3319,10 @@ void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric( |
AutofillMetrics::DialogUiEvent dialog_ui_event; |
if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) { |
// Selected to add a new item. |
- dialog_ui_event = DialogSectionToUiItemAddedEvent(section); |
+ dialog_ui_event = common::DialogSectionToUiItemAddedEvent(section); |
} else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) { |
// Selected an existing item. |
- dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); |
+ dialog_ui_event = common::DialogSectionToUiSelectionChangedEvent(section); |
} else { |
// TODO(estade): add logging for "Manage items" or "Use billing for |
// shipping"? |