Revert of base: Remove operator& from ScopedAuthorizationRef. (patchset #1 id:1 of...
[chromium-blink-merge.git] / android_webview / native / aw_contents_statics.cc
blob8c2be127ce149f692fddbeab7490324469b805ea
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 "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"
19 using base::android::AttachCurrentThread;
20 using base::android::ConvertJavaStringToUTF8;
21 using base::android::ScopedJavaGlobalRef;
22 using content::BrowserThread;
24 namespace android_webview {
26 namespace {
28 void ClientCertificatesCleared(ScopedJavaGlobalRef<jobject>* callback) {
29 DCHECK_CURRENTLY_ON(BrowserThread::UI);
30 JNIEnv* env = AttachCurrentThread();
31 Java_AwContentsStatics_clientCertificatesCleared(env, callback->obj());
34 void NotifyClientCertificatesChanged() {
35 DCHECK_CURRENTLY_ON(BrowserThread::IO);
36 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged();
39 } // namespace
41 // static
42 void ClearClientCertPreferences(JNIEnv* env, jclass, jobject callback) {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
44 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>();
45 j_callback->Reset(env, callback);
46 BrowserThread::PostTaskAndReply(
47 BrowserThread::IO,
48 FROM_HERE,
49 base::Bind(&NotifyClientCertificatesChanged),
50 base::Bind(&ClientCertificatesCleared, base::Owned(j_callback)));
53 // static
54 void SetDataReductionProxyKey(JNIEnv* env, jclass, jstring key) {
55 AwBrowserContext* browser_context = AwBrowserContext::GetDefault();
56 DCHECK(browser_context);
57 DCHECK(browser_context->GetRequestContext());
58 // The following call to GetRequestContext() could possibly be the first such
59 // call, which means AwURLRequestContextGetter::InitializeURLRequestContext
60 // will be called on IO thread as a result.
61 AwURLRequestContextGetter* aw_url_request_context_getter =
62 static_cast<AwURLRequestContextGetter*>(
63 browser_context->GetRequestContext());
65 // This PostTask has to be called after GetRequestContext, because SetKeyOnIO
66 // needs a valid DataReductionProxyRequestOptions object.
67 BrowserThread::PostTask(BrowserThread::IO,
68 FROM_HERE,
69 base::Bind(&AwURLRequestContextGetter::SetKeyOnIO,
70 aw_url_request_context_getter,
71 ConvertJavaStringToUTF8(env, key)));
74 // static
75 void SetDataReductionProxyEnabled(JNIEnv* env, jclass, jboolean enabled) {
76 AwBrowserContext::SetDataReductionProxyEnabled(enabled);
79 // static
80 jstring GetUnreachableWebDataUrl(JNIEnv* env, jclass) {
81 return base::android::ConvertUTF8ToJavaString(
82 env, content::kUnreachableWebDataURL).Release();
85 // static
86 void SetRecordFullDocument(JNIEnv* env, jclass, jboolean record_full_document) {
87 content::SynchronousCompositor::SetRecordFullDocument(record_full_document);
90 // static
91 void RegisterCrashHandler(JNIEnv* env, jclass, jstring version) {
92 crash_handler::RegisterCrashHandler(
93 ConvertJavaStringToUTF8(env, version));
96 // static
97 void SetLegacyCacheRemovalDelayForTest(JNIEnv*, jclass, jlong delay_ms) {
98 AwBrowserContext::SetLegacyCacheRemovalDelayForTest(delay_ms);
101 bool RegisterAwContentsStatics(JNIEnv* env) {
102 return RegisterNativesImpl(env);
105 } // namespace android_webview