Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H | |
| 6 #define IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H | |
| 7 | |
| 8 #import <ChromeWebView/cwv_export.h> | |
| 9 #import <Foundation/Foundation.h> | |
| 10 | |
| 11 NS_ASSUME_NONNULL_BEGIN | |
| 12 | |
| 13 @class CWVTranslationController; | |
| 14 @class CWVLanguageDetectionResult; | |
| 15 @class CWVTranslationLanguage; | |
| 16 | |
| 17 // The error domain for translation errors. | |
| 18 extern NSErrorDomain const CWVTranslationErrorDomain; | |
| 19 | |
| 20 // Possible error codes during translation. | |
| 21 // No connectivity. | |
| 22 extern const NSInteger CWVTranslationErrorNetwork; | |
| 23 // The translation script failed to initialize. | |
| 24 extern const NSInteger CWVTranslationErrorInitializationError; | |
| 25 // The page's language could not be detected. | |
| 26 extern const NSInteger CWVTranslationErrorUnknownLanguage; | |
| 27 // The server detected a language that the browser does not know. | |
| 28 extern const NSInteger CWVTranslationErrorUnsupportedLanguage; | |
| 29 // The original and target languages are the same. | |
| 30 extern const NSInteger CWVTranslationErrorIdenticalLanguages; | |
| 31 // An error was reported by the translation script during translation. | |
| 32 extern const NSInteger CWVTranslationErrorTranslationError; | |
| 33 // The library doesn't finish the translation. | |
| 34 extern const NSInteger CWVTranslationErrorTranslationTimeout; | |
| 35 // The library raises an unexpected exception. | |
| 36 extern const NSInteger CWVTranslationErrorUnexpectedScriptError; | |
| 37 // The library is blocked because of bad origin. | |
| 38 extern const NSInteger CWVTranslationErrorBadOrigin; | |
| 39 // Loader fails to load a dependent JavaScript. | |
| 40 extern const NSInteger CWVTranslationErrorScriptLoadError; | |
| 41 | |
| 42 // Updates delegate on translation progress. | |
| 43 CWV_EXPORT | |
| 44 @protocol CWVTranslationControllerDelegate<NSObject> | |
|
michaeldo
2017/05/01 18:25:38
Please move delegate definition to it's own file.
jzw1
2017/05/08 03:36:28
Done.
| |
| 45 @optional | |
| 46 // Called when language detection is completed. Contains information on the | |
| 47 // detected language, the assumed target language for translation, as well as | |
| 48 // all languages supported by this translation controller. | |
| 49 // |error| will be filled if language detection failed. | |
|
michaeldo
2017/05/01 18:25:38
s/filled/nonnull
jzw1
2017/05/08 03:36:28
Done.
| |
| 50 - (void)translationController:(CWVTranslationController*)controller | |
| 51 didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result | |
|
michaeldo
2017/05/01 18:25:37
I think didFinishLanguageDetectionWithResult shoul
jzw1
2017/05/08 03:36:28
That's fair.
| |
| 52 error:(nullable NSError*)error; | |
| 53 | |
| 54 // Called when a translation has started. | |
| 55 - (void)translationController:(CWVTranslationController*)controller | |
| 56 didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage | |
| 57 toLanguage:(CWVTranslationLanguage*)targetLanguage; | |
| 58 | |
| 59 // Called when translation finishes. |error| will be filled if it failed. | |
|
michaeldo
2017/05/01 18:25:38
s/filled/nonnull
jzw1
2017/05/08 03:36:28
Done.
| |
| 60 - (void)translationController:(CWVTranslationController*)controller | |
| 61 didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage | |
| 62 toLanguage:(CWVTranslationLanguage*)targetLanguage | |
| 63 error:(nullable NSError*)error; | |
| 64 | |
| 65 @end | |
| 66 | |
| 67 // Main interface for access to translation features. | |
|
michaeldo
2017/05/01 18:25:38
"Main interface" sounds like there are other non-m
jzw1
2017/05/08 03:36:28
Fine by me.
| |
| 68 // Allows page translation from one language to another, and to revert it. | |
| 69 // Provides delegate to inform translation progress. | |
| 70 CWV_EXPORT | |
| 71 @interface CWVTranslationController : NSObject | |
| 72 | |
| 73 // Delegate to receive translation callbacks. | |
| 74 @property(nullable, nonatomic, weak) id<CWVTranslationControllerDelegate> | |
| 75 delegate; | |
| 76 | |
| 77 // Begins translation on the current page from |sourceLanguage| to | |
| 78 // |targetLanguage|. These language parameters must be chosen from | |
| 79 // a CWWLanguageDetectionResult's |supportedLanguages|. | |
| 80 // This must not be called before the |delegate| receives | |
| 81 // |translationController:didFinishLanguageDetectionWithResult:error:|. | |
| 82 // TODO(crbug.com/706289): Document what happens if you call this out of order | |
| 83 // or many times. | |
| 84 - (void)translatePageFromLanguage:(CWVTranslationLanguage*)sourceLanguage | |
| 85 toLanguage:(CWVTranslationLanguage*)targetLanguage; | |
| 86 | |
| 87 // Reverts any translations done back to the original page language. | |
| 88 // Note that the original page language may be different from |sourceLanguage| | |
| 89 // passed to |translatePageFromLanguage:toLanguage:| above. | |
| 90 // This must not be called before the |delegate| receives | |
| 91 // |translationController:didFinishLanguageDetectionWithResult:error:|. | |
| 92 // TODO(crbug.com/706289): Document what happens if you call this out of order. | |
| 93 - (void)revertTranslation; | |
| 94 | |
| 95 @end | |
| 96 | |
| 97 NS_ASSUME_NONNULL_END | |
| 98 | |
| 99 #endif // IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H | |
| OLD | NEW |