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/scoped_observer.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/skia/include/core/SkColor.h"
40 #include "ui/base/models/combobox_model_observer.h"
41 #include "ui/base/models/simple_menu_model.h"
42 #include "ui/base/ui_base_types.h"
43 #include "ui/gfx/animation/animation_delegate.h"
44 #include "ui/gfx/animation/linear_animation.h"
55 class AutofillDataModel
;
56 class AutofillDialogView
;
57 class AutofillPopupControllerImpl
;
58 class DataModelWrapper
;
59 class TestableAutofillDialogView
;
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
: public AutofillDialogViewDelegate
,
72 public AutofillDialogController
,
73 public AutofillPopupDelegate
,
74 public content::NotificationObserver
,
75 public content::WebContentsObserver
,
76 public SuggestionsMenuModelDelegate
,
77 public wallet::WalletClientDelegate
,
78 public wallet::WalletSigninHelperDelegate
,
79 public PersonalDataManagerObserver
,
80 public AccountChooserModelDelegate
,
81 public gfx::AnimationDelegate
,
82 public ui::ComboboxModelObserver
{
84 virtual ~AutofillDialogControllerImpl();
86 static base::WeakPtr
<AutofillDialogControllerImpl
> Create(
87 content::WebContents
* contents
,
88 const FormData
& form_structure
,
89 const GURL
& source_url
,
90 const base::Callback
<void(const FormStructure
*)>& callback
);
92 // AutofillDialogController implementation.
93 virtual void Show() OVERRIDE
;
94 virtual void Hide() OVERRIDE
;
95 virtual void TabActivated() OVERRIDE
;
97 // Returns |view_| as a testable version of itself (if |view_| exists and
98 // actually implements |AutofillDialogView::GetTestableView()|).
99 TestableAutofillDialogView
* GetTestableView();
101 // AutofillDialogViewDelegate implementation.
102 virtual base::string16
DialogTitle() const OVERRIDE
;
103 virtual base::string16
AccountChooserText() const OVERRIDE
;
104 virtual base::string16
SignInLinkText() const OVERRIDE
;
105 virtual base::string16
SpinnerText() const OVERRIDE
;
106 virtual base::string16
EditSuggestionText() const OVERRIDE
;
107 virtual base::string16
CancelButtonText() const OVERRIDE
;
108 virtual base::string16
ConfirmButtonText() const OVERRIDE
;
109 virtual base::string16
SaveLocallyText() const OVERRIDE
;
110 virtual base::string16
SaveLocallyTooltip() const OVERRIDE
;
111 virtual base::string16
LegalDocumentsText() OVERRIDE
;
112 virtual bool ShouldShowSpinner() const OVERRIDE
;
113 virtual bool ShouldShowAccountChooser() const OVERRIDE
;
114 virtual bool ShouldShowSignInWebView() const OVERRIDE
;
115 virtual GURL
SignInUrl() const OVERRIDE
;
116 virtual bool ShouldOfferToSaveInChrome() const OVERRIDE
;
117 virtual bool ShouldSaveInChrome() const OVERRIDE
;
118 virtual ui::MenuModel
* MenuModelForAccountChooser() OVERRIDE
;
119 virtual gfx::Image
AccountChooserImage() OVERRIDE
;
120 virtual gfx::Image
ButtonStripImage() const OVERRIDE
;
121 virtual int GetDialogButtons() const OVERRIDE
;
122 virtual bool IsDialogButtonEnabled(ui::DialogButton button
) const OVERRIDE
;
123 virtual DialogOverlayState
GetDialogOverlay() OVERRIDE
;
124 virtual const std::vector
<gfx::Range
>& LegalDocumentLinks() OVERRIDE
;
125 virtual bool SectionIsActive(DialogSection section
) const OVERRIDE
;
126 virtual const DetailInputs
& RequestedFieldsForSection(DialogSection section
)
128 virtual ui::ComboboxModel
* ComboboxModelForAutofillType(
129 ServerFieldType type
) OVERRIDE
;
130 virtual ui::MenuModel
* MenuModelForSection(DialogSection section
) OVERRIDE
;
131 virtual base::string16
LabelForSection(DialogSection section
) const OVERRIDE
;
132 virtual SuggestionState
SuggestionStateForSection(
133 DialogSection section
) OVERRIDE
;
134 virtual FieldIconMap
IconsForFields(const FieldValueMap
& user_inputs
)
136 virtual bool FieldControlsIcons(ServerFieldType type
) const OVERRIDE
;
137 virtual base::string16
TooltipForField(ServerFieldType type
) const OVERRIDE
;
138 virtual bool InputIsEditable(const DetailInput
& input
, DialogSection section
)
140 virtual base::string16
InputValidityMessage(DialogSection section
,
141 ServerFieldType type
,
142 const base::string16
& value
) OVERRIDE
;
143 virtual ValidityMessages
InputsAreValid(
144 DialogSection section
, const FieldValueMap
& inputs
) OVERRIDE
;
145 virtual void UserEditedOrActivatedInput(DialogSection section
,
146 ServerFieldType type
,
147 gfx::NativeView parent_view
,
148 const gfx::Rect
& content_bounds
,
149 const base::string16
& field_contents
,
150 bool was_edit
) OVERRIDE
;
151 virtual bool HandleKeyPressEventInInput(
152 const content::NativeWebKeyboardEvent
& event
) OVERRIDE
;
153 virtual void FocusMoved() OVERRIDE
;
154 virtual bool ShouldShowErrorBubble() const OVERRIDE
;
155 virtual void ViewClosed() OVERRIDE
;
156 virtual std::vector
<DialogNotification
> CurrentNotifications() OVERRIDE
;
157 virtual void LinkClicked(const GURL
& url
) OVERRIDE
;
158 virtual void SignInLinkClicked() OVERRIDE
;
159 virtual void NotificationCheckboxStateChanged(DialogNotification::Type type
,
160 bool checked
) OVERRIDE
;
161 virtual void LegalDocumentLinkClicked(const gfx::Range
& range
) OVERRIDE
;
162 virtual bool OnCancel() OVERRIDE
;
163 virtual bool OnAccept() OVERRIDE
;
164 virtual Profile
* profile() OVERRIDE
;
165 virtual content::WebContents
* GetWebContents() OVERRIDE
;
167 // AutofillPopupDelegate implementation.
168 virtual void OnPopupShown() OVERRIDE
;
169 virtual void OnPopupHidden() OVERRIDE
;
170 virtual bool ShouldRepostEvent(const ui::MouseEvent
& event
) OVERRIDE
;
171 virtual void DidSelectSuggestion(int identifier
) OVERRIDE
;
172 virtual void DidAcceptSuggestion(const base::string16
& value
,
173 int identifier
) OVERRIDE
;
174 virtual void RemoveSuggestion(const base::string16
& value
,
175 int identifier
) OVERRIDE
;
176 virtual void ClearPreviewedForm() OVERRIDE
;
178 // content::NotificationObserver implementation.
179 virtual void Observe(int type
,
180 const content::NotificationSource
& source
,
181 const content::NotificationDetails
& details
) OVERRIDE
;
183 // SuggestionsMenuModelDelegate implementation.
184 virtual void SuggestionsMenuWillShow() OVERRIDE
;
185 virtual void SuggestionItemSelected(SuggestionsMenuModel
* model
,
186 size_t index
) OVERRIDE
;
188 // wallet::WalletClientDelegate implementation.
189 virtual const AutofillMetrics
& GetMetricLogger() const OVERRIDE
;
190 virtual std::string
GetRiskData() const OVERRIDE
;
191 virtual std::string
GetWalletCookieValue() const OVERRIDE
;
192 virtual bool IsShippingAddressRequired() const OVERRIDE
;
193 virtual void OnDidAcceptLegalDocuments() OVERRIDE
;
194 virtual void OnDidAuthenticateInstrument(bool success
) OVERRIDE
;
195 virtual void OnDidGetFullWallet(
196 scoped_ptr
<wallet::FullWallet
> full_wallet
) OVERRIDE
;
197 virtual void OnDidGetWalletItems(
198 scoped_ptr
<wallet::WalletItems
> wallet_items
) OVERRIDE
;
199 virtual void OnDidSaveToWallet(
200 const std::string
& instrument_id
,
201 const std::string
& address_id
,
202 const std::vector
<wallet::RequiredAction
>& required_actions
,
203 const std::vector
<wallet::FormFieldError
>& form_field_errors
) OVERRIDE
;
204 virtual void OnWalletError(
205 wallet::WalletClient::ErrorType error_type
) OVERRIDE
;
207 // PersonalDataManagerObserver implementation.
208 virtual void OnPersonalDataChanged() OVERRIDE
;
210 // AccountChooserModelDelegate implementation.
211 virtual void AccountChooserWillShow() OVERRIDE
;
212 virtual void AccountChoiceChanged() OVERRIDE
;
213 virtual void AddAccount() OVERRIDE
;
214 virtual void UpdateAccountChooserView() OVERRIDE
;
216 // wallet::WalletSigninHelperDelegate implementation.
217 virtual void OnPassiveSigninSuccess() OVERRIDE
;
218 virtual void OnPassiveSigninFailure(
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
;
227 // ui::ComboboxModelObserver implementation.
228 virtual void OnComboboxModelChanged(ui::ComboboxModel
* model
) OVERRIDE
;
231 enum DialogSignedInState
{
235 REQUIRES_PASSIVE_SIGN_IN
,
240 // Exposed for testing.
241 AutofillDialogControllerImpl(
242 content::WebContents
* contents
,
243 const FormData
& form_structure
,
244 const GURL
& source_url
,
245 const base::Callback
<void(const FormStructure
*)>& callback
);
247 // Exposed for testing.
248 AutofillDialogView
* view() { return view_
.get(); }
249 virtual AutofillDialogView
* CreateView();
250 ServerFieldType
popup_input_type() const {
251 return popup_input_type_
;
254 // Returns the PersonalDataManager for |profile_|.
255 virtual PersonalDataManager
* GetManager() const;
257 // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
259 const wallet::WalletClient
* GetWalletClient() const;
260 virtual wallet::WalletClient
* GetWalletClient();
262 // Call to disable communication to Online Wallet for this dialog.
263 // Exposed for testing.
264 void DisableWallet(wallet::WalletClient::ErrorType error_type
);
266 // Returns whether Wallet is the current data source. Exposed for testing.
267 virtual bool IsPayingWithWallet() const;
269 // Asks risk module to asynchronously load fingerprint data. Data will be
270 // returned via |OnDidLoadRiskFingerprintData()|. Exposed for testing.
271 virtual void LoadRiskFingerprintData();
272 virtual void OnDidLoadRiskFingerprintData(
273 scoped_ptr
<risk::Fingerprint
> fingerprint
);
275 // Opens the given URL in a new foreground tab.
276 virtual void OpenTabWithUrl(const GURL
& url
);
278 // The active billing section for the current state of the dialog (e.g. when
279 // paying for wallet, the combined credit card + billing address section).
280 DialogSection
ActiveBillingSection() const;
282 // Whether |section| was sent into edit mode based on existing data. This
283 // happens when a user clicks "Edit" or a suggestion is invalid.
284 virtual bool IsEditingExistingData(DialogSection section
) const;
286 // Whether the user has chosen to enter all new data in |section|. This
287 // happens via choosing "Add a new X..." from a section's suggestion menu.
288 bool IsManuallyEditingSection(DialogSection section
) const;
290 // Should be called on the Wallet sign-in error.
291 virtual void OnWalletSigninError();
293 // Whether submission is currently waiting for |action| to be handled.
294 bool IsSubmitPausedOn(wallet::RequiredAction action
) const;
296 // Shows a new credit card saved bubble and passes ownership of |new_card| and
297 // |billing_profile| to the bubble. Exposed for testing.
298 virtual void ShowNewCreditCardBubble(
299 scoped_ptr
<CreditCard
> new_card
,
300 scoped_ptr
<AutofillProfile
> billing_profile
);
302 // Called when there's nothing left to accept, update, save, or authenticate
303 // in order to fill |form_structure_| and pass data back to the invoking page.
304 void DoFinishSubmit();
306 // Delays enabling submit button for a short period of time. Exposed for
308 virtual void SubmitButtonDelayBegin();
310 // Ends the delay for enabling the submit button. Called only from tests.
311 // Without this method, the tests would have to wait for the delay timer to
312 // finish, which would be flaky.
313 void SubmitButtonDelayEndForTesting();
315 // Resets |last_wallet_items_fetch_timestamp_| for testing.
316 void ClearLastWalletItemsFetchTimestampForTesting();
318 // Allows tests to inspect the state of the account chooser.
319 AccountChooserModel
* AccountChooserModelForTesting();
321 // Returns whether |url| matches the sign in continue URL. If so, also fills
322 // in |user_index| with the index of the user account that just signed in.
323 virtual bool IsSignInContinueUrl(const GURL
& url
, size_t* user_index
) const;
325 // Whether the user is known to be signed in.
326 DialogSignedInState
SignedInState() const;
329 // Initializes or updates |suggested_cc_| et al.
330 void SuggestionsUpdated();
332 // Starts fetching the wallet items from Online Wallet.
333 void GetWalletItems();
335 // Stop showing sign in flow.
338 // Handles the SignedInState() on Wallet or sign-in state update.
339 // Triggers the user name fetch and passive sign-in.
340 void SignedInStateUpdated();
342 // Refreshes the model on Wallet or sign-in state update.
343 void OnWalletOrSigninUpdate();
345 // Called when a Save or Update call to Wallet has validation errors.
346 void OnWalletFormFieldError(
347 const std::vector
<wallet::FormFieldError
>& form_field_errors
);
349 // Calculates |legal_documents_text_| and |legal_document_link_ranges_|.
350 void ConstructLegalDocumentsText();
352 // Clears previously entered manual input and removes |section| from
353 // |section_editing_state_|. Does not update the view.
354 void ResetSectionInput(DialogSection section
);
356 // Force |section| into edit mode if the current suggestion is invalid.
357 void ShowEditUiIfBadSuggestion(DialogSection section
);
359 // Whether the |value| of |input| should be preserved on account change.
360 bool InputWasEdited(ServerFieldType type
,
361 const base::string16
& value
);
363 // Takes a snapshot of the newly inputted user data in |view_| (if it exists).
364 FieldValueMap
TakeUserInputSnapshot();
366 // Fills the detail inputs from a previously taken user input snapshot. Does
367 // not update the view.
368 void RestoreUserInputFromSnapshot(const FieldValueMap
& snapshot
);
370 // Tells the view to update |section|.
371 void UpdateSection(DialogSection section
);
373 // Tells |view_| to update the validity status of its detail inputs (if
374 // |view_| is non-null). Currently this is used solely for highlighting
375 // invalid suggestions, so if no sections are based on existing data,
376 // |view_->UpdateForErrors()| is not called.
377 void UpdateForErrors();
379 // Renders and returns one frame of the generated card animation.
380 gfx::Image
GetGeneratedCardImage(const base::string16
& card_number
,
381 const base::string16
& name
,
382 const SkColor
& gradient_top
,
383 const SkColor
& gradient_bottom
);
385 // Kicks off |card_scrambling_refresher_|.
386 void StartCardScramblingRefresher();
388 // Changes |scrambled_card_number_| and pushes an update to the view.
389 void RefreshCardScramblingOverlay();
391 // Tells the view to update the overlay.
392 void PushOverlayUpdate();
394 // Creates a DataModelWrapper item for the item that's checked in the
395 // suggestion model for |section|. This may represent Autofill
396 // data or Wallet data, depending on whether Wallet is currently enabled.
397 scoped_ptr
<DataModelWrapper
> CreateWrapper(DialogSection section
);
399 // Helper to return the current Wallet instrument or address. If the dialog
400 // isn't using Wallet or the user is adding a new instrument or address, NULL
402 const wallet::WalletItems::MaskedInstrument
* ActiveInstrument() const;
403 const wallet::Address
* ActiveShippingAddress() const;
405 // Fills in |section|-related fields in |output_| according to the state of
407 void FillOutputForSection(DialogSection section
);
408 // As above, but uses |compare| to determine whether a DetailInput matches
409 // a field. Saves any new Autofill data to the PersonalDataManager.
410 void FillOutputForSectionWithComparator(DialogSection section
,
411 const InputFieldComparator
& compare
);
413 // Returns whether |form_structure|_| has any fields that match the fieldset
414 // represented by |section|.
415 bool FormStructureCaresAboutSection(DialogSection section
) const;
417 // Finds all fields of the given |type| in |form_structure_|, if any, and sets
418 // each field's value to |output|.
419 void SetOutputForFieldsOfType(ServerFieldType type
,
420 const base::string16
& output
);
422 // Gets the value for |type| in |section|, whether it comes from manual user
423 // input or the active suggestion.
424 base::string16
GetValueFromSection(DialogSection section
,
425 ServerFieldType type
);
427 // Gets the SuggestionsMenuModel for |section|.
428 SuggestionsMenuModel
* SuggestionsMenuModelForSection(DialogSection section
);
429 const SuggestionsMenuModel
* SuggestionsMenuModelForSection(
430 DialogSection section
) const;
432 DialogSection
SectionForSuggestionsMenuModel(
433 const SuggestionsMenuModel
& model
);
435 // Gets the CountryComboboxModel for |section|.
436 CountryComboboxModel
* CountryComboboxModelForSection(DialogSection section
);
438 // Suggested text and icons for sections. Suggestion text is used to show an
439 // abridged overview of the currently used suggestion. Extra text is used when
440 // part of a section is suggested but part must be manually input (e.g. during
441 // a CVC challenge or when using Autofill's CC section [never stores CVC]).
442 bool SuggestionTextForSection(DialogSection section
,
443 base::string16
* vertically_compact
,
444 base::string16
* horizontally_compact
);
445 base::string16
RequiredActionTextForSection(DialogSection section
) const;
446 gfx::Image
SuggestionIconForSection(DialogSection section
);
447 base::string16
ExtraSuggestionTextForSection(DialogSection section
) const;
448 gfx::Image
ExtraSuggestionIconForSection(DialogSection section
);
450 // Loads profiles that can suggest data for |type|. |field_contents| is the
451 // part the user has already typed. |inputs| is the rest of section.
452 // Identifying info is loaded into the last three outparams as well as
454 void GetProfileSuggestions(
455 ServerFieldType type
,
456 const base::string16
& field_contents
,
457 const DetailInputs
& inputs
,
458 std::vector
<base::string16
>* popup_values
,
459 std::vector
<base::string16
>* popup_labels
,
460 std::vector
<base::string16
>* popup_icons
);
462 // Like RequestedFieldsForSection, but returns a pointer.
463 DetailInputs
* MutableRequestedFieldsForSection(DialogSection section
);
465 // Returns the country code (e.g. "US") for |section|.
466 std::string
CountryCodeForSection(DialogSection section
);
468 // Hides |popup_controller_|'s popup view, if it exists.
471 // Set whether the currently editing |section| was originally based on
472 // existing Wallet or Autofill data.
473 void SetEditingExistingData(DialogSection section
, bool editing
);
475 // Whether the user has chosen to enter all new data in at least one section.
476 bool IsManuallyEditingAnySection() const;
478 // Returns validity message for a given credit card number.
479 base::string16
CreditCardNumberValidityMessage(
480 const base::string16
& number
) const;
482 // Whether all of the input fields currently showing in the dialog have valid
483 // contents. This validates only by checking "sure" messages, i.e. messages
484 // that would have been displayed to the user during editing, as opposed to
486 bool AllSectionsAreValid();
488 // Whether all of the input fields currently showing in the given |section| of
489 // the dialog have valid contents. This validates only by checking "sure"
490 // messages - see AllSectionsAreValid.
491 bool SectionIsValid(DialogSection section
);
493 // Whether the currently active credit card expiration date is valid.
494 bool IsCreditCardExpirationValid(const base::string16
& year
,
495 const base::string16
& month
) const;
497 // Returns true if |key| refers to a suggestion, as opposed to some control
499 bool IsASuggestionItemKey(const std::string
& key
) const;
501 // Whether the billing section should be used to fill in the shipping details.
502 bool ShouldUseBillingForShipping();
504 // Whether the user wishes to save information locally to Autofill.
505 bool ShouldSaveDetailsLocally();
507 // Change whether the controller is currently submitting details to Autofill
508 // or Online Wallet (|is_submitting_|) and update the view.
509 void SetIsSubmitting(bool submitting
);
511 // Whether the user has accepted all the current legal documents' terms.
512 bool AreLegalDocumentsCurrent() const;
514 // Accepts any pending legal documents now that the user has pressed Submit.
515 void AcceptLegalTerms();
517 // Start the submit proccess to interact with Online Wallet (might do various
518 // things like accept documents, save details, update details, respond to
519 // required actions, etc.).
520 void SubmitWithWallet();
522 // Creates an instrument based on |views_|' contents.
523 scoped_ptr
<wallet::Instrument
> CreateTransientInstrument();
525 // Creates an address based on the contents of |view_|.
526 scoped_ptr
<wallet::Address
> CreateTransientAddress();
528 // Gets a full wallet from Online Wallet so the user can purchase something.
529 // This information is decoded to reveal a fronting (proxy) card.
530 void GetFullWallet();
532 // Updates the state of the controller and |view_| based on any required
533 // actions returned by Save or Update calls to Wallet.
534 void HandleSaveOrUpdateRequiredActions(
535 const std::vector
<wallet::RequiredAction
>& required_actions
);
537 // Shows a card generation overlay if necessary, then calls DoFinishSubmit.
540 // Writes to prefs the choice of AutofillDataModel for |section|.
541 void PersistAutofillChoice(DialogSection section
,
542 const std::string
& guid
);
544 // Sets the outparams to the default AutofillDataModel for |section| (which is
545 // the first one in the menu that is a suggestion item).
546 void GetDefaultAutofillChoice(DialogSection section
,
549 // Reads from prefs the choice of AutofillDataModel for |section|. Returns
550 // whether there was a setting to read.
551 bool GetAutofillChoice(DialogSection section
,
554 // Logs metrics when the dialog is submitted.
555 void LogOnFinishSubmitMetrics();
557 // Logs metrics when the dialog is canceled.
558 void LogOnCancelMetrics();
560 // Logs metrics when the edit ui is shown for the given |section|.
561 void LogEditUiShownMetric(DialogSection section
);
563 // Logs metrics when a suggestion item from the given |model| is selected.
564 void LogSuggestionItemSelectedMetric(const SuggestionsMenuModel
& model
);
566 // Logs the time elapsed from when the dialog was shown to when the user could
568 void LogDialogLatencyToShow();
570 // Returns the metric corresponding to the user's initial state when
571 // interacting with this dialog.
572 AutofillMetrics::DialogInitialUserStateMetric
GetInitialUserState() const;
574 // Shows an educational bubble if a new credit card was saved or the first few
575 // times an Online Wallet fronting card was generated.
576 void MaybeShowCreditCardBubble();
578 // Called when the delay for enabling the submit button ends.
579 void OnSubmitButtonDelayEnd();
581 // Gets the user's current Wallet cookie (gdToken) from the cookie jar.
582 void FetchWalletCookie();
584 // The |profile| for |contents_|.
585 Profile
* const profile_
;
587 // For logging UMA metrics.
588 const AutofillMetrics metric_logger_
;
589 base::Time dialog_shown_timestamp_
;
590 AutofillMetrics::DialogInitialUserStateMetric initial_user_state_
;
592 FormStructure form_structure_
;
594 // Whether the URL visible to the user when this dialog was requested to be
595 // invoked is the same as |source_url_|.
596 bool invoked_from_same_origin_
;
598 // The URL of the invoking site.
601 // The callback via which we return the collected data.
602 base::Callback
<void(const FormStructure
*)> callback_
;
604 // The AccountChooserModel acts as the MenuModel for the account chooser,
605 // and also tracks which data source the dialog is using.
606 scoped_ptr
<AccountChooserModel
> account_chooser_model_
;
608 // The sign-in helper to fetch the user's Wallet cookie and to perform passive
609 // sign-in. The helper is set only during fetch/sign-in, and NULL otherwise.
610 scoped_ptr
<wallet::WalletSigninHelper
> signin_helper_
;
612 // A client to talk to the Online Wallet API.
613 wallet::WalletClient wallet_client_
;
615 // True if |this| has ever called GetWalletItems().
616 bool wallet_items_requested_
;
618 // True when the user has clicked the "Use Wallet" link and we're waiting to
619 // figure out whether we need to ask them to actively sign in.
620 bool handling_use_wallet_link_click_
;
622 // True when the current WalletItems has a passive auth action which was
623 // attempted and failed.
624 bool passive_failed_
;
626 // Recently received items retrieved via |wallet_client_|.
627 scoped_ptr
<wallet::WalletItems
> wallet_items_
;
628 scoped_ptr
<wallet::FullWallet
> full_wallet_
;
630 // The default active instrument and shipping address object IDs as of the
631 // last time Wallet items were fetched. These variables are only set
632 // (i.e. non-empty) when the Wallet items are being re-fetched.
633 std::string previous_default_instrument_id_
;
634 std::string previous_default_shipping_address_id_
;
635 // The last active instrument and shipping address object IDs. These
636 // variables are only set (i.e. non-empty) when the Wallet items are being
638 std::string previously_selected_instrument_id_
;
639 std::string previously_selected_shipping_address_id_
;
641 // When the Wallet items were last fetched.
642 base::TimeTicks last_wallet_items_fetch_timestamp_
;
644 // Local machine signals to pass along on each request to trigger (or
645 // discourage) risk challenges; sent if the user is up to date on legal docs.
646 std::string risk_data_
;
648 // The text to display when the user is accepting new terms of service, etc.
649 base::string16 legal_documents_text_
;
650 // The ranges within |legal_documents_text_| to linkify.
651 std::vector
<gfx::Range
> legal_document_link_ranges_
;
653 // The instrument and address IDs from the Online Wallet server to be used
654 // when getting a full wallet.
655 std::string active_instrument_id_
;
656 std::string active_address_id_
;
658 // The fields for billing and shipping which the page has actually requested.
659 DetailInputs requested_cc_fields_
;
660 DetailInputs requested_billing_fields_
;
661 DetailInputs requested_cc_billing_fields_
;
662 DetailInputs requested_shipping_fields_
;
664 // Models for the credit card expiration inputs.
665 MonthComboboxModel cc_exp_month_combobox_model_
;
666 YearComboboxModel cc_exp_year_combobox_model_
;
668 // Models for country input.
669 CountryComboboxModel billing_country_combobox_model_
;
670 CountryComboboxModel shipping_country_combobox_model_
;
672 // Models for the suggestion views.
673 SuggestionsMenuModel suggested_cc_
;
674 SuggestionsMenuModel suggested_billing_
;
675 SuggestionsMenuModel suggested_cc_billing_
;
676 SuggestionsMenuModel suggested_shipping_
;
678 // |DialogSection|s that are in edit mode that are based on existing data.
679 std::set
<DialogSection
> section_editing_state_
;
681 // Whether |form_structure_| has asked for any details that would indicate
682 // we should show a shipping section.
683 bool cares_about_shipping_
;
685 // The GUIDs for the currently showing unverified profiles popup.
686 std::vector
<PersonalDataManager::GUIDPair
> popup_guids_
;
688 // The controller for the currently showing popup (which helps users when
689 // they're manually filling the dialog).
690 base::WeakPtr
<AutofillPopupControllerImpl
> popup_controller_
;
692 // The type of the visible Autofill popup input (or UNKNOWN_TYPE if none).
693 ServerFieldType popup_input_type_
;
695 scoped_ptr
<AutofillDialogView
> view_
;
697 // A NotificationRegistrar for tracking the completion of sign-in.
698 content::NotificationRegistrar signin_registrar_
;
700 base::WeakPtrFactory
<AutofillDialogControllerImpl
> weak_ptr_factory_
;
702 // Set to true when the user presses the sign in link, until we're ready to
703 // show the normal dialog again. This is used to hide the buttons while
704 // the spinner is showing after an explicit sign in.
705 bool waiting_for_explicit_sign_in_response_
;
707 // Whether a user accepted legal documents while this dialog is running.
708 bool has_accepted_legal_documents_
;
710 // True after the user first accepts the dialog and presses "Submit". May
711 // continue to be true while processing required actions.
714 // True if the last call to |GetFullWallet()| returned a
715 // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the
716 // selected instrument or address had become invalid since it was originally
717 // returned in |GetWalletItems()|.
718 bool choose_another_instrument_or_address_
;
720 // Whether or not the server side validation errors returned by Wallet were
722 bool wallet_server_validation_recoverable_
;
724 // Whether |callback_| was Run() with a filled |form_structure_|.
725 bool data_was_passed_back_
;
727 typedef std::map
<ServerFieldType
,
728 std::pair
<base::string16
, base::string16
> > TypeErrorInputMap
;
729 typedef std::map
<DialogSection
, TypeErrorInputMap
> WalletValidationErrors
;
730 // Wallet validation errors. section->type->(error_msg, input_value).
731 WalletValidationErrors wallet_errors_
;
733 // The notification that describes the current wallet error, if any.
734 scoped_ptr
<DialogNotification
> wallet_error_notification_
;
736 // Whether the latency to display to the UI was logged to UMA yet.
737 bool was_ui_latency_logged_
;
739 // The Google Wallet cookie value, set as an authorization header on requests
741 std::string wallet_cookie_value_
;
743 // A map from dialog sections to the GUID of a newly saved Autofill data
744 // models for that section. No entries present that don't have newly saved
746 std::map
<DialogSection
, std::string
> newly_saved_data_model_guids_
;
748 // Populated if the user chose to save a newly inputted credit card. Used to
749 // show a bubble as the dialog closes to confirm a user's new card info was
750 // saved. Never populated while incognito (as nothing's actually saved).
751 scoped_ptr
<CreditCard
> newly_saved_card_
;
753 // The last four digits of the backing card used for the current run of the
754 // dialog. Only applies to Wallet and is populated on submit.
755 base::string16 backing_card_last_four_
;
757 // The timer that delays enabling submit button for a short period of time on
759 base::OneShotTimer
<AutofillDialogControllerImpl
> submit_button_delay_timer_
;
761 // The card scrambling animation displays a random number in place of an
762 // actual credit card number. This is that random number.
763 base::string16 scrambled_card_number_
;
765 // Two timers to deal with the card scrambling animation. The first provides
766 // a one second delay before the numbers start scrambling. The second controls
767 // the rate of refresh for the number scrambling.
768 base::OneShotTimer
<AutofillDialogControllerImpl
> card_scrambling_delay_
;
769 base::RepeatingTimer
<AutofillDialogControllerImpl
> card_scrambling_refresher_
;
771 // An animation which controls the background fade when the card is done
773 gfx::LinearAnimation card_generated_animation_
;
775 // A username string we display in the card scrambling/generated overlay.
776 base::string16 submitted_cardholder_name_
;
778 ScopedObserver
<ui::ComboboxModel
, AutofillDialogControllerImpl
> observer_
;
780 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl
);
783 } // namespace autofill
785 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_