1 // Copyright 2014 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.
5 #include "android_webview/native/aw_contents_statics.h"
7 #include "android_webview/browser/aw_browser_context.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/callback.h"
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "jni/AwContentsStatics_jni.h"
14 #include "net/cert/cert_database.h"
16 using base::android::AttachCurrentThread;
17 using base::android::ConvertJavaStringToUTF8;
18 using base::android::ScopedJavaGlobalRef;
19 using content::BrowserThread;
20 using data_reduction_proxy::DataReductionProxySettings;
22 namespace android_webview {
26 void ClientCertificatesCleared(ScopedJavaGlobalRef<jobject>* callback) {
27 DCHECK_CURRENTLY_ON(BrowserThread::UI);
28 JNIEnv* env = AttachCurrentThread();
29 Java_AwContentsStatics_clientCertificatesCleared(env, callback->obj());
32 void NotifyClientCertificatesChanged() {
33 DCHECK_CURRENTLY_ON(BrowserThread::IO);
34 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged();
40 void ClearClientCertPreferences(JNIEnv* env, jclass, jobject callback) {
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
42 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
43 j_callback->Reset(env, callback);
44 BrowserThread::PostTaskAndReply(
47 base::Bind(&NotifyClientCertificatesChanged),
48 base::Bind(&ClientCertificatesCleared, base::Owned(j_callback)));
52 void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
53 AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
54 DCHECK(browser_context);
55 DataReductionProxySettings* drp_settings =
56 browser_context->GetDataReductionProxySettings();
58 drp_settings->set_key(ConvertJavaStringToUTF8(env, key));
62 void SetDataReductionProxyEnabled(JNIEnv* env, jclass, jboolean enabled) {
63 AwBrowserContext::SetDataReductionProxyEnabled(enabled);
66 bool RegisterAwContentsStatics(JNIEnv* env) {
67 return RegisterNativesImpl(env);
70 } // namespace android_webview