Skip to content

Commit

Permalink
Import from Opera (#14006)
Browse files Browse the repository at this point in the history
* Added Opera importer

* Fixed password import for Opera

* Disabled passwords import for OSX
  • Loading branch information
spylogsster authored Jul 21, 2022
1 parent 8695d6a commit cd486a8
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 17 deletions.
1 change: 1 addition & 0 deletions browser/importer/brave_external_process_importer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bool ShouldUseBraveImporter(importer::ImporterType type) {
case importer::TYPE_CHROME:
case importer::TYPE_EDGE_CHROMIUM:
case importer::TYPE_VIVALDI:
case importer::TYPE_OPERA:
return true;
default:
return false;
Expand Down
3 changes: 3 additions & 0 deletions browser/importer/brave_importer_p3a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ void RecordImporterP3A(importer::ImporterType type) {
case importer::TYPE_VIVALDI:
metric = ImporterSource::kOther;
break;
case importer::TYPE_OPERA:
metric = ImporterSource::kOpera;
break;
}

UMA_HISTOGRAM_ENUMERATION("Brave.Importer.ImporterSource.2", metric,
Expand Down
21 changes: 21 additions & 0 deletions chromium_src/chrome/browser/importer/importer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ void AddChromeToProfiles(std::vector<importer::SourceProfile>* profiles,
profile->begin(), profile->end())),
&items))
continue;
#if BUILDFLAG(IS_MAC)
// https://github.com/brave/brave-browser/issues/24130
if (type == importer::TYPE_OPERA && (items & importer::PASSWORDS)) {
items ^= importer::PASSWORDS;
}
#endif
importer::SourceProfile chrome;
std::string importer_name(brand);
importer_name.append(*name);
Expand Down Expand Up @@ -78,6 +84,21 @@ void DetectChromeProfiles(std::vector<importer::SourceProfile>* profiles) {
GetChromeSourceProfiles(GetVivaldiUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetVivaldiUserDataFolder(), "Vivaldi ", importer::TYPE_VIVALDI);

AddChromeToProfiles(
profiles,
GetChromeSourceProfiles(GetOperaUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetOperaUserDataFolder(), "Opera ", importer::TYPE_OPERA);

#if BUILDFLAG(IS_LINUX)
// Installed via snap Opera has different profile path.
AddChromeToProfiles(
profiles,
GetChromeSourceProfiles(GetOperaSnapUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetOperaSnapUserDataFolder(), "Opera ", importer::TYPE_OPERA);
#endif
}

} // namespace
Expand Down
1 change: 1 addition & 0 deletions chromium_src/chrome/browser/importer/importer_uma.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
TYPE_CHROME: \
case TYPE_EDGE_CHROMIUM: \
case TYPE_VIVALDI: \
case TYPE_OPERA: \
break; \
case TYPE_FIREFOX
#include "src/chrome/browser/importer/importer_uma.cc"
5 changes: 3 additions & 2 deletions chromium_src/chrome/common/importer/importer_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#ifndef BRAVE_CHROMIUM_SRC_CHROME_COMMON_IMPORTER_IMPORTER_TYPE_H_
#define BRAVE_CHROMIUM_SRC_CHROME_COMMON_IMPORTER_IMPORTER_TYPE_H_

#define TYPE_FIREFOX \
TYPE_CHROME = 1, TYPE_EDGE_CHROMIUM = 10, TYPE_VIVALDI = 11, TYPE_FIREFOX
#define TYPE_FIREFOX \
TYPE_CHROME = 1, TYPE_EDGE_CHROMIUM = 10, TYPE_VIVALDI = 11, \
TYPE_OPERA = 12, TYPE_FIREFOX
#include "src/chrome/common/importer/importer_type.h"
#undef TYPE_FIREFOX

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "chrome/common/importer/importer_type.h"

#if !BUILDFLAG(IS_WIN)
#define TYPE_BOOKMARKS_FILE TYPE_VIVALDI
#define TYPE_BOOKMARKS_FILE TYPE_OPERA
#else
#define TYPE_EDGE TYPE_VIVALDI
#define TYPE_EDGE TYPE_OPERA
#endif
#include "src/chrome/common/importer/profile_import_process_param_traits_macros.h"
#if !BUILDFLAG(IS_WIN)
Expand Down
2 changes: 1 addition & 1 deletion common/importer/chrome_importer_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ base::Value::List GetChromeSourceProfiles(
}
if (profiles.empty()) {
base::Value::Dict entry;
entry.Set("id", "Default");
entry.Set("id", "");
entry.Set("name", "Default");
profiles.Append(std::move(entry));
}
Expand Down
6 changes: 5 additions & 1 deletion common/importer/chrome_importer_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ base::FilePath GetChromiumUserDataFolder();
base::FilePath GetEdgeUserDataFolder();

base::FilePath GetVivaldiUserDataFolder();
base::FilePath GetOperaUserDataFolder();

#if BUILDFLAG(IS_LINUX)
base::FilePath GetOperaSnapUserDataFolder();
#endif
base::Value::List GetChromeSourceProfiles(const base::FilePath& local_state);

base::ListValue* GetOperaSourceProfiles(const base::FilePath& user_data_folder);
bool ChromeImporterCanImport(const base::FilePath& profile,
uint16_t* services_supported);

Expand Down
25 changes: 25 additions & 0 deletions common/importer/chrome_importer_utils_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,28 @@ base::FilePath GetEdgeUserDataFolder() {

return result;
}

base::FilePath GetOperaUserDataFolder() {
base::FilePath result;
if (!base::PathService::Get(base::DIR_HOME, &result))
return base::FilePath();

result = result.Append(".config");
result = result.Append("opera");

return result;
}

base::FilePath GetOperaSnapUserDataFolder() {
base::FilePath result;
if (!base::PathService::Get(base::DIR_HOME, &result))
return base::FilePath();

result = result.Append("snap");
result = result.Append("opera");
result = result.Append("current");
result = result.Append(".config");
result = result.Append("opera");

return result;
}
5 changes: 5 additions & 0 deletions common/importer/chrome_importer_utils_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@
base::FilePath result = base::mac::GetUserLibraryPath();
return result.Append("Application Support/Microsoft Edge");
}

base::FilePath GetOperaUserDataFolder() {
base::FilePath result = base::mac::GetUserLibraryPath();
return result.Append("Application Support/com.operasoftware.Opera");
}
16 changes: 8 additions & 8 deletions common/importer/chrome_importer_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ TEST(ChromeImporterUtilsTest, BasicTest) {
}

TEST(ChromeImporterUtilsTest, GetChromeUserDataFolder) {
EXPECT_EQ(GetChromeSourceProfiles(base::FilePath(FILE_PATH_LITERAL("fake"))),
base::JSONReader::Read(R"([{"id": "Default", "name": "Default" }])")
->GetList());
EXPECT_EQ(
GetChromeSourceProfiles(base::FilePath(FILE_PATH_LITERAL("fake"))),
base::JSONReader::Read(R"([{"id": "", "name": "Default" }])")->GetList());

EXPECT_EQ(GetChromeSourceProfiles(GetTestProfilePath().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
Expand All @@ -59,9 +59,9 @@ TEST(ChromeImporterUtilsTest, GetChromeUserDataFolder) {
])")
->GetList());

EXPECT_EQ(GetChromeSourceProfiles(
GetTestProfilePath().Append(base::FilePath::StringType(
FILE_PATH_LITERAL("No Profile Local State")))),
base::JSONReader::Read(R"([{"id": "Default", "name": "Default" }])")
->GetList());
EXPECT_EQ(
GetChromeSourceProfiles(
GetTestProfilePath().Append(base::FilePath::StringType(
FILE_PATH_LITERAL("No Profile Local State")))),
base::JSONReader::Read(R"([{"id": "", "name": "Default" }])")->GetList());
}
10 changes: 10 additions & 0 deletions common/importer/chrome_importer_utils_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ base::FilePath GetEdgeUserDataFolder() {
result = result.AppendASCII("Microsoft");
result = result.AppendASCII("Edge");
result = result.AppendASCII("User Data");
return result;
}

base::FilePath GetOperaUserDataFolder() {
base::FilePath result;
if (!base::PathService::Get(base::DIR_ROAMING_APP_DATA, &result))
return base::FilePath();

result = result.AppendASCII("Opera Software");
result = result.AppendASCII("Opera Stable");

return result;
}
2 changes: 2 additions & 0 deletions utility/importer/brave_profile_import_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ scoped_refptr<Importer> CreateImporterByType(importer::ImporterType type) {
return new ChromeImporter();
case importer::TYPE_VIVALDI:
return new ChromeImporter();
case importer::TYPE_OPERA:
return new ChromeImporter();
default:
NOTREACHED();
return nullptr;
Expand Down
12 changes: 9 additions & 3 deletions utility/importer/chrome_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ bool SetEncryptionKeyForPasswordImporting(
return true;
}
}

return false;
}
#endif
Expand All @@ -125,7 +124,7 @@ bool SetEncryptionKey(const base::FilePath& source_path) {
#endif

#if BUILDFLAG(IS_WIN)
base::FilePath local_state_path = source_path.DirName().Append(
base::FilePath local_state_path = source_path.Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")));
if (!base::PathExists(local_state_path))
return false;
Expand Down Expand Up @@ -198,7 +197,14 @@ void ChromeImporter::StartImport(const importer::SourceProfile& source_profile,
bridge_->NotifyItemEnded(importer::FAVORITES);
}

const bool set_encryption_key = SetEncryptionKey(source_path_);
#if BUILDFLAG(IS_WIN)
auto source_path = source_profile.importer_type == importer::TYPE_OPERA
? source_path_
: source_path_.DirName();
#else
auto source_path = source_path_;
#endif
const bool set_encryption_key = SetEncryptionKey(source_path);
if ((items & importer::PASSWORDS) && !cancelled() && set_encryption_key) {
bridge_->NotifyItemStarted(importer::PASSWORDS);
ImportPasswords();
Expand Down

0 comments on commit cd486a8

Please sign in to comment.