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