Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / autofill / autofill_dialog_controller_impl.h
index 3f48f73..9743402 100644 (file)
@@ -9,6 +9,7 @@
 #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"
@@ -35,6 +36,8 @@
 #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"
@@ -54,7 +57,6 @@ class AutofillDataModel;
 class AutofillDialogView;
 class AutofillPopupControllerImpl;
 class DataModelWrapper;
-class TestableAutofillDialogView;
 
 namespace risk {
 class Fingerprint;
@@ -66,17 +68,19 @@ class WalletSigninHelper;
 
 // 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();
 
@@ -91,10 +95,6 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   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;
@@ -221,6 +221,10 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   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,
@@ -248,6 +252,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   // 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;
@@ -320,6 +327,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   DialogSignedInState SignedInState() const;
 
  private:
+  FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerI18nTest,
+                           CorrectCountryFromInputs);
+
   // Initializes or updates |suggested_cc_| et al.
   void SuggestionsUpdated();
 
@@ -401,8 +411,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   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|.
@@ -430,6 +441,8 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   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);
@@ -461,6 +474,10 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   // 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);
 
@@ -489,6 +506,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   // 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;
@@ -611,6 +631,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   // 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_;
 
@@ -677,6 +700,9 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   // |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_;
@@ -696,8 +722,6 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   // 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.
@@ -774,6 +798,8 @@ class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
   // 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);
 };