summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-07 22:55:27 +0000
committerdavidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-07 22:55:27 +0000
commit8ae178b1da02c2ab5104060a711c305cb826221d (patch)
treead8f723b09064d68239d6db01bf0c7532831137d
parent4fe95a617e494a2e279d9d623816f3e3b7aed944 (diff)
downloadchromium_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
-rw-r--r--chrome/browser/certificate_viewer.cc18
-rw-r--r--chrome/browser/certificate_viewer.h24
-rw-r--r--chrome/browser/cocoa/certificate_viewer.mm45
-rw-r--r--chrome/browser/cocoa/page_info_window_mac.mm39
-rw-r--r--chrome/browser/gtk/certificate_viewer.cc12
-rw-r--r--chrome/browser/gtk/certificate_viewer.h2
-rw-r--r--chrome/browser/gtk/page_info_window_gtk.cc4
-rw-r--r--chrome/browser/ssl/ssl_client_auth_handler_gtk.cc5
-rw-r--r--chrome/browser/views/certificate_viewer_win.cc32
-rw-r--r--chrome/browser/views/page_info_window_view.cc41
-rw-r--r--chrome/chrome_browser.gypi4
11 files changed, 135 insertions, 91 deletions
diff --git a/chrome/browser/certificate_viewer.cc b/chrome/browser/certificate_viewer.cc
new file mode 100644
index 0000000..677c81f
--- /dev/null
+++ b/chrome/browser/certificate_viewer.cc
@@ -0,0 +1,18 @@
+// 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 "chrome/browser/cert_store.h"
+
+void ShowCertificateViewerByID(gfx::NativeWindow parent, int cert_id) {
+ 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;
+ }
+ ShowCertificateViewer(parent, cert);
+}
diff --git a/chrome/browser/certificate_viewer.h b/chrome/browser/certificate_viewer.h
new file mode 100644
index 0000000..e0ba0c7
--- /dev/null
+++ b/chrome/browser/certificate_viewer.h
@@ -0,0 +1,24 @@
+// 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.
+
+#ifndef CHROME_BROWSER_CERTIFICATE_VIEWER_H_
+#define CHROME_BROWSER_CERTIFICATE_VIEWER_H_
+
+#include "gfx/native_widget_types.h"
+
+namespace net {
+
+class X509Certificate;
+
+} // namespace net
+
+// Opens a certificate viewer under |parent| to display the certificate from
+// the |CertStore| with id |cert_id|.
+void ShowCertificateViewerByID(gfx::NativeWindow parent, int cert_id);
+
+// Opens a certificate viewer under |parent| to display |cert|.
+void ShowCertificateViewer(gfx::NativeWindow parent,
+ net::X509Certificate* cert);
+
+#endif // CHROME_BROWSER_CERTIFICATE_VIEWER_H_
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
diff --git a/chrome/browser/gtk/certificate_viewer.cc b/chrome/browser/gtk/certificate_viewer.cc
index c1e98d4..bb9312d 100644
--- a/chrome/browser/gtk/certificate_viewer.cc
+++ b/chrome/browser/gtk/certificate_viewer.cc
@@ -20,13 +20,13 @@
#include "base/string_util.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/cert_store.h"
#include "chrome/browser/gtk/certificate_dialogs.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h"
#include "chrome/third_party/mozilla_security_manager/nsNSSCertificate.h"
#include "chrome/third_party/mozilla_security_manager/nsUsageArrayHelper.h"
#include "grit/generated_resources.h"
+#include "net/base/x509_certificate.h"
// PSM = Mozilla's Personal Security Manager.
namespace psm = mozilla_security_manager;
@@ -732,13 +732,7 @@ void ShowCertificateViewer(gfx::NativeWindow parent, CERTCertificate* cert) {
(new CertificateViewer(parent, cert_chain))->Show();
}
-void ShowCertificateViewer(gfx::NativeWindow parent, int cert_id) {
- 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;
- }
+void ShowCertificateViewer(gfx::NativeWindow parent,
+ net::X509Certificate* cert) {
ShowCertificateViewer(parent, cert->os_cert_handle());
}
diff --git a/chrome/browser/gtk/certificate_viewer.h b/chrome/browser/gtk/certificate_viewer.h
index 4f801c3..24e69b9 100644
--- a/chrome/browser/gtk/certificate_viewer.h
+++ b/chrome/browser/gtk/certificate_viewer.h
@@ -5,11 +5,11 @@
#ifndef CHROME_BROWSER_GTK_CERTIFICATE_VIEWER_H_
#define CHROME_BROWSER_GTK_CERTIFICATE_VIEWER_H_
+#include "chrome/browser/certificate_viewer.h"
#include "gfx/native_widget_types.h"
typedef struct CERTCertificateStr CERTCertificate;
void ShowCertificateViewer(gfx::NativeWindow parent, CERTCertificate* cert);
-void ShowCertificateViewer(gfx::NativeWindow parent, int cert_id);
#endif // CHROME_BROWSER_GTK_CERTIFICATE_VIEWER_H_
diff --git a/chrome/browser/gtk/page_info_window_gtk.cc b/chrome/browser/gtk/page_info_window_gtk.cc
index 1409a89..ada3f81 100644
--- a/chrome/browser/gtk/page_info_window_gtk.cc
+++ b/chrome/browser/gtk/page_info_window_gtk.cc
@@ -10,7 +10,7 @@
#include "app/resource_bundle.h"
#include "base/compiler_specific.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/gtk/certificate_viewer.h"
+#include "chrome/browser/certificate_viewer.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/browser/page_info_model.h"
#include "chrome/browser/page_info_window.h"
@@ -192,7 +192,7 @@ void PageInfoWindowGtk::Show() {
}
void PageInfoWindowGtk::ShowCertDialog() {
- ShowCertificateViewer(GTK_WINDOW(dialog_), cert_id_);
+ ShowCertificateViewerByID(GTK_WINDOW(dialog_), cert_id_);
}
} // namespace
diff --git a/chrome/browser/ssl/ssl_client_auth_handler_gtk.cc b/chrome/browser/ssl/ssl_client_auth_handler_gtk.cc
index 72f332a..1045ef9 100644
--- a/chrome/browser/ssl/ssl_client_auth_handler_gtk.cc
+++ b/chrome/browser/ssl/ssl_client_auth_handler_gtk.cc
@@ -15,7 +15,7 @@
#include "base/logging.h"
#include "base/nss_util.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/gtk/certificate_viewer.h"
+#include "chrome/browser/certificate_viewer.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h"
#include "chrome/third_party/mozilla_security_manager/nsNSSCertificate.h"
@@ -305,8 +305,7 @@ void SSLClientCertificateSelector::OnResponse(
}
if (response_id == RESPONSE_SHOW_CERT_INFO) {
if (cert)
- ShowCertificateViewer(GTK_WINDOW(cert_selector->dialog_),
- cert->os_cert_handle());
+ ShowCertificateViewer(GTK_WINDOW(cert_selector->dialog_), cert);
return;
}
cert_selector->delegate_->CertificateSelected(cert);
diff --git a/chrome/browser/views/certificate_viewer_win.cc b/chrome/browser/views/certificate_viewer_win.cc
new file mode 100644
index 0000000..ba54267
--- /dev/null
+++ b/chrome/browser/views/certificate_viewer_win.cc
@@ -0,0 +1,32 @@
+// 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 <windows.h>
+#include <cryptuiapi.h>
+#pragma comment(lib, "cryptui.lib")
+
+#include "net/base/x509_certificate.h"
+
+void ShowCertificateViewer(gfx::NativeWindow parent,
+ net::X509Certificate* cert) {
+ CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = { 0 };
+ view_info.dwSize = sizeof(view_info);
+ // We set our parent to the tab window. This makes the cert dialog created
+ // in CryptUIDlgViewCertificate modal to the browser.
+ view_info.hwndParent = parent;
+ view_info.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES |
+ CRYPTUI_DISABLE_ADDTOSTORE;
+ view_info.pCertContext = cert->os_cert_handle();
+ // Search the cert store that 'cert' is in when building the cert chain.
+ HCERTSTORE cert_store = view_info.pCertContext->hCertStore;
+ view_info.cStores = 1;
+ view_info.rghStores = &cert_store;
+ BOOL properties_changed;
+
+ // This next call blocks but keeps processing windows messages, making it
+ // modal to the browser window.
+ BOOL rv = ::CryptUIDlgViewCertificate(&view_info, &properties_changed);
+}
diff --git a/chrome/browser/views/page_info_window_view.cc b/chrome/browser/views/page_info_window_view.cc
index 80d0db1..dbc790c 100644
--- a/chrome/browser/views/page_info_window_view.cc
+++ b/chrome/browser/views/page_info_window_view.cc
@@ -4,17 +4,12 @@
#include "build/build_config.h"
-#if defined(OS_WIN)
-#include <windows.h>
-#include <cryptuiapi.h>
-#pragma comment(lib, "cryptui.lib")
-#endif
-
#include "app/resource_bundle.h"
#include "app/l10n_util.h"
#include "base/compiler_specific.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/cert_store.h"
+#include "chrome/browser/certificate_viewer.h"
#include "chrome/browser/page_info_model.h"
#include "chrome/browser/page_info_window.h"
#include "chrome/common/pref_names.h"
@@ -35,8 +30,6 @@
#if defined(OS_WIN)
#include "app/win_util.h"
-#elif defined(OS_LINUX)
-#include "chrome/browser/gtk/certificate_viewer.h"
#endif
namespace {
@@ -333,37 +326,7 @@ void PageInfoWindowView::CalculateWindowBounds(gfx::Rect* bounds) {
}
void PageInfoWindowView::ShowCertDialog(int cert_id) {
-#if defined(OS_WIN)
- 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;
- }
-
- CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = { 0 };
- view_info.dwSize = sizeof(view_info);
- // We set our parent to the tab window. This makes the cert dialog created
- // in CryptUIDlgViewCertificate modal to the browser.
- view_info.hwndParent = window()->GetNativeWindow();
- view_info.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES |
- CRYPTUI_DISABLE_ADDTOSTORE;
- view_info.pCertContext = cert->os_cert_handle();
- // Search the cert store that 'cert' is in when building the cert chain.
- HCERTSTORE cert_store = view_info.pCertContext->hCertStore;
- view_info.cStores = 1;
- view_info.rghStores = &cert_store;
- BOOL properties_changed;
-
- // This next call blocks but keeps processing windows messages, making it
- // modal to the browser window.
- BOOL rv = ::CryptUIDlgViewCertificate(&view_info, &properties_changed);
-#elif defined(OS_LINUX)
- ShowCertificateViewer(window()->GetNativeWindow(), cert_id);
-#else
- NOTIMPLEMENTED();
-#endif
+ ShowCertificateViewerByID(window()->GetNativeWindow(), cert_id);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index d825f4e..46de2ad 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -317,6 +317,8 @@
'browser/cancelable_request.h',
'browser/cert_store.cc',
'browser/cert_store.h',
+ 'browser/certificate_viewer.cc',
+ 'browser/certificate_viewer.h',
'browser/character_encoding.cc',
'browser/character_encoding.h',
'browser/child_process_launcher.cc',
@@ -668,6 +670,7 @@
'browser/cocoa/bubble_view.mm',
'browser/cocoa/bug_report_window_controller.h',
'browser/cocoa/bug_report_window_controller.mm',
+ 'browser/cocoa/certificate_viewer.mm',
'browser/cocoa/chrome_browser_window.h',
'browser/cocoa/chrome_browser_window.mm',
'browser/cocoa/chrome_event_processing_window.h',
@@ -2408,6 +2411,7 @@
'browser/views/bubble_border.h',
'browser/views/bug_report_view.cc',
'browser/views/bug_report_view.h',
+ 'browser/views/certificate_viewer_win.cc',
'browser/views/chrome_views_delegate.cc',
'browser/views/chrome_views_delegate.h',
'browser/views/clear_browsing_data.cc',