autofill_dialog_controller_impl.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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.
4
5#ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
6#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
7
8#include <set>
9#include <vector>
10
11#include "base/callback.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/memory/weak_ptr.h"
14#include "base/strings/string16.h"
15#include "base/time/time.h"
16#include "chrome/browser/ui/autofill/account_chooser_model.h"
17#include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
18#include "chrome/browser/ui/autofill/autofill_dialog_models.h"
19#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
20#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
21#include "chrome/browser/ui/autofill/country_combobox_model.h"
22#include "components/autofill/content/browser/autocheckout_steps.h"
23#include "components/autofill/content/browser/wallet/wallet_client.h"
24#include "components/autofill/content/browser/wallet/wallet_client_delegate.h"
25#include "components/autofill/content/browser/wallet/wallet_items.h"
26#include "components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h"
27#include "components/autofill/core/browser/autofill_manager_delegate.h"
28#include "components/autofill/core/browser/autofill_metrics.h"
29#include "components/autofill/core/browser/autofill_popup_delegate.h"
30#include "components/autofill/core/browser/field_types.h"
31#include "components/autofill/core/browser/form_structure.h"
32#include "components/autofill/core/browser/personal_data_manager.h"
33#include "components/autofill/core/browser/personal_data_manager_observer.h"
34#include "content/public/browser/notification_observer.h"
35#include "content/public/browser/notification_registrar.h"
36#include "content/public/common/ssl_status.h"
37#include "googleurl/src/gurl.h"
38#include "ui/base/models/simple_menu_model.h"
39#include "ui/base/ui_base_types.h"
40
41class Profile;
42
43namespace content {
44class WebContents;
45}
46
47namespace user_prefs {
48class PrefRegistrySyncable;
49}
50
51namespace autofill {
52
53class AutofillDataModel;
54class AutofillDialogView;
55class AutofillPopupControllerImpl;
56class DataModelWrapper;
57class TestableAutofillDialogView;
58
59namespace risk {
60class Fingerprint;
61}
62
63namespace wallet {
64class WalletSigninHelper;
65}
66
67// This class drives the dialog that appears when a site uses the imperative
68// autocomplete API to fill out a form.
69class AutofillDialogControllerImpl : public AutofillDialogController,
70                                     public AutofillPopupDelegate,
71                                     public content::NotificationObserver,
72                                     public SuggestionsMenuModelDelegate,
73                                     public wallet::WalletClientDelegate,
74                                     public wallet::WalletSigninHelperDelegate,
75                                     public PersonalDataManagerObserver,
76                                     public AccountChooserModelDelegate {
77 public:
78  virtual ~AutofillDialogControllerImpl();
79
80  static base::WeakPtr<AutofillDialogControllerImpl> Create(
81      content::WebContents* contents,
82      const FormData& form_structure,
83      const GURL& source_url,
84      const DialogType dialog_type,
85      const base::Callback<void(const FormStructure*,
86                                const std::string&)>& callback);
87
88  static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry);
89
90  void Show();
91  void Hide();
92
93  // Whether Autocheckout is currently running.
94  bool AutocheckoutIsRunning() const;
95
96  // Adds a step in the flow to the Autocheckout UI.
97  void AddAutocheckoutStep(AutocheckoutStepType step_type);
98
99  // Updates the status of a step in the Autocheckout UI.
100  void UpdateAutocheckoutStep(AutocheckoutStepType step_type,
101                              AutocheckoutStepStatus step_status);
102
103  // Called when there is an error in an active Autocheckout flow.
104  void OnAutocheckoutError();
105
106  // Called when an Autocheckout flow completes successfully.
107  void OnAutocheckoutSuccess();
108
109  // Returns |view_| as a testable version of itself (if |view_| exists and
110  // actually implements |AutofillDialogView::GetTestableView()|).
111  TestableAutofillDialogView* GetTestableView();
112
113  // AutofillDialogController implementation.
114  virtual string16 DialogTitle() const OVERRIDE;
115  virtual string16 AccountChooserText() const OVERRIDE;
116  virtual string16 SignInLinkText() const OVERRIDE;
117  virtual string16 EditSuggestionText() const OVERRIDE;
118  virtual string16 CancelButtonText() const OVERRIDE;
119  virtual string16 ConfirmButtonText() const OVERRIDE;
120  virtual string16 SaveLocallyText() const OVERRIDE;
121  virtual string16 LegalDocumentsText() OVERRIDE;
122  virtual DialogSignedInState SignedInState() const OVERRIDE;
123  virtual bool ShouldShowSpinner() const OVERRIDE;
124  virtual bool ShouldOfferToSaveInChrome() const OVERRIDE;
125  virtual ui::MenuModel* MenuModelForAccountChooser() OVERRIDE;
126  virtual gfx::Image AccountChooserImage() OVERRIDE;
127  virtual bool ShouldShowDetailArea() const OVERRIDE;
128  virtual bool ShouldShowProgressBar() const OVERRIDE;
129  virtual int GetDialogButtons() const OVERRIDE;
130  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
131  virtual const std::vector<ui::Range>& LegalDocumentLinks() OVERRIDE;
132  virtual bool SectionIsActive(DialogSection section) const OVERRIDE;
133  virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
134      const OVERRIDE;
135  virtual ui::ComboboxModel* ComboboxModelForAutofillType(
136      AutofillFieldType type) OVERRIDE;
137  virtual ui::MenuModel* MenuModelForSection(DialogSection section) OVERRIDE;
138#if defined(OS_ANDROID)
139  virtual ui::MenuModel* MenuModelForSectionHack(DialogSection section)
140      OVERRIDE;
141#endif
142  virtual string16 LabelForSection(DialogSection section) const OVERRIDE;
143  virtual SuggestionState SuggestionStateForSection(
144      DialogSection section) OVERRIDE;
145  virtual void EditClickedForSection(DialogSection section) OVERRIDE;
146  virtual void EditCancelledForSection(DialogSection section) OVERRIDE;
147  virtual gfx::Image IconForField(AutofillFieldType type,
148                                  const string16& user_input) const OVERRIDE;
149  virtual string16 InputValidityMessage(DialogSection section,
150                                        AutofillFieldType type,
151                                        const string16& value) OVERRIDE;
152  virtual ValidityData InputsAreValid(
153      DialogSection section,
154      const DetailOutputMap& inputs,
155      ValidationType validation_type) OVERRIDE;
156  virtual void UserEditedOrActivatedInput(DialogSection section,
157                                          const DetailInput* input,
158                                          gfx::NativeView parent_view,
159                                          const gfx::Rect& content_bounds,
160                                          const string16& field_contents,
161                                          bool was_edit) OVERRIDE;
162  virtual bool HandleKeyPressEventInInput(
163      const content::NativeWebKeyboardEvent& event) OVERRIDE;
164  virtual void FocusMoved() OVERRIDE;
165  virtual gfx::Image SplashPageImage() const OVERRIDE;
166  virtual void ViewClosed() OVERRIDE;
167  virtual std::vector<DialogNotification> CurrentNotifications() OVERRIDE;
168  virtual std::vector<DialogAutocheckoutStep> CurrentAutocheckoutSteps()
169      const OVERRIDE;
170  virtual void SignInLinkClicked() OVERRIDE;
171  virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
172                                                bool checked) OVERRIDE;
173  virtual void LegalDocumentLinkClicked(const ui::Range& range) OVERRIDE;
174  virtual void OnCancel() OVERRIDE;
175  virtual void OnAccept() OVERRIDE;
176  virtual Profile* profile() OVERRIDE;
177  virtual content::WebContents* web_contents() OVERRIDE;
178
179  // AutofillPopupDelegate implementation.
180  virtual void OnPopupShown(content::KeyboardListener* listener) OVERRIDE;
181  virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE;
182  virtual void DidSelectSuggestion(int identifier) OVERRIDE;
183  virtual void DidAcceptSuggestion(const string16& value,
184                                   int identifier) OVERRIDE;
185  virtual void RemoveSuggestion(const string16& value,
186                                int identifier) OVERRIDE;
187  virtual void ClearPreviewedForm() OVERRIDE;
188
189  // content::NotificationObserver implementation.
190  virtual void Observe(int type,
191                       const content::NotificationSource& source,
192                       const content::NotificationDetails& details) OVERRIDE;
193
194  // SuggestionsMenuModelDelegate implementation.
195  virtual void SuggestionItemSelected(SuggestionsMenuModel* model,
196                                      size_t index) OVERRIDE;
197
198  // wallet::WalletClientDelegate implementation.
199  virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE;
200  virtual DialogType GetDialogType() const OVERRIDE;
201  virtual std::string GetRiskData() const OVERRIDE;
202  virtual void OnDidAcceptLegalDocuments() OVERRIDE;
203  virtual void OnDidAuthenticateInstrument(bool success) OVERRIDE;
204  virtual void OnDidGetFullWallet(
205      scoped_ptr<wallet::FullWallet> full_wallet) OVERRIDE;
206  virtual void OnDidGetWalletItems(
207      scoped_ptr<wallet::WalletItems> wallet_items) OVERRIDE;
208  virtual void OnDidSaveAddress(
209      const std::string& address_id,
210      const std::vector<wallet::RequiredAction>& required_actions,
211      const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE;
212  virtual void OnDidSaveInstrument(
213      const std::string& instrument_id,
214      const std::vector<wallet::RequiredAction>& required_actions,
215      const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE;
216  virtual void OnDidSaveInstrumentAndAddress(
217      const std::string& instrument_id,
218      const std::string& address_id,
219      const std::vector<wallet::RequiredAction>& required_actions,
220      const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE;
221  virtual void OnDidUpdateAddress(
222      const std::string& address_id,
223      const std::vector<wallet::RequiredAction>& required_actions,
224      const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE;
225  virtual void OnDidUpdateInstrument(
226      const std::string& instrument_id,
227      const std::vector<wallet::RequiredAction>& required_actions,
228      const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE;
229  virtual void OnWalletError(
230      wallet::WalletClient::ErrorType error_type) OVERRIDE;
231
232  // PersonalDataManagerObserver implementation.
233  virtual void OnPersonalDataChanged() OVERRIDE;
234
235  // AccountChooserModelDelegate implementation.
236  virtual void AccountChoiceChanged() OVERRIDE;
237  virtual void UpdateAccountChooserView() OVERRIDE;
238
239  // wallet::WalletSigninHelperDelegate implementation.
240  virtual void OnPassiveSigninSuccess(const std::string& username) OVERRIDE;
241  virtual void OnPassiveSigninFailure(
242      const GoogleServiceAuthError& error) OVERRIDE;
243  virtual void OnAutomaticSigninSuccess(const std::string& username) OVERRIDE;
244  virtual void OnAutomaticSigninFailure(
245      const GoogleServiceAuthError& error) OVERRIDE;
246  virtual void OnUserNameFetchSuccess(const std::string& username) OVERRIDE;
247  virtual void OnUserNameFetchFailure(
248      const GoogleServiceAuthError& error) OVERRIDE;
249
250  DialogType dialog_type() const { return dialog_type_; }
251
252 protected:
253  // Exposed for testing.
254  AutofillDialogControllerImpl(
255      content::WebContents* contents,
256      const FormData& form_structure,
257      const GURL& source_url,
258      const DialogType dialog_type,
259      const base::Callback<void(const FormStructure*,
260                                const std::string&)>& callback);
261
262  // Exposed for testing.
263  AutofillDialogView* view() { return view_.get(); }
264  virtual AutofillDialogView* CreateView();
265  const DetailInput* input_showing_popup() const {
266    return input_showing_popup_;
267  }
268
269  // Returns the PersonalDataManager for |profile_|.
270  virtual PersonalDataManager* GetManager();
271
272  // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
273  // for testing.
274  virtual wallet::WalletClient* GetWalletClient();
275
276  // Call to disable communication to Online Wallet for this dialog.
277  // Exposed for testing.
278  void DisableWallet(wallet::WalletClient::ErrorType error_type);
279
280  // Returns whether Wallet is the current data source. Exposed for testing.
281  virtual bool IsPayingWithWallet() const;
282
283  // Asks risk module to asynchronously load fingerprint data. Data will be
284  // returned via |OnDidLoadRiskFingerprintData()|. Exposed for testing.
285  virtual void LoadRiskFingerprintData();
286  virtual void OnDidLoadRiskFingerprintData(
287      scoped_ptr<risk::Fingerprint> fingerprint);
288
289  // Opens the given URL in a new foreground tab.
290  virtual void OpenTabWithUrl(const GURL& url);
291
292  // Whether |section| was sent into edit mode based on existing data. This
293  // happens when a user clicks "Edit" or a suggestion is invalid.
294  virtual bool IsEditingExistingData(DialogSection section) const;
295
296  // Whether the user has chosen to enter all new data in |section|. This
297  // happens via choosing "Add a new X..." from a section's suggestion menu.
298  bool IsManuallyEditingSection(DialogSection section) const;
299
300  // Should be called on the Wallet sign-in error.
301  virtual void OnWalletSigninError();
302
303  // Whether the information input in this dialog will be securely transmitted
304  // to the requesting site.
305  virtual bool TransmissionWillBeSecure() const;
306
307 private:
308  // Whether or not the current request wants credit info back.
309  bool RequestingCreditCardInfo() const;
310
311  // Initializes or updates |suggested_email_| et al.
312  void SuggestionsUpdated();
313
314  // Whether the user's wallet items have at least one address and instrument.
315  bool HasCompleteWallet() const;
316
317  // Starts fetching the wallet items from Online Wallet.
318  void GetWalletItems();
319
320  // Stop showing sign in flow.
321  void HideSignIn();
322
323  // Handles the SignedInState() on Wallet or sign-in state update.
324  // Triggers the user name fetch and the passive/automatic sign-in.
325  void SignedInStateUpdated();
326
327  // Refreshes the model on Wallet or sign-in state update.
328  void OnWalletOrSigninUpdate();
329
330  // Called when a Save or Update call to Wallet has validation errors.
331  void OnWalletFormFieldError(
332      const std::vector<wallet::FormFieldError>& form_field_errors);
333
334  // Calculates |legal_documents_text_| and |legal_document_link_ranges_| if
335  // they have not already been calculated.
336  void EnsureLegalDocumentsText();
337
338  // Clears previously entered manual input and removes |section| from
339  // |section_editing_state_|. Does not update the view.
340  void ResetSectionInput(DialogSection section);
341
342  // Force |section| into edit mode if the current suggestion is invalid.
343  void ShowEditUiIfBadSuggestion(DialogSection section);
344
345  // Whether the |value| of |input| should be preserved on account change.
346  bool InputWasEdited(const DetailInput& input,
347                      const base::string16& value);
348
349  // Takes a snapshot of the newly inputted user data in |view_| (if it exists).
350  DetailOutputMap TakeUserInputSnapshot();
351
352  // Fills the detail inputs from a previously taken user input snapshot. Does
353  // not update the view.
354  void RestoreUserInputFromSnapshot(const DetailOutputMap& snapshot);
355
356  // Tells the view to update |section|.
357  void UpdateSection(DialogSection section);
358
359  // Tells |view_| to update the validity status of its detail inputs (if
360  // |view_| is non-null). Currently this is used solely for highlighting
361  // invalid suggestions, so if no sections are based on existing data,
362  // |view_->UpdateForErrors()| is not called.
363  void UpdateForErrors();
364
365  // Creates a DataModelWrapper item for the item that's checked in the
366  // suggestion model for |section|. This may represent Autofill
367  // data or Wallet data, depending on whether Wallet is currently enabled.
368  scoped_ptr<DataModelWrapper> CreateWrapper(DialogSection section);
369
370  // Helper to return the current Wallet instrument or address. If the dialog
371  // isn't using Wallet or the user is adding a new instrument or address, NULL
372  // will be returned.
373  const wallet::WalletItems::MaskedInstrument* ActiveInstrument() const;
374  const wallet::Address* ActiveShippingAddress() const;
375
376  // Fills in |section|-related fields in |output_| according to the state of
377  // |view_|.
378  void FillOutputForSection(DialogSection section);
379  // As above, but uses |compare| to determine whether a DetailInput matches
380  // a field. Saves any new Autofill data to the PersonalDataManager.
381  void FillOutputForSectionWithComparator(DialogSection section,
382                                          const InputFieldComparator& compare);
383
384  // Returns whether |form_structure|_| has any fields that match the fieldset
385  // represented by |section|.
386  bool FormStructureCaresAboutSection(DialogSection section) const;
387
388  // Sets the CVC result on |form_structure_| to the value in |cvc|.
389  void SetCvcResult(const string16& cvc);
390
391  // Gets the value for |type| in |section|, whether it comes from manual user
392  // input or the active suggestion.
393  string16 GetValueFromSection(DialogSection section,
394                               AutofillFieldType type);
395
396  // Saves the data in |profile| to the personal data manager. This may add
397  // a new profile or tack onto an existing profile.
398  void SaveProfileGleanedFromSection(const AutofillProfile& profile,
399                                     DialogSection section);
400
401  // Gets the SuggestionsMenuModel for |section|.
402  SuggestionsMenuModel* SuggestionsMenuModelForSection(DialogSection section);
403  const SuggestionsMenuModel* SuggestionsMenuModelForSection(
404      DialogSection section) const;
405  // And the reverse.
406  DialogSection SectionForSuggestionsMenuModel(
407      const SuggestionsMenuModel& model);
408
409  // Suggested text and icons for sections. Suggestion text is used to show an
410  // abidged overview of the currently used suggestion. Extra text is used when
411  // part of a section is suggested but part must be manually input (e.g. during
412  // a CVC challenge or when using Autofill's CC section [never stores CVC]).
413  string16 SuggestionTextForSection(DialogSection section);
414  gfx::Font::FontStyle SuggestionTextStyleForSection(DialogSection section)
415      const;
416  string16 RequiredActionTextForSection(DialogSection section) const;
417  gfx::Image SuggestionIconForSection(DialogSection section);
418  string16 ExtraSuggestionTextForSection(DialogSection section) const;
419  gfx::Image ExtraSuggestionIconForSection(DialogSection section) const;
420
421  // Loads profiles that can suggest data for |type|. |field_contents| is the
422  // part the user has already typed. |inputs| is the rest of section.
423  // Identifying info is loaded into the last three outparams as well as
424  // |popup_guids_|.
425  void GetProfileSuggestions(
426      AutofillFieldType type,
427      const string16& field_contents,
428      const DetailInputs& inputs,
429      std::vector<string16>* popup_values,
430      std::vector<string16>* popup_labels,
431      std::vector<string16>* popup_icons);
432
433  // Like RequestedFieldsForSection, but returns a pointer.
434  DetailInputs* MutableRequestedFieldsForSection(DialogSection section);
435
436  // Hides |popup_controller_|'s popup view, if it exists.
437  void HidePopup();
438
439  // Set whether the currently editing |section| was originally based on
440  // existing Wallet or Autofill data.
441  void SetEditingExistingData(DialogSection section, bool editing);
442
443  // Whether the user has chosen to enter all new data in at least one section.
444  bool IsManuallyEditingAnySection() const;
445
446  // Returns validity message for a given credit card number.
447  base::string16 CreditCardNumberValidityMessage(
448      const base::string16& number) const;
449
450  // Whether a particular DetailInput in |section| should be edited or not.
451  bool InputIsEditable(const DetailInput& input, DialogSection section) const;
452
453  // Whether all of the input fields currently showing in the dialog have valid
454  // contents.
455  bool AllSectionsAreValid();
456
457  // Whether all of the input fields currently showing in the given |section| of
458  // the dialog have valid contents.
459  bool SectionIsValid(DialogSection section);
460
461  // Whether the currently active credit card expiration date is valid.
462  bool IsCreditCardExpirationValid(const base::string16& year,
463                                   const base::string16& month) const;
464
465  // Returns true if |key| refers to a suggestion, as opposed to some control
466  // menu item.
467  bool IsASuggestionItemKey(const std::string& key) const;
468
469  // Whether the billing section should be used to fill in the shipping details.
470  bool ShouldUseBillingForShipping();
471
472  // Whether the user wishes to save information locally to Autofill.
473  bool ShouldSaveDetailsLocally();
474
475  // Change whether the controller is currently submitting details to Autofill
476  // or Online Wallet (|is_submitting_|) and update the view.
477  void SetIsSubmitting(bool submitting);
478
479  // Whether the user has accepted all the current legal documents' terms.
480  bool AreLegalDocumentsCurrent() const;
481
482  // Accepts any pending legal documents now that the user has pressed Submit.
483  void AcceptLegalDocuments();
484
485  // Start the submit proccess to interact with Online Wallet (might do various
486  // things like accept documents, save details, update details, respond to
487  // required actions, etc.).
488  void SubmitWithWallet();
489
490  // Creates an instrument based on |views_|' contents.
491  scoped_ptr<wallet::Instrument> CreateTransientInstrument();
492
493  // Creates an update request based on |instrument|. May return NULL.
494  scoped_ptr<wallet::WalletClient::UpdateInstrumentRequest>
495      CreateUpdateInstrumentRequest(const wallet::Instrument* instrument,
496                                    const std::string& instrument_id);
497
498  // Creates an address based on the contents of |view_|.
499  scoped_ptr<wallet::Address> CreateTransientAddress();
500
501  // Gets a full wallet from Online Wallet so the user can purchase something.
502  // This information is decoded to reveal a fronting (proxy) card.
503  void GetFullWallet();
504
505  // Calls |GetFullWallet()| if the required members (|risk_data_|,
506  // |active_instrument_id_|, and |active_address_id_|) are populated.
507  void GetFullWalletIfReady();
508
509  // Updates the state of the controller and |view_| based on any required
510  // actions returned by Save or Update calls to Wallet.
511  void HandleSaveOrUpdateRequiredActions(
512      const std::vector<wallet::RequiredAction>& required_actions);
513
514  // Whether submission is currently waiting for |action| to be handled.
515  bool IsSubmitPausedOn(wallet::RequiredAction action) const;
516
517  // Called when there's nothing left to accept, update, save, or authenticate
518  // in order to fill |form_structure_| and pass data back to the invoking page.
519  void FinishSubmit();
520
521  // Writes to prefs the choice of AutofillDataModel for |section|.
522  void PersistAutofillChoice(DialogSection section,
523                             const std::string& guid,
524                             int variant);
525
526  // Sets the outparams to the default AutofillDataModel for |section| (which is
527  // the first one in the menu that is a suggestion item).
528  void GetDefaultAutofillChoice(DialogSection section,
529                                std::string* guid,
530                                int* variant);
531
532  // Reads from prefs the choice of AutofillDataModel for |section|. Returns
533  // whether there was a setting to read.
534  bool GetAutofillChoice(DialogSection section,
535                         std::string* guid,
536                         int* variant);
537
538  // Calculates which AutofillDataModel variant |model| is referring to.
539  size_t GetSelectedVariantForModel(const SuggestionsMenuModel& model);
540
541  // Logs metrics when the dialog is submitted.
542  void LogOnFinishSubmitMetrics();
543
544  // Logs metrics when the dialog is canceled.
545  void LogOnCancelMetrics();
546
547  // Logs metrics when the edit ui is shown for the given |section|.
548  void LogEditUiShownMetric(DialogSection section);
549
550  // Logs metrics when a suggestion item from the given |model| is selected.
551  void LogSuggestionItemSelectedMetric(const SuggestionsMenuModel& model);
552
553  // Logs the time elapsed from when the dialog was shown to when the user could
554  // interact with it.
555  void LogDialogLatencyToShow();
556
557  // Sets the state of the autocheckout flow.
558  void SetAutocheckoutState(AutocheckoutState autocheckout_state);
559
560  // Returns the metric corresponding to the user's initial state when
561  // interacting with this dialog.
562  AutofillMetrics::DialogInitialUserStateMetric GetInitialUserState() const;
563
564  // The |profile| for |contents_|.
565  Profile* const profile_;
566
567  // The WebContents where the Autofill action originated.
568  content::WebContents* const contents_;
569
570  // For logging UMA metrics.
571  const AutofillMetrics metric_logger_;
572  base::Time dialog_shown_timestamp_;
573  AutofillMetrics::DialogInitialUserStateMetric initial_user_state_;
574
575  // The time that Autocheckout started running. Reset on error. While this is
576  // a valid time, |AutocheckoutIsRunning()| will return true.
577  base::Time autocheckout_started_timestamp_;
578
579  // Whether this is an Autocheckout or a requestAutocomplete dialog.
580  const DialogType dialog_type_;
581
582  FormStructure form_structure_;
583
584  // Whether the URL visible to the user when this dialog was requested to be
585  // invoked is the same as |source_url_|.
586  bool invoked_from_same_origin_;
587
588  // The URL of the invoking site.
589  GURL source_url_;
590
591  // The SSL info from the invoking site.
592  content::SSLStatus ssl_status_;
593
594  // The callback via which we return the collected data and, if Online Wallet
595  // was used, the Google transaction id.
596  base::Callback<void(const FormStructure*, const std::string&)> callback_;
597
598  // The AccountChooserModel acts as the MenuModel for the account chooser,
599  // and also tracks which data source the dialog is using.
600  AccountChooserModel account_chooser_model_;
601
602  // The sign-in helper to fetch the user info and perform passive sign-in.
603  // The helper is set only during fetch/sign-in, and NULL otherwise.
604  scoped_ptr<wallet::WalletSigninHelper> signin_helper_;
605
606  // A client to talk to the Online Wallet API.
607  wallet::WalletClient wallet_client_;
608
609  // Recently received items retrieved via |wallet_client_|.
610  scoped_ptr<wallet::WalletItems> wallet_items_;
611  scoped_ptr<wallet::FullWallet> full_wallet_;
612
613  // Local machine signals to pass along on each request to trigger (or
614  // discourage) risk challenges; sent if the user is up to date on legal docs.
615  std::string risk_data_;
616
617  // The text to display when the user is accepting new terms of service, etc.
618  string16 legal_documents_text_;
619  // The ranges within |legal_documents_text_| to linkify.
620  std::vector<ui::Range> legal_document_link_ranges_;
621
622  // The instrument and address IDs from the Online Wallet server to be used
623  // when getting a full wallet.
624  std::string active_instrument_id_;
625  std::string active_address_id_;
626
627  // The fields for billing and shipping which the page has actually requested.
628  DetailInputs requested_email_fields_;
629  DetailInputs requested_cc_fields_;
630  DetailInputs requested_billing_fields_;
631  DetailInputs requested_cc_billing_fields_;
632  DetailInputs requested_shipping_fields_;
633
634  // Models for the credit card expiration inputs.
635  MonthComboboxModel cc_exp_month_combobox_model_;
636  YearComboboxModel cc_exp_year_combobox_model_;
637
638  // Model for the country input.
639  CountryComboboxModel country_combobox_model_;
640
641  // Models for the suggestion views.
642  SuggestionsMenuModel suggested_email_;
643  SuggestionsMenuModel suggested_cc_;
644  SuggestionsMenuModel suggested_billing_;
645  SuggestionsMenuModel suggested_cc_billing_;
646  SuggestionsMenuModel suggested_shipping_;
647
648  // |DialogSection|s that are in edit mode that are based on existing data.
649  std::set<DialogSection> section_editing_state_;
650
651  // Whether |form_structure_| has asked for any details that would indicate
652  // we should show a shipping section.
653  bool cares_about_shipping_;
654
655  // The GUIDs for the currently showing unverified profiles popup.
656  std::vector<PersonalDataManager::GUIDPair> popup_guids_;
657
658  // The controller for the currently showing popup (which helps users when
659  // they're manually filling the dialog).
660  base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
661
662  // The input for which |popup_controller_| is currently showing a popup
663  // (if any).
664  const DetailInput* input_showing_popup_;
665
666  scoped_ptr<AutofillDialogView> view_;
667
668  // A NotificationRegistrar for tracking the completion of sign-in.
669  content::NotificationRegistrar signin_registrar_;
670
671  base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_;
672
673  // Whether the wallet promos should be shown in the notification area. Based
674  // on whether the user has paid with Wallet or has signed into this dialog.
675  bool should_show_wallet_promo_;
676  bool has_shown_wallet_usage_confirmation_;
677
678  // Whether a user accepted legal documents while this dialog is running.
679  bool has_accepted_legal_documents_;
680
681  // True after the user first accepts the dialog and presses "Submit". May
682  // continue to be true while processing required actions.
683  bool is_submitting_;
684
685  // True if the last call to |GetFullWallet()| returned a
686  // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the
687  // selected instrument or address had become invalid since it was originally
688  // returned in |GetWalletItems()|.
689  bool choose_another_instrument_or_address_;
690
691  // Whether or not the server side validation errors returned by Wallet were
692  // recoverable.
693  bool wallet_server_validation_recoverable_;
694
695
696  typedef std::map<AutofillFieldType,
697      std::pair<base::string16, base::string16> > TypeErrorInputMap;
698  typedef std::map<DialogSection, TypeErrorInputMap> WalletValidationErrors;
699  // Wallet validation errors. section->type->(error_msg, input_value).
700  WalletValidationErrors wallet_errors_;
701
702  // The current state of the Autocheckout flow.
703  AutocheckoutState autocheckout_state_;
704
705  // Whether the latency to display to the UI was logged to UMA yet.
706  bool was_ui_latency_logged_;
707
708  // State of steps in the current Autocheckout flow, or empty if not an
709  // Autocheckout use case.
710  std::vector<DialogAutocheckoutStep> steps_;
711
712  DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl);
713};
714
715}  // namespace autofill
716
717#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
718