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