Skip to content

Commit

Permalink
Android translate (#14047)
Browse files Browse the repository at this point in the history
* Enable translate for Android

* Make kOfferTranslateEnabled unsyncable

* Update chromium_src/components/translate/core/browser/translate_manager.cc
  • Loading branch information
atuchin-m authored Jul 8, 2022
1 parent 297cc71 commit 05c4d2f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ constexpr char kRestrictWebSocketsPoolDescription[] =
{"brave-translate-go", \
flag_descriptions::kBraveTranslateGoName, \
flag_descriptions::kBraveTranslateGoDescription, \
kOsDesktop, \
kOsDesktop | kOsAndroid, \
FEATURE_VALUE_TYPE(translate::features::kUseBraveTranslateGo)},
#else
#define BRAVE_TRANSLATE_GO_FEATURE_ENTRIES
Expand Down
4 changes: 1 addition & 3 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
feed::RegisterProfilePrefs(registry);
registry->RegisterBooleanPref(feed::prefs::kEnableSnippets, false);
registry->RegisterBooleanPref(feed::prefs::kArticlesListVisible, false);
// Translate is not available on Android
registry->SetDefaultPrefValue(translate::prefs::kOfferTranslateEnabled,
base::Value(false));

// Explicitly disable safe browsing extended reporting by default in case they
// change it in upstream.
registry->SetDefaultPrefValue(prefs::kSafeBrowsingScoutReportingEnabled,
Expand Down
3 changes: 3 additions & 0 deletions browser/translate/brave_translate_prefs_migration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ void MigrateBraveProfilePrefs(PrefService* prefs) {
return; // Already migrated

prefs->SetBoolean(prefs::kMigratedToInternalTranslation, true);

// TODO(matuchin): make kOfferTranslateEnabled syncable again when the
// migration is finished.
prefs->ClearPref(prefs::kOfferTranslateEnabled);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

#include "components/translate/core/browser/translate_manager.h"

#include "brave/components/translate/core/common/brave_translate_features.h"
#include "brave/components/translate/core/common/brave_translate_language_filter.h"
#include "brave/components/translate/core/common/buildflags.h"
#include "build/build_config.h"
#include "components/translate/core/browser/translate_download_manager.h"
#include "components/translate/core/browser/translate_prefs.h"

Expand Down Expand Up @@ -46,6 +48,18 @@ void TranslateManager::FilterIsTranslatePossible(
ChromiumTranslateManager::FilterIsTranslatePossible(
decision, translate_prefs, page_language_code, target_lang);
#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE_GO)
#if BUILDFLAG(IS_ANDROID)
// Disable translate completely if brave translate feature is disabled.
// The code is Android only because desktops use TranslateManager to show
// Google translate extension bubble.
if (!IsBraveTranslateGoAvailable()) {
decision->PreventAllTriggering();
decision->initiation_statuses.push_back(
TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_SWITCH);
GetActiveTranslateMetricsLogger()->LogTriggerDecision(
TriggerDecision::kDisabledTranslationFeatureDisabled);
}
#endif
// The source language is not supported by Brave backend. Currently we allow a
// user to trigger a manual translation to have a chance to change the
// incorrectly recognized source language to the correct one.
Expand Down
14 changes: 0 additions & 14 deletions chromium_src/components/translate/core/browser/translate_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@
// chromium_src/chrome/browser/prefs/browser_prefs.cc
#include "components/translate/core/browser/translate_prefs.h"

#include "build/build_config.h"

#define MigrateObsoleteProfilePrefs MigrateObsoleteProfilePrefs_ChromiumImpl
#include "src/components/translate/core/browser/translate_prefs.cc"
#undef MigrateObsoleteProfilePrefs

#include "base/feature_override.h"

namespace translate {

OVERRIDE_FEATURE_DEFAULT_STATES({{
#if BUILDFLAG(IS_ANDROID)
{kTranslate, base::FEATURE_DISABLED_BY_DEFAULT},
#endif
}});

} // namespace translate
13 changes: 13 additions & 0 deletions patches/chrome-browser-ui-browser_ui_prefs.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/chrome/browser/ui/browser_ui_prefs.cc b/chrome/browser/ui/browser_ui_prefs.cc
index d70f76650ce3d2c380e81751f0fa039ec2894ad9..a2f87acfa34cfa6b59c2150baeb7a85af1048021 100644
--- a/chrome/browser/ui/browser_ui_prefs.cc
+++ b/chrome/browser/ui/browser_ui_prefs.cc
@@ -78,7 +78,7 @@ void RegisterBrowserUserPrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true);
registry->RegisterBooleanPref(
translate::prefs::kOfferTranslateEnabled, true,
- user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
+ user_prefs::PrefRegistrySyncable::NO_REGISTRATION_FLAGS);
registry->RegisterStringPref(prefs::kCloudPrintEmail, std::string());
registry->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, true);
registry->RegisterBooleanPref(prefs::kCloudPrintSubmitEnabled, true);

0 comments on commit 05c4d2f

Please sign in to comment.