import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
+import com.google.common.annotations.VisibleForTesting;
+
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.base.ThreadUtils;
TEXT_AUTOSIZING,
}
+ // These constants must be kept in sync with the Android framework, defined in WebSettimgs.
+ @VisibleForTesting
+ public static final int MIXED_CONTENT_ALWAYS_ALLOW = 0;
+ @VisibleForTesting
+ public static final int MIXED_CONTENT_NEVER_ALLOW = 1;
+ @VisibleForTesting
+ public static final int MIXED_CONTENT_COMPATIBILITY_MODE = 2;
+
private static final String TAG = "AwSettings";
// This class must be created on the UI thread. Afterwards, it can be
private float mInitialPageScalePercent = 0;
private boolean mSpatialNavigationEnabled; // Default depends on device features.
private boolean mEnableSupportedHardwareAcceleratedFeatures = false;
+ private int mMixedContentMode = MIXED_CONTENT_NEVER_ALLOW;
+ private boolean mVideoOverlayForEmbeddedVideoEnabled = false;
private final boolean mSupportLegacyQuirks;
mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
@Override
public void run() {
- nativeUpdateInitialPageScaleLocked(mNativeAwSettings);
+ if (mNativeAwSettings != 0) {
+ nativeUpdateInitialPageScaleLocked(mNativeAwSettings);
+ }
}
});
}
mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
@Override
public void run() {
- nativeUpdateFormDataPreferencesLocked(mNativeAwSettings);
+ if (mNativeAwSettings != 0) {
+ nativeUpdateFormDataPreferencesLocked(mNativeAwSettings);
+ }
}
});
}
mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
@Override
public void run() {
- nativeUpdateUserAgentLocked(mNativeAwSettings);
+ if (mNativeAwSettings != 0) {
+ nativeUpdateUserAgentLocked(mNativeAwSettings);
+ }
}
});
}
*/
public String getUserAgentString() {
synchronized (mAwSettingsLock) {
- return mUserAgent;
+ return getUserAgentLocked();
}
}
mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
@Override
public void run() {
- updateWebkitPreferencesOnUiThreadLocked();
- nativeResetScrollAndScaleState(mNativeAwSettings);
+ if (mNativeAwSettings != 0) {
+ updateWebkitPreferencesOnUiThreadLocked();
+ nativeResetScrollAndScaleState(mNativeAwSettings);
+ }
}
});
}
*/
public boolean getLoadWithOverviewMode() {
synchronized (mAwSettingsLock) {
- return mLoadWithOverviewMode;
+ return getLoadWithOverviewModeLocked();
}
}
*/
public int getTextZoom() {
synchronized (mAwSettingsLock) {
- return mTextSizePercent;
+ return getTextSizePercentLocked();
}
}
*/
public String getStandardFontFamily() {
synchronized (mAwSettingsLock) {
- return mStandardFontFamily;
+ return getStandardFontFamilyLocked();
}
}
*/
public String getFixedFontFamily() {
synchronized (mAwSettingsLock) {
- return mFixedFontFamily;
+ return getFixedFontFamilyLocked();
}
}
*/
public String getSansSerifFontFamily() {
synchronized (mAwSettingsLock) {
- return mSansSerifFontFamily;
+ return getSansSerifFontFamilyLocked();
}
}
*/
public String getSerifFontFamily() {
synchronized (mAwSettingsLock) {
- return mSerifFontFamily;
+ return getSerifFontFamilyLocked();
}
}
*/
public String getCursiveFontFamily() {
synchronized (mAwSettingsLock) {
- return mCursiveFontFamily;
+ return getCursiveFontFamilyLocked();
}
}
*/
public String getFantasyFontFamily() {
synchronized (mAwSettingsLock) {
- return mFantasyFontFamily;
+ return getFantasyFontFamilyLocked();
}
}
*/
public int getMinimumFontSize() {
synchronized (mAwSettingsLock) {
- return mMinimumFontSize;
+ return getMinimumFontSizeLocked();
}
}
*/
public int getMinimumLogicalFontSize() {
synchronized (mAwSettingsLock) {
- return mMinimumLogicalFontSize;
+ return getMinimumLogicalFontSizeLocked();
}
}
*/
public int getDefaultFontSize() {
synchronized (mAwSettingsLock) {
- return mDefaultFontSize;
+ return getDefaultFontSizeLocked();
}
}
*/
public int getDefaultFixedFontSize() {
synchronized (mAwSettingsLock) {
- return mDefaultFixedFontSize;
+ return getDefaultFixedFontSizeLocked();
}
}
*/
public boolean getLoadsImagesAutomatically() {
synchronized (mAwSettingsLock) {
- return mLoadsImagesAutomatically;
+ return getLoadsImagesAutomaticallyLocked();
}
}
*/
public boolean getAllowUniversalAccessFromFileURLs() {
synchronized (mAwSettingsLock) {
- return mAllowUniversalAccessFromFileURLs;
+ return getAllowUniversalAccessFromFileURLsLocked();
}
}
*/
public boolean getAllowFileAccessFromFileURLs() {
synchronized (mAwSettingsLock) {
- return mAllowFileAccessFromFileURLs;
+ return getAllowFileAccessFromFileURLsLocked();
}
}
*/
public boolean getJavaScriptCanOpenWindowsAutomatically() {
synchronized (mAwSettingsLock) {
- return mJavaScriptCanOpenWindowsAutomatically;
+ return getJavaScriptCanOpenWindowsAutomaticallyLocked();
}
}
*/
public boolean getUseWideViewPort() {
synchronized (mAwSettingsLock) {
- return mUseWideViewport;
+ return getUseWideViewportLocked();
}
}
*/
public String getDefaultTextEncodingName() {
synchronized (mAwSettingsLock) {
- return mDefaultTextEncoding;
+ return getDefaultTextEncodingLocked();
}
}
*/
public boolean getMediaPlaybackRequiresUserGesture() {
synchronized (mAwSettingsLock) {
- return mMediaPlaybackRequiresUserGesture;
+ return getMediaPlaybackRequiresUserGestureLocked();
}
}
*/
public String getDefaultVideoPosterURL() {
synchronized (mAwSettingsLock) {
- return mDefaultVideoPosterURL;
+ return getDefaultVideoPosterURLLocked();
}
}
}
}
+ public void setMixedContentMode(int mode) {
+ synchronized (mAwSettingsLock) {
+ if (mMixedContentMode != mode) {
+ mMixedContentMode = mode;
+ mEventHandler.updateWebkitPreferencesLocked();
+ }
+ }
+ }
+
+ public int getMixedContentMode() {
+ synchronized (mAwSettingsLock) {
+ return mMixedContentMode;
+ }
+ }
+
+ @CalledByNative
+ private boolean getAllowRunningInsecureContentLocked() {
+ assert Thread.holdsLock(mAwSettingsLock);
+ return mMixedContentMode == MIXED_CONTENT_ALWAYS_ALLOW;
+ }
+
+ @CalledByNative
+ private boolean getAllowDisplayingInsecureContentLocked() {
+ assert Thread.holdsLock(mAwSettingsLock);
+ return mMixedContentMode == MIXED_CONTENT_ALWAYS_ALLOW ||
+ mMixedContentMode == MIXED_CONTENT_COMPATIBILITY_MODE;
+ }
+
+ /**
+ * Sets whether to use the video overlay for the embedded video.
+ * @param flag whether to enable the video overlay for the embedded video.
+ */
+ public void setVideoOverlayForEmbeddedVideoEnabled(final boolean enabled) {
+ synchronized (mAwSettingsLock) {
+ if (mVideoOverlayForEmbeddedVideoEnabled != enabled) {
+ mVideoOverlayForEmbeddedVideoEnabled = enabled;
+ mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
+ @Override
+ public void run() {
+ if (mNativeAwSettings != 0) {
+ nativeUpdateRendererPreferencesLocked(mNativeAwSettings);
+ }
+ }
+ });
+ }
+ }
+ }
+
+ /**
+ * Gets whether to use the video overlay for the embedded video.
+ * @return true if the WebView enables the video overlay for the embedded video.
+ */
+ public boolean getVideoOverlayForEmbeddedVideoEnabled() {
+ synchronized (mAwSettingsLock) {
+ return getVideoOverlayForEmbeddedVideoEnabledLocked();
+ }
+ }
+
+ @CalledByNative
+ private boolean getVideoOverlayForEmbeddedVideoEnabledLocked() {
+ assert Thread.holdsLock(mAwSettingsLock);
+ return mVideoOverlayForEmbeddedVideoEnabled;
+ }
+
@CalledByNative
private boolean supportsDoubleTapZoomLocked() {
assert Thread.holdsLock(mAwSettingsLock);
@CalledByNative
private void updateEverything() {
synchronized (mAwSettingsLock) {
+ assert mNativeAwSettings != 0;
nativeUpdateEverythingLocked(mNativeAwSettings);
}
}
@CalledByNative
private void populateWebPreferences(long webPrefsPtr) {
synchronized (mAwSettingsLock) {
+ assert mNativeAwSettings != 0;
nativePopulateWebPreferencesLocked(mNativeAwSettings, webPrefsPtr);
}
}
private void updateWebkitPreferencesOnUiThreadLocked() {
assert mEventHandler.mHandler != null;
ThreadUtils.assertOnUiThread();
- nativeUpdateWebkitPreferencesLocked(mNativeAwSettings);
+ if (mNativeAwSettings != 0) {
+ nativeUpdateWebkitPreferencesLocked(mNativeAwSettings);
+ }
}
private native long nativeInit(long webContentsPtr);
private static native String nativeGetDefaultUserAgent();
private native void nativeUpdateFormDataPreferencesLocked(long nativeAwSettings);
+
+ private native void nativeUpdateRendererPreferencesLocked(long nativeAwSettings);
}