diff --git a/chromium_src/chrome/utility/importer/importer_creator.cc b/chromium_src/chrome/utility/importer/importer_creator.cc index 1e0881b1d103..a15863c6fa32 100644 --- a/chromium_src/chrome/utility/importer/importer_creator.cc +++ b/chromium_src/chrome/utility/importer/importer_creator.cc @@ -1,3 +1,8 @@ +/* Copyright 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "chrome/utility/importer/importer_creator.h" #define CreateImporterByType CreateImporterByType_ChromiumImpl #include "../../../../../chrome/utility/importer/importer_creator.cc" @@ -5,14 +10,11 @@ #include "brave/utility/importer/brave_importer.h" #include "brave/utility/importer/chrome_importer.h" -#include "brave/utility/importer/firefox_importer.h" namespace importer { scoped_refptr CreateImporterByType(ImporterType type) { switch (type) { - case TYPE_FIREFOX: - return new brave::FirefoxImporter(); case TYPE_CHROME: return new ChromeImporter(); case TYPE_BRAVE: diff --git a/common/importer/chrome_importer_utils.cc b/common/importer/chrome_importer_utils.cc index b2ce89d7eb3a..c1a527cc1cf7 100644 --- a/common/importer/chrome_importer_utils.cc +++ b/common/importer/chrome_importer_utils.cc @@ -66,8 +66,6 @@ bool ChromeImporterCanImport(const base::FilePath& profile, profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("History"))); base::FilePath passwords = profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("Login Data"))); - base::FilePath cookies = - profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("Cookies"))); if (base::PathExists(bookmarks)) *services_supported |= importer::FAVORITES; @@ -75,8 +73,6 @@ bool ChromeImporterCanImport(const base::FilePath& profile, *services_supported |= importer::HISTORY; if (base::PathExists(passwords)) *services_supported |= importer::PASSWORDS; - if (base::PathExists(cookies)) - *services_supported |= importer::COOKIES; return *services_supported != importer::NONE; } diff --git a/patches/chrome-browser-importer-importer_list.cc.patch b/patches/chrome-browser-importer-importer_list.cc.patch index b901ee6ed15a..89654cc5dffd 100644 --- a/patches/chrome-browser-importer-importer_list.cc.patch +++ b/patches/chrome-browser-importer-importer_list.cc.patch @@ -1,5 +1,5 @@ diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc -index da4c6f6cec37523f59fd6b18e9e1c603c8e6a0df..f613af5207e550b91fb878d7fe56204fbdaecbc7 100644 +index da4c6f6cec37523f59fd6b18e9e1c603c8e6a0df..569bb3a108132454c2213ece7abcb4ff23fcbc3c 100644 --- a/chrome/browser/importer/importer_list.cc +++ b/chrome/browser/importer/importer_list.cc @@ -29,6 +29,9 @@ @@ -28,15 +28,7 @@ index da4c6f6cec37523f59fd6b18e9e1c603c8e6a0df..f613af5207e550b91fb878d7fe56204f if (profile_path.empty()) return; -@@ -127,6 +135,7 @@ void DetectFirefoxProfiles(const std::string locale, - firefox.app_path = app_path; - firefox.services_supported = importer::HISTORY | importer::FAVORITES | - importer::PASSWORDS | importer::SEARCH_ENGINES | -+ importer::COOKIES | - importer::AUTOFILL_FORM_DATA; - firefox.locale = locale; - profiles->push_back(firefox); -@@ -145,21 +154,37 @@ std::vector DetectSourceProfilesWorker( +@@ -145,21 +153,37 @@ std::vector DetectSourceProfilesWorker( #if defined(OS_WIN) if (shell_integration::IsFirefoxDefaultBrowser()) { DetectFirefoxProfiles(locale, &profiles); diff --git a/patches/chrome-utility-importer-firefox_importer.cc.patch b/patches/chrome-utility-importer-firefox_importer.cc.patch deleted file mode 100644 index 8946c24735d6..000000000000 --- a/patches/chrome-utility-importer-firefox_importer.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/chrome/utility/importer/firefox_importer.cc b/chrome/utility/importer/firefox_importer.cc -index 754d10cfd0663dd25216beda49c402c68111fed2..c546bfa868f729e97003b45d603a3327db870957 100644 ---- a/chrome/utility/importer/firefox_importer.cc -+++ b/chrome/utility/importer/firefox_importer.cc -@@ -167,7 +167,6 @@ void FirefoxImporter::StartImport(const importer::SourceProfile& source_profile, - ImportAutofillFormData(); - bridge_->NotifyItemEnded(importer::AUTOFILL_FORM_DATA); - } -- bridge_->NotifyEnded(); - } - - void FirefoxImporter::ImportHistory() { diff --git a/patches/chrome-utility-importer-firefox_importer.h.patch b/patches/chrome-utility-importer-firefox_importer.h.patch deleted file mode 100644 index ea1890d38f59..000000000000 --- a/patches/chrome-utility-importer-firefox_importer.h.patch +++ /dev/null @@ -1,23 +0,0 @@ -diff --git a/chrome/utility/importer/firefox_importer.h b/chrome/utility/importer/firefox_importer.h -index 46be147c9e70dca82a79025d57c4aaa080f02793..661eb7f520164753c874c78606aa8e5f04d4430d 100644 ---- a/chrome/utility/importer/firefox_importer.h -+++ b/chrome/utility/importer/firefox_importer.h -@@ -43,6 +43,9 @@ class FirefoxImporter : public Importer { - uint16_t items, - ImporterBridge* bridge) override; - -+ protected: -+ ~FirefoxImporter() override; -+ - private: - // Location of favicons in Firefox profile. It may vary depending on Firefox - // version. -@@ -56,8 +59,6 @@ class FirefoxImporter : public Importer { - - using FaviconMap = std::map>; - -- ~FirefoxImporter() override; -- - FRIEND_TEST_ALL_PREFIXES(FirefoxImporterTest, ImportBookmarksV25); - void ImportBookmarks(); - void ImportPasswords(); diff --git a/test/BUILD.gn b/test/BUILD.gn index 1f4aed62c0ae..e1ceaaf212ec 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -171,7 +171,6 @@ test("brave_unit_tests") { "../browser/importer/chrome_profile_lock_unittest.cc", "../utility/importer/chrome_importer_unittest.cc", "../utility/importer/brave_importer_unittest.cc", - "../utility/importer/firefox_importer_unittest.cc", # These tests should probably work on Android and compile, but don't pass currently "//brave/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc", diff --git a/utility/BUILD.gn b/utility/BUILD.gn index 8293abe50a2d..340c67ab27e2 100644 --- a/utility/BUILD.gn +++ b/utility/BUILD.gn @@ -30,8 +30,6 @@ source_set("utility") { "importer/brave_importer.h", "importer/chrome_importer.cc", "importer/chrome_importer.h", - "importer/firefox_importer.cc", - "importer/firefox_importer.h", ] deps += [ diff --git a/utility/importer/chrome_importer.cc b/utility/importer/chrome_importer.cc index 52b35513b63c..5d25cdd9b106 100644 --- a/utility/importer/chrome_importer.cc +++ b/utility/importer/chrome_importer.cc @@ -86,11 +86,7 @@ void ChromeImporter::StartImport(const importer::SourceProfile& source_profile, bridge_->NotifyItemEnded(importer::PASSWORDS); } - if ((items & importer::COOKIES) && !cancelled()) { - bridge_->NotifyItemStarted(importer::COOKIES); - ImportCookies(); - bridge_->NotifyItemEnded(importer::COOKIES); - } + // Note that we do not import cookies from Chrome (issues/7044). bridge_->NotifyEnded(); } diff --git a/utility/importer/chrome_importer_unittest.cc b/utility/importer/chrome_importer_unittest.cc index 51ca4a8f59be..e10a64d4228a 100644 --- a/utility/importer/chrome_importer_unittest.cc +++ b/utility/importer/chrome_importer_unittest.cc @@ -1,16 +1,19 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/utility/importer/chrome_importer.h" -#include "brave/common/brave_paths.h" -#include "brave/common/importer/brave_mock_importer_bridge.h" + +#include #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/strings/utf_string_conversions.h" #include "base/path_service.h" +#include "base/strings/utf_string_conversions.h" +#include "brave/common/brave_paths.h" +#include "brave/common/importer/brave_mock_importer_bridge.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/importer/imported_bookmark_entry.h" #include "chrome/common/importer/importer_data_types.h" @@ -41,7 +44,8 @@ class ChromeImporterTest : public ::testing::Test { void SetUpChromeProfile() { // Creates a new profile in a new subdirectory in the temp directory. ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - base::FilePath test_path = temp_dir_.GetPath().AppendASCII("ChromeImporterTest"); + base::FilePath test_path = + temp_dir_.GetPath().AppendASCII("ChromeImporterTest"); base::DeleteFile(test_path, true); base::CreateDirectory(test_path); profile_dir_ = test_path.AppendASCII("profile"); @@ -134,7 +138,8 @@ TEST_F(ChromeImporterTest, ImportFavicons) { favicons[3].favicon_url.spec()); } -// The mock keychain only works on macOS, so only run this test on macOS (for now) +// The mock keychain only works on macOS, so only run this test on macOS (for +// now) #if defined(OS_MACOSX) TEST_F(ChromeImporterTest, ImportPasswords) { // Use mock keychain on mac to prevent blocking permissions dialogs. @@ -170,25 +175,4 @@ TEST_F(ChromeImporterTest, ImportPasswords) { OSCryptMocker::TearDown(); } -TEST_F(ChromeImporterTest, ImportCookies) { - OSCryptMocker::SetUp(); - - std::vector cookies; - - EXPECT_CALL(*bridge_, NotifyStarted()); - EXPECT_CALL(*bridge_, NotifyItemStarted(importer::COOKIES)); - EXPECT_CALL(*bridge_, SetCookies(_)) - .WillOnce(::testing::SaveArg<0>(&cookies)); - EXPECT_CALL(*bridge_, NotifyItemEnded(importer::COOKIES)); - EXPECT_CALL(*bridge_, NotifyEnded()); - - importer_->StartImport(profile_, importer::COOKIES, bridge_.get()); - - ASSERT_EQ(1u, cookies.size()); - EXPECT_EQ("localhost", cookies[0].Domain()); - EXPECT_EQ("test", cookies[0].Name()); - EXPECT_EQ("test", cookies[0].Value()); - - OSCryptMocker::TearDown(); -} #endif diff --git a/utility/importer/firefox_importer.cc b/utility/importer/firefox_importer.cc deleted file mode 100644 index 8ae9c7fba351..000000000000 --- a/utility/importer/firefox_importer.cc +++ /dev/null @@ -1,109 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/utility/importer/firefox_importer.h" - -#include - -#include "base/files/file_enumerator.h" -#include "base/files/file_util.h" -#include "base/macros.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "brave/utility/importer/brave_external_process_importer_bridge.h" -#include "build/build_config.h" -#include "chrome/grit/generated_resources.h" -#include "components/autofill/core/common/password_form.h" -#include "net/cookies/canonical_cookie.h" -#include "net/cookies/cookie_constants.h" -#include "sql/database.h" -#include "sql/statement.h" -#include "url/gurl.h" - -using base::Time; - -namespace brave { - -FirefoxImporter::FirefoxImporter() { -} - -FirefoxImporter::~FirefoxImporter() { -} - -void FirefoxImporter::StartImport(const importer::SourceProfile& source_profile, - uint16_t items, - ImporterBridge* bridge) { - ::FirefoxImporter::StartImport(source_profile, items, bridge); - - bridge_ = bridge; - source_path_ = source_profile.source_path; - if ((items & importer::COOKIES) && !cancelled()) { - bridge_->NotifyItemStarted(importer::COOKIES); - ImportCookies(); - bridge_->NotifyItemEnded(importer::COOKIES); - } - - bridge_->NotifyEnded(); -} - -void FirefoxImporter::ImportCookies() { - base::FilePath file = source_path_.AppendASCII("cookies.sqlite"); - if (!base::PathExists(file)) { - return; - } - - sql::Database db; - if (!db.Open(file)) { - return; - } - - const char query[] = - "select baseDomain, name, value, host, path, expiry, lastAccessed, " - "creationTime, isSecure, isHttpOnly, sameSite FROM moz_cookies"; - - sql::Statement s(db.GetUniqueStatement(query)); - - std::vector cookies; - while (s.Step() && !cancelled()) { - std::string domain("."); - domain.append(s.ColumnString(0)); - std::string host; - if (s.ColumnString(3)[0] == '.') { - host.append("*"); - host.append(s.ColumnString(3)); - } else { - host = s.ColumnString(3); - } - - // Firefox represents expiry in *seconds* since the Unix epoch, - // while lastAccessed and creationTime are measured in microseconds. - // Source: netwerk/cookie/nsICookie2.idl. - const Time expiry = Time::FromDoubleT(s.ColumnInt64(5)); - const Time last_accessed = Time::FromDoubleT(s.ColumnInt64(6) / 1000000); - const Time creation = Time::FromDoubleT(s.ColumnInt64(7) / 1000000); - - auto cookie = net::CanonicalCookie( - s.ColumnString(1), // name - s.ColumnString(2), // value - domain, // domain - s.ColumnString(4), // path - creation, // creation - expiry, // expiration - last_accessed, // last_access - s.ColumnBool(8), // secure - s.ColumnBool(9), // http_only - static_cast(s.ColumnInt(10)), // samesite - net::COOKIE_PRIORITY_DEFAULT // priority - ); - if (cookie.IsCanonical()) { - cookies.push_back(cookie); - } - } - - if (!cookies.empty() && !cancelled()) { - bridge_->SetCookies(cookies); - } -} - -} // namespace brave diff --git a/utility/importer/firefox_importer.h b/utility/importer/firefox_importer.h deleted file mode 100644 index a53b06986ffa..000000000000 --- a/utility/importer/firefox_importer.h +++ /dev/null @@ -1,33 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_UTILITY_IMPORTER_FIREFOX_IMPORTER_H_ -#define BRAVE_UTILITY_IMPORTER_FIREFOX_IMPORTER_H_ - -#include "chrome/utility/importer/firefox_importer.h" - -namespace brave { - -class FirefoxImporter : public ::FirefoxImporter { - public: - FirefoxImporter(); - - // Importer: - void StartImport(const importer::SourceProfile& source_profile, - uint16_t items, - ImporterBridge* bridge) override; - - private: - ~FirefoxImporter() override; - - void ImportCookies(); - - base::FilePath source_path_; - - DISALLOW_COPY_AND_ASSIGN(FirefoxImporter); -}; - -} // namespace brave - -#endif // BRAVE_UTILITY_IMPORTER_FIREFOX_IMPORTER_H_ diff --git a/utility/importer/firefox_importer_unittest.cc b/utility/importer/firefox_importer_unittest.cc deleted file mode 100644 index 5ae6cd64da4d..000000000000 --- a/utility/importer/firefox_importer_unittest.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/utility/importer/firefox_importer.h" -#include "brave/common/brave_paths.h" -#include "brave/common/importer/brave_mock_importer_bridge.h" - -#include "base/files/file_path.h" -#include "base/files/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "base/path_service.h" -#include "chrome/common/importer/importer_data_types.h" -#include "chrome/common/importer/mock_importer_bridge.h" -#include "testing/gtest/include/gtest/gtest.h" - -using ::testing::_; - -base::FilePath GetTestFirefoxProfileDir(const std::string& profile) { - base::FilePath test_dir; - base::PathService::Get(brave::DIR_TEST_DATA, &test_dir); - - return test_dir.AppendASCII("import").AppendASCII("firefox") - .AppendASCII(profile); -} - -class FirefoxImporterTest : public ::testing::Test { - protected: - void SetUpFirefoxProfile() { - // Creates a new profile in a new subdirectory in the temp directory. - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - base::FilePath test_path = temp_dir_.GetPath().AppendASCII("FirefoxImporterTest"); - base::DeleteFile(test_path, true); - base::CreateDirectory(test_path); - profile_dir_ = test_path.AppendASCII("profile"); - - base::FilePath data_dir = GetTestFirefoxProfileDir("default"); - ASSERT_TRUE(base::DirectoryExists(data_dir)); - ASSERT_TRUE(base::CopyDirectory(data_dir, profile_dir_, true)); - - profile_.source_path = profile_dir_; - } - - void SetUp() override { - SetUpFirefoxProfile(); - importer_ = new brave::FirefoxImporter; - bridge_ = new BraveMockImporterBridge; - } - - base::ScopedTempDir temp_dir_; - base::FilePath profile_dir_; - importer::SourceProfile profile_; - scoped_refptr importer_; - scoped_refptr bridge_; -}; - -TEST_F(FirefoxImporterTest, ImportCookies) { - std::vector cookies; - - EXPECT_CALL(*bridge_, NotifyStarted()); - EXPECT_CALL(*bridge_, NotifyItemStarted(importer::COOKIES)); - EXPECT_CALL(*bridge_, SetCookies(_)) - .WillOnce(::testing::SaveArg<0>(&cookies)); - EXPECT_CALL(*bridge_, NotifyItemEnded(importer::COOKIES)); - EXPECT_CALL(*bridge_, NotifyEnded()); - - importer_->StartImport(profile_, importer::COOKIES, bridge_.get()); - - ASSERT_EQ(1u, cookies.size()); - EXPECT_EQ(".localhost", cookies[0].Domain()); - EXPECT_EQ("test", cookies[0].Name()); - EXPECT_EQ("test", cookies[0].Value()); -}