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

Side by Side Diff: chrome/browser/ui/webui/options/autofill_options_handler.cc

Issue 6930052: Revert 84320 - Autofill DOMUI Prefs should work with i18n phone numbers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h" 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/autofill/autofill_country.h" 14 #include "chrome/browser/autofill/autofill_country.h"
15 #include "chrome/browser/autofill/autofill_profile.h" 15 #include "chrome/browser/autofill/autofill_profile.h"
16 #include "chrome/browser/autofill/credit_card.h" 16 #include "chrome/browser/autofill/credit_card.h"
17 #include "chrome/browser/autofill/phone_number_i18n.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/webui/web_ui_util.h" 18 #include "chrome/browser/ui/webui/web_ui_util.h"
20 #include "chrome/common/guid.h" 19 #include "chrome/common/guid.h"
21 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
22 #include "grit/webkit_resources.h" 21 #include "grit/webkit_resources.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 23
25 namespace { 24 namespace {
26 25
27 // Converts a credit card type to the appropriate resource ID of the CC icon. 26 // Converts a credit card type to the appropriate resource ID of the CC icon.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 AutofillProfile* profile) { 108 AutofillProfile* profile) {
110 std::vector<string16> values(list->GetSize()); 109 std::vector<string16> values(list->GetSize());
111 for (size_t i = 0; i < list->GetSize(); ++i) { 110 for (size_t i = 0; i < list->GetSize(); ++i) {
112 string16 value; 111 string16 value;
113 if (list->GetString(i, &value)) 112 if (list->GetString(i, &value))
114 values[i] = value; 113 values[i] = value;
115 } 114 }
116 profile->SetMultiInfo(type, values); 115 profile->SetMultiInfo(type, values);
117 } 116 }
118 117
119 // Pulls the phone number |index|, |list_value|, and |country_code| from the
120 // |args| input.
121 void ExtractPhoneNumberInformation(const ListValue* args,
122 size_t* index,
123 ListValue** list_value,
124 std::string* country_code) {
125 double number = 0.0;
126 if (!args->GetDouble(0, &number)) {
127 NOTREACHED();
128 return;
129 }
130 *index = number;
131
132 if (!args->GetList(1, list_value)) {
133 NOTREACHED();
134 return;
135 }
136
137 if (!args->GetString(2, country_code)) {
138 NOTREACHED();
139 return;
140 }
141 }
142
143 // Searches the |list| for the value at |index|. If this value is present
144 // in any of the rest of the list, then the item (at |index|) is removed.
145 // The comparison of phone number values is done on normalized versions of the
146 // phone number values.
147 void RemoveDuplicatePhoneNumberAtIndex(size_t index,
148 const std::string& country_code,
149 ListValue* list) {
150 string16 new_value;
151 list->GetString(index, &new_value);
152
153 bool is_duplicate = false;
154 for (size_t i = 0; i < list->GetSize() && !is_duplicate; ++i) {
155 if (i == index)
156 continue;
157
158 string16 existing_value;
159 list->GetString(i, &existing_value);
160 is_duplicate = autofill_i18n::PhoneNumbersMatch(new_value,
161 existing_value,
162 country_code);
163 }
164
165 if (is_duplicate)
166 list->Remove(index, NULL);
167 }
168
169 void ValidatePhoneArguments(const ListValue* args, ListValue** list) {
170 size_t index = 0;
171 std::string country_code;
172 ExtractPhoneNumberInformation(args, &index, list, &country_code);
173
174 RemoveDuplicatePhoneNumberAtIndex(index, country_code, *list);
175 }
176
177 } // namespace 118 } // namespace
178 119
179 AutofillOptionsHandler::AutofillOptionsHandler() 120 AutofillOptionsHandler::AutofillOptionsHandler()
180 : personal_data_(NULL) { 121 : personal_data_(NULL) {
181 } 122 }
182 123
183 AutofillOptionsHandler::~AutofillOptionsHandler() { 124 AutofillOptionsHandler::~AutofillOptionsHandler() {
184 if (personal_data_) 125 if (personal_data_)
185 personal_data_->RemoveObserver(this); 126 personal_data_->RemoveObserver(this);
186 } 127 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 NewCallback(this, &AutofillOptionsHandler::LoadAddressEditor)); 174 NewCallback(this, &AutofillOptionsHandler::LoadAddressEditor));
234 web_ui_->RegisterMessageCallback( 175 web_ui_->RegisterMessageCallback(
235 "loadCreditCardEditor", 176 "loadCreditCardEditor",
236 NewCallback(this, &AutofillOptionsHandler::LoadCreditCardEditor)); 177 NewCallback(this, &AutofillOptionsHandler::LoadCreditCardEditor));
237 web_ui_->RegisterMessageCallback( 178 web_ui_->RegisterMessageCallback(
238 "setAddress", 179 "setAddress",
239 NewCallback(this, &AutofillOptionsHandler::SetAddress)); 180 NewCallback(this, &AutofillOptionsHandler::SetAddress));
240 web_ui_->RegisterMessageCallback( 181 web_ui_->RegisterMessageCallback(
241 "setCreditCard", 182 "setCreditCard",
242 NewCallback(this, &AutofillOptionsHandler::SetCreditCard)); 183 NewCallback(this, &AutofillOptionsHandler::SetCreditCard));
243 web_ui_->RegisterMessageCallback(
244 "validatePhoneNumbers",
245 NewCallback(this, &AutofillOptionsHandler::ValidatePhoneNumbers));
246 web_ui_->RegisterMessageCallback(
247 "validateFaxNumbers",
248 NewCallback(this, &AutofillOptionsHandler::ValidateFaxNumbers));
249 } 184 }
250 185
251 ///////////////////////////////////////////////////////////////////////////// 186 /////////////////////////////////////////////////////////////////////////////
252 // PersonalDataManager::Observer implementation: 187 // PersonalDataManager::Observer implementation:
253 void AutofillOptionsHandler::OnPersonalDataLoaded() { 188 void AutofillOptionsHandler::OnPersonalDataLoaded() {
254 LoadAutofillData(); 189 LoadAutofillData();
255 } 190 }
256 191
257 void AutofillOptionsHandler::OnPersonalDataChanged() { 192 void AutofillOptionsHandler::OnPersonalDataChanged() {
258 LoadAutofillData(); 193 LoadAutofillData();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (args->GetString(4, &value)) 445 if (args->GetString(4, &value))
511 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, value); 446 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, value);
512 447
513 if (!guid::IsValidGUID(credit_card.guid())) { 448 if (!guid::IsValidGUID(credit_card.guid())) {
514 credit_card.set_guid(guid::GenerateGUID()); 449 credit_card.set_guid(guid::GenerateGUID());
515 personal_data_->AddCreditCard(credit_card); 450 personal_data_->AddCreditCard(credit_card);
516 } else { 451 } else {
517 personal_data_->UpdateCreditCard(credit_card); 452 personal_data_->UpdateCreditCard(credit_card);
518 } 453 }
519 } 454 }
520
521 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) {
522 if (!personal_data_->IsDataLoaded())
523 return;
524
525 ListValue* list_value = NULL;
526 ValidatePhoneArguments(args, &list_value);
527
528 web_ui_->CallJavascriptFunction(
529 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value);
530 }
531
532 void AutofillOptionsHandler::ValidateFaxNumbers(const ListValue* args) {
533 if (!personal_data_->IsDataLoaded())
534 return;
535
536 ListValue* list_value = NULL;
537 ValidatePhoneArguments(args, &list_value);
538
539 web_ui_->CallJavascriptFunction(
540 "AutofillEditAddressOverlay.setValidatedFaxNumbers", *list_value);
541 }
OLDNEW
« 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