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

Side by Side Diff: ios/web_view/public/cwv_translation_controller.h

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: Added some error handling. Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(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 @class CWVTranslationController;
12 @class CWVLanguageDetectionResult;
13 @class CWVTranslationLanguage;
14
15 // Possible errors during translation.
Eugene But (OOO till 7-30) 2017/04/26 20:15:30 s/errors/error codes ?
jzw1 2017/04/27 04:54:02 Done.
16 typedef NS_ENUM(NSInteger, CWVTranslationError) {
Eugene But (OOO till 7-30) 2017/04/26 20:15:31 Is there a need for enum? Should these constants b
jzw1 2017/04/27 04:54:02 I'm just copying the error codes over from transla
Eugene But (OOO till 7-30) 2017/04/27 13:08:08 Looks like iOS SDK do not use named enums and use
jzw1 2017/04/28 02:34:53 I'll get rid of the name. Since any of these error
Eugene But (OOO till 7-30) 2017/04/28 03:07:28 Sure.
17 // No errors.
18 CWVTranslationErrorNone = 0,
Eugene But (OOO till 7-30) 2017/04/26 20:15:30 Is there a need for this item? This error code can
jzw1 2017/04/27 04:54:02 I'm just copying the error codes over from transla
Eugene But (OOO till 7-30) 2017/04/27 13:08:08 That code is C++ code and 0 in C++ means no error.
jzw1 2017/04/28 02:34:53 Done.
19 // No connectivity.
20 CWVTranslationErrorNetwork,
Eugene But (OOO till 7-30) 2017/04/26 20:15:31 Normally large negative numbers are used for error
jzw1 2017/04/27 04:54:02 I'm just copying the error codes over from transla
Eugene But (OOO till 7-30) 2017/04/27 13:08:08 If the goal is to use the same error codes as tran
jzw1 2017/04/28 02:34:53 Good point. I'll make this change.
21 // The translation script failed to initialize.
22 CWVTranslationErrorInitializationError,
23 // The page's language could not be detected.
24 CWVTranslationErrorUnknownLanguage,
25 // The server detected a language that the browser
26 // does not know.
27 CWVTranslationErrorUnsupportedLanguage,
28 // The original and target languages are the same.
29 CWVTranslationErrorIdenticalLanguages,
30 // An error was reported by the translation script
31 // during translation.
32 CWVTranslationErrorTranslationError,
33 // The library doesn't finish the translation.
34 CWVTranslationErrorTranslationTimeout,
35 // The library raises an unexpected exception.
36 CWVTranslationErrorUnexpectedScriptError,
37 // The library is blocked because of bad origin.
38 CWVTranslationErrorBadOrigin,
39 // Loader fails to load a dependent JavaScript.
40 CWVTranslationErrorScriptLoadError
41 };
42
43 // Updates delegate on translation progress.
44 CWV_EXPORT
45 @protocol CWVTranslationControllerDelegate<NSObject>
Hiroshi Ichikawa 2017/04/26 08:40:57 How about marking this protocol as @optional, and
Eugene But (OOO till 7-30) 2017/04/26 20:15:31 +1
jzw1 2017/04/27 04:54:01 Done.
46
47 // Called when language detection is completed. Contains information on the
48 // detected language, the assumed target language for translation, as well as
49 // all languages supported by this translation controller.
50 // |error| will be filled if language detection failed.
Eugene But (OOO till 7-30) 2017/04/26 20:15:31 Do you want to create a constant for Error Domain?
jzw1 2017/04/27 04:54:02 Done.
51 - (void)translationController:(CWVTranslationController*)controller
52 didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
53 error:(NSError*)error;
54
55 // Called when a translation is in progress. Used to show loading indicator.
Eugene But (OOO till 7-30) 2017/04/26 20:15:31 s/is in progress/has started ?
Eugene But (OOO till 7-30) 2017/04/26 20:15:31 Please do not make assumptions how this is used.
jzw1 2017/04/27 04:54:02 Done.
jzw1 2017/04/27 04:54:02 Done.
56 - (void)translationController:(CWVTranslationController*)controller
57 didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
58 toLanguage:(CWVTranslationLanguage*)targetLanguage;
59
60 // Called when translation finishes. |error| will be filled if it failed.
61 - (void)translationController:(CWVTranslationController*)controller
62 didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
63 toLanguage:(CWVTranslationLanguage*)targetLanguage
64 error:(NSError*)error;
65
66 @end
67
68 // Exposes everything needed for translation features.
69 CWV_EXPORT
70 @interface CWVTranslationController : NSObject
71
72 - (instancetype)init NS_UNAVAILABLE;
73
74 // Delegate to receive translation callbacks.
75 @property(nonatomic, weak) id<CWVTranslationControllerDelegate> delegate;
76
77 // Begins translation on the current page from |sourceLanguage| to
Hiroshi Ichikawa 2017/04/26 08:40:57 Can you add a comment that this must not be called
Hiroshi Ichikawa 2017/04/27 05:35:42 Reminder: This hasn't been resolved yet.
jzw1 2017/04/27 07:03:18 Done.
Hiroshi Ichikawa 2017/04/27 07:17:23 Looks like this part of the comment hasn't been re
jzw1 2017/04/27 07:22:02 Done.
78 // |targetLanguage|.
Eugene But (OOO till 7-30) 2017/04/26 20:15:31 Could you please specify that |targetLanguage| sho
jzw1 2017/04/27 04:54:02 Done.
79 - (void)translatePageFromLanguage:(CWVTranslationLanguage*)sourceLanguage
80 toLanguage:(CWVTranslationLanguage*)targetLanguage;
81
82 // Reverts any translations done back to the original page language.
Hiroshi Ichikawa 2017/04/26 08:40:57 Can you add a comment that this must not be called
jzw1 2017/04/27 04:54:02 I'll investigate this soon after I build out some
Hiroshi Ichikawa 2017/04/27 05:35:42 Anyway this must not be called before -translation
jzw1 2017/04/27 07:03:18 Done.
83 // Note that the original page language may be different from |sourceLanguage|
84 // passed to |translatePageFromLanguage:toLanguage:| above.
Eugene But (OOO till 7-30) 2017/04/26 20:15:30 What happens if this is called for a page which ha
jzw1 2017/04/27 04:54:02 I'll report back in a future patch
Hiroshi Ichikawa 2017/04/27 05:35:42 Can you add a TODO comment for it?
jzw1 2017/04/27 07:03:18 Done.
85 - (void)revertTranslation;
86
87 @end
88
89 #endif // IOS_WEB_VIEW_PUBLIC_CWV_TRANSLATION_CONTROLLER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698