| 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/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 4186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4197 // For each AutofillProfile, transform it to a dictionary object to return. | 4197 // For each AutofillProfile, transform it to a dictionary object to return. |
| 4198 for (std::vector<AutofillProfile*>::const_iterator it = | 4198 for (std::vector<AutofillProfile*>::const_iterator it = |
| 4199 autofill_profiles.begin(); | 4199 autofill_profiles.begin(); |
| 4200 it != autofill_profiles.end(); ++it) { | 4200 it != autofill_profiles.end(); ++it) { |
| 4201 AutofillProfile* profile = *it; | 4201 AutofillProfile* profile = *it; |
| 4202 DictionaryValue* profile_info = new DictionaryValue; | 4202 DictionaryValue* profile_info = new DictionaryValue; |
| 4203 // For each of the types, if it has a value, add it to the dictionary. | 4203 // For each of the types, if it has a value, add it to the dictionary. |
| 4204 for (std::map<AutofillFieldType, std::string>::iterator | 4204 for (std::map<AutofillFieldType, std::string>::iterator |
| 4205 type_it = autofill_type_to_string.begin(); | 4205 type_it = autofill_type_to_string.begin(); |
| 4206 type_it != autofill_type_to_string.end(); ++type_it) { | 4206 type_it != autofill_type_to_string.end(); ++type_it) { |
| 4207 string16 value = profile->GetFieldText(AutofillType(type_it->first)); | 4207 string16 value = profile->GetFieldText(type_it->first); |
| 4208 if (value.length()) { // If there was something stored for that value. | 4208 if (value.length()) { // If there was something stored for that value. |
| 4209 profile_info->SetString(type_it->second, value); | 4209 profile_info->SetString(type_it->second, value); |
| 4210 } | 4210 } |
| 4211 } | 4211 } |
| 4212 profiles->Append(profile_info); | 4212 profiles->Append(profile_info); |
| 4213 } | 4213 } |
| 4214 return profiles; | 4214 return profiles; |
| 4215 } | 4215 } |
| 4216 | 4216 |
| 4217 /* static */ | 4217 /* static */ |
| 4218 ListValue* TestingAutomationProvider::GetListFromCreditCards( | 4218 ListValue* TestingAutomationProvider::GetListFromCreditCards( |
| 4219 const std::vector<CreditCard*>& credit_cards) { | 4219 const std::vector<CreditCard*>& credit_cards) { |
| 4220 ListValue* cards = new ListValue; | 4220 ListValue* cards = new ListValue; |
| 4221 | 4221 |
| 4222 std::map<AutofillFieldType, std::string> credit_card_type_to_string = | 4222 std::map<AutofillFieldType, std::string> credit_card_type_to_string = |
| 4223 GetCreditCardFieldToStringMap(); | 4223 GetCreditCardFieldToStringMap(); |
| 4224 | 4224 |
| 4225 // For each AutofillProfile, transform it to a dictionary object to return. | 4225 // For each AutofillProfile, transform it to a dictionary object to return. |
| 4226 for (std::vector<CreditCard*>::const_iterator it = | 4226 for (std::vector<CreditCard*>::const_iterator it = |
| 4227 credit_cards.begin(); | 4227 credit_cards.begin(); |
| 4228 it != credit_cards.end(); ++it) { | 4228 it != credit_cards.end(); ++it) { |
| 4229 CreditCard* card = *it; | 4229 CreditCard* card = *it; |
| 4230 DictionaryValue* card_info = new DictionaryValue; | 4230 DictionaryValue* card_info = new DictionaryValue; |
| 4231 // For each of the types, if it has a value, add it to the dictionary. | 4231 // For each of the types, if it has a value, add it to the dictionary. |
| 4232 for (std::map<AutofillFieldType, std::string>::iterator type_it = | 4232 for (std::map<AutofillFieldType, std::string>::iterator type_it = |
| 4233 credit_card_type_to_string.begin(); | 4233 credit_card_type_to_string.begin(); |
| 4234 type_it != credit_card_type_to_string.end(); ++type_it) { | 4234 type_it != credit_card_type_to_string.end(); ++type_it) { |
| 4235 string16 value = card->GetFieldText(AutofillType(type_it->first)); | 4235 string16 value = card->GetFieldText(type_it->first); |
| 4236 // If there was something stored for that value. | 4236 // If there was something stored for that value. |
| 4237 if (value.length()) { | 4237 if (value.length()) { |
| 4238 card_info->SetString(type_it->second, value); | 4238 card_info->SetString(type_it->second, value); |
| 4239 } | 4239 } |
| 4240 } | 4240 } |
| 4241 cards->Append(card_info); | 4241 cards->Append(card_info); |
| 4242 } | 4242 } |
| 4243 return cards; | 4243 return cards; |
| 4244 } | 4244 } |
| 4245 | 4245 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4258 for (int i = 0; i < num_profiles; i++) { | 4258 for (int i = 0; i < num_profiles; i++) { |
| 4259 profiles.GetDictionary(i, &profile_info); | 4259 profiles.GetDictionary(i, &profile_info); |
| 4260 AutofillProfile profile; | 4260 AutofillProfile profile; |
| 4261 // Loop through the possible profile types and add those provided. | 4261 // Loop through the possible profile types and add those provided. |
| 4262 for (std::map<AutofillFieldType, std::string>::iterator type_it = | 4262 for (std::map<AutofillFieldType, std::string>::iterator type_it = |
| 4263 autofill_type_to_string.begin(); | 4263 autofill_type_to_string.begin(); |
| 4264 type_it != autofill_type_to_string.end(); ++type_it) { | 4264 type_it != autofill_type_to_string.end(); ++type_it) { |
| 4265 if (profile_info->HasKey(type_it->second)) { | 4265 if (profile_info->HasKey(type_it->second)) { |
| 4266 if (profile_info->GetString(type_it->second, | 4266 if (profile_info->GetString(type_it->second, |
| 4267 ¤t_value)) { | 4267 ¤t_value)) { |
| 4268 profile.SetInfo(AutofillType(type_it->first), current_value); | 4268 profile.SetInfo(type_it->first, current_value); |
| 4269 } else { | 4269 } else { |
| 4270 *error_message= "All values must be strings"; | 4270 *error_message= "All values must be strings"; |
| 4271 break; | 4271 break; |
| 4272 } | 4272 } |
| 4273 } | 4273 } |
| 4274 } | 4274 } |
| 4275 autofill_profiles.push_back(profile); | 4275 autofill_profiles.push_back(profile); |
| 4276 } | 4276 } |
| 4277 return autofill_profiles; | 4277 return autofill_profiles; |
| 4278 } | 4278 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4290 int num_credit_cards = cards.GetSize(); | 4290 int num_credit_cards = cards.GetSize(); |
| 4291 for (int i = 0; i < num_credit_cards; i++) { | 4291 for (int i = 0; i < num_credit_cards; i++) { |
| 4292 cards.GetDictionary(i, &card_info); | 4292 cards.GetDictionary(i, &card_info); |
| 4293 CreditCard card; | 4293 CreditCard card; |
| 4294 // Loop through the possible credit card fields and add those provided. | 4294 // Loop through the possible credit card fields and add those provided. |
| 4295 for (std::map<AutofillFieldType, std::string>::iterator type_it = | 4295 for (std::map<AutofillFieldType, std::string>::iterator type_it = |
| 4296 credit_card_type_to_string.begin(); | 4296 credit_card_type_to_string.begin(); |
| 4297 type_it != credit_card_type_to_string.end(); ++type_it) { | 4297 type_it != credit_card_type_to_string.end(); ++type_it) { |
| 4298 if (card_info->HasKey(type_it->second)) { | 4298 if (card_info->HasKey(type_it->second)) { |
| 4299 if (card_info->GetString(type_it->second, ¤t_value)) { | 4299 if (card_info->GetString(type_it->second, ¤t_value)) { |
| 4300 card.SetInfo(AutofillType(type_it->first), current_value); | 4300 card.SetInfo(type_it->first, current_value); |
| 4301 } else { | 4301 } else { |
| 4302 *error_message= "All values must be strings"; | 4302 *error_message= "All values must be strings"; |
| 4303 break; | 4303 break; |
| 4304 } | 4304 } |
| 4305 } | 4305 } |
| 4306 } | 4306 } |
| 4307 credit_cards.push_back(card); | 4307 credit_cards.push_back(card); |
| 4308 } | 4308 } |
| 4309 return credit_cards; | 4309 return credit_cards; |
| 4310 } | 4310 } |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5198 // If you change this, update Observer for NotificationType::SESSION_END | 5198 // If you change this, update Observer for NotificationType::SESSION_END |
| 5199 // below. | 5199 // below. |
| 5200 MessageLoop::current()->PostTask(FROM_HERE, | 5200 MessageLoop::current()->PostTask(FROM_HERE, |
| 5201 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5201 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5202 } | 5202 } |
| 5203 } | 5203 } |
| 5204 | 5204 |
| 5205 void TestingAutomationProvider::OnRemoveProvider() { | 5205 void TestingAutomationProvider::OnRemoveProvider() { |
| 5206 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5206 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5207 } | 5207 } |
| OLD | NEW |