| 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/ui/website_settings/website_settings.h" | 12 #include "chrome/browser/ui/website_settings/website_settings.h" |
| 14 #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" |
| 15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/cert_store.h" | 16 #include "content/public/browser/cert_store.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/ssl_status.h" | |
| 21 #include "jni/WebsiteSettingsPopup_jni.h" | 20 #include "jni/WebsiteSettingsPopup_jni.h" |
| 22 #include "net/cert/x509_certificate.h" | |
| 23 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 24 | 22 |
| 25 using base::android::CheckException; | 23 using base::android::ConvertUTF16ToJavaString; |
| 26 using base::android::ConvertUTF8ToJavaString; | 24 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 | 25 |
| 69 // static | 26 // static |
| 70 static jlong Init(JNIEnv* env, | 27 static jlong Init(JNIEnv* env, |
| 71 jclass clazz, | 28 jclass clazz, |
| 72 jobject obj, | 29 jobject obj, |
| 73 jobject java_web_contents) { | 30 jobject java_web_contents) { |
| 74 content::WebContents* web_contents = | 31 content::WebContents* web_contents = |
| 75 content::WebContents::FromJavaWebContents(java_web_contents); | 32 content::WebContents::FromJavaWebContents(java_web_contents); |
| 76 | 33 |
| 77 return reinterpret_cast<intptr_t>( | 34 return reinterpret_cast<intptr_t>( |
| 78 new WebsiteSettingsPopupAndroid(env, obj, web_contents)); | 35 new WebsiteSettingsPopupAndroid(env, obj, web_contents)); |
| 79 } | 36 } |
| 80 | 37 |
| 81 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid( | 38 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid( |
| 82 JNIEnv* env, | 39 JNIEnv* env, |
| 83 jobject java_website_settings_pop, | 40 jobject java_website_settings_pop, |
| 84 WebContents* web_contents) { | 41 content::WebContents* web_contents) { |
| 85 // 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. |
| 86 content::NavigationEntry* nav_entry = | 43 content::NavigationEntry* nav_entry = |
| 87 web_contents->GetController().GetVisibleEntry(); | 44 web_contents->GetController().GetVisibleEntry(); |
| 88 if (nav_entry == NULL) | 45 if (nav_entry == NULL) |
| 89 return; | 46 return; |
| 90 | 47 |
| 48 url_ = nav_entry->GetURL(); |
| 49 |
| 91 popup_jobject_.Reset(env, java_website_settings_pop); | 50 popup_jobject_.Reset(env, java_website_settings_pop); |
| 92 | 51 |
| 93 presenter_.reset(new WebsiteSettings( | 52 presenter_.reset(new WebsiteSettings( |
| 94 this, | 53 this, |
| 95 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 54 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
| 96 TabSpecificContentSettings::FromWebContents(web_contents), | 55 TabSpecificContentSettings::FromWebContents(web_contents), |
| 97 InfoBarService::FromWebContents(web_contents), | 56 InfoBarService::FromWebContents(web_contents), |
| 98 nav_entry->GetURL(), | 57 nav_entry->GetURL(), |
| 99 nav_entry->GetSSL(), | 58 nav_entry->GetSSL(), |
| 100 content::CertStore::GetInstance())); | 59 content::CertStore::GetInstance())); |
| 101 } | 60 } |
| 102 | 61 |
| 103 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {} | 62 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {} |
| 104 | 63 |
| 105 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) { | 64 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) { |
| 106 delete this; | 65 delete this; |
| 107 } | 66 } |
| 108 | 67 |
| 109 void WebsiteSettingsPopupAndroid::ResetCertDecisions( | |
| 110 JNIEnv* env, | |
| 111 jobject obj, | |
| 112 jobject java_web_contents) { | |
| 113 presenter_->OnRevokeSSLErrorBypassButtonPressed(); | |
| 114 } | |
| 115 | |
| 116 void WebsiteSettingsPopupAndroid::SetIdentityInfo( | 68 void WebsiteSettingsPopupAndroid::SetIdentityInfo( |
| 117 const IdentityInfo& identity_info) { | 69 const IdentityInfo& identity_info) { |
| 118 JNIEnv* env = base::android::AttachCurrentThread(); | 70 JNIEnv* env = base::android::AttachCurrentThread(); |
| 119 | 71 |
| 120 { | 72 enum PageInfoConnectionType connection_type = CONNECTION_UNKNOWN; |
| 121 int icon_id = ResourceMapper::MapFromChromiumId( | 73 switch (identity_info.connection_status) { |
| 122 WebsiteSettingsUI::GetIdentityIconID(identity_info.identity_status)); | 74 case WebsiteSettings::SITE_CONNECTION_STATUS_UNKNOWN: |
| 123 | 75 connection_type = CONNECTION_UNKNOWN; |
| 124 // The headline and the certificate dialog link of the site's identity | 76 break; |
| 125 // section is only displayed if the site's identity was verified. If the | 77 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED: |
| 126 // site's identity was verified, then the headline contains the organization | 78 connection_type = CONNECTION_ENCRYPTED; |
| 127 // name from the provided certificate. If the organization name is not | 79 break; |
| 128 // available than the hostname of the site is used instead. | 80 case WebsiteSettings::SITE_CONNECTION_STATUS_MIXED_CONTENT: |
| 129 std::string headline; | 81 connection_type = CONNECTION_MIXED_CONTENT; |
| 130 if (identity_info.cert_id) { | 82 break; |
| 131 headline = identity_info.site_identity; | 83 case WebsiteSettings::SITE_CONNECTION_STATUS_UNENCRYPTED: |
| 132 } | 84 connection_type = CONNECTION_UNENCRYPTED; |
| 133 | 85 break; |
| 134 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString( | 86 case WebsiteSettings::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR: |
| 135 env, identity_info.identity_status_description); | 87 connection_type = CONNECTION_ENCRYPTED_ERROR; |
| 136 base::string16 certificate_label = | 88 break; |
| 137 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON); | 89 case WebsiteSettings::SITE_CONNECTION_STATUS_INTERNAL_PAGE: |
| 138 Java_WebsiteSettingsPopup_addCertificateSection( | 90 connection_type = CONNECTION_INTERNAL_PAGE; |
| 139 env, | 91 break; |
| 140 popup_jobject_.obj(), | 92 default: |
| 141 icon_id, | 93 NOTREACHED(); |
| 142 ConvertUTF8ToJavaString(env, headline).obj(), | 94 break; |
| 143 description.obj(), | |
| 144 ConvertUTF16ToJavaString(env, certificate_label).obj()); | |
| 145 | |
| 146 if (identity_info.show_ssl_decision_revoke_button) { | |
| 147 base::string16 reset_button_label = l10n_util::GetStringUTF16( | |
| 148 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON); | |
| 149 Java_WebsiteSettingsPopup_addResetCertDecisionsButton( | |
| 150 env, | |
| 151 popup_jobject_.obj(), | |
| 152 ConvertUTF16ToJavaString(env, reset_button_label).obj()); | |
| 153 } | |
| 154 } | 95 } |
| 155 | 96 |
| 156 { | 97 Java_WebsiteSettingsPopup_setURLTitle( |
| 157 int icon_id = ResourceMapper::MapFromChromiumId( | 98 env, |
| 158 WebsiteSettingsUI::GetConnectionIconID( | 99 popup_jobject_.obj(), |
| 159 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)); |
| 160 | 104 |
| 161 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString( | 105 Java_WebsiteSettingsPopup_setConnectionMessage( |
| 162 env, identity_info.connection_status_description); | 106 env, |
| 163 Java_WebsiteSettingsPopup_addDescriptionSection( | 107 popup_jobject_.obj(), |
| 164 env, popup_jobject_.obj(), icon_id, NULL, description.obj()); | 108 ConvertUTF16ToJavaString( |
| 165 } | 109 env, |
| 110 l10n_util::GetStringUTF16( |
| 111 WebsiteSettingsUI::GetConnectionSummaryMessageID( |
| 112 identity_info.connection_status))).obj()); |
| 166 | 113 |
| 167 Java_WebsiteSettingsPopup_addMoreInfoLink(env, popup_jobject_.obj(), | |
| 168 ConvertUTF8ToJavaString( | |
| 169 env, l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)).obj()); | |
| 170 Java_WebsiteSettingsPopup_showDialog(env, popup_jobject_.obj()); | 114 Java_WebsiteSettingsPopup_showDialog(env, popup_jobject_.obj()); |
| 171 } | 115 } |
| 172 | 116 |
| 173 void WebsiteSettingsPopupAndroid::SetCookieInfo( | 117 void WebsiteSettingsPopupAndroid::SetCookieInfo( |
| 174 const CookieInfoList& cookie_info_list) { | 118 const CookieInfoList& cookie_info_list) { |
| 175 NOTIMPLEMENTED(); | 119 NOTIMPLEMENTED(); |
| 176 } | 120 } |
| 177 | 121 |
| 178 void WebsiteSettingsPopupAndroid::SetPermissionInfo( | 122 void WebsiteSettingsPopupAndroid::SetPermissionInfo( |
| 179 const PermissionInfoList& permission_info_list) { | 123 const PermissionInfoList& permission_info_list) { |
| 180 NOTIMPLEMENTED(); | 124 NOTIMPLEMENTED(); |
| 181 } | 125 } |
| 182 | 126 |
| 183 void WebsiteSettingsPopupAndroid::SetSelectedTab( | 127 void WebsiteSettingsPopupAndroid::SetSelectedTab( |
| 184 WebsiteSettingsUI::TabId tab_id) { | 128 WebsiteSettingsUI::TabId tab_id) { |
| 185 // 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. |
| 186 NOTIMPLEMENTED(); | 130 NOTIMPLEMENTED(); |
| 187 } | 131 } |
| 188 | 132 |
| 189 void WebsiteSettingsPopupAndroid::SetFirstVisit( | 133 void WebsiteSettingsPopupAndroid::SetFirstVisit( |
| 190 const base::string16& first_visit) { | 134 const base::string16& first_visit) { |
| 191 NOTIMPLEMENTED(); | 135 NOTIMPLEMENTED(); |
| 192 } | 136 } |
| 193 | 137 |
| 194 // static | 138 // static |
| 195 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( | 139 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( |
| 196 JNIEnv* env) { | 140 JNIEnv* env) { |
| 197 return RegisterNativesImpl(env); | 141 return RegisterNativesImpl(env); |
| 198 } | 142 } |
| OLD | NEW |