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" | 10 #include "chrome/browser/android/resource_mapper.h" |
11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/website_settings/website_settings.h" | 13 #include "chrome/browser/ui/website_settings/website_settings.h" |
14 #include "content/public/browser/android/content_view_core.h" | |
15 #include "content/public/browser/cert_store.h" | 14 #include "content/public/browser/cert_store.h" |
16 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
19 #include "content/public/common/ssl_status.h" | 18 #include "content/public/common/ssl_status.h" |
20 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
21 #include "jni/WebsiteSettingsPopup_jni.h" | 20 #include "jni/WebsiteSettingsPopup_jni.h" |
22 #include "net/cert/x509_certificate.h" | 21 #include "net/cert/x509_certificate.h" |
23 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
24 | 23 |
25 using base::android::CheckException; | 24 using base::android::CheckException; |
26 using base::android::ConvertUTF8ToJavaString; | 25 using base::android::ConvertUTF8ToJavaString; |
27 using base::android::ConvertUTF16ToJavaString; | 26 using base::android::ConvertUTF16ToJavaString; |
28 using base::android::GetClass; | 27 using base::android::GetClass; |
29 using base::android::ScopedJavaLocalRef; | 28 using base::android::ScopedJavaLocalRef; |
30 using content::CertStore; | 29 using content::CertStore; |
31 using content::WebContents; | 30 using content::WebContents; |
32 | 31 |
33 static jobjectArray GetCertificateChain(JNIEnv* env, | 32 static jobjectArray GetCertificateChain(JNIEnv* env, |
34 jobject obj, | 33 jobject obj, |
35 jobject view) { | 34 jobject java_web_contents) { |
36 content::WebContents* contents = | 35 content::WebContents* web_contents = |
37 content::ContentViewCore::GetNativeContentViewCore(env, view)-> | 36 content::WebContents::FromJavaWebContents(java_web_contents); |
38 GetWebContents(); | 37 if (!web_contents) { |
Ted C
2014/06/11 23:32:41
personally I would drop the braces.
Yaron
2014/06/12 01:04:28
Done.
| |
39 int cert_id = contents->GetController().GetVisibleEntry()->GetSSL().cert_id; | 38 return NULL; |
39 } | |
40 int cert_id = | |
41 web_contents->GetController().GetVisibleEntry()->GetSSL().cert_id; | |
40 scoped_refptr<net::X509Certificate> cert; | 42 scoped_refptr<net::X509Certificate> cert; |
41 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert); | 43 bool ok = CertStore::GetInstance()->RetrieveCert(cert_id, &cert); |
42 CHECK(ok); | 44 CHECK(ok); |
43 | 45 |
44 std::vector<std::string> cert_chain; | 46 std::vector<std::string> cert_chain; |
45 net::X509Certificate::OSCertHandles cert_handles = | 47 net::X509Certificate::OSCertHandles cert_handles = |
46 cert->GetIntermediateCertificates(); | 48 cert->GetIntermediateCertificates(); |
47 // 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 |
48 // already there. | 50 // already there. |
49 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle()) | 51 if (cert_handles.empty() || cert_handles[0] != cert->os_cert_handle()) |
50 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle()); | 52 cert_handles.insert(cert_handles.begin(), cert->os_cert_handle()); |
51 | 53 |
52 cert_chain.reserve(cert_handles.size()); | 54 cert_chain.reserve(cert_handles.size()); |
53 for (net::X509Certificate::OSCertHandles::const_iterator it = | 55 for (net::X509Certificate::OSCertHandles::const_iterator it = |
54 cert_handles.begin(); | 56 cert_handles.begin(); |
55 it != cert_handles.end(); | 57 it != cert_handles.end(); |
56 ++it) { | 58 ++it) { |
57 std::string cert_bytes; | 59 std::string cert_bytes; |
58 net::X509Certificate::GetDEREncoded(*it, &cert_bytes); | 60 net::X509Certificate::GetDEREncoded(*it, &cert_bytes); |
59 cert_chain.push_back(cert_bytes); | 61 cert_chain.push_back(cert_bytes); |
60 } | 62 } |
61 | 63 |
62 // OK to release, JNI binding. | 64 // OK to release, JNI binding. |
63 return base::android::ToJavaArrayOfByteArray(env, cert_chain).Release(); | 65 return base::android::ToJavaArrayOfByteArray(env, cert_chain).Release(); |
64 } | 66 } |
65 | 67 |
66 // static | 68 // static |
67 void WebsiteSettingsPopupAndroid::Show(JNIEnv* env, | 69 static jlong Init(JNIEnv* env, |
68 jobject context, | 70 jclass clazz, |
69 jobject java_content_view, | 71 jobject obj, |
70 WebContents* web_contents) { | 72 jobject java_web_contents) { |
71 new WebsiteSettingsPopupAndroid(env, context, java_content_view, | 73 content::WebContents* web_contents = |
72 web_contents); | 74 content::WebContents::FromJavaWebContents(java_web_contents); |
Ted C
2014/06/11 23:32:41
this is indented 5 instead of 4
Yaron
2014/06/12 01:04:28
Done.
| |
75 | |
76 return reinterpret_cast<intptr_t>( | |
77 new WebsiteSettingsPopupAndroid(env, obj, web_contents)); | |
73 } | 78 } |
74 | 79 |
75 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid( | 80 WebsiteSettingsPopupAndroid::WebsiteSettingsPopupAndroid( |
76 JNIEnv* env, | 81 JNIEnv* env, |
77 jobject context, | 82 jobject java_website_settings_pop, |
78 jobject java_content_view, | |
79 WebContents* web_contents) { | 83 WebContents* web_contents) { |
80 // Important to use GetVisibleEntry to match what's showing in the omnibox. | 84 // Important to use GetVisibleEntry to match what's showing in the omnibox. |
81 content::NavigationEntry* nav_entry = | 85 content::NavigationEntry* nav_entry = |
82 web_contents->GetController().GetVisibleEntry(); | 86 web_contents->GetController().GetVisibleEntry(); |
83 if (nav_entry == NULL) | 87 if (nav_entry == NULL) |
84 return; | 88 return; |
85 | 89 |
86 popup_jobject_.Reset( | 90 popup_jobject_.Reset(env, java_website_settings_pop); |
87 Java_WebsiteSettingsPopup_create(env, context, java_content_view, | |
88 reinterpret_cast<intptr_t>(this))); | |
89 | 91 |
90 presenter_.reset(new WebsiteSettings( | 92 presenter_.reset(new WebsiteSettings( |
91 this, | 93 this, |
92 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 94 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
93 TabSpecificContentSettings::FromWebContents(web_contents), | 95 TabSpecificContentSettings::FromWebContents(web_contents), |
94 InfoBarService::FromWebContents(web_contents), | 96 InfoBarService::FromWebContents(web_contents), |
95 nav_entry->GetURL(), | 97 nav_entry->GetURL(), |
96 nav_entry->GetSSL(), | 98 nav_entry->GetSSL(), |
97 content::CertStore::GetInstance())); | 99 content::CertStore::GetInstance())); |
98 } | 100 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 void WebsiteSettingsPopupAndroid::SetFirstVisit( | 176 void WebsiteSettingsPopupAndroid::SetFirstVisit( |
175 const base::string16& first_visit) { | 177 const base::string16& first_visit) { |
176 NOTIMPLEMENTED(); | 178 NOTIMPLEMENTED(); |
177 } | 179 } |
178 | 180 |
179 // static | 181 // static |
180 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( | 182 bool WebsiteSettingsPopupAndroid::RegisterWebsiteSettingsPopupAndroid( |
181 JNIEnv* env) { | 183 JNIEnv* env) { |
182 return RegisterNativesImpl(env); | 184 return RegisterNativesImpl(env); |
183 } | 185 } |
OLD | NEW |