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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/web_view/internal/translate/cwv_translation_controller_internal.h" 5 #import "ios/web_view/internal/translate/cwv_translation_controller_internal.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "components/translate/core/browser/translate_download_manager.h" 12 #include "components/translate/core/browser/translate_download_manager.h"
13 #include "components/translate/core/browser/translate_manager.h" 13 #include "components/translate/core/browser/translate_manager.h"
14 #include "components/translate/core/browser/translate_pref_names.h"
14 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" 15 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h"
15 #include "ios/web_view/internal/pref_names.h" 16 #include "ios/web_view/internal/pref_names.h"
16 #import "ios/web_view/internal/translate/cwv_translation_language_internal.h" 17 #import "ios/web_view/internal/translate/cwv_translation_language_internal.h"
17 #import "ios/web_view/internal/translate/web_view_translate_client.h" 18 #import "ios/web_view/internal/translate/web_view_translate_client.h"
18 #include "ios/web_view/internal/web_view_browser_state.h" 19 #include "ios/web_view/internal/web_view_browser_state.h"
19 #import "ios/web_view/public/cwv_translation_controller_delegate.h" 20 #import "ios/web_view/public/cwv_translation_controller_delegate.h"
20 #import "ios/web_view/public/cwv_translation_policy.h" 21 #import "ios/web_view/public/cwv_translation_policy.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 23
23 #if !defined(__has_feature) || !__has_feature(objc_arc) 24 #if !defined(__has_feature) || !__has_feature(objc_arc)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 73
73 + (void)resetTranslationPolicies { 74 + (void)resetTranslationPolicies {
74 CWVWebViewConfiguration* configuration = 75 CWVWebViewConfiguration* configuration =
75 [CWVWebViewConfiguration defaultConfiguration]; 76 [CWVWebViewConfiguration defaultConfiguration];
76 PrefService* prefService = configuration.browserState->GetPrefs(); 77 PrefService* prefService = configuration.browserState->GetPrefs();
77 translate::TranslatePrefs translatePrefs(prefService, prefs::kAcceptLanguages, 78 translate::TranslatePrefs translatePrefs(prefService, prefs::kAcceptLanguages,
78 nullptr); 79 nullptr);
79 translatePrefs.ResetToDefaults(); 80 translatePrefs.ResetToDefaults();
80 } 81 }
81 82
83 + (BOOL)isTranslateEnabled {
84 CWVWebViewConfiguration* configuration =
85 [CWVWebViewConfiguration defaultConfiguration];
86 PrefService* prefService = configuration.browserState->GetPrefs();
87 translate::TranslatePrefs translatePrefs(prefService, prefs::kAcceptLanguages,
88 nullptr);
89 return translatePrefs.IsEnabled();
90 }
91
92 + (void)setTranslateEnabled:(BOOL)enabled {
93 CWVWebViewConfiguration* configuration =
94 [CWVWebViewConfiguration defaultConfiguration];
95 PrefService* prefService = configuration.browserState->GetPrefs();
96 prefService->SetBoolean(prefs::kEnableTranslate, enabled);
97 }
98
82 #pragma mark - Internal Methods 99 #pragma mark - Internal Methods
83 100
84 - (void)setWebState:(web::WebState*)webState { 101 - (void)setWebState:(web::WebState*)webState {
85 _webState = webState; 102 _webState = webState;
86 103
87 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState); 104 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState);
88 _translateClient = 105 _translateClient =
89 ios_web_view::WebViewTranslateClient::FromWebState(_webState); 106 ios_web_view::WebViewTranslateClient::FromWebState(_webState);
90 _translateClient->set_translation_controller(self); 107 _translateClient->set_translation_controller(self);
91 _translatePrefs = _translateClient->translate_manager() 108 _translatePrefs = _translateClient->translate_manager()
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 287 }
271 return _supportedLanguagesByCode; 288 return _supportedLanguagesByCode;
272 } 289 }
273 290
274 - (CWVTranslationLanguage*)languageWithCode:(const std::string&)languageCode { 291 - (CWVTranslationLanguage*)languageWithCode:(const std::string&)languageCode {
275 NSString* languageCodeString = base::SysUTF8ToNSString(languageCode); 292 NSString* languageCodeString = base::SysUTF8ToNSString(languageCode);
276 return self.supportedLanguagesByCode[languageCodeString]; 293 return self.supportedLanguagesByCode[languageCodeString];
277 } 294 }
278 295
279 @end 296 @end
OLDNEW
« 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