diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 23:03:38 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 23:03:38 +0000 |
commit | 1b5557e98c07abd93c5b022135dfcbd3cb5f644f (patch) | |
tree | 7a32fe8e5cb878703cc83b8e68d58dc480794fb6 | |
parent | 6730b450fb21fbb7560091b1943ed3be1c757852 (diff) | |
download | chromium_src-1b5557e98c07abd93c5b022135dfcbd3cb5f644f.zip chromium_src-1b5557e98c07abd93c5b022135dfcbd3cb5f644f.tar.gz chromium_src-1b5557e98c07abd93c5b022135dfcbd3cb5f644f.tar.bz2 |
DOMUI: Implement adding an AutoFill address.
BUG=49094
TEST=none
Review URL: http://codereview.chromium.org/3174037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57599 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autofill/autofill_common_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_profile.cc | 1 | ||||
-rw-r--r-- | chrome/browser/autofill/personal_data_manager.cc | 100 | ||||
-rw-r--r-- | chrome/browser/autofill/personal_data_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/autofill/personal_data_manager_unittest.cc | 72 | ||||
-rw-r--r-- | chrome/browser/dom_ui/autofill_edit_address_handler.cc | 53 | ||||
-rw-r--r-- | chrome/browser/dom_ui/autofill_edit_address_handler.h | 26 | ||||
-rw-r--r-- | chrome/browser/dom_ui/autofill_edit_creditcard_handler.cc | 52 | ||||
-rw-r--r-- | chrome/browser/dom_ui/autofill_edit_creditcard_handler.h | 25 | ||||
-rw-r--r-- | chrome/browser/dom_ui/autofill_options_handler.cc | 104 | ||||
-rw-r--r-- | chrome/browser/dom_ui/autofill_options_handler.h | 11 | ||||
-rw-r--r-- | chrome/browser/dom_ui/options_ui.cc | 5 | ||||
-rw-r--r-- | chrome/browser/resources/options/autofill_edit_address_overlay.js | 35 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 |
14 files changed, 194 insertions, 302 deletions
diff --git a/chrome/browser/autofill/autofill_common_unittest.cc b/chrome/browser/autofill/autofill_common_unittest.cc index 441379b..de14413 100644 --- a/chrome/browser/autofill/autofill_common_unittest.cc +++ b/chrome/browser/autofill/autofill_common_unittest.cc @@ -32,7 +32,9 @@ void SetProfileInfo(AutoFillProfile* profile, const char* address1, const char* address2, const char* city, const char* state, const char* zipcode, const char* country, const char* phone, const char* fax) { - profile->set_label(ASCIIToUTF16(label)); + // TODO(jhawkins): Remove |label|. + if (label) + profile->set_label(ASCIIToUTF16(label)); check_and_set(profile, NAME_FIRST, first_name); check_and_set(profile, NAME_MIDDLE, middle_name); check_and_set(profile, NAME_LAST, last_name); diff --git a/chrome/browser/autofill/autofill_profile.cc b/chrome/browser/autofill/autofill_profile.cc index f12b0f8..4150e69 100644 --- a/chrome/browser/autofill/autofill_profile.cc +++ b/chrome/browser/autofill/autofill_profile.cc @@ -462,7 +462,6 @@ string16 AutoFillProfile::ConstructInferredLabel( return label; } - // So we can compare AutoFillProfiles with EXPECT_EQ(). std::ostream& operator<<(std::ostream& os, const AutoFillProfile& profile) { return os diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc index 8fbfae4..e9838aa 100644 --- a/chrome/browser/autofill/personal_data_manager.cc +++ b/chrome/browser/autofill/personal_data_manager.cc @@ -246,8 +246,6 @@ void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) { std::mem_fun_ref(&AutoFillProfile::IsEmpty)), profiles->end()); - SetUniqueProfileLabels(profiles); - WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); if (!wds) return; @@ -386,6 +384,44 @@ void PersonalDataManager::SetCreditCards( FOR_EACH_OBSERVER(Observer, observers_, OnPersonalDataChanged()); } +// TODO(jhawkins): Refactor SetProfiles so this isn't so hacky. +void PersonalDataManager::AddProfile(const AutoFillProfile& profile) { + // Set to true if |profile| is merged into the profile list. + bool merged = false; + + // Don't save a web profile if the data in the profile is a subset of an + // auxiliary profile. + for (std::vector<AutoFillProfile*>::const_iterator iter = + auxiliary_profiles_.begin(); + iter != auxiliary_profiles_.end(); ++iter) { + if (profile.IsSubsetOf(**iter)) + return; + } + + std::vector<AutoFillProfile> profiles; + for (std::vector<AutoFillProfile*>::const_iterator iter = + web_profiles_.begin(); + iter != web_profiles_.end(); ++iter) { + if (profile.IsSubsetOf(**iter)) { + // In this case, the existing profile already contains all of the data + // in |profile|, so consider the profiles already merged. + merged = true; + } else if ((*iter)->IntersectionOfTypesHasEqualValues(profile)) { + // |profile| contains all of the data in this profile, plus + // more. + merged = true; + (*iter)->MergeWith(profile); + } + + profiles.push_back(**iter); + } + + if (!merged) + profiles.push_back(profile); + + SetProfiles(&profiles); +} + void PersonalDataManager::RemoveProfile(int unique_id) { // TODO(jhawkins): Refactor SetProfiles so this isn't so hacky. std::vector<AutoFillProfile> profiles(web_profiles_.size()); @@ -617,28 +653,6 @@ void PersonalDataManager::CancelPendingQuery(WebDataService::Handle* handle) { *handle = 0; } -void PersonalDataManager::SetUniqueProfileLabels( - std::vector<AutoFillProfile>* profiles) { - std::map<string16, std::vector<AutoFillProfile*> > label_map; - for (std::vector<AutoFillProfile>::iterator iter = profiles->begin(); - iter != profiles->end(); ++iter) { - label_map[iter->Label()].push_back(&(*iter)); - } - - for (std::map<string16, std::vector<AutoFillProfile*> >::iterator iter = - label_map.begin(); - iter != label_map.end(); ++iter) { - // Start at the second element because the first label should not be - // renamed. The appended label number starts at 2, because the first label - // has an implicit index of 1. - for (size_t i = 1; i < iter->second.size(); ++i) { - string16 newlabel = iter->second[i]->Label() + - base::UintToString16(static_cast<unsigned int>(i + 1)); - iter->second[i]->set_label(newlabel); - } - } -} - void PersonalDataManager::SetUniqueCreditCardLabels( std::vector<CreditCard>* credit_cards) { std::map<string16, std::vector<CreditCard*> > label_map; @@ -668,43 +682,7 @@ void PersonalDataManager::SaveImportedProfile() { if (!imported_profile_.get()) return; - // Set to true if |imported_profile_| is merged into the profile list. - bool merged = false; - - imported_profile_->set_label(ASCIIToUTF16(kUnlabeled)); - - // Don't save a web profile if the data in the profile is a subset of an - // auxiliary profile. - for (std::vector<AutoFillProfile*>::const_iterator iter = - auxiliary_profiles_.begin(); - iter != auxiliary_profiles_.end(); ++iter) { - if (imported_profile_->IsSubsetOf(**iter)) - return; - } - - std::vector<AutoFillProfile> profiles; - for (std::vector<AutoFillProfile*>::const_iterator iter = - web_profiles_.begin(); - iter != web_profiles_.end(); ++iter) { - if (imported_profile_->IsSubsetOf(**iter)) { - // In this case, the existing profile already contains all of the data - // in |imported_profile_|, so consider the profiles already merged. - merged = true; - } else if ((*iter)->IntersectionOfTypesHasEqualValues( - *imported_profile_)) { - // |imported_profile| contains all of the data in this profile, plus - // more. - merged = true; - (*iter)->MergeWith(*imported_profile_); - } - - profiles.push_back(**iter); - } - - if (!merged) - profiles.push_back(*imported_profile_); - - SetProfiles(&profiles); + AddProfile(*imported_profile_); } // TODO(jhawkins): Refactor and merge this with SaveImportedProfile. diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h index e3c9e92..53a2674 100644 --- a/chrome/browser/autofill/personal_data_manager.h +++ b/chrome/browser/autofill/personal_data_manager.h @@ -100,6 +100,9 @@ class PersonalDataManager // ID of newly-added profiles. void SetCreditCards(std::vector<CreditCard>* credit_cards); + // Adds |profile| to the web database. + void AddProfile(const AutoFillProfile& profile); + // Removes the profile represented by |unique_id|. void RemoveProfile(int unique_id); @@ -203,7 +206,6 @@ class PersonalDataManager // to the end of non-unique labels. // TODO(jhawkins): Create a new interface for labeled entities and turn these // two methods into one. - void SetUniqueProfileLabels(std::vector<AutoFillProfile>* profiles); void SetUniqueCreditCardLabels(std::vector<CreditCard>* credit_cards); // Saves |imported_profile_| to the WebDB if it exists. diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc index 5520653..76ff2b8 100644 --- a/chrome/browser/autofill/personal_data_manager_unittest.cc +++ b/chrome/browser/autofill/personal_data_manager_unittest.cc @@ -575,8 +575,8 @@ TEST_F(PersonalDataManagerTest, ImportFormData) { MessageLoop::current()->Run(); - AutoFillProfile expected(ASCIIToUTF16("Unlabeled"), 1); - autofill_unittest::SetProfileInfo(&expected, "Unlabeled", "George", NULL, + AutoFillProfile expected(string16(), 1); + autofill_unittest::SetProfileInfo(&expected, NULL, "George", NULL, "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); const std::vector<AutoFillProfile*>& results = personal_data_->profiles(); @@ -584,54 +584,6 @@ TEST_F(PersonalDataManagerTest, ImportFormData) { EXPECT_EQ(expected, *results[0]); } -TEST_F(PersonalDataManagerTest, SetUniqueProfileLabels) { - AutoFillProfile profile0(ASCIIToUTF16("Home"), 0); - profile0.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John")); - AutoFillProfile profile1(ASCIIToUTF16("Home"), 0); - profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Paul")); - AutoFillProfile profile2(ASCIIToUTF16("Home"), 0); - profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Ringo")); - AutoFillProfile profile3(ASCIIToUTF16("NotHome"), 0); - profile3.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Other")); - AutoFillProfile profile4(ASCIIToUTF16("Work"), 0); - profile4.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Ozzy")); - AutoFillProfile profile5(ASCIIToUTF16("Work"), 0); - profile5.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Dio")); - - // This will verify that the web database has been loaded and the notification - // sent out. - EXPECT_CALL(personal_data_observer_, - OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); - - // The message loop will exit when the mock observer is notified. - MessageLoop::current()->Run(); - - // Add the test profiles to the database. - std::vector<AutoFillProfile> update; - update.push_back(profile0); - update.push_back(profile1); - update.push_back(profile2); - update.push_back(profile3); - update.push_back(profile4); - update.push_back(profile5); - personal_data_->SetProfiles(&update); - - // And wait for the refresh. - EXPECT_CALL(personal_data_observer_, - OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); - - MessageLoop::current()->Run(); - - const std::vector<AutoFillProfile*>& results = personal_data_->profiles(); - ASSERT_EQ(6U, results.size()); - EXPECT_EQ(ASCIIToUTF16("Home"), results[0]->Label()); - EXPECT_EQ(ASCIIToUTF16("Home2"), results[1]->Label()); - EXPECT_EQ(ASCIIToUTF16("Home3"), results[2]->Label()); - EXPECT_EQ(ASCIIToUTF16("NotHome"), results[3]->Label()); - EXPECT_EQ(ASCIIToUTF16("Work"), results[4]->Label()); - EXPECT_EQ(ASCIIToUTF16("Work2"), results[5]->Label()); -} - TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { CreditCard credit_card0(ASCIIToUTF16("Home"), 0); credit_card0.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("John")); @@ -701,8 +653,8 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) { MessageLoop::current()->Run(); scoped_ptr<AutoFillProfile> expected( - new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1)); - autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL, + new AutoFillProfile(string16(), 1)); + autofill_unittest::SetProfileInfo(expected.get(), NULL, "George", NULL, "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); const std::vector<AutoFillProfile*>& results = personal_data_->profiles(); @@ -735,14 +687,14 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) { const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); ASSERT_EQ(2U, results2.size()); - expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1)); - autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL, + expected.reset(new AutoFillProfile(string16(), 1)); + autofill_unittest::SetProfileInfo(expected.get(), NULL, "George", NULL, "Washington", "theprez@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); EXPECT_EQ(*expected, *results2[0]); - expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled2"), 2)); - autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled2", "John", NULL, + expected.reset(new AutoFillProfile(string16(), 2)); + autofill_unittest::SetProfileInfo(expected.get(), NULL, "John", NULL, "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); EXPECT_EQ(*expected, *results2[1]); @@ -782,14 +734,14 @@ TEST_F(PersonalDataManagerTest, AggregateProfileData) { const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); ASSERT_EQ(2U, results3.size()); - expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled"), 1)); - autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled", "George", NULL, + expected.reset(new AutoFillProfile(string16(), 1)); + autofill_unittest::SetProfileInfo(expected.get(), NULL, "George", NULL, "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL); EXPECT_EQ(*expected, *results3[0]); - expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled2"), 2)); - autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled2", "John", NULL, + expected.reset(new AutoFillProfile(string16(), 2)); + autofill_unittest::SetProfileInfo(expected.get(), NULL, "John", NULL, "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); EXPECT_EQ(*expected, *results3[1]); diff --git a/chrome/browser/dom_ui/autofill_edit_address_handler.cc b/chrome/browser/dom_ui/autofill_edit_address_handler.cc deleted file mode 100644 index 37e4cc0..0000000 --- a/chrome/browser/dom_ui/autofill_edit_address_handler.cc +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/dom_ui/autofill_edit_address_handler.h" - -#include "app/l10n_util.h" -#include "base/values.h" -#include "grit/generated_resources.h" - -AutoFillEditAddressHandler::AutoFillEditAddressHandler() { -} - -AutoFillEditAddressHandler::~AutoFillEditAddressHandler() { -} - -void AutoFillEditAddressHandler::GetLocalizedValues( - DictionaryValue* localized_strings) { - DCHECK(localized_strings); - localized_strings->SetString("autoFillEditAddressTitle", - l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); - localized_strings->SetString("fullNameLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FULL_NAME)); - localized_strings->SetString("companyNameLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); - localized_strings->SetString("addrLine1Label", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)); - localized_strings->SetString("addrLine2Label", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)); - localized_strings->SetString("cityLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); - localized_strings->SetString("stateLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE)); - localized_strings->SetString("zipCodeLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE)); - localized_strings->SetString("countryLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); - localized_strings->SetString("countryLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); - localized_strings->SetString("phoneLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); - localized_strings->SetString("faxLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); - localized_strings->SetString("emailLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); - localized_strings->SetString("autoFillEditAddressApplyButton", - l10n_util::GetStringUTF16(IDS_OK)); - localized_strings->SetString("autoFillEditAddressCancelButton", - l10n_util::GetStringUTF16(IDS_CANCEL)); -} - -void AutoFillEditAddressHandler::RegisterMessages() { -} diff --git a/chrome/browser/dom_ui/autofill_edit_address_handler.h b/chrome/browser/dom_ui/autofill_edit_address_handler.h deleted file mode 100644 index 343d647..0000000 --- a/chrome/browser/dom_ui/autofill_edit_address_handler.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_DOM_UI_AUTOFILL_EDIT_ADDRESS_HANDLER_H_ -#define CHROME_BROWSER_DOM_UI_AUTOFILL_EDIT_ADDRESS_HANDLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "chrome/browser/dom_ui/options_ui.h" - -// Handler for the 'Edit Address' overlay. -class AutoFillEditAddressHandler : public OptionsPageUIHandler { - public: - AutoFillEditAddressHandler(); - virtual ~AutoFillEditAddressHandler(); - - // OptionsPageUIHandler implementation. - virtual void GetLocalizedValues(DictionaryValue* localized_strings); - virtual void RegisterMessages(); - - private: - DISALLOW_COPY_AND_ASSIGN(AutoFillEditAddressHandler); -}; - -#endif // CHROME_BROWSER_DOM_UI_AUTOFILL_EDIT_ADDRESS_HANDLER_H_ diff --git a/chrome/browser/dom_ui/autofill_edit_creditcard_handler.cc b/chrome/browser/dom_ui/autofill_edit_creditcard_handler.cc deleted file mode 100644 index cbdf24a..0000000 --- a/chrome/browser/dom_ui/autofill_edit_creditcard_handler.cc +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/dom_ui/autofill_edit_creditcard_handler.h" - -#include "app/l10n_util.h" -#include "base/values.h" -#include "grit/generated_resources.h" - -AutoFillEditCreditCardHandler::AutoFillEditCreditCardHandler() { -} - -AutoFillEditCreditCardHandler::~AutoFillEditCreditCardHandler() { -} - -void AutoFillEditCreditCardHandler::GetLocalizedValues( - DictionaryValue* localized_strings) { - DCHECK(localized_strings); - localized_strings->SetString("autoFillEditCreditCardTitle", - l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); - localized_strings->SetString("nameOnCardLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); - localized_strings->SetString("billingAddressLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_BILLING_ADDRESS)); - localized_strings->SetString("chooseExistingAddress", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CHOOSE_EXISTING_ADDRESS)); - localized_strings->SetString("creditCardNumberLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); - localized_strings->SetString("creditCardExpirationDateLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EXPIRATION_DATE)); - localized_strings->SetString("cityLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); - localized_strings->SetString("stateLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE)); - localized_strings->SetString("zipCodeLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE)); - localized_strings->SetString("countryLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); - localized_strings->SetString("countryLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); - localized_strings->SetString("phoneLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); - localized_strings->SetString("faxLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); - localized_strings->SetString("emailLabel", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); - localized_strings->SetString("autoFillEditCreditCardApplyButton", - l10n_util::GetStringUTF16(IDS_OK)); - localized_strings->SetString("autoFillEditCreditCardCancelButton", - l10n_util::GetStringUTF16(IDS_CANCEL)); -} diff --git a/chrome/browser/dom_ui/autofill_edit_creditcard_handler.h b/chrome/browser/dom_ui/autofill_edit_creditcard_handler.h deleted file mode 100644 index c987931..0000000 --- a/chrome/browser/dom_ui/autofill_edit_creditcard_handler.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_DOM_UI_AUTOFILL_EDIT_CREDITCARD_HANDLER_H_ -#define CHROME_BROWSER_DOM_UI_AUTOFILL_EDIT_CREDITCARD_HANDLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "chrome/browser/dom_ui/options_ui.h" - -// Handler for the 'Edit CreditCard' overlay. -class AutoFillEditCreditCardHandler : public OptionsPageUIHandler { - public: - AutoFillEditCreditCardHandler(); - virtual ~AutoFillEditCreditCardHandler(); - - // OptionsPageUIHandler implementation. - virtual void GetLocalizedValues(DictionaryValue* localized_strings); - - private: - DISALLOW_COPY_AND_ASSIGN(AutoFillEditCreditCardHandler); -}; - -#endif // CHROME_BROWSER_DOM_UI_AUTOFILL_EDIT_CREDITCARD_HANDLER_H_ diff --git a/chrome/browser/dom_ui/autofill_options_handler.cc b/chrome/browser/dom_ui/autofill_options_handler.cc index 4ae032c..9d872398 100644 --- a/chrome/browser/dom_ui/autofill_options_handler.cc +++ b/chrome/browser/dom_ui/autofill_options_handler.cc @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "base/logging.h" +#include "base/string16.h" #include "base/values.h" #include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/autofill/credit_card.h" @@ -51,6 +52,9 @@ void AutoFillOptionsHandler::GetLocalizedValues( l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_ADDRESS_CAPTION)); localized_strings->SetString("addCreditCardTitle", l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_CREDITCARD_CAPTION)); + + SetAddressOverlayStrings(localized_strings); + SetCreditCardOverlayStrings(localized_strings); } void AutoFillOptionsHandler::Initialize() { @@ -61,6 +65,20 @@ void AutoFillOptionsHandler::Initialize() { LoadAutoFillData(); } +void AutoFillOptionsHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback( + "addAddress", + NewCallback(this, &AutoFillOptionsHandler::AddAddress)); + + dom_ui_->RegisterMessageCallback( + "removeAddress", + NewCallback(this, &AutoFillOptionsHandler::RemoveAddress)); + + dom_ui_->RegisterMessageCallback( + "removeCreditCard", + NewCallback(this, &AutoFillOptionsHandler::RemoveCreditCard)); +} + ///////////////////////////////////////////////////////////////////////////// // PersonalDataManager::Observer implementation: void AutoFillOptionsHandler::OnPersonalDataLoaded() { @@ -71,14 +89,54 @@ void AutoFillOptionsHandler::OnPersonalDataChanged() { LoadAutoFillData(); } -void AutoFillOptionsHandler::RegisterMessages() { - dom_ui_->RegisterMessageCallback( - "removeAddress", - NewCallback(this, &AutoFillOptionsHandler::RemoveAddress)); +void AutoFillOptionsHandler::SetAddressOverlayStrings( + DictionaryValue* localized_strings) { + localized_strings->SetString("autoFillEditAddressTitle", + l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); + localized_strings->SetString("fullNameLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FULL_NAME)); + localized_strings->SetString("companyNameLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); + localized_strings->SetString("addrLine1Label", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)); + localized_strings->SetString("addrLine2Label", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)); + localized_strings->SetString("cityLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); + localized_strings->SetString("stateLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE)); + localized_strings->SetString("zipCodeLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE)); + localized_strings->SetString("countryLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); + localized_strings->SetString("countryLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); + localized_strings->SetString("phoneLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); + localized_strings->SetString("faxLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); + localized_strings->SetString("emailLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); + localized_strings->SetString("autoFillEditAddressApplyButton", + l10n_util::GetStringUTF16(IDS_OK)); + localized_strings->SetString("autoFillEditAddressCancelButton", + l10n_util::GetStringUTF16(IDS_CANCEL)); +} - dom_ui_->RegisterMessageCallback( - "removeCreditCard", - NewCallback(this, &AutoFillOptionsHandler::RemoveCreditCard)); +void AutoFillOptionsHandler::SetCreditCardOverlayStrings( + DictionaryValue* localized_strings) { + localized_strings->SetString("autoFillEditCreditCardTitle", + l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); + localized_strings->SetString("nameOnCardLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); + localized_strings->SetString("billingAddressLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_BILLING_ADDRESS)); + localized_strings->SetString("chooseExistingAddress", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CHOOSE_EXISTING_ADDRESS)); + localized_strings->SetString("creditCardNumberLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); + localized_strings->SetString("creditCardExpirationDateLabel", + l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EXPIRATION_DATE)); } void AutoFillOptionsHandler::LoadAutoFillData() { @@ -112,6 +170,38 @@ void AutoFillOptionsHandler::LoadAutoFillData() { credit_cards); } +void AutoFillOptionsHandler::AddAddress(const ListValue* args) { + if (!personal_data_->IsDataLoaded()) + return; + + AutoFillProfile profile; + string16 value; + if (args->GetString(0, &value)) + profile.SetInfo(AutoFillType(NAME_FULL), value); + if (args->GetString(1, &value)) + profile.SetInfo(AutoFillType(COMPANY_NAME), value); + if (args->GetString(2, &value)) + profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), value); + if (args->GetString(3, &value)) + profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), value); + if (args->GetString(4, &value)) + profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), value); + if (args->GetString(5, &value)) + profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), value); + if (args->GetString(6, &value)) + profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), value); + if (args->GetString(7, &value)) + profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), value); + if (args->GetString(8, &value)) + profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), value); + if (args->GetString(9, &value)) + profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), value); + if (args->GetString(10, &value)) + profile.SetInfo(AutoFillType(EMAIL_ADDRESS), value); + + personal_data_->AddProfile(profile); +} + void AutoFillOptionsHandler::RemoveAddress(const ListValue* args) { if (!personal_data_->IsDataLoaded()) return; diff --git a/chrome/browser/dom_ui/autofill_options_handler.h b/chrome/browser/dom_ui/autofill_options_handler.h index 73a1074..be70b72 100644 --- a/chrome/browser/dom_ui/autofill_options_handler.h +++ b/chrome/browser/dom_ui/autofill_options_handler.h @@ -17,17 +17,24 @@ class AutoFillOptionsHandler : public OptionsPageUIHandler, // OptionsUIHandler implementation. virtual void GetLocalizedValues(DictionaryValue* localized_strings); virtual void Initialize(); + virtual void RegisterMessages(); // PersonalDataManager::Observer implementation. virtual void OnPersonalDataLoaded(); virtual void OnPersonalDataChanged(); - virtual void RegisterMessages(); - private: + // Loads the strings for the address and credit card overlays. + void SetAddressOverlayStrings(DictionaryValue* localized_strings); + void SetCreditCardOverlayStrings(DictionaryValue* localized_strings); + // Loads AutoFill addresses and credit cards using the PersonalDataManager. void LoadAutoFillData(); + // Adds an address to the WebDatabase. Called from DOMUI. + // |args| - an associative array containing the address data. + void AddAddress(const ListValue* args); + // Removes an address from the WebDatabase. Called from DOMUI. // |args| - an integer, the unique ID of the address to remove. void RemoveAddress(const ListValue* args); diff --git a/chrome/browser/dom_ui/options_ui.cc b/chrome/browser/dom_ui/options_ui.cc index 352a45d..0b8b27e 100644 --- a/chrome/browser/dom_ui/options_ui.cc +++ b/chrome/browser/dom_ui/options_ui.cc @@ -19,8 +19,6 @@ #include "chrome/browser/dom_ui/about_page_handler.h" #include "chrome/browser/dom_ui/add_startup_page_handler.h" #include "chrome/browser/dom_ui/advanced_options_handler.h" -#include "chrome/browser/dom_ui/autofill_edit_address_handler.h" -#include "chrome/browser/dom_ui/autofill_edit_creditcard_handler.h" #include "chrome/browser/dom_ui/autofill_options_handler.h" #include "chrome/browser/dom_ui/browser_options_handler.h" #include "chrome/browser/dom_ui/clear_browser_data_handler.h" @@ -136,9 +134,6 @@ OptionsUI::OptionsUI(TabContents* contents) : DOMUI(contents) { AddOptionsPageUIHandler(localized_strings, new AddStartupPageHandler()); AddOptionsPageUIHandler(localized_strings, new AdvancedOptionsHandler()); - AddOptionsPageUIHandler(localized_strings, new AutoFillEditAddressHandler()); - AddOptionsPageUIHandler(localized_strings, - new AutoFillEditCreditCardHandler()); AddOptionsPageUIHandler(localized_strings, new AutoFillOptionsHandler()); AddOptionsPageUIHandler(localized_strings, new BrowserOptionsHandler()); AddOptionsPageUIHandler(localized_strings, new ClearBrowserDataHandler()); diff --git a/chrome/browser/resources/options/autofill_edit_address_overlay.js b/chrome/browser/resources/options/autofill_edit_address_overlay.js index 450ccb8..6cecbc8 100644 --- a/chrome/browser/resources/options/autofill_edit_address_overlay.js +++ b/chrome/browser/resources/options/autofill_edit_address_overlay.js @@ -31,6 +31,10 @@ cr.define('options', function() { $('autoFillEditAddressCancelButton').onclick = function(event) { self.dismissOverlay_(); } + $('autoFillEditAddressApplyButton').onclick = function(event) { + self.saveAddress_(); + OptionsPage.clearOverlays(); + } self.clearInputFields_(); self.connectInputEvents_(); @@ -46,6 +50,27 @@ cr.define('options', function() { }, /** + * Aggregates the values in the input fields into an associate array and + * sends the array to the AutoFill handler. + * @private + */ + saveAddress_: function() { + var address = new Array(); + address[0] = $('fullName').value; + address[1] = $('companyName').value; + address[2] = $('addrLine1').value; + address[3] = $('addrLine2').value; + address[4] = $('city').value; + address[5] = $('state').value; + address[6] = $('zipCode').value; + address[7] = $('country').value; + address[8] = $('phone').value; + address[9] = $('fax').value; + address[10] = $('email').value; + chrome.send('addAddress', address); + }, + + /** * Connects each input field to the inputFieldChanged_() method that enables * or disables the 'Ok' button based on whether all the fields are empty or * not. @@ -55,8 +80,9 @@ cr.define('options', function() { var self = this; $('fullName').oninput = $('companyName').oninput = $('addrLine1').oninput = $('addrLine2').oninput = $('city').oninput = - $('state').oninput = $('zipCode').oninput = $('phone').oninput = - $('fax').oninput = $('email').oninput = function(event) { + $('state').oninput = $('country').oninput = $('zipCode').oninput = + $('phone').oninput = $('fax').oninput = + $('email').oninput = function(event) { self.inputFieldChanged_(); } }, @@ -70,8 +96,8 @@ cr.define('options', function() { var disabled = !$('fullName').value && !$('companyName').value && !$('addrLine1').value && !$('addrLine2').value && !$('city').value && - !$('state').value && !$('zipCode').value && !$('phone').value && - !$('fax').value && !$('email').value; + !$('state').value && !$('zipCode').value && !('country').value && + !$('phone').value && !$('fax').value && !$('email').value; $('autoFillEditAddressApplyButton').disabled = disabled; }, @@ -87,6 +113,7 @@ cr.define('options', function() { $('city').value = ''; $('state').value = ''; $('zipCode').value = ''; + $('country').value = ''; $('phone').value = ''; $('fax').value = ''; $('email').value = ''; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 4ea29de..f7b267a 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1160,10 +1160,6 @@ 'browser/dom_operation_notification_details.h', 'browser/dom_ui/app_launcher_handler.cc', 'browser/dom_ui/app_launcher_handler.h', - 'browser/dom_ui/autofill_edit_address_handler.cc', - 'browser/dom_ui/autofill_edit_address_handler.h', - 'browser/dom_ui/autofill_edit_creditcard_handler.cc', - 'browser/dom_ui/autofill_edit_creditcard_handler.h', 'browser/dom_ui/autofill_options_handler.cc', 'browser/dom_ui/autofill_options_handler.h', 'browser/dom_ui/bookmarks_ui.cc', |