Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2739)

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 21124012: [WIP] Split AutofillDialogControllerImpl + integrate rAc on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 4c4d6526fd0546c348448188592a1b086e849202..2f689ee1cb938734c13efa0b523587c11c3a11b9 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -25,6 +25,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_utils.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"
@@ -111,44 +112,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,
- AutofillFieldType field_type) {
- // If any credit card expiration info is asked for, show both month and year
- // inputs.
- if (field_type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
- field_type == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
- field_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
- field_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
- field_type == CREDIT_CARD_EXP_MONTH) {
- return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
- input.type == CREDIT_CARD_EXP_MONTH;
- }
-
- if (field_type == CREDIT_CARD_TYPE)
- return input.type == CREDIT_CARD_NUMBER;
-
- return input.type == field_type;
-}
-
-// 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) {
- // The credit card name is filled from the billing section's data.
- if (field.type() == CREDIT_CARD_NAME &&
- (section == SECTION_BILLING || section == SECTION_CC_BILLING)) {
- return input.type == NAME_FULL;
- }
-
- return InputTypeMatchesFieldType(input, field.type());
-}
-
-bool IsCreditCardType(AutofillFieldType type) {
- return AutofillType(type).group() == AutofillType::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.
@@ -159,17 +122,7 @@ bool DetailInputMatchesShippingField(const DetailInput& input,
AutofillFieldType field_type =
AutofillType::GetEquivalentBillingFieldType(field.type());
- return InputTypeMatchesFieldType(input, 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 utils::InputTypeMatchesFieldType(input, field_type);
}
// Initializes |form_group| from user-entered data.
@@ -427,7 +380,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?
@@ -441,7 +393,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);
@@ -466,8 +417,30 @@ AutofillDialogControllerImpl::~AutofillDialogControllerImpl() {
}
// static
-base::WeakPtr<AutofillDialogControllerImpl>
- AutofillDialogControllerImpl::Create(
+base::WeakPtr<AutofillDialogTabManagerDelegate>
+AutofillDialogTabManagerDelegate::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 AutofillDialogTabManagerDelegate::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ AutofillDialogControllerImpl::RegisterProfilePrefs(registry);
+}
+
+// static
+base::WeakPtr<AutofillDialogTabManagerDelegate>
+AutofillDialogControllerImpl::Create(
content::WebContents* contents,
const FormData& form_structure,
const GURL& source_url,
@@ -543,70 +516,12 @@ 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 },
- { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR },
- { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC,
- 1.5 },
- };
-
- const DetailInput kBillingInputs[] = {
- { 4, NAME_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_);
+ utils::BuildInputsForSection(SECTION_EMAIL, &requested_email_fields_);
+ utils::BuildInputsForSection(SECTION_CC, &requested_cc_fields_);
+ utils::BuildInputsForSection(SECTION_BILLING, &requested_billing_fields_);
+ utils::BuildInputsForSection(SECTION_CC_BILLING,
+ &requested_cc_billing_fields_);
+ utils::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.
@@ -614,7 +529,7 @@ void AutofillDialogControllerImpl::Show() {
EmptyDataModelWrapper empty_wrapper;
cares_about_shipping_ = empty_wrapper.FillFormStructure(
inputs,
- base::Bind(DetailInputMatchesField, SECTION_SHIPPING),
+ base::Bind(utils::DetailInputMatchesField, SECTION_SHIPPING),
&form_structure_);
SuggestionsUpdated();
@@ -841,10 +756,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()) {
@@ -1745,7 +1657,7 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
}
std::vector<string16> popup_values, popup_labels, popup_icons;
- if (IsCreditCardType(input->type)) {
+ if (utils::IsCreditCardType(input->type)) {
GetManager()->GetCreditCardSuggestions(input->type,
field_contents,
&popup_values,
@@ -2047,7 +1959,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 (utils::IsCreditCardType(input_showing_popup_->type)) {
wrapper.reset(new AutofillCreditCardWrapper(
GetManager()->GetCreditCardByGUID(pair.first)));
} else {
@@ -2331,7 +2243,7 @@ bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const {
DCHECK_GT(form_structure_.field_count(), 0U);
for (size_t i = 0; i < form_structure_.field_count(); ++i) {
- if (IsCreditCardType(form_structure_.field(i)->type()))
+ if (utils::IsCreditCardType(form_structure_.field(i)->type()))
return true;
}
@@ -2385,7 +2297,12 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl(
}
AutofillDialogView* AutofillDialogControllerImpl::CreateView() {
+#if defined(TOOLKIT_VIEWS)
aruslan 2013/07/31 02:43:19 This should be #if defined(ENABLE_AUTOFILL_DIALOG)
aruslan 2013/08/01 19:30:29 Actually, #if should be removed entirely.
aruslan 2013/08/07 23:17:03 Done.
aruslan 2013/08/07 23:17:03 Done: removed entirely.
return AutofillDialogView::Create(this);
+#else
+ NOTIMPLEMENTED();
+ return NULL;
+#endif // defined(TOOLKIT_VIEWS)
}
PersonalDataManager* AutofillDialogControllerImpl::GetManager() {
@@ -2409,13 +2326,8 @@ void AutofillDialogControllerImpl::LoadRiskFingerprintData() {
&obfuscated_gaia_id);
DCHECK(success);
- gfx::Rect window_bounds;
-#if !defined(OS_ANDROID)
- window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds();
-#else
- // TODO(dbeam): figure out the correct browser window size to pass along for
- // android.
-#endif
+ gfx::Rect window_bounds =
+ GetBaseWindowForWebContents(web_contents())->GetBounds();
PrefService* user_prefs = profile_->GetPrefs();
std::string charset = user_prefs->GetString(::prefs::kDefaultCharset);
@@ -2445,16 +2357,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(&params);
-#else
- // TODO(estade): use TabModelList?
-#endif
}
bool AutofillDialogControllerImpl::IsEditingExistingData(
@@ -2608,7 +2516,7 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() {
const std::string app_locale = g_browser_process->GetApplicationLocale();
for (size_t i = 0; i < profiles.size(); ++i) {
if (!HasCompleteAndVerifiedData(*profiles[i],
- requested_shipping_fields_) ||
+ requested_shipping_fields_) ||
aruslan 2013/07/31 02:43:19 indent.
aruslan 2013/08/07 23:17:03 Done.
HasInvalidAddress(*profiles[i])) {
continue;
}
@@ -2780,7 +2688,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) {
FillOutputForSectionWithComparator(
- section, base::Bind(DetailInputMatchesField, section));
+ section, base::Bind(utils::DetailInputMatchesField, section));
}
bool AutofillDialogControllerImpl::FormStructureCaresAboutSection(

Powered by Google App Engine
This is Rietveld 408576698