diff options
author | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-10 12:45:52 +0000 |
---|---|---|
committer | mnaganov@chromium.org <mnaganov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-10 12:45:52 +0000 |
commit | ff022acf0a6119f1eca898bcb59de95a468f3eba (patch) | |
tree | eecd5ce44515399463aab53a5bda1ceaa7e2f312 /android_webview/java | |
parent | 364370127681a4256633eb1bc9dc7bdccf726405 (diff) | |
download | chromium_src-ff022acf0a6119f1eca898bcb59de95a468f3eba.zip chromium_src-ff022acf0a6119f1eca898bcb59de95a468f3eba.tar.gz chromium_src-ff022acf0a6119f1eca898bcb59de95a468f3eba.tar.bz2 |
[Android WebView] Remove direct access to fields in aw_settings
As per Marcus' proposal, replace direct access to Java object
fields with getter methods. This is less error-prone and leverages
facilities of automatic JNI code generation.
BUG=b/8296421
Review URL: https://chromiumcodereview.appspot.com/14698004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/java')
-rw-r--r-- | android_webview/java/src/org/chromium/android_webview/AwSettings.java | 199 |
1 files changed, 172 insertions, 27 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwSettings.java b/android_webview/java/src/org/chromium/android_webview/AwSettings.java index cd8c484..2cbaf53 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwSettings.java +++ b/android_webview/java/src/org/chromium/android_webview/AwSettings.java @@ -132,7 +132,7 @@ public class AwSettings { switch (msg.what) { case UPDATE_WEBKIT_PREFERENCES: synchronized (mAwSettingsLock) { - updateWebkitPreferencesOnUiThread(); + updateWebkitPreferencesOnUiThreadLocked(); mIsUpdateWebkitPrefsMessagePending = false; mAwSettingsLock.notifyAll(); } @@ -146,7 +146,7 @@ public class AwSettings { assert Thread.holdsLock(mAwSettingsLock); if (mNativeAwSettings == 0) return; if (Looper.myLooper() == mHandler.getLooper()) { - updateWebkitPreferencesOnUiThread(); + updateWebkitPreferencesOnUiThreadLocked(); } else { // We're being called on a background thread, so post a message. if (mIsUpdateWebkitPrefsMessagePending) { @@ -175,8 +175,6 @@ public class AwSettings { android.Manifest.permission.INTERNET, Process.myPid(), Process.myUid()) != PackageManager.PERMISSION_GRANTED; - mNativeAwSettings = nativeInit(nativeWebContents); - assert mNativeAwSettings != 0; mContentViewCore = contentViewCore; mContentViewCore.updateMultiTouchZoomSupport(supportsMultiTouchZoomLocked()); @@ -187,7 +185,11 @@ public class AwSettings { mEventHandler = new EventHandler(); mUserAgent = LazyDefaultUserAgent.sInstance; - nativeUpdateEverything(mNativeAwSettings); + + synchronized (mAwSettingsLock) { + mNativeAwSettings = nativeInit(nativeWebContents); + } + assert mNativeAwSettings != 0; } public void destroy() { @@ -201,9 +203,14 @@ public class AwSettings { } } + @CalledByNative + private double getDIPScaleLocked() { + return mDIPScale; + } + public void setWebContents(int nativeWebContents) { synchronized (mAwSettingsLock) { - nativeSetWebContents(mNativeAwSettings, nativeWebContents); + nativeSetWebContentsLocked(mNativeAwSettings, nativeWebContents); } } @@ -301,11 +308,6 @@ public class AwSettings { } } - @Deprecated - public void setEnableFixedLayoutMode(final boolean enable) { - // No-op. Will be removed. - } - /** * See {@link android.webkit.WebView#setInitialScale}. */ @@ -317,7 +319,7 @@ public class AwSettings { @Override public void run() { if (mNativeAwSettings != 0) { - nativeUpdateInitialPageScale(mNativeAwSettings); + nativeUpdateInitialPageScaleLocked(mNativeAwSettings); } } }); @@ -325,6 +327,11 @@ public class AwSettings { } } + @CalledByNative + private float getInitialPageScalePercentLocked() { + return mInitialPageScalePercent; + } + /** * See {@link android.webkit.WebSettings#setNeedInitialFocus}. */ @@ -378,7 +385,7 @@ public class AwSettings { @Override public void run() { if (mNativeAwSettings != 0) { - nativeUpdateUserAgent(mNativeAwSettings); + nativeUpdateUserAgentLocked(mNativeAwSettings); } } }); @@ -395,6 +402,11 @@ public class AwSettings { } } + @CalledByNative + private String getUserAgentLocked() { + return mUserAgent; + } + /** * See {@link android.webkit.WebSettings#setLoadWithOverviewMode}. */ @@ -424,6 +436,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getLoadWithOverviewModeLocked() { + return mLoadWithOverviewMode; + } + /** * See {@link android.webkit.WebSettings#setTextZoom}. */ @@ -445,6 +462,11 @@ public class AwSettings { } } + @CalledByNative + private int getTextSizePercentLocked() { + return mTextSizePercent; + } + /** * See {@link android.webkit.WebSettings#setStandardFontFamily}. */ @@ -466,6 +488,11 @@ public class AwSettings { } } + @CalledByNative + private String getStandardFontFamilyLocked() { + return mStandardFontFamily; + } + /** * See {@link android.webkit.WebSettings#setFixedFontFamily}. */ @@ -487,6 +514,11 @@ public class AwSettings { } } + @CalledByNative + private String getFixedFontFamilyLocked() { + return mFixedFontFamily; + } + /** * See {@link android.webkit.WebSettings#setSansSerifFontFamily}. */ @@ -508,6 +540,11 @@ public class AwSettings { } } + @CalledByNative + private String getSansSerifFontFamilyLocked() { + return mSansSerifFontFamily; + } + /** * See {@link android.webkit.WebSettings#setSerifFontFamily}. */ @@ -529,6 +566,11 @@ public class AwSettings { } } + @CalledByNative + private String getSerifFontFamilyLocked() { + return mSerifFontFamily; + } + /** * See {@link android.webkit.WebSettings#setCursiveFontFamily}. */ @@ -550,6 +592,11 @@ public class AwSettings { } } + @CalledByNative + private String getCursiveFontFamilyLocked() { + return mCursiveFontFamily; + } + /** * See {@link android.webkit.WebSettings#setFantasyFontFamily}. */ @@ -571,6 +618,11 @@ public class AwSettings { } } + @CalledByNative + private String getFantasyFontFamilyLocked() { + return mFantasyFontFamily; + } + /** * See {@link android.webkit.WebSettings#setMinimumFontSize}. */ @@ -593,6 +645,11 @@ public class AwSettings { } } + @CalledByNative + private int getMinimumFontSizeLocked() { + return mMinimumFontSize; + } + /** * See {@link android.webkit.WebSettings#setMinimumLogicalFontSize}. */ @@ -615,6 +672,11 @@ public class AwSettings { } } + @CalledByNative + private int getMinimumLogicalFontSizeLocked() { + return mMinimumLogicalFontSize; + } + /** * See {@link android.webkit.WebSettings#setDefaultFontSize}. */ @@ -637,6 +699,11 @@ public class AwSettings { } } + @CalledByNative + private int getDefaultFontSizeLocked() { + return mDefaultFontSize; + } + /** * See {@link android.webkit.WebSettings#setDefaultFixedFontSize}. */ @@ -659,6 +726,11 @@ public class AwSettings { } } + @CalledByNative + private int getDefaultFixedFontSizeLocked() { + return mDefaultFixedFontSize; + } + /** * See {@link android.webkit.WebSettings#setJavaScriptEnabled}. */ @@ -716,6 +788,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getLoadsImagesAutomaticallyLocked() { + return mLoadsImagesAutomatically; + } + /** * See {@link android.webkit.WebSettings#setImagesEnabled}. */ @@ -737,6 +814,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getImagesEnabledLocked() { + return mImagesEnabled; + } + /** * See {@link android.webkit.WebSettings#getJavaScriptEnabled}. */ @@ -746,6 +828,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getJavaScriptEnabledLocked() { + return mJavaScriptEnabled; + } + /** * See {@link android.webkit.WebSettings#getAllowUniversalAccessFromFileURLs}. */ @@ -755,6 +842,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getAllowUniversalAccessFromFileURLsLocked() { + return mAllowUniversalAccessFromFileURLs; + } + /** * See {@link android.webkit.WebSettings#getAllowFileAccessFromFileURLs}. */ @@ -764,6 +856,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getAllowFileAccessFromFileURLsLocked() { + return mAllowFileAccessFromFileURLs; + } + /** * See {@link android.webkit.WebSettings#setPluginsEnabled}. */ @@ -800,9 +897,7 @@ public class AwSettings { * @hide */ @CalledByNative - private boolean getPluginsDisabled() { - // This should only be called from UpdateWebkitPreferences, which is called - // either from the constructor, or with mAwSettingsLock being held. + private boolean getPluginsDisabledLocked() { return mPluginState == PluginState.OFF; } @@ -837,6 +932,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getJavaScriptCanOpenWindowsAutomaticallyLocked() { + return mJavaScriptCanOpenWindowsAutomatically; + } + /** * See {@link android.webkit.WebSettings#setLayoutAlgorithm}. */ @@ -865,7 +965,7 @@ public class AwSettings { * @hide */ @CalledByNative - private boolean getTextAutosizingEnabled() { + private boolean getTextAutosizingEnabledLocked() { return mLayoutAlgorithm == LayoutAlgorithm.TEXT_AUTOSIZING; } @@ -890,6 +990,16 @@ public class AwSettings { } } + @CalledByNative + private boolean getSupportMultipleWindowsLocked() { + return mSupportMultipleWindows; + } + + @CalledByNative + private boolean getSupportDeprecatedTargetDensityDPILocked() { + return mSupportDeprecatedTargetDensityDPI; + } + /** * See {@link android.webkit.WebSettings#setUseWideViewPort}. */ @@ -911,6 +1021,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getUseWideViewportLocked() { + return mUseWideViewport; + } + /** * See {@link android.webkit.WebSettings#setAppCacheEnabled}. */ @@ -952,9 +1067,7 @@ public class AwSettings { * @hide */ @CalledByNative - private boolean getAppCacheEnabled() { - // This should only be called from UpdateWebkitPreferences, which is called - // either from the constructor, or with mAwSettingsLock being held. + private boolean getAppCacheEnabledLocked() { if (!mAppCacheEnabled) { return false; } @@ -984,6 +1097,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getDomStorageEnabledLocked() { + return mDomStorageEnabled; + } + /** * See {@link android.webkit.WebSettings#setDatabaseEnabled}. */ @@ -1005,6 +1123,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getDatabaseEnabledLocked() { + return mDatabaseEnabled; + } + /** * See {@link android.webkit.WebSettings#setDefaultTextEncodingName}. */ @@ -1026,6 +1149,11 @@ public class AwSettings { } } + @CalledByNative + private String getDefaultTextEncodingLocked() { + return mDefaultTextEncoding; + } + /** * See {@link android.webkit.WebSettings#setMediaPlaybackRequiresUserGesture}. */ @@ -1047,6 +1175,11 @@ public class AwSettings { } } + @CalledByNative + private boolean getMediaPlaybackRequiresUserGestureLocked() { + return mMediaPlaybackRequiresUserGesture; + } + /** * See {@link android.webkit.WebSettings#setDefaultVideoPosterURL}. */ @@ -1069,6 +1202,11 @@ public class AwSettings { } } + @CalledByNative + private String getDefaultVideoPosterURLLocked() { + return mDefaultVideoPosterURL; + } + private void updateMultiTouchZoomSupport(final boolean supportsMultiTouchZoom) { ThreadUtils.runOnUiThreadBlocking(new Runnable() { @Override @@ -1163,10 +1301,17 @@ public class AwSettings { return size; } - private void updateWebkitPreferencesOnUiThread() { + @CalledByNative + private void updateEverything() { + synchronized (mAwSettingsLock) { + nativeUpdateEverythingLocked(mNativeAwSettings); + } + } + + private void updateWebkitPreferencesOnUiThreadLocked() { if (mNativeAwSettings != 0) { ThreadUtils.assertOnUiThread(); - nativeUpdateWebkitPreferences(mNativeAwSettings); + nativeUpdateWebkitPreferencesLocked(mNativeAwSettings); } } @@ -1176,15 +1321,15 @@ public class AwSettings { private native void nativeResetScrollAndScaleState(int nativeAwSettings); - private native void nativeSetWebContents(int nativeAwSettings, int nativeWebContents); + private native void nativeSetWebContentsLocked(int nativeAwSettings, int nativeWebContents); - private native void nativeUpdateEverything(int nativeAwSettings); + private native void nativeUpdateEverythingLocked(int nativeAwSettings); - private native void nativeUpdateInitialPageScale(int nativeAwSettings); + private native void nativeUpdateInitialPageScaleLocked(int nativeAwSettings); - private native void nativeUpdateUserAgent(int nativeAwSettings); + private native void nativeUpdateUserAgentLocked(int nativeAwSettings); - private native void nativeUpdateWebkitPreferences(int nativeAwSettings); + private native void nativeUpdateWebkitPreferencesLocked(int nativeAwSettings); private static native String nativeGetDefaultUserAgent(); } |