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/gtest_prod_util.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_client.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 "third_party/libaddressinput/chromium/chrome_address_validator.h"
39 #include "third_party/skia/include/core/SkColor.h"
40 #include "ui/base/models/simple_menu_model.h"
41 #include "ui/base/ui_base_types.h"
42 #include "ui/gfx/animation/animation_delegate.h"
43 #include "ui/gfx/animation/linear_animation.h"
53 namespace addressinput
{
60 class AutofillDataModel
;
61 class AutofillDialogView
;
62 class AutofillPopupControllerImpl
;
63 class DataModelWrapper
;
70 class WalletSigninHelper
;
73 // This class drives the dialog that appears when a site uses the imperative
74 // autocomplete API to fill out a form.
75 class AutofillDialogControllerImpl
76 : public AutofillDialogViewDelegate
,
77 public AutofillDialogController
,
78 public AutofillPopupDelegate
,
79 public content::NotificationObserver
,
80 public content::WebContentsObserver
,
81 public SuggestionsMenuModelDelegate
,
82 public wallet::WalletClientDelegate
,
83 public wallet::WalletSigninHelperDelegate
,
84 public PersonalDataManagerObserver
,
85 public AccountChooserModelDelegate
,
86 public gfx::AnimationDelegate
,
87 public LoadRulesListener
{
89 ~AutofillDialogControllerImpl() override
;
91 static base::WeakPtr
<AutofillDialogControllerImpl
> Create(
92 content::WebContents
* contents
,
93 const FormData
& form_structure
,
94 const GURL
& source_url
,
95 const AutofillClient::ResultCallback
& callback
);
97 // AutofillDialogController implementation.
100 void TabActivated() override
;
102 // AutofillDialogViewDelegate implementation.
103 base::string16
DialogTitle() const override
;
104 base::string16
AccountChooserText() const override
;
105 base::string16
SignInLinkText() const override
;
106 base::string16
SpinnerText() const override
;
107 base::string16
EditSuggestionText() const override
;
108 base::string16
CancelButtonText() const override
;
109 base::string16
ConfirmButtonText() const override
;
110 base::string16
SaveLocallyText() const override
;
111 base::string16
SaveLocallyTooltip() const override
;
112 base::string16
LegalDocumentsText() override
;
113 bool ShouldShowSpinner() const override
;
114 bool ShouldShowAccountChooser() const override
;
115 bool ShouldShowSignInWebView() const override
;
116 bool ShouldOfferToSaveInChrome() const override
;
117 bool ShouldSaveInChrome() const override
;
118 ui::MenuModel
* MenuModelForAccountChooser() override
;
119 gfx::Image
AccountChooserImage() override
;
120 gfx::Image
ButtonStripImage() const override
;
121 int GetDialogButtons() const override
;
122 bool IsDialogButtonEnabled(ui::DialogButton button
) const override
;
123 DialogOverlayState
GetDialogOverlay() override
;
124 const std::vector
<gfx::Range
>& LegalDocumentLinks() override
;
125 bool SectionIsActive(DialogSection section
) const override
;
126 const DetailInputs
& RequestedFieldsForSection(
127 DialogSection section
) const override
;
128 ui::ComboboxModel
* ComboboxModelForAutofillType(
129 ServerFieldType type
) override
;
130 ui::MenuModel
* MenuModelForSection(DialogSection section
) override
;
131 base::string16
LabelForSection(DialogSection section
) const override
;
132 SuggestionState
SuggestionStateForSection(DialogSection section
) override
;
133 FieldIconMap
IconsForFields(const FieldValueMap
& user_inputs
) const override
;
134 bool FieldControlsIcons(ServerFieldType type
) const override
;
135 base::string16
TooltipForField(ServerFieldType type
) const override
;
136 bool InputIsEditable(const DetailInput
& input
,
137 DialogSection section
) override
;
138 base::string16
InputValidityMessage(DialogSection section
,
139 ServerFieldType type
,
140 const base::string16
& value
) override
;
141 ValidityMessages
InputsAreValid(DialogSection section
,
142 const FieldValueMap
& inputs
) override
;
143 void UserEditedOrActivatedInput(DialogSection section
,
144 ServerFieldType type
,
145 gfx::NativeView parent_view
,
146 const gfx::Rect
& content_bounds
,
147 const base::string16
& field_contents
,
148 bool was_edit
) override
;
149 bool HandleKeyPressEventInInput(
150 const content::NativeWebKeyboardEvent
& event
) override
;
151 void FocusMoved() override
;
152 bool ShouldShowErrorBubble() const override
;
153 void ViewClosed() override
;
154 std::vector
<DialogNotification
> CurrentNotifications() override
;
155 void LinkClicked(const GURL
& url
) override
;
156 void SignInLinkClicked() override
;
157 void NotificationCheckboxStateChanged(DialogNotification::Type type
,
158 bool checked
) override
;
159 void LegalDocumentLinkClicked(const gfx::Range
& range
) override
;
160 bool OnCancel() override
;
161 bool OnAccept() override
;
162 Profile
* profile() override
;
163 content::WebContents
* GetWebContents() override
;
165 // AutofillPopupDelegate implementation.
166 void OnPopupShown() override
;
167 void OnPopupHidden() override
;
168 void DidSelectSuggestion(const base::string16
& value
,
169 int identifier
) override
;
170 void DidAcceptSuggestion(const base::string16
& value
,
171 int identifier
) override
;
172 void RemoveSuggestion(const base::string16
& value
, int identifier
) override
;
173 void ClearPreviewedForm() override
;
175 // content::NotificationObserver implementation.
176 void Observe(int type
,
177 const content::NotificationSource
& source
,
178 const content::NotificationDetails
& details
) override
;
180 // SuggestionsMenuModelDelegate implementation.
181 void SuggestionItemSelected(SuggestionsMenuModel
* model
,
182 size_t index
) override
;
184 // wallet::WalletClientDelegate implementation.
185 std::string
GetRiskData() const override
;
186 std::string
GetWalletCookieValue() const override
;
187 bool IsShippingAddressRequired() const override
;
188 void OnDidAcceptLegalDocuments() override
;
189 void OnDidAuthenticateInstrument(bool success
) override
;
190 void OnDidGetFullWallet(scoped_ptr
<wallet::FullWallet
> full_wallet
) override
;
191 void OnDidGetWalletItems(
192 scoped_ptr
<wallet::WalletItems
> wallet_items
) override
;
193 void OnDidSaveToWallet(
194 const std::string
& instrument_id
,
195 const std::string
& address_id
,
196 const std::vector
<wallet::RequiredAction
>& required_actions
,
197 const std::vector
<wallet::FormFieldError
>& form_field_errors
) override
;
198 void OnWalletError(wallet::WalletClient::ErrorType error_type
) override
;
200 // PersonalDataManagerObserver implementation.
201 void OnPersonalDataChanged() override
;
203 // AccountChooserModelDelegate implementation.
204 void AccountChoiceChanged() override
;
205 void AddAccount() override
;
206 void UpdateAccountChooserView() override
;
208 // wallet::WalletSigninHelperDelegate implementation.
209 void OnPassiveSigninSuccess() override
;
210 void OnPassiveSigninFailure(const GoogleServiceAuthError
& error
) override
;
211 void OnDidFetchWalletCookieValue(const std::string
& cookie_value
) override
;
213 // gfx::AnimationDelegate implementation.
214 void AnimationEnded(const gfx::Animation
* animation
) override
;
215 void AnimationProgressed(const gfx::Animation
* animation
) override
;
217 // LoadRulesListener implementation.
218 void OnAddressValidationRulesLoaded(const std::string
& country_code
,
219 bool success
) override
;
222 enum DialogSignedInState
{
226 REQUIRES_PASSIVE_SIGN_IN
,
231 // Exposed for testing.
232 AutofillDialogControllerImpl(content::WebContents
* contents
,
233 const FormData
& form_structure
,
234 const GURL
& source_url
,
235 const AutofillClient::ResultCallback
& callback
);
237 // Exposed for testing.
238 AutofillDialogView
* view() { return view_
.get(); }
239 virtual AutofillDialogView
* CreateView();
240 ServerFieldType
popup_input_type() const {
241 return popup_input_type_
;
244 // Returns the PersonalDataManager for |profile_|.
245 virtual PersonalDataManager
* GetManager() const;
247 // Returns an address validation helper. May be NULL during tests.
248 virtual AddressValidator
* GetValidator();
250 // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
252 const wallet::WalletClient
* GetWalletClient() const;
253 virtual wallet::WalletClient
* GetWalletClient();
255 // Call to disable communication to Online Wallet for this dialog.
256 // Exposed for testing.
257 void DisableWallet(wallet::WalletClient::ErrorType error_type
);
259 // Returns whether Wallet is the current data source. Exposed for testing.
260 virtual bool IsPayingWithWallet() const;
262 // Asks risk module to asynchronously load fingerprint data. Data will be
263 // returned via |OnDidLoadRiskFingerprintData()|. Exposed for testing.
264 virtual void LoadRiskFingerprintData();
265 virtual void OnDidLoadRiskFingerprintData(const std::string
& risk_data
);
267 // Opens the given URL in a new foreground tab.
268 virtual void OpenTabWithUrl(const GURL
& url
);
270 // The active billing section for the current state of the dialog (e.g. when
271 // paying for wallet, the combined credit card + billing address section).
272 DialogSection
ActiveBillingSection() const;
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 submission is currently waiting for |action| to be handled.
286 bool IsSubmitPausedOn(wallet::RequiredAction action
) const;
288 // Shows a new credit card saved bubble and passes ownership of |new_card| and
289 // |billing_profile| to the bubble. Exposed for testing.
290 virtual void ShowNewCreditCardBubble(
291 scoped_ptr
<CreditCard
> new_card
,
292 scoped_ptr
<AutofillProfile
> billing_profile
);
294 // Called when there's nothing left to accept, update, save, or authenticate
295 // in order to fill |form_structure_| and pass data back to the invoking page.
296 void DoFinishSubmit();
298 // Delays enabling submit button for a short period of time. Exposed for
300 virtual void SubmitButtonDelayBegin();
302 // Ends the delay for enabling the submit button. Called only from tests.
303 // Without this method, the tests would have to wait for the delay timer to
304 // finish, which would be flaky.
305 void SubmitButtonDelayEndForTesting();
307 // Resets |last_wallet_items_fetch_timestamp_| for testing.
308 void ClearLastWalletItemsFetchTimestampForTesting();
310 // Allows tests to inspect the state of the account chooser.
311 AccountChooserModel
* AccountChooserModelForTesting();
313 // Returns whether |url| matches the sign in continue URL. If so, also fills
314 // in |user_index| with the index of the user account that just signed in.
315 virtual bool IsSignInContinueUrl(const GURL
& url
, size_t* user_index
) const;
317 // Whether the user is known to be signed in.
318 DialogSignedInState
SignedInState() const;
320 // Tells the view to shows the webpage at |url|. Virtual for testing.
321 virtual void ShowSignIn(const GURL
& url
);
324 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerI18nTest
,
325 CorrectCountryFromInputs
);
326 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest
,
328 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerTest
,
329 TransactionAmountReadonly
);
331 // Initializes or updates |suggested_cc_| et al.
332 void SuggestionsUpdated();
334 // Starts fetching the wallet items from Online Wallet.
335 void GetWalletItems();
337 // Stop showing sign in flow.
340 // Handles the SignedInState() on Wallet or sign-in state update.
341 // Triggers the user name fetch and passive sign-in.
342 void SignedInStateUpdated();
344 // Refreshes the model on Wallet or sign-in state update.
345 void OnWalletOrSigninUpdate();
347 // Called when a Save or Update call to Wallet has validation errors.
348 void OnWalletFormFieldError(
349 const std::vector
<wallet::FormFieldError
>& form_field_errors
);
351 // Calculates |legal_documents_text_| and |legal_document_link_ranges_|.
352 void ConstructLegalDocumentsText();
354 // Clears previously entered manual input and removes |section| from
355 // |section_editing_state_|. Does not update the view.
356 void ResetSectionInput(DialogSection section
);
358 // Force |section| into edit mode if the current suggestion is invalid.
359 void ShowEditUiIfBadSuggestion(DialogSection section
);
361 // Whether the |value| of |input| should be preserved on account change.
362 bool InputWasEdited(ServerFieldType type
,
363 const base::string16
& value
);
365 // Takes a snapshot of the newly inputted user data in |view_| (if it exists).
366 FieldValueMap
TakeUserInputSnapshot();
368 // Fills the detail inputs from a previously taken user input snapshot. Does
369 // not update the view.
370 void RestoreUserInputFromSnapshot(const FieldValueMap
& snapshot
);
372 // Tells the view to update |section|.
373 void UpdateSection(DialogSection section
);
375 // Tells |view_| to update the validity status of its detail inputs (if
376 // |view_| is non-null). Currently this is used solely for highlighting
377 // invalid suggestions, so if no sections are based on existing data,
378 // |view_->UpdateForErrors()| is not called.
379 void UpdateForErrors();
381 // Renders and returns one frame of the generated card animation.
382 gfx::Image
GetGeneratedCardImage(const base::string16
& card_number
,
383 const base::string16
& name
,
384 const SkColor
& gradient_top
,
385 const SkColor
& gradient_bottom
);
387 // Kicks off |card_scrambling_refresher_|.
388 void StartCardScramblingRefresher();
390 // Changes |scrambled_card_number_| and pushes an update to the view.
391 void RefreshCardScramblingOverlay();
393 // Tells the view to update the overlay.
394 void PushOverlayUpdate();
396 // Creates a DataModelWrapper item for the item that's checked in the
397 // suggestion model for |section|. This may represent Autofill
398 // data or Wallet data, depending on whether Wallet is currently enabled.
399 scoped_ptr
<DataModelWrapper
> CreateWrapper(DialogSection section
);
401 // Helper to return the current Wallet instrument or address. If the dialog
402 // isn't using Wallet or the user is adding a new instrument or address, NULL
404 const wallet::WalletItems::MaskedInstrument
* ActiveInstrument() const;
405 const wallet::Address
* ActiveShippingAddress() const;
407 // Fills in |section|-related fields in |output_| according to the state of
409 void FillOutputForSection(DialogSection section
);
410 // As above, but uses |compare| to determine whether a DetailInput matches
411 // a field. Saves any new Autofill data to the PersonalDataManager.
412 void FillOutputForSectionWithComparator(
413 DialogSection section
,
414 const FormStructure::InputFieldComparator
& compare
);
416 // Returns whether |form_structure|_| has any fields that match the fieldset
417 // represented by |section|.
418 bool FormStructureCaresAboutSection(DialogSection section
) const;
420 // Finds all fields of the given |type| in |form_structure_|, if any, and sets
421 // each field's value to |output|.
422 void SetOutputForFieldsOfType(ServerFieldType type
,
423 const base::string16
& output
);
425 // Gets the value for |type| in |section|, whether it comes from manual user
426 // input or the active suggestion.
427 base::string16
GetValueFromSection(DialogSection section
,
428 ServerFieldType type
);
430 // Returns whether the given section can accept an address with the given
432 bool CanAcceptCountry(DialogSection section
, const std::string
& country_code
);
434 // Whether |profile| should be suggested for |section|.
435 bool ShouldSuggestProfile(DialogSection section
,
436 const AutofillProfile
& profile
);
438 // Gets the SuggestionsMenuModel for |section|.
439 SuggestionsMenuModel
* SuggestionsMenuModelForSection(DialogSection section
);
440 const SuggestionsMenuModel
* SuggestionsMenuModelForSection(
441 DialogSection section
) const;
443 DialogSection
SectionForSuggestionsMenuModel(
444 const SuggestionsMenuModel
& model
);
446 // Gets the CountryComboboxModel for |section|.
447 CountryComboboxModel
* CountryComboboxModelForSection(DialogSection section
);
449 // Clears and builds the inputs in |section| for |country_name|.
450 // When |should_clobber| is false, and the view's country value matches
451 // |country_name|, the inputs won't be rebuilt.
452 bool RebuildInputsForCountry(DialogSection section
,
453 const base::string16
& country_name
,
454 bool should_clobber
);
456 // Suggested text and icons for sections. Suggestion text is used to show an
457 // abridged overview of the currently used suggestion. Extra text is used when
458 // part of a section is suggested but part must be manually input (e.g. during
459 // a CVC challenge or when using Autofill's CC section [never stores CVC]).
460 bool SuggestionTextForSection(DialogSection section
,
461 base::string16
* vertically_compact
,
462 base::string16
* horizontally_compact
);
463 base::string16
RequiredActionTextForSection(DialogSection section
) const;
464 gfx::Image
SuggestionIconForSection(DialogSection section
);
465 base::string16
ExtraSuggestionTextForSection(DialogSection section
) const;
466 gfx::Image
ExtraSuggestionIconForSection(DialogSection section
);
468 // Suggests address completions using the downloaded i18n validation rules.
469 // Stores the suggestions in |i18n_validator_suggestions_|.
470 void GetI18nValidatorSuggestions(
471 DialogSection section
,
472 ServerFieldType type
,
473 std::vector
<autofill::Suggestion
>* popup_suggestions
);
475 // Like RequestedFieldsForSection, but returns a pointer.
476 DetailInputs
* MutableRequestedFieldsForSection(DialogSection section
);
478 // Returns a pointer to the language code that should be used for formatting
479 // the address in |section| for display. Returns NULL for a non-address
481 std::string
* MutableAddressLanguageCodeForSection(DialogSection section
);
483 // Returns the language code that should be used for formatting the address in
484 // |section|. Returns an empty string for a non-address |section|.
485 std::string
AddressLanguageCodeForSection(DialogSection section
);
487 // Returns just the |type| attributes of RequestedFieldsForSection(section).
488 std::vector
<ServerFieldType
> RequestedTypesForSection(DialogSection section
)
491 // Returns the country code (e.g. "US") for |section|.
492 std::string
CountryCodeForSection(DialogSection section
);
494 // Hides |popup_controller_|'s popup view, if it exists.
497 // Set whether the currently editing |section| was originally based on
498 // existing Wallet or Autofill data.
499 void SetEditingExistingData(DialogSection section
, bool editing
);
501 // Whether the user has chosen to enter all new data in at least one section.
502 bool IsManuallyEditingAnySection() const;
504 // Returns validity message for a given credit card number.
505 base::string16
CreditCardNumberValidityMessage(
506 const base::string16
& number
) const;
508 // Whether all of the input fields currently showing in the dialog have valid
509 // contents. This validates only by checking "sure" messages, i.e. messages
510 // that would have been displayed to the user during editing, as opposed to
512 bool AllSectionsAreValid();
514 // Whether all of the input fields currently showing in the given |section| of
515 // the dialog have valid contents. This validates only by checking "sure"
516 // messages - see AllSectionsAreValid.
517 bool SectionIsValid(DialogSection section
);
519 // Whether validation rules for |section| are loaded.
520 bool RulesAreLoaded(DialogSection section
);
522 // Whether the currently active credit card expiration date is valid.
523 bool IsCreditCardExpirationValid(const base::string16
& year
,
524 const base::string16
& month
) const;
526 // Returns true if we should reject the given credit card brand. |type| should
527 // be a display string, such as "Visa".
528 bool ShouldDisallowCcType(const base::string16
& type
) const;
530 // Returns true if |profile| has an address we can be sure is invalid.
531 // Profiles with invalid addresses are not suggested in the dropdown menu for
532 // billing and shipping addresses.
533 bool HasInvalidAddress(const AutofillProfile
& profile
);
535 // Returns true if |key| refers to a suggestion, as opposed to some control
537 bool IsASuggestionItemKey(const std::string
& key
) const;
539 // Returns whether Autofill is enabled for |profile_|.
540 bool IsAutofillEnabled() const;
542 // Whether the billing section should be used to fill in the shipping details.
543 bool ShouldUseBillingForShipping();
545 // Whether the user wishes to save information locally to Autofill.
546 bool ShouldSaveDetailsLocally();
548 // Change whether the controller is currently submitting details to Autofill
549 // or Online Wallet (|is_submitting_|) and update the view.
550 void SetIsSubmitting(bool submitting
);
552 // Whether the user has accepted all the current legal documents' terms.
553 bool AreLegalDocumentsCurrent() const;
555 // Accepts any pending legal documents now that the user has pressed Submit.
556 void AcceptLegalTerms();
558 // Start the submit proccess to interact with Online Wallet (might do various
559 // things like accept documents, save details, update details, respond to
560 // required actions, etc.).
561 void SubmitWithWallet();
563 // Creates an instrument based on |views_|' contents.
564 scoped_ptr
<wallet::Instrument
> CreateTransientInstrument();
566 // Creates an address based on the contents of |view_|.
567 scoped_ptr
<wallet::Address
> CreateTransientAddress();
569 // Gets a full wallet from Online Wallet so the user can purchase something.
570 // This information is decoded to reveal a fronting (proxy) card.
571 void GetFullWallet();
573 // Updates the state of the controller and |view_| based on any required
574 // actions returned by Save or Update calls to Wallet.
575 void HandleSaveOrUpdateRequiredActions(
576 const std::vector
<wallet::RequiredAction
>& required_actions
);
578 // Shows a card generation overlay if necessary, then calls DoFinishSubmit.
581 // Writes to prefs the choice of AutofillDataModel for |section|.
582 void PersistAutofillChoice(DialogSection section
,
583 const std::string
& guid
);
585 // Sets the outparams to the default AutofillDataModel for |section| (which is
586 // the first one in the menu that is a suggestion item).
587 void GetDefaultAutofillChoice(DialogSection section
,
590 // Reads from prefs the choice of AutofillDataModel for |section|. Returns
591 // whether there was a setting to read.
592 bool GetAutofillChoice(DialogSection section
,
595 // Logs metrics when the dialog is submitted.
596 void LogOnFinishSubmitMetrics();
598 // Logs metrics when the dialog is canceled.
599 void LogOnCancelMetrics();
601 // Logs metrics when the edit ui is shown for the given |section|.
602 void LogEditUiShownMetric(DialogSection section
);
604 // Logs metrics when a suggestion item from the given |model| is selected.
605 void LogSuggestionItemSelectedMetric(const SuggestionsMenuModel
& model
);
607 // Logs the time elapsed from when the dialog was shown to when the user could
609 void LogDialogLatencyToShow();
611 // Returns the metric corresponding to the user's initial state when
612 // interacting with this dialog.
613 AutofillMetrics::DialogInitialUserStateMetric
GetInitialUserState() const;
615 // Shows an educational bubble if a new credit card was saved or the first few
616 // times an Online Wallet fronting card was generated.
617 void MaybeShowCreditCardBubble();
619 // Called when the delay for enabling the submit button ends.
620 void OnSubmitButtonDelayEnd();
622 // Gets the user's current Wallet cookie (gdToken) from the cookie jar.
623 void FetchWalletCookie();
625 // The |profile| for |contents_|.
626 Profile
* const profile_
;
628 // For logging UMA metrics.
629 base::Time dialog_shown_timestamp_
;
630 AutofillMetrics::DialogInitialUserStateMetric initial_user_state_
;
632 FormStructure form_structure_
;
634 // Whether the URL visible to the user when this dialog was requested to be
635 // invoked is the same as |source_url_|.
636 bool invoked_from_same_origin_
;
638 // The URL of the invoking site.
641 // The callback via which we return the collected data.
642 AutofillClient::ResultCallback callback_
;
644 // The AccountChooserModel acts as the MenuModel for the account chooser,
645 // and also tracks which data source the dialog is using.
646 scoped_ptr
<AccountChooserModel
> account_chooser_model_
;
648 // The sign-in helper to fetch the user's Wallet cookie and to perform passive
649 // sign-in. The helper is set only during fetch/sign-in, and NULL otherwise.
650 scoped_ptr
<wallet::WalletSigninHelper
> signin_helper_
;
652 // A client to talk to the Online Wallet API.
653 wallet::WalletClient wallet_client_
;
655 // A helper to validate international address input.
656 scoped_ptr
<AddressValidator
> validator_
;
658 // True if |this| has ever called GetWalletItems().
659 bool wallet_items_requested_
;
661 // True when the user has clicked the "Use Wallet" link and we're waiting to
662 // figure out whether we need to ask them to actively sign in.
663 bool handling_use_wallet_link_click_
;
665 // True when the current WalletItems has a passive auth action which was
666 // attempted and failed.
667 bool passive_failed_
;
669 // Recently received items retrieved via |wallet_client_|.
670 scoped_ptr
<wallet::WalletItems
> wallet_items_
;
671 scoped_ptr
<wallet::FullWallet
> full_wallet_
;
673 // The default active instrument and shipping address object IDs as of the
674 // last time Wallet items were fetched. These variables are only set
675 // (i.e. non-empty) when the Wallet items are being re-fetched.
676 std::string previous_default_instrument_id_
;
677 std::string previous_default_shipping_address_id_
;
678 // The last active instrument and shipping address object IDs. These
679 // variables are only set (i.e. non-empty) when the Wallet items are being
681 std::string previously_selected_instrument_id_
;
682 std::string previously_selected_shipping_address_id_
;
684 // When the Wallet items were last fetched.
685 base::TimeTicks last_wallet_items_fetch_timestamp_
;
687 // Local machine signals to pass along on each request to trigger (or
688 // discourage) risk challenges; sent if the user is up to date on legal docs.
689 std::string risk_data_
;
691 // The text to display when the user is accepting new terms of service, etc.
692 base::string16 legal_documents_text_
;
693 // The ranges within |legal_documents_text_| to linkify.
694 std::vector
<gfx::Range
> legal_document_link_ranges_
;
696 // The instrument and address IDs from the Online Wallet server to be used
697 // when getting a full wallet.
698 std::string active_instrument_id_
;
699 std::string active_address_id_
;
701 // The fields for billing and shipping which the page has actually requested.
702 DetailInputs requested_cc_fields_
;
703 DetailInputs requested_billing_fields_
;
704 DetailInputs requested_cc_billing_fields_
;
705 DetailInputs requested_shipping_fields_
;
707 // The BCP 47 language codes used for formatting the addresses for display.
708 std::string billing_address_language_code_
;
709 std::string shipping_address_language_code_
;
711 // Models for the credit card expiration inputs.
712 MonthComboboxModel cc_exp_month_combobox_model_
;
713 YearComboboxModel cc_exp_year_combobox_model_
;
715 // Models for country input.
716 scoped_ptr
<CountryComboboxModel
> billing_country_combobox_model_
;
717 scoped_ptr
<CountryComboboxModel
> shipping_country_combobox_model_
;
719 // Models for the suggestion views.
720 SuggestionsMenuModel suggested_cc_
;
721 SuggestionsMenuModel suggested_billing_
;
722 SuggestionsMenuModel suggested_cc_billing_
;
723 SuggestionsMenuModel suggested_shipping_
;
725 // The set of values for cc-type that the site accepts. Empty means all types
727 std::set
<base::string16
> acceptable_cc_types_
;
729 // |DialogSection|s that are in edit mode that are based on existing data.
730 std::set
<DialogSection
> section_editing_state_
;
732 // Sections that need to be validated when their validation rules load.
733 std::set
<DialogSection
> needs_validation_
;
735 // Whether |form_structure_| has asked for any details that would indicate
736 // we should show a shipping section.
737 bool cares_about_shipping_
;
739 // Site-provided transaction amount and currency. No attempt to validate this
740 // input; it's passed directly to Wallet.
741 base::string16 transaction_amount_
;
742 base::string16 transaction_currency_
;
744 // The IDs for the currently showing unverified profiles popup. This will
745 // be the first section in the list. The rest of the items will be the
746 // i18n_validator_suggestions_.
747 std::vector
<autofill::SuggestionBackendID
> popup_suggestion_ids_
;
749 // The autofill suggestions based on downloaded i18n validation rules.
750 std::vector
< ::i18n::addressinput::AddressData
> i18n_validator_suggestions_
;
752 // The controller for the currently showing popup (which helps users when
753 // they're manually filling the dialog).
754 base::WeakPtr
<AutofillPopupControllerImpl
> popup_controller_
;
756 // The type of the visible Autofill popup input (or UNKNOWN_TYPE if none).
757 ServerFieldType popup_input_type_
;
759 // The section of the dialog that's showing a popup, undefined if no popup
761 DialogSection popup_section_
;
763 scoped_ptr
<AutofillDialogView
> view_
;
765 // A NotificationRegistrar for tracking the completion of sign-in.
766 content::NotificationRegistrar signin_registrar_
;
768 // The countries the form structure can accept for shipping.
769 std::set
<base::string16
> acceptable_shipping_countries_
;
771 // Set to true when the user presses the sign in link, until we're ready to
772 // show the normal dialog again. This is used to hide the buttons while
773 // the spinner is showing after an explicit sign in.
774 bool waiting_for_explicit_sign_in_response_
;
776 // Whether a user accepted legal documents while this dialog is running.
777 bool has_accepted_legal_documents_
;
779 // True after the user first accepts the dialog and presses "Submit". May
780 // continue to be true while processing required actions.
783 // True if the last call to |GetFullWallet()| returned a
784 // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the
785 // selected instrument or address had become invalid since it was originally
786 // returned in |GetWalletItems()|.
787 bool choose_another_instrument_or_address_
;
789 // Whether or not the server side validation errors returned by Wallet were
791 bool wallet_server_validation_recoverable_
;
793 // Whether |callback_| was Run() with a filled |form_structure_|.
794 bool data_was_passed_back_
;
796 typedef std::map
<ServerFieldType
,
797 std::pair
<base::string16
, base::string16
> > TypeErrorInputMap
;
798 typedef std::map
<DialogSection
, TypeErrorInputMap
> WalletValidationErrors
;
799 // Wallet validation errors. section->type->(error_msg, input_value).
800 WalletValidationErrors wallet_errors_
;
802 // The notification that describes the current wallet error, if any.
803 scoped_ptr
<DialogNotification
> wallet_error_notification_
;
805 // Whether the latency to display to the UI was logged to UMA yet.
806 bool was_ui_latency_logged_
;
808 // The Google Wallet cookie value, set as an authorization header on requests
810 std::string wallet_cookie_value_
;
812 // A map from dialog sections to the GUID of a newly saved Autofill data
813 // models for that section. No entries present that don't have newly saved
815 std::map
<DialogSection
, std::string
> newly_saved_data_model_guids_
;
817 // Populated if the user chose to save a newly inputted credit card. Used to
818 // show a bubble as the dialog closes to confirm a user's new card info was
819 // saved. Never populated while incognito (as nothing's actually saved).
820 scoped_ptr
<CreditCard
> newly_saved_card_
;
822 // The last four digits of the backing card used for the current run of the
823 // dialog. Only applies to Wallet and is populated on submit.
824 base::string16 backing_card_last_four_
;
826 // The timer that delays enabling submit button for a short period of time on
828 base::OneShotTimer
<AutofillDialogControllerImpl
> submit_button_delay_timer_
;
830 // The card scrambling animation displays a random number in place of an
831 // actual credit card number. This is that random number.
832 base::string16 scrambled_card_number_
;
834 // Two timers to deal with the card scrambling animation. The first provides
835 // a one second delay before the numbers start scrambling. The second controls
836 // the rate of refresh for the number scrambling.
837 base::OneShotTimer
<AutofillDialogControllerImpl
> card_scrambling_delay_
;
838 base::RepeatingTimer
<AutofillDialogControllerImpl
> card_scrambling_refresher_
;
840 // An animation which controls the background fade when the card is done
842 gfx::LinearAnimation card_generated_animation_
;
844 // A username string we display in the card scrambling/generated overlay.
845 base::string16 submitted_cardholder_name_
;
847 base::WeakPtrFactory
<AutofillDialogControllerImpl
> weak_ptr_factory_
;
849 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl
);
852 } // namespace autofill
854 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_