1// Copyright (c) 2012 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/certificate_viewer.h"
6
7#include "base/android/jni_string.h"
8#include "base/logging.h"
9#include "grit/generated_resources.h"
10#include "jni/CertificateViewer_jni.h"
11#include "net/cert/x509_certificate.h"
12#include "ui/base/l10n/l10n_util.h"
13
14using base::android::ConvertUTF8ToJavaString;
15using base::android::ScopedJavaLocalRef;
16
17void ShowCertificateViewer(content::WebContents* web_contents,
18                           gfx::NativeWindow parent,
19                           net::X509Certificate* cert) {
20  // For Android, showing the certificate is always handled in Java.
21  NOTREACHED();
22}
23
24static jstring GetCertIssuedToText(JNIEnv* env, jclass) {
25  return ConvertUTF8ToJavaString(
26      env, l10n_util::GetStringUTF8(IDS_CERT_INFO_SUBJECT_GROUP)).Release();
27}
28
29static jstring GetCertInfoCommonNameText(JNIEnv* env, jclass) {
30  return ConvertUTF8ToJavaString(
31      env, l10n_util::GetStringUTF8(IDS_CERT_INFO_COMMON_NAME_LABEL)).Release();
32}
33
34static jstring GetCertInfoOrganizationText(JNIEnv* env, jclass) {
35  return ConvertUTF8ToJavaString(
36      env, l10n_util::GetStringUTF8(
37          IDS_CERT_INFO_ORGANIZATION_LABEL)).Release();
38}
39
40static jstring GetCertInfoSerialNumberText(JNIEnv* env, jclass) {
41  return ConvertUTF8ToJavaString(
42      env, l10n_util::GetStringUTF8(
43          IDS_CERT_INFO_SERIAL_NUMBER_LABEL)).Release();
44}
45
46static jstring GetCertInfoOrganizationUnitText(JNIEnv* env, jclass) {
47  return ConvertUTF8ToJavaString(
48      env, l10n_util::GetStringUTF8(
49          IDS_CERT_INFO_ORGANIZATIONAL_UNIT_LABEL)).Release();
50}
51
52static jstring GetCertIssuedByText(JNIEnv* env, jclass) {
53  return ConvertUTF8ToJavaString(
54      env, l10n_util::GetStringUTF8(IDS_CERT_INFO_ISSUER_GROUP)).Release();
55}
56
57static jstring GetCertValidityText(JNIEnv* env, jclass) {
58  return ConvertUTF8ToJavaString(
59      env, l10n_util::GetStringUTF8(IDS_CERT_INFO_VALIDITY_GROUP)).Release();
60}
61
62static jstring GetCertIssuedOnText(JNIEnv* env, jclass) {
63  return ConvertUTF8ToJavaString(
64      env, l10n_util::GetStringUTF8(IDS_CERT_INFO_ISSUED_ON_LABEL)).Release();
65}
66
67static jstring GetCertExpiresOnText(JNIEnv* env, jclass) {
68  return ConvertUTF8ToJavaString(
69      env, l10n_util::GetStringUTF8(IDS_CERT_INFO_EXPIRES_ON_LABEL)).Release();
70}
71
72static jstring GetCertFingerprintsText(JNIEnv* env, jclass) {
73  return ConvertUTF8ToJavaString(
74      env, l10n_util::GetStringUTF8(
75          IDS_CERT_INFO_FINGERPRINTS_GROUP)).Release();
76}
77
78static jstring GetCertSHA256FingerprintText(JNIEnv* env, jclass) {
79  return ConvertUTF8ToJavaString(
80      env, l10n_util::GetStringUTF8(
81          IDS_CERT_INFO_SHA256_FINGERPRINT_LABEL)).Release();
82}
83
84static jstring GetCertSHA1FingerprintText(JNIEnv* env, jclass) {
85  return ConvertUTF8ToJavaString(
86      env, l10n_util::GetStringUTF8(
87          IDS_CERT_INFO_SHA1_FINGERPRINT_LABEL)).Release();
88}
89
90bool RegisterCertificateViewer(JNIEnv* env) {
91  return RegisterNativesImpl(env);
92}
93