blob: cf345f276aa06d38a270a9ce7b5dca57ab8b6838 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/geolocation/omnibox_geolocation_authorization_alert.h"
#import <UIKit/UIKit.h>
#import "base/ios/weak_nsobject.h"
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
#include "ios/chrome/grit/ios_google_chrome_strings.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#include "ios/public/provider/chrome/browser/string_provider.h"
#include "ui/base/l10n/l10n_util_mac.h"
@interface OmniboxGeolocationAuthorizationAlert () <UIAlertViewDelegate> {
base::WeakNSProtocol<id<OmniboxGeolocationAuthorizationAlertDelegate>>
delegate_;
}
@end
@implementation OmniboxGeolocationAuthorizationAlert
- (instancetype)initWithDelegate:
(id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
self = [super init];
if (self) {
delegate_.reset(delegate);
}
return self;
}
- (instancetype)init {
return [self initWithDelegate:nil];
}
- (id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
return delegate_.get();
}
- (void)setDelegate:(id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
delegate_.reset(delegate);
}
- (void)showAuthorizationAlert {
NSString* message =
l10n_util::GetNSString(IDS_IOS_LOCATION_AUTHORIZATION_ALERT);
NSString* cancel = l10n_util::GetNSString(IDS_IOS_LOCATION_USAGE_CANCEL);
NSString* ok = base::SysUTF16ToNSString(
ios::GetChromeBrowserProvider()->GetStringProvider()->GetOKString());
// Use a UIAlertView to match the style of the iOS system location alert.
base::scoped_nsobject<UIAlertView> alertView(
[[UIAlertView alloc] initWithTitle:nil
message:message
delegate:self
cancelButtonTitle:cancel
otherButtonTitles:ok, nil]);
[alertView show];
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView*)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
[delegate_ authorizationAlertDidCancel:self];
break;
case 1:
[delegate_ authorizationAlertDidAuthorize:self];
break;
default:
NOTREACHED();
break;
}
}
@end
|