Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / android_webview / native / aw_contents_statics.cc
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.
4
5 #include "android_webview/native/aw_contents_statics.h"
6
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 "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
13 #include "content/public/browser/android/synchronous_compositor.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/common/url_constants.h"
16 #include "jni/AwContentsStatics_jni.h"
17 #include "net/cert/cert_database.h"
18
19 using base::android::AttachCurrentThread;
20 using base::android::ConvertJavaStringToUTF8;
21 using base::android::ScopedJavaGlobalRef;
22 using content::BrowserThread;
23 using data_reduction_proxy::DataReductionProxyAuthRequestHandler;
24
25 namespace android_webview {
26
27 namespace {
28
29 void ClientCertificatesCleared(ScopedJavaGlobalRef<jobject>* callback) {
30   DCHECK_CURRENTLY_ON(BrowserThread::UI);
31   JNIEnv* env = AttachCurrentThread();
32   Java_AwContentsStatics_clientCertificatesCleared(env, callback->obj());
33 }
34
35 void NotifyClientCertificatesChanged() {
36   DCHECK_CURRENTLY_ON(BrowserThread::IO);
37   net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged();
38 }
39
40 }  // namespace
41
42 // static
43 void ClearClientCertPreferences(JNIEnv* env, jclass, 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)));
52 }
53
54 // static
55 void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
56   AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
57   DCHECK(browser_context);
58   DCHECK(browser_context->GetRequestContext());
59   AwURLRequestContextGetter* aw_url_request_context_getter =
60       static_cast<AwURLRequestContextGetter*>(
61           browser_context->GetRequestContext());
62   DataReductionProxyAuthRequestHandler* auth_request_handler =
63       aw_url_request_context_getter->GetDataReductionProxyAuthRequestHandler();
64   if (auth_request_handler) {
65     auth_request_handler->SetKeyOnUI(
66         ConvertJavaStringToUTF8(env, key));
67   } else {
68     DLOG(ERROR) << "Data reduction proxy auth request handler does not exist";
69   }
70 }
71
72 // static
73 void SetDataReductionProxyEnabled(JNIEnv* env, jclass, jboolean enabled) {
74   AwBrowserContext::SetDataReductionProxyEnabled(enabled);
75 }
76
77 // static
78 jstring GetUnreachableWebDataUrl(JNIEnv* env, jclass) {
79   return base::android::ConvertUTF8ToJavaString(
80              env, content::kUnreachableWebDataURL).Release();
81 }
82
83 // static
84 void SetRecordFullDocument(JNIEnv* env, jclass, jboolean record_full_document) {
85   content::SynchronousCompositor::SetRecordFullDocument(record_full_document);
86 }
87
88 bool RegisterAwContentsStatics(JNIEnv* env) {
89   return RegisterNativesImpl(env);
90 }
91
92 }  // namespace android_webview