Chromium Code Reviews| Index: ios/web_view/public/cwv_translation_controller.h |
| diff --git a/ios/web_view/public/cwv_translation_controller.h b/ios/web_view/public/cwv_translation_controller.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fdde007ae5bb0b1708b33099ee479916b23b9bb3 |
| --- /dev/null |
| +++ b/ios/web_view/public/cwv_translation_controller.h |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H |
| +#define IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H |
| + |
| +#import <ChromeWebView/cwv_export.h> |
| +#import <Foundation/Foundation.h> |
| + |
| +NS_ASSUME_NONNULL_BEGIN |
| + |
| +@class CWVTranslationController; |
| +@class CWVLanguageDetectionResult; |
| +@class CWVTranslationLanguage; |
| + |
| +// The error domain for translation errors. |
| +extern NSErrorDomain const CWVTranslationErrorDomain; |
| + |
| +// Possible error codes during translation. |
| +// No connectivity. |
| +extern const NSInteger CWVTranslationErrorNetwork; |
| +// The translation script failed to initialize. |
| +extern const NSInteger CWVTranslationErrorInitializationError; |
| +// The page's language could not be detected. |
| +extern const NSInteger CWVTranslationErrorUnknownLanguage; |
| +// The server detected a language that the browser does not know. |
| +extern const NSInteger CWVTranslationErrorUnsupportedLanguage; |
| +// The original and target languages are the same. |
| +extern const NSInteger CWVTranslationErrorIdenticalLanguages; |
| +// An error was reported by the translation script during translation. |
| +extern const NSInteger CWVTranslationErrorTranslationError; |
| +// The library doesn't finish the translation. |
| +extern const NSInteger CWVTranslationErrorTranslationTimeout; |
| +// The library raises an unexpected exception. |
| +extern const NSInteger CWVTranslationErrorUnexpectedScriptError; |
| +// The library is blocked because of bad origin. |
| +extern const NSInteger CWVTranslationErrorBadOrigin; |
| +// Loader fails to load a dependent JavaScript. |
| +extern const NSInteger CWVTranslationErrorScriptLoadError; |
| + |
| +// Updates delegate on translation progress. |
| +CWV_EXPORT |
| +@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.
|
| +@optional |
| +// Called when language detection is completed. Contains information on the |
| +// detected language, the assumed target language for translation, as well as |
| +// all languages supported by this translation controller. |
| +// |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.
|
| +- (void)translationController:(CWVTranslationController*)controller |
| + didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result |
|
michaeldo
2017/05/01 18:25:37
I think didFinishLanguageDetectionWithResult shoul
jzw1
2017/05/08 03:36:28
That's fair.
|
| + error:(nullable NSError*)error; |
| + |
| +// Called when a translation has started. |
| +- (void)translationController:(CWVTranslationController*)controller |
| + didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage |
| + toLanguage:(CWVTranslationLanguage*)targetLanguage; |
| + |
| +// 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.
|
| +- (void)translationController:(CWVTranslationController*)controller |
| + didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage |
| + toLanguage:(CWVTranslationLanguage*)targetLanguage |
| + error:(nullable NSError*)error; |
| + |
| +@end |
| + |
| +// 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.
|
| +// Allows page translation from one language to another, and to revert it. |
| +// Provides delegate to inform translation progress. |
| +CWV_EXPORT |
| +@interface CWVTranslationController : NSObject |
| + |
| +// Delegate to receive translation callbacks. |
| +@property(nullable, nonatomic, weak) id<CWVTranslationControllerDelegate> |
| + delegate; |
| + |
| +// Begins translation on the current page from |sourceLanguage| to |
| +// |targetLanguage|. These language parameters must be chosen from |
| +// a CWWLanguageDetectionResult's |supportedLanguages|. |
| +// This must not be called before the |delegate| receives |
| +// |translationController:didFinishLanguageDetectionWithResult:error:|. |
| +// TODO(crbug.com/706289): Document what happens if you call this out of order |
| +// or many times. |
| +- (void)translatePageFromLanguage:(CWVTranslationLanguage*)sourceLanguage |
| + toLanguage:(CWVTranslationLanguage*)targetLanguage; |
| + |
| +// Reverts any translations done back to the original page language. |
| +// Note that the original page language may be different from |sourceLanguage| |
| +// passed to |translatePageFromLanguage:toLanguage:| above. |
| +// This must not be called before the |delegate| receives |
| +// |translationController:didFinishLanguageDetectionWithResult:error:|. |
| +// TODO(crbug.com/706289): Document what happens if you call this out of order. |
| +- (void)revertTranslation; |
| + |
| +@end |
| + |
| +NS_ASSUME_NONNULL_END |
| + |
| +#endif // IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H |