Commit e0262c9d authored by mirandac@chromium.org's avatar mirandac@chromium.org

Ensure that Firefox search engines are imported correctly.

It also makes sure that engines which have been removed from Firefox
are not imported into Chrome.

BUG= http://crbug.com/12245
TEST= Install firefox, and do not change the default search engines.
Start Chrome, and import search engines from Firefox.  Default Firefox
engines should now be part of Chrome.


Review URL: http://codereview.chromium.org/115895

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17207 0039d316-1c4b-4281-b951-d872f2087c98
parent b6946352
...@@ -325,7 +325,11 @@ void Firefox3Importer::GetSearchEnginesXMLFiles( ...@@ -325,7 +325,11 @@ void Firefox3Importer::GetSearchEnginesXMLFiles(
scoped_ptr_malloc<sqlite3, DBClose> db(sqlite); scoped_ptr_malloc<sqlite3, DBClose> db(sqlite);
SQLStatement s; SQLStatement s;
const char* stmt = "SELECT engineid FROM engine_data ORDER BY value ASC"; const char* stmt = "SELECT engineid FROM engine_data "
"WHERE engineid NOT IN "
"(SELECT engineid FROM engine_data "
"WHERE name='hidden') "
"ORDER BY value ASC";
if (s.prepare(db.get(), stmt) != SQLITE_OK) if (s.prepare(db.get(), stmt) != SQLITE_OK)
return; return;
...@@ -335,31 +339,48 @@ void Firefox3Importer::GetSearchEnginesXMLFiles( ...@@ -335,31 +339,48 @@ void Firefox3Importer::GetSearchEnginesXMLFiles(
std::wstring profile_path = source_path_; std::wstring profile_path = source_path_;
file_util::AppendToPath(&profile_path, L"searchplugins"); file_util::AppendToPath(&profile_path, L"searchplugins");
const std::wstring kAppPrefix = L"[app]/"; // Firefox doesn't store any search engines in its sqlite database unless
const std::wstring kProfilePrefix = L"[profile]/"; // the user has changed the standard set of engines. If we find that the
while (s.step() == SQLITE_ROW && !cancelled()) { // database is empty, get the standard Firefox set from the app folder.
std::wstring file; if (s.step() != SQLITE_ROW) {
std::wstring engine = UTF8ToWide(s.column_string(0)); file_util::FileEnumerator engines(FilePath::FromWStringHack(app_path),
// The string contains [app]/<name>.xml or [profile]/<name>.xml where the false,
// [app] and [profile] need to be replaced with the actual app or profile file_util::FileEnumerator::FILES);
// path. for (FilePath engine_path = engines.Next(); !engine_path.value().empty();
size_t index = engine.find(kAppPrefix); engine_path = engines.Next()) {
if (index != std::wstring::npos) { std::wstring enginew = engine_path.ToWStringHack();
file = app_path; files->push_back(enginew);
file_util::AppendToPath(
&file,
engine.substr(index + kAppPrefix.length())); // Remove '[app]/'.
} else if ((index = engine.find(kProfilePrefix)) != std::wstring::npos) {
file = profile_path;
file_util::AppendToPath(
&file,
engine.substr(index + kProfilePrefix.length())); // Remove
// '[profile]/'.
} else {
NOTREACHED() << "Unexpected Firefox 3 search engine id";
continue;
} }
files->push_back(file); } else {
const std::wstring kAppPrefix = L"[app]/";
const std::wstring kProfilePrefix = L"[profile]/";
do {
std::wstring file;
std::wstring engine = UTF8ToWide(s.column_string(0));
// The string contains [app]/<name>.xml or [profile]/<name>.xml where
// the [app] and [profile] need to be replaced with the actual app or
// profile path.
size_t index = engine.find(kAppPrefix);
if (index != std::wstring::npos) {
// Remove '[app]/'.
file = app_path;
file_util::AppendToPath(
&file,
engine.substr(index + kAppPrefix.length()));
} else if ((index = engine.find(kProfilePrefix)) !=
std::wstring::npos) {
// Remove '[profile]/'.
file = profile_path;
file_util::AppendToPath(
&file,
engine.substr(index + kProfilePrefix.length()));
} else {
NOTREACHED() << "Unexpected Firefox 3 search engine id";
continue;
}
files->push_back(file);
} while (s.step() == SQLITE_ROW && !cancelled());
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment