diff --git a/.gitignore b/.gitignore index dd04f153f4c..abb9c3f8a90 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ vendor/omaha/ /.idea/ /components/brave_new_tab_ui/data/LICENSE /components/brave_wallet/browser/zcash/rust/librustzcash/src/ -/components/brave_webtorrent/extension/out/ /components/brave_rewards/resources/extension/brave_rewards/out/ /components/third_party/adblock/LICENSE /components/third_party/local_data/LICENSE diff --git a/.prettierignore b/.prettierignore index 0af653b8716..755c1fd290b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -77,7 +77,6 @@ components/brave_wallet/resources/solana_web3_script.js /components/policy/resources/templates/ /components/playlist/ /components/speedreader/ -/components/brave_webtorrent/ /components/common/ /components/cosmetic_filters/ /components/definitions/ diff --git a/brave_paks.gni b/brave_paks.gni index ac099b979b9..e57b68ea3ee 100644 --- a/brave_paks.gni +++ b/brave_paks.gni @@ -3,7 +3,6 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at https://mozilla.org/MPL/2.0/. -import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//brave/components/tor/buildflags/buildflags.gni") import("//build/config/locales.gni") import("//chrome/common/features.gni") @@ -89,12 +88,6 @@ template("brave_extra_paks") { deps += [ "//brave/components/tor/resources" ] } - if (enable_brave_webtorrent) { - sources += [ "$root_gen_dir/brave/components/brave_webtorrent/brave_webtorrent_resources.pak" ] - - deps += [ "//brave/components/brave_webtorrent:resources" ] - } - if (enable_extensions) { sources += [ "$root_gen_dir/brave/components/brave_extension/brave_extension_resources.pak" ] diff --git a/browser/DEPS b/browser/DEPS index daa2486757f..0072d05db37 100644 --- a/browser/DEPS +++ b/browser/DEPS @@ -84,7 +84,6 @@ include_rules += [ "+brave/components/body_sniffer", "+brave/components/brave_search/browser", "+brave/components/brave_search/common", - "+brave/components/brave_webtorrent/browser", "+brave/components/cosmetic_filters/browser", "+brave/components/cosmetic_filters/common", "+brave/components/decentralized_dns/content", diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index a2c8631d809..cfa9f7e06ad 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -81,7 +81,6 @@ #include "brave/components/brave_wallet/browser/brave_wallet_utils.h" #include "brave/components/brave_wallet/common/brave_wallet.mojom.h" #include "brave/components/brave_wallet/common/common_utils.h" -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" #include "brave/components/constants/pref_names.h" #include "brave/components/constants/webui_url_constants.h" #include "brave/components/containers/buildflags/buildflags.h" @@ -192,10 +191,6 @@ using extensions::ChromeContentBrowserClientExtensionsPart; #include "brave/components/ai_rewriter/common/mojom/ai_rewriter.mojom.h" #endif -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#include "brave/browser/extensions/brave_webtorrent_navigation_throttle.h" -#endif - #if BUILDFLAG(ENABLE_TOR) #include "brave/browser/tor/tor_profile_service_factory.h" #include "brave/components/tor/onion_location_navigation_throttle.h" @@ -1175,12 +1170,6 @@ void BraveContentBrowserClient::CreateThrottlesForNavigation( NewTabShowsNavigationThrottle::MaybeCreateAndAdd(registry); #endif -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) - registry.AddThrottle( - std::make_unique( - registry)); -#endif - #if BUILDFLAG(ENABLE_TOR) tor::TorNavigationThrottle::MaybeCreateAndAdd(registry, context->IsTor()); tor::OnionLocationNavigationThrottle::MaybeCreateAndAdd( diff --git a/browser/brave_content_browser_client_browsertest.cc b/browser/brave_content_browser_client_browsertest.cc index c87e7418caf..c84f1ba4bfe 100644 --- a/browser/brave_content_browser_client_browsertest.cc +++ b/browser/brave_content_browser_client_browsertest.cc @@ -13,7 +13,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/test/bind.h" #include "brave/components/brave_shields/core/common/brave_shield_constants.h" -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" #include "brave/components/constants/brave_paths.h" #include "brave/components/constants/pref_names.h" #include "brave/components/constants/webui_url_constants.h" @@ -49,10 +48,6 @@ #include "brave/net/proxy_resolution/proxy_config_service_tor.h" #endif -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#include "brave/components/brave_webtorrent/browser/magnet_protocol_handler.h" -#endif - class BraveContentBrowserClientTest : public InProcessBrowserTest { public: void SetUp() override { @@ -78,38 +73,6 @@ class BraveContentBrowserClientTest : public InProcessBrowserTest { embedded_test_server()->ServeFilesFromDirectory(test_data_dir); ASSERT_TRUE(embedded_test_server()->Start()); - - magnet_html_url_ = embedded_test_server()->GetURL("a.com", "/magnet.html"); - magnet_url_ = GURL( - "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+" - "Buck+Bunny&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker." - "coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=" - "udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%" - "2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&" - "tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker." - "openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=" - "https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fbig-buck-bunny.torrent"); - extension_url_ = GURL( - "chrome-extension://lgjmpdmojkpocjcopdikifhejkkjglho/extension/" - "brave_webtorrent.html?magnet%3A%3Fxt%3Durn%3Abtih%" - "3Add8255ecdc7ca55fb0bbf81323d87062db1f6d1c%26dn%3DBig%2BBuck%2BBunny%" - "26tr%3Dudp%253A%252F%252Fexplodie.org%253A6969%26tr%3Dudp%253A%252F%" - "252Ftracker.coppersurfer.tk%253A6969%26tr%3Dudp%253A%252F%252Ftracker." - "empire-js.us%253A1337%26tr%3Dudp%253A%252F%252Ftracker.leechers-" - "paradise.org%253A6969%26tr%3Dudp%253A%252F%252Ftracker.opentrackr.org%" - "253A1337%26tr%3Dwss%253A%252F%252Ftracker.btorrent.xyz%26tr%3Dwss%" - "253A%252F%252Ftracker.fastcast.nz%26tr%3Dwss%253A%252F%252Ftracker." - "openwebtorrent.com%26ws%3Dhttps%253A%252F%252Fwebtorrent.io%" - "252Ftorrents%252F%26xs%3Dhttps%253A%252F%252Fwebtorrent.io%" - "252Ftorrents%252Fbig-buck-bunny.torrent"); - torrent_url_ = GURL("https://webtorrent.io/torrents/sintel.torrent#ix=5"); - torrent_extension_url_ = GURL( - "chrome-extension://lgjmpdmojkpocjcopdikifhejkkjglho/extension/" - "brave_webtorrent.html?https://webtorrent.io/torrents/" - "sintel.torrent#ix=5"); - torrent_invalid_query_extension_url_ = GURL( - "chrome-extension://lgjmpdmojkpocjcopdikifhejkkjglho/extension/" - "brave_webtorrent.html?chrome://settings"); } void TearDown() override { browser_content_client_.reset(); } @@ -127,26 +90,11 @@ class BraveContentBrowserClientTest : public InProcessBrowserTest { EXPECT_EQ(contents->GetLastCommittedURL(), final_url); } - const GURL& magnet_html_url() { return magnet_html_url_; } - const GURL& magnet_url() { return magnet_url_; } - const GURL& extension_url() { return extension_url_; } - const GURL& torrent_url() { return torrent_url_; } - const GURL& torrent_extension_url() { return torrent_extension_url_; } - const GURL& torrent_invalid_query_extension_url() { - return torrent_invalid_query_extension_url_; - } - content::ContentBrowserClient* client() { return browser_content_client_.get(); } private: - GURL magnet_html_url_; - GURL magnet_url_; - GURL extension_url_; - GURL torrent_url_; - GURL torrent_extension_url_; - GURL torrent_invalid_query_extension_url_; std::unique_ptr browser_content_client_; }; @@ -288,244 +236,6 @@ 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(); - - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_url())); - ASSERT_TRUE(WaitForLoadStop(contents)); - EXPECT_EQ(contents->GetLastCommittedURL().spec(), magnet_url().spec()) - << "URL visible to users should stay as the magnet URL"; - content::NavigationEntry* entry = - contents->GetController().GetLastCommittedEntry(); - EXPECT_EQ(entry->GetURL().spec(), extension_url().spec()) - << "Real URL should be extension URL"; -} - -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())); - ASSERT_TRUE(WaitForLoadStop(contents)); - EXPECT_TRUE(content::ExecJs(contents, "clickMagnetLink();")); - // Magnet protocol handler posts to UIThreadTaskRunner, so let all tasks run, - // otherwise WaitForLoadStop may return right away. - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(WaitForLoadStop(contents)); - - EXPECT_EQ(contents->GetLastCommittedURL().spec(), magnet_url().spec()) - << "URL visible to users should stay as the magnet URL"; - content::NavigationEntry* entry = - contents->GetController().GetLastCommittedEntry(); - EXPECT_EQ(entry->GetURL().spec(), extension_url().spec()) - << "Real URL should be extension URL"; -} - -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()); - // Magnet protocol handler posts to UIThreadTaskRunner, so let all tasks run, - // otherwise WaitForLoadStop may return right away. - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(WaitForLoadStop(web_contents)); - EXPECT_EQ(magnet_url(), web_contents->GetLastCommittedURL().spec()); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - ReverseRewriteTorrentURL) { - browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - - // Used to add the extension - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_url())); - ASSERT_TRUE(WaitForLoadStop(contents)); - - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), torrent_extension_url())); - ASSERT_TRUE(WaitForLoadStop(contents)); - - EXPECT_EQ(contents->GetLastCommittedURL().spec(), - base::StrCat({url::kWebTorrentScheme, ":", torrent_url().spec()})) - << "URL visible to users should stay as the torrent URL"; - content::NavigationEntry* entry = - contents->GetController().GetLastCommittedEntry(); - EXPECT_EQ(entry->GetURL().spec(), torrent_extension_url().spec()) - << "Real URL should be extension URL"; -} - -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())); - EXPECT_TRUE(content::ExecJs(contents, "createMagnetIframe(false);")); - // Magnet protocol handler posts to UIThreadTaskRunner, so let all tasks run, - // otherwise WaitForLoadStop may return right away. - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(WaitForLoadStop(contents)); - - EXPECT_EQ(contents->GetLastCommittedURL(), magnet_url()); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - MagnetIframeWithoutUserGestureDoesNotOpenWebtorrent) { - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_html_url())); - EXPECT_TRUE(content::ExecJs(contents, "createMagnetIframe(false);", - content::EXECUTE_SCRIPT_NO_USER_GESTURE)); - // Magnet protocol handler posts to UIThreadTaskRunner, so let all tasks run, - // otherwise WaitForLoadStop may return right away. - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(WaitForLoadStop(contents)); - - EXPECT_EQ(contents->GetLastCommittedURL(), magnet_html_url()); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - MagnetIframeSandboxedDoesNotOpenWebtorrent) { - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_html_url())); - EXPECT_TRUE(content::ExecJs(contents, "createMagnetIframe(true);")); - // Magnet protocol handler posts to UIThreadTaskRunner, so let all tasks run, - // otherwise WaitForLoadStop may return right away. - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(WaitForLoadStop(contents)); - - EXPECT_EQ(contents->GetLastCommittedURL(), magnet_html_url()); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - NoReverseRewriteTorrentURLForInvalidQuery) { - browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - - // Used to add the extension - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_url())); - ASSERT_TRUE(WaitForLoadStop(contents)); - - ASSERT_TRUE(ui_test_utils::NavigateToURL( - browser(), torrent_invalid_query_extension_url())); - ASSERT_TRUE(WaitForLoadStop(contents)); - EXPECT_EQ(contents->GetLastCommittedURL().spec(), - torrent_invalid_query_extension_url().spec()) - << "URL visible to users should stay as extension URL for invalid query"; - content::NavigationEntry* entry = - contents->GetController().GetLastCommittedEntry(); - EXPECT_EQ(entry->GetURL().spec(), - torrent_invalid_query_extension_url().spec()) - << "Real URL should be extension URL"; -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - WebTorrentExtensionEnabledAfterLoad) { - browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, true); - - extensions::ExtensionRegistry* registry = - extensions::ExtensionRegistry::Get(browser()->profile()); - ASSERT_FALSE( - registry->enabled_extensions().Contains(brave_webtorrent_extension_id)); - - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_url())); - WaitForLoadStop(contents); - - ASSERT_TRUE( - registry->enabled_extensions().Contains(brave_webtorrent_extension_id)); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - PRE_NoRewriteMagnetURLURLBarWebTorrentDisabled) { - browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, false); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - NoRewriteMagnetURLURLBarWebTorrentDisabled) { - ASSERT_FALSE( - browser()->profile()->GetPrefs()->GetBoolean(kWebTorrentEnabled)); - extensions::ExtensionRegistry* registry = - extensions::ExtensionRegistry::Get(browser()->profile()); - ASSERT_FALSE( - registry->enabled_extensions().Contains(brave_webtorrent_extension_id)); - - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_url())); - ASSERT_TRUE(WaitForLoadStop(contents)); - EXPECT_EQ(contents->GetLastCommittedURL().spec(), "about:blank"); - content::NavigationEntry* entry = - contents->GetController().GetLastCommittedEntry(); - EXPECT_EQ(entry->GetURL().spec(), "about:blank"); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - PRE_NoRewriteMagnetURLLinkWebTorrentDisabled) { - browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, false); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - NoRewriteMagnetURLLinkWebTorrentDisabled) { - ASSERT_FALSE( - browser()->profile()->GetPrefs()->GetBoolean(kWebTorrentEnabled)); - extensions::ExtensionRegistry* registry = - extensions::ExtensionRegistry::Get(browser()->profile()); - ASSERT_FALSE( - registry->enabled_extensions().Contains(brave_webtorrent_extension_id)); - - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), magnet_html_url())); - ASSERT_TRUE(WaitForLoadStop(contents)); - EXPECT_TRUE(content::ExecJs(contents, "clickMagnetLink();")); - // Magnet protocol handler posts to UIThreadTaskRunner, so let all tasks run, - // otherwise WaitForLoadStop may return right away. - base::RunLoop().RunUntilIdle(); - ASSERT_TRUE(WaitForLoadStop(contents)); - - EXPECT_EQ(contents->GetLastCommittedURL().spec(), magnet_html_url().spec()); - content::NavigationEntry* entry = - contents->GetController().GetLastCommittedEntry(); - EXPECT_EQ(entry->GetURL().spec(), magnet_html_url().spec()); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - PRE_NoReverseRewriteTorrentURLWebTorrentDisabled) { - browser()->profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, false); -} - -IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, - NoReverseRewriteTorrentURLWebTorrentDisabled) { - ASSERT_FALSE( - browser()->profile()->GetPrefs()->GetBoolean(kWebTorrentEnabled)); - extensions::ExtensionRegistry* registry = - extensions::ExtensionRegistry::Get(browser()->profile()); - ASSERT_FALSE( - registry->enabled_extensions().Contains(brave_webtorrent_extension_id)); - - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), torrent_extension_url())); - WaitForLoadStop(contents); - - EXPECT_EQ(contents->GetLastCommittedURL().spec(), - torrent_extension_url().spec()) - << "No changes on the visible URL"; - content::NavigationEntry* entry = - contents->GetController().GetLastCommittedEntry(); - EXPECT_EQ(entry->GetURL().spec(), torrent_extension_url().spec()) - << "No changes on the real URL"; -} -#endif // BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) - #if BUILDFLAG(ENABLE_TOR) IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, MixedContentForOnion) { net::ProxyConfigServiceTor::SetBypassTorProxyConfigForTesting(true); diff --git a/browser/brave_prefs_browsertest.cc b/browser/brave_prefs_browsertest.cc index 16c919bfe8b..6fbdf51a332 100644 --- a/browser/brave_prefs_browsertest.cc +++ b/browser/brave_prefs_browsertest.cc @@ -13,7 +13,6 @@ #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" @@ -82,10 +81,6 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) { brave_shields::prefs::kReduceLanguageEnabled), base::FeatureList::IsEnabled( brave_shields::features::kBraveReduceLanguage)); -#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)); diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 9edcaf0edb2..ebf145ef798 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -38,7 +38,6 @@ #include "brave/components/brave_vpn/common/buildflags/buildflags.h" #include "brave/components/brave_wallet/browser/brave_wallet_prefs.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/containers/buildflags/buildflags.h" #include "brave/components/de_amp/common/pref_names.h" diff --git a/browser/extensions/BUILD.gn b/browser/extensions/BUILD.gn index 7bdae963d77..1992c836a0d 100644 --- a/browser/extensions/BUILD.gn +++ b/browser/extensions/BUILD.gn @@ -5,7 +5,6 @@ import("//brave/components/brave_vpn/common/buildflags/buildflags.gni") import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni") -import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//brave/components/playlist/common/buildflags/buildflags.gni") import("//brave/components/speedreader/common/buildflags/buildflags.gni") import("//brave/components/tor/buildflags/buildflags.gni") @@ -26,7 +25,6 @@ source_set("component_loader") { "//base", "//brave/components/brave_component_updater/browser", "//brave/components/brave_extension:static_resources", - "//brave/components/brave_webtorrent:static_resources", "//chrome/browser:browser_process", "//chrome/browser/extensions", "//chrome/browser/profiles:profile", @@ -126,7 +124,6 @@ source_set("extensions") { "//brave/components/brave_wallet/browser:utils", "//brave/components/brave_wallet/common", "//brave/components/brave_wayback_machine/buildflags", - "//brave/components/brave_webtorrent:static_resources", "//brave/components/constants", "//brave/components/de_amp/common", "//brave/components/debounce/core/common", @@ -203,14 +200,6 @@ source_set("extensions") { "//components/prefs", ] - if (enable_brave_webtorrent) { - sources += [ - "brave_webtorrent_navigation_throttle.cc", - "brave_webtorrent_navigation_throttle.h", - ] - deps += [ "//brave/components/brave_webtorrent/browser" ] - } - allow_circular_includes_from = [ ":brave_prefs_util_impl" ] } @@ -219,12 +208,6 @@ group("resources") { "//brave/components/brave_extension:generated_resources", "//brave/components/brave_extension:static_resources", ] - if (enable_brave_webtorrent) { - deps += [ - "//brave/components/brave_webtorrent:generated_resources", - "//brave/components/brave_webtorrent:static_resources", - ] - } } source_set("test_support") { diff --git a/browser/extensions/DEPS b/browser/extensions/DEPS index 86982059992..dba4a291cd3 100644 --- a/browser/extensions/DEPS +++ b/browser/extensions/DEPS @@ -1,5 +1,4 @@ include_rules = [ "+brave/components/brave_extension/grit", - "+brave/components/brave_webtorrent/grit", "+brave/components/update_client/buildflags.h", ] diff --git a/browser/extensions/api/settings_private/brave_prefs_util.cc b/browser/extensions/api/settings_private/brave_prefs_util.cc index c55017141fd..1b13a6d545f 100644 --- a/browser/extensions/api/settings_private/brave_prefs_util.cc +++ b/browser/extensions/api/settings_private/brave_prefs_util.cc @@ -214,8 +214,6 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() { (*s_brave_allowlist)[kAlwaysShowBookmarkBarOnNTP] = settings_api::PrefType::kBoolean; (*s_brave_allowlist)[kMRUCyclingEnabled] = settings_api::PrefType::kBoolean; - // WebTorrent pref - (*s_brave_allowlist)[kWebTorrentEnabled] = settings_api::PrefType::kBoolean; #if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE) (*s_brave_allowlist)[kBraveWaybackMachineEnabled] = settings_api::PrefType::kBoolean; diff --git a/browser/extensions/brave_component_loader.cc b/browser/extensions/brave_component_loader.cc index 2f152ce816e..d906fbd9a87 100644 --- a/browser/extensions/brave_component_loader.cc +++ b/browser/extensions/brave_component_loader.cc @@ -16,7 +16,6 @@ #include "brave/components/brave_component_updater/browser/brave_component_installer.h" #include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h" #include "brave/components/brave_extension/grit/brave_extension.h" -#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h" #include "brave/components/constants/brave_switches.h" #include "brave/components/constants/pref_names.h" #include "chrome/browser/browser_process.h" @@ -83,19 +82,6 @@ void BraveComponentLoader::AddDefaultComponentExtensions( UpdateBraveExtension(); } -void BraveComponentLoader::AddWebTorrentExtension() { - const base::CommandLine& command_line = - *base::CommandLine::ForCurrentProcess(); - if (!command_line.HasSwitch(switches::kDisableWebTorrentExtension) && - (!profile_prefs_->FindPreference(kWebTorrentEnabled) || - profile_prefs_->GetBoolean(kWebTorrentEnabled))) { - base::FilePath brave_webtorrent_path(FILE_PATH_LITERAL("")); - brave_webtorrent_path = - brave_webtorrent_path.Append(FILE_PATH_LITERAL("brave_webtorrent")); - Add(IDR_BRAVE_WEBTORRENT, brave_webtorrent_path); - } -} - bool BraveComponentLoader::UseBraveExtensionBackgroundPage() { // Keep sync with `pref_change_registrar_` in the ctor. return profile_prefs_->GetBoolean(kWebDiscoveryEnabled); diff --git a/browser/extensions/brave_component_loader.h b/browser/extensions/brave_component_loader.h index 57ffb58a159..f9bc382bf18 100644 --- a/browser/extensions/brave_component_loader.h +++ b/browser/extensions/brave_component_loader.h @@ -33,7 +33,6 @@ class BraveComponentLoader : public ComponentLoader { void AddDefaultComponentExtensions(bool skip_session_components) override; void OnComponentRegistered(std::string extension_id); - void AddWebTorrentExtension(); void OnComponentReady(std::string extension_id, bool allow_file_access, const base::FilePath& install_dir, diff --git a/browser/extensions/brave_webtorrent_navigation_throttle.cc b/browser/extensions/brave_webtorrent_navigation_throttle.cc deleted file mode 100644 index 87df8855aa0..00000000000 --- a/browser/extensions/brave_webtorrent_navigation_throttle.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* 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/browser/extensions/brave_webtorrent_navigation_throttle.h" - -#include "brave/browser/extensions/brave_component_loader.h" -#include "brave/components/brave_webtorrent/browser/webtorrent_util.h" -#include "brave/components/constants/pref_names.h" -#include "brave/components/constants/url_constants.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/profiles/profile.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/navigation_handle.h" -#include "content/public/browser/web_contents.h" -#include "content/public/common/url_constants.h" -#include "extensions/browser/extension_system.h" -#include "extensions/common/constants.h" -#include "extensions/common/extension.h" - -namespace extensions { - -BraveWebTorrentNavigationThrottle::BraveWebTorrentNavigationThrottle( - content::NavigationHandle* navigation_handle) - : content::NavigationThrottle(navigation_handle) {} - -BraveWebTorrentNavigationThrottle::~BraveWebTorrentNavigationThrottle() {} - -content::NavigationThrottle::ThrottleCheckResult -BraveWebTorrentNavigationThrottle::WillStartRequest() { - // This handles magnet URLs and .torrent filenames in the URL but not - // response headers. - return CommonWillProcessRequestResponse(); -} - -content::NavigationThrottle::ThrottleCheckResult -BraveWebTorrentNavigationThrottle::WillProcessResponse() { - // This handles response headers with headers that indicate torrent content. - // This is not as good as if we catch it in the WillStartRequest section - // because the user will need to manually restart the request to make it work. - return CommonWillProcessRequestResponse(); -} - -// static -bool BraveWebTorrentNavigationThrottle::MaybeLoadWebtorrent( - content::BrowserContext* context, - const GURL& url) { - // No need to load Webtorrent if pref is off or it is already enabled. - auto* prefs = Profile::FromBrowserContext(context)->GetPrefs(); - if (!prefs->GetBoolean(kWebTorrentEnabled) || - webtorrent::IsWebtorrentEnabled(context)) { - return false; - } - - static_cast( - extensions::ComponentLoader::Get(context)) - ->AddWebTorrentExtension(); - return true; -} - -content::NavigationThrottle::ThrottleCheckResult -BraveWebTorrentNavigationThrottle::CommonWillProcessRequestResponse() { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - content::WebContents* web_contents = navigation_handle()->GetWebContents(); - - // Is this navigation targeting an extension resource? - const GURL& url = navigation_handle()->GetURL(); - // Note, if we use WillProcessResponse we can also use response headers, but - // it would be too late to handle the request as WebTorrent in that case. - // So the best we can do is via URL pattern match and magnet links. - // Headers are null when processing WillStartRequest. - auto* headers = navigation_handle()->GetResponseHeaders(); - bool is_torrent_file = headers ? webtorrent::IsTorrentFile(url, headers) - : webtorrent::TorrentURLMatched(url); - if (url.SchemeIs(kMagnetScheme) || is_torrent_file) { - MaybeLoadWebtorrent(web_contents->GetBrowserContext(), url); - } - - return content::NavigationThrottle::PROCEED; -} - -const char* BraveWebTorrentNavigationThrottle::GetNameForLogging() { - return "BraveWebTorrentNavigationThrottle"; -} - -} // namespace extensions diff --git a/browser/extensions/brave_webtorrent_navigation_throttle.h b/browser/extensions/brave_webtorrent_navigation_throttle.h deleted file mode 100644 index 5ba41c25345..00000000000 --- a/browser/extensions/brave_webtorrent_navigation_throttle.h +++ /dev/null @@ -1,47 +0,0 @@ -/* 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/. */ - -#ifndef BRAVE_BROWSER_EXTENSIONS_BRAVE_WEBTORRENT_NAVIGATION_THROTTLE_H_ -#define BRAVE_BROWSER_EXTENSIONS_BRAVE_WEBTORRENT_NAVIGATION_THROTTLE_H_ - -#include "base/scoped_observation.h" -#include "base/timer/timer.h" -#include "content/public/browser/navigation_throttle.h" -#include "url/gurl.h" - -namespace content { -class BrowserContext; -class NavigationHandle; -} - -namespace extensions { - -// This class enables the WebTorrent component when a .torrent -// or magnet file is loaded. -class BraveWebTorrentNavigationThrottle : public content::NavigationThrottle { - public: - explicit BraveWebTorrentNavigationThrottle( - content::NavigationHandle* navigation_handle); - BraveWebTorrentNavigationThrottle(const BraveWebTorrentNavigationThrottle&) = - delete; - BraveWebTorrentNavigationThrottle& operator=( - const BraveWebTorrentNavigationThrottle&) = delete; - ~BraveWebTorrentNavigationThrottle() override; - - // content::NavigationThrottle implementation: - ThrottleCheckResult WillStartRequest() override; - ThrottleCheckResult WillProcessResponse() override; - const char* GetNameForLogging() override; - - static bool MaybeLoadWebtorrent( - content::BrowserContext* context, const GURL& url); - - private: - ThrottleCheckResult CommonWillProcessRequestResponse(); -}; - -} // namespace extensions - -#endif // BRAVE_BROWSER_EXTENSIONS_BRAVE_WEBTORRENT_NAVIGATION_THROTTLE_H_ diff --git a/browser/extensions/brave_webtorrent_navigation_throttle_unittest.cc b/browser/extensions/brave_webtorrent_navigation_throttle_unittest.cc deleted file mode 100644 index e9cf67ffa07..00000000000 --- a/browser/extensions/brave_webtorrent_navigation_throttle_unittest.cc +++ /dev/null @@ -1,237 +0,0 @@ -/* 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/browser/extensions/brave_webtorrent_navigation_throttle.h" - -#include -#include -#include - -#include "base/command_line.h" -#include "base/files/scoped_temp_dir.h" -#include "base/memory/raw_ptr.h" -#include "base/values.h" -#include "brave/components/constants/pref_names.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/load_error_reporter.h" -#include "chrome/browser/extensions/test_extension_system.h" -#include "chrome/browser/prefs/browser_prefs.h" -#include "chrome/test/base/scoped_testing_local_state.h" -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_profile.h" -#include "components/prefs/testing_pref_service.h" -#include "components/sync_preferences/testing_pref_service_syncable.h" -#include "content/public/browser/content_browser_client.h" -#include "content/public/browser/navigation_handle.h" -#include "content/public/browser/navigation_throttle_registry.h" -#include "content/public/common/content_client.h" -#include "content/public/test/mock_navigation_handle.h" -#include "content/public/test/test_renderer_host.h" -#include "content/public/test/web_contents_tester.h" -#include "extensions/browser/extension_system.h" -#include "extensions/common/constants.h" -#include "extensions/common/extension.h" -#include "extensions/common/extension_builder.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "url/gurl.h" - -using content::NavigationThrottle; - -namespace extensions { - -namespace { - -class MockBrowserClient : public content::ContentBrowserClient { - public: - MockBrowserClient() = default; - ~MockBrowserClient() override = default; - - // Only construct an BraveWebTorrentNavigationThrottle so that we can test it - // in isolation. - void CreateThrottlesForNavigation( - content::NavigationThrottleRegistry& registry) override { - registry.AddThrottle(std::make_unique( - ®istry.GetNavigationHandle())); - } -}; - -const GURL& GetMagnetUrl() { - static const GURL magnet_url( - "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fbig-buck-bunny.torrent"); // NOLINT - return magnet_url; -} - -const GURL& GetTorrentUrl() { - static const GURL torrent_url( - "https://webtorrent.io/torrents/big-buck-bunny.torrent"); - return torrent_url; -} - -} // namespace - -class BraveWebTorrentNavigationThrottleUnitTest - : public content::RenderViewHostTestHarness { - public: - BraveWebTorrentNavigationThrottleUnitTest() - : local_state_(TestingBrowserProcess::GetGlobal()) { - } - - BraveWebTorrentNavigationThrottleUnitTest( - const BraveWebTorrentNavigationThrottleUnitTest&) = delete; - - BraveWebTorrentNavigationThrottleUnitTest& operator=( - const BraveWebTorrentNavigationThrottleUnitTest&) = delete; - - void SetUp() override { - original_client_ = content::SetBrowserClientForTesting(&client_); - content::RenderViewHostTestHarness::SetUp(); - - // Initialize the various pieces of the extensions system. - extensions::LoadErrorReporter::Init(false); - extensions::TestExtensionSystem* extension_system = - static_cast( - extensions::ExtensionSystem::Get(profile())); - extension_system->CreateExtensionService( - base::CommandLine::ForCurrentProcess(), base::FilePath(), false); - extension_service_ = - extensions::ExtensionSystem::Get(profile())->extension_service(); - } - - std::unique_ptr CreateBrowserContext() override { - TestingProfile::Builder builder; - auto prefs = - std::make_unique(); - RegisterUserProfilePrefs(prefs->registry()); - builder.SetPrefService(std::move(prefs)); - return builder.Build(); - } - - void TearDown() override { - extension_service_ = nullptr; - content::SetBrowserClientForTesting(original_client_); - content::RenderViewHostTestHarness::TearDown(); - } - - extensions::ExtensionService* extension_service() { - return extension_service_; - } - - content::RenderFrameHostTester* render_frame_host_tester( - content::RenderFrameHost* host) { - return content::RenderFrameHostTester::For(host); - } - - content::WebContentsTester* web_contents_tester() { - return content::WebContentsTester::For(web_contents()); - } - - TestingProfile* profile() { - return static_cast(browser_context()); - } - - void AddExtension() { - extension_ = ExtensionBuilder() - .SetManifest(base::Value::Dict() - .Set("name", "ext") - .Set("version", "0.1") - .Set("manifest_version", 2)) - .SetID(brave_webtorrent_extension_id) - .Build(); - ASSERT_TRUE(extension_); - ExtensionRegistrar::Get(profile())->AddExtension(extension_); - } - - private: - scoped_refptr extension_; - MockBrowserClient client_; - ScopedTestingLocalState local_state_; - base::ScopedTempDir temp_dir_; - sync_preferences::TestingPrefServiceSyncable prefs_; - raw_ptr original_client_ = nullptr; - - // The ExtensionService associated with the primary profile. - raw_ptr extension_service_ = nullptr; -}; - -// Tests the basic case of loading a URL, it should proceed. -TEST_F(BraveWebTorrentNavigationThrottleUnitTest, ExternalWebPage) { - web_contents_tester()->NavigateAndCommit(GURL("http://example.com")); - content::RenderFrameHost* host = - render_frame_host_tester(main_rfh())->AppendChild("child"); - GURL url("http://www.example.com"); - content::MockNavigationHandle test_handle(url, host); - test_handle.set_starting_site_instance(host->GetSiteInstance()); - auto throttle = - std::make_unique(&test_handle); - EXPECT_EQ(NavigationThrottle::PROCEED, throttle->WillStartRequest().action()) - << url; -} - -// Tests the case of loading a torrent without having the extension installed. -// It should proceed with the navigation (it used to defer prior to changes in -// cr114, but OnExtensionReady is triggered immediately now when loading the -// WebTorrent extension). -TEST_F(BraveWebTorrentNavigationThrottleUnitTest, - WebTorrentUrlNotInstalled) { - web_contents_tester()->NavigateAndCommit(GURL("http://example.com")); - content::RenderFrameHost* host = - render_frame_host_tester(main_rfh())->AppendChild("child"); - content::MockNavigationHandle test_handle(GetTorrentUrl(), host); - test_handle.set_starting_site_instance(host->GetSiteInstance()); - auto throttle = - std::make_unique(&test_handle); - EXPECT_EQ(NavigationThrottle::PROCEED, throttle->WillStartRequest().action()) - << GetTorrentUrl(); -} - -// Tests the case of loading a torrent without having the extension installed. -// It should proceed with the navigation (it used to defer prior to changes in -// cr114, but OnExtensionReady is triggered immediately now when loading the -// WebTorrent extension). -TEST_F(BraveWebTorrentNavigationThrottleUnitTest, - WebTorrentMagnetUrlNotInstalled) { - web_contents_tester()->NavigateAndCommit(GURL("http://example.com")); - content::RenderFrameHost* host = - render_frame_host_tester(main_rfh())->AppendChild("child"); - content::MockNavigationHandle test_handle(GetMagnetUrl(), host); - test_handle.set_starting_site_instance(host->GetSiteInstance()); - auto throttle = - std::make_unique(&test_handle); - EXPECT_EQ(NavigationThrottle::PROCEED, throttle->WillStartRequest().action()) - << GetMagnetUrl(); -} - - -// Tests the case of loading a torrent with the extension installed. -// It should just proceed. -TEST_F(BraveWebTorrentNavigationThrottleUnitTest, WebTorrentUrlInstalled) { - AddExtension(); - web_contents_tester()->NavigateAndCommit(GURL("http://example.com")); - content::RenderFrameHost* host = - render_frame_host_tester(main_rfh())->AppendChild("child"); - content::MockNavigationHandle test_handle(GetMagnetUrl(), host); - test_handle.set_starting_site_instance(host->GetSiteInstance()); - auto throttle = - std::make_unique(&test_handle); - EXPECT_EQ(NavigationThrottle::PROCEED, throttle->WillStartRequest().action()) - << GetMagnetUrl(); -} - -// Tests the case of loading a torrent when the WebTorrent is explicitly -// disabled. -TEST_F(BraveWebTorrentNavigationThrottleUnitTest, WebTorrentDisabledByPref) { - profile()->GetPrefs()->SetBoolean(kWebTorrentEnabled, false); - web_contents_tester()->NavigateAndCommit(GURL("http://example.com")); - content::RenderFrameHost* host = - render_frame_host_tester(main_rfh())->AppendChild("child"); - content::MockNavigationHandle test_handle(GetMagnetUrl(), host); - test_handle.set_starting_site_instance(host->GetSiteInstance()); - auto throttle = - std::make_unique(&test_handle); - EXPECT_EQ(NavigationThrottle::PROCEED, - throttle->WillStartRequest().action()) << GetMagnetUrl(); -} - -} // namespace extensions diff --git a/browser/extensions/resources.gni b/browser/extensions/resources.gni index 94f06b52275..60ddb4ac7f1 100644 --- a/browser/extensions/resources.gni +++ b/browser/extensions/resources.gni @@ -6,5 +6,4 @@ brave_extensions_resources = [ "//brave/browser/extensions/api:generated_api_registration", "//brave/browser/extensions:resources", - "//brave/components/brave_webtorrent/browser/buildflags", ] diff --git a/browser/net/BUILD.gn b/browser/net/BUILD.gn index eafddac9acb..ceff8b6b2c1 100644 --- a/browser/net/BUILD.gn +++ b/browser/net/BUILD.gn @@ -3,7 +3,6 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at https://mozilla.org/MPL/2.0/. -import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//brave/components/tor/buildflags/buildflags.gni") import("//build/config/features.gni") @@ -91,16 +90,4 @@ source_set("unit_tests") { "//testing/gtest", "//third_party/abseil-cpp:absl", ] - - if (enable_brave_webtorrent) { - sources += [ - "//brave/browser/extensions/brave_webtorrent_navigation_throttle_unittest.cc", - "//brave/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc", - ] - - deps += [ - "//brave/browser/extensions", - "//brave/components/brave_referrals/browser", - ] - } } diff --git a/browser/net/brave_request_handler.cc b/browser/net/brave_request_handler.cc index a053c8f185c..44217b66471 100644 --- a/browser/net/brave_request_handler.cc +++ b/browser/net/brave_request_handler.cc @@ -22,7 +22,6 @@ #include "brave/browser/net/global_privacy_control_network_delegate_helper.h" #include "brave/browser/net/search_ads_header_network_delegate_helper.h" #include "brave/components/brave_shields/core/common/features.h" -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" #include "brave/components/constants/pref_names.h" #include "chrome/browser/browser_process.h" #include "content/public/browser/browser_task_traits.h" @@ -34,10 +33,6 @@ #include "net/base/net_errors.h" #include "third_party/blink/public/common/features.h" -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#include "brave/browser/net/brave_torrent_redirect_network_delegate_helper.h" -#endif - static bool IsInternalScheme(std::shared_ptr ctx) { DCHECK(ctx); #if BUILDFLAG(ENABLE_EXTENSIONS) @@ -103,12 +98,6 @@ void BraveRequestHandler::SetupCallbacks() { base::BindRepeating(brave::OnBeforeStartTransaction_SearchAdsHeader); before_start_transaction_callbacks_.push_back(start_transaction_callback); -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) - brave::OnHeadersReceivedCallback headers_received_callback = - base::BindRepeating(webtorrent::OnHeadersReceived_TorrentRedirectWork); - headers_received_callbacks_.push_back(headers_received_callback); -#endif - if (base::FeatureList::IsEnabled( ::brave_shields::features::kBraveAdblockCspRules)) { brave::OnHeadersReceivedCallback headers_received_callback2 = @@ -164,6 +153,7 @@ int BraveRequestHandler::OnHeadersReceived( if (headers_received_callbacks_.empty() && !ctx->request_url.SchemeIs(content::kChromeUIScheme)) { + // TODO(bsclifton): can this be removed? // Extension scheme not excluded since brave_webtorrent needs it. return net::OK; } diff --git a/browser/net/brave_torrent_redirect_network_delegate_helper.cc b/browser/net/brave_torrent_redirect_network_delegate_helper.cc deleted file mode 100644 index 7479f352c2f..00000000000 --- a/browser/net/brave_torrent_redirect_network_delegate_helper.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* 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/browser/net/brave_torrent_redirect_network_delegate_helper.h" - -#include -#include - -#include "base/strings/strcat.h" -#include "base/strings/string_util.h" -#include "brave/components/brave_webtorrent/browser/webtorrent_util.h" -#include "brave/components/constants/network_constants.h" -#include "content/public/browser/navigation_controller.h" -#include "content/public/browser/site_instance.h" -#include "content/public/browser/web_contents.h" -#include "extensions/common/constants.h" -#include "net/http/http_content_disposition.h" -#include "net/http/http_response_headers.h" -#include "net/url_request/url_request.h" -#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h" -#include "ui/base/page_transition_types.h" -#include "url/origin.h" - -namespace { - -// Returns true if the URL contains a URL fragment that starts with "ix=". For -// example, https://webtorrent.io/torrents/big-buck-bunny.torrent#ix=1. -bool IsViewerURL(const GURL& url) { - return base::StartsWith(url.ref(), - "ix=", base::CompareCase::INSENSITIVE_ASCII); -} - -bool IsWebtorrentInitiated(std::shared_ptr ctx) { - return ctx->initiator_url.scheme() == extensions::kExtensionScheme && - ctx->initiator_url.host() == brave_webtorrent_extension_id; -} - -// Returns true if the resource type is a frame (i.e. a top level page) or a -// subframe (i.e. a frame or iframe). For all other resource types (stylesheet, -// script, XHR request, etc.), returns false. -bool IsMainFrameResource(std::shared_ptr ctx) { - return ctx->resource_type == blink::mojom::ResourceType::kMainFrame; -} - -} // namespace - -namespace webtorrent { - -bool ShouldRedirectRequest( - const net::HttpResponseHeaders* original_response_headers, - std::shared_ptr ctx) { - return !(!original_response_headers || !IsMainFrameResource(ctx) || - ctx->is_webtorrent_disabled || - // download .torrent, do not redirect - (IsWebtorrentInitiated(ctx) && !IsViewerURL(ctx->request_url)) || - !IsTorrentFile(ctx->request_url, original_response_headers)); -} - -int OnHeadersReceived_TorrentRedirectWork( - const net::HttpResponseHeaders* original_response_headers, - scoped_refptr* override_response_headers, - GURL* allowed_unsafe_redirect_url, - const brave::ResponseCallback& next_callback, - std::shared_ptr ctx) { - if (!ShouldRedirectRequest(original_response_headers, ctx)) { - return net::OK; - } - - auto* contents = - content::WebContents::FromFrameTreeNodeId(ctx->frame_tree_node_id); - if (!contents) { - return net::OK; - } - - // We don't allow websites to directly link to the WebTorrent extension. - // However, this means that we can't simply redirect here (as that would be - // blocked), and instead, we need to create a new navigation. - GURL url(base::StrCat( - {extensions::kExtensionScheme, "://", brave_webtorrent_extension_id, - "/extension/brave_webtorrent2.html?", ctx->request_url.spec()})); - content::NavigationController::LoadURLParams params(url); - params.initiator_origin = url::Origin::Create(url); - params.source_site_instance = content::SiteInstance::CreateForURL( - contents->GetBrowserContext(), params.initiator_origin->GetURL()); - params.transition_type = ui::PAGE_TRANSITION_FROM_API; - - contents->GetController().LoadURLWithParams(params); - - return net::OK; -} - -} // namespace webtorrent diff --git a/browser/net/brave_torrent_redirect_network_delegate_helper.h b/browser/net/brave_torrent_redirect_network_delegate_helper.h deleted file mode 100644 index 0d4771ffcec..00000000000 --- a/browser/net/brave_torrent_redirect_network_delegate_helper.h +++ /dev/null @@ -1,43 +0,0 @@ -/* 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/. */ - -#ifndef BRAVE_BROWSER_NET_BRAVE_TORRENT_REDIRECT_NETWORK_DELEGATE_HELPER_H_ -#define BRAVE_BROWSER_NET_BRAVE_TORRENT_REDIRECT_NETWORK_DELEGATE_HELPER_H_ - -#include - -#include "brave/browser/net/url_context.h" - -namespace brave { -struct BraveRequestInfo; -} - -namespace net { -class URLRequest; -} - -namespace webtorrent { - -// Determines whether a request should be redirected to a torrent file. This -// will occur if the following conditions are met: -// 1. The request succeeded -// 2. The request is in the Main frame -// 3. WebTorrent is enabled -// 4. The request is for a torrent file / or the WebTorrent extension initiated -// the request. -bool ShouldRedirectRequest( - const net::HttpResponseHeaders* original_response_headers, - std::shared_ptr ctx); - -int OnHeadersReceived_TorrentRedirectWork( - const net::HttpResponseHeaders* original_response_headers, - scoped_refptr* override_response_headers, - GURL* allowed_unsafe_redirect_url, - const brave::ResponseCallback& next_callback, - std::shared_ptr ctx); - -} // namespace webtorrent - -#endif // BRAVE_BROWSER_NET_BRAVE_TORRENT_REDIRECT_NETWORK_DELEGATE_HELPER_H_ diff --git a/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc b/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc deleted file mode 100644 index 2b45192386b..00000000000 --- a/browser/net/brave_torrent_redirect_network_delegate_helper_unittest.cc +++ /dev/null @@ -1,248 +0,0 @@ -// 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 https://mozilla.org/MPL/2.0/. - -#include "brave/browser/net/brave_torrent_redirect_network_delegate_helper.h" - -#include -#include - -#include "base/strings/strcat.h" -#include "brave/browser/net/url_context.h" -#include "brave/components/constants/network_constants.h" -#include "net/base/net_errors.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h" - -using brave::ResponseCallback; - -class BraveTorrentRedirectNetworkDelegateHelperTest : public testing::Test { - public: - BraveTorrentRedirectNetworkDelegateHelperTest() { - torrent_url_ = GURL("https://webtorrent.io/torrents/sintel.torrent"); - torrent_viewer_url_ = - GURL("https://webtorrent.io/torrents/sintel.torrent#ix=0"); - non_torrent_url_ = GURL("https://webtorrent.io/torrents/sintel"); - - torrent_extension_url_ = GURL( - "chrome-extension://lgjmpdmojkpocjcopdikifhejkkjglho/extension/" - "brave_webtorrent2.html?https://webtorrent.io/torrents/sintel.torrent"); - torrent_viewer_extension_url_ = GURL( - "chrome-extension://lgjmpdmojkpocjcopdikifhejkkjglho/extension/" - "brave_webtorrent2.html?https://webtorrent.io/torrents/sintel.torrent" - "#ix=0"); - non_torrent_extension_url_ = GURL( - "chrome-extension://lgjmpdmojkpocjcopdikifhejkkjglho/extension/" - "brave_webtorrent2.html?https://webtorrent.io/torrents/sintel"); - } - - const GURL& torrent_url() { return torrent_url_; } - - const GURL& torrent_viewer_url() { return torrent_viewer_url_; } - - const GURL& non_torrent_url() { return non_torrent_url_; } - - const GURL& torrent_extension_url() { return torrent_extension_url_; } - - const GURL& torrent_viewer_extension_url() { - return torrent_viewer_extension_url_; - } - - const GURL& non_torrent_extension_url() { return non_torrent_extension_url_; } - - private: - GURL torrent_url_; - GURL torrent_viewer_url_; - GURL non_torrent_url_; - - GURL torrent_extension_url_; - GURL torrent_viewer_extension_url_; - GURL non_torrent_extension_url_; -}; - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, - NoRedirectWithoutMimeType) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = std::make_shared(torrent_url()); - request_info->resource_type = blink::mojom::ResourceType::kMainFrame; - - int rc = webtorrent::OnHeadersReceived_TorrentRedirectWork( - orig_response_headers.get(), &overwrite_response_headers, - &allowed_unsafe_redirect_url, ResponseCallback(), request_info); - - EXPECT_EQ(overwrite_response_headers->GetStatusLine(), "HTTP/1.0 200 OK"); - std::string location; - EXPECT_FALSE(overwrite_response_headers->EnumerateHeader(nullptr, "Location", - &location)); - EXPECT_EQ(allowed_unsafe_redirect_url, GURL()); - EXPECT_EQ(rc, net::OK); -} - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, - BittorrentMimeTypeRedirect) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - orig_response_headers->AddHeader("Content-Type", kBittorrentMimeType); - std::string mime_type; - ASSERT_TRUE(orig_response_headers->GetMimeType(&mime_type)); - ASSERT_EQ(mime_type, kBittorrentMimeType); - - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = std::make_shared(torrent_url()); - request_info->resource_type = blink::mojom::ResourceType::kMainFrame; - - auto will_redirect = webtorrent::ShouldRedirectRequest( - orig_response_headers.get(), request_info); - EXPECT_TRUE(will_redirect); -} - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, - OctetStreamMimeTypeRedirectWithTorrentURL) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - orig_response_headers->AddHeader("Content-Type", kOctetStreamMimeType); - std::string mimeType; - ASSERT_TRUE(orig_response_headers->GetMimeType(&mimeType)); - ASSERT_EQ(mimeType, kOctetStreamMimeType); - - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = std::make_shared(torrent_url()); - request_info->resource_type = blink::mojom::ResourceType::kMainFrame; - - auto will_redirect = webtorrent::ShouldRedirectRequest( - orig_response_headers.get(), request_info); - EXPECT_TRUE(will_redirect); -} - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, - OctetStreamMimeTypeRedirectWithTorrentFileName) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - orig_response_headers->AddHeader("Content-Type", kOctetStreamMimeType); - std::string mimeType; - ASSERT_TRUE(orig_response_headers->GetMimeType(&mimeType)); - ASSERT_EQ(mimeType, kOctetStreamMimeType); - orig_response_headers->AddHeader("Content-Disposition", - "filename=\"sintel.torrent\""); - ASSERT_TRUE(orig_response_headers->GetNormalizedHeader("Content-Disposition") - .has_value()); - - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = - std::make_shared(non_torrent_url()); - request_info->resource_type = blink::mojom::ResourceType::kMainFrame; - - auto will_redirect = webtorrent::ShouldRedirectRequest( - orig_response_headers.get(), request_info); - EXPECT_TRUE(will_redirect); -} - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, - OctetStreamMimeTypeNoRedirect) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - orig_response_headers->AddHeader("Content-Type", kOctetStreamMimeType); - std::string mime_type; - ASSERT_TRUE(orig_response_headers->GetMimeType(&mime_type)); - ASSERT_EQ(mime_type, kOctetStreamMimeType); - - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = - std::make_shared(non_torrent_url()); - request_info->resource_type = blink::mojom::ResourceType::kMainFrame; - - EXPECT_FALSE(webtorrent::ShouldRedirectRequest(orig_response_headers.get(), - request_info)); -} - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, MimeTypeNoRedirect) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - orig_response_headers->AddHeader("Content-Type", "text/html"); - std::string mime_type; - ASSERT_TRUE(orig_response_headers->GetMimeType(&mime_type)); - ASSERT_EQ(mime_type, "text/html"); - - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = std::make_shared(torrent_url()); - request_info->resource_type = blink::mojom::ResourceType::kMainFrame; - - EXPECT_FALSE(webtorrent::ShouldRedirectRequest(orig_response_headers.get(), - request_info)); -} - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, - WebtorrentInitiatedNoRedirect) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - orig_response_headers->AddHeader("Content-Type", kBittorrentMimeType); - std::string mime_type; - ASSERT_TRUE(orig_response_headers->GetMimeType(&mime_type)); - ASSERT_EQ(mime_type, kBittorrentMimeType); - - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = std::make_shared(torrent_url()); - request_info->initiator_url = torrent_extension_url(); - request_info->resource_type = blink::mojom::ResourceType::kMainFrame; - - EXPECT_FALSE(webtorrent::ShouldRedirectRequest(orig_response_headers.get(), - request_info)); -} - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, - WebtorrentInitiatedViewerURLRedirect) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - orig_response_headers->AddHeader("Content-Type", kBittorrentMimeType); - std::string mime_type; - ASSERT_TRUE(orig_response_headers->GetMimeType(&mime_type)); - ASSERT_EQ(mime_type, kBittorrentMimeType); - - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = - std::make_shared(torrent_viewer_url()); - request_info->initiator_url = torrent_extension_url(); - request_info->resource_type = blink::mojom::ResourceType::kMainFrame; - - auto will_redirect = webtorrent::ShouldRedirectRequest( - orig_response_headers.get(), request_info); - EXPECT_TRUE(will_redirect); -} - -TEST_F(BraveTorrentRedirectNetworkDelegateHelperTest, - BittorrentNonMainFrameResourceNoRedirect) { - scoped_refptr orig_response_headers = - new net::HttpResponseHeaders(std::string()); - orig_response_headers->AddHeader("Content-Type", kBittorrentMimeType); - std::string mime_type; - ASSERT_TRUE(orig_response_headers->GetMimeType(&mime_type)); - ASSERT_EQ(mime_type, kBittorrentMimeType); - - scoped_refptr overwrite_response_headers = - new net::HttpResponseHeaders(std::string()); - GURL allowed_unsafe_redirect_url; - auto request_info = std::make_shared(torrent_url()); - request_info->resource_type = blink::mojom::ResourceType::kXhr; - - EXPECT_FALSE(webtorrent::ShouldRedirectRequest(orig_response_headers.get(), - request_info)); -} diff --git a/browser/net/sources.gni b/browser/net/sources.gni index b130ae13f08..057e7989b03 100644 --- a/browser/net/sources.gni +++ b/browser/net/sources.gni @@ -3,7 +3,6 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at https://mozilla.org/MPL/2.0/. -import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//brave/components/tor/buildflags/buildflags.gni") import("//build/config/features.gni") import("//extensions/buildflags/buildflags.gni") @@ -70,7 +69,6 @@ brave_browser_net_deps = [ "//brave/components/brave_wallet/browser", "//brave/components/brave_wallet/common", "//brave/components/brave_wallet/common:mojom", - "//brave/components/brave_webtorrent/browser/buildflags", "//brave/components/constants", "//brave/components/constants:brave_service_key_helper", "//brave/components/decentralized_dns/content", @@ -108,15 +106,3 @@ brave_browser_net_deps = [ if (enable_extensions) { brave_browser_net_deps += [ "//extensions/common:common_constants" ] } - -if (enable_brave_webtorrent) { - brave_browser_net_sources += [ - "//brave/browser/net/brave_torrent_redirect_network_delegate_helper.cc", - "//brave/browser/net/brave_torrent_redirect_network_delegate_helper.h", - ] - - brave_browser_net_deps += [ - "//brave/components/brave_webtorrent/browser/", - "//extensions/browser", - ] -} diff --git a/browser/net/url_context.cc b/browser/net/url_context.cc index c01953a2bae..d239c2b4a9f 100644 --- a/browser/net/url_context.cc +++ b/browser/net/url_context.cc @@ -10,7 +10,6 @@ #include "brave/browser/brave_shields/brave_shields_web_contents_observer.h" #include "brave/components/brave_shields/content/browser/brave_shields_util.h" -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_thread.h" @@ -70,8 +69,6 @@ std::shared_ptr BraveRequestInfo::MakeCTX( ctx->resource_type = static_cast(request.resource_type); - ctx->is_webtorrent_disabled = true; - ctx->frame_tree_node_id = frame_tree_node_id; // TODO(iefremov): remove tab_url. Change tab_origin from GURL to Origin. diff --git a/browser/net/url_context.h b/browser/net/url_context.h index b1e0610d8bc..84900a2700e 100644 --- a/browser/net/url_context.h +++ b/browser/net/url_context.h @@ -86,7 +86,6 @@ struct BraveRequestInfo { bool aggressive_blocking = false; bool allow_http_upgradable_resource = false; bool allow_referrers = false; - bool is_webtorrent_disabled = false; content::FrameTreeNodeId frame_tree_node_id; uint64_t request_identifier = 0; size_t next_url_request_index = 0; diff --git a/browser/profiles/BUILD.gn b/browser/profiles/BUILD.gn index e072656b4f2..30a5fb79282 100644 --- a/browser/profiles/BUILD.gn +++ b/browser/profiles/BUILD.gn @@ -14,7 +14,6 @@ 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/tor/buildflags", diff --git a/browser/profiles/brave_profile_manager.cc b/browser/profiles/brave_profile_manager.cc index fbbd7c04d92..0df02fca004 100644 --- a/browser/profiles/brave_profile_manager.cc +++ b/browser/profiles/brave_profile_manager.cc @@ -20,7 +20,6 @@ #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" @@ -136,9 +135,6 @@ 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); diff --git a/browser/profiles/profile_util.cc b/browser/profiles/profile_util.cc index 84bf9f8ea60..086181a00b0 100644 --- a/browser/profiles/profile_util.cc +++ b/browser/profiles/profile_util.cc @@ -35,17 +35,4 @@ 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 diff --git a/browser/profiles/profile_util.h b/browser/profiles/profile_util.h index 5483ea3032b..28748378422 100644 --- a/browser/profiles/profile_util.h +++ b/browser/profiles/profile_util.h @@ -6,8 +6,6 @@ #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 { @@ -22,15 +20,6 @@ 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); diff --git a/browser/profiles/profile_util_unittest.cc b/browser/profiles/profile_util_unittest.cc index bcc3b46e895..a995b6d59f9 100644 --- a/browser/profiles/profile_util_unittest.cc +++ b/browser/profiles/profile_util_unittest.cc @@ -82,45 +82,3 @@ 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 diff --git a/browser/sources.gni b/browser/sources.gni index 7829c2b6d1c..042bfe77323 100644 --- a/browser/sources.gni +++ b/browser/sources.gni @@ -45,7 +45,6 @@ import("//brave/components/ai_rewriter/common/buildflags/buildflags.gni") import("//brave/components/brave_education/buildflags.gni") import("//brave/components/brave_vpn/common/buildflags/buildflags.gni") import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni") -import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//brave/components/commander/common/buildflags/buildflags.gni") import("//brave/components/containers/buildflags/buildflags.gni") import("//brave/components/tor/buildflags/buildflags.gni") @@ -184,7 +183,6 @@ brave_chrome_browser_deps = [ "//brave/components/brave_wallet/common:mojom", "//brave/components/brave_wallet/common:pref_names", "//brave/components/brave_wayback_machine/buildflags", - "//brave/components/brave_webtorrent/browser/buildflags", "//brave/components/commander/common/buildflags", "//brave/components/constants", "//brave/components/containers/buildflags", @@ -461,11 +459,6 @@ if (enable_extensions) { "//extensions/browser", "//extensions/common:common_constants", ] - - if (enable_brave_webtorrent) { - brave_chrome_browser_deps += - [ "//brave/components/brave_webtorrent/browser" ] - } } if (enable_brave_wayback_machine) { diff --git a/browser/tor/BUILD.gn b/browser/tor/BUILD.gn index fe26d95042d..0f7bf1fe4fc 100644 --- a/browser/tor/BUILD.gn +++ b/browser/tor/BUILD.gn @@ -33,7 +33,6 @@ source_set("impl") { ":util", "//base", "//brave/browser:browser_process", - "//brave/components/brave_webtorrent/browser/buildflags", "//brave/components/constants", "//brave/components/tor", "//brave/components/tor:common", diff --git a/browser/tor/test/BUILD.gn b/browser/tor/test/BUILD.gn index 1a30e6ce47e..f7c9a85633e 100644 --- a/browser/tor/test/BUILD.gn +++ b/browser/tor/test/BUILD.gn @@ -20,7 +20,6 @@ source_set("unit_tests") { "//base", "//base/test:test_support", "//brave/browser/tor", - "//brave/components/brave_webtorrent/browser/buildflags", "//brave/components/constants", "//brave/components/tor", "//brave/components/tor:test_support", diff --git a/browser/tor/test/tor_profile_manager_unittest.cc b/browser/tor/test/tor_profile_manager_unittest.cc index a13c0148fd2..1300d274433 100644 --- a/browser/tor/test/tor_profile_manager_unittest.cc +++ b/browser/tor/test/tor_profile_manager_unittest.cc @@ -9,7 +9,6 @@ #include "base/memory/raw_ptr.h" #include "base/test/bind.h" -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" #include "brave/components/constants/pref_names.h" #include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/media/router/media_router_feature.h" @@ -77,10 +76,6 @@ TEST_F(TorProfileManagerUnitTest, InitTorProfileUserPrefs) { EXPECT_FALSE( tor_profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)); -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) - EXPECT_FALSE(tor_profile->GetPrefs()->GetBoolean(kWebTorrentEnabled)); -#endif - // Check translate.enabled for translate bubble. EXPECT_FALSE(tor_profile->GetPrefs()->GetBoolean( translate::prefs::kOfferTranslateEnabled)); diff --git a/browser/tor/tor_profile_manager.cc b/browser/tor/tor_profile_manager.cc index 7785d97e440..84034023de9 100644 --- a/browser/tor/tor_profile_manager.cc +++ b/browser/tor/tor_profile_manager.cc @@ -249,8 +249,6 @@ void TorProfileManager::InitTorProfileUserPrefs(Profile* profile) { if (base::FeatureList::IsEnabled(net::features::kBraveTorWindowsHttpsOnly)) { pref_service->SetBoolean(prefs::kHttpsOnlyModeEnabled, true); } - // https://blog.torproject.org/bittorrent-over-tor-isnt-good-idea - pref_service->SetBoolean(kWebTorrentEnabled, false); // Disable the automatic translate bubble in Tor because we currently don't // support extensions in Tor mode and users cannot disable this through diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 4874e4c483c..573c69b258d 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -945,7 +945,6 @@ source_set("ui") { deps += [ "//brave/app/theme:brave_theme_resources", "//brave/app/theme:brave_unscaled_resources", - "//brave/components/brave_webtorrent:static_resources", "//brave/components/webcompat_reporter/browser", "//brave/components/webcompat_reporter/ui:generated_resources", ] diff --git a/browser/ui/webui/settings/DEPS b/browser/ui/webui/settings/DEPS index 9ac273c46c6..b0d976adb49 100644 --- a/browser/ui/webui/settings/DEPS +++ b/browser/ui/webui/settings/DEPS @@ -3,7 +3,6 @@ include_rules = [ "+brave/components/brave_shields/core/browser", "+brave/components/ntp_background_images/common", "+brave/components/brave_ads/core/browser/service", - "+brave/components/brave_webtorrent/grit", "+brave/components/email_aliases", "+brave/components/version_info", "+brave/components/sync/service", diff --git a/build/commands/lib/start.js b/build/commands/lib/start.js index a45a4fc6b51..50e8367e23c 100644 --- a/build/commands/lib/start.js +++ b/build/commands/lib/start.js @@ -32,9 +32,6 @@ const start = ( if (options.disable_pdfjs_extension) { braveArgs.push('--disable-pdfjs-extension') } - if (options.disable_webtorrent_extension) { - braveArgs.push('--disable-webtorrent-extension') - } if (options.ui_mode) { braveArgs.push(`--ui-mode=${options.ui_mode}`) } diff --git a/build/commands/scripts/commands.js b/build/commands/scripts/commands.js index 13de046c45b..f0ef3f8af5f 100644 --- a/build/commands/scripts/commands.js +++ b/build/commands/scripts/commands.js @@ -269,10 +269,6 @@ program 'disable loading the Brave Rewards extension', ) .option('--disable_pdfjs_extension', 'disable loading the PDFJS extension') - .option( - '--disable_webtorrent_extension', - 'disable loading the WebTorrent extension', - ) .option( '--ui_mode ', 'which built-in ui appearance mode to use', diff --git a/chromium_src/chrome/browser/extensions/DEPS b/chromium_src/chrome/browser/extensions/DEPS index 35d5cdbcf8e..df636d4fc66 100644 --- a/chromium_src/chrome/browser/extensions/DEPS +++ b/chromium_src/chrome/browser/extensions/DEPS @@ -1,5 +1,3 @@ include_rules = [ "+brave/components/brave_extension", - "+brave/components/brave_webtorrent/browser/buildflags", - "+brave/components/brave_webtorrent/grit", ] diff --git a/chromium_src/chrome/browser/extensions/chrome_component_extension_resource_manager.cc b/chromium_src/chrome/browser/extensions/chrome_component_extension_resource_manager.cc index 7086f78525e..50cbca179d9 100644 --- a/chromium_src/chrome/browser/extensions/chrome_component_extension_resource_manager.cc +++ b/chromium_src/chrome/browser/extensions/chrome_component_extension_resource_manager.cc @@ -7,26 +7,10 @@ #include "brave/components/brave_extension/grit/brave_extension_generated_map.h" #include "brave/components/brave_extension/grit/brave_extension_resources_map.h" -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" - -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#include "brave/components/brave_webtorrent/grit/brave_webtorrent_generated_map.h" -#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources_map.h" -#endif - -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#define BRAVE_WEBTORRENT_RESOURCES \ - AddComponentResourceEntries(kBraveWebtorrentResources); \ - AddComponentResourceEntries(kBraveWebtorrentGenerated); -#else -#define BRAVE_WEBTORRENT_RESOURCES -#endif #define BRAVE_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_DATA_DATA \ AddComponentResourceEntries(kBraveExtension); \ - AddComponentResourceEntries(kBraveExtensionGenerated); \ - BRAVE_WEBTORRENT_RESOURCES + AddComponentResourceEntries(kBraveExtensionGenerated); #include "src/chrome/browser/extensions/chrome_component_extension_resource_manager.cc" #undef BRAVE_CHROME_COMPONENT_EXTENSION_RESOURCE_MANAGER_DATA_DATA -#undef BRAVE_WEBTORRENT_RESOURCES diff --git a/chromium_src/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc b/chromium_src/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc index ae6a9aa0d73..05d0e2d1efe 100644 --- a/chromium_src/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc +++ b/chromium_src/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc @@ -10,17 +10,13 @@ #undef IsComponentExtensionAllowlisted #include "brave/components/brave_extension/grit/brave_extension.h" -#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h" #include "components/grit/brave_components_resources.h" #include "extensions/common/constants.h" namespace extensions { bool IsComponentExtensionAllowlisted(const std::string& extension_id) { - const char* const kAllowed[] = { - brave_extension_id, - brave_webtorrent_extension_id - }; + const char* const kAllowed[] = {brave_extension_id}; for (const auto* id : kAllowed) { if (extension_id == id) { @@ -35,7 +31,6 @@ namespace extensions { switch (manifest_resource_id) { // Please keep the list in alphabetical order. case IDR_BRAVE_EXTENSION: - case IDR_BRAVE_WEBTORRENT: return true; } diff --git a/chromium_src/chrome/browser/external_protocol/DEPS b/chromium_src/chrome/browser/external_protocol/DEPS deleted file mode 100644 index 0efe795a5a8..00000000000 --- a/chromium_src/chrome/browser/external_protocol/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+brave/components/brave_webtorrent/browser", -] diff --git a/chromium_src/chrome/browser/external_protocol/external_protocol_handler.cc b/chromium_src/chrome/browser/external_protocol/external_protocol_handler.cc deleted file mode 100644 index 0324b1901a2..00000000000 --- a/chromium_src/chrome/browser/external_protocol/external_protocol_handler.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. - -#include - -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" -#include "chrome/browser/external_protocol/external_protocol_handler.h" - -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#include "brave/components/brave_webtorrent/browser/magnet_protocol_handler.h" -#endif // BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) - -#define LaunchUrl LaunchUrl_ChromiumImpl - -#include "src/chrome/browser/external_protocol/external_protocol_handler.cc" - -#undef LaunchUrl - -// static -void ExternalProtocolHandler::LaunchUrl( - const GURL& url, - content::WebContents::Getter web_contents_getter, - ui::PageTransition page_transition, - bool has_user_gesture, - bool is_in_fenced_frame_tree, - const std::optional& initiating_origin, - content::WeakDocumentPtr initiator_document -#if BUILDFLAG(IS_ANDROID) - , - mojo::PendingRemote* out_factory -#endif -) { -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) - if (webtorrent::HandleMagnetProtocol( - url, web_contents_getter, page_transition, has_user_gesture, - is_in_fenced_frame_tree, initiating_origin, initiator_document)) { - return; - } -#endif - - LaunchUrl_ChromiumImpl(url, web_contents_getter, page_transition, - has_user_gesture, is_in_fenced_frame_tree, - initiating_origin, initiator_document -#if BUILDFLAG(IS_ANDROID) - , - out_factory -#endif - ); -} diff --git a/chromium_src/chrome/browser/external_protocol/external_protocol_handler.h b/chromium_src/chrome/browser/external_protocol/external_protocol_handler.h deleted file mode 100644 index 51db600d50c..00000000000 --- a/chromium_src/chrome/browser/external_protocol/external_protocol_handler.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. - -#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_ -#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_ - -#define LaunchUrl(...) \ - LaunchUrl_ChromiumImpl(__VA_ARGS__); \ - static void LaunchUrl(__VA_ARGS__) - -#include "src/chrome/browser/external_protocol/external_protocol_handler.h" // IWYU pragma: export - -#undef LaunchUrl - -#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_ diff --git a/chromium_src/chrome/browser/ui/BUILD.gn b/chromium_src/chrome/browser/ui/BUILD.gn index e139d286a0e..2e8f4da077c 100644 --- a/chromium_src/chrome/browser/ui/BUILD.gn +++ b/chromium_src/chrome/browser/ui/BUILD.gn @@ -3,7 +3,6 @@ # 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/. -import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//build/config/ui.gni") group("ui") { @@ -21,8 +20,4 @@ group("ui") { "//brave/components/sidebar/browser", ] } - - if (enable_brave_webtorrent) { - deps += [ "//brave/components/brave_webtorrent/browser" ] - } } diff --git a/chromium_src/chrome/browser/ui/DEPS b/chromium_src/chrome/browser/ui/DEPS index 08d804d25cc..7ba8438663d 100644 --- a/chromium_src/chrome/browser/ui/DEPS +++ b/chromium_src/chrome/browser/ui/DEPS @@ -5,5 +5,4 @@ include_rules += [ "+brave/components/vector_icons", "+brave/components/commander/common", "+brave/components/constants", - "+brave/components/brave_webtorrent/browser", ] diff --git a/chromium_src/chrome/browser/ui/browser_tabrestore.cc b/chromium_src/chrome/browser/ui/browser_tabrestore.cc deleted file mode 100644 index 4e15a149d4a..00000000000 --- a/chromium_src/chrome/browser/ui/browser_tabrestore.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (c) 2020 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 - -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" -#include "chrome/browser/ui/browser_tabrestore.h" - -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#include "brave/browser/extensions/brave_component_loader.h" -#include "brave/browser/extensions/brave_webtorrent_navigation_throttle.h" -#include "brave/components/brave_webtorrent/browser/webtorrent_util.h" -#include "chrome/browser/extensions/extension_service.h" -#include "extensions/browser/extension_system.h" -#endif - -#define AddRestoredTab AddRestoredTab_ChromiumImpl -#include "src/chrome/browser/ui/browser_tabrestore.cc" -#undef AddRestoredTab - -namespace { - -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -void MaybeLoadWebtorrent(Browser* browser, - bool from_session_restore, - const GURL& restore_url) { - if (!from_session_restore || !webtorrent::IsWebtorrentURL(restore_url)) - return; - - extensions::BraveWebTorrentNavigationThrottle::MaybeLoadWebtorrent( - browser->profile(), restore_url); -} -#endif - -} // namespace - -namespace chrome { - -WebContents* AddRestoredTab( - Browser* browser, - const std::vector& navigations, - int tab_index, - int selected_navigation, - const std::string& extension_app_id, - std::optional group, - bool select, - bool pin, - base::TimeTicks last_active_time_ticks, - base::Time last_active_time, - content::SessionStorageNamespace* session_storage_namespace, - const sessions::SerializedUserAgentOverride& user_agent_override, - const std::map& extra_data, - bool from_session_restore, - std::optional is_active_browser) { -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) - MaybeLoadWebtorrent( - browser, - from_session_restore, - navigations.at(selected_navigation).original_request_url()); -#endif - - return AddRestoredTab_ChromiumImpl( - browser, navigations, tab_index, selected_navigation, extension_app_id, - group, select, pin, last_active_time_ticks, last_active_time, - session_storage_namespace, user_agent_override, extra_data, - from_session_restore, is_active_browser); -} - -} // namespace chrome diff --git a/chromium_src/chrome/browser/ui/views/page_info/DEPS b/chromium_src/chrome/browser/ui/views/page_info/DEPS deleted file mode 100644 index 0efe795a5a8..00000000000 --- a/chromium_src/chrome/browser/ui/views/page_info/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+brave/components/brave_webtorrent/browser", -] diff --git a/chromium_src/chrome/browser/ui/views/page_info/page_info_bubble_view.cc b/chromium_src/chrome/browser/ui/views/page_info/page_info_bubble_view.cc deleted file mode 100644 index b605afa3102..00000000000 --- a/chromium_src/chrome/browser/ui/views/page_info/page_info_bubble_view.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. - -#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" -#include "components/grit/brave_components_strings.h" -#include "components/page_info/page_info.h" -#include "content/public/common/url_constants.h" - -#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#include "brave/components/brave_webtorrent/browser/magnet_protocol_handler.h" - -// Show the InternalPageInfoBubbleView when viewing a page with the webtorrent -// scheme. -#define IsFileOrInternalPage(url) \ - IsFileOrInternalPage(url) || url.SchemeIs(url::kWebTorrentScheme) - -// Set the text for the InternalPageInfoBubbleView on webtorrent: pages. -#define kFileScheme kWebTorrentScheme)) { \ - text = IDS_PAGE_INFO_BRAVE_WEBTORRENT; \ - } \ - else if (url.SchemeIs(url::kFileScheme - -#endif - -#include "src/chrome/browser/ui/views/page_info/page_info_bubble_view.cc" - -#undef kFileScheme -#undef IsFileOrInternalPage diff --git a/chromium_src/extensions/common/constants.h b/chromium_src/extensions/common/constants.h index 34d619df2bd..10d54802305 100644 --- a/chromium_src/extensions/common/constants.h +++ b/chromium_src/extensions/common/constants.h @@ -14,13 +14,6 @@ inline constexpr char brave_extension_id[] = "mnojpmjdmbbfmejpflffifhffcmidifd"; inline constexpr char crl_set_extension_id[] = "hfnkpimlhhgieaddgfemjhofmfblmnib"; -inline constexpr char brave_webtorrent_extension_id[] = - "lgjmpdmojkpocjcopdikifhejkkjglho"; -inline constexpr char brave_webtorrent_extension_filename[] = - "brave_webtorrent.html"; -inline constexpr char brave_webtorrent_extension_filename2[] = - "brave_webtorrent2.html"; - inline constexpr char google_translate_extension_id[] = "aapbdbdomjkkjkaonfhkkikfgjllcleb"; diff --git a/components/brave_webtorrent/BUILD.gn b/components/brave_webtorrent/BUILD.gn deleted file mode 100644 index ae5cfd04e44..00000000000 --- a/components/brave_webtorrent/BUILD.gn +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (c) 2018 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 https://mozilla.org/MPL/2.0/. - -import("//brave/components/common/typescript.gni") -import("//brave/resources/brave_grit.gni") -import("//tools/grit/repack.gni") - -assert(!is_android && !is_ios) - -brave_grit("static_resources") { - source = "resources.grd" - outputs = [ - "grit/brave_webtorrent_resources_map.cc", - "grit/brave_webtorrent_resources_map.h", - "grit/brave_webtorrent_resources.h", - "brave_webtorrent_static.pak", - ] -} - -pack_web_resources("generated_resources") { - resource_name = "brave_webtorrent" - output_dir = "$root_gen_dir/brave/components/brave_webtorrent" - - # Need wepack and GRD generation first - deps = [ "extension:generate_brave_webtorrent" ] -} - -repack("resources") { - deps = [ - ":generated_resources", - ":static_resources", - ] - sources = [ - "$root_gen_dir/brave/components/brave_webtorrent/brave_webtorrent_generated.pak", - "$root_gen_dir/brave/components/brave_webtorrent/brave_webtorrent_static.pak", - ] - - # This output repacked by brave_paks.gni - output = "$root_gen_dir/brave/components/brave_webtorrent/brave_webtorrent_resources.pak" -} diff --git a/components/brave_webtorrent/browser/BUILD.gn b/components/brave_webtorrent/browser/BUILD.gn deleted file mode 100644 index 4c6154a93ae..00000000000 --- a/components/brave_webtorrent/browser/BUILD.gn +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) 2018 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 https://mozilla.org/MPL/2.0/. - -import("//extensions/buildflags/buildflags.gni") - -assert(enable_extensions) - -static_library("browser") { - sources = [ - "magnet_protocol_handler.cc", - "magnet_protocol_handler.h", - "webtorrent_util.cc", - "webtorrent_util.h", - ] - - deps = [ - "//base", - "//brave/components/constants", - "//components/pref_registry", - "//components/prefs", - "//content/public/browser", - "//extensions/browser", - "//extensions/buildflags", - "//extensions/common", - "//net", - ] - - public_deps = [ "buildflags" ] -} diff --git a/components/brave_webtorrent/browser/buildflags/BUILD.gn b/components/brave_webtorrent/browser/buildflags/BUILD.gn deleted file mode 100644 index 50288d8bf07..00000000000 --- a/components/brave_webtorrent/browser/buildflags/BUILD.gn +++ /dev/null @@ -1,10 +0,0 @@ -import("//build/buildflag_header.gni") -import("buildflags.gni") - -buildflag_header("buildflags") { - header = "buildflags.h" - flags = [ - "ENABLE_BRAVE_WEBTORRENT=$enable_brave_webtorrent", - ] -} - diff --git a/components/brave_webtorrent/browser/buildflags/buildflags.gni b/components/brave_webtorrent/browser/buildflags/buildflags.gni deleted file mode 100644 index d351bcb8caf..00000000000 --- a/components/brave_webtorrent/browser/buildflags/buildflags.gni +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright (c) 2025 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 https://mozilla.org/MPL/2.0/. - -import("//extensions/buildflags/buildflags.gni") - -declare_args() { - enable_brave_webtorrent = false -} diff --git a/components/brave_webtorrent/browser/magnet_protocol_handler.cc b/components/brave_webtorrent/browser/magnet_protocol_handler.cc deleted file mode 100644 index 2a24563af6d..00000000000 --- a/components/brave_webtorrent/browser/magnet_protocol_handler.cc +++ /dev/null @@ -1,159 +0,0 @@ -/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ - -#include "brave/components/brave_webtorrent/browser/magnet_protocol_handler.h" - -#include -#include -#include - -#include "base/check.h" -#include "base/metrics/histogram_macros.h" -#include "base/strings/escape.h" -#include "base/strings/strcat.h" -#include "base/strings/string_util.h" -#include "brave/components/brave_webtorrent/browser/webtorrent_util.h" -#include "brave/components/constants/url_constants.h" -#include "content/public/browser/browser_task_traits.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/weak_document_ptr.h" -#include "extensions/browser/extension_registry.h" -#include "extensions/common/constants.h" -#include "ui/base/page_transition_types.h" - -namespace webtorrent { - -namespace { - -constexpr char kWebtorrentUsageHistogramName[] = "Brave.WebTorrent.UsageWeekly"; - -bool IsMagnetProtocol(const GURL& url) { - return url.SchemeIs(kMagnetScheme); -} - -void LoadMagnetURL(const GURL& url, - content::WebContents::Getter web_contents_getter, - ui::PageTransition page_transition, - bool has_user_gesture, - bool is_in_fenced_frame_tree, - const std::optional& initiating_origin, - content::WeakDocumentPtr initiator_document) { - content::WebContents* web_contents = web_contents_getter.Run(); - if (!web_contents) { - return; - } - - DCHECK(IsMagnetProtocol(url)); - DCHECK(IsWebtorrentEnabled(web_contents->GetBrowserContext())); - page_transition = ui::PageTransitionIsMainFrame(page_transition) - ? page_transition - : ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL; - web_contents->GetController().LoadURL(url, content::Referrer(), - page_transition, std::string()); -} - -} // namespace - -GURL TranslateMagnetURL(const GURL& url) { - GURL extension_page_url(base::StrCat( - {extensions::kExtensionScheme, "://", brave_webtorrent_extension_id, - "/extension/brave_webtorrent.html?%s"})); - std::string translatedSpec(extension_page_url.spec()); - base::ReplaceFirstSubstringAfterOffset( - &translatedSpec, 0, "%s", base::EscapeQueryParamValue(url.spec(), true)); - return GURL(translatedSpec); -} - -GURL TranslateTorrentUIURLReversed(const GURL& url) { - GURL translated_url(base::UnescapeURLComponent( - url.query(), - base::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | - base::UnescapeRule::PATH_SEPARATORS)); - GURL::Replacements replacements; - replacements.SetRefStr(url.ref_piece()); - return GURL( - base::StrCat({url::kWebTorrentScheme, ":", - translated_url.ReplaceComponents(replacements).spec()})); -} - -bool HandleTorrentURLReverseRewrite(GURL* url, - content::BrowserContext* browser_context) { - if (url->SchemeIs(extensions::kExtensionScheme) && - url->host() == brave_webtorrent_extension_id && - url->ExtractFileName() == "brave_webtorrent.html" && - GURL(url->query()).SchemeIsHTTPOrHTTPS()) { - *url = TranslateTorrentUIURLReversed(*url); - return true; - } - - return false; -} - -bool HandleTorrentURLRewrite(GURL* url, - content::BrowserContext* browser_context) { - if (!IsWebtorrentEnabled(browser_context)) { - return false; - } - - // The HTTP/HTTPS URL could be modified later by the network delegate if the - // mime type matches or .torrent is in the path. - // Handle http and https here for making reverse_on_redirect to be true in - // BrowserURLHandlerImpl::RewriteURLIfNecessary to trigger ReverseURLRewrite - // for updating the virtual URL. - if (url->SchemeIsHTTPOrHTTPS() || - (url->SchemeIs(extensions::kExtensionScheme) && - url->host() == brave_webtorrent_extension_id && - url->ExtractFileName() == "brave_webtorrent.html" && - GURL(url->query()).SchemeIsHTTPOrHTTPS())) { - return true; - } - - return false; -} - -bool HandleMagnetURLRewrite(GURL* url, - content::BrowserContext* browser_context) { - if (IsWebtorrentEnabled(browser_context) && IsMagnetProtocol(*url)) { - *url = TranslateMagnetURL(*url); - return true; - } - - return false; -} - -bool HandleMagnetProtocol(const GURL& url, - content::WebContents::Getter web_contents_getter, - ui::PageTransition page_transition, - bool has_user_gesture, - bool is_in_fenced_frame_tree, - const std::optional& initiating_origin, - content::WeakDocumentPtr initiator_document) { - if (!IsMagnetProtocol(url)) { - return false; - } - - // Handle subframe magnet links only if a user gesture is present. - if (!ui::PageTransitionIsMainFrame(page_transition) && !has_user_gesture) { - return false; - } - - content::WebContents* web_contents = web_contents_getter.Run(); - if (!web_contents || - !IsWebtorrentEnabled(web_contents->GetBrowserContext())) { - return false; - } - - UMA_HISTOGRAM_BOOLEAN(kWebtorrentUsageHistogramName, true); - - content::GetUIThreadTaskRunner({})->PostTask( - FROM_HERE, - base::BindOnce(&LoadMagnetURL, url, web_contents_getter, page_transition, - has_user_gesture, is_in_fenced_frame_tree, - initiating_origin, std::move(initiator_document))); - return true; -} - -} // namespace webtorrent diff --git a/components/brave_webtorrent/browser/magnet_protocol_handler.h b/components/brave_webtorrent/browser/magnet_protocol_handler.h deleted file mode 100644 index 9154d510467..00000000000 --- a/components/brave_webtorrent/browser/magnet_protocol_handler.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_BRAVE_WEBTORRENT_BROWSER_MAGNET_PROTOCOL_HANDLER_H_ -#define BRAVE_COMPONENTS_BRAVE_WEBTORRENT_BROWSER_MAGNET_PROTOCOL_HANDLER_H_ - -#include - -#include "brave/components/brave_webtorrent/browser/webtorrent_util.h" -#include "content/public/browser/weak_document_ptr.h" -#include "content/public/browser/web_contents.h" -#include "ui/base/page_transition_types.h" - -// Define this variable in the url namespace to make patching easier. -namespace url { - -inline constexpr char kWebTorrentScheme[] = "webtorrent"; - -} // namespace url - -namespace webtorrent { - -GURL TranslateMagnetURL(const GURL& url); - -GURL TranslateTorrentUIURLReversed(const GURL& url); -bool HandleTorrentURLReverseRewrite(GURL* url, - content::BrowserContext* browser_context); - -bool HandleTorrentURLRewrite(GURL* url, - content::BrowserContext* browser_context); -bool HandleMagnetURLRewrite(GURL* url, - content::BrowserContext* browser_context); - -bool HandleMagnetProtocol(const GURL& url, - content::WebContents::Getter web_contents_getter, - ui::PageTransition page_transition, - bool has_user_gesture, - bool is_in_fenced_frame_tree, - const std::optional& initiating_origin, - content::WeakDocumentPtr initiator_document); - -} // namespace webtorrent - -#endif // BRAVE_COMPONENTS_BRAVE_WEBTORRENT_BROWSER_MAGNET_PROTOCOL_HANDLER_H_ diff --git a/components/brave_webtorrent/browser/webtorrent_util.cc b/components/brave_webtorrent/browser/webtorrent_util.cc deleted file mode 100644 index 4d56e70c3b9..00000000000 --- a/components/brave_webtorrent/browser/webtorrent_util.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* 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/components/brave_webtorrent/browser/webtorrent_util.h" - -#include - -#include "base/strings/string_util.h" -#include "brave/components/constants/network_constants.h" -#include "brave/components/constants/pref_names.h" -#include "components/pref_registry/pref_registry_syncable.h" -#include "components/prefs/pref_service.h" -#include "extensions/browser/extension_registry.h" -#include "extensions/common/constants.h" -#include "net/http/http_content_disposition.h" -#include "net/http/http_response_headers.h" - -namespace webtorrent { - -bool TorrentFileNameMatched(const net::HttpResponseHeaders* headers) { - std::optional disposition = - headers->GetNormalizedHeader("Content-Disposition"); - if (!disposition) { - return false; - } - - net::HttpContentDisposition cd_headers(*disposition, std::string()); - if (base::EndsWith(cd_headers.filename(), ".torrent", - base::CompareCase::INSENSITIVE_ASCII) || - base::EndsWith(cd_headers.filename(), ".torrent\"", - base::CompareCase::INSENSITIVE_ASCII)) { - return true; - } - - return false; -} - -bool TorrentURLMatched(const GURL& url) { - return base::EndsWith(url.path(), ".torrent", - base::CompareCase::INSENSITIVE_ASCII); -} - -bool IsWebtorrentEnabled(content::BrowserContext* browser_context) { - extensions::ExtensionRegistry* registry = - extensions::ExtensionRegistry::Get(browser_context); - if (!registry) { - return false; - } - return registry->enabled_extensions().Contains(brave_webtorrent_extension_id); -} - -void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { - registry->RegisterBooleanPref(kWebTorrentEnabled, true); -} - -bool IsWebtorrentURL(const GURL& url) { - if (url.SchemeIs(extensions::kExtensionScheme) && - url.host() == brave_webtorrent_extension_id && - (url.ExtractFileName() == brave_webtorrent_extension_filename || - url.ExtractFileName() == brave_webtorrent_extension_filename2)) { - return true; - } - - return false; -} - -bool IsTorrentFile(const GURL& url, const net::HttpResponseHeaders* headers) { - if (!headers) { - return false; - } - - std::string mimeType; - if (!headers->GetMimeType(&mimeType)) { - return false; - } - - if (mimeType == kBittorrentMimeType) { - return true; - } - - if (mimeType == kOctetStreamMimeType && - (TorrentURLMatched(url) || TorrentFileNameMatched(headers))) { - return true; - } - - return false; -} - -} // namespace webtorrent diff --git a/components/brave_webtorrent/browser/webtorrent_util.h b/components/brave_webtorrent/browser/webtorrent_util.h deleted file mode 100644 index 8278e959b34..00000000000 --- a/components/brave_webtorrent/browser/webtorrent_util.h +++ /dev/null @@ -1,33 +0,0 @@ -/* 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 https://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_BRAVE_WEBTORRENT_BROWSER_WEBTORRENT_UTIL_H_ -#define BRAVE_COMPONENTS_BRAVE_WEBTORRENT_BROWSER_WEBTORRENT_UTIL_H_ - -class GURL; - -namespace content { -class BrowserContext; -} - -namespace user_prefs { -class PrefRegistrySyncable; -} - -namespace net { -class HttpResponseHeaders; -} - -namespace webtorrent { - -bool IsWebtorrentEnabled(content::BrowserContext* browser_context); -void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); -bool IsWebtorrentURL(const GURL& url); -bool IsTorrentFile(const GURL& url, const net::HttpResponseHeaders* headers); -bool TorrentURLMatched(const GURL& url); - -} // namespace webtorrent - -#endif // BRAVE_COMPONENTS_BRAVE_WEBTORRENT_BROWSER_WEBTORRENT_UTIL_H_ diff --git a/components/brave_webtorrent/extension/BUILD.gn b/components/brave_webtorrent/extension/BUILD.gn deleted file mode 100644 index 20cf91a48aa..00000000000 --- a/components/brave_webtorrent/extension/BUILD.gn +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2018 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 https://mozilla.org/MPL/2.0/. - -import("//brave/components/common/typescript.gni") - -transpile_web_ui("generate_brave_webtorrent") { - entry_points = [ - [ - "brave_webtorrent", - rebase_path("brave_webtorrent.tsx"), - ], - [ - "brave_webtorrent_background", - rebase_path("background.ts"), - ], - ] - - # For explanation of "chromeapp", see: - # https://github.com/brave/brave-browser/issues/5587 - webpack_aliases = [ "chromeapp" ] - resource_name = "brave_webtorrent" - - # Must match the relative path from the static GRD to the manifest.json - # plus any other relative path we want these files to live in the extension - resource_path_prefix = "brave_webtorrent/extension/out" - - public_asset_path = "/extension/out/" -} diff --git a/components/brave_webtorrent/extension/actions/tab_actions.ts b/components/brave_webtorrent/extension/actions/tab_actions.ts deleted file mode 100644 index ab9c2cb5788..00000000000 --- a/components/brave_webtorrent/extension/actions/tab_actions.ts +++ /dev/null @@ -1,22 +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 https://mozilla.org/MPL/2.0/. */ - -import { action } from 'typesafe-actions' - -// Constants -import { types } from '../constants/tab_types' - -export const tabUpdated = (tabId: number, - changeInfo: { url: string }) => - action(types.TAB_UPDATED, { - tabId, changeInfo - }) - -export const tabRemoved = (tabId: number) => action(types.TAB_REMOVED, { - tabId -}) - -export const tabRetrieved = (tab: chrome.tabs.Tab) => action(types.TAB_RETRIEVED, { - tab -}) diff --git a/components/brave_webtorrent/extension/actions/webtorrent_actions.ts b/components/brave_webtorrent/extension/actions/webtorrent_actions.ts deleted file mode 100644 index 6ec8bbe6b7b..00000000000 --- a/components/brave_webtorrent/extension/actions/webtorrent_actions.ts +++ /dev/null @@ -1,19 +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 https://mozilla.org/MPL/2.0/. */ - -import { action } from 'typesafe-actions' -import { Torrent } from 'webtorrent' -import { Instance } from 'parse-torrent' - -// Constants -import { types } from '../constants/webtorrent_types' - -export const progressUpdated = (torrent: Torrent) => action(types.WEBTORRENT_PROGRESS_UPDATED, { torrent }) -export const infoUpdated = (torrent: Torrent) => action(types.WEBTORRENT_INFO_UPDATED, { torrent }) -export const serverUpdated = (torrent: Torrent, serverURL: string) => - action(types.WEBTORRENT_SERVER_UPDATED, { torrent, serverURL }) -export const startTorrent = (torrentId: string, tabId: number) => action(types.WEBTORRENT_START_TORRENT, { torrentId, tabId }) -export const stopDownload = (tabId: number) => action(types.WEBTORRENT_STOP_DOWNLOAD, { tabId }) -export const torrentParsed = (torrentId: string, tabId: number, infoHash: string | undefined, errorMsg: string | undefined, parsedTorrent?: Instance) => action(types.WEBTORRENT_TORRENT_PARSED, { torrentId, tabId, infoHash, errorMsg, parsedTorrent }) -export const saveAllFiles = (infoHash: string) => action(types.WEBTORRENT_SAVE_ALL_FILES, { infoHash }) diff --git a/components/brave_webtorrent/extension/assets/images/webtorrent-logotype.svg b/components/brave_webtorrent/extension/assets/images/webtorrent-logotype.svg deleted file mode 100644 index ecb35f7d3bf..00000000000 --- a/components/brave_webtorrent/extension/assets/images/webtorrent-logotype.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/brave_webtorrent/extension/assets/locale.ts b/components/brave_webtorrent/extension/assets/locale.ts deleted file mode 100644 index bc5295944f1..00000000000 --- a/components/brave_webtorrent/extension/assets/locale.ts +++ /dev/null @@ -1,12 +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 https://mozilla.org/MPL/2.0/. */ - -const locale = { - startDownload: 'Start download', - stopDownload: 'Stop download', - saveTorrentFile: 'Save .torrent file', - startTorrentIntro: 'Click "Start Torrent" to begin your download.' -} - -export default locale diff --git a/components/brave_webtorrent/extension/background.ts b/components/brave_webtorrent/extension/background.ts deleted file mode 100644 index 109661bcdee..00000000000 --- a/components/brave_webtorrent/extension/background.ts +++ /dev/null @@ -1,8 +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 https://mozilla.org/MPL/2.0/. */ - -import './background/events/webtorrentEvents' -import './background/events/torrentEvents' -import './background/events/tabsEvents' -import './background/store' diff --git a/components/brave_webtorrent/extension/background/actions/tabActions.ts b/components/brave_webtorrent/extension/background/actions/tabActions.ts deleted file mode 100644 index 8a9131c2674..00000000000 --- a/components/brave_webtorrent/extension/background/actions/tabActions.ts +++ /dev/null @@ -1,8 +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 https://mozilla.org/MPL/2.0/. */ - -import { bindActionCreators } from 'redux' -import store from '../store' -import * as tabActions from '../../actions/tab_actions' -export default bindActionCreators(tabActions, store.dispatch) diff --git a/components/brave_webtorrent/extension/background/actions/webtorrentActions.ts b/components/brave_webtorrent/extension/background/actions/webtorrentActions.ts deleted file mode 100644 index ed24b1dbf7d..00000000000 --- a/components/brave_webtorrent/extension/background/actions/webtorrentActions.ts +++ /dev/null @@ -1,8 +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 https://mozilla.org/MPL/2.0/. */ - -import { bindActionCreators } from 'redux' -import store from '../store' -import * as webtorrentActions from '../../actions/webtorrent_actions' -export default bindActionCreators(webtorrentActions, store.dispatch) diff --git a/components/brave_webtorrent/extension/background/api/torrent_api.ts b/components/brave_webtorrent/extension/background/api/torrent_api.ts deleted file mode 100644 index bb8c0215e02..00000000000 --- a/components/brave_webtorrent/extension/background/api/torrent_api.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. - -import * as ParseTorrent from 'parse-torrent' - -export const parseTorrentRemote = (torrentId: string, tabId: number) => { - ParseTorrent.remote( - torrentId, - (err: Error, parsedTorrent?: ParseTorrent.Instance) => { - const webtorrentActions = require('../actions/webtorrentActions').default - const errMsg = err ? err.message : undefined - const infoHash = parsedTorrent ? parsedTorrent.infoHash : undefined - webtorrentActions.torrentParsed( - torrentId, - tabId, - infoHash, - errMsg, - parsedTorrent - ) - } - ) -} diff --git a/components/brave_webtorrent/extension/background/events/tabsEvents.ts b/components/brave_webtorrent/extension/background/events/tabsEvents.ts deleted file mode 100644 index 71cb86d60fa..00000000000 --- a/components/brave_webtorrent/extension/background/events/tabsEvents.ts +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. - -import tabActions from '../actions/tabActions' - -// On initialization, make sure we tell WebTorrent about all existing tabs. This -// fixes a bug where WebTorrent wouldn't load for the first click of magnet -// links (as the background page would not be running on that first load). -// Note: Empty query for {} returns all tabs this extension is interested in. -chrome.tabs.query({}, tabs => { - if (chrome.runtime.lastError) { - console.error('Error querying tabs: ', chrome.runtime.lastError); - return; - } - - for (const tab of tabs) { - tabActions.tabUpdated(tab.id!, { url: tab.url ?? '' }) - } -}) - -chrome.webNavigation.onCommitted.addListener( - (details: chrome.webNavigation.WebNavigationFramedCallbackDetails) => { - tabActions.tabUpdated(details.tabId, details) - }, - { - url: [ - { pathSuffix: '.torrent' }, - // have a magnet scheme - { schemes: ['magnet'] }] - } - ) - -chrome.webNavigation.onCommitted.addListener( - (details: chrome.webNavigation.WebNavigationFramedCallbackDetails) => { - // navigation events come in with the webtorrent extension as - // the schema/host, the actual webtorrent URL appended to it - // after the chrome-extenion://extension-id/view.html? - // delete everything up to the first question mark - let original = details.url.replace(new RegExp(/^[^\?]*\?/), '') - let decoded = decodeURIComponent(original) - details.url = decoded - tabActions.tabUpdated(details.tabId, details) - }, - { - url: [ - // when handling URLs as chrome-extension://... - // the actual torrent URL is within query parameters - { schemes: ['chrome-extension'], queryContains: '.torrent' }, - { schemes: ['chrome-extension'], queryContains: 'magnet%3A' }] - } -) - -chrome.tabs.onRemoved.addListener( - (tabId: number, removeInfo: chrome.tabs.TabRemoveInfo) => { - tabActions.tabRemoved(tabId) - } -) diff --git a/components/brave_webtorrent/extension/background/events/torrentEvents.ts b/components/brave_webtorrent/extension/background/events/torrentEvents.ts deleted file mode 100644 index 6e170e82727..00000000000 --- a/components/brave_webtorrent/extension/background/events/torrentEvents.ts +++ /dev/null @@ -1,45 +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 https://mozilla.org/MPL/2.0/. */ - -import { Torrent } from 'webtorrent' -import * as throttle from 'throttleit' - -import webtorrentActions from '../actions/webtorrentActions' -import { createServer } from '../webtorrent' - -interface TorrentExtended extends Torrent { - progressInterval?: number -} - -export const addTorrentEvents = (torrent: TorrentExtended) => { - torrent.on('warning', (e: Error) => console.log('warning: ', torrent, e)) - torrent.on('error', (e: Error) => console.log('error: ', torrent, e)) - - torrent.on('ready', () => { - createServer(torrent, (serverURL: string) => { - webtorrentActions.serverUpdated(torrent, serverURL) - }) - }) - - torrent.on('infoHash', () => webtorrentActions.infoUpdated(torrent)) - torrent.on('metadata', () => webtorrentActions.infoUpdated(torrent)) - - const progressUpdatedThrottled = throttle((bytes: number) => { - webtorrentActions.progressUpdated(torrent) - }, 500) - - torrent.on('download', progressUpdatedThrottled) - torrent.on('upload', progressUpdatedThrottled) - torrent.on('done', progressUpdatedThrottled) - torrent.on('wire', progressUpdatedThrottled) - - // Always update stats at least once every 5 seconds, even when no torrent - // events fire. Ensures that download/upload speeds do not get stuck on a - // positive value when the transfer stalls. - torrent.progressInterval = window.setInterval(progressUpdatedThrottled, 5000) -} - -export const removeTorrentEvents = (torrent: TorrentExtended) => { - window.clearInterval(torrent.progressInterval) -} diff --git a/components/brave_webtorrent/extension/background/events/webtorrentEvents.ts b/components/brave_webtorrent/extension/background/events/webtorrentEvents.ts deleted file mode 100644 index 31c754f49a2..00000000000 --- a/components/brave_webtorrent/extension/background/events/webtorrentEvents.ts +++ /dev/null @@ -1,11 +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 https://mozilla.org/MPL/2.0/. */ - -import { Instance } from 'webtorrent' - -export const addWebtorrentEvents = (webtorrent: Instance) => { - webtorrent.on('error', (e: Error) => { - console.log('WebTorrent error: ', e) - }) -} diff --git a/components/brave_webtorrent/extension/background/reducers/index.ts b/components/brave_webtorrent/extension/background/reducers/index.ts deleted file mode 100644 index 4d332c2f36b..00000000000 --- a/components/brave_webtorrent/extension/background/reducers/index.ts +++ /dev/null @@ -1,13 +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 https://mozilla.org/MPL/2.0/. */ - -import { combineReducers } from 'redux' - -// Utils -import { webtorrentReducer } from './webtorrent_reducer' -import { ApplicationState } from '../../constants/webtorrentState' - -export default combineReducers({ - torrentsData: webtorrentReducer -}) diff --git a/components/brave_webtorrent/extension/background/reducers/webtorrent_reducer.ts b/components/brave_webtorrent/extension/background/reducers/webtorrent_reducer.ts deleted file mode 100644 index 203fb971cb2..00000000000 --- a/components/brave_webtorrent/extension/background/reducers/webtorrent_reducer.ts +++ /dev/null @@ -1,327 +0,0 @@ -// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. - -import * as ParseTorrent from 'parse-torrent' -import { Torrent } from 'webtorrent' -import { parse } from 'querystring' - -// Constants -import * as tabTypes from '../../constants/tab_types' -import * as torrentTypes from '../../constants/webtorrent_types' -import { - File, - TorrentState, - TorrentStateMap, - TorrentsState -} from '../../constants/webtorrentState' - -// Utils -import { - addTorrent, - delTorrent, - findTorrent, - saveAllFiles as webtorrentSaveAllFiles -} from '../webtorrent' -import { parseTorrentRemote } from '../api/torrent_api' - -const tabUpdated = (tabId: number, url: string, state: TorrentsState) => { - const { torrentStateMap, torrentObjMap } = state - const origTorrentState: TorrentState = torrentStateMap[tabId] - const origInfoHash = origTorrentState ? origTorrentState.infoHash : undefined - let newTorrentState: TorrentState | undefined - let newInfoHash: string | undefined - - // create new torrent state - const parsedURL = new window.URL(url) - const torrentId = parsedURL.href - if (parsedURL.protocol === 'magnet:') { - // parse torrent - try { - const { name, infoHash, ix } = ParseTorrent(torrentId) - newInfoHash = infoHash - newTorrentState = { tabId, torrentId, name, infoHash, ix } - } catch (error) { - newTorrentState = { tabId, torrentId, errorMsg: error.message } - } - } else if ( - parsedURL.protocol === 'https:' || - parsedURL.protocol === 'http:' - ) { - const name = parsedURL.pathname.substr( - parsedURL.pathname.lastIndexOf('/') + 1 - ) - // for .torrent case, ix (index of file) for selecting a specific file in - // the file list is given in url like #ix=5 - let ix: number | undefined = Number(parse(parsedURL.hash.slice(1)).ix) - ix = Number.isNaN(ix) ? undefined : ix - - // Use an existing infoHash if it's the same torrentId - const torrentUrl = parsedURL.origin + parsedURL.pathname - const key = (Object.keys(torrentStateMap) as unknown as Array).find( - (key) => - torrentStateMap[key].infoHash && - torrentStateMap[key].torrentId === torrentUrl - ) - newInfoHash = key ? torrentStateMap[key].infoHash : undefined - - newTorrentState = { tabId, torrentId, name, ix, infoHash: newInfoHash } - } - - // delete old torrent state - delete torrentStateMap[tabId] - - // unsubscribe old torrent if not the same - const isSameTorrent = newInfoHash && origInfoHash === newInfoHash - if (origInfoHash && torrentObjMap[origInfoHash] && !isSameTorrent) { - torrentObjMap[origInfoHash].tabClients.delete(tabId) - if (!torrentObjMap[origInfoHash].tabClients.size) { - delete torrentObjMap[origInfoHash] - delTorrent(origInfoHash) - } - } - - // save new torrent state and subscribe directly if torrent already existed - if (newTorrentState) { - torrentStateMap[tabId] = newTorrentState - if (newInfoHash && torrentObjMap[newInfoHash]) { - torrentObjMap[newInfoHash].tabClients.add(tabId) - } - } - - return { ...state, torrentStateMap, torrentObjMap } -} - -const tabRemoved = (tabId: number, state: TorrentsState) => { - const { torrentStateMap, torrentObjMap } = state - const torrentState = torrentStateMap[tabId] - if (torrentState) { - const infoHash = torrentState.infoHash - if (infoHash && torrentObjMap[infoHash]) { - // unsubscribe - if (torrentObjMap[infoHash].tabClients) { - torrentObjMap[infoHash].tabClients.delete(tabId) - } - if (!torrentObjMap[infoHash].tabClients.size) { - delete torrentObjMap[infoHash] - delTorrent(infoHash) - } - } - delete torrentStateMap[tabId] - } - - return { ...state, torrentStateMap, torrentObjMap } -} - -const startTorrent = ( - torrentId: string, - tabId: number, - state: TorrentsState -) => { - const { torrentStateMap, torrentObjMap } = state - const torrentState = torrentStateMap[tabId] - - // infoHash might not be available yet for .torrent case - if (torrentState && !torrentState.errorMsg && !torrentState.infoHash) { - parseTorrentRemote(torrentId, tabId) - } - - if ( - torrentState && - torrentState.infoHash && - !findTorrent(torrentState.infoHash) - ) { - addTorrent(torrentId) // objectMap will be updated when info event is emitted - } else if ( - torrentState && - torrentState.infoHash && - torrentObjMap[torrentState.infoHash] - ) { - torrentObjMap[torrentState.infoHash].tabClients.add(tabId) - } - - return { ...state, torrentObjMap } -} - -const stopDownload = (tabId: number, state: TorrentsState) => { - const { torrentStateMap, torrentObjMap } = state - const infoHash = torrentStateMap[tabId].infoHash - - if (infoHash && torrentObjMap[infoHash]) { - delete torrentObjMap[infoHash] - delTorrent(infoHash) - } - - return { ...state, torrentStateMap, torrentObjMap } -} - -const updateProgress = (state: TorrentsState, torrent: Torrent) => { - const { torrentObjMap } = state - // don't add a new entry since the download might be stopped already - if (!torrentObjMap[torrent.infoHash]) { - return state - } - - const { - downloaded, - uploaded, - downloadSpeed, - uploadSpeed, - progress, - ratio, - numPeers, - timeRemaining - } = torrent - torrentObjMap[torrent.infoHash] = { - ...torrentObjMap[torrent.infoHash], - downloaded, - uploaded, - downloadSpeed, - uploadSpeed, - progress, - ratio, - numPeers, - timeRemaining - } - - return { ...state, torrentObjMap } -} - -const updateInfo = (state: TorrentsState, torrent: Torrent) => { - const { torrentStateMap, torrentObjMap } = state - const { - name, - downloaded, - uploaded, - downloadSpeed, - uploadSpeed, - progress, - ratio, - numPeers, - timeRemaining, - infoHash - } = torrent - let length: number = 0 - const files: File[] = torrent.files.map((file) => { - length += file.length - return { name: file.name, length: file.length, path: file.path } - }) - - const tabClients: Set = new Set() - ; (Object.keys(torrentStateMap) as unknown as Array) - .filter((key) => torrentStateMap[key].infoHash === infoHash) - .map((key) => { - tabClients.add(torrentStateMap[key].tabId) - }) - - torrentObjMap[torrent.infoHash] = { - ...torrentObjMap[torrent.infoHash], - files, - name, - downloaded, - uploaded, - downloadSpeed, - uploadSpeed, - progress, - ratio, - numPeers, - timeRemaining, - length, - tabClients - } - - return { ...state, torrentStateMap, torrentObjMap } -} - -const updateServer = ( - state: TorrentsState, - torrent: Torrent, - serverURL: string -) => { - const { torrentObjMap } = state - torrentObjMap[torrent.infoHash] = { - ...torrentObjMap[torrent.infoHash], - serverURL - } - return { ...state, torrentObjMap } -} - -const torrentParsed = ( - torrentId: string, - tabId: number, - infoHash: string | undefined, - errorMsg: string | undefined, - parsedTorrent: ParseTorrent.Instance | undefined, - state: TorrentsState -) => { - const { torrentObjMap, torrentStateMap } = state - torrentStateMap[tabId] = { ...torrentStateMap[tabId], infoHash, errorMsg } - - if (infoHash && !findTorrent(infoHash) && parsedTorrent) { - addTorrent(parsedTorrent) // objectMap will be updated when info event is emitted - } else if (infoHash && torrentObjMap[infoHash]) { - torrentObjMap[infoHash].tabClients.add(tabId) - } - - return { ...state, torrentObjMap, torrentStateMap } -} - -const saveAllFiles = (state: TorrentsState, infoHash: string) => { - webtorrentSaveAllFiles(infoHash) - return { ...state } -} - -const defaultState: TorrentsState = { torrentStateMap: {}, torrentObjMap: {} } -export const webtorrentReducer = ( - state: TorrentsState = defaultState, - action: any -) => { - // TODO: modify any to be actual action type - const payload = action.payload - switch (action.type) { - case tabTypes.types.TAB_UPDATED: - if (payload.changeInfo.url) { - state = tabUpdated(payload.tabId, payload.changeInfo.url, state) - } - break - case tabTypes.types.TAB_REMOVED: - state = tabRemoved(payload.tabId, state) - break - case tabTypes.types.TAB_RETRIEVED: - if (payload.tab.id && payload.tab.url) { - state = tabUpdated(payload.tab.id, payload.tab.url, state) - } - break - case torrentTypes.types.WEBTORRENT_PROGRESS_UPDATED: - state = updateProgress(state, payload.torrent) - break - case torrentTypes.types.WEBTORRENT_INFO_UPDATED: - state = updateInfo(state, payload.torrent) - break - case torrentTypes.types.WEBTORRENT_SERVER_UPDATED: - state = updateServer(state, payload.torrent, payload.serverURL) - break - case torrentTypes.types.WEBTORRENT_START_TORRENT: - state = startTorrent(payload.torrentId, payload.tabId, state) - break - case torrentTypes.types.WEBTORRENT_STOP_DOWNLOAD: - state = stopDownload(payload.tabId, state) - break - case torrentTypes.types.WEBTORRENT_TORRENT_PARSED: - state = torrentParsed( - payload.torrentId, - payload.tabId, - payload.infoHash, - payload.errorMsg, - payload.parsedTorrent, - state - ) - break - case torrentTypes.types.WEBTORRENT_SAVE_ALL_FILES: - state = saveAllFiles(state, payload.infoHash) - break - } - - return state -} diff --git a/components/brave_webtorrent/extension/background/store.ts b/components/brave_webtorrent/extension/background/store.ts deleted file mode 100644 index 88212456b90..00000000000 --- a/components/brave_webtorrent/extension/background/store.ts +++ /dev/null @@ -1,16 +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 https://mozilla.org/MPL/2.0/. */ - -import { createStore } from 'redux' -import { wrapStore } from 'webext-redux' - -import reducers from './reducers' - -const store = createStore(reducers) - -wrapStore(store, { - portName: 'WEBTORRENT' -}) - -export default store diff --git a/components/brave_webtorrent/extension/background/webtorrent.ts b/components/brave_webtorrent/extension/background/webtorrent.ts deleted file mode 100644 index f2effb580b3..00000000000 --- a/components/brave_webtorrent/extension/background/webtorrent.ts +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. - -const WebTorrent = require('webtorrent') -import type * as TWebTorrent from 'webtorrent' -import { addTorrentEvents, removeTorrentEvents } from './events/torrentEvents' -import { addWebtorrentEvents } from './events/webtorrentEvents' -import { AddressInfo } from 'net' -import { Instance } from 'parse-torrent' -import { basename, extname } from 'path' -import * as JSZip from 'jszip' - -let webTorrent: TWebTorrent.Instance | undefined -let servers: { [key: string]: any } = {} - -export const getWebTorrent = (): TWebTorrent.Instance => { - if (!webTorrent) { - webTorrent = new WebTorrent({ tracker: { wrtc: false } }) - addWebtorrentEvents(webTorrent!) - } - - return webTorrent! -} - -export const createServer = ( - torrent: TWebTorrent.Torrent, - cb: (serverURL: string) => void -) => { - if (!torrent.infoHash) return // torrent is not ready - - const opts = { - // Only allow requests from this origin ('chrome-extension://...) so - // websites cannot violate same-origin policy by reading contents of - // active torrents. - origin: window.location.origin, - // Use hostname option to mitigate DNS rebinding - // Ref: https://github.com/brave/browser-laptop/issues/12616 - hostname: '127.0.0.1' - } - const server = torrent.createServer(opts) - if (!server) return - - try { - server.listen(0, '127.0.0.1', undefined, () => { - // Explicitly cast server.address() to AddressInfo to access its - // properties. It's safe to cast here because the only possible type of - // server.address() here is AddressInfo since pipe name (as string) is - // not supported in chrome-net. - const addrInfo = server.address() as AddressInfo - servers[torrent.infoHash] = server - cb('http://' + addrInfo.address + ':' + addrInfo.port.toString()) - }) - } catch (error) { - console.log('server listen error: ', error) - } -} - -export const addTorrent = (torrentId: string | Instance) => { - const client = getWebTorrent() - const torrent = client.add(torrentId) - addTorrentEvents(torrent) -} - -export const findTorrent = (infoHash: string) => { - return getWebTorrent().torrents.find( - (torrent) => torrent.infoHash === infoHash - ) -} - -const maybeDestroyWebTorrent = () => { - if (!webTorrent || webTorrent.torrents.length !== 0) return - webTorrent.destroy() - webTorrent = undefined -} - -export const delTorrent = (infoHash: string) => { - const torrent = findTorrent(infoHash) - if (torrent) { - removeTorrentEvents(torrent) - torrent.destroy() - } - - if (servers[infoHash]) { - servers[infoHash].close() - delete servers[infoHash] - } - - maybeDestroyWebTorrent() -} - -export const saveAllFiles = (infoHash: string) => { - const torrent = findTorrent(infoHash) - - if (!torrent || !torrent.name || !torrent.files) return - - const files: TWebTorrent.TorrentFile[] = torrent.files - - let zip: any = new JSZip() - const zipFilename = basename(torrent.name, extname(torrent.name)) + '.zip' - - const downloadBlob = (blob: Blob) => { - const url = URL.createObjectURL(blob) - - chrome.downloads.download({ - url: url, - filename: zipFilename, - saveAs: false, - conflictAction: 'uniquify' - }) - } - - const downloadZip = () => { - if (files.length > 1) { - // generate the zip relative to the torrent folder - zip = zip.folder(torrent.name) - } - - zip.generateAsync({ type: 'blob' }).then( - (blob: Blob) => downloadBlob(blob), - (err: Error) => console.error(err) - ) - } - - const addFilesToZip = () => { - let addedFiles = 0 - - files.forEach((file) => { - file.getBlob((err, blob) => { - if (err) { - console.error(err) - } else { - // add file to zip - zip.file(file.path, blob) - } - - addedFiles += 1 - - // start the download when all files have been added - if (addedFiles === files.length) { - downloadZip() - } - }) - }) - } - - addFilesToZip() -} diff --git a/components/brave_webtorrent/extension/brave_webtorrent.html b/components/brave_webtorrent/extension/brave_webtorrent.html deleted file mode 100644 index 27d8423946d..00000000000 --- a/components/brave_webtorrent/extension/brave_webtorrent.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - WebTorrent - - - -
- - diff --git a/components/brave_webtorrent/extension/brave_webtorrent.tsx b/components/brave_webtorrent/extension/brave_webtorrent.tsx deleted file mode 100644 index ebaa862452e..00000000000 --- a/components/brave_webtorrent/extension/brave_webtorrent.tsx +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. - -import * as React from 'react' -import { render } from 'react-dom' -import { Provider } from 'react-redux' -import { Store } from 'webext-redux' - -import Theme from 'brave-ui/theme/brave-default' -import { createGlobalStyle, ThemeProvider } from 'styled-components' - -// Components -import App from './components/app' - -// Constants -import { ApplicationState } from './constants/webtorrentState' - -import '$web-components/app.global.scss' - -// This is a hack that's needed for lazy loading -// Basically we need the browser to restart the navigation, so we redirect first -// to brave_webtorrent2.html and have that rewrite the URL to -// brave_webtorrent.html -if (window.location.pathname === '/extension/brave_webtorrent2.html') { - window.location.href = window.location.href.replace( - 'brave_webtorrent2.html', - 'brave_webtorrent.html' - ) -} - -const GlobalStyle = createGlobalStyle` - body { - background: var(--background2); - } -` - -const store: Store = new Store({ - portName: 'WEBTORRENT' -}) - -// This pattern is described in the webext-redux docs. When the proxy store is -// ready, it doesn't necessarily have a value (and might be {}). If we want -// the same store value as the background page, we should wait for the first -// update and unsubscribe. -// https://github.com/tshaddix/webext-redux/wiki/Advanced-Usage#initializing-ui-components -const unsubscribe = store.subscribe(async () => { - unsubscribe() - - try { - const tab: any = await new Promise((resolve) => - chrome.tabs.getCurrent(resolve) - ) - - render( - - - - - - , - document.getElementById('root') - ) - } catch (err) { - console.log('Problem mounting webtorrent', err) - } -}) diff --git a/components/brave_webtorrent/extension/brave_webtorrent2.html b/components/brave_webtorrent/extension/brave_webtorrent2.html deleted file mode 100644 index 27d8423946d..00000000000 --- a/components/brave_webtorrent/extension/brave_webtorrent2.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - WebTorrent - - - -
- - diff --git a/components/brave_webtorrent/extension/components/app.tsx b/components/brave_webtorrent/extension/components/app.tsx deleted file mode 100644 index 4db7c042cee..00000000000 --- a/components/brave_webtorrent/extension/components/app.tsx +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. - -import * as React from 'react' -import { bindActionCreators, Dispatch } from 'redux' -import { connect } from 'react-redux' - -// Components -import MediaViewer from './mediaViewer' -import TorrentViewer from './torrentViewer' - -// Constants -import { - TorrentObj, - TorrentState, - ApplicationState, - getTorrentObj, - getTorrentState -} from '../constants/webtorrentState' - -// Utils -import * as torrentActions from '../actions/webtorrent_actions' - -interface Props { - torrentState: TorrentState - torrentObj?: TorrentObj - actions: any -} - -// Exported for tests. -export function BraveWebTorrentPage({ - actions, - torrentState, - torrentObj -}: Props) { - const name = torrentObj?.name ?? torrentState?.name - React.useEffect(() => { - document.title = name ? `${name} - WebTorrent` : 'WebTorrent' - }, [name]) - - if (!torrentState) return null - - if ( - torrentObj && - typeof torrentState.ix === 'number' && - torrentState.infoHash - ) { - return ( - - ) - } - - return ( - - ) -} - -export const mapStateToProps = ( - state: ApplicationState, - ownProps: { tabId: number } -) => { - return { - torrentState: getTorrentState(state.torrentsData, ownProps.tabId), - torrentObj: getTorrentObj(state.torrentsData, ownProps.tabId) - } -} - -export const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators(torrentActions, dispatch) -}) - -export default connect(mapStateToProps, mapDispatchToProps)(BraveWebTorrentPage) diff --git a/components/brave_webtorrent/extension/components/header.tsx b/components/brave_webtorrent/extension/components/header.tsx deleted file mode 100644 index 285006e8642..00000000000 --- a/components/brave_webtorrent/extension/components/header.tsx +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2022 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 https://mozilla.org/MPL/2.0/. - -import styled from 'styled-components' - -export const Header = styled.h2` - all: unset; - font-weight: 600; - font-size: 24px; - color: var(--text2); -` diff --git a/components/brave_webtorrent/extension/components/link.tsx b/components/brave_webtorrent/extension/components/link.tsx deleted file mode 100644 index 2d9d06ad933..00000000000 --- a/components/brave_webtorrent/extension/components/link.tsx +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2022 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 https://mozilla.org/MPL/2.0/. - -import styled, { css } from 'styled-components' - -export const Link = styled('a')<{ inactive?: boolean }>` - text-decoration: none; - color: var(--interactive2); - - ${p => p.inactive && css` - color: var(--text3); - :hover { - cursor: default; - } - `} -` diff --git a/components/brave_webtorrent/extension/components/mediaViewer.tsx b/components/brave_webtorrent/extension/components/mediaViewer.tsx deleted file mode 100644 index 374815dd4db..00000000000 --- a/components/brave_webtorrent/extension/components/mediaViewer.tsx +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. - -import * as React from 'react' -import styled from 'styled-components' - -// Constants -import { TorrentObj } from '../constants/webtorrentState' -import { getFileType, isMedia } from '../utils/fileType' -import Spinner from './spinner' - -const getSelectedFile = (torrent: TorrentObj, ix: number) => torrent.files?.[ix] - -const Container = styled.div` - video, - audio, - image-rendering, - object, - iframe, - img { - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 0; - max-height: 100%; - max-width: 100%; - margin: auto; - } - - object, - iframe { - width: 100%; - height: 100%; - } - - iframe { - border: 0; - } -` - -const LoadingContainer = styled.div` - color: var(--text3); - margin-top: 40px; - display: flex; - gap: 8px; - justify-content: center; - align-items: center; - width: 100%; -` - -interface Props { - torrent: TorrentObj - ix: number -} - -const playMedia = (element: HTMLMediaElement) => - element.play().catch((err) => console.error('Autoplay failed', err)) -const setMediaElementRef = (element: HTMLMediaElement | null) => { - if (!element) return - if (element.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) { - playMedia(element) - return - } - element.addEventListener('loadeddata', () => playMedia(element), { - once: true - }) -} - -export default function MediaViewer({ torrent, ix }: Props) { - const file = getSelectedFile(torrent, ix) - const fileType = getFileType(file) - const fileURL = torrent.serverURL && torrent.serverURL + '/' + ix - const loading = !file || !fileURL - - React.useEffect(() => { - document.body.style.backgroundColor = isMedia(fileType) - ? 'rgb(0, 0, 0)' - : '' - - // Reset background color when unmounted. - return () => { - document.body.style.backgroundColor = '' - } - }, [fileType]) - - return ( - - {loading ? ( - - - Loading media... - - ) : ( - <> - {fileType === 'video' && ( -