diff options
author | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 22:55:27 +0000 |
---|---|---|
committer | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 22:55:27 +0000 |
commit | 8ae178b1da02c2ab5104060a711c305cb826221d (patch) | |
tree | ad8f723b09064d68239d6db01bf0c7532831137d /chrome/browser/cocoa | |
parent | 4fe95a617e494a2e279d9d623816f3e3b7aed944 (diff) | |
download | chromium_src-8ae178b1da02c2ab5104060a711c305cb826221d.zip chromium_src-8ae178b1da02c2ab5104060a711c305cb826221d.tar.gz chromium_src-8ae178b1da02c2ab5104060a711c305cb826221d.tar.bz2 |
Refactor certificate viewer code behind ShowCertificateViewer
This abstracts away the platform-specific certificate viewer behind a common
function call.
R=wtc,mattm
BUG=none
TEST=Viewing the certificate information on an SSL session continues to work
Review URL: http://codereview.chromium.org/2815024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/certificate_viewer.mm | 45 | ||||
-rw-r--r-- | chrome/browser/cocoa/page_info_window_mac.mm | 39 |
2 files changed, 47 insertions, 37 deletions
diff --git a/chrome/browser/cocoa/certificate_viewer.mm b/chrome/browser/cocoa/certificate_viewer.mm new file mode 100644 index 0000000..ed29ef4 --- /dev/null +++ b/chrome/browser/cocoa/certificate_viewer.mm @@ -0,0 +1,45 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/certificate_viewer.h" + +#include <Security/Security.h> +#include <SecurityInterface/SFCertificatePanel.h> + +#include <vector> + +#include "base/logging.h" +#include "base/scoped_cftyperef.h" +#include "net/base/x509_certificate.h" + +void ShowCertificateViewer(gfx::NativeWindow parent, + net::X509Certificate* cert) { + SecCertificateRef cert_mac = cert->os_cert_handle(); + if (!cert_mac) + return; + + scoped_cftyperef<CFMutableArrayRef> certificates( + CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); + if (!certificates.get()) { + NOTREACHED(); + return; + } + CFArrayAppendValue(certificates, cert_mac); + + // Server certificate must be first in the array; subsequent certificates + // in the chain can be in any order. + const std::vector<SecCertificateRef>& ca_certs = + cert->GetIntermediateCertificates(); + for (size_t i = 0; i < ca_certs.size(); ++i) + CFArrayAppendValue(certificates, ca_certs[i]); + + [[[SFCertificatePanel alloc] init] + beginSheetForWindow:parent + modalDelegate:nil + didEndSelector:NULL + contextInfo:NULL + certificates:reinterpret_cast<NSArray*>(certificates.get()) + showGroup:YES]; + // The SFCertificatePanel releases itself when the sheet is dismissed. +} diff --git a/chrome/browser/cocoa/page_info_window_mac.mm b/chrome/browser/cocoa/page_info_window_mac.mm index 5a4bddf..cc40b2e 100644 --- a/chrome/browser/cocoa/page_info_window_mac.mm +++ b/chrome/browser/cocoa/page_info_window_mac.mm @@ -5,8 +5,6 @@ #include "chrome/browser/cocoa/page_info_window_mac.h" #include <algorithm> -#include <Security/Security.h> -#include <SecurityInterface/SFCertificatePanel.h> #include "app/l10n_util.h" #include "base/scoped_cftyperef.h" @@ -16,6 +14,7 @@ #include "base/sys_string_conversions.h" #import "chrome/browser/cocoa/page_info_window_controller.h" #include "chrome/browser/cert_store.h" +#include "chrome/browser/certificate_viewer.h" #include "chrome/browser/profile.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -105,41 +104,7 @@ void PageInfoWindowMac::Show() { void PageInfoWindowMac::ShowCertDialog(int) { DCHECK(cert_id_ != 0); - scoped_refptr<net::X509Certificate> cert; - CertStore::GetSharedInstance()->RetrieveCert(cert_id_, &cert); - if (!cert.get()) { - // The certificate was not found. Could be that the renderer crashed before - // we displayed the page info. - return; - } - - SecCertificateRef cert_mac = cert->os_cert_handle(); - if (!cert_mac) - return; - - scoped_cftyperef<CFMutableArrayRef> certificates( - CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); - if (!certificates.get()) { - NOTREACHED(); - return; - } - CFArrayAppendValue(certificates, cert_mac); - - // Server certificate must be first in the array; subsequent certificates - // in the chain can be in any order. - const std::vector<SecCertificateRef>& ca_certs = - cert->GetIntermediateCertificates(); - for (size_t i = 0; i < ca_certs.size(); ++i) - CFArrayAppendValue(certificates, ca_certs[i]); - - [[[SFCertificatePanel alloc] init] - beginSheetForWindow:[controller_ window] - modalDelegate:nil - didEndSelector:NULL - contextInfo:NULL - certificates:reinterpret_cast<NSArray*>(certificates.get()) - showGroup:YES]; - // The SFCertificatePanel releases itself when the sheet is dismissed. + ShowCertificateViewerByID([controller_ window], cert_id_); } // This will create the subviews for the page info window. The general layout |