OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/importer/firefox_importer_utils.h" | 5 #include "chrome/browser/importer/firefox_importer_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 | 188 |
189 return true; | 189 return true; |
190 } | 190 } |
191 | 191 |
192 void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files, | 192 void ParseSearchEnginesFromXMLFiles(const std::vector<std::wstring>& xml_files, |
193 std::vector<TemplateURL*>* search_engines) { | 193 std::vector<TemplateURL*>* search_engines) { |
194 DCHECK(search_engines); | 194 DCHECK(search_engines); |
195 | 195 |
196 std::map<std::wstring, TemplateURL*> search_engine_for_url; | 196 std::map<std::wstring, TemplateURL*> search_engine_for_url; |
197 std::string content; | 197 std::string content; |
198 bool need_to_increment_iter; | |
198 // The first XML file represents the default search engine in Firefox 3, so we | 199 // The first XML file represents the default search engine in Firefox 3, so we |
199 // need to keep it on top of the list. | 200 // need to keep it on top of the list. |
200 TemplateURL* default_turl = NULL; | 201 TemplateURL* default_turl = NULL; |
201 for (std::vector<std::wstring>::const_iterator iter = xml_files.begin(); | 202 for (std::vector<std::wstring>::const_iterator iter = xml_files.begin(); |
202 iter != xml_files.end(); ++iter) { | 203 iter != xml_files.end();) { |
204 need_to_increment_iter = true; | |
203 file_util::ReadFileToString(*iter, &content); | 205 file_util::ReadFileToString(*iter, &content); |
204 TemplateURL* template_url = new TemplateURL(); | 206 TemplateURL* template_url = new TemplateURL(); |
205 FirefoxURLParameterFilter param_filter; | 207 FirefoxURLParameterFilter param_filter; |
206 if (TemplateURLParser::Parse( | 208 if (TemplateURLParser::Parse( |
207 reinterpret_cast<const unsigned char*>(content.data()), | 209 reinterpret_cast<const unsigned char*>(content.data()), |
208 content.length(), ¶m_filter, template_url) && | 210 content.length(), ¶m_filter, template_url) && |
209 template_url->url()) { | 211 template_url->url()) { |
210 std::wstring url = template_url->url()->url(); | 212 std::wstring url = template_url->url()->url(); |
211 std::map<std::wstring, TemplateURL*>::iterator iter = | 213 std::map<std::wstring, TemplateURL*>::iterator iter = |
212 search_engine_for_url.find(url); | 214 search_engine_for_url.find(url); |
213 if (iter != search_engine_for_url.end()) { | 215 if (iter != search_engine_for_url.end()) { |
214 // We have already found a search engine with the same URL. We give | 216 // We have already found a search engine with the same URL. We give |
215 // priority to the latest one found, as GetSearchEnginesXMLFiles() | 217 // priority to the latest one found, as GetSearchEnginesXMLFiles() |
216 // returns a vector with first Firefox default search engines and then | 218 // returns a vector with first Firefox default search engines and then |
217 // the user's ones. We want to give priority to the user ones. | 219 // the user's ones. We want to give priority to the user ones. |
218 delete iter->second; | 220 delete iter->second; |
219 search_engine_for_url.erase(iter); | 221 iter = search_engine_for_url.erase(iter); |
222 need_to_increment_iter = false; | |
MAD
2009/02/26 18:13:24
This is not the same iter as the one used for the
| |
220 } | 223 } |
221 // Give this a keyword to facilitate tab-to-search, if possible. | 224 // Give this a keyword to facilitate tab-to-search, if possible. |
222 template_url->set_keyword(TemplateURLModel::GenerateKeyword(GURL(url), | 225 template_url->set_keyword(TemplateURLModel::GenerateKeyword(GURL(url), |
223 false)); | 226 false)); |
224 template_url->set_show_in_default_list(true); | 227 template_url->set_show_in_default_list(true); |
225 search_engine_for_url[url] = template_url; | 228 search_engine_for_url[url] = template_url; |
226 if (!default_turl) | 229 if (!default_turl) |
227 default_turl = template_url; | 230 default_turl = template_url; |
228 } else { | 231 } else { |
229 delete template_url; | 232 delete template_url; |
230 } | 233 } |
231 content.clear(); | 234 content.clear(); |
235 if (need_to_increment_iter) | |
236 ++iter; | |
232 } | 237 } |
233 | 238 |
234 // Put the results in the |search_engines| vector. | 239 // Put the results in the |search_engines| vector. |
235 std::map<std::wstring, TemplateURL*>::iterator t_iter; | 240 std::map<std::wstring, TemplateURL*>::iterator t_iter; |
236 for (t_iter = search_engine_for_url.begin(); | 241 for (t_iter = search_engine_for_url.begin(); |
237 t_iter != search_engine_for_url.end(); ++t_iter) { | 242 t_iter != search_engine_for_url.end(); ++t_iter) { |
238 if (t_iter->second == default_turl) | 243 if (t_iter->second == default_turl) |
239 search_engines->insert(search_engines->begin(), default_turl); | 244 search_engines->insert(search_engines->begin(), default_turl); |
240 else | 245 else |
241 search_engines->push_back(t_iter->second); | 246 search_engines->push_back(t_iter->second); |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 // Version 3 has an extra line for further use. | 733 // Version 3 has an extra line for further use. |
729 if (version == 3) { | 734 if (version == 3) { |
730 ++begin; | 735 ++begin; |
731 } | 736 } |
732 | 737 |
733 forms->push_back(form); | 738 forms->push_back(form); |
734 } | 739 } |
735 } | 740 } |
736 } | 741 } |
737 | 742 |
OLD | NEW |