ContentSettings.java revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1// Copyright 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 5package org.chromium.content.browser; 6 7import org.chromium.base.CalledByNative; 8import org.chromium.base.JNINamespace; 9import 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") 16public 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 long 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, long 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(long 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 long nativeInit(long contentViewPtr); 60 61 private native boolean nativeGetJavaScriptEnabled(long nativeContentSettings); 62} 63