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/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 5176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5187 cards->Append(card_info); | 5187 cards->Append(card_info); |
5188 } | 5188 } |
5189 return cards; | 5189 return cards; |
5190 } | 5190 } |
5191 | 5191 |
5192 /* static */ | 5192 /* static */ |
5193 std::vector<AutofillProfile> | 5193 std::vector<AutofillProfile> |
5194 TestingAutomationProvider::GetAutofillProfilesFromList( | 5194 TestingAutomationProvider::GetAutofillProfilesFromList( |
5195 const ListValue& profiles, std::string* error_message) { | 5195 const ListValue& profiles, std::string* error_message) { |
5196 std::vector<AutofillProfile> autofill_profiles; | 5196 std::vector<AutofillProfile> autofill_profiles; |
5197 DictionaryValue* profile_info = NULL; | 5197 const DictionaryValue* profile_info = NULL; |
5198 ListValue* current_value = NULL; | 5198 const ListValue* current_value = NULL; |
5199 | 5199 |
5200 std::map<AutofillFieldType, std::string> autofill_type_to_string = | 5200 std::map<AutofillFieldType, std::string> autofill_type_to_string = |
5201 GetAutofillFieldToStringMap(); | 5201 GetAutofillFieldToStringMap(); |
5202 | 5202 |
5203 int num_profiles = profiles.GetSize(); | 5203 int num_profiles = profiles.GetSize(); |
5204 for (int i = 0; i < num_profiles; i++) { | 5204 for (int i = 0; i < num_profiles; i++) { |
5205 profiles.GetDictionary(i, &profile_info); | 5205 profiles.GetDictionary(i, &profile_info); |
5206 AutofillProfile profile; | 5206 AutofillProfile profile; |
5207 // Loop through the possible profile types and add those provided. | 5207 // Loop through the possible profile types and add those provided. |
5208 for (std::map<AutofillFieldType, std::string>::iterator type_it = | 5208 for (std::map<AutofillFieldType, std::string>::iterator type_it = |
5209 autofill_type_to_string.begin(); | 5209 autofill_type_to_string.begin(); |
5210 type_it != autofill_type_to_string.end(); ++type_it) { | 5210 type_it != autofill_type_to_string.end(); ++type_it) { |
5211 if (profile_info->HasKey(type_it->second)) { | 5211 if (profile_info->HasKey(type_it->second)) { |
5212 if (profile_info->GetList(type_it->second, ¤t_value)) { | 5212 if (profile_info->GetList(type_it->second, ¤t_value)) { |
5213 std::vector<string16> value_list; | 5213 std::vector<string16> value_list; |
5214 for (ListValue::iterator list_it = current_value->begin(); | 5214 for (ListValue::const_iterator list_it = current_value->begin(); |
5215 list_it != current_value->end(); ++list_it) { | 5215 list_it != current_value->end(); ++list_it) { |
5216 string16 value; | 5216 string16 value; |
5217 if ((*list_it)->GetAsString(&value)) { | 5217 if ((*list_it)->GetAsString(&value)) { |
5218 value_list.insert(value_list.end(), value); | 5218 value_list.insert(value_list.end(), value); |
5219 } else { | 5219 } else { |
5220 *error_message = "All list values must be strings"; | 5220 *error_message = "All list values must be strings"; |
5221 return autofill_profiles; | 5221 return autofill_profiles; |
5222 } | 5222 } |
5223 } | 5223 } |
5224 profile.SetMultiInfo(type_it->first, value_list); | 5224 profile.SetMultiInfo(type_it->first, value_list); |
5225 } else { | 5225 } else { |
5226 *error_message= "All values must be lists"; | 5226 *error_message= "All values must be lists"; |
5227 return autofill_profiles; | 5227 return autofill_profiles; |
5228 } | 5228 } |
5229 } | 5229 } |
5230 } | 5230 } |
5231 autofill_profiles.push_back(profile); | 5231 autofill_profiles.push_back(profile); |
5232 } | 5232 } |
5233 return autofill_profiles; | 5233 return autofill_profiles; |
5234 } | 5234 } |
5235 | 5235 |
5236 /* static */ | 5236 /* static */ |
5237 std::vector<CreditCard> TestingAutomationProvider::GetCreditCardsFromList( | 5237 std::vector<CreditCard> TestingAutomationProvider::GetCreditCardsFromList( |
5238 const ListValue& cards, std::string* error_message) { | 5238 const ListValue& cards, std::string* error_message) { |
5239 std::vector<CreditCard> credit_cards; | 5239 std::vector<CreditCard> credit_cards; |
5240 DictionaryValue* card_info = NULL; | 5240 const DictionaryValue* card_info = NULL; |
5241 string16 current_value; | 5241 string16 current_value; |
5242 | 5242 |
5243 std::map<AutofillFieldType, std::string> credit_card_type_to_string = | 5243 std::map<AutofillFieldType, std::string> credit_card_type_to_string = |
5244 GetCreditCardFieldToStringMap(); | 5244 GetCreditCardFieldToStringMap(); |
5245 | 5245 |
5246 int num_credit_cards = cards.GetSize(); | 5246 int num_credit_cards = cards.GetSize(); |
5247 for (int i = 0; i < num_credit_cards; i++) { | 5247 for (int i = 0; i < num_credit_cards; i++) { |
5248 if (!cards.GetDictionary(i, &card_info)) | 5248 if (!cards.GetDictionary(i, &card_info)) |
5249 continue; | 5249 continue; |
5250 CreditCard card; | 5250 CreditCard card; |
(...skipping 1926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7177 void TestingAutomationProvider::OnRemoveProvider() { | 7177 void TestingAutomationProvider::OnRemoveProvider() { |
7178 if (g_browser_process) | 7178 if (g_browser_process) |
7179 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7179 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
7180 } | 7180 } |
7181 | 7181 |
7182 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 7182 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
7183 WebContents* tab) { | 7183 WebContents* tab) { |
7184 if (chrome::GetActiveWebContents(browser) != tab) | 7184 if (chrome::GetActiveWebContents(browser) != tab) |
7185 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); | 7185 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); |
7186 } | 7186 } |
OLD | NEW |