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.
5 package org.chromium.content.browser;
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace;
9 import org.chromium.base.ThreadUtils;
12 * Manages settings state for a ContentView. A ContentSettings instance is obtained
13 * from ContentViewCore.getContentSettings().
15 @JNINamespace("content")
16 public class ContentSettings {
18 private static final String TAG = "ContentSettings";
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;
24 private ContentViewCore mContentViewCore;
27 * Package constructor to prevent clients from creating a new settings
28 * instance. Must be called on the UI thread.
30 ContentSettings(ContentViewCore contentViewCore, int nativeContentView) {
31 ThreadUtils.assertOnUiThread();
32 mContentViewCore = contentViewCore;
33 mNativeContentSettings = nativeInit(nativeContentView);
34 assert mNativeContentSettings != 0;
38 * Notification from the native side that it is being destroyed.
39 * @param nativeContentSettings the native instance that is going away.
42 private void onNativeContentSettingsDestroyed(int nativeContentSettings) {
43 assert mNativeContentSettings == nativeContentSettings;
44 mNativeContentSettings = 0;
48 * Return true if JavaScript is enabled. Must be called on the UI thread.
50 * @return True if JavaScript is enabled.
52 public boolean getJavaScriptEnabled() {
53 ThreadUtils.assertOnUiThread();
54 return mNativeContentSettings != 0 ?
55 nativeGetJavaScriptEnabled(mNativeContentSettings) : false;
58 // Initialize the ContentSettings native side.
59 private native int nativeInit(int contentViewPtr);
61 private native boolean nativeGetJavaScriptEnabled(int nativeContentSettings);