| 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 <UIKit/UIKit.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #import "ios/web_view/public/criwv_translate_manager.h" | |
| 11 | |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 13 #error "This file requires ARC support." | |
| 14 #endif | |
| 15 | |
| 16 @interface TranslateController () | |
| 17 // Action Sheet to prompt user whether or not the page should be translated. | |
| 18 @property (nonatomic, strong) UIAlertController* beforeTranslateActionSheet; | |
| 19 // Manager which performs the translation of the content. | |
| 20 @property (nonatomic, strong) id<CRIWVTranslateManager> translateManager; | |
| 21 @end | |
| 22 | |
| 23 @implementation TranslateController | |
| 24 | |
| 25 @synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet; | |
| 26 @synthesize translateManager = _translateManager; | |
| 27 | |
| 28 - (void)dealloc { | |
| 29 [_beforeTranslateActionSheet dismissViewControllerAnimated:YES | |
| 30 completion:nil]; | |
| 31 } | |
| 32 | |
| 33 #pragma mark CRIWVTranslateDelegate methods | |
| 34 | |
| 35 - (void)translateStepChanged:(CRIWVTransateStep)step | |
| 36 manager:(id<CRIWVTranslateManager>)manager { | |
| 37 if (step == CRIWVTransateStepBeforeTranslate) { | |
| 38 DCHECK(!_translateManager); | |
| 39 DCHECK(!_beforeTranslateActionSheet); | |
| 40 self.translateManager = manager; | |
| 41 self.beforeTranslateActionSheet = [UIAlertController | |
| 42 alertControllerWithTitle:nil | |
| 43 message:@"Translate?" | |
| 44 preferredStyle:UIAlertControllerStyleActionSheet]; | |
| 45 UIAlertAction* cancelAction = | |
| 46 [UIAlertAction actionWithTitle:@"Nope." | |
| 47 style:UIAlertActionStyleCancel | |
| 48 handler:^(UIAlertAction* action) { | |
| 49 DCHECK(_beforeTranslateActionSheet); | |
| 50 self.beforeTranslateActionSheet = nil; | |
| 51 DCHECK(_translateManager); | |
| 52 self.translateManager = nil; | |
| 53 }]; | |
| 54 [_beforeTranslateActionSheet addAction:cancelAction]; | |
| 55 | |
| 56 UIAlertAction* translateAction = | |
| 57 [UIAlertAction actionWithTitle:@"Yes!" | |
| 58 style:UIAlertActionStyleDefault | |
| 59 handler:^(UIAlertAction* action) { | |
| 60 DCHECK(_beforeTranslateActionSheet); | |
| 61 self.beforeTranslateActionSheet = nil; | |
| 62 DCHECK(_translateManager); | |
| 63 [_translateManager translate]; | |
| 64 self.translateManager = nil; | |
| 65 }]; | |
| 66 [_beforeTranslateActionSheet addAction:translateAction]; | |
| 67 | |
| 68 [[UIApplication sharedApplication].keyWindow.rootViewController | |
| 69 presentViewController:_beforeTranslateActionSheet | |
| 70 animated:YES | |
| 71 completion:nil]; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 @end | |
| OLD | NEW |