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