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/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
16 #include "base/time/time.h"
17 #include "chrome/browser/ui/autofill/account_chooser_model.h"
18 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
19 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
20 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
21 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
22 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
23 #include "chrome/browser/ui/autofill/country_combobox_model.h"
24 #include "components/autofill/content/browser/wallet/wallet_client.h"
25 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h"
26 #include "components/autofill/content/browser/wallet/wallet_items.h"
27 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h"
28 #include "components/autofill/core/browser/autofill_manager_delegate.h"
29 #include "components/autofill/core/browser/autofill_metrics.h"
30 #include "components/autofill/core/browser/autofill_popup_delegate.h"
31 #include "components/autofill/core/browser/field_types.h"
32 #include "components/autofill/core/browser/form_structure.h"
33 #include "components/autofill/core/browser/personal_data_manager.h"
34 #include "components/autofill/core/browser/personal_data_manager_observer.h"
35 #include "content/public/browser/notification_observer.h"
36 #include "content/public/browser/notification_registrar.h"
37 #include "content/public/browser/web_contents_observer.h"
38 #include "content/public/common/ssl_status.h"
39 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h"
40 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_rules_delegate.h"
41 #include "third_party/skia/include/core/SkColor.h"
42 #include "ui/base/models/simple_menu_model.h"
43 #include "ui/base/ui_base_types.h"
44 #include "ui/gfx/animation/animation_delegate.h"
45 #include "ui/gfx/animation/linear_animation.h"
56 class AutofillDataModel;
57 class AutofillDialogView;
58 class AutofillPopupControllerImpl;
59 class DataModelWrapper;
66 class WalletSigninHelper;
69 // This class drives the dialog that appears when a site uses the imperative
70 // autocomplete API to fill out a form.
71 class AutofillDialogControllerImpl
72 : public AutofillDialogViewDelegate,
73 public AutofillDialogController,
74 public AutofillPopupDelegate,
75 public content::NotificationObserver,
76 public content::WebContentsObserver,
77 public SuggestionsMenuModelDelegate,
78 public wallet::WalletClientDelegate,
79 public wallet::WalletSigninHelperDelegate,
80 public PersonalDataManagerObserver,
81 public AccountChooserModelDelegate,
82 public gfx::AnimationDelegate,
83 public ::i18n::addressinput::LoadRulesDelegate {
85 virtual ~AutofillDialogControllerImpl();
87 static base::WeakPtr<AutofillDialogControllerImpl> Create(
88 content::WebContents* contents,
89 const FormData& form_structure,
90 const GURL& source_url,
91 const base::Callback<void(const FormStructure*)>& callback);
93 // AutofillDialogController implementation.
94 virtual void Show() OVERRIDE;
95 virtual void Hide() OVERRIDE;
96 virtual void TabActivated() OVERRIDE;
98 // AutofillDialogViewDelegate implementation.
99 virtual base::string16 DialogTitle() const OVERRIDE;
100 virtual base::string16 AccountChooserText() const OVERRIDE;
101 virtual base::string16 SignInLinkText() const OVERRIDE;
102 virtual base::string16 SpinnerText() const OVERRIDE;
103 virtual base::string16 EditSuggestionText() const OVERRIDE;
104 virtual base::string16 CancelButtonText() const OVERRIDE;
105 virtual base::string16 ConfirmButtonText() const OVERRIDE;
106 virtual base::string16 SaveLocallyText() const OVERRIDE;
107 virtual base::string16 SaveLocallyTooltip() const OVERRIDE;
108 virtual base::string16 LegalDocumentsText() OVERRIDE;
109 virtual bool ShouldShowSpinner() const OVERRIDE;
110 virtual bool ShouldShowAccountChooser() const OVERRIDE;
111 virtual bool ShouldShowSignInWebView() const OVERRIDE;
112 virtual GURL SignInUrl() const OVERRIDE;
113 virtual bool ShouldOfferToSaveInChrome() const OVERRIDE;
114 virtual bool ShouldSaveInChrome() const OVERRIDE;
115 virtual ui::MenuModel* MenuModelForAccountChooser() OVERRIDE;
116 virtual gfx::Image AccountChooserImage() OVERRIDE;
117 virtual gfx::Image ButtonStripImage() const OVERRIDE;
118 virtual int GetDialogButtons() const OVERRIDE;
119 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
120 virtual DialogOverlayState GetDialogOverlay() OVERRIDE;
121 virtual const std::vector<gfx::Range>& LegalDocumentLinks() OVERRIDE;
122 virtual bool SectionIsActive(DialogSection section) const OVERRIDE;
123 virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
125 virtual ui::ComboboxModel* ComboboxModelForAutofillType(
126 ServerFieldType type) OVERRIDE;
127 virtual ui::MenuModel* MenuModelForSection(DialogSection section) OVERRIDE;
128 virtual base::string16 LabelForSection(DialogSection section) const OVERRIDE;
129 virtual SuggestionState SuggestionStateForSection(
130 DialogSection section) OVERRIDE;
131 virtual FieldIconMap IconsForFields(const FieldValueMap& user_inputs)
133 virtual bool FieldControlsIcons(ServerFieldType type) const OVERRIDE;
134 virtual base::string16 TooltipForField(ServerFieldType type) const OVERRIDE;
135 virtual bool InputIsEditable(const DetailInput& input, DialogSection section)
137 virtual base::string16 InputValidityMessage(DialogSection section,
138 ServerFieldType type,
139 const base::string16& value) OVERRIDE;
140 virtual ValidityMessages InputsAreValid(
141 DialogSection section, const FieldValueMap& inputs) OVERRIDE;
142 virtual void UserEditedOrActivatedInput(DialogSection section,
143 ServerFieldType type,
144 gfx::NativeView parent_view,
145 const gfx::Rect& content_bounds,
146 const base::string16& field_contents,
147 bool was_edit) OVERRIDE;
148 virtual bool HandleKeyPressEventInInput(
149 const content::NativeWebKeyboardEvent& event) OVERRIDE;
150 virtual void FocusMoved() OVERRIDE;
151 virtual bool ShouldShowErrorBubble() const OVERRIDE;
152 virtual void ViewClosed() OVERRIDE;
153 virtual std::vector<DialogNotification> CurrentNotifications() OVERRIDE;
154 virtual void LinkClicked(const GURL& url) OVERRIDE;
155 virtual void SignInLinkClicked() OVERRIDE;
156 virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
157 bool checked) OVERRIDE;
158 virtual void LegalDocumentLinkClicked(const gfx::Range& range) OVERRIDE;
159 virtual bool OnCancel() OVERRIDE;
160 virtual bool OnAccept() OVERRIDE;
161 virtual Profile* profile() OVERRIDE;
162 virtual content::WebContents* GetWebContents() OVERRIDE;
164 // AutofillPopupDelegate implementation.
165 virtual void OnPopupShown() OVERRIDE;
166 virtual void OnPopupHidden() OVERRIDE;
167 virtual bool ShouldRepostEvent(const ui::MouseEvent& event) OVERRIDE;
168 virtual void DidSelectSuggestion(int identifier) OVERRIDE;
169 virtual void DidAcceptSuggestion(const base::string16& value,
170 int identifier) OVERRIDE;
171 virtual void RemoveSuggestion(const base::string16& value,
172 int identifier) OVERRIDE;
173 virtual void ClearPreviewedForm() OVERRIDE;
175 // content::NotificationObserver implementation.
176 virtual void Observe(int type,
177 const content::NotificationSource& source,
178 const content::NotificationDetails& details) OVERRIDE;
180 // SuggestionsMenuModelDelegate implementation.
181 virtual void SuggestionsMenuWillShow() OVERRIDE;
182 virtual void SuggestionItemSelected(SuggestionsMenuModel* model,
183 size_t index) OVERRIDE;
185 // wallet::WalletClientDelegate implementation.
186 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE;
187 virtual std::string GetRiskData() const OVERRIDE;
188 virtual std::string GetWalletCookieValue() const OVERRIDE;
189 virtual bool IsShippingAddressRequired() const OVERRIDE;
190 virtual void OnDidAcceptLegalDocuments() OVERRIDE;
191 virtual void OnDidAuthenticateInstrument(bool success) OVERRIDE;
192 virtual void OnDidGetFullWallet(
193 scoped_ptr<wallet::FullWallet> full_wallet) OVERRIDE;
194 virtual void OnDidGetWalletItems(
195 scoped_ptr<wallet::WalletItems> wallet_items) OVERRIDE;
196 virtual void OnDidSaveToWallet(
197 const std::string& instrument_id,
198 const std::string& address_id,
199 const std::vector<wallet::RequiredAction>& required_actions,
200 const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE;
201 virtual void OnWalletError(
202 wallet::WalletClient::ErrorType error_type) OVERRIDE;
204 // PersonalDataManagerObserver implementation.
205 virtual void OnPersonalDataChanged() OVERRIDE;
207 // AccountChooserModelDelegate implementation.
208 virtual void AccountChooserWillShow() OVERRIDE;
209 virtual void AccountChoiceChanged() OVERRIDE;
210 virtual void AddAccount() OVERRIDE;
211 virtual void UpdateAccountChooserView() OVERRIDE;
213 // wallet::WalletSigninHelperDelegate implementation.
214 virtual void OnPassiveSigninSuccess() OVERRIDE;
215 virtual void OnPassiveSigninFailure(
216 const GoogleServiceAuthError& error) OVERRIDE;
217 virtual void OnDidFetchWalletCookieValue(
218 const std::string& cookie_value) OVERRIDE;
220 // gfx::AnimationDelegate implementation.
221 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
222 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
224 // ::i18n::addressinput::LoadRulesDelegate implementation.
225 virtual void OnAddressValidationRulesLoaded(const std::string& country_code,
226 bool success) OVERRIDE;
229 enum DialogSignedInState {
233 REQUIRES_PASSIVE_SIGN_IN,
238 // Exposed for testing.
239 AutofillDialogControllerImpl(
240 content::WebContents* contents,
241 const FormData& form_structure,
242 const GURL& source_url,
243 const base::Callback<void(const FormStructure*)>& callback);
245 // Exposed for testing.
246 AutofillDialogView* view() { return view_.get(); }
247 virtual AutofillDialogView* CreateView();
248 ServerFieldType popup_input_type() const {
249 return popup_input_type_;
252 // Returns the PersonalDataManager for |profile_|.
253 virtual PersonalDataManager* GetManager() const;
255 // Returns an address validation helper. May be NULL during tests.
256 virtual ::i18n::addressinput::AddressValidator* GetValidator();
258 // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
260 const wallet::WalletClient* GetWalletClient() const;
261 virtual wallet::WalletClient* GetWalletClient();
263 // Call to disable communication to Online Wallet for this dialog.
264 // Exposed for testing.
265 void DisableWallet(wallet::WalletClient::ErrorType error_type);
267 // Returns whether Wallet is the current data source. Exposed for testing.
268 virtual bool IsPayingWithWallet() const;
270 // Asks risk module to asynchronously load fingerprint data. Data will be
271 // returned via |OnDidLoadRiskFingerprintData()|. Exposed for testing.
272 virtual void LoadRiskFingerprintData();
273 virtual void OnDidLoadRiskFingerprintData(
274 scoped_ptr<risk::Fingerprint> fingerprint);
276 // Opens the given URL in a new foreground tab.
277 virtual void OpenTabWithUrl(const GURL& url);
279 // The active billing section for the current state of the dialog (e.g. when
280 // paying for wallet, the combined credit card + billing address section).
281 DialogSection ActiveBillingSection() const;
283 // Whether |section| was sent into edit mode based on existing data. This
284 // happens when a user clicks "Edit" or a suggestion is invalid.
285 virtual bool IsEditingExistingData(DialogSection section) const;
287 // Whether the user has chosen to enter all new data in |section|. This
288 // happens via choosing "Add a new X..." from a section's suggestion menu.
289 bool IsManuallyEditingSection(DialogSection section) const;
291 // Should be called on the Wallet sign-in error.
292 virtual void OnWalletSigninError();
294 // Whether submission is currently waiting for |action| to be handled.
295 bool IsSubmitPausedOn(wallet::RequiredAction action) const;
297 // Shows a new credit card saved bubble and passes ownership of |new_card| and
298 // |billing_profile| to the bubble. Exposed for testing.
299 virtual void ShowNewCreditCardBubble(
300 scoped_ptr<CreditCard> new_card,
301 scoped_ptr<AutofillProfile> billing_profile);
303 // Called when there's nothing left to accept, update, save, or authenticate
304 // in order to fill |form_structure_| and pass data back to the invoking page.
305 void DoFinishSubmit();
307 // Delays enabling submit button for a short period of time. Exposed for
309 virtual void SubmitButtonDelayBegin();
311 // Ends the delay for enabling the submit button. Called only from tests.
312 // Without this method, the tests would have to wait for the delay timer to
313 // finish, which would be flaky.
314 void SubmitButtonDelayEndForTesting();
316 // Resets |last_wallet_items_fetch_timestamp_| for testing.
317 void ClearLastWalletItemsFetchTimestampForTesting();
319 // Allows tests to inspect the state of the account chooser.
320 AccountChooserModel* AccountChooserModelForTesting();
322 // Returns whether |url| matches the sign in continue URL. If so, also fills
323 // in |user_index| with the index of the user account that just signed in.
324 virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const;
326 // Whether the user is known to be signed in.
327 DialogSignedInState SignedInState() const;
330 FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerI18nTest,
331 CorrectCountryFromInputs);
333 // Initializes or updates |suggested_cc_| et al.
334 void SuggestionsUpdated();
336 // Starts fetching the wallet items from Online Wallet.
337 void GetWalletItems();
339 // Stop showing sign in flow.
342 // Handles the SignedInState() on Wallet or sign-in state update.
343 // Triggers the user name fetch and passive sign-in.
344 void SignedInStateUpdated();
346 // Refreshes the model on Wallet or sign-in state update.
347 void OnWalletOrSigninUpdate();
349 // Called when a Save or Update call to Wallet has validation errors.
350 void OnWalletFormFieldError(
351 const std::vector<wallet::FormFieldError>& form_field_errors);
353 // Calculates |legal_documents_text_| and |legal_document_link_ranges_|.
354 void ConstructLegalDocumentsText();
356 // Clears previously entered manual input and removes |section| from
357 // |section_editing_state_|. Does not update the view.
358 void ResetSectionInput(DialogSection section);
360 // Force |section| into edit mode if the current suggestion is invalid.
361 void ShowEditUiIfBadSuggestion(DialogSection section);
363 // Whether the |value| of |input| should be preserved on account change.
364 bool InputWasEdited(ServerFieldType type,
365 const base::string16& value);
367 // Takes a snapshot of the newly inputted user data in |view_| (if it exists).
368 FieldValueMap TakeUserInputSnapshot();
370 // Fills the detail inputs from a previously taken user input snapshot. Does
371 // not update the view.
372 void RestoreUserInputFromSnapshot(const FieldValueMap& snapshot);
374 // Tells the view to update |section|.
375 void UpdateSection(DialogSection section);
377 // Tells |view_| to update the validity status of its detail inputs (if
378 // |view_| is non-null). Currently this is used solely for highlighting
379 // invalid suggestions, so if no sections are based on existing data,
380 // |view_->UpdateForErrors()| is not called.
381 void UpdateForErrors();
383 // Renders and returns one frame of the generated card animation.
384 gfx::Image GetGeneratedCardImage(const base::string16& card_number,
385 const base::string16& name,
386 const SkColor& gradient_top,
387 const SkColor& gradient_bottom);
389 // Kicks off |card_scrambling_refresher_|.
390 void StartCardScramblingRefresher();
392 // Changes |scrambled_card_number_| and pushes an update to the view.
393 void RefreshCardScramblingOverlay();
395 // Tells the view to update the overlay.
396 void PushOverlayUpdate();
398 // Creates a DataModelWrapper item for the item that's checked in the
399 // suggestion model for |section|. This may represent Autofill
400 // data or Wallet data, depending on whether Wallet is currently enabled.
401 scoped_ptr<DataModelWrapper> CreateWrapper(DialogSection section);
403 // Helper to return the current Wallet instrument or address. If the dialog
404 // isn't using Wallet or the user is adding a new instrument or address, NULL
406 const wallet::WalletItems::MaskedInstrument* ActiveInstrument() const;
407 const wallet::Address* ActiveShippingAddress() const;
409 // Fills in |section|-related fields in |output_| according to the state of
411 void FillOutputForSection(DialogSection section);
412 // As above, but uses |compare| to determine whether a DetailInput matches
413 // a field. Saves any new Autofill data to the PersonalDataManager.
414 void FillOutputForSectionWithComparator(
415 DialogSection section,
416 const FormStructure::InputFieldComparator& compare);
418 // Returns whether |form_structure|_| has any fields that match the fieldset
419 // represented by |section|.
420 bool FormStructureCaresAboutSection(DialogSection section) const;
422 // Finds all fields of the given |type| in |form_structure_|, if any, and sets
423 // each field's value to |output|.
424 void SetOutputForFieldsOfType(ServerFieldType type,
425 const base::string16& output);
427 // Gets the value for |type| in |section|, whether it comes from manual user
428 // input or the active suggestion.
429 base::string16 GetValueFromSection(DialogSection section,
430 ServerFieldType type);
432 // Gets the SuggestionsMenuModel for |section|.
433 SuggestionsMenuModel* SuggestionsMenuModelForSection(DialogSection section);
434 const SuggestionsMenuModel* SuggestionsMenuModelForSection(
435 DialogSection section) const;
437 DialogSection SectionForSuggestionsMenuModel(
438 const SuggestionsMenuModel& model);
440 // Gets the CountryComboboxModel for |section|.
441 CountryComboboxModel* CountryComboboxModelForSection(DialogSection section);
443 // Clears and builds the inputs in |section| for |country_name|.
444 // When |should_clobber| is false, and the view's country value matches
445 // |country_name|, the inputs won't be rebuilt.
446 bool RebuildInputsForCountry(DialogSection section,
447 const base::string16& country_name,
448 bool should_clobber);
450 // Suggested text and icons for sections. Suggestion text is used to show an
451 // abridged overview of the currently used suggestion. Extra text is used when
452 // part of a section is suggested but part must be manually input (e.g. during
453 // a CVC challenge or when using Autofill's CC section [never stores CVC]).
454 bool SuggestionTextForSection(DialogSection section,
455 base::string16* vertically_compact,
456 base::string16* horizontally_compact);
457 base::string16 RequiredActionTextForSection(DialogSection section) const;
458 gfx::Image SuggestionIconForSection(DialogSection section);
459 base::string16 ExtraSuggestionTextForSection(DialogSection section) const;
460 gfx::Image ExtraSuggestionIconForSection(DialogSection section);
462 // Loads profiles that can suggest data for |type|. |field_contents| is the
463 // part the user has already typed. |inputs| is the rest of section.
464 // Identifying info is loaded into the last three outparams as well as
466 void GetProfileSuggestions(
467 ServerFieldType type,
468 const base::string16& field_contents,
469 const DetailInputs& inputs,
470 std::vector<base::string16>* popup_values,
471 std::vector<base::string16>* popup_labels,
472 std::vector<base::string16>* popup_icons);
474 // Like RequestedFieldsForSection, but returns a pointer.
475 DetailInputs* MutableRequestedFieldsForSection(DialogSection section);
477 // Returns just the |type| attributes of RequestedFieldsForSection(section).
478 std::vector<ServerFieldType> RequestedTypesForSection(DialogSection section)
481 // Returns the country code (e.g. "US") for |section|.
482 std::string CountryCodeForSection(DialogSection section);
484 // Hides |popup_controller_|'s popup view, if it exists.
487 // Set whether the currently editing |section| was originally based on
488 // existing Wallet or Autofill data.
489 void SetEditingExistingData(DialogSection section, bool editing);
491 // Whether the user has chosen to enter all new data in at least one section.
492 bool IsManuallyEditingAnySection() const;
494 // Returns validity message for a given credit card number.
495 base::string16 CreditCardNumberValidityMessage(
496 const base::string16& number) const;
498 // Whether all of the input fields currently showing in the dialog have valid
499 // contents. This validates only by checking "sure" messages, i.e. messages
500 // that would have been displayed to the user during editing, as opposed to
502 bool AllSectionsAreValid();
504 // Whether all of the input fields currently showing in the given |section| of
505 // the dialog have valid contents. This validates only by checking "sure"
506 // messages - see AllSectionsAreValid.
507 bool SectionIsValid(DialogSection section);
509 // Whether validation rules for |section| are loaded.
510 bool RulesAreLoaded(DialogSection section);
512 // Whether the currently active credit card expiration date is valid.
513 bool IsCreditCardExpirationValid(const base::string16& year,
514 const base::string16& month) const;
516 // Returns true if |key| refers to a suggestion, as opposed to some control
518 bool IsASuggestionItemKey(const std::string& key) const;
520 // Whether the billing section should be used to fill in the shipping details.
521 bool ShouldUseBillingForShipping();
523 // Whether the user wishes to save information locally to Autofill.
524 bool ShouldSaveDetailsLocally();
526 // Change whether the controller is currently submitting details to Autofill
527 // or Online Wallet (|is_submitting_|) and update the view.
528 void SetIsSubmitting(bool submitting);
530 // Whether the user has accepted all the current legal documents' terms.
531 bool AreLegalDocumentsCurrent() const;
533 // Accepts any pending legal documents now that the user has pressed Submit.
534 void AcceptLegalTerms();
536 // Start the submit proccess to interact with Online Wallet (might do various
537 // things like accept documents, save details, update details, respond to
538 // required actions, etc.).
539 void SubmitWithWallet();
541 // Creates an instrument based on |views_|' contents.
542 scoped_ptr<wallet::Instrument> CreateTransientInstrument();
544 // Creates an address based on the contents of |view_|.
545 scoped_ptr<wallet::Address> CreateTransientAddress();
547 // Gets a full wallet from Online Wallet so the user can purchase something.
548 // This information is decoded to reveal a fronting (proxy) card.
549 void GetFullWallet();
551 // Updates the state of the controller and |view_| based on any required
552 // actions returned by Save or Update calls to Wallet.
553 void HandleSaveOrUpdateRequiredActions(
554 const std::vector<wallet::RequiredAction>& required_actions);
556 // Shows a card generation overlay if necessary, then calls DoFinishSubmit.
559 // Writes to prefs the choice of AutofillDataModel for |section|.
560 void PersistAutofillChoice(DialogSection section,
561 const std::string& guid);
563 // Sets the outparams to the default AutofillDataModel for |section| (which is
564 // the first one in the menu that is a suggestion item).
565 void GetDefaultAutofillChoice(DialogSection section,
568 // Reads from prefs the choice of AutofillDataModel for |section|. Returns
569 // whether there was a setting to read.
570 bool GetAutofillChoice(DialogSection section,
573 // Logs metrics when the dialog is submitted.
574 void LogOnFinishSubmitMetrics();
576 // Logs metrics when the dialog is canceled.
577 void LogOnCancelMetrics();
579 // Logs metrics when the edit ui is shown for the given |section|.
580 void LogEditUiShownMetric(DialogSection section);
582 // Logs metrics when a suggestion item from the given |model| is selected.
583 void LogSuggestionItemSelectedMetric(const SuggestionsMenuModel& model);
585 // Logs the time elapsed from when the dialog was shown to when the user could
587 void LogDialogLatencyToShow();
589 // Returns the metric corresponding to the user's initial state when
590 // interacting with this dialog.
591 AutofillMetrics::DialogInitialUserStateMetric GetInitialUserState() const;
593 // Shows an educational bubble if a new credit card was saved or the first few
594 // times an Online Wallet fronting card was generated.
595 void MaybeShowCreditCardBubble();
597 // Called when the delay for enabling the submit button ends.
598 void OnSubmitButtonDelayEnd();
600 // Gets the user's current Wallet cookie (gdToken) from the cookie jar.
601 void FetchWalletCookie();
603 // The |profile| for |contents_|.
604 Profile* const profile_;
606 // For logging UMA metrics.
607 const AutofillMetrics metric_logger_;
608 base::Time dialog_shown_timestamp_;
609 AutofillMetrics::DialogInitialUserStateMetric initial_user_state_;
611 FormStructure form_structure_;
613 // Whether the URL visible to the user when this dialog was requested to be
614 // invoked is the same as |source_url_|.
615 bool invoked_from_same_origin_;
617 // The URL of the invoking site.
620 // The callback via which we return the collected data.
621 base::Callback<void(const FormStructure*)> callback_;
623 // The AccountChooserModel acts as the MenuModel for the account chooser,
624 // and also tracks which data source the dialog is using.
625 scoped_ptr<AccountChooserModel> account_chooser_model_;
627 // The sign-in helper to fetch the user's Wallet cookie and to perform passive
628 // sign-in. The helper is set only during fetch/sign-in, and NULL otherwise.
629 scoped_ptr<wallet::WalletSigninHelper> signin_helper_;
631 // A client to talk to the Online Wallet API.
632 wallet::WalletClient wallet_client_;
634 // A helper to validate international address input.
635 scoped_ptr< ::i18n::addressinput::AddressValidator> validator_;
637 // True if |this| has ever called GetWalletItems().
638 bool wallet_items_requested_;
640 // True when the user has clicked the "Use Wallet" link and we're waiting to
641 // figure out whether we need to ask them to actively sign in.
642 bool handling_use_wallet_link_click_;
644 // True when the current WalletItems has a passive auth action which was
645 // attempted and failed.
646 bool passive_failed_;
648 // Recently received items retrieved via |wallet_client_|.
649 scoped_ptr<wallet::WalletItems> wallet_items_;
650 scoped_ptr<wallet::FullWallet> full_wallet_;
652 // The default active instrument and shipping address object IDs as of the
653 // last time Wallet items were fetched. These variables are only set
654 // (i.e. non-empty) when the Wallet items are being re-fetched.
655 std::string previous_default_instrument_id_;
656 std::string previous_default_shipping_address_id_;
657 // The last active instrument and shipping address object IDs. These
658 // variables are only set (i.e. non-empty) when the Wallet items are being
660 std::string previously_selected_instrument_id_;
661 std::string previously_selected_shipping_address_id_;
663 // When the Wallet items were last fetched.
664 base::TimeTicks last_wallet_items_fetch_timestamp_;
666 // Local machine signals to pass along on each request to trigger (or
667 // discourage) risk challenges; sent if the user is up to date on legal docs.
668 std::string risk_data_;
670 // The text to display when the user is accepting new terms of service, etc.
671 base::string16 legal_documents_text_;
672 // The ranges within |legal_documents_text_| to linkify.
673 std::vector<gfx::Range> legal_document_link_ranges_;
675 // The instrument and address IDs from the Online Wallet server to be used
676 // when getting a full wallet.
677 std::string active_instrument_id_;
678 std::string active_address_id_;
680 // The fields for billing and shipping which the page has actually requested.
681 DetailInputs requested_cc_fields_;
682 DetailInputs requested_billing_fields_;
683 DetailInputs requested_cc_billing_fields_;
684 DetailInputs requested_shipping_fields_;
686 // Models for the credit card expiration inputs.
687 MonthComboboxModel cc_exp_month_combobox_model_;
688 YearComboboxModel cc_exp_year_combobox_model_;
690 // Models for country input.
691 CountryComboboxModel billing_country_combobox_model_;
692 CountryComboboxModel shipping_country_combobox_model_;
694 // Models for the suggestion views.
695 SuggestionsMenuModel suggested_cc_;
696 SuggestionsMenuModel suggested_billing_;
697 SuggestionsMenuModel suggested_cc_billing_;
698 SuggestionsMenuModel suggested_shipping_;
700 // |DialogSection|s that are in edit mode that are based on existing data.
701 std::set<DialogSection> section_editing_state_;
703 // Sections that need to be validated when their validation rules load.
704 std::set<DialogSection> needs_validation_;
706 // Whether |form_structure_| has asked for any details that would indicate
707 // we should show a shipping section.
708 bool cares_about_shipping_;
710 // The GUIDs for the currently showing unverified profiles popup.
711 std::vector<PersonalDataManager::GUIDPair> popup_guids_;
713 // The controller for the currently showing popup (which helps users when
714 // they're manually filling the dialog).
715 base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
717 // The type of the visible Autofill popup input (or UNKNOWN_TYPE if none).
718 ServerFieldType popup_input_type_;
720 scoped_ptr<AutofillDialogView> view_;
722 // A NotificationRegistrar for tracking the completion of sign-in.
723 content::NotificationRegistrar signin_registrar_;
725 // Set to true when the user presses the sign in link, until we're ready to
726 // show the normal dialog again. This is used to hide the buttons while
727 // the spinner is showing after an explicit sign in.
728 bool waiting_for_explicit_sign_in_response_;
730 // Whether a user accepted legal documents while this dialog is running.
731 bool has_accepted_legal_documents_;
733 // True after the user first accepts the dialog and presses "Submit". May
734 // continue to be true while processing required actions.
737 // True if the last call to |GetFullWallet()| returned a
738 // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the
739 // selected instrument or address had become invalid since it was originally
740 // returned in |GetWalletItems()|.
741 bool choose_another_instrument_or_address_;
743 // Whether or not the server side validation errors returned by Wallet were
745 bool wallet_server_validation_recoverable_;
747 // Whether |callback_| was Run() with a filled |form_structure_|.
748 bool data_was_passed_back_;
750 typedef std::map<ServerFieldType,
751 std::pair<base::string16, base::string16> > TypeErrorInputMap;
752 typedef std::map<DialogSection, TypeErrorInputMap> WalletValidationErrors;
753 // Wallet validation errors. section->type->(error_msg, input_value).
754 WalletValidationErrors wallet_errors_;
756 // The notification that describes the current wallet error, if any.
757 scoped_ptr<DialogNotification> wallet_error_notification_;
759 // Whether the latency to display to the UI was logged to UMA yet.
760 bool was_ui_latency_logged_;
762 // The Google Wallet cookie value, set as an authorization header on requests
764 std::string wallet_cookie_value_;
766 // A map from dialog sections to the GUID of a newly saved Autofill data
767 // models for that section. No entries present that don't have newly saved
769 std::map<DialogSection, std::string> newly_saved_data_model_guids_;
771 // Populated if the user chose to save a newly inputted credit card. Used to
772 // show a bubble as the dialog closes to confirm a user's new card info was
773 // saved. Never populated while incognito (as nothing's actually saved).
774 scoped_ptr<CreditCard> newly_saved_card_;
776 // The last four digits of the backing card used for the current run of the
777 // dialog. Only applies to Wallet and is populated on submit.
778 base::string16 backing_card_last_four_;
780 // The timer that delays enabling submit button for a short period of time on
782 base::OneShotTimer<AutofillDialogControllerImpl> submit_button_delay_timer_;
784 // The card scrambling animation displays a random number in place of an
785 // actual credit card number. This is that random number.
786 base::string16 scrambled_card_number_;
788 // Two timers to deal with the card scrambling animation. The first provides
789 // a one second delay before the numbers start scrambling. The second controls
790 // the rate of refresh for the number scrambling.
791 base::OneShotTimer<AutofillDialogControllerImpl> card_scrambling_delay_;
792 base::RepeatingTimer<AutofillDialogControllerImpl> card_scrambling_refresher_;
794 // An animation which controls the background fade when the card is done
796 gfx::LinearAnimation card_generated_animation_;
798 // A username string we display in the card scrambling/generated overlay.
799 base::string16 submitted_cardholder_name_;
801 base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_;
803 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl);
806 } // namespace autofill
808 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_