#include <vector>
#include "base/callback.h"
+#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/ssl_status.h"
+#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h"
+#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_rules_delegate.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/ui_base_types.h"
class AutofillDialogView;
class AutofillPopupControllerImpl;
class DataModelWrapper;
-class TestableAutofillDialogView;
namespace risk {
class Fingerprint;
// This class drives the dialog that appears when a site uses the imperative
// autocomplete API to fill out a form.
-class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
- public AutofillDialogController,
- public AutofillPopupDelegate,
- public content::NotificationObserver,
- public content::WebContentsObserver,
- public SuggestionsMenuModelDelegate,
- public wallet::WalletClientDelegate,
- public wallet::WalletSigninHelperDelegate,
- public PersonalDataManagerObserver,
- public AccountChooserModelDelegate,
- public gfx::AnimationDelegate {
+class AutofillDialogControllerImpl
+ : public AutofillDialogViewDelegate,
+ public AutofillDialogController,
+ public AutofillPopupDelegate,
+ public content::NotificationObserver,
+ public content::WebContentsObserver,
+ public SuggestionsMenuModelDelegate,
+ public wallet::WalletClientDelegate,
+ public wallet::WalletSigninHelperDelegate,
+ public PersonalDataManagerObserver,
+ public AccountChooserModelDelegate,
+ public gfx::AnimationDelegate,
+ public ::i18n::addressinput::LoadRulesDelegate {
public:
virtual ~AutofillDialogControllerImpl();
virtual void Hide() OVERRIDE;
virtual void TabActivated() OVERRIDE;
- // Returns |view_| as a testable version of itself (if |view_| exists and
- // actually implements |AutofillDialogView::GetTestableView()|).
- TestableAutofillDialogView* GetTestableView();
-
// AutofillDialogViewDelegate implementation.
virtual base::string16 DialogTitle() const OVERRIDE;
virtual base::string16 AccountChooserText() const OVERRIDE;
virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
+ // ::i18n::addressinput::LoadRulesDelegate implementation.
+ virtual void OnAddressValidationRulesLoaded(const std::string& country_code,
+ bool success) OVERRIDE;
+
protected:
enum DialogSignedInState {
NOT_CHECKED,
// Returns the PersonalDataManager for |profile_|.
virtual PersonalDataManager* GetManager() const;
+ // Returns an address validation helper. May be NULL during tests.
+ virtual ::i18n::addressinput::AddressValidator* GetValidator();
+
// Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
// for testing.
const wallet::WalletClient* GetWalletClient() const;
DialogSignedInState SignedInState() const;
private:
+ FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerI18nTest,
+ CorrectCountryFromInputs);
+
// Initializes or updates |suggested_cc_| et al.
void SuggestionsUpdated();
void FillOutputForSection(DialogSection section);
// As above, but uses |compare| to determine whether a DetailInput matches
// a field. Saves any new Autofill data to the PersonalDataManager.
- void FillOutputForSectionWithComparator(DialogSection section,
- const InputFieldComparator& compare);
+ void FillOutputForSectionWithComparator(
+ DialogSection section,
+ const FormStructure::InputFieldComparator& compare);
// Returns whether |form_structure|_| has any fields that match the fieldset
// represented by |section|.
CountryComboboxModel* CountryComboboxModelForSection(DialogSection section);
// Clears and builds the inputs in |section| for |country_name|.
+ // When |should_clobber| is false, and the view's country value matches
+ // |country_name|, the inputs won't be rebuilt.
bool RebuildInputsForCountry(DialogSection section,
const base::string16& country_name,
bool should_clobber);
// Like RequestedFieldsForSection, but returns a pointer.
DetailInputs* MutableRequestedFieldsForSection(DialogSection section);
+ // Returns just the |type| attributes of RequestedFieldsForSection(section).
+ std::vector<ServerFieldType> RequestedTypesForSection(DialogSection section)
+ const;
+
// Returns the country code (e.g. "US") for |section|.
std::string CountryCodeForSection(DialogSection section);
// messages - see AllSectionsAreValid.
bool SectionIsValid(DialogSection section);
+ // Whether validation rules for |section| are loaded.
+ bool RulesAreLoaded(DialogSection section);
+
// Whether the currently active credit card expiration date is valid.
bool IsCreditCardExpirationValid(const base::string16& year,
const base::string16& month) const;
// A client to talk to the Online Wallet API.
wallet::WalletClient wallet_client_;
+ // A helper to validate international address input.
+ scoped_ptr< ::i18n::addressinput::AddressValidator> validator_;
+
// True if |this| has ever called GetWalletItems().
bool wallet_items_requested_;
// |DialogSection|s that are in edit mode that are based on existing data.
std::set<DialogSection> section_editing_state_;
+ // Sections that need to be validated when their validation rules load.
+ std::set<DialogSection> needs_validation_;
+
// Whether |form_structure_| has asked for any details that would indicate
// we should show a shipping section.
bool cares_about_shipping_;
// A NotificationRegistrar for tracking the completion of sign-in.
content::NotificationRegistrar signin_registrar_;
- base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_;
-
// Set to true when the user presses the sign in link, until we're ready to
// show the normal dialog again. This is used to hide the buttons while
// the spinner is showing after an explicit sign in.
// A username string we display in the card scrambling/generated overlay.
base::string16 submitted_cardholder_name_;
+ base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_;
+
DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl);
};