From 2f755b008529776daa51d383a7375e4b68e4b53d Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Wed, 21 Aug 2019 18:40:06 -0700 Subject: [PATCH] Disable translate pref in Tor profile. --- browser/profiles/BUILD.gn | 2 ++ browser/profiles/brave_profile_manager.cc | 8 ++++++++ .../profiles/brave_profile_manager_unittest.cc | 16 +++++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/browser/profiles/BUILD.gn b/browser/profiles/BUILD.gn index 41d2b04ee18e..32a82129ed5c 100644 --- a/browser/profiles/BUILD.gn +++ b/browser/profiles/BUILD.gn @@ -8,11 +8,13 @@ source_set("profiles") { deps = [ "//base", "//brave/browser/tor", + "//brave/browser/translate/buildflags", "//brave/common/tor", "//brave/components/brave_ads/browser", "//brave/components/brave_rewards/browser", "//brave/content:browser", "//chrome/common", + "//components/translate/core/browser", "//content/public/common", "//ui/base", ] diff --git a/browser/profiles/brave_profile_manager.cc b/browser/profiles/brave_profile_manager.cc index 422fe3ba85b7..44beb69314d1 100644 --- a/browser/profiles/brave_profile_manager.cc +++ b/browser/profiles/brave_profile_manager.cc @@ -13,6 +13,7 @@ #include "brave/browser/tor/buildflags.h" #include "brave/browser/tor/tor_profile_service.h" #include "brave/browser/tor/tor_profile_service_factory.h" +#include "brave/browser/translate/buildflags/buildflags.h" #include "brave/common/pref_names.h" #include "brave/common/tor/pref_names.h" #include "brave/common/tor/tor_constants.h" @@ -31,6 +32,7 @@ #include "components/prefs/pref_service.h" #include "components/safe_browsing/common/safe_browsing_prefs.h" #include "components/signin/core/browser/signin_pref_names.h" +#include "components/translate/core/browser/translate_pref_names.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/url_data_source.h" #include "content/public/common/webrtc_ip_handling_policy.h" @@ -66,6 +68,12 @@ void BraveProfileManager::InitTorProfileUserPrefs(Profile* profile) { // https://blog.torproject.org/bittorrent-over-tor-isnt-good-idea #if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) pref_service->SetBoolean(kWebTorrentEnabled, false); +#endif + // Disable the automatic translate bubble in Tor because we currently don't + // support extensions in Tor mode and users cannot disable this through + // settings page for Tor windows. +#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE_EXTENSION) + pref_service->SetBoolean(prefs::kOfferTranslateEnabled, false); #endif } diff --git a/browser/profiles/brave_profile_manager_unittest.cc b/browser/profiles/brave_profile_manager_unittest.cc index b3260c3f5ee3..0cb3404ec65a 100644 --- a/browser/profiles/brave_profile_manager_unittest.cc +++ b/browser/profiles/brave_profile_manager_unittest.cc @@ -13,6 +13,7 @@ #include "base/strings/utf_string_conversions.h" #include "brave/browser/profiles/tor_unittest_profile_manager.h" #include "brave/browser/tor/tor_launcher_factory.h" +#include "brave/browser/translate/buildflags/buildflags.h" #include "brave/common/tor/pref_names.h" #include "brave/common/tor/tor_constants.h" #include "brave/components/brave_webtorrent/browser/webtorrent_util.h" @@ -29,6 +30,7 @@ #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "components/safe_browsing/common/safe_browsing_prefs.h" +#include "components/translate/core/browser/translate_pref_names.h" #include "content/public/common/webrtc_ip_handling_policy.h" #include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_utils.h" @@ -142,19 +144,23 @@ TEST_F(BraveProfileManagerTest, InitProfileUserPrefs) { tor_profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); EXPECT_EQ(avatar_index, size_t(0)); EXPECT_FALSE( - tor_profile->GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName)); + tor_profile->GetPrefs()->GetBoolean(prefs::kProfileUsingDefaultName)); EXPECT_FALSE(profile->GetPrefs()->GetBoolean(tor::prefs::kProfileUsingTor)); EXPECT_TRUE( - tor_profile->GetPrefs()->GetBoolean(tor::prefs::kProfileUsingTor)); + tor_profile->GetPrefs()->GetBoolean(tor::prefs::kProfileUsingTor)); // Check WebRTC IP handling policy. EXPECT_EQ( - tor_profile->GetPrefs()->GetString(prefs::kWebRTCIPHandlingPolicy), - content::kWebRTCIPHandlingDisableNonProxiedUdp); + tor_profile->GetPrefs()->GetString(prefs::kWebRTCIPHandlingPolicy), + content::kWebRTCIPHandlingDisableNonProxiedUdp); // Check SafeBrowsing status EXPECT_FALSE( - tor_profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)); + tor_profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)); + + // Check translate.enabled for translate bubble. + EXPECT_FALSE( + tor_profile->GetPrefs()->GetBoolean(prefs::kOfferTranslateEnabled)); } // This is for tor guest window, remove it when we have persistent tor profiles