Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Unified Diff: ios/web_view/internal/translate/cwv_translation_controller.mm

Issue 2983453002: Expose way to enable/disable translate. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web_view/internal/translate/cwv_translation_controller.mm
diff --git a/ios/web_view/internal/translate/cwv_translation_controller.mm b/ios/web_view/internal/translate/cwv_translation_controller.mm
index 17ed9e99831dac924f91ad294a7bd0d3526293d2..26c2df5564829cae7dce1438f99e6f1241a67607 100644
--- a/ios/web_view/internal/translate/cwv_translation_controller.mm
+++ b/ios/web_view/internal/translate/cwv_translation_controller.mm
@@ -11,6 +11,7 @@
#include "base/strings/sys_string_conversions.h"
#include "components/translate/core/browser/translate_download_manager.h"
#include "components/translate/core/browser/translate_manager.h"
+#include "components/translate/core/browser/translate_pref_names.h"
#import "ios/web_view/internal/cwv_web_view_configuration_internal.h"
#include "ios/web_view/internal/pref_names.h"
#import "ios/web_view/internal/translate/cwv_translation_language_internal.h"
@@ -79,6 +80,22 @@ const NSInteger CWVTranslationErrorScriptLoadError =
translatePrefs.ResetToDefaults();
}
++ (BOOL)isTranslateEnabled {
+ CWVWebViewConfiguration* configuration =
+ [CWVWebViewConfiguration defaultConfiguration];
+ PrefService* prefService = configuration.browserState->GetPrefs();
+ translate::TranslatePrefs translatePrefs(prefService, prefs::kAcceptLanguages,
+ nullptr);
+ return translatePrefs.IsEnabled();
+}
+
++ (void)setTranslateEnabled:(BOOL)enabled {
+ CWVWebViewConfiguration* configuration =
+ [CWVWebViewConfiguration defaultConfiguration];
+ PrefService* prefService = configuration.browserState->GetPrefs();
+ prefService->SetBoolean(prefs::kEnableTranslate, enabled);
+}
+
#pragma mark - Internal Methods
- (void)setWebState:(web::WebState*)webState {
« no previous file with comments | « no previous file | ios/web_view/public/cwv_translation_controller.h » ('j') | ios/web_view/public/cwv_translation_controller.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698