| OLD | NEW |
| (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/translate_controller.h" | |
| 6 | |
| 7 #import <ChromeWebView/ChromeWebView.h> | |
| 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 TranslateController () | |
| 15 // Action Sheet to prompt user whether or not the page should be translated. | |
| 16 @property(nonatomic, strong) UIAlertController* beforeTranslateActionSheet; | |
| 17 // Manager which performs the translation of the content. | |
| 18 @property(nonatomic, strong) id<CWVTranslateManager> translateManager; | |
| 19 @end | |
| 20 | |
| 21 @implementation TranslateController | |
| 22 | |
| 23 @synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet; | |
| 24 @synthesize translateManager = _translateManager; | |
| 25 | |
| 26 - (void)dealloc { | |
| 27 [_beforeTranslateActionSheet dismissViewControllerAnimated:YES | |
| 28 completion:nil]; | |
| 29 } | |
| 30 | |
| 31 #pragma mark CWVTranslateDelegate methods | |
| 32 | |
| 33 - (void)translateStepChanged:(CRIWVTransateStep)step | |
| 34 manager:(id<CWVTranslateManager>)manager { | |
| 35 if (step == CRIWVTransateStepBeforeTranslate) { | |
| 36 self.translateManager = manager; | |
| 37 self.beforeTranslateActionSheet = [UIAlertController | |
| 38 alertControllerWithTitle:nil | |
| 39 message:@"Translate?" | |
| 40 preferredStyle:UIAlertControllerStyleActionSheet]; | |
| 41 UIAlertAction* cancelAction = | |
| 42 [UIAlertAction actionWithTitle:@"Nope." | |
| 43 style:UIAlertActionStyleCancel | |
| 44 handler:^(UIAlertAction* action) { | |
| 45 self.beforeTranslateActionSheet = nil; | |
| 46 self.translateManager = nil; | |
| 47 }]; | |
| 48 [_beforeTranslateActionSheet addAction:cancelAction]; | |
| 49 | |
| 50 UIAlertAction* translateAction = | |
| 51 [UIAlertAction actionWithTitle:@"Yes!" | |
| 52 style:UIAlertActionStyleDefault | |
| 53 handler:^(UIAlertAction* action) { | |
| 54 self.beforeTranslateActionSheet = nil; | |
| 55 [_translateManager translate]; | |
| 56 self.translateManager = nil; | |
| 57 }]; | |
| 58 [_beforeTranslateActionSheet addAction:translateAction]; | |
| 59 | |
| 60 [[UIApplication sharedApplication].keyWindow.rootViewController | |
| 61 presentViewController:_beforeTranslateActionSheet | |
| 62 animated:YES | |
| 63 completion:nil]; | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 @end | |
| OLD | NEW |