autofill_dialog_controller_impl.h revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
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/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 AutofillDialogViewDelegate,
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  // Called when the tab hosting this dialog is activated by a user gesture.
94  // Used to trigger a refresh of the user's Wallet data.
95  void TabActivated();
96
97  // Adds a step in the flow to the Autocheckout UI.
98  void AddAutocheckoutStep(AutocheckoutStepType step_type);
99
100  // Updates the status of a step in the Autocheckout UI.
101  void UpdateAutocheckoutStep(AutocheckoutStepType step_type,
102                              AutocheckoutStepStatus step_status);
103
104  // Called when there is an error in an active Autocheckout flow.
105  void OnAutocheckoutError();
106
107  // Called when an Autocheckout flow completes successfully.
108  void OnAutocheckoutSuccess();
109
110  // Returns |view_| as a testable version of itself (if |view_| exists and
111  // actually implements |AutofillDialogView::GetTestableView()|).
112  TestableAutofillDialogView* GetTestableView();
113
114  // AutofillDialogViewDelegate implementation.
115  virtual string16 DialogTitle() const OVERRIDE;
116  virtual string16 AccountChooserText() const OVERRIDE;
117  virtual string16 SignInLinkText() const OVERRIDE;
118  virtual string16 EditSuggestionText() const OVERRIDE;
119  virtual string16 CancelButtonText() const OVERRIDE;
120  virtual string16 ConfirmButtonText() const OVERRIDE;
121  virtual string16 SaveLocallyText() const OVERRIDE;
122  virtual string16 LegalDocumentsText() OVERRIDE;
123  virtual DialogSignedInState SignedInState() const OVERRIDE;
124  virtual bool ShouldShowSpinner() const OVERRIDE;
125  virtual bool ShouldOfferToSaveInChrome() const OVERRIDE;
126  virtual ui::MenuModel* MenuModelForAccountChooser() OVERRIDE;
127  virtual gfx::Image AccountChooserImage() OVERRIDE;
128  virtual bool ShouldShowDetailArea() const OVERRIDE;
129  virtual bool ShouldShowProgressBar() const OVERRIDE;
130  virtual gfx::Image ButtonStripImage() const OVERRIDE;
131  virtual int GetDialogButtons() const OVERRIDE;
132  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
133  virtual DialogOverlayState GetDialogOverlay() const OVERRIDE;
134  virtual const std::vector<ui::Range>& LegalDocumentLinks() OVERRIDE;
135  virtual bool SectionIsActive(DialogSection section) const OVERRIDE;
136  virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
137      const OVERRIDE;
138  virtual ui::ComboboxModel* ComboboxModelForAutofillType(
139      ServerFieldType type) OVERRIDE;
140  virtual ui::MenuModel* MenuModelForSection(DialogSection section) OVERRIDE;
141  virtual string16 LabelForSection(DialogSection section) const OVERRIDE;
142  virtual SuggestionState SuggestionStateForSection(
143      DialogSection section) OVERRIDE;
144  virtual void EditClickedForSection(DialogSection section) OVERRIDE;
145  virtual void EditCancelledForSection(DialogSection section) OVERRIDE;
146  virtual gfx::Image IconForField(ServerFieldType type,
147                                  const string16& user_input) const OVERRIDE;
148  virtual string16 InputValidityMessage(DialogSection section,
149                                        ServerFieldType type,
150                                        const string16& value) OVERRIDE;
151  virtual ValidityData InputsAreValid(
152      DialogSection section,
153      const DetailOutputMap& inputs,
154      ValidationType validation_type) OVERRIDE;
155  virtual void UserEditedOrActivatedInput(DialogSection section,
156                                          const DetailInput* input,
157                                          gfx::NativeView parent_view,
158                                          const gfx::Rect& content_bounds,
159                                          const string16& field_contents,
160                                          bool was_edit) OVERRIDE;
161  virtual bool HandleKeyPressEventInInput(
162      const content::NativeWebKeyboardEvent& event) OVERRIDE;
163  virtual void FocusMoved() OVERRIDE;
164  virtual gfx::Image SplashPageImage() const OVERRIDE;
165  virtual void ViewClosed() OVERRIDE;
166  virtual std::vector<DialogNotification> CurrentNotifications() OVERRIDE;
167  virtual std::vector<DialogAutocheckoutStep> CurrentAutocheckoutSteps()
168      const OVERRIDE;
169  virtual void SignInLinkClicked() OVERRIDE;
170  virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
171                                                bool checked) OVERRIDE;
172  virtual void LegalDocumentLinkClicked(const ui::Range& range) OVERRIDE;
173  virtual void OverlayButtonPressed() OVERRIDE;
174  virtual bool OnCancel() OVERRIDE;
175  virtual bool 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 std::string GetWalletCookieValue() const OVERRIDE;
203  virtual bool IsShippingAddressRequired() const OVERRIDE;
204  virtual void OnDidAcceptLegalDocuments() OVERRIDE;
205  virtual void OnDidAuthenticateInstrument(bool success) OVERRIDE;
206  virtual void OnDidGetFullWallet(
207      scoped_ptr<wallet::FullWallet> full_wallet) OVERRIDE;
208  virtual void OnDidGetWalletItems(
209      scoped_ptr<wallet::WalletItems> wallet_items) OVERRIDE;
210  virtual void OnDidSaveToWallet(
211      const std::string& instrument_id,
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 OnWalletError(
216      wallet::WalletClient::ErrorType error_type) OVERRIDE;
217
218  // PersonalDataManagerObserver implementation.
219  virtual void OnPersonalDataChanged() OVERRIDE;
220
221  // AccountChooserModelDelegate implementation.
222  virtual void AccountChoiceChanged() OVERRIDE;
223  virtual void UpdateAccountChooserView() OVERRIDE;
224
225  // wallet::WalletSigninHelperDelegate implementation.
226  virtual void OnPassiveSigninSuccess(const std::string& username) OVERRIDE;
227  virtual void OnPassiveSigninFailure(
228      const GoogleServiceAuthError& error) OVERRIDE;
229  virtual void OnUserNameFetchSuccess(const std::string& username) OVERRIDE;
230  virtual void OnUserNameFetchFailure(
231      const GoogleServiceAuthError& error) OVERRIDE;
232  virtual void OnDidFetchWalletCookieValue(
233      const std::string& cookie_value) OVERRIDE;
234
235  DialogType dialog_type() const { return dialog_type_; }
236
237 protected:
238  // Exposed for testing.
239  AutofillDialogControllerImpl(
240      content::WebContents* contents,
241      const FormData& form_structure,
242      const GURL& source_url,
243      const DialogType dialog_type,
244      const base::Callback<void(const FormStructure*,
245                                const std::string&)>& callback);
246
247  // Exposed for testing.
248  AutofillDialogView* view() { return view_.get(); }
249  virtual AutofillDialogView* CreateView();
250  const DetailInput* input_showing_popup() const {
251    return input_showing_popup_;
252  }
253
254  // Returns the PersonalDataManager for |profile_|.
255  virtual PersonalDataManager* GetManager();
256
257  // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
258  // for testing.
259  virtual wallet::WalletClient* GetWalletClient();
260
261  // Call to disable communication to Online Wallet for this dialog.
262  // Exposed for testing.
263  void DisableWallet(wallet::WalletClient::ErrorType error_type);
264
265  // Returns whether Wallet is the current data source. Exposed for testing.
266  virtual bool IsPayingWithWallet() const;
267
268  // Asks risk module to asynchronously load fingerprint data. Data will be
269  // returned via |OnDidLoadRiskFingerprintData()|. Exposed for testing.
270  virtual void LoadRiskFingerprintData();
271  virtual void OnDidLoadRiskFingerprintData(
272      scoped_ptr<risk::Fingerprint> fingerprint);
273
274  // Opens the given URL in a new foreground tab.
275  virtual void OpenTabWithUrl(const GURL& url);
276
277  // Whether |section| was sent into edit mode based on existing data. This
278  // happens when a user clicks "Edit" or a suggestion is invalid.
279  virtual bool IsEditingExistingData(DialogSection section) const;
280
281  // Whether the user has chosen to enter all new data in |section|. This
282  // happens via choosing "Add a new X..." from a section's suggestion menu.
283  bool IsManuallyEditingSection(DialogSection section) const;
284
285  // Should be called on the Wallet sign-in error.
286  virtual void OnWalletSigninError();
287
288  // Whether the information input in this dialog will be securely transmitted
289  // to the requesting site.
290  virtual bool TransmissionWillBeSecure() const;
291
292  AutocheckoutState autocheckout_state() const { return autocheckout_state_; }
293
294 private:
295  // Whether or not the current request wants credit info back.
296  bool RequestingCreditCardInfo() const;
297
298  // Initializes or updates |suggested_email_| et al.
299  void SuggestionsUpdated();
300
301  // Whether the user's wallet items have at least one address and instrument.
302  bool HasCompleteWallet() const;
303
304  // Starts fetching the wallet items from Online Wallet.
305  void GetWalletItems();
306
307  // Stop showing sign in flow.
308  void HideSignIn();
309
310  // Handles the SignedInState() on Wallet or sign-in state update.
311  // Triggers the user name fetch and passive sign-in.
312  void SignedInStateUpdated();
313
314  // Refreshes the model on Wallet or sign-in state update.
315  void OnWalletOrSigninUpdate();
316
317  // Called when a Save or Update call to Wallet has validation errors.
318  void OnWalletFormFieldError(
319      const std::vector<wallet::FormFieldError>& form_field_errors);
320
321  // Calculates |legal_documents_text_| and |legal_document_link_ranges_| if
322  // they have not already been calculated.
323  void EnsureLegalDocumentsText();
324
325  // Clears previously entered manual input and removes |section| from
326  // |section_editing_state_|. Does not update the view.
327  void ResetSectionInput(DialogSection section);
328
329  // Force |section| into edit mode if the current suggestion is invalid.
330  void ShowEditUiIfBadSuggestion(DialogSection section);
331
332  // Whether the |value| of |input| should be preserved on account change.
333  bool InputWasEdited(const DetailInput& input,
334                      const base::string16& value);
335
336  // Takes a snapshot of the newly inputted user data in |view_| (if it exists).
337  DetailOutputMap TakeUserInputSnapshot();
338
339  // Fills the detail inputs from a previously taken user input snapshot. Does
340  // not update the view.
341  void RestoreUserInputFromSnapshot(const DetailOutputMap& snapshot);
342
343  // Tells the view to update |section|.
344  void UpdateSection(DialogSection section);
345
346  // Tells |view_| to update the validity status of its detail inputs (if
347  // |view_| is non-null). Currently this is used solely for highlighting
348  // invalid suggestions, so if no sections are based on existing data,
349  // |view_->UpdateForErrors()| is not called.
350  void UpdateForErrors();
351
352  // Creates a DataModelWrapper item for the item that's checked in the
353  // suggestion model for |section|. This may represent Autofill
354  // data or Wallet data, depending on whether Wallet is currently enabled.
355  scoped_ptr<DataModelWrapper> CreateWrapper(DialogSection section);
356
357  // Helper to return the current Wallet instrument or address. If the dialog
358  // isn't using Wallet or the user is adding a new instrument or address, NULL
359  // will be returned.
360  const wallet::WalletItems::MaskedInstrument* ActiveInstrument() const;
361  const wallet::Address* ActiveShippingAddress() const;
362
363  // Fills in |section|-related fields in |output_| according to the state of
364  // |view_|.
365  void FillOutputForSection(DialogSection section);
366  // As above, but uses |compare| to determine whether a DetailInput matches
367  // a field. Saves any new Autofill data to the PersonalDataManager.
368  void FillOutputForSectionWithComparator(DialogSection section,
369                                          const InputFieldComparator& compare);
370
371  // Returns whether |form_structure|_| has any fields that match the fieldset
372  // represented by |section|.
373  bool FormStructureCaresAboutSection(DialogSection section) const;
374
375  // Sets the CVC result on |form_structure_| to the value in |cvc|.
376  void SetCvcResult(const string16& cvc);
377
378  // Gets the value for |type| in |section|, whether it comes from manual user
379  // input or the active suggestion.
380  string16 GetValueFromSection(DialogSection section,
381                               ServerFieldType type);
382
383  // Saves the data in |profile| to the personal data manager. This may add
384  // a new profile or tack onto an existing profile.
385  void SaveProfileGleanedFromSection(const AutofillProfile& profile,
386                                     DialogSection section);
387
388  // Gets the SuggestionsMenuModel for |section|.
389  SuggestionsMenuModel* SuggestionsMenuModelForSection(DialogSection section);
390  const SuggestionsMenuModel* SuggestionsMenuModelForSection(
391      DialogSection section) const;
392  // And the reverse.
393  DialogSection SectionForSuggestionsMenuModel(
394      const SuggestionsMenuModel& model);
395
396  // Suggested text and icons for sections. Suggestion text is used to show an
397  // abidged overview of the currently used suggestion. Extra text is used when
398  // part of a section is suggested but part must be manually input (e.g. during
399  // a CVC challenge or when using Autofill's CC section [never stores CVC]).
400  string16 SuggestionTextForSection(DialogSection section);
401  gfx::Font::FontStyle SuggestionTextStyleForSection(DialogSection section)
402      const;
403  string16 RequiredActionTextForSection(DialogSection section) const;
404  gfx::Image SuggestionIconForSection(DialogSection section);
405  string16 ExtraSuggestionTextForSection(DialogSection section) const;
406  gfx::Image ExtraSuggestionIconForSection(DialogSection section) const;
407
408  // Loads profiles that can suggest data for |type|. |field_contents| is the
409  // part the user has already typed. |inputs| is the rest of section.
410  // Identifying info is loaded into the last three outparams as well as
411  // |popup_guids_|.
412  void GetProfileSuggestions(
413      ServerFieldType type,
414      const string16& field_contents,
415      const DetailInputs& inputs,
416      std::vector<string16>* popup_values,
417      std::vector<string16>* popup_labels,
418      std::vector<string16>* popup_icons);
419
420  // Like RequestedFieldsForSection, but returns a pointer.
421  DetailInputs* MutableRequestedFieldsForSection(DialogSection section);
422
423  // Hides |popup_controller_|'s popup view, if it exists.
424  void HidePopup();
425
426  // Set whether the currently editing |section| was originally based on
427  // existing Wallet or Autofill data.
428  void SetEditingExistingData(DialogSection section, bool editing);
429
430  // Whether the user has chosen to enter all new data in at least one section.
431  bool IsManuallyEditingAnySection() const;
432
433  // Returns validity message for a given credit card number.
434  base::string16 CreditCardNumberValidityMessage(
435      const base::string16& number) const;
436
437  // Whether a particular DetailInput in |section| should be edited or not.
438  bool InputIsEditable(const DetailInput& input, DialogSection section) const;
439
440  // Whether all of the input fields currently showing in the dialog have valid
441  // contents.
442  bool AllSectionsAreValid();
443
444  // Whether all of the input fields currently showing in the given |section| of
445  // the dialog have valid contents.
446  bool SectionIsValid(DialogSection section);
447
448  // Whether the currently active credit card expiration date is valid.
449  bool IsCreditCardExpirationValid(const base::string16& year,
450                                   const base::string16& month) const;
451
452  // Returns true if |key| refers to a suggestion, as opposed to some control
453  // menu item.
454  bool IsASuggestionItemKey(const std::string& key) const;
455
456  // Whether the billing section should be used to fill in the shipping details.
457  bool ShouldUseBillingForShipping();
458
459  // Whether the user wishes to save information locally to Autofill.
460  bool ShouldSaveDetailsLocally();
461
462  // Change whether the controller is currently submitting details to Autofill
463  // or Online Wallet (|is_submitting_|) and update the view.
464  void SetIsSubmitting(bool submitting);
465
466  // Whether the user has accepted all the current legal documents' terms.
467  bool AreLegalDocumentsCurrent() const;
468
469  // Accepts any pending legal documents now that the user has pressed Submit.
470  void AcceptLegalDocuments();
471
472  // Start the submit proccess to interact with Online Wallet (might do various
473  // things like accept documents, save details, update details, respond to
474  // required actions, etc.).
475  void SubmitWithWallet();
476
477  // Creates an instrument based on |views_|' contents.
478  scoped_ptr<wallet::Instrument> CreateTransientInstrument();
479
480  // Creates an address based on the contents of |view_|.
481  scoped_ptr<wallet::Address> CreateTransientAddress();
482
483  // Gets a full wallet from Online Wallet so the user can purchase something.
484  // This information is decoded to reveal a fronting (proxy) card.
485  void GetFullWallet();
486
487  // Updates the state of the controller and |view_| based on any required
488  // actions returned by Save or Update calls to Wallet.
489  void HandleSaveOrUpdateRequiredActions(
490      const std::vector<wallet::RequiredAction>& required_actions);
491
492  // Whether submission is currently waiting for |action| to be handled.
493  bool IsSubmitPausedOn(wallet::RequiredAction action) const;
494
495  // Called when there's nothing left to accept, update, save, or authenticate
496  // in order to fill |form_structure_| and pass data back to the invoking page.
497  void FinishSubmit();
498
499  // Writes to prefs the choice of AutofillDataModel for |section|.
500  void PersistAutofillChoice(DialogSection section,
501                             const std::string& guid,
502                             int variant);
503
504  // Sets the outparams to the default AutofillDataModel for |section| (which is
505  // the first one in the menu that is a suggestion item).
506  void GetDefaultAutofillChoice(DialogSection section,
507                                std::string* guid,
508                                int* variant);
509
510  // Reads from prefs the choice of AutofillDataModel for |section|. Returns
511  // whether there was a setting to read.
512  bool GetAutofillChoice(DialogSection section,
513                         std::string* guid,
514                         int* variant);
515
516  // Calculates which AutofillDataModel variant |model| is referring to.
517  size_t GetSelectedVariantForModel(const SuggestionsMenuModel& model);
518
519  // Logs metrics when the dialog is submitted.
520  void LogOnFinishSubmitMetrics();
521
522  // Logs metrics when the dialog is canceled.
523  void LogOnCancelMetrics();
524
525  // Logs metrics when the edit ui is shown for the given |section|.
526  void LogEditUiShownMetric(DialogSection section);
527
528  // Logs metrics when a suggestion item from the given |model| is selected.
529  void LogSuggestionItemSelectedMetric(const SuggestionsMenuModel& model);
530
531  // Logs the time elapsed from when the dialog was shown to when the user could
532  // interact with it.
533  void LogDialogLatencyToShow();
534
535  // Sets the state of the autocheckout flow.
536  void SetAutocheckoutState(AutocheckoutState autocheckout_state);
537
538  // Obscures the web contents.
539  void DeemphasizeRenderView();
540
541  // Returns the metric corresponding to the user's initial state when
542  // interacting with this dialog.
543  AutofillMetrics::DialogInitialUserStateMetric GetInitialUserState() const;
544
545  // Shows an educational bubble if a new credit card was saved or the first few
546  // times an Online Wallet fronting card was generated.
547  void MaybeShowCreditCardBubble();
548
549  // The |profile| for |contents_|.
550  Profile* const profile_;
551
552  // The WebContents where the Autofill action originated.
553  content::WebContents* const contents_;
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