diff --git a/common/importer/chrome_importer_utils.cc b/common/importer/chrome_importer_utils.cc index 5e9a795da988..b06ffae56624 100644 --- a/common/importer/chrome_importer_utils.cc +++ b/common/importer/chrome_importer_utils.cc @@ -63,11 +63,15 @@ bool ChromeImporterCanImport(const base::FilePath& profile, profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("Bookmarks"))); base::FilePath history = profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("History"))); + base::FilePath passwords = + profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("Login Data"))); if (base::PathExists(bookmarks)) *services_supported |= importer::FAVORITES; if (base::PathExists(history)) *services_supported |= importer::HISTORY; + if (base::PathExists(passwords)) + *services_supported |= importer::PASSWORDS; return *services_supported != importer::NONE; } diff --git a/utility/importer/chrome_importer.cc b/utility/importer/chrome_importer.cc index c469e506d9cd..00d61338255d 100644 --- a/utility/importer/chrome_importer.cc +++ b/utility/importer/chrome_importer.cc @@ -58,6 +58,12 @@ void ChromeImporter::StartImport(const importer::SourceProfile& source_profile, bridge_->NotifyItemEnded(importer::FAVORITES); } + if ((items & importer::PASSWORDS) && !cancelled()) { + bridge_->NotifyItemStarted(importer::PASSWORDS); + ImportPasswords(); + bridge_->NotifyItemEnded(importer::PASSWORDS); + } + bridge_->NotifyEnded(); } @@ -265,3 +271,93 @@ void ChromeImporter::RecursiveReadBookmarksFolder( double ChromeImporter::chromeTimeToDouble(int64_t time) { return ((time * 10 - 0x19DB1DED53E8000) / 10000) / 1000; } + +void ChromeImporter::ImportPasswords() { + #if !defined(USE_X11) + base::FilePath passwords_path = + source_path_.Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Login Data"))); + + password_manager::LoginDatabase database(passwords_path); + if (!database.Init()) { + LOG(ERROR) << "LoginDatabase Init() failed"; + return; + } + + std::vector> forms; + bool success = database.GetAutofillableLogins(&forms); + if (success) { + for (size_t i = 0; i < forms.size(); ++i) { + bridge_->SetPasswordForm(*forms[i].get()); + } + } + std::vector> blacklist; + success = database.GetBlacklistLogins(&blacklist); + if (success) { + for (size_t i = 0; i < blacklist.size(); ++i) { + bridge_->SetPasswordForm(*blacklist[i].get()); + } + } + #else + base::FilePath prefs_path = + source_path_.Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Preferences"))); + const base::Value *value; + scoped_refptr prefs = new JsonPrefStore(prefs_path); + int local_profile_id; + if (prefs->ReadPrefs() != PersistentPrefStore::PREF_READ_ERROR_NONE) { + return; + } + if (!prefs->GetValue(password_manager::prefs::kLocalProfileId, &value)) { + return; + } + if (!value->GetAsInteger(&local_profile_id)) { + return; + } + + std::unique_ptr backend; + base::nix::DesktopEnvironment desktop_env = GetDesktopEnvironment(); + + // WIP proper kEnableEncryptionSelection + os_crypt::SelectedLinuxBackend selected_backend = + os_crypt::SelectBackend(std::string(), true, desktop_env); + if (!backend && + (selected_backend == os_crypt::SelectedLinuxBackend::KWALLET || + selected_backend == os_crypt::SelectedLinuxBackend::KWALLET5)) { + base::nix::DesktopEnvironment used_desktop_env = + selected_backend == os_crypt::SelectedLinuxBackend::KWALLET + ? base::nix::DESKTOP_ENVIRONMENT_KDE4 + : base::nix::DESKTOP_ENVIRONMENT_KDE5; + backend.reset(new NativeBackendKWallet(local_profile_id, + used_desktop_env)); + } else if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || + selected_backend == + os_crypt::SelectedLinuxBackend::GNOME_KEYRING || + selected_backend == + os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { + #if defined(USE_LIBSECRET) + if (!backend && + (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || + selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET)) { + backend.reset(new NativeBackendLibsecret(local_profile_id)); + } + #endif + } + if (backend && backend->Init()) { + std::vector> forms; + bool success = backend->GetAutofillableLogins(&forms); + if (success) { + for (size_t i = 0; i < forms.size(); ++i) { + bridge_->SetPasswordForm(*forms[i].get()); + } + } + std::vector> blacklist; + success = backend->GetBlacklistLogins(&blacklist); + if (success) { + for (size_t i = 0; i < blacklist.size(); ++i) { + bridge_->SetPasswordForm(*blacklist[i].get()); + } + } + } + #endif +} diff --git a/utility/importer/chrome_importer.h b/utility/importer/chrome_importer.h index e3d21194920b..82ea7afd1b55 100644 --- a/utility/importer/chrome_importer.h +++ b/utility/importer/chrome_importer.h @@ -45,6 +45,7 @@ class ChromeImporter : public Importer { void ImportBookmarks(); void ImportHistory(); + void ImportPasswords(); // Multiple URLs can share the same favicon; this is a map // of URLs -> IconIDs that we load as a temporary step before