| 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. |
| 4 | |
| 5 | package org.chromium.android_webview; |
| 6 | |
| 7 | import android.content.Context; |
| 8 | import android.os.Handler; |
| 9 | import android.os.Looper; |
| 10 | import android.os.Message; |
| 11 | import android.provider.Settings; |
| 12 | import android.webkit.WebSettings.PluginState; |
| 13 | import android.webkit.WebSettings; |
| 14 | import android.webkit.WebView; |
| 15 | |
| 16 | import org.chromium.base.CalledByNative; |
| 17 | import org.chromium.base.JNINamespace; |
| 18 | import org.chromium.base.ThreadUtils; |
| 19 | import org.chromium.content.browser.ContentViewCore; |
| 20 | |
| 21 | /** |
| 22 | * Stores Android WebView specific settings that does not need to be synced to WebKit. |
| 23 | * Use {@link org.chromium.content.browser.ContentSettings} for WebKit settings. |
| 24 | * |
| 25 | * Methods in this class can be called from any thread, including threads created by |
| 26 | * the client of WebView. |
| 27 | */ |
| 28 | @JNINamespace("android_webview") |
| 29 | public class AwSettings { |
| 30 | // This enum corresponds to WebSettings.LayoutAlgorithm. We use our own to be |
| 31 | // able to extend it. |
| 32 | public enum LayoutAlgorithm { |
| 33 | NORMAL, |
| 34 | SINGLE_COLUMN, |
| 35 | NARROW_COLUMNS, |
| 36 | TEXT_AUTOSIZING, |
| 37 | } |
| 38 | |
| 39 | private static final String TAG = "AwSettings"; |
| 40 | |
| 41 | // This class must be created on the UI thread. Afterwards, it can be |
| 42 | // used from any thread. Internally, the class uses a message queue |
| 43 | // to call native code on the UI thread only. |
| 44 | |
| 45 | // Values passed in on construction. |
| 46 | private final boolean mHasInternetPermission; |
| 47 | private final ZoomSupportChangeListener mZoomChangeListener; |
| 48 | private final double mDIPScale; |
| 49 | |
| 50 | // Lock to protect all settings. |
| 51 | private final Object mAwSettingsLock = new Object(); |
| 52 | |
| 53 | private LayoutAlgorithm mLayoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS; |
| 54 | private int mTextSizePercent = 100; |
| 55 | private String mStandardFontFamily = "sans-serif"; |
| 56 | private String mFixedFontFamily = "monospace"; |
| 57 | private String mSansSerifFontFamily = "sans-serif"; |
| 58 | private String mSerifFontFamily = "serif"; |
| 59 | private String mCursiveFontFamily = "cursive"; |
| 60 | private String mFantasyFontFamily = "fantasy"; |
| 61 | // TODO(mnaganov): Should be obtained from Android. Problem: it is hidden. |
| 62 | private String mDefaultTextEncoding = "Latin-1"; |
| 63 | private String mUserAgent; |
| 64 | private int mMinimumFontSize = 8; |
| 65 | private int mMinimumLogicalFontSize = 8; |
| 66 | private int mDefaultFontSize = 16; |
| 67 | private int mDefaultFixedFontSize = 13; |
| 68 | private boolean mLoadsImagesAutomatically = true; |
| 69 | private boolean mImagesEnabled = true; |
| 70 | private boolean mJavaScriptEnabled = false; |
| 71 | private boolean mAllowUniversalAccessFromFileURLs = false; |
| 72 | private boolean mAllowFileAccessFromFileURLs = false; |
| 73 | private boolean mJavaScriptCanOpenWindowsAutomatically = false; |
| 74 | private boolean mSupportMultipleWindows = false; |
| 75 | private PluginState mPluginState = PluginState.OFF; |
| 76 | private boolean mAppCacheEnabled = false; |
| 77 | private boolean mDomStorageEnabled = false; |
| 78 | private boolean mDatabaseEnabled = false; |
| 79 | private boolean mUseWideViewport = false; |
| 80 | private boolean mLoadWithOverviewMode = false; |
| 81 | private boolean mMediaPlaybackRequiresUserGesture = true; |
| 82 | private String mDefaultVideoPosterURL; |
| 83 | private float mInitialPageScalePercent = 0; |
| 84 | |
| 85 | private final boolean mSupportDeprecatedTargetDensityDPI; |
| 86 | |
| 87 | private final boolean mPasswordEchoEnabled; |
| 88 | |
| 89 | // Not accessed by the native side. |
| 90 | private boolean mBlockNetworkLoads; // Default depends on permission of embedding APK. |
| 91 | private boolean mAllowContentUrlAccess = true; |
| 92 | private boolean mAllowFileUrlAccess = true; |
| 93 | private int mCacheMode = WebSettings.LOAD_DEFAULT; |
| 94 | private boolean mShouldFocusFirstNode = true; |
| 95 | private boolean mGeolocationEnabled = true; |
| 96 | private boolean mAutoCompleteEnabled = true; |
| 97 | private boolean mSupportZoom = true; |
| 98 | private boolean mBuiltInZoomControls = false; |
| 99 | private boolean mDisplayZoomControls = true; |
| 100 | |
| 101 | static class LazyDefaultUserAgent{ |
| 102 | // Lazy Holder pattern |
| 103 | private static final String sInstance = nativeGetDefaultUserAgent(); |
| 104 | } |
| 105 | |
| 106 | // Protects access to settings global fields. |
| 107 | private static final Object sGlobalContentSettingsLock = new Object(); |
| 108 | // For compatibility with the legacy WebView, we can only enable AppCache when the path is |
| 109 | // provided. However, we don't use the path, so we just check if we have received it from the |
| 110 | // client. |
| 111 | private static boolean sAppCachePathIsSet = false; |
| 112 | |
| 113 | // The native side of this object. It's lifetime is bounded by the WebContent it is attached to. |
| 114 | private int mNativeAwSettings = 0; |
| 115 | |
| 116 | // A flag to avoid sending superfluous synchronization messages. |
| 117 | private boolean mIsUpdateWebkitPrefsMessagePending = false; |
| 118 | // Custom handler that queues messages to call native code on the UI thread. |
| 119 | private final EventHandler mEventHandler; |
| 120 | |
| 121 | private static final int MINIMUM_FONT_SIZE = 1; |
| 122 | private static final int MAXIMUM_FONT_SIZE = 72; |
| 123 | |
| 124 | // Class to handle messages to be processed on the UI thread. |
| 125 | private class EventHandler { |
| 126 | // Message id for updating Webkit preferences |
| 127 | private static final int UPDATE_WEBKIT_PREFERENCES = 0; |
| 128 | // Actual UI thread handler |
| 129 | private Handler mHandler; |
| 130 | |
| 131 | EventHandler() { |
| 132 | mHandler = new Handler(Looper.getMainLooper()) { |
| 133 | @Override |
| 134 | public void handleMessage(Message msg) { |
| 135 | switch (msg.what) { |
| 136 | case UPDATE_WEBKIT_PREFERENCES: |
| 137 | synchronized (mAwSettingsLock) { |
| 138 | updateWebkitPreferencesOnUiThreadLocked(); |
| 139 | mIsUpdateWebkitPrefsMessagePending = false; |
| 140 | mAwSettingsLock.notifyAll(); |
| 141 | } |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | }; |
| 146 | } |
| 147 | |
| 148 | private void updateWebkitPreferencesLocked() { |
| 149 | assert Thread.holdsLock(mAwSettingsLock); |
| 150 | if (mNativeAwSettings == 0) return; |
| 151 | if (Looper.myLooper() == mHandler.getLooper()) { |
| 152 | updateWebkitPreferencesOnUiThreadLocked(); |
| 153 | } else { |
| 154 | // We're being called on a background thread, so post a message. |
| 155 | if (mIsUpdateWebkitPrefsMessagePending) { |
| 156 | return; |
| 157 | } |
| 158 | mIsUpdateWebkitPrefsMessagePending = true; |
| 159 | mHandler.sendMessage(Message.obtain(null, UPDATE_WEBKIT_PREFERENCES)); |
| 160 | // We must block until the settings have been sync'd to native to |
| 161 | // ensure that they have taken effect. |
| 162 | try { |
| 163 | while (mIsUpdateWebkitPrefsMessagePending) { |
| 164 | mAwSettingsLock.wait(); |
| 165 | } |
| 166 | } catch (InterruptedException e) {} |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | interface ZoomSupportChangeListener { |
| 172 | public void onGestureZoomSupportChanged(boolean supportsGestureZoom); |
| 173 | } |
| 174 | |
| 175 | public AwSettings(Context context, boolean hasInternetPermission, |
| 176 | ZoomSupportChangeListener zoomChangeListener, |
| 177 | boolean isAccessFromFileURLsGrantedByDefault, |
| 178 | double dipScale, |
| 179 | boolean supportsLegacyQuirks) { |
| 180 | ThreadUtils.assertOnUiThread(); |
| 181 | synchronized (mAwSettingsLock) { |
| 182 | mHasInternetPermission = hasInternetPermission; |
| 183 | mZoomChangeListener = zoomChangeListener; |
| 184 | mDIPScale = dipScale; |
| 185 | mEventHandler = new EventHandler(); |
| 186 | mBlockNetworkLoads = !hasInternetPermission; |
| 187 | |
| 188 | if (isAccessFromFileURLsGrantedByDefault) { |
| 189 | mAllowUniversalAccessFromFileURLs = true; |
| 190 | mAllowFileAccessFromFileURLs = true; |
| 191 | } |
| 192 | |
| 193 | mUserAgent = LazyDefaultUserAgent.sInstance; |
| 194 | onGestureZoomSupportChanged(supportsGestureZoomLocked()); |
| 195 | |
| 196 | // Respect the system setting for password echoing. |
| 197 | mPasswordEchoEnabled = Settings.System.getInt(context.getContentResolver(), |
| 198 | Settings.System.TEXT_SHOW_PASSWORD, 1) == 1; |
| 199 | |
| 200 | mSupportDeprecatedTargetDensityDPI = supportsLegacyQuirks; |
| 201 | } |
| 202 | // Defer initializing the native side until a native WebContents instance is set. |
| 203 | } |
| 204 | |
| 205 | @CalledByNative |
| 206 | private void nativeAwSettingsGone(int nativeAwSettings) { |
| 207 | assert mNativeAwSettings != 0 && mNativeAwSettings == nativeAwSettings; |
| 208 | mNativeAwSettings = 0; |
| 209 | } |
| 210 | |
| 211 | @CalledByNative |
| 212 | private double getDIPScaleLocked() { |
| 213 | return mDIPScale; |
| 214 | } |
| 215 | |
| 216 | public void setWebContents(int nativeWebContents) { |
| 217 | synchronized (mAwSettingsLock) { |
| 218 | if (mNativeAwSettings != 0) { |
| 219 | nativeDestroy(mNativeAwSettings); |
| 220 | assert mNativeAwSettings == 0; // nativeAwSettingsGone should have been called. |
| 221 | } |
| 222 | if (nativeWebContents != 0) { |
| 223 | mNativeAwSettings = nativeInit(nativeWebContents); |
| 224 | nativeUpdateEverythingLocked(mNativeAwSettings); |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * See {@link android.webkit.WebSettings#setBlockNetworkLoads}. |
| 231 | */ |
| 232 | public void setBlockNetworkLoads(boolean flag) { |
| 233 | synchronized (mAwSettingsLock) { |
| 234 | if (!flag && !mHasInternetPermission) { |
| 235 | throw new SecurityException("Permission denied - " + |
| 236 | "application missing INTERNET permission"); |
| 237 | } |
| 238 | mBlockNetworkLoads = flag; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * See {@link android.webkit.WebSettings#getBlockNetworkLoads}. |
| 244 | */ |
| 245 | public boolean getBlockNetworkLoads() { |
| 246 | synchronized (mAwSettingsLock) { |
| 247 | return mBlockNetworkLoads; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * See {@link android.webkit.WebSettings#setAllowFileAccess}. |
| 253 | */ |
| 254 | public void setAllowFileAccess(boolean allow) { |
| 255 | synchronized (mAwSettingsLock) { |
| 256 | if (mAllowFileUrlAccess != allow) { |
| 257 | mAllowFileUrlAccess = allow; |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * See {@link android.webkit.WebSettings#getAllowFileAccess}. |
| 264 | */ |
| 265 | public boolean getAllowFileAccess() { |
| 266 | synchronized (mAwSettingsLock) { |
| 267 | return mAllowFileUrlAccess; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * See {@link android.webkit.WebSettings#setAllowContentAccess}. |
| 273 | */ |
| 274 | public void setAllowContentAccess(boolean allow) { |
| 275 | synchronized (mAwSettingsLock) { |
| 276 | if (mAllowContentUrlAccess != allow) { |
| 277 | mAllowContentUrlAccess = allow; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * See {@link android.webkit.WebSettings#getAllowContentAccess}. |
| 284 | */ |
| 285 | public boolean getAllowContentAccess() { |
| 286 | synchronized (mAwSettingsLock) { |
| 287 | return mAllowContentUrlAccess; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * See {@link android.webkit.WebSettings#setCacheMode}. |
| 293 | */ |
| 294 | public void setCacheMode(int mode) { |
| 295 | synchronized (mAwSettingsLock) { |
| 296 | if (mCacheMode != mode) { |
| 297 | mCacheMode = mode; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * See {@link android.webkit.WebSettings#getCacheMode}. |
| 304 | */ |
| 305 | public int getCacheMode() { |
| 306 | synchronized (mAwSettingsLock) { |
| 307 | return mCacheMode; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * See {@link android.webkit.WebSettings#setNeedInitialFocus}. |
| 313 | */ |
| 314 | public void setShouldFocusFirstNode(boolean flag) { |
| 315 | synchronized (mAwSettingsLock) { |
| 316 | mShouldFocusFirstNode = flag; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * See {@link android.webkit.WebView#setInitialScale}. |
| 322 | */ |
| 323 | public void setInitialPageScale(final float scaleInPercent) { |
| 324 | synchronized (mAwSettingsLock) { |
| 325 | if (mInitialPageScalePercent != scaleInPercent) { |
| 326 | mInitialPageScalePercent = scaleInPercent; |
| 327 | ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 328 | @Override |
| 329 | public void run() { |
| 330 | if (mNativeAwSettings != 0) { |
| 331 | nativeUpdateInitialPageScaleLocked(mNativeAwSettings); |
| 332 | } |
| 333 | } |
| 334 | }); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | @CalledByNative |
| 340 | private float getInitialPageScalePercentLocked() { |
| 341 | return mInitialPageScalePercent; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * See {@link android.webkit.WebSettings#setNeedInitialFocus}. |
| 346 | */ |
| 347 | public boolean shouldFocusFirstNode() { |
| 348 | synchronized(mAwSettingsLock) { |
| 349 | return mShouldFocusFirstNode; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * See {@link android.webkit.WebSettings#setGeolocationEnabled}. |
| 355 | */ |
| 356 | public void setGeolocationEnabled(boolean flag) { |
| 357 | synchronized (mAwSettingsLock) { |
| 358 | if (mGeolocationEnabled != flag) { |
| 359 | mGeolocationEnabled = flag; |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * @return Returns if geolocation is currently enabled. |
| 366 | */ |
| 367 | boolean getGeolocationEnabled() { |
| 368 | synchronized (mAwSettingsLock) { |
| 369 | return mGeolocationEnabled; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * See {@link android.webkit.WebSettings#setSaveFormData}. |
| 375 | */ |
| 376 | public void setSaveFormData(final boolean enable) { |
| 377 | synchronized (mAwSettingsLock) { |
| 378 | if (mAutoCompleteEnabled != enable) { |
| 379 | mAutoCompleteEnabled = enable; |
| 380 | ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 381 | @Override |
| 382 | public void run() { |
| 383 | if (mNativeAwSettings != 0) { |
| 384 | nativeUpdateFormDataPreferencesLocked(mNativeAwSettings); |
| 385 | } |
| 386 | } |
| 387 | }); |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * See {@link android.webkit.WebSettings#getSaveFormData}. |
| 394 | */ |
| 395 | public boolean getSaveFormData() { |
| 396 | synchronized (mAwSettingsLock) { |
| 397 | return getSaveFormDataLocked(); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | @CalledByNative |
| 402 | private boolean getSaveFormDataLocked() { |
| 403 | return mAutoCompleteEnabled; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * @returns the default User-Agent used by each ContentViewCore instance, i.e. unless |
| 408 | * overridden by {@link #setUserAgentString()} |
| 409 | */ |
| 410 | public static String getDefaultUserAgent() { |
| 411 | return LazyDefaultUserAgent.sInstance; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * See {@link android.webkit.WebSettings#setUserAgentString}. |
| 416 | */ |
| 417 | public void setUserAgentString(String ua) { |
| 418 | synchronized (mAwSettingsLock) { |
| 419 | final String oldUserAgent = mUserAgent; |
| 420 | if (ua == null || ua.length() == 0) { |
| 421 | mUserAgent = LazyDefaultUserAgent.sInstance; |
| 422 | } else { |
| 423 | mUserAgent = ua; |
| 424 | } |
| 425 | if (!oldUserAgent.equals(mUserAgent)) { |
| 426 | ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 427 | @Override |
| 428 | public void run() { |
| 429 | if (mNativeAwSettings != 0) { |
| 430 | nativeUpdateUserAgentLocked(mNativeAwSettings); |
| 431 | } |
| 432 | } |
| 433 | }); |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * See {@link android.webkit.WebSettings#getUserAgentString}. |
| 440 | */ |
| 441 | public String getUserAgentString() { |
| 442 | synchronized (mAwSettingsLock) { |
| 443 | return mUserAgent; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | @CalledByNative |
| 448 | private String getUserAgentLocked() { |
| 449 | return mUserAgent; |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * See {@link android.webkit.WebSettings#setLoadWithOverviewMode}. |
| 454 | */ |
| 455 | public void setLoadWithOverviewMode(boolean overview) { |
| 456 | synchronized (mAwSettingsLock) { |
| 457 | if (mLoadWithOverviewMode != overview) { |
| 458 | mLoadWithOverviewMode = overview; |
| 459 | mEventHandler.updateWebkitPreferencesLocked(); |
| 460 | ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 461 | @Override |
| 462 | public void run() { |
| 463 | if (mNativeAwSettings != 0) { |
| 464 | nativeResetScrollAndScaleState(mNativeAwSettings); |
| 465 | } |
| 466 | } |
| 467 | }); |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * See {@link android.webkit.WebSettings#getLoadWithOverviewMode}. |
| 474 | */ |
| 475 | public boolean getLoadWithOverviewMode() { |
| 476 | synchronized (mAwSettingsLock) { |
| 477 | return mLoadWithOverviewMode; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | @CalledByNative |
| 482 | private boolean getLoadWithOverviewModeLocked() { |
| 483 | return mLoadWithOverviewMode; |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * See {@link android.webkit.WebSettings#setTextZoom}. |
| 488 | */ |
| 489 | public void setTextZoom(final int textZoom) { |
| 490 | synchronized (mAwSettingsLock) { |
| 491 | if (mTextSizePercent != textZoom) { |
| 492 | mTextSizePercent = textZoom; |
| 493 | mEventHandler.updateWebkitPreferencesLocked(); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * See {@link android.webkit.WebSettings#getTextZoom}. |
| 500 | */ |
| 501 | public int getTextZoom() { |
| 502 | synchronized (mAwSettingsLock) { |
| 503 | return mTextSizePercent; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | @CalledByNative |
| 508 | private int getTextSizePercentLocked() { |
| 509 | return mTextSizePercent; |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * See {@link android.webkit.WebSettings#setStandardFontFamily}. |
| 514 | */ |
| 515 | public void setStandardFontFamily(String font) { |
| 516 | synchronized (mAwSettingsLock) { |
| 517 | if (font != null && !mStandardFontFamily.equals(font)) { |
| 518 | mStandardFontFamily = font; |
| 519 | mEventHandler.updateWebkitPreferencesLocked(); |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * See {@link android.webkit.WebSettings#getStandardFontFamily}. |
| 526 | */ |
| 527 | public String getStandardFontFamily() { |
| 528 | synchronized (mAwSettingsLock) { |
| 529 | return mStandardFontFamily; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | @CalledByNative |
| 534 | private String getStandardFontFamilyLocked() { |
| 535 | return mStandardFontFamily; |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * See {@link android.webkit.WebSettings#setFixedFontFamily}. |
| 540 | */ |
| 541 | public void setFixedFontFamily(String font) { |
| 542 | synchronized (mAwSettingsLock) { |
| 543 | if (font != null && !mFixedFontFamily.equals(font)) { |
| 544 | mFixedFontFamily = font; |
| 545 | mEventHandler.updateWebkitPreferencesLocked(); |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * See {@link android.webkit.WebSettings#getFixedFontFamily}. |
| 552 | */ |
| 553 | public String getFixedFontFamily() { |
| 554 | synchronized (mAwSettingsLock) { |
| 555 | return mFixedFontFamily; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | @CalledByNative |
| 560 | private String getFixedFontFamilyLocked() { |
| 561 | return mFixedFontFamily; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * See {@link android.webkit.WebSettings#setSansSerifFontFamily}. |
| 566 | */ |
| 567 | public void setSansSerifFontFamily(String font) { |
| 568 | synchronized (mAwSettingsLock) { |
| 569 | if (font != null && !mSansSerifFontFamily.equals(font)) { |
| 570 | mSansSerifFontFamily = font; |
| 571 | mEventHandler.updateWebkitPreferencesLocked(); |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * See {@link android.webkit.WebSettings#getSansSerifFontFamily}. |
| 578 | */ |
| 579 | public String getSansSerifFontFamily() { |
| 580 | synchronized (mAwSettingsLock) { |
| 581 | return mSansSerifFontFamily; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | @CalledByNative |
| 586 | private String getSansSerifFontFamilyLocked() { |
| 587 | return mSansSerifFontFamily; |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * See {@link android.webkit.WebSettings#setSerifFontFamily}. |
| 592 | */ |
| 593 | public void setSerifFontFamily(String font) { |
| 594 | synchronized (mAwSettingsLock) { |
| 595 | if (font != null && !mSerifFontFamily.equals(font)) { |
| 596 | mSerifFontFamily = font; |
| 597 | mEventHandler.updateWebkitPreferencesLocked(); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * See {@link android.webkit.WebSettings#getSerifFontFamily}. |
| 604 | */ |
| 605 | public String getSerifFontFamily() { |
| 606 | synchronized (mAwSettingsLock) { |
| 607 | return mSerifFontFamily; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | @CalledByNative |
| 612 | private String getSerifFontFamilyLocked() { |
| 613 | return mSerifFontFamily; |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * See {@link android.webkit.WebSettings#setCursiveFontFamily}. |
| 618 | */ |
| 619 | public void setCursiveFontFamily(String font) { |
| 620 | synchronized (mAwSettingsLock) { |
| 621 | if (font != null && !mCursiveFontFamily.equals(font)) { |
| 622 | mCursiveFontFamily = font; |
| 623 | mEventHandler.updateWebkitPreferencesLocked(); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * See {@link android.webkit.WebSettings#getCursiveFontFamily}. |
| 630 | */ |
| 631 | public String getCursiveFontFamily() { |
| 632 | synchronized (mAwSettingsLock) { |
| 633 | return mCursiveFontFamily; |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | @CalledByNative |
| 638 | private String getCursiveFontFamilyLocked() { |
| 639 | return mCursiveFontFamily; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * See {@link android.webkit.WebSettings#setFantasyFontFamily}. |
| 644 | */ |
| 645 | public void setFantasyFontFamily(String font) { |
| 646 | synchronized (mAwSettingsLock) { |
| 647 | if (font != null && !mFantasyFontFamily.equals(font)) { |
| 648 | mFantasyFontFamily = font; |
| 649 | mEventHandler.updateWebkitPreferencesLocked(); |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * See {@link android.webkit.WebSettings#getFantasyFontFamily}. |
| 656 | */ |
| 657 | public String getFantasyFontFamily() { |
| 658 | synchronized (mAwSettingsLock) { |
| 659 | return mFantasyFontFamily; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | @CalledByNative |
| 664 | private String getFantasyFontFamilyLocked() { |
| 665 | return mFantasyFontFamily; |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * See {@link android.webkit.WebSettings#setMinimumFontSize}. |
| 670 | */ |
| 671 | public void setMinimumFontSize(int size) { |
| 672 | synchronized (mAwSettingsLock) { |
| 673 | size = clipFontSize(size); |
| 674 | if (mMinimumFontSize != size) { |
| 675 | mMinimumFontSize = size; |
| 676 | mEventHandler.updateWebkitPreferencesLocked(); |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * See {@link android.webkit.WebSettings#getMinimumFontSize}. |
| 683 | */ |
| 684 | public int getMinimumFontSize() { |
| 685 | synchronized (mAwSettingsLock) { |
| 686 | return mMinimumFontSize; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | @CalledByNative |
| 691 | private int getMinimumFontSizeLocked() { |
| 692 | return mMinimumFontSize; |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * See {@link android.webkit.WebSettings#setMinimumLogicalFontSize}. |
| 697 | */ |
| 698 | public void setMinimumLogicalFontSize(int size) { |
| 699 | synchronized (mAwSettingsLock) { |
| 700 | size = clipFontSize(size); |
| 701 | if (mMinimumLogicalFontSize != size) { |
| 702 | mMinimumLogicalFontSize = size; |
| 703 | mEventHandler.updateWebkitPreferencesLocked(); |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * See {@link android.webkit.WebSettings#getMinimumLogicalFontSize}. |
| 710 | */ |
| 711 | public int getMinimumLogicalFontSize() { |
| 712 | synchronized (mAwSettingsLock) { |
| 713 | return mMinimumLogicalFontSize; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | @CalledByNative |
| 718 | private int getMinimumLogicalFontSizeLocked() { |
| 719 | return mMinimumLogicalFontSize; |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * See {@link android.webkit.WebSettings#setDefaultFontSize}. |
| 724 | */ |
| 725 | public void setDefaultFontSize(int size) { |
| 726 | synchronized (mAwSettingsLock) { |
| 727 | size = clipFontSize(size); |
| 728 | if (mDefaultFontSize != size) { |
| 729 | mDefaultFontSize = size; |
| 730 | mEventHandler.updateWebkitPreferencesLocked(); |
| 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * See {@link android.webkit.WebSettings#getDefaultFontSize}. |
| 737 | */ |
| 738 | public int getDefaultFontSize() { |
| 739 | synchronized (mAwSettingsLock) { |
| 740 | return mDefaultFontSize; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | @CalledByNative |
| 745 | private int getDefaultFontSizeLocked() { |
| 746 | return mDefaultFontSize; |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * See {@link android.webkit.WebSettings#setDefaultFixedFontSize}. |
| 751 | */ |
| 752 | public void setDefaultFixedFontSize(int size) { |
| 753 | synchronized (mAwSettingsLock) { |
| 754 | size = clipFontSize(size); |
| 755 | if (mDefaultFixedFontSize != size) { |
| 756 | mDefaultFixedFontSize = size; |
| 757 | mEventHandler.updateWebkitPreferencesLocked(); |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * See {@link android.webkit.WebSettings#getDefaultFixedFontSize}. |
| 764 | */ |
| 765 | public int getDefaultFixedFontSize() { |
| 766 | synchronized (mAwSettingsLock) { |
| 767 | return mDefaultFixedFontSize; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | @CalledByNative |
| 772 | private int getDefaultFixedFontSizeLocked() { |
| 773 | return mDefaultFixedFontSize; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * See {@link android.webkit.WebSettings#setJavaScriptEnabled}. |
| 778 | */ |
| 779 | public void setJavaScriptEnabled(boolean flag) { |
| 780 | synchronized (mAwSettingsLock) { |
| 781 | if (mJavaScriptEnabled != flag) { |
| 782 | mJavaScriptEnabled = flag; |
| 783 | mEventHandler.updateWebkitPreferencesLocked(); |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | /** |
| 789 | * See {@link android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs}. |
| 790 | */ |
| 791 | public void setAllowUniversalAccessFromFileURLs(boolean flag) { |
| 792 | synchronized (mAwSettingsLock) { |
| 793 | if (mAllowUniversalAccessFromFileURLs != flag) { |
| 794 | mAllowUniversalAccessFromFileURLs = flag; |
| 795 | mEventHandler.updateWebkitPreferencesLocked(); |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * See {@link android.webkit.WebSettings#setAllowFileAccessFromFileURLs}. |
| 802 | */ |
| 803 | public void setAllowFileAccessFromFileURLs(boolean flag) { |
| 804 | synchronized (mAwSettingsLock) { |
| 805 | if (mAllowFileAccessFromFileURLs != flag) { |
| 806 | mAllowFileAccessFromFileURLs = flag; |
| 807 | mEventHandler.updateWebkitPreferencesLocked(); |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * See {@link android.webkit.WebSettings#setLoadsImagesAutomatically}. |
| 814 | */ |
| 815 | public void setLoadsImagesAutomatically(boolean flag) { |
| 816 | synchronized (mAwSettingsLock) { |
| 817 | if (mLoadsImagesAutomatically != flag) { |
| 818 | mLoadsImagesAutomatically = flag; |
| 819 | mEventHandler.updateWebkitPreferencesLocked(); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * See {@link android.webkit.WebSettings#getLoadsImagesAutomatically}. |
| 826 | */ |
| 827 | public boolean getLoadsImagesAutomatically() { |
| 828 | synchronized (mAwSettingsLock) { |
| 829 | return mLoadsImagesAutomatically; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | @CalledByNative |
| 834 | private boolean getLoadsImagesAutomaticallyLocked() { |
| 835 | return mLoadsImagesAutomatically; |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * See {@link android.webkit.WebSettings#setImagesEnabled}. |
| 840 | */ |
| 841 | public void setImagesEnabled(boolean flag) { |
| 842 | synchronized (mAwSettingsLock) { |
| 843 | if (mImagesEnabled != flag) { |
| 844 | mImagesEnabled = flag; |
| 845 | mEventHandler.updateWebkitPreferencesLocked(); |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | /** |
| 851 | * See {@link android.webkit.WebSettings#getImagesEnabled}. |
| 852 | */ |
| 853 | public boolean getImagesEnabled() { |
| 854 | synchronized (mAwSettingsLock) { |
| 855 | return mImagesEnabled; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | @CalledByNative |
| 860 | private boolean getImagesEnabledLocked() { |
| 861 | return mImagesEnabled; |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * See {@link android.webkit.WebSettings#getJavaScriptEnabled}. |
| 866 | */ |
| 867 | public boolean getJavaScriptEnabled() { |
| 868 | synchronized (mAwSettingsLock) { |
| 869 | return mJavaScriptEnabled; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | @CalledByNative |
| 874 | private boolean getJavaScriptEnabledLocked() { |
| 875 | return mJavaScriptEnabled; |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * See {@link android.webkit.WebSettings#getAllowUniversalAccessFromFileURLs}. |
| 880 | */ |
| 881 | public boolean getAllowUniversalAccessFromFileURLs() { |
| 882 | synchronized (mAwSettingsLock) { |
| 883 | return mAllowUniversalAccessFromFileURLs; |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | @CalledByNative |
| 888 | private boolean getAllowUniversalAccessFromFileURLsLocked() { |
| 889 | return mAllowUniversalAccessFromFileURLs; |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * See {@link android.webkit.WebSettings#getAllowFileAccessFromFileURLs}. |
| 894 | */ |
| 895 | public boolean getAllowFileAccessFromFileURLs() { |
| 896 | synchronized (mAwSettingsLock) { |
| 897 | return mAllowFileAccessFromFileURLs; |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | @CalledByNative |
| 902 | private boolean getAllowFileAccessFromFileURLsLocked() { |
| 903 | return mAllowFileAccessFromFileURLs; |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * See {@link android.webkit.WebSettings#setPluginsEnabled}. |
| 908 | */ |
| 909 | public void setPluginsEnabled(boolean flag) { |
| 910 | setPluginState(flag ? PluginState.ON : PluginState.OFF); |
| 911 | } |
| 912 | |
| 913 | /** |
| 914 | * See {@link android.webkit.WebSettings#setPluginState}. |
| 915 | */ |
| 916 | public void setPluginState(PluginState state) { |
| 917 | synchronized (mAwSettingsLock) { |
| 918 | if (mPluginState != state) { |
| 919 | mPluginState = state; |
| 920 | mEventHandler.updateWebkitPreferencesLocked(); |
| 921 | } |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | /** |
| 926 | * See {@link android.webkit.WebSettings#getPluginsEnabled}. |
| 927 | */ |
| 928 | public boolean getPluginsEnabled() { |
| 929 | synchronized (mAwSettingsLock) { |
| 930 | return mPluginState == PluginState.ON; |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Return true if plugins are disabled. |
| 936 | * @return True if plugins are disabled. |
| 937 | * @hide |
| 938 | */ |
| 939 | @CalledByNative |
| 940 | private boolean getPluginsDisabledLocked() { |
| 941 | return mPluginState == PluginState.OFF; |
| 942 | } |
| 943 | |
| 944 | /** |
| 945 | * See {@link android.webkit.WebSettings#getPluginState}. |
| 946 | */ |
| 947 | public PluginState getPluginState() { |
| 948 | synchronized (mAwSettingsLock) { |
| 949 | return mPluginState; |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | |
| 954 | /** |
| 955 | * See {@link android.webkit.WebSettings#setJavaScriptCanOpenWindowsAutomatically}. |
| 956 | */ |
| 957 | public void setJavaScriptCanOpenWindowsAutomatically(boolean flag) { |
| 958 | synchronized (mAwSettingsLock) { |
| 959 | if (mJavaScriptCanOpenWindowsAutomatically != flag) { |
| 960 | mJavaScriptCanOpenWindowsAutomatically = flag; |
| 961 | mEventHandler.updateWebkitPreferencesLocked(); |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * See {@link android.webkit.WebSettings#getJavaScriptCanOpenWindowsAutomatically}. |
| 968 | */ |
| 969 | public boolean getJavaScriptCanOpenWindowsAutomatically() { |
| 970 | synchronized (mAwSettingsLock) { |
| 971 | return mJavaScriptCanOpenWindowsAutomatically; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | @CalledByNative |
| 976 | private boolean getJavaScriptCanOpenWindowsAutomaticallyLocked() { |
| 977 | return mJavaScriptCanOpenWindowsAutomatically; |
| 978 | } |
| 979 | |
| 980 | /** |
| 981 | * See {@link android.webkit.WebSettings#setLayoutAlgorithm}. |
| 982 | */ |
| 983 | public void setLayoutAlgorithm(LayoutAlgorithm l) { |
| 984 | synchronized (mAwSettingsLock) { |
| 985 | if (mLayoutAlgorithm != l) { |
| 986 | mLayoutAlgorithm = l; |
| 987 | mEventHandler.updateWebkitPreferencesLocked(); |
| 988 | } |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * See {@link android.webkit.WebSettings#getLayoutAlgorithm}. |
| 994 | */ |
| 995 | public LayoutAlgorithm getLayoutAlgorithm() { |
| 996 | synchronized (mAwSettingsLock) { |
| 997 | return mLayoutAlgorithm; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * Gets whether Text Auto-sizing layout algorithm is enabled. |
| 1003 | * |
| 1004 | * @return true if Text Auto-sizing layout algorithm is enabled |
| 1005 | * @hide |
| 1006 | */ |
| 1007 | @CalledByNative |
| 1008 | private boolean getTextAutosizingEnabledLocked() { |
| 1009 | return mLayoutAlgorithm == LayoutAlgorithm.TEXT_AUTOSIZING; |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * See {@link android.webkit.WebSettings#setSupportMultipleWindows}. |
| 1014 | */ |
| 1015 | public void setSupportMultipleWindows(boolean support) { |
| 1016 | synchronized (mAwSettingsLock) { |
| 1017 | if (mSupportMultipleWindows != support) { |
| 1018 | mSupportMultipleWindows = support; |
| 1019 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * See {@link android.webkit.WebSettings#supportMultipleWindows}. |
| 1026 | */ |
| 1027 | public boolean supportMultipleWindows() { |
| 1028 | synchronized (mAwSettingsLock) { |
| 1029 | return mSupportMultipleWindows; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | @CalledByNative |
| 1034 | private boolean getSupportMultipleWindowsLocked() { |
| 1035 | return mSupportMultipleWindows; |
| 1036 | } |
| 1037 | |
| 1038 | @CalledByNative |
| 1039 | private boolean getSupportDeprecatedTargetDensityDPILocked() { |
| 1040 | return mSupportDeprecatedTargetDensityDPI; |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * See {@link android.webkit.WebSettings#setUseWideViewPort}. |
| 1045 | */ |
| 1046 | public void setUseWideViewPort(boolean use) { |
| 1047 | synchronized (mAwSettingsLock) { |
| 1048 | if (mUseWideViewport != use) { |
| 1049 | mUseWideViewport = use; |
| 1050 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | /** |
| 1056 | * See {@link android.webkit.WebSettings#getUseWideViewPort}. |
| 1057 | */ |
| 1058 | public boolean getUseWideViewPort() { |
| 1059 | synchronized (mAwSettingsLock) { |
| 1060 | return mUseWideViewport; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | @CalledByNative |
| 1065 | private boolean getUseWideViewportLocked() { |
| 1066 | return mUseWideViewport; |
| 1067 | } |
| 1068 | |
| 1069 | @CalledByNative |
| 1070 | private boolean getPasswordEchoEnabled() { |
| 1071 | return mPasswordEchoEnabled; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * See {@link android.webkit.WebSettings#setAppCacheEnabled}. |
| 1076 | */ |
| 1077 | public void setAppCacheEnabled(boolean flag) { |
| 1078 | synchronized (mAwSettingsLock) { |
| 1079 | if (mAppCacheEnabled != flag) { |
| 1080 | mAppCacheEnabled = flag; |
| 1081 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | * See {@link android.webkit.WebSettings#setAppCachePath}. |
| 1088 | */ |
| 1089 | public void setAppCachePath(String path) { |
| 1090 | boolean needToSync = false; |
| 1091 | synchronized (sGlobalContentSettingsLock) { |
| 1092 | // AppCachePath can only be set once. |
| 1093 | if (!sAppCachePathIsSet && path != null && !path.isEmpty()) { |
| 1094 | sAppCachePathIsSet = true; |
| 1095 | needToSync = true; |
| 1096 | } |
| 1097 | } |
| 1098 | // The obvious problem here is that other WebViews will not be updated, |
| 1099 | // until they execute synchronization from Java to the native side. |
| 1100 | // But this is the same behaviour as it was in the legacy WebView. |
| 1101 | if (needToSync) { |
| 1102 | synchronized (mAwSettingsLock) { |
| 1103 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | /** |
| 1109 | * Gets whether Application Cache is enabled. |
| 1110 | * |
| 1111 | * @return true if Application Cache is enabled |
| 1112 | * @hide |
| 1113 | */ |
| 1114 | @CalledByNative |
| 1115 | private boolean getAppCacheEnabledLocked() { |
| 1116 | if (!mAppCacheEnabled) { |
| 1117 | return false; |
| 1118 | } |
| 1119 | synchronized (sGlobalContentSettingsLock) { |
| 1120 | return sAppCachePathIsSet; |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * See {@link android.webkit.WebSettings#setDomStorageEnabled}. |
| 1126 | */ |
| 1127 | public void setDomStorageEnabled(boolean flag) { |
| 1128 | synchronized (mAwSettingsLock) { |
| 1129 | if (mDomStorageEnabled != flag) { |
| 1130 | mDomStorageEnabled = flag; |
| 1131 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * See {@link android.webkit.WebSettings#getDomStorageEnabled}. |
| 1138 | */ |
| 1139 | public boolean getDomStorageEnabled() { |
| 1140 | synchronized (mAwSettingsLock) { |
| 1141 | return mDomStorageEnabled; |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | @CalledByNative |
| 1146 | private boolean getDomStorageEnabledLocked() { |
| 1147 | return mDomStorageEnabled; |
| 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * See {@link android.webkit.WebSettings#setDatabaseEnabled}. |
| 1152 | */ |
| 1153 | public void setDatabaseEnabled(boolean flag) { |
| 1154 | synchronized (mAwSettingsLock) { |
| 1155 | if (mDatabaseEnabled != flag) { |
| 1156 | mDatabaseEnabled = flag; |
| 1157 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * See {@link android.webkit.WebSettings#getDatabaseEnabled}. |
| 1164 | */ |
| 1165 | public boolean getDatabaseEnabled() { |
| 1166 | synchronized (mAwSettingsLock) { |
| 1167 | return mDatabaseEnabled; |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | @CalledByNative |
| 1172 | private boolean getDatabaseEnabledLocked() { |
| 1173 | return mDatabaseEnabled; |
| 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * See {@link android.webkit.WebSettings#setDefaultTextEncodingName}. |
| 1178 | */ |
| 1179 | public void setDefaultTextEncodingName(String encoding) { |
| 1180 | synchronized (mAwSettingsLock) { |
| 1181 | if (encoding != null && !mDefaultTextEncoding.equals(encoding)) { |
| 1182 | mDefaultTextEncoding = encoding; |
| 1183 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | /** |
| 1189 | * See {@link android.webkit.WebSettings#getDefaultTextEncodingName}. |
| 1190 | */ |
| 1191 | public String getDefaultTextEncodingName() { |
| 1192 | synchronized (mAwSettingsLock) { |
| 1193 | return mDefaultTextEncoding; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | @CalledByNative |
| 1198 | private String getDefaultTextEncodingLocked() { |
| 1199 | return mDefaultTextEncoding; |
| 1200 | } |
| 1201 | |
| 1202 | /** |
| 1203 | * See {@link android.webkit.WebSettings#setMediaPlaybackRequiresUserGesture}. |
| 1204 | */ |
| 1205 | public void setMediaPlaybackRequiresUserGesture(boolean require) { |
| 1206 | synchronized (mAwSettingsLock) { |
| 1207 | if (mMediaPlaybackRequiresUserGesture != require) { |
| 1208 | mMediaPlaybackRequiresUserGesture = require; |
| 1209 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1210 | } |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * See {@link android.webkit.WebSettings#getMediaPlaybackRequiresUserGesture}. |
| 1216 | */ |
| 1217 | public boolean getMediaPlaybackRequiresUserGesture() { |
| 1218 | synchronized (mAwSettingsLock) { |
| 1219 | return mMediaPlaybackRequiresUserGesture; |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | @CalledByNative |
| 1224 | private boolean getMediaPlaybackRequiresUserGestureLocked() { |
| 1225 | return mMediaPlaybackRequiresUserGesture; |
| 1226 | } |
| 1227 | |
| 1228 | /** |
| 1229 | * See {@link android.webkit.WebSettings#setDefaultVideoPosterURL}. |
| 1230 | */ |
| 1231 | public void setDefaultVideoPosterURL(String url) { |
| 1232 | synchronized (mAwSettingsLock) { |
| 1233 | if (mDefaultVideoPosterURL != null && !mDefaultVideoPosterURL.equals(url) || |
| 1234 | mDefaultVideoPosterURL == null && url != null) { |
| 1235 | mDefaultVideoPosterURL = url; |
| 1236 | mEventHandler.updateWebkitPreferencesLocked(); |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * See {@link android.webkit.WebSettings#getDefaultVideoPosterURL}. |
| 1243 | */ |
| 1244 | public String getDefaultVideoPosterURL() { |
| 1245 | synchronized (mAwSettingsLock) { |
| 1246 | return mDefaultVideoPosterURL; |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | @CalledByNative |
| 1251 | private String getDefaultVideoPosterURLLocked() { |
| 1252 | return mDefaultVideoPosterURL; |
| 1253 | } |
| 1254 | |
| 1255 | private void onGestureZoomSupportChanged(final boolean supportsGestureZoom) { |
| 1256 | // Always post asynchronously here, to avoid doubling back onto the caller. |
| 1257 | ThreadUtils.postOnUiThread(new Runnable() { |
| 1258 | @Override |
| 1259 | public void run() { |
| 1260 | mZoomChangeListener.onGestureZoomSupportChanged(supportsGestureZoom); |
| 1261 | } |
| 1262 | }); |
| 1263 | } |
| 1264 | |
| 1265 | /** |
| 1266 | * See {@link android.webkit.WebSettings#setSupportZoom}. |
| 1267 | */ |
| 1268 | public void setSupportZoom(boolean support) { |
| 1269 | synchronized (mAwSettingsLock) { |
| 1270 | if (mSupportZoom != support) { |
| 1271 | mSupportZoom = support; |
| 1272 | onGestureZoomSupportChanged(supportsGestureZoomLocked()); |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * See {@link android.webkit.WebSettings#supportZoom}. |
| 1279 | */ |
| 1280 | public boolean supportZoom() { |
| 1281 | synchronized (mAwSettingsLock) { |
| 1282 | return mSupportZoom; |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * See {@link android.webkit.WebSettings#setBuiltInZoomControls}. |
| 1288 | */ |
| 1289 | public void setBuiltInZoomControls(boolean enabled) { |
| 1290 | synchronized (mAwSettingsLock) { |
| 1291 | if (mBuiltInZoomControls != enabled) { |
| 1292 | mBuiltInZoomControls = enabled; |
| 1293 | onGestureZoomSupportChanged(supportsGestureZoomLocked()); |
| 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | /** |
| 1299 | * See {@link android.webkit.WebSettings#getBuiltInZoomControls}. |
| 1300 | */ |
| 1301 | public boolean getBuiltInZoomControls() { |
| 1302 | synchronized (mAwSettingsLock) { |
| 1303 | return mBuiltInZoomControls; |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * See {@link android.webkit.WebSettings#setDisplayZoomControls}. |
| 1309 | */ |
| 1310 | public void setDisplayZoomControls(boolean enabled) { |
| 1311 | synchronized (mAwSettingsLock) { |
| 1312 | mDisplayZoomControls = enabled; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * See {@link android.webkit.WebSettings#getDisplayZoomControls}. |
| 1318 | */ |
| 1319 | public boolean getDisplayZoomControls() { |
| 1320 | synchronized (mAwSettingsLock) { |
| 1321 | return mDisplayZoomControls; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | private boolean supportsGestureZoomLocked() { |
| 1326 | assert Thread.holdsLock(mAwSettingsLock); |
| 1327 | return mSupportZoom && mBuiltInZoomControls; |
| 1328 | } |
| 1329 | |
| 1330 | boolean supportsGestureZoom() { |
| 1331 | synchronized (mAwSettingsLock) { |
| 1332 | return supportsGestureZoomLocked(); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | boolean shouldDisplayZoomControls() { |
| 1337 | synchronized (mAwSettingsLock) { |
| 1338 | return supportsGestureZoomLocked() && mDisplayZoomControls; |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | private int clipFontSize(int size) { |
| 1343 | if (size < MINIMUM_FONT_SIZE) { |
| 1344 | return MINIMUM_FONT_SIZE; |
| 1345 | } else if (size > MAXIMUM_FONT_SIZE) { |
| 1346 | return MAXIMUM_FONT_SIZE; |
| 1347 | } |
| 1348 | return size; |
| 1349 | } |
| 1350 | |
| 1351 | @CalledByNative |
| 1352 | private void updateEverything() { |
| 1353 | synchronized (mAwSettingsLock) { |
| 1354 | nativeUpdateEverythingLocked(mNativeAwSettings); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | private void updateWebkitPreferencesOnUiThreadLocked() { |
| 1359 | if (mNativeAwSettings != 0) { |
| 1360 | ThreadUtils.assertOnUiThread(); |
| 1361 | nativeUpdateWebkitPreferencesLocked(mNativeAwSettings); |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | private native int nativeInit(int webContentsPtr); |
| 1366 | |
| 1367 | private native void nativeDestroy(int nativeAwSettings); |
| 1368 | |
| 1369 | private native void nativeResetScrollAndScaleState(int nativeAwSettings); |
| 1370 | |
| 1371 | private native void nativeUpdateEverythingLocked(int nativeAwSettings); |
| 1372 | |
| 1373 | private native void nativeUpdateInitialPageScaleLocked(int nativeAwSettings); |
| 1374 | |
| 1375 | private native void nativeUpdateUserAgentLocked(int nativeAwSettings); |
| 1376 | |
| 1377 | private native void nativeUpdateWebkitPreferencesLocked(int nativeAwSettings); |
| 1378 | |
| 1379 | private static native String nativeGetDefaultUserAgent(); |
| 1380 | |
| 1381 | private native void nativeUpdateFormDataPreferencesLocked(int nativeAwSettings); |
| 1382 | } |