Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/importer/firefox3_importer.cc

Issue 3221007: Fix a couple of firefox search engine import bugs. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: added test, TODO Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/firefox3_importer.h" 5 #include "chrome/browser/importer/firefox3_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/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/stl_util-inl.h" 12 #include "base/stl_util-inl.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/history/history_types.h" 16 #include "chrome/browser/history/history_types.h"
16 #include "chrome/browser/importer/firefox2_importer.h" 17 #include "chrome/browser/importer/firefox2_importer.h"
17 #include "chrome/browser/importer/firefox_importer_utils.h" 18 #include "chrome/browser/importer/firefox_importer_utils.h"
18 #include "chrome/browser/importer/importer_bridge.h" 19 #include "chrome/browser/importer/importer_bridge.h"
19 #include "chrome/browser/importer/importer_data_types.h" 20 #include "chrome/browser/importer/importer_data_types.h"
20 #include "chrome/browser/importer/nss_decryptor.h" 21 #include "chrome/browser/importer/nss_decryptor.h"
21 #include "chrome/browser/search_engines/template_url.h" 22 #include "chrome/browser/search_engines/template_url.h"
22 #include "chrome/common/time_format.h" 23 #include "chrome/common/time_format.h"
23 #include "chrome/common/sqlite_utils.h" 24 #include "chrome/common/sqlite_utils.h"
24 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
25 #include "webkit/glue/password_form.h" 26 #include "webkit/glue/password_form.h"
26 27
27 using base::Time; 28 using base::Time;
28 using importer::BOOKMARKS_HTML; 29 using importer::BOOKMARKS_HTML;
29 using importer::FAVORITES; 30 using importer::FAVORITES;
30 using importer::HISTORY; 31 using importer::HISTORY;
31 using importer::HOME_PAGE; 32 using importer::HOME_PAGE;
32 using importer::PASSWORDS; 33 using importer::PASSWORDS;
33 using importer::ProfileInfo; 34 using importer::ProfileInfo;
34 using importer::SEARCH_ENGINES; 35 using importer::SEARCH_ENGINES;
35 using webkit_glue::PasswordForm; 36 using webkit_glue::PasswordForm;
36 37
38 Firefox3Importer::Firefox3Importer() {
39 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
40
41 locale_ = g_browser_process->GetApplicationLocale();
42 }
43
44 Firefox3Importer::~Firefox3Importer() {
45 }
46
37 void Firefox3Importer::StartImport(importer::ProfileInfo profile_info, 47 void Firefox3Importer::StartImport(importer::ProfileInfo profile_info,
38 uint16 items, 48 uint16 items,
39 ImporterBridge* bridge) { 49 ImporterBridge* bridge) {
50 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
40 bridge_ = bridge; 51 bridge_ = bridge;
41 source_path_ = profile_info.source_path; 52 source_path_ = profile_info.source_path;
42 app_path_ = profile_info.app_path; 53 app_path_ = profile_info.app_path;
43 54
44
45 // The order here is important! 55 // The order here is important!
46 bridge_->NotifyStarted(); 56 bridge_->NotifyStarted();
47 if ((items & importer::HOME_PAGE) && !cancelled()) 57 if ((items & importer::HOME_PAGE) && !cancelled())
48 ImportHomepage(); // Doesn't have a UI item. 58 ImportHomepage(); // Doesn't have a UI item.
49 59
50 // Note history should be imported before bookmarks because bookmark import 60 // Note history should be imported before bookmarks because bookmark import
51 // will also import favicons and we store favicon for a URL only if the URL 61 // will also import favicons and we store favicon for a URL only if the URL
52 // exist in history or bookmarks. 62 // exist in history or bookmarks.
53 if ((items & importer::HISTORY) && !cancelled()) { 63 if ((items & importer::HISTORY) && !cancelled()) {
54 bridge_->NotifyItemStarted(importer::HISTORY); 64 bridge_->NotifyItemStarted(importer::HISTORY);
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 "(SELECT engineid FROM engine_data " 353 "(SELECT engineid FROM engine_data "
344 "WHERE name='hidden') " 354 "WHERE name='hidden') "
345 "ORDER BY value ASC"; 355 "ORDER BY value ASC";
346 356
347 if (s.prepare(db.get(), stmt) != SQLITE_OK) 357 if (s.prepare(db.get(), stmt) != SQLITE_OK)
348 return; 358 return;
349 359
350 FilePath app_path = app_path_.AppendASCII("searchplugins"); 360 FilePath app_path = app_path_.AppendASCII("searchplugins");
351 FilePath profile_path = source_path_.AppendASCII("searchplugins"); 361 FilePath profile_path = source_path_.AppendASCII("searchplugins");
352 362
353 // Firefox doesn't store a search engine in its sqlite database unless 363 // Firefox doesn't store a search engine in its sqlite database unless the
354 // the user has changed the default definition of engine. So we get search 364 // user has added a engine. So we get search engines from sqlite db as well
355 // engines from sqlite db as well as from file system. 365 // as from the file system.
356 if (s.step() == SQLITE_ROW) { 366 if (s.step() == SQLITE_ROW) {
357 const std::wstring kAppPrefix = L"[app]/"; 367 const std::wstring kAppPrefix = L"[app]/";
358 const std::wstring kProfilePrefix = L"[profile]/"; 368 const std::wstring kProfilePrefix = L"[profile]/";
359 do { 369 do {
360 FilePath file; 370 FilePath file;
361 std::wstring engine = UTF8ToWide(s.column_string(0)); 371 std::wstring engine = UTF8ToWide(s.column_string(0));
362 372
363 // The string contains [app]/<name>.xml or [profile]/<name>.xml where 373 // The string contains [app]/<name>.xml or [profile]/<name>.xml where
364 // the [app] and [profile] need to be replaced with the actual app or 374 // the [app] and [profile] need to be replaced with the actual app or
365 // profile path. 375 // profile path.
366 size_t index = engine.find(kAppPrefix); 376 size_t index = engine.find(kAppPrefix);
367 if (index != std::wstring::npos) { 377 if (index != std::wstring::npos) {
368 // Remove '[app]/'. 378 // Remove '[app]/'.
369 file = app_path.Append(FilePath::FromWStringHack( 379 file = app_path.Append(FilePath::FromWStringHack(
370 engine.substr(index + kAppPrefix.length()))); 380 engine.substr(index + kAppPrefix.length())));
371 } else if ((index = engine.find(kProfilePrefix)) != std::wstring::npos) { 381 } else if ((index = engine.find(kProfilePrefix)) != std::wstring::npos) {
372 // Remove '[profile]/'. 382 // Remove '[profile]/'.
373 file = profile_path.Append( 383 file = profile_path.Append(
374 FilePath::FromWStringHack( 384 FilePath::FromWStringHack(
375 engine.substr(index + kProfilePrefix.length()))); 385 engine.substr(index + kProfilePrefix.length())));
376 } else { 386 } else {
377 // Looks like absolute path to the file. 387 // Looks like absolute path to the file.
378 file = FilePath::FromWStringHack(engine); 388 file = FilePath::FromWStringHack(engine);
379 } 389 }
380 files->push_back(file); 390 files->push_back(file);
381 } while (s.step() == SQLITE_ROW && !cancelled()); 391 } while (s.step() == SQLITE_ROW && !cancelled());
382 } 392 }
383 393
394 #if defined(OS_LINUX)
395 // Ubuntu-flavored Firefox3 supports locale-specific search engines via
396 // locale-named subdirectories. They fall back to en-US.
397 // See http://crbug.com/53899
398 // TODO(jshin): we need to make sure our locale code matches that of
399 // Firefox.
400 FilePath locale_app_path = app_path.AppendASCII(locale_);
401 FilePath default_locale_app_path = app_path.AppendASCII("en-US");
402 if (file_util::DirectoryExists(locale_app_path))
403 app_path = locale_app_path;
404 else if (file_util::DirectoryExists(default_locale_app_path))
405 app_path = default_locale_app_path;
406 #endif
407
384 // Get search engine definition from file system. 408 // Get search engine definition from file system.
385 file_util::FileEnumerator engines(app_path, false, 409 file_util::FileEnumerator engines(app_path, false,
386 file_util::FileEnumerator::FILES); 410 file_util::FileEnumerator::FILES);
387 for (FilePath engine_path = engines.Next(); !engine_path.value().empty(); 411 for (FilePath engine_path = engines.Next(); !engine_path.value().empty();
388 engine_path = engines.Next()) { 412 engine_path = engines.Next()) {
389 files->push_back(engine_path); 413 files->push_back(engine_path);
390 } 414 }
391 } 415 }
392 416
393 void Firefox3Importer::LoadRootNodeID(sqlite3* db, 417 void Firefox3Importer::LoadRootNodeID(sqlite3* db,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 548
525 if (!ReencodeFavicon(&data[0], data.size(), &usage.png_data)) 549 if (!ReencodeFavicon(&data[0], data.size(), &usage.png_data))
526 continue; // Unable to decode. 550 continue; // Unable to decode.
527 551
528 usage.urls = i->second; 552 usage.urls = i->second;
529 favicons->push_back(usage); 553 favicons->push_back(usage);
530 } 554 }
531 s.reset(); 555 s.reset();
532 } 556 }
533 } 557 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox3_importer.h ('k') | chrome/browser/importer/firefox_importer_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698