Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: ios/chrome/browser/web/resubmit_data_controller.mm

Issue 2518583002: [ObjC ARC] Converts ios/chrome/browser/web:web to ARC. (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/web/dom_altering_lock.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/chrome/browser/web/resubmit_data_controller.h" 5 #import "ios/chrome/browser/web/resubmit_data_controller.h"
6 6
7 #import "base/logging.h" 7 #import "base/logging.h"
8 #include "base/mac/scoped_block.h"
9 #import "base/mac/scoped_nsobject.h"
10 #include "components/strings/grit/components_strings.h" 8 #include "components/strings/grit/components_strings.h"
11 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
12 10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
13 @interface ResubmitDataController () { 15 @interface ResubmitDataController () {
14 base::scoped_nsobject<UIAlertController> _alertController; 16 UIAlertController* _alertController;
15 } 17 }
16 @end 18 @end
17 19
18 @implementation ResubmitDataController 20 @implementation ResubmitDataController
19 21
20 - (instancetype)init { 22 - (instancetype)init {
21 NOTREACHED(); 23 NOTREACHED();
22 return nil; 24 return nil;
23 } 25 }
24 26
25 - (instancetype)initWithContinueBlock:(ProceduralBlock)continueBlock 27 - (instancetype)initWithContinueBlock:(ProceduralBlock)continueBlock
26 cancelBlock:(ProceduralBlock)cancelBlock { 28 cancelBlock:(ProceduralBlock)cancelBlock {
27 DCHECK(continueBlock); 29 DCHECK(continueBlock);
28 DCHECK(cancelBlock); 30 DCHECK(cancelBlock);
29 self = [super init]; 31 self = [super init];
30 if (self) { 32 if (self) {
31 NSString* message = [NSString 33 NSString* message = [NSString
32 stringWithFormat:@"%@\n\n%@", 34 stringWithFormat:@"%@\n\n%@",
33 l10n_util::GetNSString(IDS_HTTP_POST_WARNING_TITLE), 35 l10n_util::GetNSString(IDS_HTTP_POST_WARNING_TITLE),
34 l10n_util::GetNSString(IDS_HTTP_POST_WARNING)]; 36 l10n_util::GetNSString(IDS_HTTP_POST_WARNING)];
35 NSString* buttonTitle = 37 NSString* buttonTitle =
36 l10n_util::GetNSString(IDS_HTTP_POST_WARNING_RESEND); 38 l10n_util::GetNSString(IDS_HTTP_POST_WARNING_RESEND);
37 NSString* cancelTitle = l10n_util::GetNSString(IDS_CANCEL); 39 NSString* cancelTitle = l10n_util::GetNSString(IDS_CANCEL);
38 40
39 _alertController.reset([[UIAlertController 41 _alertController = [UIAlertController
40 alertControllerWithTitle:nil 42 alertControllerWithTitle:nil
41 message:message 43 message:message
42 preferredStyle:UIAlertControllerStyleActionSheet] retain]); 44 preferredStyle:UIAlertControllerStyleActionSheet];
43
44 // Make sure the blocks are located on the heap. 45 // Make sure the blocks are located on the heap.
45 base::mac::ScopedBlock<ProceduralBlock> guaranteeOnHeap; 46 continueBlock = [continueBlock copy];
46 guaranteeOnHeap.reset([continueBlock copy]); 47 cancelBlock = [cancelBlock copy];
47 guaranteeOnHeap.reset([cancelBlock copy]);
48 48
49 UIAlertAction* cancelAction = 49 UIAlertAction* cancelAction =
50 [UIAlertAction actionWithTitle:cancelTitle 50 [UIAlertAction actionWithTitle:cancelTitle
51 style:UIAlertActionStyleCancel 51 style:UIAlertActionStyleCancel
52 handler:^(UIAlertAction* _Nonnull action) { 52 handler:^(UIAlertAction* _Nonnull action) {
53 cancelBlock(); 53 cancelBlock();
54 }]; 54 }];
55 [_alertController addAction:cancelAction]; 55 [_alertController addAction:cancelAction];
56 UIAlertAction* continueAction = 56 UIAlertAction* continueAction =
57 [UIAlertAction actionWithTitle:buttonTitle 57 [UIAlertAction actionWithTitle:buttonTitle
58 style:UIAlertActionStyleDefault 58 style:UIAlertActionStyleDefault
59 handler:^(UIAlertAction* _Nonnull action) { 59 handler:^(UIAlertAction* _Nonnull action) {
60 continueBlock(); 60 continueBlock();
61 }]; 61 }];
62 [_alertController addAction:continueAction]; 62 [_alertController addAction:continueAction];
63 } 63 }
64 return self; 64 return self;
65 } 65 }
66 66
67 - (void)presentActionSheetFromRect:(CGRect)rect inView:(UIView*)view { 67 - (void)presentActionSheetFromRect:(CGRect)rect inView:(UIView*)view {
68 _alertController.get().modalPresentationStyle = UIModalPresentationPopover; 68 _alertController.modalPresentationStyle = UIModalPresentationPopover;
69 UIPopoverPresentationController* popPresenter = 69 UIPopoverPresentationController* popPresenter =
70 _alertController.get().popoverPresentationController; 70 _alertController.popoverPresentationController;
71 popPresenter.sourceView = view; 71 popPresenter.sourceView = view;
72 popPresenter.sourceRect = rect; 72 popPresenter.sourceRect = rect;
73 73
74 UIViewController* topController = view.window.rootViewController; 74 UIViewController* topController = view.window.rootViewController;
75 while (topController.presentedViewController) 75 while (topController.presentedViewController)
76 topController = topController.presentedViewController; 76 topController = topController.presentedViewController;
77 [topController presentViewController:_alertController 77 [topController presentViewController:_alertController
78 animated:YES 78 animated:YES
79 completion:nil]; 79 completion:nil];
80 } 80 }
81 81
82 - (void)dismissActionSheet { 82 - (void)dismissActionSheet {
83 [_alertController.get().presentingViewController 83 [_alertController.presentingViewController dismissViewControllerAnimated:YES
84 dismissViewControllerAnimated:YES 84 completion:nil];
85 completion:nil];
86 } 85 }
87 86
88 @end 87 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/dom_altering_lock.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698