OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "ios/chrome/browser/geolocation/omnibox_geolocation_authorization_alert .h" | 5 #include "ios/chrome/browser/geolocation/omnibox_geolocation_authorization_alert .h" |
6 | 6 |
7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
8 | 8 |
9 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
12 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
13 #include "ios/chrome/grit/ios_chromium_strings.h" | 13 #include "ios/chrome/grit/ios_chromium_strings.h" |
14 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 14 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
15 #include "ui/base/l10n/l10n_util_mac.h" | 15 #include "ui/base/l10n/l10n_util_mac.h" |
16 | 16 |
17 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
18 #error "This file requires ARC support." | |
19 #endif | |
20 | |
17 @interface OmniboxGeolocationAuthorizationAlert () { | 21 @interface OmniboxGeolocationAuthorizationAlert () { |
18 base::WeakNSProtocol<id<OmniboxGeolocationAuthorizationAlertDelegate>> | 22 base::WeakNSProtocol<id<OmniboxGeolocationAuthorizationAlertDelegate>> |
19 delegate_; | 23 delegate_; |
20 } | 24 } |
21 @end | 25 @end |
22 | 26 |
23 @implementation OmniboxGeolocationAuthorizationAlert | 27 @implementation OmniboxGeolocationAuthorizationAlert |
24 | 28 |
25 - (instancetype)initWithDelegate: | 29 - (instancetype)initWithDelegate: |
26 (id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate { | 30 (id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate { |
(...skipping 17 matching lines...) Expand all Loading... | |
44 } | 48 } |
45 | 49 |
46 - (void)showAuthorizationAlert { | 50 - (void)showAuthorizationAlert { |
47 NSString* message = | 51 NSString* message = |
48 l10n_util::GetNSString(IDS_IOS_LOCATION_AUTHORIZATION_ALERT); | 52 l10n_util::GetNSString(IDS_IOS_LOCATION_AUTHORIZATION_ALERT); |
49 NSString* cancel = l10n_util::GetNSString(IDS_NOT_NOW); | 53 NSString* cancel = l10n_util::GetNSString(IDS_NOT_NOW); |
50 NSString* ok = l10n_util::GetNSString(IDS_OK); | 54 NSString* ok = l10n_util::GetNSString(IDS_OK); |
51 | 55 |
52 // Use a UIAlertController to match the style of the iOS system location | 56 // Use a UIAlertController to match the style of the iOS system location |
53 // alert. | 57 // alert. |
54 base::WeakNSObject<OmniboxGeolocationAuthorizationAlert> weakSelf(self); | 58 base::WeakNSObject<OmniboxGeolocationAuthorizationAlert> weakSelf(self); |
sdefresne
2016/11/25 10:16:46
I thought you wanted to remove base::WeakNSObject<
stkhapugin
2016/11/25 14:57:16
Done.
| |
55 UIAlertController* alert = | 59 UIAlertController* alert = |
56 [UIAlertController alertControllerWithTitle:nil | 60 [UIAlertController alertControllerWithTitle:nil |
57 message:message | 61 message:message |
58 preferredStyle:UIAlertControllerStyleAlert]; | 62 preferredStyle:UIAlertControllerStyleAlert]; |
59 | 63 |
60 UIAlertAction* defaultAction = [UIAlertAction | 64 UIAlertAction* defaultAction = [UIAlertAction |
61 actionWithTitle:ok | 65 actionWithTitle:ok |
62 style:UIAlertActionStyleDefault | 66 style:UIAlertActionStyleDefault |
63 handler:^(UIAlertAction* action) { | 67 handler:^(UIAlertAction* action) { |
64 base::scoped_nsobject<OmniboxGeolocationAuthorizationAlert> | 68 base::scoped_nsobject<OmniboxGeolocationAuthorizationAlert> |
65 strongSelf([weakSelf retain]); | 69 strongSelf(weakSelf); |
66 if (strongSelf) { | 70 if (strongSelf) { |
67 [[strongSelf delegate] | 71 [[strongSelf delegate] |
68 authorizationAlertDidAuthorize:strongSelf]; | 72 authorizationAlertDidAuthorize:strongSelf]; |
69 } | 73 } |
70 }]; | 74 }]; |
71 [alert addAction:defaultAction]; | 75 [alert addAction:defaultAction]; |
72 | 76 |
73 UIAlertAction* cancelAction = [UIAlertAction | 77 UIAlertAction* cancelAction = [UIAlertAction |
74 actionWithTitle:cancel | 78 actionWithTitle:cancel |
75 style:UIAlertActionStyleCancel | 79 style:UIAlertActionStyleCancel |
76 handler:^(UIAlertAction* action) { | 80 handler:^(UIAlertAction* action) { |
77 base::scoped_nsobject<OmniboxGeolocationAuthorizationAlert> | 81 base::scoped_nsobject<OmniboxGeolocationAuthorizationAlert> |
78 strongSelf([weakSelf retain]); | 82 strongSelf(weakSelf); |
79 if (strongSelf) { | 83 if (strongSelf) { |
80 [[strongSelf delegate] | 84 [[strongSelf delegate] |
81 authorizationAlertDidCancel:strongSelf]; | 85 authorizationAlertDidCancel:strongSelf]; |
82 } | 86 } |
83 }]; | 87 }]; |
84 [alert addAction:cancelAction]; | 88 [alert addAction:cancelAction]; |
85 | 89 |
86 [[[[UIApplication sharedApplication] keyWindow] rootViewController] | 90 [[[[UIApplication sharedApplication] keyWindow] rootViewController] |
87 presentViewController:alert | 91 presentViewController:alert |
88 animated:YES | 92 animated:YES |
89 completion:nil]; | 93 completion:nil]; |
90 } | 94 } |
91 | 95 |
92 @end | 96 @end |
OLD | NEW |