diff --git a/chromium_src/chrome/browser/importer/importer_list.cc b/chromium_src/chrome/browser/importer/importer_list.cc index 04c7e1883dc..d0d66c7178a 100644 --- a/chromium_src/chrome/browser/importer/importer_list.cc +++ b/chromium_src/chrome/browser/importer/importer_list.cc @@ -24,8 +24,9 @@ void AddChromeToProfiles(std::vector* profiles, importer::ImporterType type) { for (const auto& value : chrome_profiles) { const auto* dict = value.GetIfDict(); - if (!dict) + if (!dict) { continue; + } uint16_t items = importer::NONE; auto* profile = dict->FindString("id"); auto* name = dict->FindString("name"); @@ -34,15 +35,9 @@ void AddChromeToProfiles(std::vector* profiles, base::FilePath path = user_data_folder; if (!ChromeImporterCanImport(path.Append(base::FilePath::StringType( profile->begin(), profile->end())), - &items)) + type, &items)) { continue; -#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) - // We can import password from Whale only on macOS. - // Decryption failed on Windows and Linux. - if (type == importer::TYPE_WHALE && (items & importer::PASSWORDS)) { - items ^= importer::PASSWORDS; } -#endif importer::SourceProfile chrome; chrome.importer_name = base::UTF8ToUTF16(base::StrCat({brand, " ", *name})); chrome.importer_type = type; diff --git a/common/importer/chrome_importer_utils.cc b/common/importer/chrome_importer_utils.cc index b5374611d08..ee3cd663228 100644 --- a/common/importer/chrome_importer_utils.cc +++ b/common/importer/chrome_importer_utils.cc @@ -148,6 +148,25 @@ bool IsLastActiveProfile(const std::string& profile, return false; } +bool CanImportPasswordsForType(importer::ImporterType type) { + // We can't import passwords from Chrome due to encryption. See + // https://github.com/brave/brave-browser/issues/34046 + // #issuecomment-2857856039 + if (type == importer::TYPE_CHROME) { + return false; + } + + // We can import password from Whale only on macOS. Decryption fails on + // Windows and Linux. +#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) + if (type == importer::TYPE_WHALE) { + return false; + } +#endif + + return true; +} + } // namespace base::Value::List GetChromeSourceProfiles( @@ -207,27 +226,38 @@ base::Value::List GetChromeSourceProfiles( } bool ChromeImporterCanImport(const base::FilePath& profile, + importer::ImporterType type, uint16_t* services_supported) { DCHECK(services_supported); *services_supported = importer::NONE; - base::FilePath bookmarks = - 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"))); - base::FilePath passwords_for_account = profile.Append( - base::FilePath::StringType(FILE_PATH_LITERAL("Login Data For Account"))); - if (base::PathExists(bookmarks)) + base::FilePath bookmarks = profile.Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Bookmarks"))); + if (base::PathExists(bookmarks)) { *services_supported |= importer::FAVORITES; - if (base::PathExists(history)) - *services_supported |= importer::HISTORY; - if (base::PathExists(passwords) || base::PathExists(passwords_for_account)) { - *services_supported |= importer::PASSWORDS; } + + base::FilePath history = + profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("History"))); + if (base::PathExists(history)) { + *services_supported |= importer::HISTORY; + } + + if (CanImportPasswordsForType(type)) { + base::FilePath passwords = profile.Append( + base::FilePath::StringType(FILE_PATH_LITERAL("Login Data"))); + base::FilePath passwords_for_account = + profile.Append(base::FilePath::StringType( + FILE_PATH_LITERAL("Login Data For Account"))); + if (base::PathExists(passwords) || + base::PathExists(passwords_for_account)) { + *services_supported |= importer::PASSWORDS; + } + } + if (HasPaymentMethods(profile.Append(kWebDataFilename))) *services_supported |= importer::PAYMENTS; + #if BUILDFLAG(ENABLE_EXTENSIONS) if (HasImportableExtensions(profile)) *services_supported |= importer::EXTENSIONS; diff --git a/common/importer/chrome_importer_utils.h b/common/importer/chrome_importer_utils.h index f37ab57e3bd..a9b47a61492 100644 --- a/common/importer/chrome_importer_utils.h +++ b/common/importer/chrome_importer_utils.h @@ -12,6 +12,7 @@ #include "base/values.h" #include "build/build_config.h" +#include "chrome/common/importer/importer_type.h" #include "extensions/buildflags/buildflags.h" namespace base { @@ -41,6 +42,7 @@ base::FilePath GetOperaSnapUserDataFolder(); #endif base::Value::List GetChromeSourceProfiles(const base::FilePath& local_state); bool ChromeImporterCanImport(const base::FilePath& profile, + importer::ImporterType type, uint16_t* services_supported); #if BUILDFLAG(ENABLE_EXTENSIONS) diff --git a/common/importer/chrome_importer_utils_unittest.cc b/common/importer/chrome_importer_utils_unittest.cc index 4051cef0259..b5f7726ca2e 100644 --- a/common/importer/chrome_importer_utils_unittest.cc +++ b/common/importer/chrome_importer_utils_unittest.cc @@ -124,8 +124,8 @@ TEST_F(BraveChromeImporterUtilsTest, ChromeImporterCanImport) { kChromeSecurePreferencesFile); CopyTestFileToProfile(kChromePreferencesFile, kChromePreferencesFile); uint16_t services_supported = importer::NONE; - EXPECT_TRUE( - ChromeImporterCanImport(GetTestProfilePath(), &services_supported)); + EXPECT_TRUE(ChromeImporterCanImport( + GetTestProfilePath(), importer::TYPE_CHROME, &services_supported)); EXPECT_EQ(services_supported, importer::EXTENSIONS); } @@ -133,15 +133,15 @@ TEST_F(BraveChromeImporterUtilsTest, BadFiles) { CopyTestFileToProfile("non_json_preferences", kChromeSecurePreferencesFile); CopyTestFileToProfile("non_json_preferences", kChromePreferencesFile); uint16_t services_supported = importer::NONE; - EXPECT_FALSE( - ChromeImporterCanImport(GetTestProfilePath(), &services_supported)); + EXPECT_FALSE(ChromeImporterCanImport( + GetTestProfilePath(), importer::TYPE_CHROME, &services_supported)); EXPECT_EQ(services_supported, importer::NONE); CopyTestFileToProfile("non_dict_extension", kChromeSecurePreferencesFile); CopyTestFileToProfile("non_dict_extension", kChromePreferencesFile); services_supported = importer::NONE; // Empty list is anyway considered as something to import. - EXPECT_TRUE( - ChromeImporterCanImport(GetTestProfilePath(), &services_supported)); + EXPECT_TRUE(ChromeImporterCanImport( + GetTestProfilePath(), importer::TYPE_CHROME, &services_supported)); EXPECT_EQ(services_supported, importer::EXTENSIONS); }