- add sources.
[platform/framework/web/crosswalk.git] / src / content / public / android / java / src / org / chromium / content / browser / ContentSettings.java
1 // Copyright (c) 2012 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.content.browser;
6
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace;
9 import org.chromium.base.ThreadUtils;
10
11 /**
12  * Manages settings state for a ContentView. A ContentSettings instance is obtained
13  * from ContentViewCore.getContentSettings().
14  */
15 @JNINamespace("content")
16 public class ContentSettings {
17
18     private static final String TAG = "ContentSettings";
19
20     // The native side of this object. Ownership is retained native-side by the WebContents
21     // instance that backs the associated ContentViewCore.
22     private int mNativeContentSettings = 0;
23
24     private ContentViewCore mContentViewCore;
25
26     /**
27      * Package constructor to prevent clients from creating a new settings
28      * instance. Must be called on the UI thread.
29      */
30     ContentSettings(ContentViewCore contentViewCore, int nativeContentView) {
31         ThreadUtils.assertOnUiThread();
32         mContentViewCore = contentViewCore;
33         mNativeContentSettings = nativeInit(nativeContentView);
34         assert mNativeContentSettings != 0;
35     }
36
37     /**
38      * Notification from the native side that it is being destroyed.
39      * @param nativeContentSettings the native instance that is going away.
40      */
41     @CalledByNative
42     private void onNativeContentSettingsDestroyed(int nativeContentSettings) {
43         assert mNativeContentSettings == nativeContentSettings;
44         mNativeContentSettings = 0;
45     }
46
47     /**
48      * Return true if JavaScript is enabled. Must be called on the UI thread.
49      *
50      * @return True if JavaScript is enabled.
51      */
52     public boolean getJavaScriptEnabled() {
53         ThreadUtils.assertOnUiThread();
54         return mNativeContentSettings != 0 ?
55                 nativeGetJavaScriptEnabled(mNativeContentSettings) : false;
56     }
57
58     // Initialize the ContentSettings native side.
59     private native int nativeInit(int contentViewPtr);
60
61     private native boolean nativeGetJavaScriptEnabled(int nativeContentSettings);
62 }