| 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 5093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5104 cards->Append(card_info); | 5104 cards->Append(card_info); |
| 5105 } | 5105 } |
| 5106 return cards; | 5106 return cards; |
| 5107 } | 5107 } |
| 5108 | 5108 |
| 5109 /* static */ | 5109 /* static */ |
| 5110 std::vector<AutofillProfile> | 5110 std::vector<AutofillProfile> |
| 5111 TestingAutomationProvider::GetAutofillProfilesFromList( | 5111 TestingAutomationProvider::GetAutofillProfilesFromList( |
| 5112 const ListValue& profiles, std::string* error_message) { | 5112 const ListValue& profiles, std::string* error_message) { |
| 5113 std::vector<AutofillProfile> autofill_profiles; | 5113 std::vector<AutofillProfile> autofill_profiles; |
| 5114 DictionaryValue* profile_info = NULL; | 5114 const DictionaryValue* profile_info = NULL; |
| 5115 ListValue* current_value = NULL; | 5115 const ListValue* current_value = NULL; |
| 5116 | 5116 |
| 5117 std::map<AutofillFieldType, std::string> autofill_type_to_string = | 5117 std::map<AutofillFieldType, std::string> autofill_type_to_string = |
| 5118 GetAutofillFieldToStringMap(); | 5118 GetAutofillFieldToStringMap(); |
| 5119 | 5119 |
| 5120 int num_profiles = profiles.GetSize(); | 5120 int num_profiles = profiles.GetSize(); |
| 5121 for (int i = 0; i < num_profiles; i++) { | 5121 for (int i = 0; i < num_profiles; i++) { |
| 5122 profiles.GetDictionary(i, &profile_info); | 5122 profiles.GetDictionary(i, &profile_info); |
| 5123 AutofillProfile profile; | 5123 AutofillProfile profile; |
| 5124 // Loop through the possible profile types and add those provided. | 5124 // Loop through the possible profile types and add those provided. |
| 5125 for (std::map<AutofillFieldType, std::string>::iterator type_it = | 5125 for (std::map<AutofillFieldType, std::string>::iterator type_it = |
| 5126 autofill_type_to_string.begin(); | 5126 autofill_type_to_string.begin(); |
| 5127 type_it != autofill_type_to_string.end(); ++type_it) { | 5127 type_it != autofill_type_to_string.end(); ++type_it) { |
| 5128 if (profile_info->HasKey(type_it->second)) { | 5128 if (profile_info->HasKey(type_it->second)) { |
| 5129 if (profile_info->GetList(type_it->second, ¤t_value)) { | 5129 if (profile_info->GetList(type_it->second, ¤t_value)) { |
| 5130 std::vector<string16> value_list; | 5130 std::vector<string16> value_list; |
| 5131 for (ListValue::iterator list_it = current_value->begin(); | 5131 for (ListValue::const_iterator list_it = current_value->begin(); |
| 5132 list_it != current_value->end(); ++list_it) { | 5132 list_it != current_value->end(); ++list_it) { |
| 5133 string16 value; | 5133 string16 value; |
| 5134 if ((*list_it)->GetAsString(&value)) { | 5134 if ((*list_it)->GetAsString(&value)) { |
| 5135 value_list.insert(value_list.end(), value); | 5135 value_list.insert(value_list.end(), value); |
| 5136 } else { | 5136 } else { |
| 5137 *error_message = "All list values must be strings"; | 5137 *error_message = "All list values must be strings"; |
| 5138 return autofill_profiles; | 5138 return autofill_profiles; |
| 5139 } | 5139 } |
| 5140 } | 5140 } |
| 5141 profile.SetMultiInfo(type_it->first, value_list); | 5141 profile.SetMultiInfo(type_it->first, value_list); |
| 5142 } else { | 5142 } else { |
| 5143 *error_message= "All values must be lists"; | 5143 *error_message= "All values must be lists"; |
| 5144 return autofill_profiles; | 5144 return autofill_profiles; |
| 5145 } | 5145 } |
| 5146 } | 5146 } |
| 5147 } | 5147 } |
| 5148 autofill_profiles.push_back(profile); | 5148 autofill_profiles.push_back(profile); |
| 5149 } | 5149 } |
| 5150 return autofill_profiles; | 5150 return autofill_profiles; |
| 5151 } | 5151 } |
| 5152 | 5152 |
| 5153 /* static */ | 5153 /* static */ |
| 5154 std::vector<CreditCard> TestingAutomationProvider::GetCreditCardsFromList( | 5154 std::vector<CreditCard> TestingAutomationProvider::GetCreditCardsFromList( |
| 5155 const ListValue& cards, std::string* error_message) { | 5155 const ListValue& cards, std::string* error_message) { |
| 5156 std::vector<CreditCard> credit_cards; | 5156 std::vector<CreditCard> credit_cards; |
| 5157 DictionaryValue* card_info = NULL; | 5157 const DictionaryValue* card_info = NULL; |
| 5158 string16 current_value; | 5158 string16 current_value; |
| 5159 | 5159 |
| 5160 std::map<AutofillFieldType, std::string> credit_card_type_to_string = | 5160 std::map<AutofillFieldType, std::string> credit_card_type_to_string = |
| 5161 GetCreditCardFieldToStringMap(); | 5161 GetCreditCardFieldToStringMap(); |
| 5162 | 5162 |
| 5163 int num_credit_cards = cards.GetSize(); | 5163 int num_credit_cards = cards.GetSize(); |
| 5164 for (int i = 0; i < num_credit_cards; i++) { | 5164 for (int i = 0; i < num_credit_cards; i++) { |
| 5165 if (!cards.GetDictionary(i, &card_info)) | 5165 if (!cards.GetDictionary(i, &card_info)) |
| 5166 continue; | 5166 continue; |
| 5167 CreditCard card; | 5167 CreditCard card; |
| (...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7084 void TestingAutomationProvider::OnRemoveProvider() { | 7084 void TestingAutomationProvider::OnRemoveProvider() { |
| 7085 if (g_browser_process) | 7085 if (g_browser_process) |
| 7086 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7086 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 7087 } | 7087 } |
| 7088 | 7088 |
| 7089 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 7089 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 7090 WebContents* tab) { | 7090 WebContents* tab) { |
| 7091 if (chrome::GetActiveWebContents(browser) != tab) | 7091 if (chrome::GetActiveWebContents(browser) != tab) |
| 7092 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); | 7092 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); |
| 7093 } | 7093 } |
| OLD | NEW |