Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / android_webview / java / src / org / chromium / android_webview / AwContentsStatics.java
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 package org.chromium.android_webview;
6
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace;
9 import org.chromium.base.ThreadUtils;
10
11 import java.lang.Runnable;
12
13 /**
14  * Implementations of various static methods, and also a home for static
15  * data structures that are meant to be shared between all webviews.
16  */
17 @JNINamespace("android_webview")
18 public class AwContentsStatics {
19
20     private static ClientCertLookupTable sClientCertLookupTable;
21
22     /**
23      * Return the client certificate lookup table.
24      */
25     public static ClientCertLookupTable getClientCertLookupTable() {
26         ThreadUtils.assertOnUiThread();
27         if (sClientCertLookupTable == null) {
28             sClientCertLookupTable = new ClientCertLookupTable();
29         }
30         return sClientCertLookupTable;
31     }
32
33     /**
34      * Clear client cert lookup table. Should only be called from UI thread.
35      */
36     public static void clearClientCertPreferences(Runnable callback) {
37         ThreadUtils.assertOnUiThread();
38         getClientCertLookupTable().clear();
39         nativeClearClientCertPreferences(callback);
40     }
41
42     @CalledByNative
43     private static void clientCertificatesCleared(Runnable callback) {
44         if (callback == null) return;
45         callback.run();
46     }
47
48     /**
49      * Set Data Reduction Proxy key for authentication.
50      */
51     public static void setDataReductionProxyKey(String key) {
52         ThreadUtils.assertOnUiThread();
53         nativeSetDataReductionProxyKey(key);
54     }
55
56     /*
57      * Enable or disable data reduction proxy.
58      */
59     public static void setDataReductionProxyEnabled(boolean enabled) {
60         ThreadUtils.assertOnUiThread();
61         nativeSetDataReductionProxyEnabled(enabled);
62     }
63
64     //--------------------------------------------------------------------------------------------
65     //  Native methods
66     //--------------------------------------------------------------------------------------------
67     private static native void nativeClearClientCertPreferences(Runnable callback);
68     private static native void nativeSetDataReductionProxyKey(String key);
69     private static native void nativeSetDataReductionProxyEnabled(boolean enabled);
70 }