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