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

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

Issue 1288183004: jni_generator: Make all object-returning natives return ScopedJavaLocalRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some newlines for readability Created 5 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/connection_info_popup_android.h" 5 #include "chrome/browser/ui/android/connection_info_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" 10 #include "chrome/browser/android/resource_mapper.h"
(...skipping 12 matching lines...) Expand all
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 24
25 using base::android::CheckException; 25 using base::android::CheckException;
26 using base::android::ConvertUTF8ToJavaString; 26 using base::android::ConvertUTF8ToJavaString;
27 using base::android::ConvertUTF16ToJavaString; 27 using base::android::ConvertUTF16ToJavaString;
28 using base::android::GetClass; 28 using base::android::GetClass;
29 using base::android::ScopedJavaLocalRef; 29 using base::android::ScopedJavaLocalRef;
30 using content::CertStore; 30 using content::CertStore;
31 using content::WebContents; 31 using content::WebContents;
32 32
33 static jobjectArray GetCertificateChain(JNIEnv* env, 33 static ScopedJavaLocalRef<jobjectArray>
34 jobject obj, 34 GetCertificateChain(JNIEnv* env, jobject obj, jobject java_web_contents) {
35 jobject java_web_contents) {
36 content::WebContents* web_contents = 35 content::WebContents* web_contents =
37 content::WebContents::FromJavaWebContents(java_web_contents); 36 content::WebContents::FromJavaWebContents(java_web_contents);
38 if (!web_contents) 37 if (!web_contents)
39 return NULL; 38 return ScopedJavaLocalRef<jobjectArray>();
40 39
41 int cert_id = 40 int cert_id =
42 web_contents->GetController().GetVisibleEntry()->GetSSL().cert_id; 41 web_contents->GetController().GetVisibleEntry()->GetSSL().cert_id;
43 scoped_refptr<net::X509Certificate> cert; 42 scoped_refptr<net::X509Certificate> cert;
44 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert); 43 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert);
45 CHECK(ok); 44 CHECK(ok);
46 45
47 std::vector<std::string> cert_chain; 46 std::vector<std::string> cert_chain;
48 net::X509Certificate::OSCertHandles cert_handles = 47 net::X509Certificate::OSCertHandles cert_handles =
49 cert->GetIntermediateCertificates(); 48 cert->GetIntermediateCertificates();
50 // Make sure the peer's own cert is the first in the chain, if it's not 49 // Make sure the peer's own cert is the first in the chain, if it's not
51 // already there. 50 // already there.
52 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle()) 51 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle())
53 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle()); 52 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle());
54 53
55 cert_chain.reserve(cert_handles.size()); 54 cert_chain.reserve(cert_handles.size());
56 for (net::X509Certificate::OSCertHandles::const_iterator it = 55 for (net::X509Certificate::OSCertHandles::const_iterator it =
57 cert_handles.begin(); 56 cert_handles.begin();
58 it != cert_handles.end(); 57 it != cert_handles.end();
59 ++it) { 58 ++it) {
60 std::string cert_bytes; 59 std::string cert_bytes;
61 net::X509Certificate::GetDEREncoded(*it, &cert_bytes); 60 net::X509Certificate::GetDEREncoded(*it, &cert_bytes);
62 cert_chain.push_back(cert_bytes); 61 cert_chain.push_back(cert_bytes);
63 } 62 }
64 63
65 // OK to release, JNI binding. 64 return base::android::ToJavaArrayOfByteArray(env, cert_chain);
66 return base::android::ToJavaArrayOfByteArray(env, cert_chain).Release();
67 } 65 }
68 66
69 // static 67 // static
70 static jlong Init(JNIEnv* env, 68 static jlong Init(JNIEnv* env,
71 jclass clazz, 69 jclass clazz,
72 jobject obj, 70 jobject obj,
73 jobject java_web_contents) { 71 jobject java_web_contents) {
74 content::WebContents* web_contents = 72 content::WebContents* web_contents =
75 content::WebContents::FromJavaWebContents(java_web_contents); 73 content::WebContents::FromJavaWebContents(java_web_contents);
76 74
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // There's no tab UI on Android - only connection info is shown. 186 // There's no tab UI on Android - only connection info is shown.
189 NOTIMPLEMENTED(); 187 NOTIMPLEMENTED();
190 } 188 }
191 189
192 // static 190 // static
193 bool 191 bool
194 ConnectionInfoPopupAndroid::RegisterConnectionInfoPopupAndroid( 192 ConnectionInfoPopupAndroid::RegisterConnectionInfoPopupAndroid(
195 JNIEnv* env) { 193 JNIEnv* env) {
196 return RegisterNativesImpl(env); 194 return RegisterNativesImpl(env);
197 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698