Roll src/third_party/WebKit 06cb9e9:a978ee5 (svn 202558:202559)
[chromium-blink-merge.git] / android_webview / native / aw_contents_statics.cc
blobe408c7c4551efeb1f1b563e45dc117542a0d6b5b
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 "android_webview/browser/net/aw_url_request_context_getter.h"
9 #include "android_webview/common/aw_version_info_values.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/callback.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/common/url_constants.h"
15 #include "jni/AwContentsStatics_jni.h"
16 #include "net/cert/cert_database.h"
18 using base::android::AttachCurrentThread;
19 using base::android::ConvertJavaStringToUTF8;
20 using base::android::ScopedJavaGlobalRef;
21 using content::BrowserThread;
23 namespace android_webview {
25 namespace {
27 void ClientCertificatesCleared(ScopedJavaGlobalRef<jobject>* callback) {
28 DCHECK_CURRENTLY_ON(BrowserThread::UI);
29 JNIEnv* env = AttachCurrentThread();
30 Java_AwContentsStatics_clientCertificatesCleared(env, callback->obj());
33 void NotifyClientCertificatesChanged() {
34 DCHECK_CURRENTLY_ON(BrowserThread::IO);
35 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged();
38 } // namespace
40 // static
41 void ClearClientCertPreferences(JNIEnv* env,
42 const JavaParamRef<jclass>&,
43 const JavaParamRef<jobject>& callback) {
44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
45 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
46 j_callback->Reset(env, callback);
47 BrowserThread::PostTaskAndReply(
48 BrowserThread::IO,
49 FROM_HERE,
50 base::Bind(&NotifyClientCertificatesChanged),
51 base::Bind(&ClientCertificatesCleared, base::Owned(j_callback)));
54 // static
55 void SetDataReductionProxyKey(JNIEnv* env,
56 const JavaParamRef<jclass>&,
57 const JavaParamRef<jstring>& key) {
58 AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
59 DCHECK(browser_context);
60 DCHECK(browser_context->GetRequestContext());
61 // The following call to GetRequestContext() could possibly be the first such
62 // call, which means AwURLRequestContextGetter::InitializeURLRequestContext
63 // will be called on IO thread as a result.
64 AwURLRequestContextGetter* aw_url_request_context_getter =
65 static_cast<AwURLRequestContextGetter*>(
66 browser_context->GetRequestContext());
68 // This PostTask has to be called after GetRequestContext, because SetKeyOnIO
69 // needs a valid DataReductionProxyRequestOptions object.
70 BrowserThread::PostTask(BrowserThread::IO,
71 FROM_HERE,
72 base::Bind(&AwURLRequestContextGetter::SetKeyOnIO,
73 aw_url_request_context_getter,
74 ConvertJavaStringToUTF8(env, key)));
77 // static
78 void SetDataReductionProxyEnabled(JNIEnv* env,
79 const JavaParamRef<jclass>&,
80 jboolean enabled) {
81 AwBrowserContext::SetDataReductionProxyEnabled(enabled);
84 // static
85 ScopedJavaLocalRef<jstring> GetUnreachableWebDataUrl(
86 JNIEnv* env,
87 const JavaParamRef<jclass>&) {
88 return base::android::ConvertUTF8ToJavaString(
89 env, content::kUnreachableWebDataURL);
92 // static
93 void SetLegacyCacheRemovalDelayForTest(JNIEnv*,
94 const JavaParamRef<jclass>&,
95 jlong delay_ms) {
96 AwBrowserContext::SetLegacyCacheRemovalDelayForTest(delay_ms);
99 // static
100 ScopedJavaLocalRef<jstring> GetProductVersion(JNIEnv* env,
101 const JavaParamRef<jclass>&) {
102 return base::android::ConvertUTF8ToJavaString(env, PRODUCT_VERSION);
105 bool RegisterAwContentsStatics(JNIEnv* env) {
106 return RegisterNativesImpl(env);
109 } // namespace android_webview