Fix missing .Pass() on returning scoped_ptr<SdchManager::DictionarySet>
[chromium-blink-merge.git] / android_webview / native / aw_contents_statics.cc
blobe09fcb8c61dd7c9319d0ff6a7dce9076accf31bf
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_crash_handler.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/callback.h"
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
14 #include "content/public/browser/android/synchronous_compositor.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/common/url_constants.h"
17 #include "jni/AwContentsStatics_jni.h"
18 #include "net/cert/cert_database.h"
20 using base::android::AttachCurrentThread;
21 using base::android::ConvertJavaStringToUTF8;
22 using base::android::ScopedJavaGlobalRef;
23 using content::BrowserThread;
24 using data_reduction_proxy::DataReductionProxyAuthRequestHandler;
26 namespace android_webview {
28 namespace {
30 void ClientCertificatesCleared(ScopedJavaGlobalRef<jobject>* callback) {
31 DCHECK_CURRENTLY_ON(BrowserThread::UI);
32 JNIEnv* env = AttachCurrentThread();
33 Java_AwContentsStatics_clientCertificatesCleared(env, callback->obj());
36 void NotifyClientCertificatesChanged() {
37 DCHECK_CURRENTLY_ON(BrowserThread::IO);
38 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged();
41 } // namespace
43 // static
44 void ClearClientCertPreferences(JNIEnv* env, jclass, jobject callback) {
45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
46 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
47 j_callback->Reset(env, callback);
48 BrowserThread::PostTaskAndReply(
49 BrowserThread::IO,
50 FROM_HERE,
51 base::Bind(&NotifyClientCertificatesChanged),
52 base::Bind(&ClientCertificatesCleared, base::Owned(j_callback)));
55 // static
56 void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
57 AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
58 DCHECK(browser_context);
59 DCHECK(browser_context->GetRequestContext());
60 // The following call to GetRequestContext() could possibly be the first such
61 // call, which means AwURLRequestContextGetter::InitializeURLRequestContext
62 // will be called on IO thread as a result. InitializeURLRequestContext()
63 // will initialize DataReductionProxyAuthRequestHandler.
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 DataReductionProxyAuthRequestHandler 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, jclass, jboolean enabled) {
79 AwBrowserContext::SetDataReductionProxyEnabled(enabled);
82 // static
83 jstring GetUnreachableWebDataUrl(JNIEnv* env, jclass) {
84 return base::android::ConvertUTF8ToJavaString(
85 env, content::kUnreachableWebDataURL).Release();
88 // static
89 void SetRecordFullDocument(JNIEnv* env, jclass, jboolean record_full_document) {
90 content::SynchronousCompositor::SetRecordFullDocument(record_full_document);
93 // static
94 void RegisterCrashHandler(JNIEnv* env, jclass, jstring version) {
95 crash_handler::RegisterCrashHandler(
96 ConvertJavaStringToUTF8(env, version));
99 // static
100 void SetLegacyCacheRemovalDelayForTest(JNIEnv*, jclass, jlong delay_ms) {
101 AwBrowserContext::SetLegacyCacheRemovalDelayForTest(delay_ms);
104 bool RegisterAwContentsStatics(JNIEnv* env) {
105 return RegisterNativesImpl(env);
108 } // namespace android_webview