OLD | NEW |
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 Loading... |
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 Loading... |
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 |
243 // Returns the PersonalDataManager for |profile_|. | 252 // Returns the PersonalDataManager for |profile_|. |
244 virtual PersonalDataManager* GetManager() const; | 253 virtual PersonalDataManager* GetManager() const; |
245 | 254 |
| 255 // Returns an address validation helper. May be NULL during tests. |
| 256 virtual ::i18n::addressinput::AddressValidator* GetValidator(); |
| 257 |
246 // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed | 258 // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed |
247 // for testing. | 259 // for testing. |
248 const wallet::WalletClient* GetWalletClient() const; | 260 const wallet::WalletClient* GetWalletClient() const; |
249 virtual wallet::WalletClient* GetWalletClient(); | 261 virtual wallet::WalletClient* GetWalletClient(); |
250 | 262 |
251 // Call to disable communication to Online Wallet for this dialog. | 263 // Call to disable communication to Online Wallet for this dialog. |
252 // Exposed for testing. | 264 // Exposed for testing. |
253 void DisableWallet(wallet::WalletClient::ErrorType error_type); | 265 void DisableWallet(wallet::WalletClient::ErrorType error_type); |
254 | 266 |
255 // Returns whether Wallet is the current data source. Exposed for testing. | 267 // Returns whether Wallet is the current data source. Exposed for testing. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 AccountChooserModel* AccountChooserModelForTesting(); | 320 AccountChooserModel* AccountChooserModelForTesting(); |
309 | 321 |
310 // Returns whether |url| matches the sign in continue URL. If so, also fills | 322 // 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. | 323 // 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; | 324 virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const; |
313 | 325 |
314 // Whether the user is known to be signed in. | 326 // Whether the user is known to be signed in. |
315 DialogSignedInState SignedInState() const; | 327 DialogSignedInState SignedInState() const; |
316 | 328 |
317 private: | 329 private: |
| 330 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerI18nTest, |
| 331 CorrectCountryFromInputs); |
| 332 |
318 // Initializes or updates |suggested_cc_| et al. | 333 // Initializes or updates |suggested_cc_| et al. |
319 void SuggestionsUpdated(); | 334 void SuggestionsUpdated(); |
320 | 335 |
321 // Starts fetching the wallet items from Online Wallet. | 336 // Starts fetching the wallet items from Online Wallet. |
322 void GetWalletItems(); | 337 void GetWalletItems(); |
323 | 338 |
324 // Stop showing sign in flow. | 339 // Stop showing sign in flow. |
325 void HideSignIn(); | 340 void HideSignIn(); |
326 | 341 |
327 // Handles the SignedInState() on Wallet or sign-in state update. | 342 // Handles the SignedInState() on Wallet or sign-in state update. |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 // and also tracks which data source the dialog is using. | 619 // and also tracks which data source the dialog is using. |
605 scoped_ptr<AccountChooserModel> account_chooser_model_; | 620 scoped_ptr<AccountChooserModel> account_chooser_model_; |
606 | 621 |
607 // The sign-in helper to fetch the user's Wallet cookie and to perform passive | 622 // The sign-in helper to fetch the user's Wallet cookie and to perform passive |
608 // sign-in. The helper is set only during fetch/sign-in, and NULL otherwise. | 623 // sign-in. The helper is set only during fetch/sign-in, and NULL otherwise. |
609 scoped_ptr<wallet::WalletSigninHelper> signin_helper_; | 624 scoped_ptr<wallet::WalletSigninHelper> signin_helper_; |
610 | 625 |
611 // A client to talk to the Online Wallet API. | 626 // A client to talk to the Online Wallet API. |
612 wallet::WalletClient wallet_client_; | 627 wallet::WalletClient wallet_client_; |
613 | 628 |
| 629 // A helper to validate international address input. |
| 630 scoped_ptr< ::i18n::addressinput::AddressValidator> validator_; |
| 631 |
614 // True if |this| has ever called GetWalletItems(). | 632 // True if |this| has ever called GetWalletItems(). |
615 bool wallet_items_requested_; | 633 bool wallet_items_requested_; |
616 | 634 |
617 // True when the user has clicked the "Use Wallet" link and we're waiting to | 635 // True when the user has clicked the "Use Wallet" link and we're waiting to |
618 // figure out whether we need to ask them to actively sign in. | 636 // figure out whether we need to ask them to actively sign in. |
619 bool handling_use_wallet_link_click_; | 637 bool handling_use_wallet_link_click_; |
620 | 638 |
621 // True when the current WalletItems has a passive auth action which was | 639 // True when the current WalletItems has a passive auth action which was |
622 // attempted and failed. | 640 // attempted and failed. |
623 bool passive_failed_; | 641 bool passive_failed_; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 base::WeakPtr<AutofillPopupControllerImpl> popup_controller_; | 707 base::WeakPtr<AutofillPopupControllerImpl> popup_controller_; |
690 | 708 |
691 // The type of the visible Autofill popup input (or UNKNOWN_TYPE if none). | 709 // The type of the visible Autofill popup input (or UNKNOWN_TYPE if none). |
692 ServerFieldType popup_input_type_; | 710 ServerFieldType popup_input_type_; |
693 | 711 |
694 scoped_ptr<AutofillDialogView> view_; | 712 scoped_ptr<AutofillDialogView> view_; |
695 | 713 |
696 // A NotificationRegistrar for tracking the completion of sign-in. | 714 // A NotificationRegistrar for tracking the completion of sign-in. |
697 content::NotificationRegistrar signin_registrar_; | 715 content::NotificationRegistrar signin_registrar_; |
698 | 716 |
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 | 717 // 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 | 718 // show the normal dialog again. This is used to hide the buttons while |
703 // the spinner is showing after an explicit sign in. | 719 // the spinner is showing after an explicit sign in. |
704 bool waiting_for_explicit_sign_in_response_; | 720 bool waiting_for_explicit_sign_in_response_; |
705 | 721 |
706 // Whether a user accepted legal documents while this dialog is running. | 722 // Whether a user accepted legal documents while this dialog is running. |
707 bool has_accepted_legal_documents_; | 723 bool has_accepted_legal_documents_; |
708 | 724 |
709 // True after the user first accepts the dialog and presses "Submit". May | 725 // True after the user first accepts the dialog and presses "Submit". May |
710 // continue to be true while processing required actions. | 726 // continue to be true while processing required actions. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 base::OneShotTimer<AutofillDialogControllerImpl> card_scrambling_delay_; | 783 base::OneShotTimer<AutofillDialogControllerImpl> card_scrambling_delay_; |
768 base::RepeatingTimer<AutofillDialogControllerImpl> card_scrambling_refresher_; | 784 base::RepeatingTimer<AutofillDialogControllerImpl> card_scrambling_refresher_; |
769 | 785 |
770 // An animation which controls the background fade when the card is done | 786 // An animation which controls the background fade when the card is done |
771 // scrambling. | 787 // scrambling. |
772 gfx::LinearAnimation card_generated_animation_; | 788 gfx::LinearAnimation card_generated_animation_; |
773 | 789 |
774 // A username string we display in the card scrambling/generated overlay. | 790 // A username string we display in the card scrambling/generated overlay. |
775 base::string16 submitted_cardholder_name_; | 791 base::string16 submitted_cardholder_name_; |
776 | 792 |
| 793 base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_; |
| 794 |
777 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl); | 795 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl); |
778 }; | 796 }; |
779 | 797 |
780 } // namespace autofill | 798 } // namespace autofill |
781 | 799 |
782 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_ | 800 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_ |
OLD | NEW |