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