| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/android/website_settings_popup_android.h" | 5 #include "chrome/browser/ui/android/website_settings_popup_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "chrome/browser/android/resource_mapper.h" | |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | |
| 14 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" | |
| 15 #include "chrome/browser/ui/website_settings/website_settings.h" | 12 #include "chrome/browser/ui/website_settings/website_settings.h" |
| 16 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
| 14 #include "components/content_settings/core/common/content_settings_types.h" |
| 17 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/cert_store.h" | 16 #include "content/public/browser/cert_store.h" |
| 19 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 20 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 21 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/ssl_status.h" | |
| 23 #include "jni/WebsiteSettingsPopup_jni.h" | 20 #include "jni/WebsiteSettingsPopup_jni.h" |
| 24 #include "net/cert/x509_certificate.h" | |
| 25 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 26 | 22 |
| 27 using base::android::CheckException; | 23 using base::android::ConvertUTF16ToJavaString; |
| 28 using base::android::ConvertUTF8ToJavaString; | 24 using base::android::ConvertUTF8ToJavaString; |
| 29 using base::android::ConvertUTF16ToJavaString; | |
| 30 using base::android::GetClass; | |
| 31 using base::android::ScopedJavaLocalRef; | |
| 32 using content::CertStore; | |
| 33 using content::WebContents; | |
| 34 | |
| 35 static jobjectArray GetCertificateChain(JNIEnv* env, | |
| 36 jobject obj, | |
| 37 jobject java_web_contents) { | |
| 38 content::WebContents* web_contents = | |
| 39 content::WebContents::FromJavaWebContents(java_web_contents); | |
| 40 if (!web_contents) | |
| 41 return NULL; | |
| 42 | |
| 43 int cert_id = | |
| 44 web_contents->GetController().GetVisibleEntry()->GetSSL().cert_id; | |
| 45 scoped_refptr<net::X509Certificate> cert; | |
| 46 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert); | |
| 47 CHECK(ok); | |
| 48 | |
| 49 std::vector<std::string> cert_chain; | |
| 50 net::X509Certificate::OSCertHandles cert_handles = | |
| 51 cert->GetIntermediateCertificates(); | |
| 52 // Make sure the peer's own cert is the first in the chain, if it's not | |
| 53 // already there. | |
| 54 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle()) | |
| 55 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle()); | |
| 56 | |
| 57 cert_chain.reserve(cert_handles.size()); | |
| 58 for (net::X509Certificate::OSCertHandles::const_iterator it = | |
| 59 cert_handles.begin(); | |
| 60 it != cert_handles.end(); | |
| 61 ++it) { | |
| 62 std::string cert_bytes; | |
| 63 net::X509Certificate::GetDEREncoded(*it, &cert_bytes); | |
| 64 cert_chain.push_back(cert_bytes); | |
| 65 } | |
| 66 | |
| 67 // OK to release, JNI binding. | |
| 68 return base::android::ToJavaArrayOfByteArray(env, cert_chain).Release(); | |
| 69 } | |
| 70 | 25 |
| 71 // static | 26 // static |
| 72 static jlong Init(JNIEnv* env, | 27 static jlong Init(JNIEnv* env, |
| 73 jclass clazz, | 28 jclass clazz, |
| 74 jobject obj, | 29 jobject obj, |
| 75 jobject java_web_contents) { | 30 jobject java_web_contents) { |
| 76 content::WebContents* web_contents = | 31 content::WebContents* web_contents = |
| 77 content::WebContents::FromJavaWebContents(java_web_contents); | 32 content::WebContents::FromJavaWebContents(java_web_contents); |
| 78 | 33 |
| 79 return reinterpret_cast<intptr_t>( | 34 return reinterpret_cast<intptr_t>( |
| 80 new WebsiteSettingsPopupAndroid(env, obj, web_contents)); | 35 new WebsiteSettingsPopupAndroid(env, obj, web_contents)); |
| 81 } | 36 } |
| 82 | 37 |
| 83 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid( | 38 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid( |
| 84 JNIEnv* env, | 39 JNIEnv* env, |
| 85 jobject java_website_settings_pop, | 40 jobject java_website_settings_pop, |
| 86 WebContents* web_contents) { | 41 content::WebContents* web_contents) { |
| 87 // Important to use GetVisibleEntry to match what's showing in the omnibox. | 42 // Important to use GetVisibleEntry to match what's showing in the omnibox. |
| 88 content::NavigationEntry* nav_entry = | 43 content::NavigationEntry* nav_entry = |
| 89 web_contents->GetController().GetVisibleEntry(); | 44 web_contents->GetController().GetVisibleEntry(); |
| 90 if (nav_entry == NULL) | 45 if (nav_entry == NULL) |
| 91 return; | 46 return; |
| 92 | 47 |
| 48 url_ = nav_entry->GetURL(); |
| 49 |
| 93 popup_jobject_.Reset(env, java_website_settings_pop); | 50 popup_jobject_.Reset(env, java_website_settings_pop); |
| 94 | 51 |
| 95 presenter_.reset(new WebsiteSettings( | 52 presenter_.reset(new WebsiteSettings( |
| 96 this, | 53 this, |
| 97 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 54 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
| 98 TabSpecificContentSettings::FromWebContents(web_contents), | 55 TabSpecificContentSettings::FromWebContents(web_contents), |
| 99 InfoBarService::FromWebContents(web_contents), | 56 InfoBarService::FromWebContents(web_contents), |
| 100 nav_entry->GetURL(), | 57 nav_entry->GetURL(), |
| 101 nav_entry->GetSSL(), | 58 nav_entry->GetSSL(), |
| 102 content::CertStore::GetInstance())); | 59 content::CertStore::GetInstance())); |
| 103 } | 60 } |
| 104 | 61 |
| 105 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {} | 62 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {} |
| 106 | 63 |
| 107 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) { | 64 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) { |
| 108 delete this; | 65 delete this; |
| 109 } | 66 } |
| 110 | 67 |
| 111 void WebsiteSettingsPopupAndroid::ResetCertDecisions( | |
| 112 JNIEnv* env, | |
| 113 jobject obj, | |
| 114 jobject java_web_contents) { | |
| 115 content::WebContents* web_contents = | |
| 116 content::WebContents::FromJavaWebContents(java_web_contents); | |
| 117 if (!web_contents) | |
| 118 return; | |
| 119 ChromeSSLHostStateDelegate* delegate = | |
| 120 presenter_->chrome_ssl_host_state_delegate(); | |
| 121 DCHECK(delegate); | |
| 122 delegate->RevokeUserDecisionsHard(presenter_->site_url().host()); | |
| 123 } | |
| 124 | |
| 125 void WebsiteSettingsPopupAndroid::SetIdentityInfo( | 68 void WebsiteSettingsPopupAndroid::SetIdentityInfo( |
| 126 const IdentityInfo& identity_info) { | 69 const IdentityInfo& identity_info) { |
| 127 JNIEnv* env = base::android::AttachCurrentThread(); | 70 JNIEnv* env = base::android::AttachCurrentThread(); |
| 128 | 71 |
| 129 { | 72 enum PageInfoConnectionType connection_type = PAGE_INFO_CONNECTION_UNKNOWN; |
| 130 int icon_id = ResourceMapper::MapFromChromiumId( | 73 switch (identity_info.connection_status) { |
| 131 WebsiteSettingsUI::GetIdentityIconID(identity_info.identity_status)); | 74 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN: |
| 132 | 75 connection_type = PAGE_INFO_CONNECTION_UNKNOWN; |
| 133 // The headline and the certificate dialog link of the site's identity | 76 break; |
| 134 // section is only displayed if the site's identity was verified. If the | 77 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED: |
| 135 // site's identity was verified, then the headline contains the organization | 78 connection_type = PAGE_INFO_CONNECTION_ENCRYPTED; |
| 136 // name from the provided certificate. If the organization name is not | 79 break; |
| 137 // available than the hostname of the site is used instead. | 80 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT: |
| 138 std::string headline; | 81 connection_type = PAGE_INFO_CONNECTION_MIXED_CONTENT; |
| 139 if (identity_info.cert_id) { | 82 break; |
| 140 headline = identity_info.site_identity; | 83 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED: |
| 141 } | 84 connection_type = PAGE_INFO_CONNECTION_UNENCRYPTED; |
| 142 | 85 break; |
| 143 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString( | 86 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR: |
| 144 env, identity_info.identity_status_description); | 87 connection_type = PAGE_INFO_CONNECTION_ENCRYPTED_ERROR; |
| 145 base::string16 certificate_label = | 88 break; |
| 146 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON); | 89 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE: |
| 147 Java_WebsiteSettingsPopup_addCertificateSection( | 90 connection_type = PAGE_INFO_CONNECTION_INTERNAL_PAGE; |
| 148 env, | 91 break; |
| 149 popup_jobject_.obj(), | 92 default: |
| 150 icon_id, | 93 NOTREACHED(); |
| 151 ConvertUTF8ToJavaString(env, headline).obj(), | 94 break; |
| 152 description.obj(), | |
| 153 ConvertUTF16ToJavaString(env, certificate_label).obj()); | |
| 154 | |
| 155 if (identity_info.show_ssl_decision_revoke_button) { | |
| 156 base::string16 reset_button_label = l10n_util::GetStringUTF16( | |
| 157 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON); | |
| 158 Java_WebsiteSettingsPopup_addResetCertDecisionsButton( | |
| 159 env, | |
| 160 popup_jobject_.obj(), | |
| 161 ConvertUTF16ToJavaString(env, reset_button_label).obj()); | |
| 162 } | |
| 163 } | 95 } |
| 164 | 96 |
| 165 { | 97 Java_WebsiteSettingsPopup_setURLTitle( |
| 166 int icon_id = ResourceMapper::MapFromChromiumId( | 98 env, |
| 167 WebsiteSettingsUI::GetConnectionIconID( | 99 popup_jobject_.obj(), |
| 168 identity_info.connection_status)); | 100 ConvertUTF8ToJavaString(env, url_.scheme()).obj(), |
| 101 ConvertUTF8ToJavaString(env, url_.host()).obj(), |
| 102 ConvertUTF8ToJavaString(env, url_.path()).obj(), |
| 103 static_cast<jint>(connection_type)); |
| 169 | 104 |
| 170 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString( | 105 Java_WebsiteSettingsPopup_setConnectionMessage( |
| 171 env, identity_info.connection_status_description); | 106 env, |
| 172 Java_WebsiteSettingsPopup_addDescriptionSection( | 107 popup_jobject_.obj(), |
| 173 env, popup_jobject_.obj(), icon_id, NULL, description.obj()); | 108 ConvertUTF16ToJavaString( |
| 174 } | 109 env, |
| 110 l10n_util::GetStringUTF16( |
| 111 WebsiteSettingsUI::GetConnectionSummaryMessageID( |
| 112 identity_info.connection_status))).obj()); |
| 175 | 113 |
| 176 Java_WebsiteSettingsPopup_addMoreInfoLink(env, popup_jobject_.obj(), | |
| 177 ConvertUTF8ToJavaString( | |
| 178 env, l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)).obj()); | |
| 179 Java_WebsiteSettingsPopup_showDialog(env, popup_jobject_.obj()); | 114 Java_WebsiteSettingsPopup_showDialog(env, popup_jobject_.obj()); |
| 180 } | 115 } |
| 181 | 116 |
| 182 void WebsiteSettingsPopupAndroid::SetCookieInfo( | 117 void WebsiteSettingsPopupAndroid::SetCookieInfo( |
| 183 const CookieInfoList& cookie_info_list) { | 118 const CookieInfoList& cookie_info_list) { |
| 184 NOTIMPLEMENTED(); | 119 NOTIMPLEMENTED(); |
| 185 } | 120 } |
| 186 | 121 |
| 187 void WebsiteSettingsPopupAndroid::SetPermissionInfo( | 122 void WebsiteSettingsPopupAndroid::SetPermissionInfo( |
| 188 const PermissionInfoList& permission_info_list) { | 123 const PermissionInfoList& permission_info_list) { |
| 189 NOTIMPLEMENTED(); | 124 NOTIMPLEMENTED(); |
| 190 } | 125 } |
| 191 | 126 |
| 192 void WebsiteSettingsPopupAndroid::SetSelectedTab( | 127 void WebsiteSettingsPopupAndroid::SetSelectedTab( |
| 193 WebsiteSettingsUI::TabId tab_id) { | 128 WebsiteSettingsUI::TabId tab_id) { |
| 194 // There's no tab UI on Android - only connection info is shown. | 129 // There's no tab UI on Android - only connection info is shown. |
| 195 NOTIMPLEMENTED(); | 130 NOTIMPLEMENTED(); |
| 196 } | 131 } |
| 197 | 132 |
| 198 void WebsiteSettingsPopupAndroid::SetFirstVisit( | 133 void WebsiteSettingsPopupAndroid::SetFirstVisit( |
| 199 const base::string16& first_visit) { | 134 const base::string16& first_visit) { |
| 200 NOTIMPLEMENTED(); | 135 NOTIMPLEMENTED(); |
| 201 } | 136 } |
| 202 | 137 |
| 203 // static | 138 // static |
| 204 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( | 139 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( |
| 205 JNIEnv* env) { | 140 JNIEnv* env) { |
| 206 return RegisterNativesImpl(env); | 141 return RegisterNativesImpl(env); |
| 207 } | 142 } |
| OLD | NEW |