Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: chrome/browser/ui/webui/options/autofill_options_handler.cc

Issue 6935033: Autofill DOMUI Prefs should work with i18n phone numbers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Namespace and comments. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/options/autofill_options_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/options/autofill_options_handler.cc
diff --git a/chrome/browser/ui/webui/options/autofill_options_handler.cc b/chrome/browser/ui/webui/options/autofill_options_handler.cc
index ab0038b0d06fcf74523c33edd3b283ae984a3e56..d9410f59805629df270c88feb6cfdadc2b4c71ba 100644
--- a/chrome/browser/ui/webui/options/autofill_options_handler.cc
+++ b/chrome/browser/ui/webui/options/autofill_options_handler.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/autofill/autofill_country.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/credit_card.h"
+#include "chrome/browser/autofill/phone_number_i18n.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/common/guid.h"
@@ -115,6 +116,66 @@ void SetValueList(const ListValue* list,
profile->SetMultiInfo(type, values);
}
+// Pulls the phone (or fax) number |index|, |phone_number_list|, and
+// |country_code| from the |args| input.
+void ExtractPhoneNumberInformation(const ListValue* args,
+ size_t* index,
+ ListValue** phone_number_list,
+ std::string* country_code) {
+ // Retrieve index as a |double|, as that is how it comes across from
+ // JavaScript.
+ double number = 0.0;
+ if (!args->GetDouble(0, &number)) {
+ NOTREACHED();
+ return;
+ }
+ *index = number;
+
+ if (!args->GetList(1, phone_number_list)) {
+ NOTREACHED();
+ return;
+ }
+
+ if (!args->GetString(2, country_code)) {
+ NOTREACHED();
+ return;
+ }
+}
+
+// Searches the |list| for the value at |index|. If this value is present
+// in any of the rest of the list, then the item (at |index|) is removed.
+// The comparison of phone number values is done on normalized versions of the
+// phone number values.
+void RemoveDuplicatePhoneNumberAtIndex(size_t index,
+ const std::string& country_code,
+ ListValue* list) {
+ string16 new_value;
+ list->GetString(index, &new_value);
+
+ bool is_duplicate = false;
+ for (size_t i = 0; i < list->GetSize() && !is_duplicate; ++i) {
+ if (i == index)
+ continue;
+
+ string16 existing_value;
+ list->GetString(i, &existing_value);
+ is_duplicate = autofill_i18n::PhoneNumbersMatch(new_value,
+ existing_value,
+ country_code);
+ }
+
+ if (is_duplicate)
+ list->Remove(index, NULL);
+}
+
+void ValidatePhoneArguments(const ListValue* args, ListValue** list) {
+ size_t index = 0;
+ std::string country_code;
+ ExtractPhoneNumberInformation(args, &index, list, &country_code);
+
+ RemoveDuplicatePhoneNumberAtIndex(index, country_code, *list);
+}
+
} // namespace
AutofillOptionsHandler::AutofillOptionsHandler()
@@ -181,6 +242,12 @@ void AutofillOptionsHandler::RegisterMessages() {
web_ui_->RegisterMessageCallback(
"setCreditCard",
NewCallback(this, &AutofillOptionsHandler::SetCreditCard));
+ web_ui_->RegisterMessageCallback(
+ "validatePhoneNumbers",
+ NewCallback(this, &AutofillOptionsHandler::ValidatePhoneNumbers));
+ web_ui_->RegisterMessageCallback(
+ "validateFaxNumbers",
+ NewCallback(this, &AutofillOptionsHandler::ValidateFaxNumbers));
}
/////////////////////////////////////////////////////////////////////////////
@@ -452,3 +519,25 @@ void AutofillOptionsHandler::SetCreditCard(const ListValue* args) {
personal_data_->UpdateCreditCard(credit_card);
}
}
+
+void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) {
+ if (!personal_data_->IsDataLoaded())
+ return;
+
+ ListValue* list_value = NULL;
+ ValidatePhoneArguments(args, &list_value);
+
+ web_ui_->CallJavascriptFunction(
+ "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value);
+}
+
+void AutofillOptionsHandler::ValidateFaxNumbers(const ListValue* args) {
+ if (!personal_data_->IsDataLoaded())
+ return;
+
+ ListValue* list_value = NULL;
+ ValidatePhoneArguments(args, &list_value);
+
+ web_ui_->CallJavascriptFunction(
+ "AutofillEditAddressOverlay.setValidatedFaxNumbers", *list_value);
+}
« no previous file with comments | « chrome/browser/ui/webui/options/autofill_options_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698