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

Unified Diff: ios/web_view/public/cwv_translation_controller.h

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: change error codes and renamed some things Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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..268116fa7dd5869598bcf7e8402240225e7b3d96
--- /dev/null
+++ b/ios/web_view/public/cwv_translation_controller.h
@@ -0,0 +1,98 @@
+// 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 kCWVTranslationErrorDomain;
Eugene But (OOO till 7-30) 2017/04/28 03:07:29 Per Style Guide we don't need k prefix for public
jzw1 2017/04/28 05:43:36 Done
+// Possible error codes during translation.
Eugene But (OOO till 7-30) 2017/04/28 03:07:29 nit: Add a linebreak after kCWVTranslationErrorDom
jzw1 2017/04/28 05:43:36 Done.
+// No connectivity.
+extern const NSInteger kCWVTranslationErrorNetwork;
+// The translation script failed to initialize.
+extern const NSInteger kCWVTranslationErrorInitializationError;
+// The page's language could not be detected.
+extern const NSInteger kCWVTranslationErrorUnknownLanguage;
+// The server detected a language that the browser
+// does not know.
Eugene But (OOO till 7-30) 2017/04/28 03:07:29 No need for linebreak. This code fits 80 symbols
jzw1 2017/04/28 05:43:36 Done.
+extern const NSInteger kCWVTranslationErrorUnsupportedLanguage;
+// The original and target languages are the same.
+extern const NSInteger kCWVTranslationErrorIdenticalLanguages;
+// An error was reported by the translation script
+// during translation.
+extern const NSInteger kCWVTranslationErrorTranslationError;
+// The library doesn't finish the translation.
+extern const NSInteger kCWVTranslationErrorTranslationTimeout;
+// The library raises an unexpected exception.
+extern const NSInteger kCWVTranslationErrorUnexpectedScriptError;
+// The library is blocked because of bad origin.
+extern const NSInteger kCWVTranslationErrorBadOrigin;
+// Loader fails to load a dependent JavaScript.
+extern const NSInteger kCWVTranslationErrorScriptLoadError;
+
+// Updates delegate on translation progress.
+CWV_EXPORT
+@protocol CWVTranslationControllerDelegate<NSObject>
+@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.
+- (void)translationController:(CWVTranslationController*)controller
+ didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
+ 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.
+- (void)translationController:(CWVTranslationController*)controller
+ didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
+ toLanguage:(CWVTranslationLanguage*)targetLanguage
+ error:(nullable NSError*)error;
+
+@end
+
+// Exposes everything needed for translation features.
Eugene But (OOO till 7-30) 2017/04/28 03:07:29 nit: Do you want to explain what this class allows
jzw1 2017/04/28 05:43:36 Done.
+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

Powered by Google App Engine
This is Rietveld 408576698