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