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_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/api/infobars/infobar_service.h" | |
11 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/ui/website_settings/website_settings.h" | |
13 #include "content/public/browser/android/content_view_core.h" | |
14 #include "content/public/browser/cert_store.h" | |
15 #include "content/public/browser/navigation_controller.h" | |
16 #include "content/public/browser/navigation_entry.h" | |
17 #include "content/public/browser/web_contents.h" | |
18 #include "content/public/common/ssl_status.h" | |
19 #include "grit/generated_resources.h" | |
20 #include "jni/WebsiteSettingsPopup_jni.h" | |
21 #include "net/base/x509_certificate.h" | |
22 #include "ui/base/l10n/l10n_util.h" | |
23 #include "ui/gfx/android/java_bitmap.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 using gfx::ConvertToJavaBitmap; | |
33 | |
34 static jobjectArray GetCertChain(JNIEnv* env, jobject obj, jobject view) { | |
35 content::WebContents* contents = | |
36 content::ContentViewCore::GetNativeContentViewCore(env, view)-> | |
37 GetWebContents(); | |
38 int cert_id = contents->GetController().GetActiveEntry()->GetSSL().cert_id; | |
39 scoped_refptr<net::X509Certificate> cert; | |
40 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert); | |
41 CHECK(ok); | |
42 | |
43 std::vector<std::string> cert_chain; | |
44 net::X509Certificate::OSCertHandles cert_handles = | |
45 cert->GetIntermediateCertificates(); | |
46 // Make sure the peer's own cert is the first in the chain, if it's not | |
47 // already there. | |
48 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle()) | |
49 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle()); | |
50 | |
51 cert_chain.reserve(cert_handles.size()); | |
52 for (net::X509Certificate::OSCertHandles::const_iterator it = | |
53 cert_handles.begin(); | |
54 it != cert_handles.end(); | |
55 ++it) { | |
56 std::string cert_bytes; | |
57 net::X509Certificate::GetDEREncoded(*it, &cert_bytes); | |
58 cert_chain.push_back(cert_bytes); | |
59 } | |
60 | |
61 // OK to release, JNI binding. | |
62 return base::android::ToJavaArrayOfByteArray(env, cert_chain).Release(); | |
63 } | |
64 | |
65 // static | |
66 void WebsiteSettingsPopupAndroid::Show(JNIEnv* env, | |
67 jobject context, | |
Ted C
2013/01/25 02:04:05
indent is off.
Yaron
2013/01/25 19:25:17
Done.
| |
68 jobject java_content_view, | |
69 WebContents* web_contents) { | |
70 new WebsiteSettingsPopupAndroid(env, context, java_content_view, | |
71 web_contents); | |
72 } | |
73 | |
74 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid(JNIEnv* env, | |
75 jobject context, | |
Ted C
2013/01/25 02:04:05
same here too.
Yaron
2013/01/25 19:25:17
Done.
| |
76 jobject java_content_view, | |
77 WebContents* web_contents) { | |
78 | |
79 if (web_contents->GetController().GetActiveEntry() == NULL) | |
80 return; | |
81 | |
82 popup_jobject_.Reset( | |
83 Java_WebsiteSettingsPopup_create(env, context, java_content_view, | |
84 reinterpret_cast<jint>(this))); | |
85 | |
86 presenter_.reset(new WebsiteSettings( | |
87 this, | |
88 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | |
89 TabSpecificContentSettings::FromWebContents(web_contents), | |
90 InfoBarService::FromWebContents(web_contents), | |
91 web_contents->GetURL(), | |
92 web_contents->GetController().GetActiveEntry()->GetSSL(), | |
93 content::CertStore::GetInstance())); | |
94 } | |
95 | |
96 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {} | |
97 | |
98 void WebsiteSettingsPopupAndroid::SetIdentityInfo( | |
99 const IdentityInfo& identity_info) { | |
100 JNIEnv* env = base::android::AttachCurrentThread(); | |
101 | |
102 { | |
103 const gfx::Image& icon_image = WebsiteSettingsUI::GetIdentityIcon( | |
104 identity_info.identity_status); | |
105 // Creates a java version of the bitmap and makes a copy of the pixels | |
106 ScopedJavaLocalRef<jobject> icon = ConvertToJavaBitmap( | |
107 icon_image.ToSkBitmap()); | |
108 | |
109 // The headline and the certificate dialog link of the site's identity | |
110 // section is only displayed if the site's identity was verified. If the | |
111 // site's identity was verified, then the headline contains the organization | |
112 // name from the provided certificate. If the organization name is not | |
113 // available than the hostname of the site is used instead. | |
114 std::string headline; | |
115 if (identity_info.cert_id) { | |
116 headline = identity_info.site_identity; | |
117 } | |
118 | |
119 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString( | |
120 env, identity_info.identity_status_description); | |
121 Java_WebsiteSettingsPopup_addSection(env, popup_jobject_.obj(), icon.obj(), | |
122 ConvertUTF8ToJavaString(env, headline).obj(), description.obj()); | |
123 | |
124 string16 certificate_label = | |
125 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON); | |
126 if (!certificate_label.empty()) { | |
127 Java_WebsiteSettingsPopup_setCertificateViewer(env, popup_jobject_.obj(), | |
128 ConvertUTF16ToJavaString(env, certificate_label).obj()); | |
129 } | |
130 | |
131 Java_WebsiteSettingsPopup_addDivider(env, popup_jobject_.obj()); | |
132 } | |
133 | |
134 { | |
135 const gfx::Image& icon_image = WebsiteSettingsUI::GetConnectionIcon( | |
136 identity_info.connection_status); | |
137 ScopedJavaLocalRef<jobject> icon = ConvertToJavaBitmap( | |
138 icon_image.ToSkBitmap()); | |
139 | |
140 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString( | |
141 env, identity_info.connection_status_description); | |
142 Java_WebsiteSettingsPopup_addSection(env, popup_jobject_.obj(), icon.obj(), | |
143 NULL, description.obj()); | |
Ted C
2013/01/25 02:04:05
indented too much
Yaron
2013/01/25 19:25:17
Done.
| |
144 | |
145 Java_WebsiteSettingsPopup_addDivider(env, popup_jobject_.obj()); | |
146 } | |
147 | |
148 Java_WebsiteSettingsPopup_addMoreInfoLink(env, popup_jobject_.obj()); | |
149 Java_WebsiteSettingsPopup_show(env, popup_jobject_.obj()); | |
150 } | |
151 | |
152 void WebsiteSettingsPopupAndroid::SetCookieInfo( | |
153 const CookieInfoList& cookie_info_list) { | |
154 NOTIMPLEMENTED(); | |
155 } | |
156 | |
157 void WebsiteSettingsPopupAndroid::SetPermissionInfo( | |
158 const PermissionInfoList& permission_info_list) { | |
159 NOTIMPLEMENTED(); | |
160 } | |
161 | |
162 void WebsiteSettingsPopupAndroid::SetSelectedTab( | |
163 WebsiteSettingsUI::TabId tab_id) { | |
164 // There's no tab UI on Android - only connection info is shown. | |
165 NOTIMPLEMENTED(); | |
166 } | |
167 | |
168 void WebsiteSettingsPopupAndroid::SetFirstVisit( | |
169 const string16& first_visit) { | |
170 NOTIMPLEMENTED(); | |
171 } | |
172 | |
173 | |
Ted C
2013/01/25 02:04:05
remove this extra line
Yaron
2013/01/25 19:25:17
Done.
| |
174 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) { | |
Ted C
2013/01/25 02:04:05
destroy should move up to match the ordering of th
Yaron
2013/01/25 19:25:17
Done.
| |
175 delete this; | |
176 } | |
177 | |
178 // static | |
179 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( | |
180 JNIEnv* env) { | |
181 return RegisterNativesImpl(env); | |
182 } | |
OLD | NEW |