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

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: Created 7 years, 10 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
« no previous file with comments | « chrome/browser/ui/android/website_settings_popup_android.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (web_contents->GetController().GetActiveEntry() == NULL)
82 return;
83
84 popup_jobject_.Reset(
85 Java_WebsiteSettingsPopup_create(env, context, java_content_view,
86 reinterpret_cast<jint>(this)));
87
88 presenter_.reset(new WebsiteSettings(
89 this,
90 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
91 TabSpecificContentSettings::FromWebContents(web_contents),
92 InfoBarService::FromWebContents(web_contents),
93 web_contents->GetURL(),
94 web_contents->GetController().GetActiveEntry()->GetSSL(),
95 content::CertStore::GetInstance()));
96 }
97
98 WebsiteSettingsPopupAndroid::~WebsiteSettingsPopupAndroid() {}
99
100 void WebsiteSettingsPopupAndroid::Destroy(JNIEnv* env, jobject obj) {
101 delete this;
102 }
103
104 void WebsiteSettingsPopupAndroid::SetIdentityInfo(
105 const IdentityInfo& identity_info) {
106 JNIEnv* env = base::android::AttachCurrentThread();
107
108 {
109 const gfx::Image& icon_image = WebsiteSettingsUI::GetIdentityIcon(
110 identity_info.identity_status);
111 // Creates a java version of the bitmap and makes a copy of the pixels
112 ScopedJavaLocalRef<jobject> icon = ConvertToJavaBitmap(
113 icon_image.ToSkBitmap());
114
115 // The headline and the certificate dialog link of the site's identity
116 // section is only displayed if the site's identity was verified. If the
117 // site's identity was verified, then the headline contains the organization
118 // name from the provided certificate. If the organization name is not
119 // available than the hostname of the site is used instead.
120 std::string headline;
121 if (identity_info.cert_id) {
122 headline = identity_info.site_identity;
123 }
124
125 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString(
126 env, identity_info.identity_status_description);
127 Java_WebsiteSettingsPopup_addSection(env, popup_jobject_.obj(), icon.obj(),
128 ConvertUTF8ToJavaString(env, headline).obj(), description.obj());
129
130 string16 certificate_label =
131 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON);
132 if (!certificate_label.empty()) {
133 Java_WebsiteSettingsPopup_setCertificateViewer(env, popup_jobject_.obj(),
134 ConvertUTF16ToJavaString(env, certificate_label).obj());
135 }
136
137 Java_WebsiteSettingsPopup_addDivider(env, popup_jobject_.obj());
138 }
139
140 {
141 const gfx::Image& icon_image = WebsiteSettingsUI::GetConnectionIcon(
142 identity_info.connection_status);
143 ScopedJavaLocalRef<jobject> icon = ConvertToJavaBitmap(
144 icon_image.ToSkBitmap());
145
146 ScopedJavaLocalRef<jstring> description = ConvertUTF8ToJavaString(
147 env, identity_info.connection_status_description);
148 Java_WebsiteSettingsPopup_addSection(env, popup_jobject_.obj(), icon.obj(),
149 NULL, description.obj());
150
151 Java_WebsiteSettingsPopup_addDivider(env, popup_jobject_.obj());
152 }
153
154 Java_WebsiteSettingsPopup_addMoreInfoLink(env, popup_jobject_.obj(),
155 ConvertUTF8ToJavaString(
156 env, l10n_util::GetStringUTF8(IDS_PAGE_INFO_HELP_CENTER_LINK)).obj());
157 Java_WebsiteSettingsPopup_show(env, popup_jobject_.obj());
158 }
159
160 void WebsiteSettingsPopupAndroid::SetCookieInfo(
161 const CookieInfoList& cookie_info_list) {
162 NOTIMPLEMENTED();
163 }
164
165 void WebsiteSettingsPopupAndroid::SetPermissionInfo(
166 const PermissionInfoList& permission_info_list) {
167 NOTIMPLEMENTED();
168 }
169
170 void WebsiteSettingsPopupAndroid::SetSelectedTab(
171 WebsiteSettingsUI::TabId tab_id) {
172 // There's no tab UI on Android - only connection info is shown.
173 NOTIMPLEMENTED();
174 }
175
176 void WebsiteSettingsPopupAndroid::SetFirstVisit(
177 const string16& first_visit) {
178 NOTIMPLEMENTED();
179 }
180
181 // static
182 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid(
183 JNIEnv* env) {
184 return RegisterNativesImpl(env);
185 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/android/website_settings_popup_android.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698