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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.h

Issue 145553009: rAc: use libaddressinput to validate international addresses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win compile? Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_ 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_ 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "chrome/browser/ui/autofill/account_chooser_model.h" 17 #include "chrome/browser/ui/autofill/account_chooser_model.h"
17 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" 18 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
18 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 19 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
19 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" 20 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
20 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" 21 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
21 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 22 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
22 #include "chrome/browser/ui/autofill/country_combobox_model.h" 23 #include "chrome/browser/ui/autofill/country_combobox_model.h"
23 #include "components/autofill/content/browser/wallet/wallet_client.h" 24 #include "components/autofill/content/browser/wallet/wallet_client.h"
24 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" 25 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h"
25 #include "components/autofill/content/browser/wallet/wallet_items.h" 26 #include "components/autofill/content/browser/wallet/wallet_items.h"
26 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega te.h" 27 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega te.h"
27 #include "components/autofill/core/browser/autofill_manager_delegate.h" 28 #include "components/autofill/core/browser/autofill_manager_delegate.h"
28 #include "components/autofill/core/browser/autofill_metrics.h" 29 #include "components/autofill/core/browser/autofill_metrics.h"
29 #include "components/autofill/core/browser/autofill_popup_delegate.h" 30 #include "components/autofill/core/browser/autofill_popup_delegate.h"
30 #include "components/autofill/core/browser/field_types.h" 31 #include "components/autofill/core/browser/field_types.h"
31 #include "components/autofill/core/browser/form_structure.h" 32 #include "components/autofill/core/browser/form_structure.h"
32 #include "components/autofill/core/browser/personal_data_manager.h" 33 #include "components/autofill/core/browser/personal_data_manager.h"
33 #include "components/autofill/core/browser/personal_data_manager_observer.h" 34 #include "components/autofill/core/browser/personal_data_manager_observer.h"
34 #include "content/public/browser/notification_observer.h" 35 #include "content/public/browser/notification_observer.h"
35 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
36 #include "content/public/browser/web_contents_observer.h" 37 #include "content/public/browser/web_contents_observer.h"
37 #include "content/public/common/ssl_status.h" 38 #include "content/public/common/ssl_status.h"
39 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_validator.h"
40 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_ rules_delegate.h"
38 #include "third_party/skia/include/core/SkColor.h" 41 #include "third_party/skia/include/core/SkColor.h"
39 #include "ui/base/models/simple_menu_model.h" 42 #include "ui/base/models/simple_menu_model.h"
40 #include "ui/base/ui_base_types.h" 43 #include "ui/base/ui_base_types.h"
41 #include "ui/gfx/animation/animation_delegate.h" 44 #include "ui/gfx/animation/animation_delegate.h"
42 #include "ui/gfx/animation/linear_animation.h" 45 #include "ui/gfx/animation/linear_animation.h"
43 #include "url/gurl.h" 46 #include "url/gurl.h"
44 47
45 class Profile; 48 class Profile;
46 49
47 namespace content { 50 namespace content {
(...skipping 10 matching lines...) Expand all
58 namespace risk { 61 namespace risk {
59 class Fingerprint; 62 class Fingerprint;
60 } 63 }
61 64
62 namespace wallet { 65 namespace wallet {
63 class WalletSigninHelper; 66 class WalletSigninHelper;
64 } 67 }
65 68
66 // This class drives the dialog that appears when a site uses the imperative 69 // This class drives the dialog that appears when a site uses the imperative
67 // autocomplete API to fill out a form. 70 // autocomplete API to fill out a form.
68 class AutofillDialogControllerImpl : public AutofillDialogViewDelegate, 71 class AutofillDialogControllerImpl
69 public AutofillDialogController, 72 : public AutofillDialogViewDelegate,
70 public AutofillPopupDelegate, 73 public AutofillDialogController,
71 public content::NotificationObserver, 74 public AutofillPopupDelegate,
72 public content::WebContentsObserver, 75 public content::NotificationObserver,
73 public SuggestionsMenuModelDelegate, 76 public content::WebContentsObserver,
74 public wallet::WalletClientDelegate, 77 public SuggestionsMenuModelDelegate,
75 public wallet::WalletSigninHelperDelegate, 78 public wallet::WalletClientDelegate,
76 public PersonalDataManagerObserver, 79 public wallet::WalletSigninHelperDelegate,
77 public AccountChooserModelDelegate, 80 public PersonalDataManagerObserver,
78 public gfx::AnimationDelegate { 81 public AccountChooserModelDelegate,
82 public gfx::AnimationDelegate,
83 public ::i18n::addressinput::LoadRulesDelegate {
79 public: 84 public:
80 virtual ~AutofillDialogControllerImpl(); 85 virtual ~AutofillDialogControllerImpl();
81 86
82 static base::WeakPtr<AutofillDialogControllerImpl> Create( 87 static base::WeakPtr<AutofillDialogControllerImpl> Create(
83 content::WebContents* contents, 88 content::WebContents* contents,
84 const FormData& form_structure, 89 const FormData& form_structure,
85 const GURL& source_url, 90 const GURL& source_url,
86 const base::Callback<void(const FormStructure*)>& callback); 91 const base::Callback<void(const FormStructure*)>& callback);
87 92
88 // AutofillDialogController implementation. 93 // AutofillDialogController implementation.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 virtual void OnPassiveSigninSuccess() OVERRIDE; 214 virtual void OnPassiveSigninSuccess() OVERRIDE;
210 virtual void OnPassiveSigninFailure( 215 virtual void OnPassiveSigninFailure(
211 const GoogleServiceAuthError& error) OVERRIDE; 216 const GoogleServiceAuthError& error) OVERRIDE;
212 virtual void OnDidFetchWalletCookieValue( 217 virtual void OnDidFetchWalletCookieValue(
213 const std::string& cookie_value) OVERRIDE; 218 const std::string& cookie_value) OVERRIDE;
214 219
215 // gfx::AnimationDelegate implementation. 220 // gfx::AnimationDelegate implementation.
216 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 221 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
217 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 222 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
218 223
224 // ::i18n::addressinput::LoadRulesDelegate implementation.
225 virtual void OnAddressValidationRulesLoaded(const std::string& country_code,
226 bool success) OVERRIDE;
227
219 protected: 228 protected:
220 enum DialogSignedInState { 229 enum DialogSignedInState {
221 NOT_CHECKED, 230 NOT_CHECKED,
222 REQUIRES_RESPONSE, 231 REQUIRES_RESPONSE,
223 REQUIRES_SIGN_IN, 232 REQUIRES_SIGN_IN,
224 REQUIRES_PASSIVE_SIGN_IN, 233 REQUIRES_PASSIVE_SIGN_IN,
225 SIGNED_IN, 234 SIGNED_IN,
226 SIGN_IN_DISABLED, 235 SIGN_IN_DISABLED,
227 }; 236 };
228 237
229 // Exposed for testing. 238 // Exposed for testing.
230 AutofillDialogControllerImpl( 239 AutofillDialogControllerImpl(
231 content::WebContents* contents, 240 content::WebContents* contents,
232 const FormData& form_structure, 241 const FormData& form_structure,
233 const GURL& source_url, 242 const GURL& source_url,
234 const base::Callback<void(const FormStructure*)>& callback); 243 const base::Callback<void(const FormStructure*)>& callback);
235 244
236 // Exposed for testing. 245 // Exposed for testing.
237 AutofillDialogView* view() { return view_.get(); } 246 AutofillDialogView* view() { return view_.get(); }
238 virtual AutofillDialogView* CreateView(); 247 virtual AutofillDialogView* CreateView();
239 ServerFieldType popup_input_type() const { 248 ServerFieldType popup_input_type() const {
240 return popup_input_type_; 249 return popup_input_type_;
241 } 250 }
242 251
252 // Extract |type| from |inputs| using |section| to determine whether the info
253 // should be billing or shipping specific (for sections with address info).
254 static base::string16 GetInfoFromInputs(const FieldValueMap& inputs,
255 DialogSection section,
256 const AutofillType& type);
257
243 // Returns the PersonalDataManager for |profile_|. 258 // Returns the PersonalDataManager for |profile_|.
244 virtual PersonalDataManager* GetManager() const; 259 virtual PersonalDataManager* GetManager() const;
245 260
246 // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed 261 // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
247 // for testing. 262 // for testing.
248 const wallet::WalletClient* GetWalletClient() const; 263 const wallet::WalletClient* GetWalletClient() const;
249 virtual wallet::WalletClient* GetWalletClient(); 264 virtual wallet::WalletClient* GetWalletClient();
250 265
266 // Returns an address validation helper. May be NULL during tests.
267 virtual ::i18n::addressinput::AddressValidator* GetValidator();
268
251 // Call to disable communication to Online Wallet for this dialog. 269 // Call to disable communication to Online Wallet for this dialog.
252 // Exposed for testing. 270 // Exposed for testing.
253 void DisableWallet(wallet::WalletClient::ErrorType error_type); 271 void DisableWallet(wallet::WalletClient::ErrorType error_type);
254 272
255 // Returns whether Wallet is the current data source. Exposed for testing. 273 // Returns whether Wallet is the current data source. Exposed for testing.
256 virtual bool IsPayingWithWallet() const; 274 virtual bool IsPayingWithWallet() const;
257 275
258 // Asks risk module to asynchronously load fingerprint data. Data will be 276 // Asks risk module to asynchronously load fingerprint data. Data will be
259 // returned via |OnDidLoadRiskFingerprintData()|. Exposed for testing. 277 // returned via |OnDidLoadRiskFingerprintData()|. Exposed for testing.
260 virtual void LoadRiskFingerprintData(); 278 virtual void LoadRiskFingerprintData();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 AccountChooserModel* AccountChooserModelForTesting(); 326 AccountChooserModel* AccountChooserModelForTesting();
309 327
310 // Returns whether |url| matches the sign in continue URL. If so, also fills 328 // Returns whether |url| matches the sign in continue URL. If so, also fills
311 // in |user_index| with the index of the user account that just signed in. 329 // in |user_index| with the index of the user account that just signed in.
312 virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const; 330 virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const;
313 331
314 // Whether the user is known to be signed in. 332 // Whether the user is known to be signed in.
315 DialogSignedInState SignedInState() const; 333 DialogSignedInState SignedInState() const;
316 334
317 private: 335 private:
336 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerI18nTest,
337 CorrectCountryFromInputs);
338
318 // Initializes or updates |suggested_cc_| et al. 339 // Initializes or updates |suggested_cc_| et al.
319 void SuggestionsUpdated(); 340 void SuggestionsUpdated();
320 341
321 // Starts fetching the wallet items from Online Wallet. 342 // Starts fetching the wallet items from Online Wallet.
322 void GetWalletItems(); 343 void GetWalletItems();
323 344
324 // Stop showing sign in flow. 345 // Stop showing sign in flow.
325 void HideSignIn(); 346 void HideSignIn();
326 347
327 // Handles the SignedInState() on Wallet or sign-in state update. 348 // Handles the SignedInState() on Wallet or sign-in state update.
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 base::WeakPtr<AutofillPopupControllerImpl> popup_controller_; 710 base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
690 711
691 // The type of the visible Autofill popup input (or UNKNOWN_TYPE if none). 712 // The type of the visible Autofill popup input (or UNKNOWN_TYPE if none).
692 ServerFieldType popup_input_type_; 713 ServerFieldType popup_input_type_;
693 714
694 scoped_ptr<AutofillDialogView> view_; 715 scoped_ptr<AutofillDialogView> view_;
695 716
696 // A NotificationRegistrar for tracking the completion of sign-in. 717 // A NotificationRegistrar for tracking the completion of sign-in.
697 content::NotificationRegistrar signin_registrar_; 718 content::NotificationRegistrar signin_registrar_;
698 719
699 base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_;
700
701 // Set to true when the user presses the sign in link, until we're ready to 720 // Set to true when the user presses the sign in link, until we're ready to
702 // show the normal dialog again. This is used to hide the buttons while 721 // show the normal dialog again. This is used to hide the buttons while
703 // the spinner is showing after an explicit sign in. 722 // the spinner is showing after an explicit sign in.
704 bool waiting_for_explicit_sign_in_response_; 723 bool waiting_for_explicit_sign_in_response_;
705 724
706 // Whether a user accepted legal documents while this dialog is running. 725 // Whether a user accepted legal documents while this dialog is running.
707 bool has_accepted_legal_documents_; 726 bool has_accepted_legal_documents_;
708 727
709 // True after the user first accepts the dialog and presses "Submit". May 728 // True after the user first accepts the dialog and presses "Submit". May
710 // continue to be true while processing required actions. 729 // continue to be true while processing required actions.
711 bool is_submitting_; 730 bool is_submitting_;
712 731
732 // A helper to validate international address input.
733 scoped_ptr< ::i18n::addressinput::AddressValidator> validator_;
734
713 // True if the last call to |GetFullWallet()| returned a 735 // True if the last call to |GetFullWallet()| returned a
714 // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the 736 // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the
715 // selected instrument or address had become invalid since it was originally 737 // selected instrument or address had become invalid since it was originally
716 // returned in |GetWalletItems()|. 738 // returned in |GetWalletItems()|.
717 bool choose_another_instrument_or_address_; 739 bool choose_another_instrument_or_address_;
718 740
719 // Whether or not the server side validation errors returned by Wallet were 741 // Whether or not the server side validation errors returned by Wallet were
720 // recoverable. 742 // recoverable.
721 bool wallet_server_validation_recoverable_; 743 bool wallet_server_validation_recoverable_;
722 744
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 base::OneShotTimer<AutofillDialogControllerImpl> card_scrambling_delay_; 789 base::OneShotTimer<AutofillDialogControllerImpl> card_scrambling_delay_;
768 base::RepeatingTimer<AutofillDialogControllerImpl> card_scrambling_refresher_; 790 base::RepeatingTimer<AutofillDialogControllerImpl> card_scrambling_refresher_;
769 791
770 // An animation which controls the background fade when the card is done 792 // An animation which controls the background fade when the card is done
771 // scrambling. 793 // scrambling.
772 gfx::LinearAnimation card_generated_animation_; 794 gfx::LinearAnimation card_generated_animation_;
773 795
774 // A username string we display in the card scrambling/generated overlay. 796 // A username string we display in the card scrambling/generated overlay.
775 base::string16 submitted_cardholder_name_; 797 base::string16 submitted_cardholder_name_;
776 798
799 base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_;
800
777 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl); 801 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl);
778 }; 802 };
779 803
780 } // namespace autofill 804 } // namespace autofill
781 805
782 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_ 806 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698