Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/browser/ui/android/website_settings_popup_android.cc

Issue 12045081: Android implementation of WebsiteSettingsUi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 GetCertificateChain(JNIEnv* env,
35 jobject obj,
36 jobject view) {
37 content::WebContents* contents =
38 content::ContentViewCore::GetNativeContentViewCore(env, view)->
39 GetWebContents();
40 int cert_id = contents->GetController().GetActiveEntry()->GetSSL().cert_id;
41 scoped_refptr<net::X509Certificate> cert;
42 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert);
43 CHECK(ok);
44
45 std::vector<std::string> cert_chain;
46 net::X509Certificate::OSCertHandles cert_handles =
47 cert->GetIntermediateCertificates();
48 // Make sure the peer's own cert is the first in the chain, if it's not
49 // already there.
50 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle())
51 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle());
52
53 cert_chain.reserve(cert_handles.size());
54 for (net::X509Certificate::OSCertHandles::const_iterator it =
55 cert_handles.begin();
56 it != cert_handles.end();
57 ++it) {
58 std::string cert_bytes;
59 net::X509Certificate::GetDEREncoded(*it, &cert_bytes);
60 cert_chain.push_back(cert_bytes);
61 }
62
63 // OK to release, JNI binding.
64 return base::android::ToJavaArrayOfByteArray(env, cert_chain).Release();
65 }
66
67 // static
68 void WebsiteSettingsPopupAndroid::Show(JNIEnv* env,
69 jobject context,
70 jobject java_content_view,
71 WebContents* web_contents) {
72 new WebsiteSettingsPopupAndroid(env, context, java_content_view,
73 web_contents);
74 }
75
76 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid(
77 JNIEnv* env,
78 jobject context,
79 jobject java_content_view,
80 WebContents* web_contents) {
81
markusheintz_ 2013/01/25 22:12:18 nit: I don't think we need this empty line.
82 if (web_contents->GetController().GetActiveEntry() == NULL)
83 return;
84
85 popup_jobject_.Reset(
86 Java_WebsiteSettingsPopup_create(env, context, java_content_view,
87 reinterpret_cast<jint>(this)));
88
89 presenter_.reset(new WebsiteSettings(
90 this,
91 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
92 TabSpecificContentSettings::FromWebContents(web_contents),
93 InfoBarService::FromWebContents(web_contents),
94 web_contents->GetURL(),
95 web_contents->GetController().GetActiveEntry()->GetSSL(),
96 content::CertStore::GetInstance()));
97 }
98
99 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {}
100
101 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) {
102 delete this;
103 }
104
105 void WebsiteSettingsPopupAndroid::SetIdentityInfo(
106 const IdentityInfo& identity_info) {
107 JNIEnv* env = base::android::AttachCurrentThread();
108
109 {
110 const gfx::Image& icon_image = WebsiteSettingsUI::GetIdentityIcon(
111 identity_info.identity_status);
112 // Creates a java version of the bitmap and makes a copy of the pixels
113 ScopedJavaLocalRef<jobject> icon = ConvertToJavaBitmap(
114 icon_image.ToSkBitmap());
115
116 // The headline and the certificate dialog link of the site's identity
117 // section is only displayed if the site's identity was verified. If the
118 // site's identity was verified, then the headline contains the organization
119 // name from the provided certificate. If the organization name is not
120 // available than the hostname of the site is used instead.
121 std::string headline;
122 if (identity_info.cert_id) {
123 headline = identity_info.site_identity;
124 }
125
126 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString(
127 env, identity_info.identity_status_description);
128 Java_WebsiteSettingsPopup_addSection(env, popup_jobject_.obj(), icon.obj(),
129 ConvertUTF8ToJavaString(env, headline).obj(), description.obj());
130
131 string16 certificate_label =
132 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON);
133 if (!certificate_label.empty()) {
134 Java_WebsiteSettingsPopup_setCertificateViewer(env, popup_jobject_.obj(),
135 ConvertUTF16ToJavaString(env, certificate_label).obj());
136 }
137
138 Java_WebsiteSettingsPopup_addDivider(env, popup_jobject_.obj());
139 }
140
141 {
142 const gfx::Image& icon_image = WebsiteSettingsUI::GetConnectionIcon(
143 identity_info.connection_status);
144 ScopedJavaLocalRef<jobject> icon = ConvertToJavaBitmap(
145 icon_image.ToSkBitmap());
146
147 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString(
148 env, identity_info.connection_status_description);
149 Java_WebsiteSettingsPopup_addSection(env, popup_jobject_.obj(), icon.obj(),
150 NULL, description.obj());
151
152 Java_WebsiteSettingsPopup_addDivider(env, popup_jobject_.obj());
153 }
154
155 Java_WebsiteSettingsPopup_addMoreInfoLink(env, popup_jobject_.obj(),
156 ConvertUTF8ToJavaString(
157 env, l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)).obj());
158 Java_WebsiteSettingsPopup_show(env, popup_jobject_.obj());
159 }
160
161 void WebsiteSettingsPopupAndroid::SetCookieInfo(
162 const CookieInfoList& cookie_info_list) {
163 NOTIMPLEMENTED();
164 }
165
166 void WebsiteSettingsPopupAndroid::SetPermissionInfo(
167 const PermissionInfoList& permission_info_list) {
168 NOTIMPLEMENTED();
169 }
170
171 void WebsiteSettingsPopupAndroid::SetSelectedTab(
172 WebsiteSettingsUI::TabId tab_id) {
173 // There's no tab UI on Android - only connection info is shown.
174 NOTIMPLEMENTED();
175 }
176
177 void WebsiteSettingsPopupAndroid::SetFirstVisit(
178 const string16& first_visit) {
179 NOTIMPLEMENTED();
180 }
181
182 // static
183 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid(
184 JNIEnv* env) {
185 return RegisterNativesImpl(env);
186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698