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