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.
5 #include "chrome/browser/ui/android/certificate_viewer_android.h"
7 #include "base/android/jni_string.h"
8 #include "base/logging.h"
9 #include "chrome/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"
14 using base::android::ConvertUTF8ToJavaString
;
15 using base::android::ScopedJavaLocalRef
;
17 void ShowCertificateViewer(content::WebContents
* web_contents
,
18 gfx::NativeWindow parent
,
19 net::X509Certificate
* cert
) {
20 // For Android, showing the certificate is always handled in Java.
24 static ScopedJavaLocalRef
<jstring
> GetCertIssuedToText(
26 const JavaParamRef
<jclass
>&) {
27 return ConvertUTF8ToJavaString(
28 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_SUBJECT_GROUP
));
31 static ScopedJavaLocalRef
<jstring
> GetCertInfoCommonNameText(
33 const JavaParamRef
<jclass
>&) {
34 return ConvertUTF8ToJavaString(
35 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_COMMON_NAME_LABEL
));
38 static ScopedJavaLocalRef
<jstring
> GetCertInfoOrganizationText(
40 const JavaParamRef
<jclass
>&) {
41 return ConvertUTF8ToJavaString(
42 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_ORGANIZATION_LABEL
));
45 static ScopedJavaLocalRef
<jstring
> GetCertInfoSerialNumberText(
47 const JavaParamRef
<jclass
>&) {
48 return ConvertUTF8ToJavaString(
49 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_SERIAL_NUMBER_LABEL
));
52 static ScopedJavaLocalRef
<jstring
> GetCertInfoOrganizationUnitText(
54 const JavaParamRef
<jclass
>&) {
55 return ConvertUTF8ToJavaString(
56 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_ORGANIZATIONAL_UNIT_LABEL
));
59 static ScopedJavaLocalRef
<jstring
> GetCertIssuedByText(
61 const JavaParamRef
<jclass
>&) {
62 return ConvertUTF8ToJavaString(
63 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_ISSUER_GROUP
));
66 static ScopedJavaLocalRef
<jstring
> GetCertValidityText(
68 const JavaParamRef
<jclass
>&) {
69 return ConvertUTF8ToJavaString(
70 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_VALIDITY_GROUP
));
73 static ScopedJavaLocalRef
<jstring
> GetCertIssuedOnText(
75 const JavaParamRef
<jclass
>&) {
76 return ConvertUTF8ToJavaString(
77 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_ISSUED_ON_LABEL
));
80 static ScopedJavaLocalRef
<jstring
> GetCertExpiresOnText(
82 const JavaParamRef
<jclass
>&) {
83 return ConvertUTF8ToJavaString(
84 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_EXPIRES_ON_LABEL
));
87 static ScopedJavaLocalRef
<jstring
> GetCertFingerprintsText(
89 const JavaParamRef
<jclass
>&) {
90 return ConvertUTF8ToJavaString(
91 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_FINGERPRINTS_GROUP
));
94 static ScopedJavaLocalRef
<jstring
> GetCertSHA256FingerprintText(
96 const JavaParamRef
<jclass
>&) {
97 return ConvertUTF8ToJavaString(
98 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_SHA256_FINGERPRINT_LABEL
));
101 static ScopedJavaLocalRef
<jstring
> GetCertSHA1FingerprintText(
103 const JavaParamRef
<jclass
>&) {
104 return ConvertUTF8ToJavaString(
105 env
, l10n_util::GetStringUTF8(IDS_CERT_INFO_SHA1_FINGERPRINT_LABEL
));
108 bool RegisterCertificateViewer(JNIEnv
* env
) {
109 return RegisterNativesImpl(env
);