Chromium Code Reviews| 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 ios_web_view::WebViewBrowserState* browserState = | |
| 75 [CWVWebViewConfiguration defaultConfiguration].browserState; | |
|
michaeldo
2017/07/07 18:16:01
Sorry I didn't think of this before, but will this
Eugene But (OOO till 7-30)
2017/07/07 20:10:28
What if clients want to reset policies for incogni
jzw1
2017/07/08 01:09:41
OK guys I've changed it so:
1. global instance for
Eugene But (OOO till 7-30)
2017/07/10 16:17:43
All methods related to translate policies are inst
jzw1
2017/07/10 18:51:40
The reason is because you can't get to an instance
| |
| 76 translate::TranslatePrefs translatePrefs(browserState->GetPrefs(), | |
| 77 prefs::kAcceptLanguages, nullptr); | |
| 78 translatePrefs.ResetToDefaults(); | |
| 79 } | |
| 80 | |
| 68 #pragma mark - Internal Methods | 81 #pragma mark - Internal Methods |
| 69 | 82 |
| 70 - (void)setWebState:(web::WebState*)webState { | 83 - (void)setWebState:(web::WebState*)webState { |
| 71 _webState = webState; | 84 _webState = webState; |
| 72 | 85 |
| 73 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState); | 86 ios_web_view::WebViewTranslateClient::CreateForWebState(_webState); |
| 74 _translateClient = | 87 _translateClient = |
| 75 ios_web_view::WebViewTranslateClient::FromWebState(_webState); | 88 ios_web_view::WebViewTranslateClient::FromWebState(_webState); |
| 76 _translateClient->set_translation_controller(self); | 89 _translateClient->set_translation_controller(self); |
| 77 _translatePrefs = _translateClient->translate_manager() | 90 _translatePrefs = _translateClient->translate_manager() |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 } | 267 } |
| 255 return _supportedLanguagesByCode; | 268 return _supportedLanguagesByCode; |
| 256 } | 269 } |
| 257 | 270 |
| 258 - (CWVTranslationLanguage*)languageWithCode:(const std::string&)languageCode { | 271 - (CWVTranslationLanguage*)languageWithCode:(const std::string&)languageCode { |
| 259 NSString* languageCodeString = base::SysUTF8ToNSString(languageCode); | 272 NSString* languageCodeString = base::SysUTF8ToNSString(languageCode); |
| 260 return self.supportedLanguagesByCode[languageCodeString]; | 273 return self.supportedLanguagesByCode[languageCodeString]; |
| 261 } | 274 } |
| 262 | 275 |
| 263 @end | 276 @end |
| OLD | NEW |