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_chromium_strings.h"
14 #include "ios/chrome/grit/ios_google_chrome_strings.h"
15 #include "ios/chrome/grit/ios_strings.h"
16 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
17 #include "ios/public/provider/chrome/browser/string_provider.h"
18 #include "ui/base/l10n/l10n_util_mac.h"
20 @interface OmniboxGeolocationAuthorizationAlert () <UIAlertViewDelegate> {
21 base::WeakNSProtocol<id<OmniboxGeolocationAuthorizationAlertDelegate>>
27 @implementation OmniboxGeolocationAuthorizationAlert
29 - (instancetype)initWithDelegate:
30 (id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
33 delegate_.reset(delegate);
38 - (instancetype)init {
39 return [self initWithDelegate:nil];
42 - (id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
43 return delegate_.get();
46 - (void)setDelegate:(id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
47 delegate_.reset(delegate);
50 - (void)showAuthorizationAlert {
52 l10n_util::GetNSString(IDS_IOS_LOCATION_AUTHORIZATION_ALERT);
53 NSString* cancel = l10n_util::GetNSString(IDS_IOS_LOCATION_USAGE_CANCEL);
54 NSString* ok = base::SysUTF16ToNSString(
55 ios::GetChromeBrowserProvider()->GetStringProvider()->GetOKString());
57 // Use a UIAlertView to match the style of the iOS system location alert.
58 base::scoped_nsobject<UIAlertView> alertView(
59 [[UIAlertView alloc] initWithTitle:nil
62 cancelButtonTitle:cancel
63 otherButtonTitles:ok, nil]);
68 #pragma mark - UIAlertViewDelegate
70 - (void)alertView:(UIAlertView*)alertView
71 clickedButtonAtIndex:(NSInteger)buttonIndex {
72 switch (buttonIndex) {
74 [delegate_ authorizationAlertDidCancel:self];
77 [delegate_ authorizationAlertDidAuthorize:self];