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 @property (nonatomic, strong) UIAlertController* beforeTranslateActionSheet; | |
Eugene But (OOO till 7-30)
2017/01/30 17:53:39
Please add comments.
| |
18 @property (nonatomic, strong) id<CRIWVTranslateManager> translateManager; | |
19 | |
17 @end | 20 @end |
18 | 21 |
19 @implementation TranslateController | 22 @implementation TranslateController |
20 | 23 |
24 @synthesize beforeTranslateActionSheet = _beforeTranslateActionSheet; | |
25 @synthesize translateManager = _translateManager; | |
26 | |
21 - (void)dealloc { | 27 - (void)dealloc { |
22 [_beforeTranslateActionSheet dismissViewControllerAnimated:YES | 28 [_beforeTranslateActionSheet dismissViewControllerAnimated:YES |
23 completion:nil]; | 29 completion:nil]; |
24 [super dealloc]; | |
25 } | 30 } |
26 | 31 |
27 #pragma mark CRIWVTranslateDelegate methods | 32 #pragma mark CRIWVTranslateDelegate methods |
28 | 33 |
29 - (void)translateStepChanged:(CRIWVTransateStep)step | 34 - (void)translateStepChanged:(CRIWVTransateStep)step |
30 manager:(id<CRIWVTranslateManager>)manager { | 35 manager:(id<CRIWVTranslateManager>)manager { |
31 if (step == CRIWVTransateStepBeforeTranslate) { | 36 if (step == CRIWVTransateStepBeforeTranslate) { |
32 DCHECK(!_translateManager); | 37 DCHECK(!_translateManager); |
33 DCHECK(!_beforeTranslateActionSheet); | 38 DCHECK(!_beforeTranslateActionSheet); |
34 _translateManager.reset([manager retain]); | 39 self.translateManager = manager; |
35 _beforeTranslateActionSheet.reset([[UIAlertController | 40 self.beforeTranslateActionSheet = [UIAlertController |
36 alertControllerWithTitle:nil | 41 alertControllerWithTitle:nil |
37 message:@"Translate?" | 42 message:@"Translate?" |
38 preferredStyle:UIAlertControllerStyleActionSheet] retain]); | 43 preferredStyle:UIAlertControllerStyleActionSheet]; |
39 UIAlertAction* cancelAction = | 44 UIAlertAction* cancelAction = |
40 [UIAlertAction actionWithTitle:@"Nope." | 45 [UIAlertAction actionWithTitle:@"Nope." |
41 style:UIAlertActionStyleCancel | 46 style:UIAlertActionStyleCancel |
42 handler:^(UIAlertAction* action) { | 47 handler:^(UIAlertAction* action) { |
43 DCHECK(_beforeTranslateActionSheet); | 48 DCHECK(_beforeTranslateActionSheet); |
44 _beforeTranslateActionSheet.reset(); | 49 _beforeTranslateActionSheet = nil; |
Eugene But (OOO till 7-30)
2017/01/30 17:53:39
nit: self.beforeTranslateActionSheet = nil? Same f
michaeldo
2017/01/30 19:30:35
Done.
| |
45 DCHECK(_translateManager); | 50 DCHECK(_translateManager); |
46 _translateManager.reset(); | 51 _translateManager = nil; |
47 }]; | 52 }]; |
48 [_beforeTranslateActionSheet addAction:cancelAction]; | 53 [_beforeTranslateActionSheet addAction:cancelAction]; |
49 | 54 |
50 UIAlertAction* translateAction = | 55 UIAlertAction* translateAction = |
51 [UIAlertAction actionWithTitle:@"Yes!" | 56 [UIAlertAction actionWithTitle:@"Yes!" |
52 style:UIAlertActionStyleDefault | 57 style:UIAlertActionStyleDefault |
53 handler:^(UIAlertAction* action) { | 58 handler:^(UIAlertAction* action) { |
54 DCHECK(_beforeTranslateActionSheet); | 59 DCHECK(_beforeTranslateActionSheet); |
55 _beforeTranslateActionSheet.reset(); | 60 _beforeTranslateActionSheet = nil; |
56 DCHECK(_translateManager); | 61 DCHECK(_translateManager); |
57 [_translateManager translate]; | 62 [_translateManager translate]; |
58 _translateManager.reset(); | 63 _translateManager = nil; |
59 }]; | 64 }]; |
60 [_beforeTranslateActionSheet addAction:translateAction]; | 65 [_beforeTranslateActionSheet addAction:translateAction]; |
61 | 66 |
62 [[UIApplication sharedApplication].keyWindow.rootViewController | 67 [[UIApplication sharedApplication].keyWindow.rootViewController |
63 presentViewController:_beforeTranslateActionSheet | 68 presentViewController:_beforeTranslateActionSheet |
64 animated:YES | 69 animated:YES |
65 completion:nil]; | 70 completion:nil]; |
66 } | 71 } |
67 } | 72 } |
68 | 73 |
69 @end | 74 @end |
OLD | NEW |