| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/options2/autofill_options_handler.h" | 5 #include "chrome/browser/ui/webui/options2/autofill_options_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 for (size_t i = 0; i < first_names.size(); ++i) { | 151 for (size_t i = 0; i < first_names.size(); ++i) { |
| 152 ListValue* name = new ListValue; // owned by |list| | 152 ListValue* name = new ListValue; // owned by |list| |
| 153 name->Set(0, Value::CreateStringValue(first_names[i])); | 153 name->Set(0, Value::CreateStringValue(first_names[i])); |
| 154 name->Set(1, Value::CreateStringValue(middle_names[i])); | 154 name->Set(1, Value::CreateStringValue(middle_names[i])); |
| 155 name->Set(2, Value::CreateStringValue(last_names[i])); | 155 name->Set(2, Value::CreateStringValue(last_names[i])); |
| 156 (*names)->Set(i, name); | 156 (*names)->Set(i, name); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Set the multi-valued element for |type| from input |list| values. | 160 // Set the multi-valued element for |type| from input |list| values. |
| 161 void SetNameList(const ListValue* names, | 161 void SetNameList(const ListValue* names, AutofillProfile* profile) { |
| 162 AutofillProfile* profile) { | |
| 163 const size_t size = names->GetSize(); | 162 const size_t size = names->GetSize(); |
| 164 std::vector<string16> first_names(size); | 163 std::vector<string16> first_names(size); |
| 165 std::vector<string16> middle_names(size); | 164 std::vector<string16> middle_names(size); |
| 166 std::vector<string16> last_names(size); | 165 std::vector<string16> last_names(size); |
| 167 | 166 |
| 168 for (size_t i = 0; i < size; ++i) { | 167 for (size_t i = 0; i < size; ++i) { |
| 169 ListValue* name; | 168 const ListValue* name; |
| 170 bool success = names->GetList(i, &name); | 169 bool success = names->GetList(i, &name); |
| 171 DCHECK(success); | 170 DCHECK(success); |
| 172 | 171 |
| 173 string16 first_name; | 172 string16 first_name; |
| 174 success = name->GetString(0, &first_name); | 173 success = name->GetString(0, &first_name); |
| 175 DCHECK(success); | 174 DCHECK(success); |
| 176 first_names[i] = first_name; | 175 first_names[i] = first_name; |
| 177 | 176 |
| 178 string16 middle_name; | 177 string16 middle_name; |
| 179 success = name->GetString(1, &middle_name); | 178 success = name->GetString(1, &middle_name); |
| 180 DCHECK(success); | 179 DCHECK(success); |
| 181 middle_names[i] = middle_name; | 180 middle_names[i] = middle_name; |
| 182 | 181 |
| 183 string16 last_name; | 182 string16 last_name; |
| 184 success = name->GetString(2, &last_name); | 183 success = name->GetString(2, &last_name); |
| 185 DCHECK(success); | 184 DCHECK(success); |
| 186 last_names[i] = last_name; | 185 last_names[i] = last_name; |
| 187 } | 186 } |
| 188 | 187 |
| 189 profile->SetMultiInfo(NAME_FIRST, first_names); | 188 profile->SetMultiInfo(NAME_FIRST, first_names); |
| 190 profile->SetMultiInfo(NAME_MIDDLE, middle_names); | 189 profile->SetMultiInfo(NAME_MIDDLE, middle_names); |
| 191 profile->SetMultiInfo(NAME_LAST, last_names); | 190 profile->SetMultiInfo(NAME_LAST, last_names); |
| 192 } | 191 } |
| 193 | 192 |
| 194 // Pulls the phone number |index|, |phone_number_list|, and |country_code| from | 193 // Pulls the phone number |index|, |phone_number_list|, and |country_code| from |
| 195 // the |args| input. | 194 // the |args| input. |
| 196 void ExtractPhoneNumberInformation(const ListValue* args, | 195 void ExtractPhoneNumberInformation(const ListValue* args, |
| 197 size_t* index, | 196 size_t* index, |
| 198 ListValue** phone_number_list, | 197 const ListValue** phone_number_list, |
| 199 std::string* country_code) { | 198 std::string* country_code) { |
| 200 // Retrieve index as a |double|, as that is how it comes across from | 199 // Retrieve index as a |double|, as that is how it comes across from |
| 201 // JavaScript. | 200 // JavaScript. |
| 202 double number = 0.0; | 201 double number = 0.0; |
| 203 if (!args->GetDouble(0, &number)) { | 202 if (!args->GetDouble(0, &number)) { |
| 204 NOTREACHED(); | 203 NOTREACHED(); |
| 205 return; | 204 return; |
| 206 } | 205 } |
| 207 *index = number; | 206 *index = number; |
| 208 | 207 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 241 } |
| 243 is_duplicate = autofill_i18n::PhoneNumbersMatch(new_value, | 242 is_duplicate = autofill_i18n::PhoneNumbersMatch(new_value, |
| 244 existing_value, | 243 existing_value, |
| 245 country_code); | 244 country_code); |
| 246 } | 245 } |
| 247 | 246 |
| 248 if (is_duplicate) | 247 if (is_duplicate) |
| 249 list->Remove(index, NULL); | 248 list->Remove(index, NULL); |
| 250 } | 249 } |
| 251 | 250 |
| 252 void ValidatePhoneArguments(const ListValue* args, ListValue** list) { | 251 scoped_ptr<ListValue> ValidatePhoneArguments(const ListValue* args) { |
| 253 size_t index = 0; | 252 size_t index = 0; |
| 254 std::string country_code; | 253 std::string country_code; |
| 255 ExtractPhoneNumberInformation(args, &index, list, &country_code); | 254 const ListValue* extracted_list = NULL; |
| 255 ExtractPhoneNumberInformation(args, &index, &extracted_list, &country_code); |
| 256 | 256 |
| 257 RemoveDuplicatePhoneNumberAtIndex(index, country_code, *list); | 257 scoped_ptr<ListValue> list(extracted_list->DeepCopy()); |
| 258 RemoveDuplicatePhoneNumberAtIndex(index, country_code, list.get()); |
| 259 return list.Pass(); |
| 258 } | 260 } |
| 259 | 261 |
| 260 } // namespace | 262 } // namespace |
| 261 | 263 |
| 262 namespace options2 { | 264 namespace options2 { |
| 263 | 265 |
| 264 AutofillOptionsHandler::AutofillOptionsHandler() | 266 AutofillOptionsHandler::AutofillOptionsHandler() |
| 265 : personal_data_(NULL) { | 267 : personal_data_(NULL) { |
| 266 } | 268 } |
| 267 | 269 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 std::string guid; | 545 std::string guid; |
| 544 if (!args->GetString(0, &guid)) { | 546 if (!args->GetString(0, &guid)) { |
| 545 NOTREACHED(); | 547 NOTREACHED(); |
| 546 return; | 548 return; |
| 547 } | 549 } |
| 548 | 550 |
| 549 AutofillProfile profile(guid); | 551 AutofillProfile profile(guid); |
| 550 | 552 |
| 551 std::string country_code; | 553 std::string country_code; |
| 552 string16 value; | 554 string16 value; |
| 553 ListValue* list_value; | 555 const ListValue* list_value; |
| 554 if (args->GetList(1, &list_value)) | 556 if (args->GetList(1, &list_value)) |
| 555 SetNameList(list_value, &profile); | 557 SetNameList(list_value, &profile); |
| 556 if (args->GetString(2, &value)) | 558 if (args->GetString(2, &value)) |
| 557 profile.SetInfo(COMPANY_NAME, value); | 559 profile.SetInfo(COMPANY_NAME, value); |
| 558 if (args->GetString(3, &value)) | 560 if (args->GetString(3, &value)) |
| 559 profile.SetInfo(ADDRESS_HOME_LINE1, value); | 561 profile.SetInfo(ADDRESS_HOME_LINE1, value); |
| 560 if (args->GetString(4, &value)) | 562 if (args->GetString(4, &value)) |
| 561 profile.SetInfo(ADDRESS_HOME_LINE2, value); | 563 profile.SetInfo(ADDRESS_HOME_LINE2, value); |
| 562 if (args->GetString(5, &value)) | 564 if (args->GetString(5, &value)) |
| 563 profile.SetInfo(ADDRESS_HOME_CITY, value); | 565 profile.SetInfo(ADDRESS_HOME_CITY, value); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 personal_data_->AddCreditCard(credit_card); | 609 personal_data_->AddCreditCard(credit_card); |
| 608 } else { | 610 } else { |
| 609 personal_data_->UpdateCreditCard(credit_card); | 611 personal_data_->UpdateCreditCard(credit_card); |
| 610 } | 612 } |
| 611 } | 613 } |
| 612 | 614 |
| 613 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) { | 615 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) { |
| 614 if (!IsPersonalDataLoaded()) | 616 if (!IsPersonalDataLoaded()) |
| 615 return; | 617 return; |
| 616 | 618 |
| 617 ListValue* list_value = NULL; | 619 scoped_ptr<ListValue> list_value = ValidatePhoneArguments(args); |
| 618 ValidatePhoneArguments(args, &list_value); | |
| 619 | 620 |
| 620 web_ui()->CallJavascriptFunction( | 621 web_ui()->CallJavascriptFunction( |
| 621 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 622 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
| 622 } | 623 } |
| 623 | 624 |
| 624 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 625 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
| 625 return personal_data_ && personal_data_->IsDataLoaded(); | 626 return personal_data_ && personal_data_->IsDataLoaded(); |
| 626 } | 627 } |
| 627 | 628 |
| 628 } // namespace options2 | 629 } // namespace options2 |
| OLD | NEW |