From 4eec20fca634944de02ed0f1cbc9f01c7fe8b27f Mon Sep 17 00:00:00 2001 From: "jhawkins@chromium.org" Date: Wed, 22 Dec 2010 22:24:10 +0000 Subject: DOMUI: Implement the new-style Autofill options page. BUG=59281 TEST=none Review URL: http://codereview.chromium.org/6034005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69989 0039d316-1c4b-4281-b951-d872f2087c98 --- .../dom_ui/options/autofill_options_handler.cc | 198 +++++++-------- .../dom_ui/options/autofill_options_handler.h | 59 +++-- .../dom_ui/options/personal_options_handler.cc | 2 + .../options/autofill_edit_address_overlay.js | 2 +- .../options/autofill_edit_creditcard_overlay.js | 2 +- .../browser/resources/options/autofill_options.css | 18 +- .../resources/options/autofill_options.html | 42 +--- .../browser/resources/options/autofill_options.js | 271 +++++++-------------- .../resources/options/autofill_options_list.js | 93 +++++++ .../resources/options/content_settings.html | 14 +- chrome/browser/resources/options/options.html | 1 + chrome/browser/resources/options/options_page.css | 6 + .../browser/resources/options/password_manager.css | 5 - .../resources/options/password_manager.html | 14 +- chrome/browser/resources/shared/js/cr/ui/list.js | 15 ++ 15 files changed, 364 insertions(+), 378 deletions(-) create mode 100644 chrome/browser/resources/options/autofill_options_list.js (limited to 'chrome/browser') diff --git a/chrome/browser/dom_ui/options/autofill_options_handler.cc b/chrome/browser/dom_ui/options/autofill_options_handler.cc index e6d0f00..1e09fd2 100644 --- a/chrome/browser/dom_ui/options/autofill_options_handler.cc +++ b/chrome/browser/dom_ui/options/autofill_options_handler.cc @@ -34,20 +34,14 @@ void AutoFillOptionsHandler::GetLocalizedValues( localized_strings->SetString("autoFillOptionsTitle", l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_TITLE)); - localized_strings->SetString("autoFillEnabled", - l10n_util::GetStringUTF16(IDS_OPTIONS_AUTOFILL_ENABLE)); - localized_strings->SetString("addressesHeader", + localized_strings->SetString("autoFillAddresses", l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESSES_GROUP_NAME)); - localized_strings->SetString("creditCardsHeader", + localized_strings->SetString("autoFillCreditCards", l10n_util::GetStringUTF16(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME)); - localized_strings->SetString("addAddressButton", + localized_strings->SetString("autoFillAddAddress", l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_ADDRESS_BUTTON)); - localized_strings->SetString("addCreditCardButton", + localized_strings->SetString("autoFillAddCreditCard", l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_CREDITCARD_BUTTON)); - localized_strings->SetString("editButton", - l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_BUTTON)); - localized_strings->SetString("deleteButton", - l10n_util::GetStringUTF16(IDS_AUTOFILL_DELETE_BUTTON)); localized_strings->SetString("helpButton", l10n_util::GetStringUTF16(IDS_AUTOFILL_HELP_LABEL)); localized_strings->SetString("addAddressTitle", @@ -64,8 +58,7 @@ void AutoFillOptionsHandler::GetLocalizedValues( } void AutoFillOptionsHandler::Initialize() { - personal_data_ = - dom_ui_->GetProfile()->GetOriginalProfile()->GetPersonalDataManager(); + personal_data_ = dom_ui_->GetProfile()->GetPersonalDataManager(); personal_data_->SetObserver(this); LoadAutoFillData(); @@ -73,28 +66,17 @@ void AutoFillOptionsHandler::Initialize() { void AutoFillOptionsHandler::RegisterMessages() { dom_ui_->RegisterMessageCallback( - "updateAddress", - NewCallback(this, &AutoFillOptionsHandler::UpdateAddress)); - - dom_ui_->RegisterMessageCallback( - "editAddress", - NewCallback(this, &AutoFillOptionsHandler::EditAddress)); - + "removeAutoFillProfile", + NewCallback(this, &AutoFillOptionsHandler::RemoveAutoFillProfile)); dom_ui_->RegisterMessageCallback( - "removeAddress", - NewCallback(this, &AutoFillOptionsHandler::RemoveAddress)); - + "loadProfileEditor", + NewCallback(this, &AutoFillOptionsHandler::LoadProfileEditor)); dom_ui_->RegisterMessageCallback( - "updateCreditCard", - NewCallback(this, &AutoFillOptionsHandler::UpdateCreditCard)); - - dom_ui_->RegisterMessageCallback( - "editCreditCard", - NewCallback(this, &AutoFillOptionsHandler::EditCreditCard)); - + "setAddress", + NewCallback(this, &AutoFillOptionsHandler::SetAddress)); dom_ui_->RegisterMessageCallback( - "removeCreditCard", - NewCallback(this, &AutoFillOptionsHandler::RemoveCreditCard)); + "setCreditCard", + NewCallback(this, &AutoFillOptionsHandler::SetCreditCard)); } ///////////////////////////////////////////////////////////////////////////// @@ -157,30 +139,68 @@ void AutoFillOptionsHandler::LoadAutoFillData() { for (std::vector::const_iterator i = personal_data_->web_profiles().begin(); i != personal_data_->web_profiles().end(); ++i) { - DictionaryValue* address = new DictionaryValue(); - address->SetString("label", (*i)->Label()); - address->SetString("guid", (*i)->guid()); - addresses.Append(address); + ListValue* entry = new ListValue(); + entry->Append(new StringValue((*i)->guid())); + entry->Append(new StringValue((*i)->Label())); + addresses.Append(entry); } - dom_ui_->CallJavascriptFunction(L"AutoFillOptions.updateAddresses", + dom_ui_->CallJavascriptFunction(L"AutoFillOptions.setAddressList", addresses); ListValue credit_cards; for (std::vector::const_iterator i = personal_data_->credit_cards().begin(); i != personal_data_->credit_cards().end(); ++i) { - DictionaryValue* credit_card = new DictionaryValue(); - credit_card->SetString("label", (*i)->PreviewSummary()); - credit_card->SetString("guid", (*i)->guid()); - credit_cards.Append(credit_card); + ListValue* entry = new ListValue(); + entry->Append(new StringValue((*i)->guid())); + entry->Append(new StringValue((*i)->PreviewSummary())); + credit_cards.Append(entry); } - dom_ui_->CallJavascriptFunction(L"AutoFillOptions.updateCreditCards", + dom_ui_->CallJavascriptFunction(L"AutoFillOptions.setCreditCardList", credit_cards); } -void AutoFillOptionsHandler::UpdateAddress(const ListValue* args) { +void AutoFillOptionsHandler::RemoveAutoFillProfile(const ListValue* args) { + DCHECK(personal_data_->IsDataLoaded()); + + std::string guid; + if (!args->GetString(0, &guid)) { + NOTREACHED(); + return; + } + + // |guid| is the GUID of either an address or a credit card. Try to load the + // corresponding address. If it exists, then remove that address; otherwise, + // the GUID identifies a credit card, so remove the credit card. + // TODO(jhawkins): Make RemoveProfile return true/false depending on whether + // the profile was removed or not. + if (personal_data_->GetProfileByGUID(guid) != NULL) + personal_data_->RemoveProfile(guid); + else + personal_data_->RemoveCreditCard(guid); +} + +void AutoFillOptionsHandler::LoadProfileEditor(const ListValue* args) { + DCHECK(personal_data_->IsDataLoaded()); + + std::string guid; + if (!args->GetString(0, &guid)) { + NOTREACHED(); + return; + } + + // |guid| is the GUID of either an address or a credit card. Try to load the + // corresponding address. If it exists, then edit that address; otherwise, the + // GUID identifies a credit card, so load the credit card editor. + if (personal_data_->GetProfileByGUID(guid) != NULL) + EditAddress(guid); + else + EditCreditCard(guid); +} + +void AutoFillOptionsHandler::SetAddress(const ListValue* args) { if (!personal_data_->IsDataLoaded()) return; @@ -224,7 +244,7 @@ void AutoFillOptionsHandler::UpdateAddress(const ListValue* args) { } } -void AutoFillOptionsHandler::EditAddress(const ListValue* args) { +void AutoFillOptionsHandler::SetCreditCard(const ListValue* args) { if (!personal_data_->IsDataLoaded()) return; @@ -234,6 +254,29 @@ void AutoFillOptionsHandler::EditAddress(const ListValue* args) { return; } + CreditCard credit_card(guid); + + string16 value; + if (args->GetString(1, &value)) + credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), value); + if (args->GetString(2, &value)) + credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), value); + if (args->GetString(3, &value)) + credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), value); + if (args->GetString(4, &value)) + credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); + + if (!guid::IsValidGUID(credit_card.guid())) { + credit_card.set_guid(guid::GenerateGUID()); + personal_data_->AddCreditCard(credit_card); + } else { + personal_data_->UpdateCreditCard(credit_card); + } +} + +void AutoFillOptionsHandler::EditAddress(const std::string& guid) { + DCHECK(personal_data_->IsDataLoaded()); + AutoFillProfile* profile = personal_data_->GetProfileByGUID(guid); if (!profile) { NOTREACHED(); @@ -275,62 +318,10 @@ void AutoFillOptionsHandler::EditAddress(const ListValue* args) { addressList); } -void AutoFillOptionsHandler::RemoveAddress(const ListValue* args) { - if (!personal_data_->IsDataLoaded()) - return; - - std::string guid; - if (!args->GetString(0, &guid)) { - NOTREACHED(); - return; - } - - personal_data_->RemoveProfile(guid); -} - -void AutoFillOptionsHandler::UpdateCreditCard(const ListValue* args) { - if (!personal_data_->IsDataLoaded()) - return; - - std::string guid; - if (!args->GetString(0, &guid)) { - NOTREACHED(); - return; - } - - CreditCard credit_card(guid); - - string16 value; - if (args->GetString(1, &value)) - credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), value); - if (args->GetString(2, &value)) - credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), value); - if (args->GetString(3, &value)) - credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), value); - if (args->GetString(4, &value)) - credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); - - if (!guid::IsValidGUID(credit_card.guid())) { - credit_card.set_guid(guid::GenerateGUID()); - personal_data_->AddCreditCard(credit_card); - } else { - personal_data_->UpdateCreditCard(credit_card); - } - -} - -void AutoFillOptionsHandler::EditCreditCard(const ListValue* args) { - if (!personal_data_->IsDataLoaded()) - return; - - std::string guid; - if (!args->GetString(0, &guid)) { - NOTREACHED(); - return; - } +void AutoFillOptionsHandler::EditCreditCard(const std::string& guid) { + DCHECK(personal_data_->IsDataLoaded()); CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); - if (!credit_card) { NOTREACHED(); return; @@ -358,16 +349,3 @@ void AutoFillOptionsHandler::EditCreditCard(const ListValue* args) { dom_ui_->CallJavascriptFunction(L"AutoFillOptions.editCreditCard", credit_card_list); } - -void AutoFillOptionsHandler::RemoveCreditCard(const ListValue* args) { - if (!personal_data_->IsDataLoaded()) - return; - - std::string guid; - if (!args->GetString(0, &guid)) { - NOTREACHED(); - return; - } - - personal_data_->RemoveCreditCard(guid); -} diff --git a/chrome/browser/dom_ui/options/autofill_options_handler.h b/chrome/browser/dom_ui/options/autofill_options_handler.h index e932047..eff357a 100644 --- a/chrome/browser/dom_ui/options/autofill_options_handler.h +++ b/chrome/browser/dom_ui/options/autofill_options_handler.h @@ -5,9 +5,14 @@ #ifndef CHROME_BROWSER_DOM_UI_OPTIONS_AUTOFILL_OPTIONS_HANDLER_H_ #define CHROME_BROWSER_DOM_UI_OPTIONS_AUTOFILL_OPTIONS_HANDLER_H_ +#include + #include "chrome/browser/autofill/personal_data_manager.h" #include "chrome/browser/dom_ui/options/options_ui.h" +class DictionaryValue; +class ListValue; + class AutoFillOptionsHandler : public OptionsPageUIHandler, public PersonalDataManager::Observer { public: @@ -31,38 +36,38 @@ class AutoFillOptionsHandler : public OptionsPageUIHandler, // Loads AutoFill addresses and credit cards using the PersonalDataManager. void LoadAutoFillData(); - // Adds or updates an address, depending on the unique ID of the address. If - // the unique ID is 0, a new address is added to the WebDatabase; otherwise, - // the address with the matching ID is updated. Called from DOMUI. - // |args| - an array containing the unique ID of the address followed by the + // Removes either an address or a credit card, depending on the type of the + // profile. + // |args| - A string, the GUID of the profile to remove. + void RemoveAutoFillProfile(const ListValue* args); + + // Requests profile data for a specific profile. Calls into DOMUI with the + // loaded profile data to open the appropriate editor, depending on the type + // of the profile. + // |args| - A string, the GUID of the profile to load. + void LoadProfileEditor(const ListValue* args); + + // Adds or updates an address, depending on the GUID of the profile. If the + // GUID is empty, a new address is added to the WebDatabase; otherwise, the + // address with the matching GUID is updated. Called from DOMUI. + // |args| - an array containing the GUID of the address followed by the // address data. - void UpdateAddress(const ListValue* args); + void SetAddress(const ListValue* args); + + // Adds or updates a credit card, depending on the GUID of the profile. If the + // GUID is empty, a new credit card is added to the WebDatabase; otherwise, + // the credit card with the matching GUID is updated. Called from DOMUI. + // |args| - an array containing the GUID of the credit card followed by the + // credit card data. + void SetCreditCard(const ListValue* args); // Loads the data from an address and sends this data back to the DOMUI to - // show in the address editor. Called from DOMUI. - // |args| - an integer, the unique ID of the address to edit. - void EditAddress(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); - - // Adds or updates a credit card, depending on the unique ID of the credit - // card. If the unique ID is 0, a new credit card is added to the WebDatabase; - // otherwise, the credit card with the matching ID is updated. Called from - // DOMUI. - // |args| - an array containing the unique ID of the credit card followed by - // the credit card data. - void UpdateCreditCard(const ListValue* args); + // show in the address editor. |guid| is the GUID of the profile to load. + void EditAddress(const std::string& guid); // Loads the data from a credit card and sends this data back to the DOMUI to - // show in the credit card editor. Called from DOMUI. - // |args| - an integer, the unique ID of the credit card to edit. - void EditCreditCard(const ListValue* args); - - // Removes a credit card from the WebDatabase. Called from DOMUI. - // |args| - an integer, the unique ID of the credit card to remove. - void RemoveCreditCard(const ListValue* args); + // show in the credit card editor. |guid| is the GUID of the profile to load. + void EditCreditCard(const std::string& guid); // The personal data manager, used to load AutoFill profiles and credit cards. // Unowned pointer, may not be NULL. diff --git a/chrome/browser/dom_ui/options/personal_options_handler.cc b/chrome/browser/dom_ui/options/personal_options_handler.cc index a7bacb0..bc14c1f 100644 --- a/chrome/browser/dom_ui/options/personal_options_handler.cc +++ b/chrome/browser/dom_ui/options/personal_options_handler.cc @@ -73,6 +73,8 @@ void PersonalOptionsHandler::GetLocalizedValues( localized_strings->SetString("autofill", dom_options_util::StripColon( l10n_util::GetStringUTF16(IDS_AUTOFILL_SETTING_WINDOWS_GROUP_NAME))); + localized_strings->SetString("autoFillEnabled", + l10n_util::GetStringUTF16(IDS_OPTIONS_AUTOFILL_ENABLE)); localized_strings->SetString("manageAutofillSettings", l10n_util::GetStringUTF16(IDS_OPTIONS_MANAGE_AUTOFILL_SETTINGS)); diff --git a/chrome/browser/resources/options/autofill_edit_address_overlay.js b/chrome/browser/resources/options/autofill_edit_address_overlay.js index 46a17d0..5794daa 100644 --- a/chrome/browser/resources/options/autofill_edit_address_overlay.js +++ b/chrome/browser/resources/options/autofill_edit_address_overlay.js @@ -75,7 +75,7 @@ cr.define('options', function() { address[10] = $('fax').value; address[11] = $('email').value; - chrome.send('updateAddress', address); + chrome.send('setAddress', address); }, /** diff --git a/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js b/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js index 01b1722..c61255e 100644 --- a/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js +++ b/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js @@ -68,7 +68,7 @@ cr.define('options', function() { creditCard[3] = $('expirationMonth').value; creditCard[4] = $('expirationYear').value; - chrome.send('updateCreditCard', creditCard); + chrome.send('setCreditCard', creditCard); }, /** diff --git a/chrome/browser/resources/options/autofill_options.css b/chrome/browser/resources/options/autofill_options.css index 0c18e3c..673731c 100644 --- a/chrome/browser/resources/options/autofill_options.css +++ b/chrome/browser/resources/options/autofill_options.css @@ -1,16 +1,12 @@ -div.autofill-section { - display: block; - padding: 1em 0 0; +.autofill-list-item { + -webkit-padding-start: 8px; } -#profile-select-container { - display: -webkit-box; +#autofill-options > div:last-child { + margin-top: 15px; } -#profile-select-left-column { - -webkit-box-flex: 1; -} - -#profile-select-left-column select { - width: 100%; +#autofill-options * div.settings-list > :last-child { + border-top: 1px solid #D9D9D9; + padding: 5px 10px; } diff --git a/chrome/browser/resources/options/autofill_options.html b/chrome/browser/resources/options/autofill_options.html index c5bbb72..727c9ae 100644 --- a/chrome/browser/resources/options/autofill_options.html +++ b/chrome/browser/resources/options/autofill_options.html @@ -1,38 +1,22 @@