OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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. |
| 4 |
| 5 #include "chrome/browser/ui/views/platform_keys_certificate_selector_chromeos.h" |
| 6 |
| 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "ui/base/l10n/l10n_util.h" |
| 12 |
| 13 namespace chromeos { |
| 14 |
| 15 PlatformKeysCertificateSelector::PlatformKeysCertificateSelector( |
| 16 const net::CertificateList& certificates, |
| 17 const std::string& extension_name, |
| 18 const CertificateSelectedCallback& callback, |
| 19 content::WebContents* web_contents) |
| 20 : CertificateSelector(certificates, web_contents), |
| 21 extension_name_(extension_name), |
| 22 callback_(callback) { |
| 23 } |
| 24 |
| 25 PlatformKeysCertificateSelector::~PlatformKeysCertificateSelector() { |
| 26 } |
| 27 |
| 28 void PlatformKeysCertificateSelector::Init() { |
| 29 const base::string16 text = |
| 30 l10n_util::GetStringFUTF16(IDS_PLATFORM_KEYS_SELECT_CERT_DIALOG_TEXT, |
| 31 base::ASCIIToUTF16(extension_name_)); |
| 32 CertificateSelector::InitWithText(text); |
| 33 } |
| 34 |
| 35 bool PlatformKeysCertificateSelector::Cancel() { |
| 36 callback_.Run(nullptr); |
| 37 return true; |
| 38 } |
| 39 |
| 40 bool PlatformKeysCertificateSelector::Accept() { |
| 41 scoped_refptr<net::X509Certificate> cert = GetSelectedCert(); |
| 42 if (!cert) |
| 43 return false; |
| 44 callback_.Run(cert); |
| 45 return true; |
| 46 } |
| 47 |
| 48 void ShowPlatformKeysCertificateSelector( |
| 49 content::WebContents* web_contents, |
| 50 const std::string& extension_name, |
| 51 const net::CertificateList& certificates, |
| 52 const base::Callback<void(const scoped_refptr<net::X509Certificate>&)>& |
| 53 callback) { |
| 54 PlatformKeysCertificateSelector* selector = |
| 55 new PlatformKeysCertificateSelector(certificates, extension_name, |
| 56 callback, web_contents); |
| 57 selector->Init(); |
| 58 selector->Show(); |
| 59 } |
| 60 |
| 61 } // namespace chromeos |
OLD | NEW |