autofill_dialog_controller_impl.h revision effb81e5f8246d0db0270817048dc992db66e9fb
158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// found in the LICENSE file.
458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include <set>
958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include <vector>
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "base/callback.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/gtest_prod_util.h"
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/memory/weak_ptr.h"
15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/strings/string16.h"
16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/time/time.h"
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/autofill/account_chooser_model.h"
186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
1958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_models.h"
2058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chrome/browser/ui/autofill/country_combobox_model.h"
2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_client.h"
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_client_delegate.h"
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_items.h"
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h"
2858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "components/autofill/core/browser/autofill_manager_delegate.h"
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/autofill/core/browser/autofill_metrics.h"
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/autofill/core/browser/autofill_popup_delegate.h"
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/autofill/core/browser/field_types.h"
32effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "components/autofill/core/browser/form_structure.h"
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/autofill/core/browser/personal_data_manager.h"
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/autofill/core/browser/personal_data_manager_observer.h"
35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/browser/notification_observer.h"
3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/notification_registrar.h"
3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/browser/web_contents_observer.h"
3858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "content/public/common/ssl_status.h"
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h"
4058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/load_rules_delegate.h"
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "third_party/skia/include/core/SkColor.h"
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/base/models/simple_menu_model.h"
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/base/ui_base_types.h"
441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/gfx/animation/animation_delegate.h"
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/animation/linear_animation.h"
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "url/gurl.h"
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Profile;
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace content {
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass WebContents;
5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
5358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace autofill {
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass AutofillDataModel;
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class AutofillDialogView;
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class AutofillPopupControllerImpl;
5958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class DataModelWrapper;
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace risk {
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Fingerprint;
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace wallet {
66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class WalletSigninHelper;
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This class drives the dialog that appears when a site uses the imperative
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// autocomplete API to fill out a form.
71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class AutofillDialogControllerImpl
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    : public AutofillDialogViewDelegate,
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      public AutofillDialogController,
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      public AutofillPopupDelegate,
75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      public content::NotificationObserver,
76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      public content::WebContentsObserver,
77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      public SuggestionsMenuModelDelegate,
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      public wallet::WalletClientDelegate,
796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      public wallet::WalletSigninHelperDelegate,
806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      public PersonalDataManagerObserver,
816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      public AccountChooserModelDelegate,
82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      public gfx::AnimationDelegate,
83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      public ::i18n::addressinput::LoadRulesDelegate {
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual ~AutofillDialogControllerImpl();
8658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
87f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static base::WeakPtr<AutofillDialogControllerImpl> Create(
88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      content::WebContents* contents,
8958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const FormData& form_structure,
9058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const GURL& source_url,
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const base::Callback<void(const FormStructure*)>& callback);
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // AutofillDialogController implementation.
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void Show() OVERRIDE;
9558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void Hide() OVERRIDE;
9658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void TabActivated() OVERRIDE;
9758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
9858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // AutofillDialogViewDelegate implementation.
99f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual base::string16 DialogTitle() const OVERRIDE;
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 AccountChooserText() const OVERRIDE;
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 SignInLinkText() const OVERRIDE;
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 SpinnerText() const OVERRIDE;
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 EditSuggestionText() const OVERRIDE;
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 CancelButtonText() const OVERRIDE;
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 ConfirmButtonText() const OVERRIDE;
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 SaveLocallyText() const OVERRIDE;
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 SaveLocallyTooltip() const OVERRIDE;
108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual base::string16 LegalDocumentsText() OVERRIDE;
109f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool ShouldShowSpinner() const OVERRIDE;
110f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool ShouldShowAccountChooser() const OVERRIDE;
11158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual bool ShouldShowSignInWebView() const OVERRIDE;
11258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual GURL SignInUrl() const OVERRIDE;
11358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual bool ShouldOfferToSaveInChrome() const OVERRIDE;
1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool ShouldSaveInChrome() const OVERRIDE;
115f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual ui::MenuModel* MenuModelForAccountChooser() OVERRIDE;
11658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual gfx::Image AccountChooserImage() OVERRIDE;
11758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual gfx::Image ButtonStripImage() const OVERRIDE;
11858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual int GetDialogButtons() const OVERRIDE;
119f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual DialogOverlayState GetDialogOverlay() OVERRIDE;
12158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual const std::vector<gfx::Range>& LegalDocumentLinks() OVERRIDE;
12258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual bool SectionIsActive(DialogSection section) const OVERRIDE;
12358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual const DetailInputs& RequestedFieldsForSection(DialogSection section)
124f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const OVERRIDE;
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ui::ComboboxModel* ComboboxModelForAutofillType(
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ServerFieldType type) OVERRIDE;
127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual ui::MenuModel* MenuModelForSection(DialogSection section) OVERRIDE;
128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual base::string16 LabelForSection(DialogSection section) const OVERRIDE;
129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual SuggestionState SuggestionStateForSection(
130effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      DialogSection section) OVERRIDE;
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual FieldIconMap IconsForFields(const FieldValueMap& user_inputs)
1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const OVERRIDE;
1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool FieldControlsIcons(ServerFieldType type) const OVERRIDE;
1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 TooltipForField(ServerFieldType type) const OVERRIDE;
1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool InputIsEditable(const DetailInput& input, DialogSection section)
1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      OVERRIDE;
1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual base::string16 InputValidityMessage(DialogSection section,
1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                        ServerFieldType type,
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                        const base::string16& value) OVERRIDE;
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ValidityMessages InputsAreValid(
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      DialogSection section, const FieldValueMap& inputs) OVERRIDE;
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void UserEditedOrActivatedInput(DialogSection section,
143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                          ServerFieldType type,
144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                          gfx::NativeView parent_view,
1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const gfx::Rect& content_bounds,
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const base::string16& field_contents,
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          bool was_edit) OVERRIDE;
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool HandleKeyPressEventInInput(
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const content::NativeWebKeyboardEvent& event) OVERRIDE;
1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void FocusMoved() OVERRIDE;
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool ShouldShowErrorBubble() const OVERRIDE;
15258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void ViewClosed() OVERRIDE;
15358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual std::vector<DialogNotification> CurrentNotifications() OVERRIDE;
15458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void LinkClicked(const GURL& url) OVERRIDE;
15558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  virtual void SignInLinkClicked() OVERRIDE;
156f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void NotificationCheckboxStateChanged(DialogNotification::Type type,
157f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                bool checked) OVERRIDE;
158f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void LegalDocumentLinkClicked(const gfx::Range& range) OVERRIDE;
159f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool OnCancel() OVERRIDE;
160f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool OnAccept() OVERRIDE;
161f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual Profile* profile() OVERRIDE;
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual content::WebContents* GetWebContents() OVERRIDE;
163effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // AutofillPopupDelegate implementation.
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnPopupShown() OVERRIDE;
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnPopupHidden() OVERRIDE;
167f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool ShouldRepostEvent(const ui::MouseEvent& event) OVERRIDE;
168f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void DidSelectSuggestion(const base::string16& value,
169f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                   int identifier) OVERRIDE;
170f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void DidAcceptSuggestion(const base::string16& value,
171f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                   int identifier) OVERRIDE;
172f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void RemoveSuggestion(const base::string16& value,
173f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                int identifier) OVERRIDE;
174f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void ClearPreviewedForm() OVERRIDE;
175f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
176f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // content::NotificationObserver implementation.
177f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void Observe(int type,
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       const content::NotificationSource& source,
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
180effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // SuggestionsMenuModelDelegate implementation.
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SuggestionsMenuWillShow() OVERRIDE;
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SuggestionItemSelected(SuggestionsMenuModel* model,
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                      size_t index) OVERRIDE;
185f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
186f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // wallet::WalletClientDelegate implementation.
187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE;
188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual std::string GetRiskData() const OVERRIDE;
189f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual std::string GetWalletCookieValue() const OVERRIDE;
190f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool IsShippingAddressRequired() const OVERRIDE;
191f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void OnDidAcceptLegalDocuments() OVERRIDE;
192f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void OnDidAuthenticateInstrument(bool success) OVERRIDE;
193f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void OnDidGetFullWallet(
194f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      scoped_ptr<wallet::FullWallet> full_wallet) OVERRIDE;
195f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void OnDidGetWalletItems(
196f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      scoped_ptr<wallet::WalletItems> wallet_items) OVERRIDE;
197f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void OnDidSaveToWallet(
19858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const std::string& instrument_id,
19958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const std::string& address_id,
20058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const std::vector<wallet::RequiredAction>& required_actions,
20158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE;
202  virtual void OnWalletError(
203      wallet::WalletClient::ErrorType error_type) OVERRIDE;
204
205  // PersonalDataManagerObserver implementation.
206  virtual void OnPersonalDataChanged() OVERRIDE;
207
208  // AccountChooserModelDelegate implementation.
209  virtual void AccountChooserWillShow() OVERRIDE;
210  virtual void AccountChoiceChanged() OVERRIDE;
211  virtual void AddAccount() OVERRIDE;
212  virtual void UpdateAccountChooserView() OVERRIDE;
213
214  // wallet::WalletSigninHelperDelegate implementation.
215  virtual void OnPassiveSigninSuccess() OVERRIDE;
216  virtual void OnPassiveSigninFailure(
217      const GoogleServiceAuthError& error) OVERRIDE;
218  virtual void OnDidFetchWalletCookieValue(
219      const std::string& cookie_value) OVERRIDE;
220
221  // gfx::AnimationDelegate implementation.
222  virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
223  virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
224
225  // ::i18n::addressinput::LoadRulesDelegate implementation.
226  virtual void OnAddressValidationRulesLoaded(const std::string& country_code,
227                                              bool success) OVERRIDE;
228
229 protected:
230  enum DialogSignedInState {
231    NOT_CHECKED,
232    REQUIRES_RESPONSE,
233    REQUIRES_SIGN_IN,
234    REQUIRES_PASSIVE_SIGN_IN,
235    SIGNED_IN,
236    SIGN_IN_DISABLED,
237  };
238
239  // Exposed for testing.
240  AutofillDialogControllerImpl(
241      content::WebContents* contents,
242      const FormData& form_structure,
243      const GURL& source_url,
244      const base::Callback<void(const FormStructure*)>& callback);
245
246  // Exposed for testing.
247  AutofillDialogView* view() { return view_.get(); }
248  virtual AutofillDialogView* CreateView();
249  ServerFieldType popup_input_type() const {
250    return popup_input_type_;
251  }
252
253  // Returns the PersonalDataManager for |profile_|.
254  virtual PersonalDataManager* GetManager() const;
255
256  // Returns an address validation helper. May be NULL during tests.
257  virtual ::i18n::addressinput::AddressValidator* GetValidator();
258
259  // Returns the WalletClient* this class uses to talk to Online Wallet. Exposed
260  // for testing.
261  const wallet::WalletClient* GetWalletClient() const;
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  // The active billing section for the current state of the dialog (e.g. when
281  // paying for wallet, the combined credit card + billing address section).
282  DialogSection ActiveBillingSection() const;
283
284  // Whether |section| was sent into edit mode based on existing data. This
285  // happens when a user clicks "Edit" or a suggestion is invalid.
286  virtual bool IsEditingExistingData(DialogSection section) const;
287
288  // Whether the user has chosen to enter all new data in |section|. This
289  // happens via choosing "Add a new X..." from a section's suggestion menu.
290  bool IsManuallyEditingSection(DialogSection section) const;
291
292  // Should be called on the Wallet sign-in error.
293  virtual void OnWalletSigninError();
294
295  // Whether submission is currently waiting for |action| to be handled.
296  bool IsSubmitPausedOn(wallet::RequiredAction action) const;
297
298  // Shows a new credit card saved bubble and passes ownership of |new_card| and
299  // |billing_profile| to the bubble. Exposed for testing.
300  virtual void ShowNewCreditCardBubble(
301      scoped_ptr<CreditCard> new_card,
302      scoped_ptr<AutofillProfile> billing_profile);
303
304  // Called when there's nothing left to accept, update, save, or authenticate
305  // in order to fill |form_structure_| and pass data back to the invoking page.
306  void DoFinishSubmit();
307
308  // Delays enabling submit button for a short period of time. Exposed for
309  // testing.
310  virtual void SubmitButtonDelayBegin();
311
312  // Ends the delay for enabling the submit button. Called only from tests.
313  // Without this method, the tests would have to wait for the delay timer to
314  // finish, which would be flaky.
315  void SubmitButtonDelayEndForTesting();
316
317  // Resets |last_wallet_items_fetch_timestamp_| for testing.
318  void ClearLastWalletItemsFetchTimestampForTesting();
319
320  // Allows tests to inspect the state of the account chooser.
321  AccountChooserModel* AccountChooserModelForTesting();
322
323  // Returns whether |url| matches the sign in continue URL. If so, also fills
324  // in |user_index| with the index of the user account that just signed in.
325  virtual bool IsSignInContinueUrl(const GURL& url, size_t* user_index) const;
326
327  // Whether the user is known to be signed in.
328  DialogSignedInState SignedInState() const;
329
330 private:
331  FRIEND_TEST_ALL_PREFIXES(AutofillDialogControllerI18nTest,
332                           CorrectCountryFromInputs);
333
334  // Initializes or updates |suggested_cc_| et al.
335  void SuggestionsUpdated();
336
337  // Starts fetching the wallet items from Online Wallet.
338  void GetWalletItems();
339
340  // Stop showing sign in flow.
341  void HideSignIn();
342
343  // Handles the SignedInState() on Wallet or sign-in state update.
344  // Triggers the user name fetch and passive sign-in.
345  void SignedInStateUpdated();
346
347  // Refreshes the model on Wallet or sign-in state update.
348  void OnWalletOrSigninUpdate();
349
350  // Called when a Save or Update call to Wallet has validation errors.
351  void OnWalletFormFieldError(
352      const std::vector<wallet::FormFieldError>& form_field_errors);
353
354  // Calculates |legal_documents_text_| and |legal_document_link_ranges_|.
355  void ConstructLegalDocumentsText();
356
357  // Clears previously entered manual input and removes |section| from
358  // |section_editing_state_|. Does not update the view.
359  void ResetSectionInput(DialogSection section);
360
361  // Force |section| into edit mode if the current suggestion is invalid.
362  void ShowEditUiIfBadSuggestion(DialogSection section);
363
364  // Whether the |value| of |input| should be preserved on account change.
365  bool InputWasEdited(ServerFieldType type,
366                      const base::string16& value);
367
368  // Takes a snapshot of the newly inputted user data in |view_| (if it exists).
369  FieldValueMap TakeUserInputSnapshot();
370
371  // Fills the detail inputs from a previously taken user input snapshot. Does
372  // not update the view.
373  void RestoreUserInputFromSnapshot(const FieldValueMap& snapshot);
374
375  // Tells the view to update |section|.
376  void UpdateSection(DialogSection section);
377
378  // Tells |view_| to update the validity status of its detail inputs (if
379  // |view_| is non-null). Currently this is used solely for highlighting
380  // invalid suggestions, so if no sections are based on existing data,
381  // |view_->UpdateForErrors()| is not called.
382  void UpdateForErrors();
383
384  // Renders and returns one frame of the generated card animation.
385  gfx::Image GetGeneratedCardImage(const base::string16& card_number,
386                                   const base::string16& name,
387                                   const SkColor& gradient_top,
388                                   const SkColor& gradient_bottom);
389
390  // Kicks off |card_scrambling_refresher_|.
391  void StartCardScramblingRefresher();
392
393  // Changes |scrambled_card_number_| and pushes an update to the view.
394  void RefreshCardScramblingOverlay();
395
396  // Tells the view to update the overlay.
397  void PushOverlayUpdate();
398
399  // Creates a DataModelWrapper item for the item that's checked in the
400  // suggestion model for |section|. This may represent Autofill
401  // data or Wallet data, depending on whether Wallet is currently enabled.
402  scoped_ptr<DataModelWrapper> CreateWrapper(DialogSection section);
403
404  // Helper to return the current Wallet instrument or address. If the dialog
405  // isn't using Wallet or the user is adding a new instrument or address, NULL
406  // will be returned.
407  const wallet::WalletItems::MaskedInstrument* ActiveInstrument() const;
408  const wallet::Address* ActiveShippingAddress() const;
409
410  // Fills in |section|-related fields in |output_| according to the state of
411  // |view_|.
412  void FillOutputForSection(DialogSection section);
413  // As above, but uses |compare| to determine whether a DetailInput matches
414  // a field. Saves any new Autofill data to the PersonalDataManager.
415  void FillOutputForSectionWithComparator(
416      DialogSection section,
417      const FormStructure::InputFieldComparator& compare);
418
419  // Returns whether |form_structure|_| has any fields that match the fieldset
420  // represented by |section|.
421  bool FormStructureCaresAboutSection(DialogSection section) const;
422
423  // Finds all fields of the given |type| in |form_structure_|, if any, and sets
424  // each field's value to |output|.
425  void SetOutputForFieldsOfType(ServerFieldType type,
426                                const base::string16& output);
427
428  // Gets the value for |type| in |section|, whether it comes from manual user
429  // input or the active suggestion.
430  base::string16 GetValueFromSection(DialogSection section,
431                                     ServerFieldType type);
432
433  // Returns whether the given section can accept an address with the given
434  // country code.
435  bool CanAcceptCountry(DialogSection section, const std::string& country_code);
436
437  // Whether |profile| should be suggested for |section|.
438  bool ShouldSuggestProfile(DialogSection section,
439                            const AutofillProfile& profile);
440
441  // Gets the SuggestionsMenuModel for |section|.
442  SuggestionsMenuModel* SuggestionsMenuModelForSection(DialogSection section);
443  const SuggestionsMenuModel* SuggestionsMenuModelForSection(
444      DialogSection section) const;
445  // And the reverse.
446  DialogSection SectionForSuggestionsMenuModel(
447      const SuggestionsMenuModel& model);
448
449  // Gets the CountryComboboxModel for |section|.
450  CountryComboboxModel* CountryComboboxModelForSection(DialogSection section);
451
452  // Clears and builds the inputs in |section| for |country_name|.
453  // When |should_clobber| is false, and the view's country value matches
454  // |country_name|, the inputs won't be rebuilt.
455  bool RebuildInputsForCountry(DialogSection section,
456                               const base::string16& country_name,
457                               bool should_clobber);
458
459  // Suggested text and icons for sections. Suggestion text is used to show an
460  // abridged overview of the currently used suggestion. Extra text is used when
461  // part of a section is suggested but part must be manually input (e.g. during
462  // a CVC challenge or when using Autofill's CC section [never stores CVC]).
463  bool SuggestionTextForSection(DialogSection section,
464                                base::string16* vertically_compact,
465                                base::string16* horizontally_compact);
466  base::string16 RequiredActionTextForSection(DialogSection section) const;
467  gfx::Image SuggestionIconForSection(DialogSection section);
468  base::string16 ExtraSuggestionTextForSection(DialogSection section) const;
469  gfx::Image ExtraSuggestionIconForSection(DialogSection section);
470
471  // Suggests address completions using the downloaded i18n validation rules.
472  // Stores the suggestions in |i18n_validator_suggestions_|.
473  void GetI18nValidatorSuggestions(DialogSection section,
474                                   ServerFieldType type,
475                                   std::vector<base::string16>* popup_values,
476                                   std::vector<base::string16>* popup_labels,
477                                   std::vector<base::string16>* popup_icons);
478
479  // Like RequestedFieldsForSection, but returns a pointer.
480  DetailInputs* MutableRequestedFieldsForSection(DialogSection section);
481
482  // Returns just the |type| attributes of RequestedFieldsForSection(section).
483  std::vector<ServerFieldType> RequestedTypesForSection(DialogSection section)
484      const;
485
486  // Returns the country code (e.g. "US") for |section|.
487  std::string CountryCodeForSection(DialogSection section);
488
489  // Hides |popup_controller_|'s popup view, if it exists.
490  void HidePopup();
491
492  // Set whether the currently editing |section| was originally based on
493  // existing Wallet or Autofill data.
494  void SetEditingExistingData(DialogSection section, bool editing);
495
496  // Whether the user has chosen to enter all new data in at least one section.
497  bool IsManuallyEditingAnySection() const;
498
499  // Returns validity message for a given credit card number.
500  base::string16 CreditCardNumberValidityMessage(
501      const base::string16& number) const;
502
503  // Whether all of the input fields currently showing in the dialog have valid
504  // contents. This validates only by checking "sure" messages, i.e. messages
505  // that would have been displayed to the user during editing, as opposed to
506  // submission.
507  bool AllSectionsAreValid();
508
509  // Whether all of the input fields currently showing in the given |section| of
510  // the dialog have valid contents. This validates only by checking "sure"
511  // messages - see AllSectionsAreValid.
512  bool SectionIsValid(DialogSection section);
513
514  // Whether validation rules for |section| are loaded.
515  bool RulesAreLoaded(DialogSection section);
516
517  // Whether the currently active credit card expiration date is valid.
518  bool IsCreditCardExpirationValid(const base::string16& year,
519                                   const base::string16& month) const;
520
521  // Returns true if |profile| has an address we can be sure is invalid.
522  // Profiles with invalid addresses are not suggested in the dropdown menu for
523  // billing and shipping addresses.
524  bool HasInvalidAddress(const AutofillProfile& profile);
525
526  // Returns true if |key| refers to a suggestion, as opposed to some control
527  // menu item.
528  bool IsASuggestionItemKey(const std::string& key) const;
529
530  // Returns whether Autofill is enabled for |profile_|.
531  bool IsAutofillEnabled() const;
532
533  // Whether the billing section should be used to fill in the shipping details.
534  bool ShouldUseBillingForShipping();
535
536  // Whether the user wishes to save information locally to Autofill.
537  bool ShouldSaveDetailsLocally();
538
539  // Change whether the controller is currently submitting details to Autofill
540  // or Online Wallet (|is_submitting_|) and update the view.
541  void SetIsSubmitting(bool submitting);
542
543  // Whether the user has accepted all the current legal documents' terms.
544  bool AreLegalDocumentsCurrent() const;
545
546  // Accepts any pending legal documents now that the user has pressed Submit.
547  void AcceptLegalTerms();
548
549  // Start the submit proccess to interact with Online Wallet (might do various
550  // things like accept documents, save details, update details, respond to
551  // required actions, etc.).
552  void SubmitWithWallet();
553
554  // Creates an instrument based on |views_|' contents.
555  scoped_ptr<wallet::Instrument> CreateTransientInstrument();
556
557  // Creates an address based on the contents of |view_|.
558  scoped_ptr<wallet::Address> CreateTransientAddress();
559
560  // Gets a full wallet from Online Wallet so the user can purchase something.
561  // This information is decoded to reveal a fronting (proxy) card.
562  void GetFullWallet();
563
564  // Updates the state of the controller and |view_| based on any required
565  // actions returned by Save or Update calls to Wallet.
566  void HandleSaveOrUpdateRequiredActions(
567      const std::vector<wallet::RequiredAction>& required_actions);
568
569  // Shows a card generation overlay if necessary, then calls DoFinishSubmit.
570  void FinishSubmit();
571
572  // Writes to prefs the choice of AutofillDataModel for |section|.
573  void PersistAutofillChoice(DialogSection section,
574                             const std::string& guid);
575
576  // Sets the outparams to the default AutofillDataModel for |section| (which is
577  // the first one in the menu that is a suggestion item).
578  void GetDefaultAutofillChoice(DialogSection section,
579                                std::string* guid);
580
581  // Reads from prefs the choice of AutofillDataModel for |section|. Returns
582  // whether there was a setting to read.
583  bool GetAutofillChoice(DialogSection section,
584                         std::string* guid);
585
586  // Logs metrics when the dialog is submitted.
587  void LogOnFinishSubmitMetrics();
588
589  // Logs metrics when the dialog is canceled.
590  void LogOnCancelMetrics();
591
592  // Logs metrics when the edit ui is shown for the given |section|.
593  void LogEditUiShownMetric(DialogSection section);
594
595  // Logs metrics when a suggestion item from the given |model| is selected.
596  void LogSuggestionItemSelectedMetric(const SuggestionsMenuModel& model);
597
598  // Logs the time elapsed from when the dialog was shown to when the user could
599  // interact with it.
600  void LogDialogLatencyToShow();
601
602  // Returns the metric corresponding to the user's initial state when
603  // interacting with this dialog.
604  AutofillMetrics::DialogInitialUserStateMetric GetInitialUserState() const;
605
606  // Shows an educational bubble if a new credit card was saved or the first few
607  // times an Online Wallet fronting card was generated.
608  void MaybeShowCreditCardBubble();
609
610  // Called when the delay for enabling the submit button ends.
611  void OnSubmitButtonDelayEnd();
612
613  // Gets the user's current Wallet cookie (gdToken) from the cookie jar.
614  void FetchWalletCookie();
615
616  // The |profile| for |contents_|.
617  Profile* const profile_;
618
619  // For logging UMA metrics.
620  const AutofillMetrics metric_logger_;
621  base::Time dialog_shown_timestamp_;
622  AutofillMetrics::DialogInitialUserStateMetric initial_user_state_;
623
624  FormStructure form_structure_;
625
626  // Whether the URL visible to the user when this dialog was requested to be
627  // invoked is the same as |source_url_|.
628  bool invoked_from_same_origin_;
629
630  // The URL of the invoking site.
631  GURL source_url_;
632
633  // The callback via which we return the collected data.
634  base::Callback<void(const FormStructure*)> callback_;
635
636  // The AccountChooserModel acts as the MenuModel for the account chooser,
637  // and also tracks which data source the dialog is using.
638  scoped_ptr<AccountChooserModel> account_chooser_model_;
639
640  // The sign-in helper to fetch the user's Wallet cookie and to perform passive
641  // sign-in. The helper is set only during fetch/sign-in, and NULL otherwise.
642  scoped_ptr<wallet::WalletSigninHelper> signin_helper_;
643
644  // A client to talk to the Online Wallet API.
645  wallet::WalletClient wallet_client_;
646
647  // A helper to validate international address input.
648  scoped_ptr< ::i18n::addressinput::AddressValidator> validator_;
649
650  // True if |this| has ever called GetWalletItems().
651  bool wallet_items_requested_;
652
653  // True when the user has clicked the "Use Wallet" link and we're waiting to
654  // figure out whether we need to ask them to actively sign in.
655  bool handling_use_wallet_link_click_;
656
657  // True when the current WalletItems has a passive auth action which was
658  // attempted and failed.
659  bool passive_failed_;
660
661  // Recently received items retrieved via |wallet_client_|.
662  scoped_ptr<wallet::WalletItems> wallet_items_;
663  scoped_ptr<wallet::FullWallet> full_wallet_;
664
665  // The default active instrument and shipping address object IDs as of the
666  // last time Wallet items were fetched. These variables are only set
667  // (i.e. non-empty) when the Wallet items are being re-fetched.
668  std::string previous_default_instrument_id_;
669  std::string previous_default_shipping_address_id_;
670  // The last active instrument and shipping address object IDs. These
671  // variables are only set (i.e. non-empty) when the Wallet items are being
672  // re-fetched.
673  std::string previously_selected_instrument_id_;
674  std::string previously_selected_shipping_address_id_;
675
676  // When the Wallet items were last fetched.
677  base::TimeTicks last_wallet_items_fetch_timestamp_;
678
679  // Local machine signals to pass along on each request to trigger (or
680  // discourage) risk challenges; sent if the user is up to date on legal docs.
681  std::string risk_data_;
682
683  // The text to display when the user is accepting new terms of service, etc.
684  base::string16 legal_documents_text_;
685  // The ranges within |legal_documents_text_| to linkify.
686  std::vector<gfx::Range> legal_document_link_ranges_;
687
688  // The instrument and address IDs from the Online Wallet server to be used
689  // when getting a full wallet.
690  std::string active_instrument_id_;
691  std::string active_address_id_;
692
693  // The fields for billing and shipping which the page has actually requested.
694  DetailInputs requested_cc_fields_;
695  DetailInputs requested_billing_fields_;
696  DetailInputs requested_cc_billing_fields_;
697  DetailInputs requested_shipping_fields_;
698
699  // Models for the credit card expiration inputs.
700  MonthComboboxModel cc_exp_month_combobox_model_;
701  YearComboboxModel cc_exp_year_combobox_model_;
702
703  // Models for country input.
704  scoped_ptr<CountryComboboxModel> billing_country_combobox_model_;
705  scoped_ptr<CountryComboboxModel> shipping_country_combobox_model_;
706
707  // Models for the suggestion views.
708  SuggestionsMenuModel suggested_cc_;
709  SuggestionsMenuModel suggested_billing_;
710  SuggestionsMenuModel suggested_cc_billing_;
711  SuggestionsMenuModel suggested_shipping_;
712
713  // |DialogSection|s that are in edit mode that are based on existing data.
714  std::set<DialogSection> section_editing_state_;
715
716  // Sections that need to be validated when their validation rules load.
717  std::set<DialogSection> needs_validation_;
718
719  // Whether |form_structure_| has asked for any details that would indicate
720  // we should show a shipping section.
721  bool cares_about_shipping_;
722
723  // The GUIDs for the currently showing unverified profiles popup.
724  std::vector<PersonalDataManager::GUIDPair> popup_guids_;
725
726  // The autofill suggestions based on downloaded i18n validation rules.
727  std::vector< ::i18n::addressinput::AddressData> i18n_validator_suggestions_;
728
729  // The controller for the currently showing popup (which helps users when
730  // they're manually filling the dialog).
731  base::WeakPtr<AutofillPopupControllerImpl> popup_controller_;
732
733  // The type of the visible Autofill popup input (or UNKNOWN_TYPE if none).
734  ServerFieldType popup_input_type_;
735
736  scoped_ptr<AutofillDialogView> view_;
737
738  // A NotificationRegistrar for tracking the completion of sign-in.
739  content::NotificationRegistrar signin_registrar_;
740
741  // Set to true when the user presses the sign in link, until we're ready to
742  // show the normal dialog again. This is used to hide the buttons while
743  // the spinner is showing after an explicit sign in.
744  bool waiting_for_explicit_sign_in_response_;
745
746  // Whether a user accepted legal documents while this dialog is running.
747  bool has_accepted_legal_documents_;
748
749  // True after the user first accepts the dialog and presses "Submit". May
750  // continue to be true while processing required actions.
751  bool is_submitting_;
752
753  // True if the last call to |GetFullWallet()| returned a
754  // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the
755  // selected instrument or address had become invalid since it was originally
756  // returned in |GetWalletItems()|.
757  bool choose_another_instrument_or_address_;
758
759  // Whether or not the server side validation errors returned by Wallet were
760  // recoverable.
761  bool wallet_server_validation_recoverable_;
762
763  // Whether |callback_| was Run() with a filled |form_structure_|.
764  bool data_was_passed_back_;
765
766  typedef std::map<ServerFieldType,
767      std::pair<base::string16, base::string16> > TypeErrorInputMap;
768  typedef std::map<DialogSection, TypeErrorInputMap> WalletValidationErrors;
769  // Wallet validation errors. section->type->(error_msg, input_value).
770  WalletValidationErrors wallet_errors_;
771
772  // The notification that describes the current wallet error, if any.
773  scoped_ptr<DialogNotification> wallet_error_notification_;
774
775  // Whether the latency to display to the UI was logged to UMA yet.
776  bool was_ui_latency_logged_;
777
778  // The Google Wallet cookie value, set as an authorization header on requests
779  // to Wallet.
780  std::string wallet_cookie_value_;
781
782  // A map from dialog sections to the GUID of a newly saved Autofill data
783  // models for that section. No entries present that don't have newly saved
784  // data models.
785  std::map<DialogSection, std::string> newly_saved_data_model_guids_;
786
787  // Populated if the user chose to save a newly inputted credit card. Used to
788  // show a bubble as the dialog closes to confirm a user's new card info was
789  // saved. Never populated while incognito (as nothing's actually saved).
790  scoped_ptr<CreditCard> newly_saved_card_;
791
792  // The last four digits of the backing card used for the current run of the
793  // dialog. Only applies to Wallet and is populated on submit.
794  base::string16 backing_card_last_four_;
795
796  // The timer that delays enabling submit button for a short period of time on
797  // startup.
798  base::OneShotTimer<AutofillDialogControllerImpl> submit_button_delay_timer_;
799
800  // The card scrambling animation displays a random number in place of an
801  // actual credit card number. This is that random number.
802  base::string16 scrambled_card_number_;
803
804  // Two timers to deal with the card scrambling animation. The first provides
805  // a one second delay before the numbers start scrambling. The second controls
806  // the rate of refresh for the number scrambling.
807  base::OneShotTimer<AutofillDialogControllerImpl> card_scrambling_delay_;
808  base::RepeatingTimer<AutofillDialogControllerImpl> card_scrambling_refresher_;
809
810  // An animation which controls the background fade when the card is done
811  // scrambling.
812  gfx::LinearAnimation card_generated_animation_;
813
814  // A username string we display in the card scrambling/generated overlay.
815  base::string16 submitted_cardholder_name_;
816
817  base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_;
818
819  DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl);
820};
821
822}  // namespace autofill
823
824#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_
825