Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / android_webview / java / src / org / chromium / android_webview / AwSettings.java
index a00235b..315e354 100644 (file)
@@ -14,6 +14,8 @@ import android.util.Log;
 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;
@@ -36,6 +38,14 @@ public class AwSettings {
         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
@@ -83,6 +93,8 @@ public class AwSettings {
     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;
 
@@ -373,7 +385,9 @@ public class AwSettings {
                 mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
                     @Override
                     public void run() {
-                        nativeUpdateInitialPageScaleLocked(mNativeAwSettings);
+                        if (mNativeAwSettings != 0) {
+                            nativeUpdateInitialPageScaleLocked(mNativeAwSettings);
+                        }
                     }
                 });
             }
@@ -455,7 +469,9 @@ public class AwSettings {
                 mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
                     @Override
                     public void run() {
-                        nativeUpdateFormDataPreferencesLocked(mNativeAwSettings);
+                        if (mNativeAwSettings != 0) {
+                            nativeUpdateFormDataPreferencesLocked(mNativeAwSettings);
+                        }
                     }
                 });
             }
@@ -500,7 +516,9 @@ public class AwSettings {
                 mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
                     @Override
                     public void run() {
-                        nativeUpdateUserAgentLocked(mNativeAwSettings);
+                        if (mNativeAwSettings != 0) {
+                            nativeUpdateUserAgentLocked(mNativeAwSettings);
+                        }
                     }
                 });
             }
@@ -512,7 +530,7 @@ public class AwSettings {
      */
     public String getUserAgentString() {
         synchronized (mAwSettingsLock) {
-            return mUserAgent;
+            return getUserAgentLocked();
         }
     }
 
@@ -532,8 +550,10 @@ public class AwSettings {
                 mEventHandler.runOnUiThreadBlockingAndLocked(new Runnable() {
                     @Override
                     public void run() {
-                        updateWebkitPreferencesOnUiThreadLocked();
-                        nativeResetScrollAndScaleState(mNativeAwSettings);
+                        if (mNativeAwSettings != 0) {
+                            updateWebkitPreferencesOnUiThreadLocked();
+                            nativeResetScrollAndScaleState(mNativeAwSettings);
+                        }
                     }
                 });
             }
@@ -545,7 +565,7 @@ public class AwSettings {
      */
     public boolean getLoadWithOverviewMode() {
         synchronized (mAwSettingsLock) {
-            return mLoadWithOverviewMode;
+            return getLoadWithOverviewModeLocked();
         }
     }
 
@@ -572,7 +592,7 @@ public class AwSettings {
      */
     public int getTextZoom() {
         synchronized (mAwSettingsLock) {
-            return mTextSizePercent;
+            return getTextSizePercentLocked();
         }
     }
 
@@ -599,7 +619,7 @@ public class AwSettings {
      */
     public String getStandardFontFamily() {
         synchronized (mAwSettingsLock) {
-            return mStandardFontFamily;
+            return getStandardFontFamilyLocked();
         }
     }
 
@@ -626,7 +646,7 @@ public class AwSettings {
      */
     public String getFixedFontFamily() {
         synchronized (mAwSettingsLock) {
-            return mFixedFontFamily;
+            return getFixedFontFamilyLocked();
         }
     }
 
@@ -653,7 +673,7 @@ public class AwSettings {
      */
     public String getSansSerifFontFamily() {
         synchronized (mAwSettingsLock) {
-            return mSansSerifFontFamily;
+            return getSansSerifFontFamilyLocked();
         }
     }
 
@@ -680,7 +700,7 @@ public class AwSettings {
      */
     public String getSerifFontFamily() {
         synchronized (mAwSettingsLock) {
-            return mSerifFontFamily;
+            return getSerifFontFamilyLocked();
         }
     }
 
@@ -707,7 +727,7 @@ public class AwSettings {
      */
     public String getCursiveFontFamily() {
         synchronized (mAwSettingsLock) {
-            return mCursiveFontFamily;
+            return getCursiveFontFamilyLocked();
         }
     }
 
@@ -734,7 +754,7 @@ public class AwSettings {
      */
     public String getFantasyFontFamily() {
         synchronized (mAwSettingsLock) {
-            return mFantasyFontFamily;
+            return getFantasyFontFamilyLocked();
         }
     }
 
@@ -762,7 +782,7 @@ public class AwSettings {
      */
     public int getMinimumFontSize() {
         synchronized (mAwSettingsLock) {
-            return mMinimumFontSize;
+            return getMinimumFontSizeLocked();
         }
     }
 
@@ -790,7 +810,7 @@ public class AwSettings {
      */
     public int getMinimumLogicalFontSize() {
         synchronized (mAwSettingsLock) {
-            return mMinimumLogicalFontSize;
+            return getMinimumLogicalFontSizeLocked();
         }
     }
 
@@ -818,7 +838,7 @@ public class AwSettings {
      */
     public int getDefaultFontSize() {
         synchronized (mAwSettingsLock) {
-            return mDefaultFontSize;
+            return getDefaultFontSizeLocked();
         }
     }
 
@@ -846,7 +866,7 @@ public class AwSettings {
      */
     public int getDefaultFixedFontSize() {
         synchronized (mAwSettingsLock) {
-            return mDefaultFixedFontSize;
+            return getDefaultFixedFontSizeLocked();
         }
     }
 
@@ -909,7 +929,7 @@ public class AwSettings {
      */
     public boolean getLoadsImagesAutomatically() {
         synchronized (mAwSettingsLock) {
-            return mLoadsImagesAutomatically;
+            return getLoadsImagesAutomaticallyLocked();
         }
     }
 
@@ -966,7 +986,7 @@ public class AwSettings {
      */
     public boolean getAllowUniversalAccessFromFileURLs() {
         synchronized (mAwSettingsLock) {
-            return mAllowUniversalAccessFromFileURLs;
+            return getAllowUniversalAccessFromFileURLsLocked();
         }
     }
 
@@ -981,7 +1001,7 @@ public class AwSettings {
      */
     public boolean getAllowFileAccessFromFileURLs() {
         synchronized (mAwSettingsLock) {
-            return mAllowFileAccessFromFileURLs;
+            return getAllowFileAccessFromFileURLsLocked();
         }
     }
 
@@ -1056,7 +1076,7 @@ public class AwSettings {
      */
     public boolean getJavaScriptCanOpenWindowsAutomatically() {
         synchronized (mAwSettingsLock) {
-            return mJavaScriptCanOpenWindowsAutomatically;
+            return getJavaScriptCanOpenWindowsAutomaticallyLocked();
         }
     }
 
@@ -1150,7 +1170,7 @@ public class AwSettings {
      */
     public boolean getUseWideViewPort() {
         synchronized (mAwSettingsLock) {
-            return mUseWideViewport;
+            return getUseWideViewportLocked();
         }
     }
 
@@ -1287,7 +1307,7 @@ public class AwSettings {
      */
     public String getDefaultTextEncodingName() {
         synchronized (mAwSettingsLock) {
-            return mDefaultTextEncoding;
+            return getDefaultTextEncodingLocked();
         }
     }
 
@@ -1314,7 +1334,7 @@ public class AwSettings {
      */
     public boolean getMediaPlaybackRequiresUserGesture() {
         synchronized (mAwSettingsLock) {
-            return mMediaPlaybackRequiresUserGesture;
+            return getMediaPlaybackRequiresUserGestureLocked();
         }
     }
 
@@ -1342,7 +1362,7 @@ public class AwSettings {
      */
     public String getDefaultVideoPosterURL() {
         synchronized (mAwSettingsLock) {
-            return mDefaultVideoPosterURL;
+            return getDefaultVideoPosterURLLocked();
         }
     }
 
@@ -1430,6 +1450,70 @@ public class AwSettings {
         }
     }
 
+    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);
@@ -1465,6 +1549,7 @@ public class AwSettings {
     @CalledByNative
     private void updateEverything() {
         synchronized (mAwSettingsLock) {
+            assert mNativeAwSettings != 0;
             nativeUpdateEverythingLocked(mNativeAwSettings);
         }
     }
@@ -1472,6 +1557,7 @@ public class AwSettings {
     @CalledByNative
     private void populateWebPreferences(long webPrefsPtr) {
         synchronized (mAwSettingsLock) {
+            assert mNativeAwSettings != 0;
             nativePopulateWebPreferencesLocked(mNativeAwSettings, webPrefsPtr);
         }
     }
@@ -1479,7 +1565,9 @@ public class AwSettings {
     private void updateWebkitPreferencesOnUiThreadLocked() {
         assert mEventHandler.mHandler != null;
         ThreadUtils.assertOnUiThread();
-        nativeUpdateWebkitPreferencesLocked(mNativeAwSettings);
+        if (mNativeAwSettings != 0) {
+            nativeUpdateWebkitPreferencesLocked(mNativeAwSettings);
+        }
     }
 
     private native long nativeInit(long webContentsPtr);
@@ -1501,4 +1589,6 @@ public class AwSettings {
     private static native String nativeGetDefaultUserAgent();
 
     private native void nativeUpdateFormDataPreferencesLocked(long nativeAwSettings);
+
+    private native void nativeUpdateRendererPreferencesLocked(long nativeAwSettings);
 }