diff --git a/app/brave_main_delegate.cc b/app/brave_main_delegate.cc index a65fd6aaf779..fefd01ef52c1 100644 --- a/app/brave_main_delegate.cc +++ b/app/brave_main_delegate.cc @@ -15,6 +15,7 @@ #include "build/build_config.h" #include "brave/app/brave_command_line_helper.h" #include "brave/browser/brave_content_browser_client.h" +#include "brave/browser/translate/buildflags/buildflags.h" #include "brave/common/brave_switches.h" #include "brave/common/resource_bundle_helper.h" #include "brave/components/brave_ads/browser/buildflags/buildflags.h" @@ -28,6 +29,7 @@ #include "components/autofill/core/common/autofill_payments_features.h" #include "components/omnibox/common/omnibox_features.h" #include "components/password_manager/core/common/password_manager_features.h" +#include "components/translate/core/browser/translate_prefs.h" #include "components/unified_consent/feature.h" #include "extensions/common/extension_features.h" #include "services/network/public/cpp/features.h" @@ -149,11 +151,12 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) { autofill::features::kAutofillServerCommunication.name, network::features::kNetworkService.name, unified_consent::kUnifiedConsent.name, +#if !BUILDFLAG(ENABLE_BRAVE_TRANSLATE) + translate::kTranslateUI.name, +#endif }; - command_line.AppendFeatures(enabled_features, disabled_features); - bool ret = ChromeMainDelegate::BasicStartupComplete(exit_code); #if BUILDFLAG(BUNDLE_WIDEVINE_CDM) diff --git a/browser/BUILD.gn b/browser/BUILD.gn index 9f859e4bc03a..e398f4982d4d 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -87,6 +87,7 @@ source_set("browser_process") { "ui", "//base", "//brave/browser/tor", + "//brave/browser/translate/buildflags", "//brave/common", "//brave/components/brave_ads/browser", "//brave/components/brave_component_updater/browser", diff --git a/browser/net/BUILD.gn b/browser/net/BUILD.gn index 4d8fda981b6b..efe1963b2cb4 100644 --- a/browser/net/BUILD.gn +++ b/browser/net/BUILD.gn @@ -1,4 +1,5 @@ import("//brave/browser/tor/buildflags/buildflags.gni") +import("//brave/browser/translate/buildflags/buildflags.gni") import("//brave/components/brave_webtorrent/browser/buildflags/buildflags.gni") import("//build/config/features.gni") @@ -23,8 +24,6 @@ source_set("net") { "brave_static_redirect_network_delegate_helper.h", "brave_system_network_delegate.cc", "brave_system_network_delegate.h", - "brave_translate_redirect_network_delegate_helper.cc", - "brave_translate_redirect_network_delegate_helper.h", "url_context.cc", "url_context.h", ] @@ -56,4 +55,11 @@ source_set("net") { "//brave/components/brave_webtorrent/browser/net", ] } + + if (enable_brave_translate) { + sources += [ + "brave_translate_redirect_network_delegate_helper.cc", + "brave_translate_redirect_network_delegate_helper.h", + ] + } } diff --git a/browser/net/brave_profile_network_delegate.cc b/browser/net/brave_profile_network_delegate.cc index 833e35106f80..a73ede548d42 100644 --- a/browser/net/brave_profile_network_delegate.cc +++ b/browser/net/brave_profile_network_delegate.cc @@ -10,8 +10,8 @@ #include "brave/browser/net/cookie_network_delegate_helper.h" #include "brave/browser/net/brave_httpse_network_delegate_helper.h" #include "brave/browser/net/brave_site_hacks_network_delegate_helper.h" -#include "brave/browser/net/brave_translate_redirect_network_delegate_helper.h" #include "brave/browser/tor/buildflags.h" +#include "brave/browser/translate/buildflags/buildflags.h" #include "brave/common/pref_names.h" #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" #include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h" @@ -30,6 +30,10 @@ #include "brave/components/brave_webtorrent/browser/net/brave_torrent_redirect_network_delegate_helper.h" #endif +#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE) +#include "brave/browser/net/brave_translate_redirect_network_delegate_helper.h" +#endif + BraveProfileNetworkDelegate::BraveProfileNetworkDelegate( extensions::EventRouterForwarder* event_router) : BraveNetworkDelegateBase(event_router) { @@ -60,9 +64,11 @@ BraveProfileNetworkDelegate::BraveProfileNetworkDelegate( before_url_request_callbacks_.push_back(callback); #endif +#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE) callback = base::BindRepeating( brave::OnBeforeURLRequest_TranslateRedirectWork); before_url_request_callbacks_.push_back(callback); +#endif brave::OnBeforeStartTransactionCallback start_transaction_callback = base::Bind(brave::OnBeforeStartTransaction_SiteHacksWork); diff --git a/browser/net/brave_static_redirect_network_delegate_helper.cc b/browser/net/brave_static_redirect_network_delegate_helper.cc index ab1d8bf6e05e..9cb5936c6a09 100644 --- a/browser/net/brave_static_redirect_network_delegate_helper.cc +++ b/browser/net/brave_static_redirect_network_delegate_helper.cc @@ -8,6 +8,7 @@ #include #include +#include "brave/browser/translate/buildflags/buildflags.h" #include "brave/common/network_constants.h" #include "brave/common/translate_network_constants.h" #include "extensions/common/url_pattern.h" @@ -33,11 +34,12 @@ int OnBeforeURLRequest_StaticRedirectWork( URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kCRLSetPrefix4); static URLPattern crxDownload_pattern( URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kCRXDownloadPrefix); +#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE) static URLPattern translate_pattern(URLPattern::SCHEME_HTTPS, kTranslateElementJSPattern); static URLPattern translate_language_pattern(URLPattern::SCHEME_HTTPS, kTranslateLanguagePattern); - +#endif if (geo_pattern.MatchesURL(ctx->request_url)) { ctx->new_url_spec = GURL(GOOGLEAPIS_ENDPOINT GOOGLEAPIS_API_KEY).spec(); return net::OK; @@ -89,7 +91,7 @@ int OnBeforeURLRequest_StaticRedirectWork( ctx->new_url_spec = ctx->request_url.ReplaceComponents(replacements).spec(); return net::OK; } - +#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE) if (translate_pattern.MatchesURL(ctx->request_url)) { replacements.SetQueryStr(ctx->request_url.query_piece()); replacements.SetPathStr(ctx->request_url.path_piece()); @@ -102,6 +104,7 @@ int OnBeforeURLRequest_StaticRedirectWork( ctx->new_url_spec = GURL(kBraveTranslateLanguageEndpoint).spec(); return net::OK; } +#endif #if !defined(NDEBUG) GURL gurl = ctx->request_url; diff --git a/browser/net/brave_static_redirect_network_delegate_helper_unittest.cc b/browser/net/brave_static_redirect_network_delegate_helper_unittest.cc index ae7feb696e02..f92cc89fe6f8 100644 --- a/browser/net/brave_static_redirect_network_delegate_helper_unittest.cc +++ b/browser/net/brave_static_redirect_network_delegate_helper_unittest.cc @@ -9,6 +9,7 @@ #include #include "brave/browser/net/url_context.h" +#include "brave/browser/translate/buildflags/buildflags.h" #include "brave/common/network_constants.h" #include "brave/common/translate_network_constants.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" @@ -304,6 +305,7 @@ TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, EXPECT_EQ(ret, net::OK); } +#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE) TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, RedirectTranslate) { net::TestDelegate test_delegate; std::string query_string( @@ -350,5 +352,6 @@ TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, EXPECT_EQ(before_url_context->new_url_spec, expected_url); EXPECT_EQ(ret, net::OK); } +#endif } // namespace diff --git a/browser/resources/settings/BUILD.gn b/browser/resources/settings/BUILD.gn index fdf133e91d04..354f7867f403 100644 --- a/browser/resources/settings/BUILD.gn +++ b/browser/resources/settings/BUILD.gn @@ -1,3 +1,4 @@ +import("//brave/build/config.gni") import("//chrome/browser/resources/optimize_webui.gni") import("//chrome/common/features.gni") import("//tools/grit/grit_rule.gni") @@ -5,6 +6,8 @@ import("//tools/grit/grit_rule.gni") grit("resources") { source = "settings_resources.grd" + defines = ["is_release_channel=$is_release_channel"] + source_is_generated = optimize_webui outputs = [ @@ -50,4 +53,4 @@ if (optimize_webui) { rebase_path("$target_gen_dir/${pak_file}", root_build_dir), ] } -} \ No newline at end of file +} diff --git a/browser/resources/settings/brave_settings_overrides.js b/browser/resources/settings/brave_settings_overrides.js index 66d5877e2c33..f7c0a2a35e6c 100644 --- a/browser/resources/settings/brave_settings_overrides.js +++ b/browser/resources/settings/brave_settings_overrides.js @@ -349,7 +349,16 @@ BravePatching.RegisterPolymerTemplateModifications({ console.error('[Brave Settings Overrides] Could not find manage payments link') } manageLink.remove() + }, +// + 'settings-languages-page': (templateContent) => { + const offerTranslateToggle = templateContent.querySelector('#offerTranslateOtherLanguages') + if (!offerTranslateToggle) { + console.error('[Brave Settings Overrides] Could not find offer translate toggle') + } + offerTranslateToggle.remove() } +// }) // Icons diff --git a/browser/resources/settings/settings_resources.grd b/browser/resources/settings/settings_resources.grd index 7d59c9d72bca..a996f40c6a86 100644 --- a/browser/resources/settings/settings_resources.grd +++ b/browser/resources/settings/settings_resources.grd @@ -11,7 +11,7 @@ - + diff --git a/browser/translate/buildflags/BUILD.gn b/browser/translate/buildflags/BUILD.gn new file mode 100644 index 000000000000..134847e26e7a --- /dev/null +++ b/browser/translate/buildflags/BUILD.gn @@ -0,0 +1,9 @@ +import("//build/buildflag_header.gni") +import("//brave/browser/translate/buildflags/buildflags.gni") + +buildflag_header("buildflags") { + header = "buildflags.h" + flags = [ + "ENABLE_BRAVE_TRANSLATE=$enable_brave_translate", + ] +} diff --git a/browser/translate/buildflags/buildflags.gni b/browser/translate/buildflags/buildflags.gni new file mode 100644 index 000000000000..e90affe33ce6 --- /dev/null +++ b/browser/translate/buildflags/buildflags.gni @@ -0,0 +1,6 @@ +import("//brave/build/config.gni") +import("//build/config/features.gni") + +declare_args() { + enable_brave_translate = !is_release_channel +} diff --git a/build/config.gni b/build/config.gni index 50336dfe75eb..a69a3fc4f7bf 100644 --- a/build/config.gni +++ b/build/config.gni @@ -8,7 +8,7 @@ declare_args() { # "nightly" for nightly channel release. # "" for stable channel release. brave_channel = "" - + is_release_channel = true base_sparkle_update_url = "" brave_dsa_file = "dsa_pub.pem" @@ -105,3 +105,5 @@ if (is_win) { } else if (is_linux) { brave_platform = "linux" } + +is_release_channel = brave_channel == "" diff --git a/chromium_src/chrome/browser/translate/translate_service.cc b/chromium_src/chrome/browser/translate/translate_service.cc new file mode 100644 index 000000000000..7456a35f0e85 --- /dev/null +++ b/chromium_src/chrome/browser/translate/translate_service.cc @@ -0,0 +1,17 @@ +/* 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/translate/buildflags/buildflags.h" + +namespace { +bool IsBraveTranslateEnabled() { +#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE) + return true; +#endif + return false; +} +} // namespace + +#include "../../../../../../chrome/browser/translate/translate_service.cc" // NOLINT diff --git a/patches/chrome-browser-translate-translate_service.cc.patch b/patches/chrome-browser-translate-translate_service.cc.patch new file mode 100644 index 000000000000..dd297f386b5d --- /dev/null +++ b/patches/chrome-browser-translate-translate_service.cc.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/translate/translate_service.cc b/chrome/browser/translate/translate_service.cc +index 06eacc6c808221f905aea64e33dd64a3e373bb62..22e589b8729d7f197aeac2b1c9a230b9344d24b0 100644 +--- a/chrome/browser/translate/translate_service.cc ++++ b/chrome/browser/translate/translate_service.cc +@@ -136,7 +136,7 @@ bool TranslateService::IsTranslatableURL(const GURL& url) { + // - Chrome OS file manager extension + // - an FTP page (as FTP pages tend to have long lists of filenames that may + // confuse the CLD) +- return !url.is_empty() && !url.SchemeIs(content::kChromeUIScheme) && ++ return IsBraveTranslateEnabled() && !url.is_empty() && !url.SchemeIs(content::kChromeUIScheme) && + !url.SchemeIs(content::kChromeDevToolsScheme) && + #if defined(OS_CHROMEOS) + !(url.SchemeIs(extensions::kExtensionScheme) && diff --git a/test/BUILD.gn b/test/BUILD.gn index 93f810a99ba9..d630b5df5d96 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -1,4 +1,5 @@ import("//brave/build/config.gni") +import("//brave/browser/translate/buildflags/buildflags.gni") import("//brave/components/brave_ads/browser/buildflags/buildflags.gni") import("//brave/components/brave_rewards/browser/buildflags/buildflags.gni") import("//testing/test.gni") @@ -59,7 +60,6 @@ test("brave_unit_tests") { "//brave/browser/net/brave_site_hacks_network_delegate_helper_unittest.cc", "//brave/browser/net/brave_static_redirect_network_delegate_helper_unittest.cc", "//brave/browser/net/brave_tor_network_delegate_helper_unittest.cc", - "//brave/browser/net/brave_translate_redirect_network_delegate_helper_unittest.cc", "//brave/browser/profiles/tor_unittest_profile_manager.cc", "//brave/browser/profiles/tor_unittest_profile_manager.h", "//brave/browser/profiles/brave_profile_manager_unittest.cc", @@ -145,6 +145,12 @@ test("brave_unit_tests") { ] } + if (enable_brave_translate) { + sources += [ + "//brave/browser/net/brave_translate_redirect_network_delegate_helper_unittest.cc", + ] + } + # On Windows, brave_install_static_unittests covers channel test. if (is_mac || is_linux) { sources += [