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