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

Side by Side Diff: ios/web_view/shell/shell_translation_delegate.m

Issue 2839093002: Implemented new Translate API for purely Objective-C clients. (Closed)
Patch Set: addressed final comments 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 2014 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 #import "ios/web_view/shell/shell_translation_delegate.h"
6
7 #import <ChromeWebView/ChromeWebView.h>
michaeldo 2017/05/01 18:25:38 Can we remove ChromeWebView import, it is already
jzw1 2017/05/08 03:36:28 Done.
8 #import <UIKit/UIKit.h>
9
10 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support."
12 #endif
13
14 @interface ShellTranslationDelegate ()
15 // Action Sheet to prompt user whether or not the page should be translated.
16 @property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet;
17 @end
18
19 @implementation ShellTranslationDelegate
20
21 @synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet;
22
23 - (void)dealloc {
24 [_beforeTranslateActionSheet dismissViewControllerAnimated:YES
25 completion:nil];
26 }
27
28 #pragma mark - CWVTranslationDelegate methods
29
30 - (void)translationController:(CWVTranslationController*)controller
31 didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result
32 error:(NSError*)error {
33 self.beforeTranslateActionSheet = [UIAlertController
34 alertControllerWithTitle:nil
35 message:@"Translate?"
36 preferredStyle:UIAlertControllerStyleActionSheet];
37 UIAlertAction* cancelAction =
38 [UIAlertAction actionWithTitle:@"Nope."
39 style:UIAlertActionStyleCancel
40 handler:^(UIAlertAction* action) {
41 self.beforeTranslateActionSheet = nil;
michaeldo 2017/05/01 18:25:38 Please use __weak self reference inside action han
jzw1 2017/05/08 03:36:29 Done.
42 }];
43 [_beforeTranslateActionSheet addAction:cancelAction];
44
45 UIAlertAction* translateAction = [UIAlertAction
46 actionWithTitle:@"Yes!"
47 style:UIAlertActionStyleDefault
48 handler:^(UIAlertAction* action) {
49 self.beforeTranslateActionSheet = nil;
michaeldo 2017/05/01 18:25:38 Please use __weak self reference inside action han
jzw1 2017/05/08 03:36:28 Done.
50 CWVTranslationLanguage* source = result.pageLanguage;
51 CWVTranslationLanguage* target = result.suggestedTargetLanguage;
52 [controller translatePageFromLanguage:source toLanguage:target];
53 }];
54 [_beforeTranslateActionSheet addAction:translateAction];
55
56 [[UIApplication sharedApplication].keyWindow.rootViewController
57 presentViewController:_beforeTranslateActionSheet
58 animated:YES
59 completion:nil];
60 }
61
62 - (void)translationController:(CWVTranslationController*)controller
michaeldo 2017/05/01 18:25:38 No need for empty implementations because these de
jzw1 2017/05/08 03:36:28 Done.
63 didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
64 toLanguage:(CWVTranslationLanguage*)targetLanguage {
65 }
66
67 - (void)translationController:(CWVTranslationController*)controller
68 didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage
69 toLanguage:(CWVTranslationLanguage*)targetLanguage
70 error:(NSError*)error {
71 }
72
73 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698