diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-12 01:22:41 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-12 01:22:41 +0000 |
commit | 28d0021fff7a2fccb3a1b3d6289d391f85af5fcf (patch) | |
tree | e3d11d7d239cc55624943bade5bc355e1b041701 | |
parent | bca66479f9604dc2189b2c1b7badabe06ca93c11 (diff) | |
download | chromium_src-28d0021fff7a2fccb3a1b3d6289d391f85af5fcf.zip chromium_src-28d0021fff7a2fccb3a1b3d6289d391f85af5fcf.tar.gz chromium_src-28d0021fff7a2fccb3a1b3d6289d391f85af5fcf.tar.bz2 |
Clobber the requestAutocomplete dialog when autofill data changes.
BUG=none
Review URL: https://codereview.chromium.org/12231006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181807 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 62 insertions, 36 deletions
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index b75c24b..a6e86b0 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -219,6 +219,7 @@ void AutofillDialogControllerImpl::Show() { // fields. First we must figure out what the "right" fields are. view_.reset(AutofillDialogView::Create(this)); view_->Show(); + GetManager()->AddObserver(this); // Request sugar info after the view is showing to simplify code for now. wallet_client_.GetWalletItems(this); @@ -229,6 +230,10 @@ void AutofillDialogControllerImpl::Hide() { view_->Hide(); } +void AutofillDialogControllerImpl::UpdateProgressBar(double value) { + view_->UpdateProgressBar(value); +} + //////////////////////////////////////////////////////////////////////////////// // AutofillDialogController implementation. @@ -360,17 +365,11 @@ string16 AutofillDialogControllerImpl::SuggestionTextForSection( if (section == SECTION_CC) { CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); - if (!card) - return string16(); - return card->TypeAndLastFourDigits(); } - AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); - if (!profile) - return string16(); - const std::string app_locale = AutofillCountry::ApplicationLocale(); + AutofillProfile* profile = GetManager()->GetProfileByGUID(item_key); string16 comma = ASCIIToUTF16(", "); string16 label = profile->GetInfo(NAME_FULL, app_locale) + comma + profile->GetInfo(ADDRESS_HOME_LINE1, app_locale); @@ -391,11 +390,8 @@ gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( std::string item_key = suggested_cc_.GetItemKeyAt(suggested_cc_.checked_item()); - CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); - if (!card) - return gfx::Image(); - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + CreditCard* card = GetManager()->GetCreditCardByGUID(item_key); return rb.GetImageNamed(card->IconResourceId()); } @@ -417,11 +413,7 @@ void AutofillDialogControllerImpl::EditClickedForSection( FormGroup* form_group = section == SECTION_CC ? static_cast<FormGroup*>(GetManager()->GetCreditCardByGUID(guid)) : static_cast<FormGroup*>(GetManager()->GetProfileByGUID(guid)); - - // TODO(estade): we shouldn't let this happen. - if (!form_group) - return; - + DCHECK(form_group); FillInputFromFormGroup(form_group, inputs); } @@ -513,6 +505,8 @@ void AutofillDialogControllerImpl::FocusMoved() { } void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { + GetManager()->RemoveObserver(this); + if (action == ACTION_SUBMIT) { FillOutputForSection(SECTION_EMAIL); FillOutputForSection(SECTION_CC); @@ -535,10 +529,6 @@ void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { delete this; } -void AutofillDialogControllerImpl::UpdateProgressBar(double value) { - view_->UpdateProgressBar(value); -} - DialogNotification AutofillDialogControllerImpl::CurrentNotification() const { if (HasRequiredAction(wallet::VERIFY_CVV)) { return DialogNotification( @@ -585,7 +575,7 @@ content::WebContents* AutofillDialogControllerImpl::web_contents() { } //////////////////////////////////////////////////////////////////////////////// -// AutofillPopupDelegate +// AutofillPopupDelegate implementation. void AutofillDialogControllerImpl::OnPopupShown( content::KeyboardListener* listener) {} @@ -605,10 +595,7 @@ void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, static_cast<FormGroup*>(GetManager()->GetCreditCardByGUID(pair.first)) : // TODO(estade): need to use the variant, |pair.second|. static_cast<FormGroup*>(GetManager()->GetProfileByGUID(pair.first)); - - // TODO(estade): we shouldn't let this happen. - if (!form_group) - return; + DCHECK(form_group); FillInputFromFormGroup( form_group, @@ -629,7 +616,7 @@ void AutofillDialogControllerImpl::ClearPreviewedForm() { } //////////////////////////////////////////////////////////////////////////////// -// content::NotificationObserver +// content::NotificationObserver implementation. void AutofillDialogControllerImpl::Observe( int type, @@ -648,7 +635,7 @@ void AutofillDialogControllerImpl::Observe( } //////////////////////////////////////////////////////////////////////////////// -// SuggestionsMenuModelDelegate +// SuggestionsMenuModelDelegate implementation. void AutofillDialogControllerImpl::SuggestionItemSelected( const SuggestionsMenuModel& model) { @@ -658,7 +645,7 @@ void AutofillDialogControllerImpl::SuggestionItemSelected( } //////////////////////////////////////////////////////////////////////////////// -// wallet::WalletClientObserver +// wallet::WalletClientObserver implementation. void AutofillDialogControllerImpl::OnDidAcceptLegalDocuments() { NOTIMPLEMENTED(); @@ -728,6 +715,15 @@ void AutofillDialogControllerImpl::OnNetworkError(int response_code) { } //////////////////////////////////////////////////////////////////////////////// +// PersonalDataManagerObserver implementation. + +void AutofillDialogControllerImpl::OnPersonalDataChanged() { + HidePopup(); + GenerateSuggestionsModels(); + view_->ModelChanged(); +} + +//////////////////////////////////////////////////////////////////////////////// bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( const content::NativeWebKeyboardEvent& event) { @@ -767,6 +763,11 @@ bool AutofillDialogControllerImpl::HasRequiredAction( } void AutofillDialogControllerImpl::GenerateSuggestionsModels() { + suggested_cc_.Reset(); + suggested_billing_.Reset(); + suggested_email_.Reset(); + suggested_shipping_.Reset(); + PersonalDataManager* manager = GetManager(); const std::vector<CreditCard*>& cards = manager->credit_cards(); for (size_t i = 0; i < cards.size(); ++i) { @@ -824,9 +825,7 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( FormGroup* form_group = section == SECTION_CC ? static_cast<FormGroup*>(manager->GetCreditCardByGUID(guid)) : static_cast<FormGroup*>(manager->GetProfileByGUID(guid)); - // TODO(estade): we shouldn't let this happen. - if (!form_group) - return; + DCHECK(form_group); // Calculate the variant by looking at how many items come from the same // FormGroup. TODO(estade): add a test for this. diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h index 5a6bd89..012abaa 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.h @@ -14,6 +14,7 @@ #include "chrome/browser/autofill/field_types.h" #include "chrome/browser/autofill/form_structure.h" #include "chrome/browser/autofill/personal_data_manager.h" +#include "chrome/browser/autofill/personal_data_manager_observer.h" #include "chrome/browser/autofill/wallet/required_action.h" #include "chrome/browser/autofill/wallet/wallet_client.h" #include "chrome/browser/autofill/wallet/wallet_client_observer.h" @@ -46,7 +47,8 @@ class AutofillDialogControllerImpl : public AutofillDialogController, public AutofillPopupDelegate, public content::NotificationObserver, public SuggestionsMenuModelDelegate, - public wallet::WalletClientObserver { + public wallet::WalletClientObserver, + public PersonalDataManagerObserver { public: AutofillDialogControllerImpl( content::WebContents* contents, @@ -59,6 +61,10 @@ class AutofillDialogControllerImpl : public AutofillDialogController, void Show(); void Hide(); + // Updates the progress bar based on the Autocheckout progress. |value| should + // be in [0.0, 1.0]. + void UpdateProgressBar(double value); + // AutofillDialogController implementation. virtual string16 DialogTitle() const OVERRIDE; virtual string16 EditSuggestionText() const OVERRIDE; @@ -108,7 +114,7 @@ class AutofillDialogControllerImpl : public AutofillDialogController, int identifier) OVERRIDE; virtual void ClearPreviewedForm() OVERRIDE; - // content::NotificationObserver implementation: + // content::NotificationObserver implementation. virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; @@ -138,9 +144,8 @@ class AutofillDialogControllerImpl : public AutofillDialogController, virtual void OnMalformedResponse() OVERRIDE; virtual void OnNetworkError(int response_code) OVERRIDE; - // Updates the progress bar based on the Autocheckout progress. |value| should - // be in [0.0, 1.0]. - void UpdateProgressBar(double value); + // PersonalDataManagerObserver implementation. + virtual void OnPersonalDataChanged() OVERRIDE; private: // Determines whether |input| and |field| match. diff --git a/chrome/browser/ui/autofill/autofill_dialog_models.cc b/chrome/browser/ui/autofill/autofill_dialog_models.cc index 30fa0e1..a455d64 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_models.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_models.cc @@ -29,6 +29,12 @@ void SuggestionsMenuModel::AddKeyedItem( AddCheckItem(items_.size() - 1, item); } +void SuggestionsMenuModel::Reset() { + checked_item_ = 0; + items_.clear(); + Clear(); +} + std::string SuggestionsMenuModel::GetItemKeyAt(int index) const { return items_[index].first; } diff --git a/chrome/browser/ui/autofill/autofill_dialog_models.h b/chrome/browser/ui/autofill/autofill_dialog_models.h index 9c942ee..9cb3d4e 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_models.h +++ b/chrome/browser/ui/autofill/autofill_dialog_models.h @@ -38,6 +38,9 @@ class SuggestionsMenuModel : public ui::SimpleMenuModel, // Adds an item and its identifying key to the model. Keys needn't be unique. void AddKeyedItem(const std::string& key, const string16& display_label); + // Resets the model to empty. + void Reset(); + // Returns the ID key for the item at |index|. std::string GetItemKeyAt(int index) const; diff --git a/chrome/browser/ui/autofill/autofill_dialog_view.h b/chrome/browser/ui/autofill/autofill_dialog_view.h index 9ab6763..8dcea71 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_view.h +++ b/chrome/browser/ui/autofill/autofill_dialog_view.h @@ -60,6 +60,9 @@ class AutofillDialogView { // be in [0.0, 1.0]. virtual void UpdateProgressBar(double value) = 0; + // Called when the active suggestions data model changed. + virtual void ModelChanged() = 0; + // Factory function to create the dialog (implemented once per view // implementation). |controller| will own the created dialog. static AutofillDialogView* Create(AutofillDialogController* controller); diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc index c4786fb..e9d2b78 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc @@ -479,6 +479,15 @@ void AutofillDialogViews::UpdateProgressBar(double value) { autocheckout_progress_bar_->SetValue(value); } +void AutofillDialogViews::ModelChanged() { + menu_runner_.reset(); + + for (DetailGroupMap::iterator iter = detail_groups_.begin(); + iter != detail_groups_.end(); ++iter) { + UpdateDetailsGroupState(iter->second); + } +} + string16 AutofillDialogViews::GetWindowTitle() const { return controller_->DialogTitle(); } diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.h b/chrome/browser/ui/views/autofill/autofill_dialog_views.h index abc1c63..f6a3071 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.h +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.h @@ -75,6 +75,7 @@ class AutofillDialogViews : public AutofillDialogView, virtual const content::NavigationController& ShowSignIn() OVERRIDE; virtual void HideSignIn() OVERRIDE; virtual void UpdateProgressBar(double value) OVERRIDE; + virtual void ModelChanged() OVERRIDE; // views::DialogDelegate implementation: virtual string16 GetWindowTitle() const OVERRIDE; |