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/autocheckout_steps.h" 24 #include "components/autofill/content/browser/wallet/wallet_client.h" 25 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" 26 #include "components/autofill/content/browser/wallet/wallet_items.h" 27 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h" 28 #include "components/autofill/core/browser/autofill_manager_delegate.h" 29 #include "components/autofill/core/browser/autofill_metrics.h" 30 #include "components/autofill/core/browser/autofill_popup_delegate.h" 31 #include "components/autofill/core/browser/field_types.h" 32 #include "components/autofill/core/browser/form_structure.h" 33 #include "components/autofill/core/browser/personal_data_manager.h" 34 #include "components/autofill/core/browser/personal_data_manager_observer.h" 35 #include "content/public/browser/notification_observer.h" 36 #include "content/public/browser/notification_registrar.h" 37 #include "content/public/browser/web_contents_observer.h" 38 #include "content/public/common/ssl_status.h" 39 #include "ui/base/models/simple_menu_model.h" 40 #include "ui/base/ui_base_types.h" 41 #include "url/gurl.h" 42 43 class Profile; 44 45 namespace content { 46 class WebContents; 47 } 48 49 namespace user_prefs { 50 class PrefRegistrySyncable; 51 } 52 53 namespace autofill { 54 55 class AutofillDataModel; 56 class AutofillDialogView; 57 class AutofillPopupControllerImpl; 58 class DataModelWrapper; 59 class TestableAutofillDialogView; 60 61 namespace risk { 62 class Fingerprint; 63 } 64 65 namespace wallet { 66 class WalletSigninHelper; 67 } 68 69 // This class drives the dialog that appears when a site uses the imperative 70 // autocomplete API to fill out a form. 71 class AutofillDialogControllerImpl : 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: 82 virtual ~AutofillDialogControllerImpl(); 83 84 static base::WeakPtr<AutofillDialogControllerImpl> Create( 85 content::WebContents* contents, 86 const FormData& form_structure, 87 const GURL& source_url, 88 const DialogType dialog_type, 89 const base::Callback<void(const FormStructure*, 90 const std::string&)>& 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 virtual void AddAutocheckoutStep(AutocheckoutStepType step_type) OVERRIDE; 99 virtual void UpdateAutocheckoutStep( 100 AutocheckoutStepType step_type, 101 AutocheckoutStepStatus step_status) OVERRIDE; 102 virtual void OnAutocheckoutError() OVERRIDE; 103 virtual void OnAutocheckoutSuccess() OVERRIDE; 104 105 // Returns |view_| as a testable version of itself (if |view_| exists and 106 // actually implements |AutofillDialogView::GetTestableView()|). 107 TestableAutofillDialogView* GetTestableView(); 108 109 // AutofillDialogViewDelegate implementation. 110 virtual string16 DialogTitle() const OVERRIDE; 111 virtual string16 AccountChooserText() const OVERRIDE; 112 virtual string16 SignInLinkText() const OVERRIDE; 113 virtual string16 EditSuggestionText() const OVERRIDE; 114 virtual string16 CancelButtonText() const OVERRIDE; 115 virtual string16 ConfirmButtonText() const OVERRIDE; 116 virtual string16 SaveLocallyText() const OVERRIDE; 117 virtual string16 SaveLocallyTooltip() const OVERRIDE; 118 virtual string16 LegalDocumentsText() OVERRIDE; 119 virtual DialogSignedInState SignedInState() const OVERRIDE; 120 virtual bool ShouldShowSpinner() const OVERRIDE; 121 virtual bool ShouldOfferToSaveInChrome() const OVERRIDE; 122 virtual ui::MenuModel* MenuModelForAccountChooser() OVERRIDE; 123 virtual gfx::Image AccountChooserImage() OVERRIDE; 124 virtual bool ShouldShowDetailArea() const OVERRIDE; 125 virtual bool ShouldShowProgressBar() const OVERRIDE; 126 virtual gfx::Image ButtonStripImage() const OVERRIDE; 127 virtual int GetDialogButtons() const OVERRIDE; 128 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; 129 virtual DialogOverlayState GetDialogOverlay() const OVERRIDE; 130 virtual const std::vector<ui::Range>& LegalDocumentLinks() OVERRIDE; 131 virtual bool SectionIsActive(DialogSection section) const OVERRIDE; 132 virtual const DetailInputs& RequestedFieldsForSection(DialogSection section) 133 const OVERRIDE; 134 virtual ui::ComboboxModel* ComboboxModelForAutofillType( 135 ServerFieldType type) OVERRIDE; 136 virtual ui::MenuModel* MenuModelForSection(DialogSection section) OVERRIDE; 137 virtual string16 LabelForSection(DialogSection section) const OVERRIDE; 138 virtual SuggestionState SuggestionStateForSection( 139 DialogSection section) OVERRIDE; 140 virtual void EditClickedForSection(DialogSection section) OVERRIDE; 141 virtual void EditCancelledForSection(DialogSection section) OVERRIDE; 142 virtual gfx::Image IconForField(ServerFieldType type, 143 const string16& user_input) const OVERRIDE; 144 virtual string16 InputValidityMessage(DialogSection section, 145 ServerFieldType type, 146 const string16& value) OVERRIDE; 147 virtual ValidityData InputsAreValid( 148 DialogSection section, 149 const DetailOutputMap& inputs, 150 ValidationType validation_type) OVERRIDE; 151 virtual void UserEditedOrActivatedInput(DialogSection section, 152 const DetailInput* input, 153 gfx::NativeView parent_view, 154 const gfx::Rect& content_bounds, 155 const string16& field_contents, 156 bool was_edit) OVERRIDE; 157 virtual bool HandleKeyPressEventInInput( 158 const content::NativeWebKeyboardEvent& event) OVERRIDE; 159 virtual void FocusMoved() OVERRIDE; 160 virtual gfx::Image SplashPageImage() const OVERRIDE; 161 virtual void ViewClosed() OVERRIDE; 162 virtual std::vector<DialogNotification> CurrentNotifications() OVERRIDE; 163 virtual std::vector<DialogAutocheckoutStep> CurrentAutocheckoutSteps() 164 const OVERRIDE; 165 virtual void SignInLinkClicked() OVERRIDE; 166 virtual void NotificationCheckboxStateChanged(DialogNotification::Type type, 167 bool checked) OVERRIDE; 168 virtual void LegalDocumentLinkClicked(const ui::Range& range) OVERRIDE; 169 virtual void OverlayButtonPressed() OVERRIDE; 170 virtual bool OnCancel() OVERRIDE; 171 virtual bool OnAccept() OVERRIDE; 172 virtual Profile* profile() OVERRIDE; 173 virtual content::WebContents* GetWebContents() OVERRIDE; 174 175 // AutofillPopupDelegate implementation. 176 virtual void OnPopupShown(content::KeyboardListener* listener) OVERRIDE; 177 virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE; 178 virtual void DidSelectSuggestion(int identifier) OVERRIDE; 179 virtual void DidAcceptSuggestion(const string16& value, 180 int identifier) OVERRIDE; 181 virtual void RemoveSuggestion(const string16& value, 182 int identifier) OVERRIDE; 183 virtual void ClearPreviewedForm() OVERRIDE; 184 185 // content::NotificationObserver implementation. 186 virtual void Observe(int type, 187 const content::NotificationSource& source, 188 const content::NotificationDetails& details) OVERRIDE; 189 190 // SuggestionsMenuModelDelegate implementation. 191 virtual void SuggestionItemSelected(SuggestionsMenuModel* model, 192 size_t index) OVERRIDE; 193 194 // wallet::WalletClientDelegate implementation. 195 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE; 196 virtual DialogType GetDialogType() const OVERRIDE; 197 virtual std::string GetRiskData() const OVERRIDE; 198 virtual std::string GetWalletCookieValue() const OVERRIDE; 199 virtual bool IsShippingAddressRequired() const OVERRIDE; 200 virtual void OnDidAcceptLegalDocuments() OVERRIDE; 201 virtual void OnDidAuthenticateInstrument(bool success) OVERRIDE; 202 virtual void OnDidGetFullWallet( 203 scoped_ptr<wallet::FullWallet> full_wallet) OVERRIDE; 204 virtual void OnDidGetWalletItems( 205 scoped_ptr<wallet::WalletItems> wallet_items) OVERRIDE; 206 virtual void OnDidSaveToWallet( 207 const std::string& instrument_id, 208 const std::string& address_id, 209 const std::vector<wallet::RequiredAction>& required_actions, 210 const std::vector<wallet::FormFieldError>& form_field_errors) OVERRIDE; 211 virtual void OnWalletError( 212 wallet::WalletClient::ErrorType error_type) OVERRIDE; 213 214 // PersonalDataManagerObserver implementation. 215 virtual void OnPersonalDataChanged() OVERRIDE; 216 217 // AccountChooserModelDelegate implementation. 218 virtual void AccountChoiceChanged() OVERRIDE; 219 virtual void UpdateAccountChooserView() OVERRIDE; 220 221 // wallet::WalletSigninHelperDelegate implementation. 222 virtual void OnPassiveSigninSuccess(const std::string& username) OVERRIDE; 223 virtual void OnPassiveSigninFailure( 224 const GoogleServiceAuthError& error) OVERRIDE; 225 virtual void OnUserNameFetchSuccess(const std::string& username) OVERRIDE; 226 virtual void OnUserNameFetchFailure( 227 const GoogleServiceAuthError& error) OVERRIDE; 228 virtual void OnDidFetchWalletCookieValue( 229 const std::string& cookie_value) OVERRIDE; 230 231 DialogType dialog_type() const { return dialog_type_; } 232 233 protected: 234 // Exposed for testing. 235 AutofillDialogControllerImpl( 236 content::WebContents* contents, 237 const FormData& form_structure, 238 const GURL& source_url, 239 const DialogType dialog_type, 240 const base::Callback<void(const FormStructure*, 241 const std::string&)>& 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 AutocheckoutState autocheckout_state() const { return autocheckout_state_; } 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 private: 297 // Whether or not the current request wants credit info back. 298 bool RequestingCreditCardInfo() const; 299 300 // Initializes or updates |suggested_email_| et al. 301 void SuggestionsUpdated(); 302 303 // Whether the user's wallet items have at least one address and instrument. 304 bool HasCompleteWallet() const; 305 306 // Starts fetching the wallet items from Online Wallet. 307 void GetWalletItems(); 308 309 // Stop showing sign in flow. 310 void HideSignIn(); 311 312 // Handles the SignedInState() on Wallet or sign-in state update. 313 // Triggers the user name fetch and passive sign-in. 314 void SignedInStateUpdated(); 315 316 // Refreshes the model on Wallet or sign-in state update. 317 void OnWalletOrSigninUpdate(); 318 319 // Called when a Save or Update call to Wallet has validation errors. 320 void OnWalletFormFieldError( 321 const std::vector<wallet::FormFieldError>& form_field_errors); 322 323 // Calculates |legal_documents_text_| and |legal_document_link_ranges_| if 324 // they have not already been calculated. 325 void EnsureLegalDocumentsText(); 326 327 // Clears previously entered manual input and removes |section| from 328 // |section_editing_state_|. Does not update the view. 329 void ResetSectionInput(DialogSection section); 330 331 // Force |section| into edit mode if the current suggestion is invalid. 332 void ShowEditUiIfBadSuggestion(DialogSection section); 333 334 // Whether the |value| of |input| should be preserved on account change. 335 bool InputWasEdited(ServerFieldType type, 336 const base::string16& value); 337 338 // Takes a snapshot of the newly inputted user data in |view_| (if it exists). 339 DetailOutputMap TakeUserInputSnapshot(); 340 341 // Fills the detail inputs from a previously taken user input snapshot. Does 342 // not update the view. 343 void RestoreUserInputFromSnapshot(const DetailOutputMap& snapshot); 344 345 // Tells the view to update |section|. 346 void UpdateSection(DialogSection section); 347 348 // Tells |view_| to update the validity status of its detail inputs (if 349 // |view_| is non-null). Currently this is used solely for highlighting 350 // invalid suggestions, so if no sections are based on existing data, 351 // |view_->UpdateForErrors()| is not called. 352 void UpdateForErrors(); 353 354 // Creates a DataModelWrapper item for the item that's checked in the 355 // suggestion model for |section|. This may represent Autofill 356 // data or Wallet data, depending on whether Wallet is currently enabled. 357 scoped_ptr<DataModelWrapper> CreateWrapper(DialogSection section); 358 359 // Helper to return the current Wallet instrument or address. If the dialog 360 // isn't using Wallet or the user is adding a new instrument or address, NULL 361 // will be returned. 362 const wallet::WalletItems::MaskedInstrument* ActiveInstrument() const; 363 const wallet::Address* ActiveShippingAddress() const; 364 365 // Fills in |section|-related fields in |output_| according to the state of 366 // |view_|. 367 void FillOutputForSection(DialogSection section); 368 // As above, but uses |compare| to determine whether a DetailInput matches 369 // a field. Saves any new Autofill data to the PersonalDataManager. 370 void FillOutputForSectionWithComparator(DialogSection section, 371 const InputFieldComparator& compare); 372 373 // Returns whether |form_structure|_| has any fields that match the fieldset 374 // represented by |section|. 375 bool FormStructureCaresAboutSection(DialogSection section) const; 376 377 // Sets the CVC result on |form_structure_| to the value in |cvc|. 378 void SetCvcResult(const string16& cvc); 379 380 // Gets the value for |type| in |section|, whether it comes from manual user 381 // input or the active suggestion. 382 string16 GetValueFromSection(DialogSection section, 383 ServerFieldType type); 384 385 // Saves the data in |profile| to the personal data manager. This may add 386 // a new profile or tack onto an existing profile. 387 void SaveProfileGleanedFromSection(const AutofillProfile& profile, 388 DialogSection section); 389 390 // Gets the SuggestionsMenuModel for |section|. 391 SuggestionsMenuModel* SuggestionsMenuModelForSection(DialogSection section); 392 const SuggestionsMenuModel* SuggestionsMenuModelForSection( 393 DialogSection section) const; 394 // And the reverse. 395 DialogSection SectionForSuggestionsMenuModel( 396 const SuggestionsMenuModel& model); 397 398 // Suggested text and icons for sections. Suggestion text is used to show an 399 // abidged overview of the currently used suggestion. Extra text is used when 400 // part of a section is suggested but part must be manually input (e.g. during 401 // a CVC challenge or when using Autofill's CC section [never stores CVC]). 402 bool SuggestionTextForSection(DialogSection section, 403 base::string16* vertically_compact, 404 base::string16* horizontally_compact); 405 string16 RequiredActionTextForSection(DialogSection section) const; 406 gfx::Image SuggestionIconForSection(DialogSection section); 407 string16 ExtraSuggestionTextForSection(DialogSection section) const; 408 gfx::Image ExtraSuggestionIconForSection(DialogSection section) const; 409 410 // Loads profiles that can suggest data for |type|. |field_contents| is the 411 // part the user has already typed. |inputs| is the rest of section. 412 // Identifying info is loaded into the last three outparams as well as 413 // |popup_guids_|. 414 void GetProfileSuggestions( 415 ServerFieldType type, 416 const string16& field_contents, 417 const DetailInputs& inputs, 418 std::vector<string16>* popup_values, 419 std::vector<string16>* popup_labels, 420 std::vector<string16>* popup_icons); 421 422 // Like RequestedFieldsForSection, but returns a pointer. 423 DetailInputs* MutableRequestedFieldsForSection(DialogSection section); 424 425 // Hides |popup_controller_|'s popup view, if it exists. 426 void HidePopup(); 427 428 // Set whether the currently editing |section| was originally based on 429 // existing Wallet or Autofill data. 430 void SetEditingExistingData(DialogSection section, bool editing); 431 432 // Whether the user has chosen to enter all new data in at least one section. 433 bool IsManuallyEditingAnySection() const; 434 435 // Returns validity message for a given credit card number. 436 base::string16 CreditCardNumberValidityMessage( 437 const base::string16& number) const; 438 439 // Whether a particular DetailInput in |section| should be edited or not. 440 bool InputIsEditable(const DetailInput& input, DialogSection section) const; 441 442 // Whether all of the input fields currently showing in the dialog have valid 443 // contents. 444 bool AllSectionsAreValid(); 445 446 // Whether all of the input fields currently showing in the given |section| of 447 // the dialog have valid contents. 448 bool SectionIsValid(DialogSection section); 449 450 // Whether the currently active credit card expiration date is valid. 451 bool IsCreditCardExpirationValid(const base::string16& year, 452 const base::string16& month) const; 453 454 // Returns true if |key| refers to a suggestion, as opposed to some control 455 // menu item. 456 bool IsASuggestionItemKey(const std::string& key) const; 457 458 // Whether the billing section should be used to fill in the shipping details. 459 bool ShouldUseBillingForShipping(); 460 461 // Whether the user wishes to save information locally to Autofill. 462 bool ShouldSaveDetailsLocally(); 463 464 // Change whether the controller is currently submitting details to Autofill 465 // or Online Wallet (|is_submitting_|) and update the view. 466 void SetIsSubmitting(bool submitting); 467 468 // Whether the user has accepted all the current legal documents' terms. 469 bool AreLegalDocumentsCurrent() const; 470 471 // Accepts any pending legal documents now that the user has pressed Submit. 472 void AcceptLegalDocuments(); 473 474 // Start the submit proccess to interact with Online Wallet (might do various 475 // things like accept documents, save details, update details, respond to 476 // required actions, etc.). 477 void SubmitWithWallet(); 478 479 // Creates an instrument based on |views_|' contents. 480 scoped_ptr<wallet::Instrument> CreateTransientInstrument(); 481 482 // Creates an address based on the contents of |view_|. 483 scoped_ptr<wallet::Address> CreateTransientAddress(); 484 485 // Gets a full wallet from Online Wallet so the user can purchase something. 486 // This information is decoded to reveal a fronting (proxy) card. 487 void GetFullWallet(); 488 489 // Updates the state of the controller and |view_| based on any required 490 // actions returned by Save or Update calls to Wallet. 491 void HandleSaveOrUpdateRequiredActions( 492 const std::vector<wallet::RequiredAction>& required_actions); 493 494 // Whether submission is currently waiting for |action| to be handled. 495 bool IsSubmitPausedOn(wallet::RequiredAction action) const; 496 497 // Called when there's nothing left to accept, update, save, or authenticate 498 // in order to fill |form_structure_| and pass data back to the invoking page. 499 void FinishSubmit(); 500 501 // Writes to prefs the choice of AutofillDataModel for |section|. 502 void PersistAutofillChoice(DialogSection section, 503 const std::string& guid, 504 int variant); 505 506 // Sets the outparams to the default AutofillDataModel for |section| (which is 507 // the first one in the menu that is a suggestion item). 508 void GetDefaultAutofillChoice(DialogSection section, 509 std::string* guid, 510 int* variant); 511 512 // Reads from prefs the choice of AutofillDataModel for |section|. Returns 513 // whether there was a setting to read. 514 bool GetAutofillChoice(DialogSection section, 515 std::string* guid, 516 int* variant); 517 518 // Calculates which AutofillDataModel variant |model| is referring to. 519 size_t GetSelectedVariantForModel(const SuggestionsMenuModel& model); 520 521 // Logs metrics when the dialog is submitted. 522 void LogOnFinishSubmitMetrics(); 523 524 // Logs metrics when the dialog is canceled. 525 void LogOnCancelMetrics(); 526 527 // Logs metrics when the edit ui is shown for the given |section|. 528 void LogEditUiShownMetric(DialogSection section); 529 530 // Logs metrics when a suggestion item from the given |model| is selected. 531 void LogSuggestionItemSelectedMetric(const SuggestionsMenuModel& model); 532 533 // Logs the time elapsed from when the dialog was shown to when the user could 534 // interact with it. 535 void LogDialogLatencyToShow(); 536 537 // Sets the state of the autocheckout flow. 538 void SetAutocheckoutState(AutocheckoutState autocheckout_state); 539 540 // Obscures the web contents. 541 void DeemphasizeRenderView(); 542 543 // Returns the metric corresponding to the user's initial state when 544 // interacting with this dialog. 545 AutofillMetrics::DialogInitialUserStateMetric GetInitialUserState() const; 546 547 // Shows an educational bubble if a new credit card was saved or the first few 548 // times an Online Wallet fronting card was generated. 549 void MaybeShowCreditCardBubble(); 550 551 // The |profile| for |contents_|. 552 Profile* const profile_; 553 554 // For logging UMA metrics. 555 const AutofillMetrics metric_logger_; 556 base::Time dialog_shown_timestamp_; 557 AutofillMetrics::DialogInitialUserStateMetric initial_user_state_; 558 559 // The time that Autocheckout started running. Reset on error. While this is 560 // a valid time, |AutocheckoutIsRunning()| will return true. 561 base::Time autocheckout_started_timestamp_; 562 563 // Whether this is an Autocheckout or a requestAutocomplete dialog. 564 const DialogType dialog_type_; 565 566 FormStructure form_structure_; 567 568 // Whether the URL visible to the user when this dialog was requested to be 569 // invoked is the same as |source_url_|. 570 bool invoked_from_same_origin_; 571 572 // The URL of the invoking site. 573 GURL source_url_; 574 575 // The callback via which we return the collected data and, if Online Wallet 576 // was used, the Google transaction id. 577 base::Callback<void(const FormStructure*, const std::string&)> callback_; 578 579 // The AccountChooserModel acts as the MenuModel for the account chooser, 580 // and also tracks which data source the dialog is using. 581 AccountChooserModel account_chooser_model_; 582 583 // The sign-in helper to fetch the user info and perform passive sign-in. 584 // The helper is set only during fetch/sign-in, and NULL otherwise. 585 scoped_ptr<wallet::WalletSigninHelper> signin_helper_; 586 587 // A client to talk to the Online Wallet API. 588 wallet::WalletClient wallet_client_; 589 590 // Recently received items retrieved via |wallet_client_|. 591 scoped_ptr<wallet::WalletItems> wallet_items_; 592 scoped_ptr<wallet::FullWallet> full_wallet_; 593 594 // The last active instrument and shipping address object ids. These 595 // variables are only set (i.e. non-empty) when the Wallet items are being 596 // re-fetched. 597 std::string previously_selected_instrument_id_; 598 std::string previously_selected_shipping_address_id_; 599 600 // When the Wallet items were last fetched. 601 base::TimeTicks last_wallet_items_fetch_timestamp_; 602 603 // Local machine signals to pass along on each request to trigger (or 604 // discourage) risk challenges; sent if the user is up to date on legal docs. 605 std::string risk_data_; 606 607 // The text to display when the user is accepting new terms of service, etc. 608 string16 legal_documents_text_; 609 // The ranges within |legal_documents_text_| to linkify. 610 std::vector<ui::Range> legal_document_link_ranges_; 611 612 // The instrument and address IDs from the Online Wallet server to be used 613 // when getting a full wallet. 614 std::string active_instrument_id_; 615 std::string active_address_id_; 616 617 // The fields for billing and shipping which the page has actually requested. 618 DetailInputs requested_email_fields_; 619 DetailInputs requested_cc_fields_; 620 DetailInputs requested_billing_fields_; 621 DetailInputs requested_cc_billing_fields_; 622 DetailInputs requested_shipping_fields_; 623 624 // Models for the credit card expiration inputs. 625 MonthComboboxModel cc_exp_month_combobox_model_; 626 YearComboboxModel cc_exp_year_combobox_model_; 627 628 // Model for the country input. 629 CountryComboboxModel country_combobox_model_; 630 631 // Models for the suggestion views. 632 SuggestionsMenuModel suggested_email_; 633 SuggestionsMenuModel suggested_cc_; 634 SuggestionsMenuModel suggested_billing_; 635 SuggestionsMenuModel suggested_cc_billing_; 636 SuggestionsMenuModel suggested_shipping_; 637 638 // |DialogSection|s that are in edit mode that are based on existing data. 639 std::set<DialogSection> section_editing_state_; 640 641 // Whether |form_structure_| has asked for any details that would indicate 642 // we should show a shipping section. 643 bool cares_about_shipping_; 644 645 // The GUIDs for the currently showing unverified profiles popup. 646 std::vector<PersonalDataManager::GUIDPair> popup_guids_; 647 648 // The controller for the currently showing popup (which helps users when 649 // they're manually filling the dialog). 650 base::WeakPtr<AutofillPopupControllerImpl> popup_controller_; 651 652 // The input for which |popup_controller_| is currently showing a popup 653 // (if any). 654 const DetailInput* input_showing_popup_; 655 656 scoped_ptr<AutofillDialogView> view_; 657 658 // A NotificationRegistrar for tracking the completion of sign-in. 659 content::NotificationRegistrar signin_registrar_; 660 661 base::WeakPtrFactory<AutofillDialogControllerImpl> weak_ptr_factory_; 662 663 // Whether the wallet promos should be shown in the notification area. Based 664 // on whether the user has paid with Wallet or has signed into this dialog. 665 bool should_show_wallet_promo_; 666 bool has_shown_wallet_usage_confirmation_; 667 668 // Whether a user accepted legal documents while this dialog is running. 669 bool has_accepted_legal_documents_; 670 671 // True after the user first accepts the dialog and presses "Submit". May 672 // continue to be true while processing required actions. 673 bool is_submitting_; 674 675 // True if the last call to |GetFullWallet()| returned a 676 // CHOOSE_ANOTHER_INSTRUMENT_OR_ADDRESS required action, indicating that the 677 // selected instrument or address had become invalid since it was originally 678 // returned in |GetWalletItems()|. 679 bool choose_another_instrument_or_address_; 680 681 // Whether or not the server side validation errors returned by Wallet were 682 // recoverable. 683 bool wallet_server_validation_recoverable_; 684 685 // Whether |callback_| was Run() with a filled |form_structure_|. 686 bool data_was_passed_back_; 687 688 typedef std::map<ServerFieldType, 689 std::pair<base::string16, base::string16> > TypeErrorInputMap; 690 typedef std::map<DialogSection, TypeErrorInputMap> WalletValidationErrors; 691 // Wallet validation errors. section->type->(error_msg, input_value). 692 WalletValidationErrors wallet_errors_; 693 694 // The current state of the Autocheckout flow. 695 AutocheckoutState autocheckout_state_; 696 697 // Whether the latency to display to the UI was logged to UMA yet. 698 bool was_ui_latency_logged_; 699 700 // Whether or not the render view has been deemphasized. 701 bool deemphasized_render_view_; 702 703 // State of steps in the current Autocheckout flow, or empty if not an 704 // Autocheckout use case. 705 std::vector<DialogAutocheckoutStep> steps_; 706 707 // The Google Wallet cookie value, set as an authorization header on requests 708 // to Wallet. 709 std::string wallet_cookie_value_; 710 711 // Populated if the user chose to save a newly inputted credit card. Used to 712 // show a bubble as the dialog closes to confirm a user's new card info was 713 // saved. Never populated while incognito (as nothing's actually saved). 714 scoped_ptr<CreditCard> newly_saved_card_; 715 716 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerImpl); 717 }; 718 719 } // namespace autofill 720 721 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_DIALOG_CONTROLLER_IMPL_H_ 722