Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / android / connection_info_popup_android.cc
blob9e41c35baaa233ef176b038e47b8329a6371ccc2
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/connection_info_popup_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h"
10 #include "chrome/browser/android/resource_mapper.h"
11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/website_settings/website_settings.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/cert_store.h"
17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/ssl_status.h"
21 #include "jni/ConnectionInfoPopup_jni.h"
22 #include "net/cert/x509_certificate.h"
23 #include "ui/base/l10n/l10n_util.h"
25 using base::android::CheckException;
26 using base::android::ConvertUTF8ToJavaString;
27 using base::android::ConvertUTF16ToJavaString;
28 using base::android::GetClass;
29 using base::android::ScopedJavaLocalRef;
30 using content::CertStore;
31 using content::WebContents;
33 static ScopedJavaLocalRef<jobjectArray>
34 GetCertificateChain(JNIEnv* env, jobject obj, jobject java_web_contents) {
35 content::WebContents* web_contents =
36 content::WebContents::FromJavaWebContents(java_web_contents);
37 if (!web_contents)
38 return ScopedJavaLocalRef<jobjectArray>();
40 int cert_id =
41 web_contents->GetController().GetVisibleEntry()->GetSSL().cert_id;
42 scoped_refptr<net::X509Certificate> cert;
43 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert);
44 CHECK(ok);
46 std::vector<std::string> cert_chain;
47 net::X509Certificate::OSCertHandles cert_handles =
48 cert->GetIntermediateCertificates();
49 // Make sure the peer's own cert is the first in the chain, if it's not
50 // already there.
51 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle())
52 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle());
54 cert_chain.reserve(cert_handles.size());
55 for (net::X509Certificate::OSCertHandles::const_iterator it =
56 cert_handles.begin();
57 it != cert_handles.end();
58 ++it) {
59 std::string cert_bytes;
60 net::X509Certificate::GetDEREncoded(*it, &cert_bytes);
61 cert_chain.push_back(cert_bytes);
64 return base::android::ToJavaArrayOfByteArray(env, cert_chain);
67 // static
68 static jlong Init(JNIEnv* env,
69 jclass clazz,
70 jobject obj,
71 jobject java_web_contents) {
72 content::WebContents* web_contents =
73 content::WebContents::FromJavaWebContents(java_web_contents);
75 return reinterpret_cast<intptr_t>(
76 new ConnectionInfoPopupAndroid(env, obj, web_contents));
79 ConnectionInfoPopupAndroid::ConnectionInfoPopupAndroid(
80 JNIEnv* env,
81 jobject java_website_settings_pop,
82 WebContents* web_contents) {
83 // Important to use GetVisibleEntry to match what's showing in the omnibox.
84 content::NavigationEntry* nav_entry =
85 web_contents->GetController().GetVisibleEntry();
86 if (nav_entry == NULL)
87 return;
89 popup_jobject_.Reset(env, java_website_settings_pop);
91 presenter_.reset(new WebsiteSettings(
92 this,
93 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
94 TabSpecificContentSettings::FromWebContents(web_contents),
95 web_contents,
96 nav_entry->GetURL(),
97 nav_entry->GetSSL(),
98 content::CertStore::GetInstance()));
101 ConnectionInfoPopupAndroid::~ConnectionInfoPopupAndroid() {
104 void ConnectionInfoPopupAndroid::Destroy(JNIEnv* env, jobject obj) {
105 delete this;
108 void ConnectionInfoPopupAndroid::ResetCertDecisions(
109 JNIEnv* env,
110 jobject obj,
111 jobject java_web_contents) {
112 presenter_->OnRevokeSSLErrorBypassButtonPressed();
115 void ConnectionInfoPopupAndroid::SetIdentityInfo(
116 const IdentityInfo& identity_info) {
117 JNIEnv* env = base::android::AttachCurrentThread();
120 int icon_id = ResourceMapper::MapFromChromiumId(
121 WebsiteSettingsUI::GetIdentityIconID(identity_info.identity_status));
123 // The headline and the certificate dialog link of the site's identity
124 // section is only displayed if the site's identity was verified. If the
125 // site's identity was verified, then the headline contains the organization
126 // name from the provided certificate. If the organization name is not
127 // available than the hostname of the site is used instead.
128 std::string headline;
129 if (identity_info.cert_id) {
130 headline = identity_info.site_identity;
133 ScopedJavaLocalRef<jstring> description =
134 ConvertUTF8ToJavaString(env, identity_info.identity_status_description);
135 base::string16 certificate_label =
136 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON);
137 Java_ConnectionInfoPopup_addCertificateSection(
138 env,
139 popup_jobject_.obj(),
140 icon_id,
141 ConvertUTF8ToJavaString(env, headline).obj(),
142 description.obj(),
143 ConvertUTF16ToJavaString(env, certificate_label).obj());
145 if (identity_info.show_ssl_decision_revoke_button) {
146 base::string16 reset_button_label = l10n_util::GetStringUTF16(
147 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON);
148 Java_ConnectionInfoPopup_addResetCertDecisionsButton(
149 env,
150 popup_jobject_.obj(),
151 ConvertUTF16ToJavaString(env, reset_button_label).obj());
156 int icon_id = ResourceMapper::MapFromChromiumId(
157 WebsiteSettingsUI::GetConnectionIconID(
158 identity_info.connection_status));
160 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString(
161 env, identity_info.connection_status_description);
162 Java_ConnectionInfoPopup_addDescriptionSection(
163 env, popup_jobject_.obj(), icon_id, NULL, description.obj());
166 Java_ConnectionInfoPopup_addMoreInfoLink(
167 env,
168 popup_jobject_.obj(),
169 ConvertUTF8ToJavaString(
170 env, l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)).obj());
171 Java_ConnectionInfoPopup_showDialog(env, popup_jobject_.obj());
174 void ConnectionInfoPopupAndroid::SetCookieInfo(
175 const CookieInfoList& cookie_info_list) {
176 NOTIMPLEMENTED();
179 void ConnectionInfoPopupAndroid::SetPermissionInfo(
180 const PermissionInfoList& permission_info_list) {
181 NOTIMPLEMENTED();
184 void ConnectionInfoPopupAndroid::SetSelectedTab(
185 WebsiteSettingsUI::TabId tab_id) {
186 // There's no tab UI on Android - only connection info is shown.
187 NOTIMPLEMENTED();
190 // static
191 bool
192 ConnectionInfoPopupAndroid::RegisterConnectionInfoPopupAndroid(
193 JNIEnv* env) {
194 return RegisterNativesImpl(env);