Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / geolocation / omnibox_geolocation_authorization_alert.mm
blobcf345f276aa06d38a270a9ce7b5dca57ab8b6838
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>>
22       delegate_;
25 @end
27 @implementation OmniboxGeolocationAuthorizationAlert
29 - (instancetype)initWithDelegate:
30         (id<OmniboxGeolocationAuthorizationAlertDelegate>)delegate {
31   self = [super init];
32   if (self) {
33     delegate_.reset(delegate);
34   }
35   return self;
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 {
51   NSString* message =
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
60                                  message:message
61                                 delegate:self
62                        cancelButtonTitle:cancel
63                        otherButtonTitles:ok, nil]);
65   [alertView show];
68 #pragma mark - UIAlertViewDelegate
70 - (void)alertView:(UIAlertView*)alertView
71     clickedButtonAtIndex:(NSInteger)buttonIndex {
72   switch (buttonIndex) {
73     case 0:
74       [delegate_ authorizationAlertDidCancel:self];
75       break;
76     case 1:
77       [delegate_ authorizationAlertDidAuthorize:self];
78       break;
79     default:
80       NOTREACHED();
81       break;
82   }
85 @end