Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / android / connection_info_popup_android.cc
blobfad847545fce359f08f5cca2edcd53d0cbcd6016
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 jobjectArray GetCertificateChain(JNIEnv* env,
34 jobject obj,
35 jobject java_web_contents) {
36 content::WebContents* web_contents =
37 content::WebContents::FromJavaWebContents(java_web_contents);
38 if (!web_contents)
39 return NULL;
41 int cert_id =
42 web_contents->GetController().GetVisibleEntry()->GetSSL().cert_id;
43 scoped_refptr<net::X509Certificate> cert;
44 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert);
45 CHECK(ok);
47 std::vector<std::string> cert_chain;
48 net::X509Certificate::OSCertHandles cert_handles =
49 cert->GetIntermediateCertificates();
50 // Make sure the peer's own cert is the first in the chain, if it's not
51 // already there.
52 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle())
53 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle());
55 cert_chain.reserve(cert_handles.size());
56 for (net::X509Certificate::OSCertHandles::const_iterator it =
57 cert_handles.begin();
58 it != cert_handles.end();
59 ++it) {
60 std::string cert_bytes;
61 net::X509Certificate::GetDEREncoded(*it, &cert_bytes);
62 cert_chain.push_back(cert_bytes);
65 // OK to release, JNI binding.
66 return base::android::ToJavaArrayOfByteArray(env, cert_chain).Release();
69 // static
70 static jlong Init(JNIEnv* env,
71 jclass clazz,
72 jobject obj,
73 jobject java_web_contents) {
74 content::WebContents* web_contents =
75 content::WebContents::FromJavaWebContents(java_web_contents);
77 return reinterpret_cast<intptr_t>(
78 new ConnectionInfoPopupAndroid(env, obj, web_contents));
81 ConnectionInfoPopupAndroid::ConnectionInfoPopupAndroid(
82 JNIEnv* env,
83 jobject java_website_settings_pop,
84 WebContents* web_contents) {
85 // Important to use GetVisibleEntry to match what's showing in the omnibox.
86 content::NavigationEntry* nav_entry =
87 web_contents->GetController().GetVisibleEntry();
88 if (nav_entry == NULL)
89 return;
91 popup_jobject_.Reset(env, java_website_settings_pop);
93 presenter_.reset(new WebsiteSettings(
94 this,
95 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
96 TabSpecificContentSettings::FromWebContents(web_contents),
97 InfoBarService::FromWebContents(web_contents),
98 nav_entry->GetURL(),
99 nav_entry->GetSSL(),
100 content::CertStore::GetInstance()));
103 ConnectionInfoPopupAndroid::~ConnectionInfoPopupAndroid() {
106 void ConnectionInfoPopupAndroid::Destroy(JNIEnv* env, jobject obj) {
107 delete this;
110 void ConnectionInfoPopupAndroid::ResetCertDecisions(
111 JNIEnv* env,
112 jobject obj,
113 jobject java_web_contents) {
114 presenter_->OnRevokeSSLErrorBypassButtonPressed();
117 void ConnectionInfoPopupAndroid::SetIdentityInfo(
118 const IdentityInfo& identity_info) {
119 JNIEnv* env = base::android::AttachCurrentThread();
122 int icon_id = ResourceMapper::MapFromChromiumId(
123 WebsiteSettingsUI::GetIdentityIconID(identity_info.identity_status));
125 // The headline and the certificate dialog link of the site's identity
126 // section is only displayed if the site's identity was verified. If the
127 // site's identity was verified, then the headline contains the organization
128 // name from the provided certificate. If the organization name is not
129 // available than the hostname of the site is used instead.
130 std::string headline;
131 if (identity_info.cert_id) {
132 headline = identity_info.site_identity;
135 ScopedJavaLocalRef<jstring> description =
136 ConvertUTF8ToJavaString(env, identity_info.identity_status_description);
137 base::string16 certificate_label =
138 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON);
139 Java_ConnectionInfoPopup_addCertificateSection(
140 env,
141 popup_jobject_.obj(),
142 icon_id,
143 ConvertUTF8ToJavaString(env, headline).obj(),
144 description.obj(),
145 ConvertUTF16ToJavaString(env, certificate_label).obj());
147 if (identity_info.show_ssl_decision_revoke_button) {
148 base::string16 reset_button_label = l10n_util::GetStringUTF16(
149 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON);
150 Java_ConnectionInfoPopup_addResetCertDecisionsButton(
151 env,
152 popup_jobject_.obj(),
153 ConvertUTF16ToJavaString(env, reset_button_label).obj());
158 int icon_id = ResourceMapper::MapFromChromiumId(
159 WebsiteSettingsUI::GetConnectionIconID(
160 identity_info.connection_status));
162 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString(
163 env, identity_info.connection_status_description);
164 Java_ConnectionInfoPopup_addDescriptionSection(
165 env, popup_jobject_.obj(), icon_id, NULL, description.obj());
168 Java_ConnectionInfoPopup_addMoreInfoLink(
169 env,
170 popup_jobject_.obj(),
171 ConvertUTF8ToJavaString(
172 env, l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)).obj());
173 Java_ConnectionInfoPopup_showDialog(env, popup_jobject_.obj());
176 void ConnectionInfoPopupAndroid::SetCookieInfo(
177 const CookieInfoList& cookie_info_list) {
178 NOTIMPLEMENTED();
181 void ConnectionInfoPopupAndroid::SetPermissionInfo(
182 const PermissionInfoList& permission_info_list) {
183 NOTIMPLEMENTED();
186 void ConnectionInfoPopupAndroid::SetSelectedTab(
187 WebsiteSettingsUI::TabId tab_id) {
188 // There's no tab UI on Android - only connection info is shown.
189 NOTIMPLEMENTED();
192 void ConnectionInfoPopupAndroid::SetFirstVisit(
193 const base::string16& first_visit) {
194 NOTIMPLEMENTED();
197 // static
198 bool
199 ConnectionInfoPopupAndroid::RegisterConnectionInfoPopupAndroid(
200 JNIEnv* env) {
201 return RegisterNativesImpl(env);