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