Chromium Code Reviews| Index: ios/web_view/shell/shell_translation_delegate.m |
| diff --git a/ios/web_view/shell/shell_translation_delegate.m b/ios/web_view/shell/shell_translation_delegate.m |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..32c8087b18c202450d0d0a6ede95e5843ec4547c |
| --- /dev/null |
| +++ b/ios/web_view/shell/shell_translation_delegate.m |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2014 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. |
| + |
| +#import "ios/web_view/shell/shell_translation_delegate.h" |
| + |
| +#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.
|
| +#import <UIKit/UIKit.h> |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +@interface ShellTranslationDelegate () |
| +// Action Sheet to prompt user whether or not the page should be translated. |
| +@property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet; |
| +@end |
| + |
| +@implementation ShellTranslationDelegate |
| + |
| +@synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet; |
| + |
| +- (void)dealloc { |
| + [_beforeTranslateActionSheet dismissViewControllerAnimated:YES |
| + completion:nil]; |
| +} |
| + |
| +#pragma mark - CWVTranslationDelegate methods |
| + |
| +- (void)translationController:(CWVTranslationController*)controller |
| + didFinishLanguageDetectionWithResult:(CWVLanguageDetectionResult*)result |
| + error:(NSError*)error { |
| + self.beforeTranslateActionSheet = [UIAlertController |
| + alertControllerWithTitle:nil |
| + message:@"Translate?" |
| + preferredStyle:UIAlertControllerStyleActionSheet]; |
| + UIAlertAction* cancelAction = |
| + [UIAlertAction actionWithTitle:@"Nope." |
| + style:UIAlertActionStyleCancel |
| + handler:^(UIAlertAction* action) { |
| + 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.
|
| + }]; |
| + [_beforeTranslateActionSheet addAction:cancelAction]; |
| + |
| + UIAlertAction* translateAction = [UIAlertAction |
| + actionWithTitle:@"Yes!" |
| + style:UIAlertActionStyleDefault |
| + handler:^(UIAlertAction* action) { |
| + 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.
|
| + CWVTranslationLanguage* source = result.pageLanguage; |
| + CWVTranslationLanguage* target = result.suggestedTargetLanguage; |
| + [controller translatePageFromLanguage:source toLanguage:target]; |
| + }]; |
| + [_beforeTranslateActionSheet addAction:translateAction]; |
| + |
| + [[UIApplication sharedApplication].keyWindow.rootViewController |
| + presentViewController:_beforeTranslateActionSheet |
| + animated:YES |
| + completion:nil]; |
| +} |
| + |
| +- (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.
|
| + didStartTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage |
| + toLanguage:(CWVTranslationLanguage*)targetLanguage { |
| +} |
| + |
| +- (void)translationController:(CWVTranslationController*)controller |
| + didFinishTranslationFromLanguage:(CWVTranslationLanguage*)sourceLanguage |
| + toLanguage:(CWVTranslationLanguage*)targetLanguage |
| + error:(NSError*)error { |
| +} |
| + |
| +@end |