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
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/geolocation/omnibox_geolocation_authorization_alert.h"
7 #import <UIKit/UIKit.h>
9 #import "base/ios/weak_nsobject.h"
10 #include "base/logging.h"
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/strings/sys_string_conversions.h"
13 #include "ios/chrome/grit/ios_strings_resources.h"
14 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
15 #include "ios/public/provider/chrome/browser/string_provider.h"
16 #include "ui/base/l10n/l10n_util_mac.h"
18 @interface OmniboxGeolocationAuthorizationAlert () <UIAlertViewDelegate> {
19 base::WeakNSProtocol<id<OmniboxGeolocationAuthorizationAlertDelegate>>
25 @implementation OmniboxGeolocationAuthorizationAlert
27 - (instancetype)initWithDelegate:
28 (id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
31 delegate_.reset(delegate);
36 - (instancetype)init {
37 return [self initWithDelegate:nil];
40 - (id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
41 return delegate_.get();
44 - (void)setDelegate:(id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
45 delegate_.reset(delegate);
48 - (void)showAuthorizationAlert {
50 l10n_util::GetNSString(IDS_IOS_LOCATION_AUTHORIZATION_ALERT);
51 NSString* cancel = l10n_util::GetNSString(IDS_IOS_LOCATION_USAGE_CANCEL);
52 NSString* ok = base::SysUTF16ToNSString(
53 ios::GetChromeBrowserProvider()->GetStringProvider()->GetOKString());
55 // Use a UIAlertView to match the style of the iOS system location alert.
56 base::scoped_nsobject<UIAlertView> alertView(
57 [[UIAlertView alloc] initWithTitle:nil
60 cancelButtonTitle:cancel
61 otherButtonTitles:ok, nil]);
66 #pragma mark - UIAlertViewDelegate
68 - (void)alertView:(UIAlertView*)alertView
69 clickedButtonAtIndex:(NSInteger)buttonIndex {
70 switch (buttonIndex) {
72 [delegate_ authorizationAlertDidCancel:self];
75 [delegate_ authorizationAlertDidAuthorize:self];