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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "base/time/time.h"
16 #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_models.h"
19 #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_popup_controller_impl.h"
22 #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_delegate.h"
25 #include "components/autofill/content/browser/wallet/wallet_items.h"
26 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h"
27 #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_popup_delegate.h"
30 #include "components/autofill/core/browser/field_types.h"
31 #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_observer.h"
34 #include "content/public/browser/notification_observer.h"
35 #include "content/public/browser/notification_registrar.h"
36 #include "content/public/browser/web_contents_observer.h"
37 #include "content/public/common/ssl_status.h"
38 #include "ui/base/models/simple_menu_model.h"
39 #include "ui/base/ui_base_types.h"
40 #include "ui/gfx/animation/animation_delegate.h"
41 #include "ui/gfx/animation/linear_animation.h"
52 class AutofillDataModel;
53 class AutofillDialogView;
54 class AutofillPopupControllerImpl;
55 class DataModelWrapper;
56 class TestableAutofillDialogView;
63 class WalletSigninHelper;
66 // This class drives the dialog that appears when a site uses the imperative
67 // autocomplete API to fill out a form.
68 class AutofillDialogControllerImpl : public AutofillDialogViewDelegate,
69 public AutofillDialogController,
70 public AutofillPopupDelegate,
71 public content::NotificationObserver,
72 public content::WebContentsObserver,
73 public SuggestionsMenuModelDelegate,
74 public wallet::WalletClientDelegate,
75 public wallet::WalletSigninHelperDelegate,
76 public PersonalDataManagerObserver,
77 public AccountChooserModelDelegate,
78 public gfx::AnimationDelegate {
80 virtual ~AutofillDialogControllerImpl();
82 static base::WeakPtr<AutofillDialogControllerImpl> Create(
83 content::WebContents* contents,
84 const FormData& form_structure,
85 const GURL& source_url,
86 const base::Callback<void(const FormStructure*)>& callback);
88 // AutofillDialogController implementation.
89 virtual void Show() OVERRIDE;
90 virtual void Hide() OVERRIDE;
91 virtual void TabActivated() OVERRIDE;
93 // Returns |view_| as a testable version of itself (if |view_| exists and
94 // actually implements |AutofillDialogView::GetTestableView()|).
95 TestableAutofillDialogView* GetTestableView();
97 // AutofillDialogViewDelegate implementation.
98 virtual string16 DialogTitle() const OVERRIDE;
99 virtual string16 AccountChooserText() const OVERRIDE;
100 virtual string16 SignInLinkText() const OVERRIDE;
101 virtual string16 SpinnerText() const OVERRIDE;
102 virtual string16 EditSuggestionText() const OVERRIDE;
103 virtual string16 CancelButtonText() const OVERRIDE;
104 virtual string16 ConfirmButtonText() const OVERRIDE;
105 virtual string16 SaveLocallyText() const OVERRIDE;
106 virtual string16 SaveLocallyTooltip() const OVERRIDE;
107 virtual string16 LegalDocumentsText() OVERRIDE;
108 virtual bool ShouldDisableSignInLink() const OVERRIDE;
109 virtual bool ShouldShowSpinner() const OVERRIDE;
110 virtual bool ShouldShowSignInWebView() const OVERRIDE;
111 virtual GURL SignInUrl() const OVERRIDE;
112 virtual bool ShouldOfferToSaveInChrome() const OVERRIDE;
113 virtual bool ShouldSaveInChrome() const OVERRIDE;
114 virtual ui::MenuModel* MenuModelForAccountChooser() OVERRIDE;
115 virtual gfx::Image AccountChooserImage() OVERRIDE;
116 virtual gfx::Image ButtonStripImage() const OVERRIDE;
117 virtual int GetDialogButtons() const OVERRIDE;
118 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
119 virtual DialogOverlayState GetDialogOverlay() OVERRIDE;
120 virtual const std::vector<gfx::Range>& LegalDocumentLinks() OVERRIDE;
121 virtual bool SectionIsActive(DialogSection section) const OVERRIDE;
122 virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
124 virtual ui::ComboboxModel* ComboboxModelForAutofillType(
125 ServerFieldType type) OVERRIDE;
126 virtual ui::MenuModel* MenuModelForSection(DialogSection section) OVERRIDE;
127 virtual string16 LabelForSection(DialogSection section) const OVERRIDE;
128 virtual SuggestionState SuggestionStateForSection(
129 DialogSection section) OVERRIDE;
130 virtual FieldIconMap IconsForFields(const FieldValueMap& user_inputs)
132 virtual bool FieldControlsIcons(ServerFieldType type) const OVERRIDE;
133 virtual string16 TooltipForField(ServerFieldType type) const OVERRIDE;
134 virtual bool InputIsEditable(const DetailInput& input, DialogSection section)
136 virtual string16 InputValidityMessage(DialogSection section,
137 ServerFieldType type,
138 const string16& value) OVERRIDE;
139 virtual ValidityMessages InputsAreValid(
140 DialogSection section, const DetailOutputMap& inputs) OVERRIDE;
141 virtual void UserEditedOrActivatedInput(DialogSection section,
142 const DetailInput* input,
143 gfx::NativeView parent_view,
144 const gfx::Rect& content_bounds,
145 const string16& field_contents,
146 bool was_edit) OVERRIDE;
147 virtual bool HandleKeyPressEventInInput(
148 const content::NativeWebKeyboardEvent& event) OVERRIDE;
149 virtual void FocusMoved() OVERRIDE;
150 virtual bool ShouldShowErrorBubble() const OVERRIDE;
151 virtual void ViewClosed() OVERRIDE;
152 virtual std::vector<DialogNotification> CurrentNotifications() OVERRIDE;
153 virtual void LinkClicked(const GURL& url) OVERRIDE;
154 virtual void SignInLinkClicked() OVERRIDE;
155 virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
156 bool checked) OVERRIDE;
157 virtual void LegalDocumentLinkClicked(const gfx::Range& range) OVERRIDE;
158 virtual bool OnCancel() OVERRIDE;
159 virtual bool OnAccept() OVERRIDE;
160 virtual Profile* profile() OVERRIDE;
161 virtual content::WebContents* GetWebContents() OVERRIDE;
163 // AutofillPopupDelegate implementation.
164 virtual void OnPopupShown() OVERRIDE;
165 virtual void OnPopupHidden() OVERRIDE;
166 virtual bool ShouldRepostEvent(const ui::MouseEvent& event) OVERRIDE;
167 virtual void DidSelectSuggestion(int identifier) OVERRIDE;
168 virtual void DidAcceptSuggestion(const string16& value,
169 int identifier) OVERRIDE;
170 virtual void RemoveSuggestion(const string16& value,
171 int identifier) OVERRIDE;
172 virtual void ClearPreviewedForm() OVERRIDE;
174 // content::NotificationObserver implementation.
175 virtual void Observe(int type,
176 const content::NotificationSource& source,
177 const content::NotificationDetails& details) OVERRIDE;
179 // SuggestionsMenuModelDelegate implementation.
180 virtual void SuggestionsMenuWillShow() OVERRIDE;
181 virtual void SuggestionItemSelected(SuggestionsMenuModel* model,
182 size_t index) OVERRIDE;
184 // wallet::WalletClientDelegate implementation.
185 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE;
186 virtual std::string GetRiskData() const OVERRIDE;
187 virtual std::string GetWalletCookieValue() const OVERRIDE;
188 virtual bool IsShippingAddressRequired() const OVERRIDE;
189 virtual void OnDidAcceptLegalDocuments() OVERRIDE;
190 virtual void OnDidAuthenticateInstrument(bool success) OVERRIDE;
191 virtual void OnDidGetFullWallet(
192 scoped_ptr<wallet::FullWallet> full_wallet) OVERRIDE;
193 virtual void OnDidGetWalletItems(
194 scoped_ptr<wallet::WalletItems> wallet_items) OVERRIDE;
195 virtual void OnDidSaveToWallet(
196 const std::string& instrument_id,
197 const std::string& address_id,
198 const std::vector<wallet::RequiredAction>& required_actions,
199 const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE;
200 virtual void OnWalletError(
201 wallet::WalletClient::ErrorType error_type) OVERRIDE;
203 // PersonalDataManagerObserver implementation.
204 virtual void OnPersonalDataChanged() OVERRIDE;
206 // AccountChooserModelDelegate implementation.
207 virtual void AccountChooserWillShow() OVERRIDE;
208 virtual void AccountChoiceChanged() OVERRIDE;
209 virtual void UpdateAccountChooserView() OVERRIDE;
211 // wallet::WalletSigninHelperDelegate implementation.
212 virtual void OnPassiveSigninSuccess(const std::vector<std::string>& username)
214 virtual void OnPassiveSigninFailure(
215 const GoogleServiceAuthError& error) OVERRIDE;
216 virtual void OnUserNameFetchSuccess(const std::vector<std::string>& username)
218 virtual void OnUserNameFetchFailure(
219 const GoogleServiceAuthError& error) OVERRIDE;
220 virtual void OnDidFetchWalletCookieValue(
221 const std::string& cookie_value) OVERRIDE;
223 // gfx::AnimationDelegate implementation.
224 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
225 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
228 enum DialogSignedInState {
232 REQUIRES_PASSIVE_SIGN_IN,
237 // Exposed for testing.
238 AutofillDialogControllerImpl(
239 content::WebContents* contents,
240 const FormData& form_structure,
241 const GURL& source_url,
242 const base::Callback<void(const FormStructure*)>& callback);
244 // Exposed for testing.
245 AutofillDialogView* view() { return view_.get(); }
246 virtual AutofillDialogView* CreateView();
247 const DetailInput* input_showing_popup() const {
248 return input_showing_popup_;
251 // Returns the PersonalDataManager for |profile_|.
252 virtual PersonalDataManager* GetManager();
254 // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
256 virtual wallet::WalletClient* GetWalletClient();
258 // Call to disable communication to Online Wallet for this dialog.
259 // Exposed for testing.
260 void DisableWallet(wallet::WalletClient::ErrorType error_type);
262 // Returns whether Wallet is the current data source. Exposed for testing.
263 virtual bool IsPayingWithWallet() const;
265 // Asks risk module to asynchronously load fingerprint data. Data will be
266 // returned via |OnDidLoadRiskFingerprintData()|. Exposed for testing.
267 virtual void LoadRiskFingerprintData();
268 virtual void OnDidLoadRiskFingerprintData(
269 scoped_ptr<risk::Fingerprint> fingerprint);
271 // Opens the given URL in a new foreground tab.
272 virtual void OpenTabWithUrl(const GURL& url);
274 // Whether |section| was sent into edit mode based on existing data. This
275 // happens when a user clicks "Edit" or a suggestion is invalid.
276 virtual bool IsEditingExistingData(DialogSection section) const;
278 // Whether the user has chosen to enter all new data in |section|. This
279 // happens via choosing "Add a new X..." from a section's suggestion menu.
280 bool IsManuallyEditingSection(DialogSection section) const;
282 // Should be called on the Wallet sign-in error.
283 virtual void OnWalletSigninError();
285 // Whether the information input in this dialog will be securely transmitted
286 // to the requesting site.
287 virtual bool TransmissionWillBeSecure() const;
289 // Whether submission is currently waiting for |action| to be handled.
290 bool IsSubmitPausedOn(wallet::RequiredAction action) const;
292 // Shows a new credit card saved bubble and passes ownership of |new_card| and
293 // |billing_profile| to the bubble. Exposed for testing.
294 virtual void ShowNewCreditCardBubble(
295 scoped_ptr<CreditCard> new_card,
296 scoped_ptr<AutofillProfile> billing_profile);
298 // Called when there's nothing left to accept, update, save, or authenticate
299 // in order to fill |form_structure_| and pass data back to the invoking page.
300 void DoFinishSubmit();
302 // Delays enabling submit button for a short period of time. Exposed for
304 virtual void SubmitButtonDelayBegin();
306 // Ends the delay for enabling the submit button. Called only from tests.
307 // Without this method, the tests would have to wait for the delay timer to
308 // finish, which would be flaky.
309 void SubmitButtonDelayEndForTesting();
311 // Resets |last_wallet_items_fetch_timestamp_| for testing.
312 void ClearLastWalletItemsFetchTimestampForTesting();
314 // Allows tests to inspect the state of the account chooser.
315 const AccountChooserModel& AccountChooserModelForTesting() const;
317 // Returns whether |url| matches the sign in continue URL.
318 virtual bool IsSignInContinueUrl(const GURL& url) const;
320 // Whether the user is known to be signed in.
321 DialogSignedInState SignedInState() const;
324 // Whether or not the current request wants credit info back.
325 bool RequestingCreditCardInfo() const;
327 // Initializes or updates |suggested_cc_| et al.
328 void SuggestionsUpdated();
330 // Starts fetching the wallet items from Online Wallet.
331 void GetWalletItems();
333 // Stop showing sign in flow.
336 // Handles the SignedInState() on Wallet or sign-in state update.
337 // Triggers the user name fetch and passive sign-in.
338 void SignedInStateUpdated();
340 // Refreshes the model on Wallet or sign-in state update.
341 void OnWalletOrSigninUpdate();
343 // Called when a Save or Update call to Wallet has validation errors.
344 void OnWalletFormFieldError(
345 const std::vector<wallet::FormFieldError>& form_field_errors);
347 // Calculates |legal_documents_text_| and |legal_document_link_ranges_|.
348 void ConstructLegalDocumentsText();
350 // Clears previously entered manual input and removes |section| from
351 // |section_editing_state_|. Does not update the view.
352 void ResetSectionInput(DialogSection section);
354 // Force |section| into edit mode if the current suggestion is invalid.
355 void ShowEditUiIfBadSuggestion(DialogSection section);
357 // Whether the |value| of |input| should be preserved on account change.
358 bool InputWasEdited(ServerFieldType type,
359 const base::string16& value);
361 // Takes a snapshot of the newly inputted user data in |view_| (if it exists).
362 DetailOutputMap TakeUserInputSnapshot();
364 // Fills the detail inputs from a previously taken user input snapshot. Does
365 // not update the view.
366 void RestoreUserInputFromSnapshot(const DetailOutputMap& snapshot);
368 // Tells the view to update |section|.
369 void UpdateSection(DialogSection section);
371 // Tells |view_| to update the validity status of its detail inputs (if
372 // |view_| is non-null). Currently this is used solely for highlighting
373 // invalid suggestions, so if no sections are based on existing data,
374 // |view_->UpdateForErrors()| is not called.
375 void UpdateForErrors();
377 // Kicks off |card_scrambling_refresher_|.
378 void StartCardScramblingRefresher();
380 // Changes |scrambled_card_number_| and pushes an update to the view.
381 void RefreshCardScramblingOverlay();
383 // Tells the view to update the overlay.
384 void PushOverlayUpdate();
386 // Creates a DataModelWrapper item for the item that's checked in the
387 // suggestion model for |section|. This may represent Autofill
388 // data or Wallet data, depending on whether Wallet is currently enabled.
389 scoped_ptr<DataModelWrapper> CreateWrapper(DialogSection section);
391 // Helper to return the current Wallet instrument or address. If the dialog
392 // isn't using Wallet or the user is adding a new instrument or address, NULL
394 const wallet::WalletItems::MaskedInstrument* ActiveInstrument() const;
395 const wallet::Address* ActiveShippingAddress() const;
397 // Fills in |section|-related fields in |output_| according to the state of
399 void FillOutputForSection(DialogSection section);
400 // As above, but uses |compare| to determine whether a DetailInput matches
401 // a field. Saves any new Autofill data to the PersonalDataManager.
402 void FillOutputForSectionWithComparator(DialogSection section,
403 const InputFieldComparator& compare);
405 // Returns whether |form_structure|_| has any fields that match the fieldset
406 // represented by |section|.
407 bool FormStructureCaresAboutSection(DialogSection section) const;
409 // Finds all fields of the given |type| in |form_structure_|, if any, and sets
410 // each field's value to |output|.
411 void SetOutputForFieldsOfType(ServerFieldType type, const string16& output);
413 // Gets the value for |type| in |section|, whether it comes from manual user
414 // input or the active suggestion.
415 string16 GetValueFromSection(DialogSection section,
416 ServerFieldType type);
418 // Gets the SuggestionsMenuModel for |section|.
419 SuggestionsMenuModel* SuggestionsMenuModelForSection(DialogSection section);
420 const SuggestionsMenuModel* SuggestionsMenuModelForSection(
421 DialogSection section) const;
423 DialogSection SectionForSuggestionsMenuModel(
424 const SuggestionsMenuModel& model);
426 // Suggested text and icons for sections. Suggestion text is used to show an
427 // abridged overview of the currently used suggestion. Extra text is used when
428 // part of a section is suggested but part must be manually input (e.g. during
429 // a CVC challenge or when using Autofill's CC section [never stores CVC]).
430 bool SuggestionTextForSection(DialogSection section,
431 base::string16* vertically_compact,
432 base::string16* horizontally_compact);
433 string16 RequiredActionTextForSection(DialogSection section) const;
434 gfx::Image SuggestionIconForSection(DialogSection section);
435 string16 ExtraSuggestionTextForSection(DialogSection section) const;
436 gfx::Image ExtraSuggestionIconForSection(DialogSection section);
438 // Loads profiles that can suggest data for |type|. |field_contents| is the
439 // part the user has already typed. |inputs| is the rest of section.
440 // Identifying info is loaded into the last three outparams as well as
442 void GetProfileSuggestions(
443 ServerFieldType type,
444 const string16& field_contents,
445 const DetailInputs& inputs,
446 std::vector<string16>* popup_values,
447 std::vector<string16>* popup_labels,
448 std::vector<string16>* popup_icons);
450 // Like RequestedFieldsForSection, but returns a pointer.
451 DetailInputs* MutableRequestedFieldsForSection(DialogSection section);
453 // Hides |popup_controller_|'s popup view, if it exists.
456 // Set whether the currently editing |section| was originally based on
457 // existing Wallet or Autofill data.
458 void SetEditingExistingData(DialogSection section, bool editing);
460 // Whether the user has chosen to enter all new data in at least one section.
461 bool IsManuallyEditingAnySection() const;
463 // Returns validity message for a given credit card number.
464 base::string16 CreditCardNumberValidityMessage(
465 const base::string16& number) const;
467 // Whether all of the input fields currently showing in the dialog have valid
468 // contents. This validates only by checking "sure" messages, i.e. messages
469 // that would have been displayed to the user during editing, as opposed to
471 bool AllSectionsAreValid();
473 // Whether all of the input fields currently showing in the given |section| of
474 // the dialog have valid contents. This validates only by checking "sure"
475 // messages - see AllSectionsAreValid.
476 bool SectionIsValid(DialogSection section);
478 // Whether the currently active credit card expiration date is valid.
479 bool IsCreditCardExpirationValid(const base::string16& year,
480 const base::string16& month) const;
482 // Returns true if |key| refers to a suggestion, as opposed to some control
484 bool IsASuggestionItemKey(const std::string& key) const;
486 // Whether the billing section should be used to fill in the shipping details.
487 bool ShouldUseBillingForShipping();
489 // Whether the user wishes to save information locally to Autofill.
490 bool ShouldSaveDetailsLocally();
492 // Change whether the controller is currently submitting details to Autofill
493 // or Online Wallet (|is_submitting_|) and update the view.
494 void SetIsSubmitting(bool submitting);
496 // Whether the user has accepted all the current legal documents' terms.
497 bool AreLegalDocumentsCurrent() const;
499 // Accepts any pending legal documents now that the user has pressed Submit.
500 void AcceptLegalTerms();
502 // Start the submit proccess to interact with Online Wallet (might do various
503 // things like accept documents, save details, update details, respond to
504 // required actions, etc.).
505 void SubmitWithWallet();
507 // Creates an instrument based on |views_|' contents.
508 scoped_ptr<wallet::Instrument> CreateTransientInstrument();
510 // Creates an address based on the contents of |view_|.
511 scoped_ptr<wallet::Address> CreateTransientAddress();
513 // Gets a full wallet from Online Wallet so the user can purchase something.
514 // This information is decoded to reveal a fronting (proxy) card.
515 void GetFullWallet();
517 // Updates the state of the controller and |view_| based on any required
518 // actions returned by Save or Update calls to Wallet.
519 void HandleSaveOrUpdateRequiredActions(
520 const std::vector<wallet::RequiredAction>& required_actions);
522 // Shows a card generation overlay if necessary, then calls DoFinishSubmit.
525 // Writes to prefs the choice of AutofillDataModel for |section|.
526 void PersistAutofillChoice(DialogSection section,
527 const std::string& guid);
529 // Sets the outparams to the default AutofillDataModel for |section| (which is
530 // the first one in the menu that is a suggestion item).
531 void GetDefaultAutofillChoice(DialogSection section,
534 // Reads from prefs the choice of AutofillDataModel for |section|. Returns
535 // whether there was a setting to read.
536 bool GetAutofillChoice(DialogSection section,
539 // Logs metrics when the dialog is submitted.
540 void LogOnFinishSubmitMetrics();
542 // Logs metrics when the dialog is canceled.
543 void LogOnCancelMetrics();
545 // Logs metrics when the edit ui is shown for the given |section|.
546 void LogEditUiShownMetric(DialogSection section);
548 // Logs metrics when a suggestion item from the given |model| is selected.
549 void LogSuggestionItemSelectedMetric(const SuggestionsMenuModel& model);
551 // Logs the time elapsed from when the dialog was shown to when the user could
553 void LogDialogLatencyToShow();
555 // Returns the metric corresponding to the user's initial state when
556 // interacting with this dialog.
557 AutofillMetrics::DialogInitialUserStateMetric GetInitialUserState() const;
559 // Shows an educational bubble if a new credit card was saved or the first few
560 // times an Online Wallet fronting card was generated.
561 void MaybeShowCreditCardBubble();
563 // Called when the delay for enabling the submit button ends.
564 void OnSubmitButtonDelayEnd();
566 // Initiates a fetch of the user's current Wallet cookie and Google username.
567 void FetchWalletCookieAndUserName();
569 // The |profile| for |contents_|.
570 Profile* const profile_;
572 // For logging UMA metrics.
573 const AutofillMetrics metric_logger_;
574 base::Time dialog_shown_timestamp_;
575 AutofillMetrics::DialogInitialUserStateMetric initial_user_state_;
577 FormStructure form_structure_;
579 // Whether the URL visible to the user when this dialog was requested to be
580 // invoked is the same as |source_url_|.
581 bool invoked_from_same_origin_;
583 // The URL of the invoking site.
586 // The callback via which we return the collected data.
587 base::Callback<void(const FormStructure*)> callback_;
589 // The AccountChooserModel acts as the MenuModel for the account chooser,
590 // and also tracks which data source the dialog is using.
591 AccountChooserModel account_chooser_model_;
593 // The sign-in helper to fetch the user's Wallet cookie and to perform passive
594 // sign-in. The helper is set only during fetch/sign-in, and NULL otherwise.
595 scoped_ptr<wallet::WalletSigninHelper> signin_helper_;
597 // The sign-in helper to fetch the user's human-readable username. The helper
598 // is set only while fetching the username, and NULL otherwise.
599 scoped_ptr<wallet::WalletSigninHelper> username_fetcher_;
601 // A client to talk to the Online Wallet API.
602 wallet::WalletClient wallet_client_;
604 // True if |this| has ever called GetWalletItems().
605 bool wallet_items_requested_;
607 // True when the user has clicked the "Use Wallet" link and we're waiting to
608 // figure out whether we need to ask them to actively sign in.
609 bool handling_use_wallet_link_click_;
611 // Recently received items retrieved via |wallet_client_|.
612 scoped_ptr<wallet::WalletItems> wallet_items_;
613 scoped_ptr<wallet::FullWallet> full_wallet_;
615 // The default active instrument and shipping address object IDs as of the
616 // last time Wallet items were fetched. These variables are only set
617 // (i.e. non-empty) when the Wallet items are being re-fetched.
618 std::string previous_default_instrument_id_;
619 std::string previous_default_shipping_address_id_;
620 // The last active instrument and shipping address object IDs. These
621 // variables are only set (i.e. non-empty) when the Wallet items are being
623 std::string previously_selected_instrument_id_;
624 std::string previously_selected_shipping_address_id_;
626 // When the Wallet items were last fetched.
627 base::TimeTicks last_wallet_items_fetch_timestamp_;
629 // Local machine signals to pass along on each request to trigger (or
630 // discourage) risk challenges; sent if the user is up to date on legal docs.
631 std::string risk_data_;
633 // The text to display when the user is accepting new terms of service, etc.
634 string16 legal_documents_text_;
635 // The ranges within |legal_documents_text_| to linkify.
636 std::vector<gfx::Range> legal_document_link_ranges_;
638 // The instrument and address IDs from the Online Wallet server to be used
639 // when getting a full wallet.
640 std::string active_instrument_id_;
641 std::string active_address_id_;
643 // The fields for billing and shipping which the page has actually requested.
644 DetailInputs requested_cc_fields_;
645 DetailInputs requested_billing_fields_;
646 DetailInputs requested_cc_billing_fields_;
647 DetailInputs requested_shipping_fields_;
649 // Models for the credit card expiration inputs.
650 MonthComboboxModel cc_exp_month_combobox_model_;
651 YearComboboxModel cc_exp_year_combobox_model_;
653 // Model for the country input.
654 CountryComboboxModel country_combobox_model_;
656 // Models for the suggestion views.
657 SuggestionsMenuModel suggested_cc_;
658 SuggestionsMenuModel suggested_billing_;
659 SuggestionsMenuModel suggested_cc_billing_;
660 SuggestionsMenuModel suggested_shipping_;
662 // |DialogSection|s that are in edit mode that are based on existing data.
663 std::set<DialogSection> section_editing_state_;
665 // Whether |form_structure_| has asked for any details that would indicate
666 // we should show a shipping section.
667 bool cares_about_shipping_;
669 // The GUIDs for the currently showing unverified profiles popup.
670 std::vector<PersonalDataManager::GUIDPair> popup_guids_;
672 // The controller for the currently showing popup (which helps users when
673 // they're manually filling the dialog).
674 base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
676 // The input for which |popup_controller_| is currently showing a popup
678 const DetailInput* input_showing_popup_;
680 scoped_ptr<AutofillDialogView> view_;
682 // A NotificationRegistrar for tracking the completion of sign-in.
683 content::NotificationRegistrar signin_registrar_;
685 base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_;
687 // Set to true when the user presses the sign in link, until we're ready to
688 // show the normal dialog again. This is used to hide the buttons while
689 // the spinner is showing after an explicit sign in.
690 bool waiting_for_explicit_sign_in_response_;
692 // Whether a user accepted legal documents while this dialog is running.
693 bool has_accepted_legal_documents_;
695 // True after the user first accepts the dialog and presses "Submit". May
696 // continue to be true while processing required actions.
699 // True if the last call to |GetFullWallet()| returned a
700 // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the
701 // selected instrument or address had become invalid since it was originally
702 // returned in |GetWalletItems()|.
703 bool choose_another_instrument_or_address_;
705 // Whether or not the server side validation errors returned by Wallet were
707 bool wallet_server_validation_recoverable_;
709 // Whether |callback_| was Run() with a filled |form_structure_|.
710 bool data_was_passed_back_;
712 typedef std::map<ServerFieldType,
713 std::pair<base::string16, base::string16> > TypeErrorInputMap;
714 typedef std::map<DialogSection, TypeErrorInputMap> WalletValidationErrors;
715 // Wallet validation errors. section->type->(error_msg, input_value).
716 WalletValidationErrors wallet_errors_;
718 // The notification that describes the current wallet error, if any.
719 scoped_ptr<DialogNotification> wallet_error_notification_;
721 // Whether the latency to display to the UI was logged to UMA yet.
722 bool was_ui_latency_logged_;
724 // The Google Wallet cookie value, set as an authorization header on requests
726 std::string wallet_cookie_value_;
728 // A map from dialog sections to the GUID of a newly saved Autofill data
729 // models for that section. No entries present that don't have newly saved
731 std::map<DialogSection, std::string> newly_saved_data_model_guids_;
733 // Populated if the user chose to save a newly inputted credit card. Used to
734 // show a bubble as the dialog closes to confirm a user's new card info was
735 // saved. Never populated while incognito (as nothing's actually saved).
736 scoped_ptr<CreditCard> newly_saved_card_;
738 // The last four digits of the backing card used for the current run of the
739 // dialog. Only applies to Wallet and is populated on submit.
740 base::string16 backing_card_last_four_;
742 // The timer that delays enabling submit button for a short period of time on
744 base::OneShotTimer<AutofillDialogControllerImpl> submit_button_delay_timer_;
746 // The card scrambling animation displays a random number in place of an
747 // actual credit card number. This is that random number.
748 base::string16 scrambled_card_number_;
750 // Two timers to deal with the card scrambling animation. The first provides
751 // a one second delay before the numbers start scrambling. The second controls
752 // the rate of refresh for the number scrambling.
753 base::OneShotTimer<AutofillDialogControllerImpl> card_scrambling_delay_;
754 base::RepeatingTimer<AutofillDialogControllerImpl> card_scrambling_refresher_;
756 // An animation which controls the background fade when the card is done
758 gfx::LinearAnimation card_generated_animation_;
760 // A username string we display in the card scrambling/generated overlay.
761 base::string16 submitted_cardholder_name_;
763 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl);
766 } // namespace autofill
768 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_