| OLD | NEW |
| 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 #import "ios/web_view/internal/cwv_web_view_configuration_internal.h" |
| 15 #include "ios/web_view/internal/pref_names.h" |
| 14 #import "ios/web_view/internal/translate/cwv_translation_language_internal.h" | 16 #import "ios/web_view/internal/translate/cwv_translation_language_internal.h" |
| 15 #import "ios/web_view/internal/translate/web_view_translate_client.h" | 17 #import "ios/web_view/internal/translate/web_view_translate_client.h" |
| 18 #include "ios/web_view/internal/web_view_browser_state.h" |
| 16 #import "ios/web_view/public/cwv_translation_controller_delegate.h" | 19 #import "ios/web_view/public/cwv_translation_controller_delegate.h" |
| 17 #import "ios/web_view/public/cwv_translation_policy.h" | 20 #import "ios/web_view/public/cwv_translation_policy.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 19 | 22 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) | 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." | 24 #error "This file requires ARC support." |
| 22 #endif | 25 #endif |
| 23 | 26 |
| 24 NSErrorDomain const CWVTranslationErrorDomain = | 27 NSErrorDomain const CWVTranslationErrorDomain = |
| 25 @"org.chromium.chromewebview.TranslationErrorDomain"; | 28 @"org.chromium.chromewebview.TranslationErrorDomain"; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 61 |
| 59 @implementation CWVTranslationController { | 62 @implementation CWVTranslationController { |
| 60 ios_web_view::WebViewTranslateClient* _translateClient; | 63 ios_web_view::WebViewTranslateClient* _translateClient; |
| 61 std::unique_ptr<translate::TranslatePrefs> _translatePrefs; | 64 std::unique_ptr<translate::TranslatePrefs> _translatePrefs; |
| 62 } | 65 } |
| 63 | 66 |
| 64 @synthesize delegate = _delegate; | 67 @synthesize delegate = _delegate; |
| 65 @synthesize supportedLanguagesByCode = _supportedLanguagesByCode; | 68 @synthesize supportedLanguagesByCode = _supportedLanguagesByCode; |
| 66 @synthesize webState = _webState; | 69 @synthesize webState = _webState; |
| 67 | 70 |
| 71 #pragma mark - Class Methods |
| 72 |
| 73 + (void)resetTranslationPolicies { |
| 74 CWVWebViewConfiguration* configuration = |
| 75 [CWVWebViewConfiguration defaultConfiguration]; |
| 76 PrefService* prefService = configuration.browserState->GetPrefs(); |
| 77 translate::TranslatePrefs translatePrefs(prefService, prefs::kAcceptLanguages, |
| 78 nullptr); |
| 79 translatePrefs.ResetToDefaults(); |
| 80 } |
| 81 |
| 68 #pragma mark - Internal Methods | 82 #pragma mark - Internal Methods |
| 69 | 83 |
| 70 - (void)setWebState:(web::WebState*)webState { | 84 - (void)setWebState:(web::WebState*)webState { |
| 71 _webState = webState; | 85 _webState = webState; |
| 72 | 86 |
| 73 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState); | 87 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState); |
| 74 _translateClient = | 88 _translateClient = |
| 75 ios_web_view::WebViewTranslateClient::FromWebState(_webState); | 89 ios_web_view::WebViewTranslateClient::FromWebState(_webState); |
| 76 _translateClient->set_translation_controller(self); | 90 _translateClient->set_translation_controller(self); |
| 77 _translatePrefs = _translateClient->translate_manager() | 91 _translatePrefs = _translateClient->translate_manager() |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 268 } |
| 255 return _supportedLanguagesByCode; | 269 return _supportedLanguagesByCode; |
| 256 } | 270 } |
| 257 | 271 |
| 258 - (CWVTranslationLanguage*)languageWithCode:(const std::string&)languageCode { | 272 - (CWVTranslationLanguage*)languageWithCode:(const std::string&)languageCode { |
| 259 NSString* languageCodeString = base::SysUTF8ToNSString(languageCode); | 273 NSString* languageCodeString = base::SysUTF8ToNSString(languageCode); |
| 260 return self.supportedLanguagesByCode[languageCodeString]; | 274 return self.supportedLanguagesByCode[languageCodeString]; |
| 261 } | 275 } |
| 262 | 276 |
| 263 @end | 277 @end |
| OLD | NEW |