Hides Passwords checkbox in import dialog for Chrome. (#29149)

Chrome encrypts passwords and their code for doing so is not open
source.
This commit is contained in:
Max Karolinskiy
2025-05-21 12:21:28 -07:00
committed by GitHub
parent da06807733
commit c7041efd19
4 changed files with 54 additions and 27 deletions
@@ -24,8 +24,9 @@ void AddChromeToProfiles(std::vector<importer::SourceProfile>* 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<importer::SourceProfile>* 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;
+43 -13
View File
@@ -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;
+2
View File
@@ -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)
@@ -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);
}