Chromium Code Reviews| 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/importer/in_process_importer_bridge.h" | 5 #include "chrome/browser/importer/in_process_importer_bridge.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/dump_without_crashing.h" | 8 #include "base/debug/dump_without_crashing.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 low_value.find("moz:") != std::string::npos) { | 94 low_value.find("moz:") != std::string::npos) { |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); | 101 DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 // Creates a TemplateURL with the |keyword| and |url|. |title| may be empty. | 104 // Creates a TemplateURL with the |keyword| and |url|. If the |url| is invalid |
| 105 // then |raw_url| is used in creating the TemplateURL so that it can be | |
| 106 // imported as search engine. |title| and |raw_url| may be empty. | |
|
Ilya Sherman
2014/09/30 20:54:12
nit: "as search engine" -> "as a search engine"
Tapu Ghose
2014/10/07 02:02:43
Done.
| |
| 105 // This function transfers ownership of the created TemplateURL to the caller. | 107 // This function transfers ownership of the created TemplateURL to the caller. |
| 106 TemplateURL* CreateTemplateURL(const base::string16& title, | 108 TemplateURL* CreateTemplateURL(const base::string16& title, |
| 107 const base::string16& keyword, | 109 const base::string16& keyword, |
| 108 const GURL& url) { | 110 const GURL& url, |
| 109 // Skip if the url is invalid. | 111 const base::string16& raw_url) { |
|
Ilya Sherman
2014/09/30 20:54:12
Peter understands the TemplateURL code better than
Peter Kasting
2014/10/01 01:02:54
I agree. The caller should simply not call this i
Tapu Ghose
2014/10/07 02:02:43
Acknowledged.
Tapu Ghose
2014/10/07 02:02:43
In that case I would use |raw_url| and get rid of
| |
| 110 if (!url.is_valid()) | 112 // Skip if the url is invalid and raw_url is empty. |
| 113 if (!url.is_valid() && raw_url.empty()) | |
| 111 return NULL; | 114 return NULL; |
| 112 | 115 |
| 113 TemplateURLData data; | 116 TemplateURLData data; |
| 114 if (keyword.empty()) | 117 if (keyword.empty()) |
| 115 data.SetKeyword(TemplateURL::GenerateKeyword(url)); | 118 data.SetKeyword(TemplateURL::GenerateKeyword(url)); |
| 116 else | 119 else |
| 117 data.SetKeyword(keyword); | 120 data.SetKeyword(keyword); |
| 118 // We set short name by using the title if it exists. | 121 // We set short name by using the title if it exists. |
| 119 // Otherwise, we use the shortcut. | 122 // Otherwise, we use the shortcut. |
| 120 data.short_name = title.empty() ? keyword : title; | 123 data.short_name = title.empty() ? keyword : title; |
| 124 base::string16 str_url = | |
| 125 url.is_valid() ? base::UTF8ToUTF16(url.spec()) : raw_url; | |
| 121 data.SetURL( | 126 data.SetURL( |
| 122 TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec()))); | 127 TemplateURLRef::DisplayURLToURLRef(str_url)); |
| 123 return new TemplateURL(data); | 128 return new TemplateURL(data); |
| 124 } | 129 } |
| 125 | 130 |
| 126 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| | 131 // Parses the OpenSearch XML files in |xml_files| and populates |search_engines| |
| 127 // with the resulting TemplateURLs. | 132 // with the resulting TemplateURLs. |
| 128 void ParseSearchEnginesFromFirefoxXMLData( | 133 void ParseSearchEnginesFromFirefoxXMLData( |
| 129 const std::vector<std::string>& xml_data, | 134 const std::vector<std::string>& xml_data, |
| 130 std::vector<TemplateURL*>* search_engines) { | 135 std::vector<TemplateURL*>* search_engines) { |
| 131 DCHECK(search_engines); | 136 DCHECK(search_engines); |
| 132 | 137 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 } | 236 } |
| 232 | 237 |
| 233 void InProcessImporterBridge::SetKeywords( | 238 void InProcessImporterBridge::SetKeywords( |
| 234 const std::vector<importer::URLKeywordInfo>& url_keywords, | 239 const std::vector<importer::URLKeywordInfo>& url_keywords, |
| 235 bool unique_on_host_and_path) { | 240 bool unique_on_host_and_path) { |
| 236 ScopedVector<TemplateURL> owned_template_urls; | 241 ScopedVector<TemplateURL> owned_template_urls; |
| 237 for (size_t i = 0; i < url_keywords.size(); ++i) { | 242 for (size_t i = 0; i < url_keywords.size(); ++i) { |
| 238 owned_template_urls.push_back( | 243 owned_template_urls.push_back( |
| 239 CreateTemplateURL(url_keywords[i].display_name, | 244 CreateTemplateURL(url_keywords[i].display_name, |
| 240 url_keywords[i].keyword, | 245 url_keywords[i].keyword, |
| 241 url_keywords[i].url)); | 246 url_keywords[i].url, |
| 247 url_keywords[i].raw_url)); | |
| 242 } | 248 } |
| 243 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 249 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 244 base::Bind(&ProfileWriter::AddKeywords, writer_, | 250 base::Bind(&ProfileWriter::AddKeywords, writer_, |
| 245 base::Passed(&owned_template_urls), unique_on_host_and_path)); | 251 base::Passed(&owned_template_urls), unique_on_host_and_path)); |
| 246 } | 252 } |
| 247 | 253 |
| 248 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( | 254 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( |
| 249 const std::vector<std::string>& search_engine_data) { | 255 const std::vector<std::string>& search_engine_data) { |
| 250 std::vector<TemplateURL*> search_engines; | 256 std::vector<TemplateURL*> search_engines; |
| 251 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); | 257 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 BrowserThread::PostTask( | 314 BrowserThread::PostTask( |
| 309 BrowserThread::UI, FROM_HERE, | 315 BrowserThread::UI, FROM_HERE, |
| 310 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); | 316 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); |
| 311 } | 317 } |
| 312 | 318 |
| 313 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { | 319 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { |
| 314 return l10n_util::GetStringUTF16(message_id); | 320 return l10n_util::GetStringUTF16(message_id); |
| 315 } | 321 } |
| 316 | 322 |
| 317 InProcessImporterBridge::~InProcessImporterBridge() {} | 323 InProcessImporterBridge::~InProcessImporterBridge() {} |
| OLD | NEW |