OLD | NEW |
---|---|
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/dom_ui/options/autofill_options_handler.h" | 5 #include "chrome/browser/dom_ui/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" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 AutoFillProfile* profile = personal_data_->GetProfileByGUID(guid); | 243 AutoFillProfile* profile = personal_data_->GetProfileByGUID(guid); |
244 if (!profile) { | 244 if (!profile) { |
245 // There is a race where a user can click once on the close button and | 245 // There is a race where a user can click once on the close button and |
246 // quickly click again on the list item before the item is removed (since | 246 // quickly click again on the list item before the item is removed (since |
247 // the list is not updated until the model tells the list an item has been | 247 // the list is not updated until the model tells the list an item has been |
248 // removed). This will activate the editor for a profile that has been | 248 // removed). This will activate the editor for a profile that has been |
249 // removed. Do nothing in that case. | 249 // removed. Do nothing in that case. |
250 return; | 250 return; |
251 } | 251 } |
252 | 252 |
253 // TODO(jhawkins): This is hacky because we can't send DictionaryValue | 253 DictionaryValue address; |
James Hawkins
2011/02/12 20:37:34
We can send DictionaryValue now?
Ilya Sherman
2011/02/13 12:24:59
It seemed to work when I tried it, at any rate.
arv (Not doing code reviews)
2011/02/14 18:41:44
Haven't we always been able to send all Value type
James Hawkins
2011/02/16 20:43:59
It's cool that we can now, and I'm not sure what's
| |
254 // directly to CallJavascriptFunction(). | 254 address.SetString("guid", profile->guid()); |
255 ListValue addressList; | 255 address.SetString("fullName", |
256 DictionaryValue* address = new DictionaryValue(); | 256 profile->GetFieldText(AutoFillType(NAME_FULL))); |
257 address->SetString("guid", profile->guid()); | 257 address.SetString("companyName", |
258 address->SetString("fullName", | 258 profile->GetFieldText(AutoFillType(COMPANY_NAME))); |
259 profile->GetFieldText(AutoFillType(NAME_FULL))); | 259 address.SetString("addrLine1", |
260 address->SetString("companyName", | 260 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); |
261 profile->GetFieldText(AutoFillType(COMPANY_NAME))); | 261 address.SetString("addrLine2", |
262 address->SetString("addrLine1", | 262 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); |
263 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); | 263 address.SetString("city", |
264 address->SetString("addrLine2", | 264 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); |
265 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); | 265 address.SetString("state", |
266 address->SetString("city", | 266 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); |
267 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); | 267 address.SetString("zipCode", |
268 address->SetString("state", | 268 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); |
269 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); | 269 address.SetString("country", |
270 address->SetString("zipCode", | |
271 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); | |
272 address->SetString("country", | |
273 profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); | 270 profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); |
274 address->SetString( | 271 address.SetString( |
275 "phone", | 272 "phone", |
276 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); | 273 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); |
277 address->SetString( | 274 address.SetString( |
278 "fax", | 275 "fax", |
279 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); | 276 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); |
280 address->SetString("email", | 277 address.SetString("email", |
281 profile->GetFieldText(AutoFillType(EMAIL_ADDRESS))); | 278 profile->GetFieldText(AutoFillType(EMAIL_ADDRESS))); |
282 addressList.Append(address); | |
283 | 279 |
284 dom_ui_->CallJavascriptFunction(L"AutoFillOptions.editAddress", | 280 dom_ui_->CallJavascriptFunction(L"AutoFillOptions.editAddress", address); |
285 addressList); | |
286 } | 281 } |
287 | 282 |
288 void AutoFillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { | 283 void AutoFillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { |
289 DCHECK(personal_data_->IsDataLoaded()); | 284 DCHECK(personal_data_->IsDataLoaded()); |
290 | 285 |
291 std::string guid; | 286 std::string guid; |
292 if (!args->GetString(0, &guid)) { | 287 if (!args->GetString(0, &guid)) { |
293 NOTREACHED(); | 288 NOTREACHED(); |
294 return; | 289 return; |
295 } | 290 } |
296 | 291 |
297 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); | 292 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); |
298 if (!credit_card) { | 293 if (!credit_card) { |
299 // There is a race where a user can click once on the close button and | 294 // There is a race where a user can click once on the close button and |
300 // quickly click again on the list item before the item is removed (since | 295 // quickly click again on the list item before the item is removed (since |
301 // the list is not updated until the model tells the list an item has been | 296 // the list is not updated until the model tells the list an item has been |
302 // removed). This will activate the editor for a profile that has been | 297 // removed). This will activate the editor for a profile that has been |
303 // removed. Do nothing in that case. | 298 // removed. Do nothing in that case. |
304 return; | 299 return; |
305 } | 300 } |
306 | 301 |
307 // TODO(jhawkins): This is hacky because we can't send DictionaryValue | 302 DictionaryValue credit_card_data; |
308 // directly to CallJavascriptFunction(). | 303 credit_card_data.SetString("guid", credit_card->guid()); |
309 ListValue credit_card_list; | 304 credit_card_data.SetString( |
310 DictionaryValue* credit_card_data = new DictionaryValue(); | |
311 credit_card_data->SetString("guid", credit_card->guid()); | |
312 credit_card_data->SetString( | |
313 "nameOnCard", | 305 "nameOnCard", |
314 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NAME))); | 306 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NAME))); |
315 credit_card_data->SetString( | 307 credit_card_data.SetString( |
316 "creditCardNumber", | 308 "creditCardNumber", |
317 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))); | 309 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))); |
318 credit_card_data->SetString("obfuscatedCardNumber", | 310 credit_card_data.SetString("obfuscatedCardNumber", |
319 credit_card->ObfuscatedNumber()); | 311 credit_card->ObfuscatedNumber()); |
320 credit_card_data->SetString( | 312 credit_card_data.SetString( |
321 "expirationMonth", | 313 "expirationMonth", |
322 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH))); | 314 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH))); |
323 credit_card_data->SetString( | 315 credit_card_data.SetString( |
324 "expirationYear", | 316 "expirationYear", |
325 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); | 317 credit_card->GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); |
326 credit_card_list.Append(credit_card_data); | |
327 | 318 |
328 dom_ui_->CallJavascriptFunction(L"AutoFillOptions.editCreditCard", | 319 dom_ui_->CallJavascriptFunction(L"AutoFillOptions.editCreditCard", |
329 credit_card_list); | 320 credit_card_data); |
330 } | 321 } |
331 | 322 |
332 void AutoFillOptionsHandler::SetAddress(const ListValue* args) { | 323 void AutoFillOptionsHandler::SetAddress(const ListValue* args) { |
333 if (!personal_data_->IsDataLoaded()) | 324 if (!personal_data_->IsDataLoaded()) |
334 return; | 325 return; |
335 | 326 |
336 std::string guid; | 327 std::string guid; |
337 if (!args->GetString(0, &guid)) { | 328 if (!args->GetString(0, &guid)) { |
338 NOTREACHED(); | 329 NOTREACHED(); |
339 return; | 330 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 if (args->GetString(4, &value)) | 386 if (args->GetString(4, &value)) |
396 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); | 387 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); |
397 | 388 |
398 if (!guid::IsValidGUID(credit_card.guid())) { | 389 if (!guid::IsValidGUID(credit_card.guid())) { |
399 credit_card.set_guid(guid::GenerateGUID()); | 390 credit_card.set_guid(guid::GenerateGUID()); |
400 personal_data_->AddCreditCard(credit_card); | 391 personal_data_->AddCreditCard(credit_card); |
401 } else { | 392 } else { |
402 personal_data_->UpdateCreditCard(credit_card); | 393 personal_data_->UpdateCreditCard(credit_card); |
403 } | 394 } |
404 } | 395 } |
OLD | NEW |