| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/utility/importer/firefox_importer.h" | 5 #include "chrome/utility/importer/firefox_importer.h" | 
| 6 | 6 | 
| 7 #include <set> | 7 #include <set> | 
| 8 | 8 | 
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" | 
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" | 
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 376 | 376 | 
| 377 void FirefoxImporter::ImportHomepage() { | 377 void FirefoxImporter::ImportHomepage() { | 
| 378   GURL home_page = GetHomepage(source_path_); | 378   GURL home_page = GetHomepage(source_path_); | 
| 379   if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { | 379   if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { | 
| 380     bridge_->AddHomePage(home_page); | 380     bridge_->AddHomePage(home_page); | 
| 381   } | 381   } | 
| 382 } | 382 } | 
| 383 | 383 | 
| 384 void FirefoxImporter::GetSearchEnginesXMLData( | 384 void FirefoxImporter::GetSearchEnginesXMLData( | 
| 385     std::vector<std::string>* search_engine_data) { | 385     std::vector<std::string>* search_engine_data) { | 
|  | 386   // TODO(mpawlowski): This may no longer work, search engines are stored in | 
|  | 387   // search.json since Firefox 3.5, not in search.sqlite. XML definitions are | 
|  | 388   // still necessary. http://crbug.com/329175 | 
| 386   base::FilePath file = source_path_.AppendASCII("search.sqlite"); | 389   base::FilePath file = source_path_.AppendASCII("search.sqlite"); | 
| 387   if (!base::PathExists(file)) | 390   if (!base::PathExists(file)) | 
| 388     return; | 391     return; | 
| 389 | 392 | 
| 390   sql::Connection db; | 393   sql::Connection db; | 
| 391   if (!db.Open(file)) | 394   if (!db.Open(file)) | 
| 392     return; | 395     return; | 
| 393 | 396 | 
| 394   const char* query = "SELECT engineid FROM engine_data " | 397   const char* query = "SELECT engineid FROM engine_data " | 
| 395                       "WHERE engineid NOT IN " | 398                       "WHERE engineid NOT IN " | 
| 396                       "(SELECT engineid FROM engine_data " | 399                       "(SELECT engineid FROM engine_data " | 
| 397                       "WHERE name='hidden') " | 400                       "WHERE name='hidden') " | 
| 398                       "ORDER BY value ASC"; | 401                       "ORDER BY value ASC"; | 
| 399 | 402 | 
| 400   sql::Statement s(db.GetUniqueStatement(query)); | 403   sql::Statement s(db.GetUniqueStatement(query)); | 
| 401   if (!s.is_valid()) | 404   if (!s.is_valid()) | 
| 402     return; | 405     return; | 
| 403 | 406 | 
| 404   base::FilePath app_path = app_path_.AppendASCII("searchplugins"); | 407   const base::FilePath searchplugins_path(FILE_PATH_LITERAL("searchplugins")); | 
| 405   base::FilePath profile_path = source_path_.AppendASCII("searchplugins"); | 408   // Search engine definitions are XMLs stored in two directories. Default | 
|  | 409   // engines are in the app directory (app_path_) and custom engines are | 
|  | 410   // in the profile directory (source_path_). | 
|  | 411 | 
|  | 412   // Since Firefox 21, app_path_ engines are in 'browser' subdirectory: | 
|  | 413   base::FilePath app_path = | 
|  | 414       app_path_.AppendASCII("browser").Append(searchplugins_path); | 
|  | 415   if (!base::PathExists(app_path)) { | 
|  | 416     // This might be an older Firefox, try old location without the 'browser' | 
|  | 417     // path component: | 
|  | 418     app_path = app_path_.Append(searchplugins_path); | 
|  | 419   } | 
|  | 420 | 
|  | 421   base::FilePath profile_path = source_path_.Append(searchplugins_path); | 
| 406 | 422 | 
| 407   // Firefox doesn't store a search engine in its sqlite database unless the | 423   // Firefox doesn't store a search engine in its sqlite database unless the | 
| 408   // user has added a engine. So we get search engines from sqlite db as well | 424   // user has added a engine. So we get search engines from sqlite db as well | 
| 409   // as from the file system. | 425   // as from the file system. | 
| 410   if (s.Step()) { | 426   if (s.Step()) { | 
| 411     const std::string kAppPrefix("[app]/"); | 427     const std::string kAppPrefix("[app]/"); | 
| 412     const std::string kProfilePrefix("[profile]/"); | 428     const std::string kProfilePrefix("[profile]/"); | 
| 413     do { | 429     do { | 
| 414       base::FilePath file; | 430       base::FilePath file; | 
| 415       std::string engine(s.ColumnString(0)); | 431       std::string engine(s.ColumnString(0)); | 
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 595 | 611 | 
| 596       if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 612       if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 
| 597         continue;  // Unable to decode. | 613         continue;  // Unable to decode. | 
| 598 | 614 | 
| 599       usage.urls = i->second; | 615       usage.urls = i->second; | 
| 600       favicons->push_back(usage); | 616       favicons->push_back(usage); | 
| 601     } | 617     } | 
| 602     s.Reset(true); | 618     s.Reset(true); | 
| 603   } | 619   } | 
| 604 } | 620 } | 
| OLD | NEW | 
|---|