Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / password_manager / password_manager_util_mac.mm
blobe8d81cdc9db5c9dd7343bae363705dec155a62d9
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 "chrome/browser/password_manager/password_manager_util_mac.h"
7 #include <CoreFoundation/CoreFoundation.h>
8 #import <Foundation/Foundation.h>
9 #include <Security/Authorization.h>
11 #include "base/basictypes.h"
12 #include "base/mac/authorization_util.h"
13 #include "base/mac/bundle_locations.h"
14 #include "base/mac/foundation_util.h"
15 #include "base/mac/scoped_authorizationref.h"
16 #include "chrome/grit/chromium_strings.h"
17 #include "ui/base/l10n/l10n_util.h"
19 namespace password_manager_util_mac {
21 bool AuthenticateUser() {
22   NSString* identifier = [base::mac::MainBundle() bundleIdentifier];
23   AuthorizationString name =
24       [[identifier stringByAppendingString:@".show-passwords"] UTF8String];
25   AuthorizationItem right_items[] = {
26     {name, 0, NULL, 0}
27   };
28   AuthorizationRights rights = {arraysize(right_items), right_items};
30   NSString* prompt =
31       l10n_util::GetNSString(IDS_PASSWORDS_PAGE_AUTHENTICATION_PROMPT);
33   // Pass kAuthorizationFlagDestroyRights to prevent the OS from saving the
34   // authorization and not prompting the user when future requests are made.
35   base::mac::ScopedAuthorizationRef authorization(
36       base::mac::GetAuthorizationRightsWithPrompt(
37           &rights, base::mac::NSToCFCast(prompt),
38           kAuthorizationFlagDestroyRights));
39   return authorization.get() != NULL;
42 }  // namespace password_manager_util_mac