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

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

Issue 6930037: Autofill DOMUI Prefs should work with i18n phone numbers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding DEPS. Created 9 years, 8 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
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..81b9ebb97d5eea83d6530135f4fe242c5ca32057 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,64 @@ void SetValueList(const ListValue* list,
profile->SetMultiInfo(type, values);
}
+// Pulls the phone number |index|, |list_value|, and |country_code| from the
+// |args| input.
+void ExtractPhoneNumberInformation(const ListValue* args,
+ size_t* index,
+ ListValue** list_value,
+ std::string* country_code) {
+ double number = 0.0;
+ if (!args->GetDouble(0, &number)) {
+ NOTREACHED();
+ return;
+ }
+ *index = number;
+
+ if (!args->GetList(1, list_value)) {
+ 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 +240,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 +517,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);
+}

Powered by Google App Engine
This is Rietveld 408576698