Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable WebTorrent extension by default #27876

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions browser/brave_content_browser_client_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, RewriteAdblock) {
}
}

#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, RewriteMagnetURLURLBar) {
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();

Expand All @@ -322,6 +324,7 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, RewriteMagnetURLURLBar) {
}

IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, RewriteMagnetURLLink) {
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_html_url()));
Expand All @@ -342,6 +345,7 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, RewriteMagnetURLLink) {
}

IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, TypedMagnetURL) {
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::SendToOmniboxAndSubmit(browser(), magnet_url().spec());
Expand All @@ -352,9 +356,9 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, TypedMagnetURL) {
EXPECT_EQ(magnet_url(), web_contents->GetLastCommittedURL().spec());
}

#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
ReverseRewriteTorrentURL) {
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();

Expand All @@ -374,10 +378,10 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
torrent_extension_url().spec().c_str())
<< "Real URL should be extension URL";
}
#endif

IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
MagnetIframeWithUserGestureOpensWebtorrent) {
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_html_url()));
Expand Down Expand Up @@ -421,6 +425,7 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,

IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
NoReverseRewriteTorrentURLForInvalidQuery) {
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();

Expand All @@ -443,7 +448,7 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,

IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
WebTorrentExtensionEnabledAfterLoad) {
ASSERT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(kWebTorrentEnabled));
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);

extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(browser()->profile());
Expand Down Expand Up @@ -543,6 +548,7 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest,
torrent_extension_url().spec().c_str())
<< "No changes on the real URL";
}
#endif // BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)

#if BUILDFLAG(ENABLE_TOR)
IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, MixedContentForOnion) {
Expand Down
7 changes: 5 additions & 2 deletions browser/brave_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "brave/components/brave_wallet/browser/pref_names.h"
#include "brave/components/brave_wallet/common/brave_wallet.mojom.h"
#include "brave/components/brave_wayback_machine/buildflags/buildflags.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/ntp_background_images/buildflags/buildflags.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -86,9 +87,11 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
brave_shields::prefs::kReduceLanguageEnabled),
base::FeatureList::IsEnabled(
brave_shields::features::kBraveReduceLanguage));
#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
EXPECT_TRUE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean(
#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean(
kWebTorrentEnabled));
#endif
#if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE)
EXPECT_TRUE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean(
kBraveWaybackMachineEnabled));
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "brave/browser/net/url_context.h"
#include "brave/components/constants/pref_names.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/page_type.h"
Expand Down Expand Up @@ -96,6 +98,7 @@ class BraveTorrentRedirectNetworkDelegateHelperTest

IN_PROC_BROWSER_TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest,
TorrentFileIsRedirected) {
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
auto* contents = browser()->tab_strip_model()->GetActiveWebContents();

NavigateParams params(browser(), torrent_url(),
Expand All @@ -108,6 +111,7 @@ IN_PROC_BROWSER_TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest,

IN_PROC_BROWSER_TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest,
LinkToExtensionFails) {
browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
auto* contents = browser()->tab_strip_model()->GetActiveWebContents();

NavigateParams params(browser(), torrent_extension_url(),
Expand Down
1 change: 1 addition & 0 deletions browser/profiles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ source_set("util") {
"//brave/common",
"//brave/components/brave_shields/content/browser",
"//brave/components/brave_shields/core/common",
"//brave/components/brave_webtorrent/browser/buildflags",
"//brave/components/ntp_background_images/browser",
"//brave/components/ntp_background_images/common",
"//brave/components/search_engines",
Expand Down
4 changes: 4 additions & 0 deletions browser/profiles/brave_profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "brave/browser/url_sanitizer/url_sanitizer_service_factory.h"
#include "brave/components/brave_shields/content/browser/brave_shields_p3a.h"
#include "brave/components/brave_shields/content/browser/brave_shields_util.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/content_settings/core/browser/brave_content_settings_pref_provider.h"
#include "brave/components/ntp_background_images/browser/ntp_p3a_util.h"
Expand Down Expand Up @@ -134,6 +135,9 @@ void BraveProfileManager::InitProfileUserPrefs(Profile* profile) {
ProfileManager::InitProfileUserPrefs(profile);
RecordInitialP3AValues(profile);
brave::SetDefaultSearchVersion(profile, profile->IsNewProfile());
#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
brave::SetWebTorrentEnabled(profile, profile->IsNewProfile());
#endif
brave::SetDefaultThirdPartyCookieBlockValue(profile);
perf::MaybeEnableBraveFeatureForPerfTesting(profile);
MigrateHttpsUpgradeSettings(profile);
Expand Down
14 changes: 14 additions & 0 deletions browser/profiles/profile_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "brave/browser/profiles/profile_util.h"

#include "brave/components/brave_shields/content/browser/brave_shields_p3a.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/search_engines/brave_prepopulated_engines.h"
#include "chrome/browser/profiles/profile.h"
#include "components/content_settings/core/browser/cookie_settings.h"
Expand Down Expand Up @@ -34,4 +35,17 @@ void SetDefaultThirdPartyCookieBlockValue(Profile* profile) {
content_settings::CookieControlsMode::kBlockThirdParty)));
}

#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
void SetWebTorrentEnabled(Profile* profile, bool is_new_profile) {
const PrefService::Preference* pref_webtorrent_enabled =
profile->GetPrefs()->FindPreference(kWebTorrentEnabled);
if (!pref_webtorrent_enabled->HasUserSetting()) {
profile->GetPrefs()->SetBoolean(
kWebTorrentEnabled,
is_new_profile ? false
: profile->GetPrefs()->GetBoolean(kWebTorrentEnabled));
}
}
#endif

} // namespace brave
11 changes: 11 additions & 0 deletions browser/profiles/profile_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef BRAVE_BROWSER_PROFILES_PROFILE_UTIL_H_
#define BRAVE_BROWSER_PROFILES_PROFILE_UTIL_H_

#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"

class Profile;

namespace brave {
Expand All @@ -20,6 +22,15 @@ void SetDefaultSearchVersion(Profile* profile, bool is_new_profile);
// instead of 'Block Third Party in Incognito'
void SetDefaultThirdPartyCookieBlockValue(Profile* profile);

#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
// Used for capturing the current value of WebTorrent.
// WebTorrent will be disabled for new users starting with
// https://github.com/brave/brave-browser/issues/44303
// Once the feature is deprecated, this code can be removed and the preference
// can be added under `RegisterProfilePrefsForMigration`.
void SetWebTorrentEnabled(Profile* profile, bool is_new_profile);
#endif

// Checks if the user previously had fingerprinting mode disabled.
// If so, set the new fingerprinting toggle to disabled.
void MigrateFingerprintingSettings(Profile* profile);
Expand Down
46 changes: 46 additions & 0 deletions browser/profiles/profile_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "brave/components/constants/pref_names.h"
#include "brave/components/search_engines/brave_prepopulated_engines.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/test/base/testing_browser_process.h"
Expand Down Expand Up @@ -38,6 +39,9 @@ class BraveProfileUtilTest : public testing::Test {
base::ScopedTempDir temp_dir_;
};

// SetDefaultSearchVersion
// #######################

// No entry yet. Check initialized value
TEST_F(BraveProfileUtilTest, SetDefaultSearchVersionExistingProfileNoEntryYet) {
const PrefService::Preference* pref =
Expand Down Expand Up @@ -78,3 +82,45 @@ TEST_F(BraveProfileUtilTest,
brave::SetDefaultSearchVersion(GetProfile(), true);
ASSERT_EQ(GetPrefs()->GetInteger(prefs::kBraveDefaultSearchVersion), 1);
}

// SetWebTorrentEnabled
// ####################
#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
// No entry yet. Check initialized value
TEST_F(BraveProfileUtilTest, SetWebTorrentEnabledExistingProfileNoEntryYet) {
const PrefService::Preference* pref =
GetPrefs()->FindPreference(kWebTorrentEnabled);
EXPECT_FALSE(pref->HasUserSetting());
brave::SetWebTorrentEnabled(GetProfile(), false);
EXPECT_TRUE(GetPrefs()->GetBoolean(kWebTorrentEnabled));
}

TEST_F(BraveProfileUtilTest, SetWebTorrentEnabledNewProfileNoEntryYet) {
const PrefService::Preference* pref =
GetPrefs()->FindPreference(kWebTorrentEnabled);
EXPECT_FALSE(pref->HasUserSetting());
brave::SetWebTorrentEnabled(GetProfile(), true);
EXPECT_FALSE(GetPrefs()->GetBoolean(kWebTorrentEnabled));
}

// Entry there; ensure value is kept
TEST_F(BraveProfileUtilTest,
SetWebTorrentEnabledExistingProfileHasEntryKeepsValue) {
GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
const PrefService::Preference* pref =
GetPrefs()->FindPreference(kWebTorrentEnabled);
EXPECT_TRUE(pref->HasUserSetting());
brave::SetWebTorrentEnabled(GetProfile(), false);
EXPECT_TRUE(GetPrefs()->GetBoolean(kWebTorrentEnabled));
}

TEST_F(BraveProfileUtilTest, SetWebTorrentEnabledNewProfileHasEntryKeepsValue) {
// This is an anomaly case; new profile won't ever have a hard set value
GetPrefs()->SetBoolean(kWebTorrentEnabled, true);
const PrefService::Preference* pref =
GetPrefs()->FindPreference(kWebTorrentEnabled);
EXPECT_TRUE(pref->HasUserSetting());
brave::SetWebTorrentEnabled(GetProfile(), true);
EXPECT_TRUE(GetPrefs()->GetBoolean(kWebTorrentEnabled));
}
#endif // ENABLE_BRAVE_WEBTORRENT
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ test("brave_browser_tests") {
"//brave/components/brave_wallet/renderer",
"//brave/components/brave_wallet/resources:ethereum_provider_generated_resources",
"//brave/components/brave_wayback_machine/buildflags",
"//brave/components/brave_webtorrent/browser/buildflags",
"//brave/components/constants",
"//brave/components/de_amp/browser/test:browser_tests",
"//brave/components/de_amp/common:common",
Expand Down
Loading