Fix errors in MB when run for the first time on a new builder.
[chromium-blink-merge.git] / android_webview / native / aw_contents_statics.cc
blob8e1e112122ba2b109d9a2ff901b8d14dee04b426
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 "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h"
11 #include "base/callback.h"
12 #include "content/public/browser/android/synchronous_compositor.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, jclass, jobject callback) {
42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
43 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
44 j_callback->Reset(env, callback);
45 BrowserThread::PostTaskAndReply(
46 BrowserThread::IO,
47 FROM_HERE,
48 base::Bind(&NotifyClientCertificatesChanged),
49 base::Bind(&ClientCertificatesCleared, base::Owned(j_callback)));
52 // static
53 void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
54 AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
55 DCHECK(browser_context);
56 DCHECK(browser_context->GetRequestContext());
57 // The following call to GetRequestContext() could possibly be the first such
58 // call, which means AwURLRequestContextGetter::InitializeURLRequestContext
59 // will be called on IO thread as a result.
60 AwURLRequestContextGetter* aw_url_request_context_getter =
61 static_cast<AwURLRequestContextGetter*>(
62 browser_context->GetRequestContext());
64 // This PostTask has to be called after GetRequestContext, because SetKeyOnIO
65 // needs a valid DataReductionProxyRequestOptions object.
66 BrowserThread::PostTask(BrowserThread::IO,
67 FROM_HERE,
68 base::Bind(&AwURLRequestContextGetter::SetKeyOnIO,
69 aw_url_request_context_getter,
70 ConvertJavaStringToUTF8(env, key)));
73 // static
74 void SetDataReductionProxyEnabled(JNIEnv* env, jclass, jboolean enabled) {
75 AwBrowserContext::SetDataReductionProxyEnabled(enabled);
78 // static
79 jstring GetUnreachableWebDataUrl(JNIEnv* env, jclass) {
80 return base::android::ConvertUTF8ToJavaString(
81 env, content::kUnreachableWebDataURL).Release();
84 // static
85 void SetRecordFullDocument(JNIEnv* env, jclass, jboolean record_full_document) {
86 content::SynchronousCompositor::SetRecordFullDocument(record_full_document);
89 // static
90 void SetLegacyCacheRemovalDelayForTest(JNIEnv*, jclass, jlong delay_ms) {
91 AwBrowserContext::SetLegacyCacheRemovalDelayForTest(delay_ms);
94 bool RegisterAwContentsStatics(JNIEnv* env) {
95 return RegisterNativesImpl(env);
98 } // namespace android_webview