| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 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/ui/android/website_settings_popup_legacy_android.h" | |
| 6 | |
| 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/WebsiteSettingsPopupLegacy_jni.h" | |
| 22 #include "net/cert/x509_certificate.h" | |
| 23 #include "ui/base/l10n/l10n_util.h" | |
| 24 | |
| 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; | |
| 32 | |
| 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; | |
| 40 | |
| 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); | |
| 46 | |
| 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()); | |
| 54 | |
| 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); | |
| 63 } | |
| 64 | |
| 65 // OK to release, JNI binding. | |
| 66 return base::android::ToJavaArrayOfByteArray(env, cert_chain).Release(); | |
| 67 } | |
| 68 | |
| 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); | |
| 76 | |
| 77 return reinterpret_cast<intptr_t>( | |
| 78 new WebsiteSettingsPopupLegacyAndroid(env, obj, web_contents)); | |
| 79 } | |
| 80 | |
| 81 WebsiteSettingsPopupLegacyAndroid::WebsiteSettingsPopupLegacyAndroid( | |
| 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; | |
| 90 | |
| 91 popup_jobject_.Reset(env, java_website_settings_pop); | |
| 92 | |
| 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())); | |
| 101 } | |
| 102 | |
| 103 WebsiteSettingsPopupLegacyAndroid::~WebsiteSettingsPopupLegacyAndroid() { | |
| 104 } | |
| 105 | |
| 106 void WebsiteSettingsPopupLegacyAndroid::Destroy(JNIEnv* env, jobject obj) { | |
| 107 delete this; | |
| 108 } | |
| 109 | |
| 110 void WebsiteSettingsPopupLegacyAndroid::ResetCertDecisions( | |
| 111 JNIEnv* env, | |
| 112 jobject obj, | |
| 113 jobject java_web_contents) { | |
| 114 presenter_->OnRevokeSSLErrorBypassButtonPressed(); | |
| 115 } | |
| 116 | |
| 117 void WebsiteSettingsPopupLegacyAndroid::SetIdentityInfo( | |
| 118 const IdentityInfo& identity_info) { | |
| 119 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 120 | |
| 121 { | |
| 122 int icon_id = ResourceMapper::MapFromChromiumId( | |
| 123 WebsiteSettingsUI::GetIdentityIconID(identity_info.identity_status)); | |
| 124 | |
| 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; | |
| 133 } | |
| 134 | |
| 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_WebsiteSettingsPopupLegacy_addCertificateSection( | |
| 140 env, | |
| 141 popup_jobject_.obj(), | |
| 142 icon_id, | |
| 143 ConvertUTF8ToJavaString(env, headline).obj(), | |
| 144 description.obj(), | |
| 145 ConvertUTF16ToJavaString(env, certificate_label).obj()); | |
| 146 | |
| 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_WebsiteSettingsPopupLegacy_addResetCertDecisionsButton( | |
| 151 env, | |
| 152 popup_jobject_.obj(), | |
| 153 ConvertUTF16ToJavaString(env, reset_button_label).obj()); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 { | |
| 158 int icon_id = ResourceMapper::MapFromChromiumId( | |
| 159 WebsiteSettingsUI::GetConnectionIconID( | |
| 160 identity_info.connection_status)); | |
| 161 | |
| 162 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString( | |
| 163 env, identity_info.connection_status_description); | |
| 164 Java_WebsiteSettingsPopupLegacy_addDescriptionSection( | |
| 165 env, popup_jobject_.obj(), icon_id, NULL, description.obj()); | |
| 166 } | |
| 167 | |
| 168 Java_WebsiteSettingsPopupLegacy_addMoreInfoLink( | |
| 169 env, | |
| 170 popup_jobject_.obj(), | |
| 171 ConvertUTF8ToJavaString( | |
| 172 env, l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)).obj()); | |
| 173 Java_WebsiteSettingsPopupLegacy_showDialog(env, popup_jobject_.obj()); | |
| 174 } | |
| 175 | |
| 176 void WebsiteSettingsPopupLegacyAndroid::SetCookieInfo( | |
| 177 const CookieInfoList& cookie_info_list) { | |
| 178 NOTIMPLEMENTED(); | |
| 179 } | |
| 180 | |
| 181 void WebsiteSettingsPopupLegacyAndroid::SetPermissionInfo( | |
| 182 const PermissionInfoList& permission_info_list) { | |
| 183 NOTIMPLEMENTED(); | |
| 184 } | |
| 185 | |
| 186 void WebsiteSettingsPopupLegacyAndroid::SetSelectedTab( | |
| 187 WebsiteSettingsUI::TabId tab_id) { | |
| 188 // There's no tab UI on Android - only connection info is shown. | |
| 189 NOTIMPLEMENTED(); | |
| 190 } | |
| 191 | |
| 192 void WebsiteSettingsPopupLegacyAndroid::SetFirstVisit( | |
| 193 const base::string16& first_visit) { | |
| 194 NOTIMPLEMENTED(); | |
| 195 } | |
| 196 | |
| 197 // static | |
| 198 bool | |
| 199 WebsiteSettingsPopupLegacyAndroid::RegisterWebsiteSettingsPopupLegacyAndroid( | |
| 200 JNIEnv* env) { | |
| 201 return RegisterNativesImpl(env); | |
| 202 } | |
| OLD | NEW |