1 package org.robolectric.fakes; 2 3 import android.webkit.WebSettings; 4 5 /** 6 * Robolectric implementation of {@link android.webkit.WebSettings}. 7 */ 8 public class RoboWebSettings extends WebSettings { 9 private boolean blockNetworkImage = false; 10 private boolean javaScriptEnabled = false; 11 private boolean javaScriptCanOpenWindowAutomatically = false; 12 private boolean lightTouchEnabled = false; 13 private boolean needInitialFocus = false; 14 private RenderPriority renderPriority = RenderPriority.NORMAL; 15 private boolean pluginsEnabled = false; 16 private boolean saveFormData = false; 17 private boolean supportMultipleWindows = false; 18 private boolean supportZoom = true; 19 private boolean useWideViewPort = false; 20 private int cacheMode; 21 private WebSettings.LayoutAlgorithm layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS; 22 private String defaultTextEncoding = "UTF-8"; 23 private int defaultFontSize = 16; 24 private boolean loadsImagesAutomatically; 25 private int defaultFixedFontSize; 26 private int minimumLogicalFontSize; 27 private int minimumFontSize; 28 private String fantasyFontFamily; 29 private String cursiveFontFamily; 30 private String serifFontFamily; 31 private String sansSerifFontFamily; 32 private String fixedFontFamily; 33 private String standardFontFamily; 34 private boolean savePassword; 35 private int userAgent; 36 private boolean navDump; 37 38 @Override 39 public synchronized boolean getBlockNetworkImage() { 40 return blockNetworkImage; 41 } 42 43 @Override 44 public synchronized void setBlockNetworkImage(boolean flag) { 45 blockNetworkImage = flag; 46 } 47 48 @Override 49 public synchronized boolean getJavaScriptEnabled() { 50 return javaScriptEnabled; 51 } 52 53 @Override 54 public synchronized void setJavaScriptEnabled(boolean flag) { 55 javaScriptEnabled = flag; 56 } 57 58 @Override 59 public boolean getLightTouchEnabled() { 60 return lightTouchEnabled; 61 } 62 63 @Override 64 public void setLightTouchEnabled(boolean flag) { 65 lightTouchEnabled = flag; 66 } 67 68 public boolean getNeedInitialFocus() { 69 return needInitialFocus; 70 } 71 72 @Override 73 public void setNeedInitialFocus(boolean flag) { 74 needInitialFocus = flag; 75 } 76 77 @Override 78 public synchronized void setRenderPriority(RenderPriority priority) { 79 renderPriority = priority; 80 } 81 82 public RenderPriority getRenderPriority() { 83 return renderPriority; 84 } 85 86 @Override 87 public synchronized boolean getPluginsEnabled() { 88 return pluginsEnabled; 89 } 90 91 @Override 92 public synchronized void setPluginsEnabled(boolean flag) { 93 pluginsEnabled = flag; 94 } 95 96 public boolean getSupportMultipleWindows() { 97 return supportMultipleWindows; 98 } 99 100 @Override 101 public synchronized void setSupportMultipleWindows(boolean support) { 102 supportMultipleWindows = support; 103 } 104 105 public boolean getSupportZoom() { 106 return supportZoom; 107 } 108 109 @Override 110 public void setSupportZoom(boolean support) { 111 supportZoom = support; 112 } 113 114 @Override 115 public void setCacheMode(int mode) { 116 this.cacheMode = mode; 117 } 118 119 @Override 120 public int getCacheMode() { 121 return cacheMode; 122 } 123 124 @Override 125 public boolean getUseWideViewPort() { 126 return useWideViewPort; 127 } 128 129 @Override 130 public void setUseWideViewPort(boolean useWideViewPort) { 131 this.useWideViewPort = useWideViewPort; 132 } 133 134 @Override 135 public boolean getSaveFormData() { 136 return saveFormData; 137 } 138 139 @Override 140 public void setSaveFormData(boolean saveFormData) { 141 this.saveFormData = saveFormData; 142 } 143 144 @Override 145 public void setJavaScriptCanOpenWindowsAutomatically(boolean javaScriptCanOpenWindowAutomatically) { 146 this.javaScriptCanOpenWindowAutomatically = javaScriptCanOpenWindowAutomatically; 147 } 148 149 @Override 150 public boolean getJavaScriptCanOpenWindowsAutomatically() { 151 return this.javaScriptCanOpenWindowAutomatically; 152 } 153 154 @Override 155 public synchronized void setLayoutAlgorithm(WebSettings.LayoutAlgorithm algorithm) { 156 this.layoutAlgorithm = algorithm; 157 } 158 159 @Override 160 public String getDefaultTextEncodingName() { 161 return this.defaultTextEncoding; 162 } 163 164 @Override 165 public void setDefaultTextEncodingName(String defaultTextEncoding) { 166 this.defaultTextEncoding = defaultTextEncoding; 167 } 168 169 @Override 170 public int getDefaultFontSize() { 171 return defaultFontSize; 172 } 173 174 @Override 175 public void setDefaultFontSize(int defaultFontSize) { 176 this.defaultFontSize = defaultFontSize; 177 } 178 179 @Override 180 public boolean getLoadsImagesAutomatically() { 181 return loadsImagesAutomatically; 182 } 183 184 @Override public void setLoadsImagesAutomatically(boolean loadsImagesAutomatically) { 185 this.loadsImagesAutomatically = loadsImagesAutomatically; 186 } 187 188 @Override 189 public int getDefaultFixedFontSize() { 190 return defaultFixedFontSize; 191 } 192 193 @Override public void setDefaultFixedFontSize(int defaultFixedFontSize) { 194 this.defaultFixedFontSize = defaultFixedFontSize; 195 } 196 197 @Override 198 public int getMinimumLogicalFontSize() { 199 return minimumLogicalFontSize; 200 } 201 202 @Override public void setMinimumLogicalFontSize(int minimumLogicalFontSize) { 203 this.minimumLogicalFontSize = minimumLogicalFontSize; 204 } 205 206 @Override 207 public int getMinimumFontSize() { 208 return minimumFontSize; 209 } 210 211 @Override public void setMinimumFontSize(int minimumFontSize) { 212 this.minimumFontSize = minimumFontSize; 213 } 214 215 @Override 216 public String getFantasyFontFamily() { 217 return fantasyFontFamily; 218 } 219 220 @Override public void setFantasyFontFamily(String fantasyFontFamily) { 221 this.fantasyFontFamily = fantasyFontFamily; 222 } 223 224 @Override 225 public String getCursiveFontFamily() { 226 return cursiveFontFamily; 227 } 228 229 @Override public void setCursiveFontFamily(String cursiveFontFamily) { 230 this.cursiveFontFamily = cursiveFontFamily; 231 } 232 233 @Override 234 public String getSerifFontFamily() { 235 return serifFontFamily; 236 } 237 238 @Override public void setSerifFontFamily(String serifFontFamily) { 239 this.serifFontFamily = serifFontFamily; 240 } 241 242 @Override 243 public String getSansSerifFontFamily() { 244 return sansSerifFontFamily; 245 } 246 247 @Override public void setSansSerifFontFamily(String sansSerifFontFamily) { 248 this.sansSerifFontFamily = sansSerifFontFamily; 249 } 250 251 @Override 252 public String getFixedFontFamily() { 253 return fixedFontFamily; 254 } 255 256 @Override public void setFixedFontFamily(String fixedFontFamily) { 257 this.fixedFontFamily = fixedFontFamily; 258 } 259 260 @Override 261 public String getStandardFontFamily() { 262 return standardFontFamily; 263 } 264 265 @Override public void setStandardFontFamily(String standardFontFamily) { 266 this.standardFontFamily = standardFontFamily; 267 } 268 269 @Override 270 public LayoutAlgorithm getLayoutAlgorithm() { 271 return layoutAlgorithm; 272 } 273 274 @Override 275 public boolean supportMultipleWindows() { 276 return supportMultipleWindows; 277 } 278 279 @Override 280 public boolean getSavePassword() { 281 return savePassword; 282 } 283 284 @Override 285 public void setSavePassword(boolean savePassword) { 286 this.savePassword = savePassword; 287 } 288 289 @Override 290 public boolean supportZoom() { 291 return supportZoom; 292 } 293 294 @Override 295 public int getUserAgent() { 296 return userAgent; 297 } 298 299 @Override 300 public void setUserAgent(int userAgent) { 301 this.userAgent = userAgent; 302 } 303 304 @Override 305 public boolean getNavDump() { 306 return navDump; 307 } 308 309 @Override 310 public void setNavDump(boolean navDump) { 311 this.navDump = navDump; 312 } 313 314 private boolean allowFileAccess = true; 315 private boolean builtInZoomControls = true; 316 private String userAgentString = "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"; 317 318 @Override 319 public boolean getAllowFileAccess() { 320 return allowFileAccess; 321 } 322 323 @Override 324 public void setAllowFileAccess(boolean allow) { 325 allowFileAccess = allow; 326 } 327 328 @Override 329 public boolean getBuiltInZoomControls() { 330 return builtInZoomControls; 331 } 332 333 @Override 334 public void setBuiltInZoomControls(boolean enabled) { 335 builtInZoomControls = enabled; 336 } 337 338 @Override 339 public synchronized void setUserAgentString(String ua) { 340 userAgentString = ua; 341 } 342 343 @Override 344 public synchronized String getUserAgentString() { 345 return userAgentString; 346 } 347 // End API 3 348 349 private boolean databaseEnabled = false; 350 private String databasePath = "database"; 351 private String geolocationDatabasePath = "geolocation"; 352 private boolean geolocationEnabled = false; 353 354 @Override 355 public synchronized boolean getDatabaseEnabled() { 356 return databaseEnabled; 357 } 358 359 @Override 360 public synchronized void setDatabaseEnabled(boolean flag) { 361 databaseEnabled = flag; 362 } 363 364 @Override 365 public synchronized void setDatabasePath(String path) { 366 databasePath = path; 367 } 368 369 @Override 370 public synchronized String getDatabasePath() { 371 return databasePath; 372 } 373 374 public String getGeolocationDatabasePath() { 375 return geolocationDatabasePath; 376 } 377 378 @Override 379 public void setGeolocationDatabasePath(String geolocationDatabasePath) { 380 this.geolocationDatabasePath = geolocationDatabasePath; 381 } 382 383 public boolean getGeolocationEnabled() { 384 return geolocationEnabled; 385 } 386 387 @Override 388 public void setGeolocationEnabled(boolean geolocationEnabled) { 389 this.geolocationEnabled = geolocationEnabled; 390 } 391 // End API 5 392 393 private ZoomDensity defaultZoom; 394 private boolean domStorageEnabled = false; 395 private boolean loadWithOverviewMode = false; 396 private boolean appCacheEnabled = false; 397 private long appCacheMaxSize; 398 private String appCachePath = "appcache"; 399 400 @Override 401 public void setDefaultZoom(ZoomDensity zoom) { 402 this.defaultZoom = zoom; 403 } 404 405 @Override 406 public ZoomDensity getDefaultZoom() { 407 return defaultZoom; 408 } 409 410 @Override 411 public synchronized boolean getDomStorageEnabled() { 412 return domStorageEnabled; 413 } 414 415 @Override 416 public synchronized void setDomStorageEnabled(boolean flag) { 417 domStorageEnabled = flag; 418 } 419 420 @Override 421 public boolean getLoadWithOverviewMode() { 422 return loadWithOverviewMode; 423 } 424 425 @Override 426 public void setLoadWithOverviewMode(boolean flag) { 427 loadWithOverviewMode = flag; 428 } 429 430 public boolean getAppCacheEnabled() { 431 return appCacheEnabled; 432 } 433 434 @Override 435 public void setAppCacheEnabled(boolean appCacheEnabled) { 436 this.appCacheEnabled = appCacheEnabled; 437 } 438 439 @Override 440 public void setAppCacheMaxSize(long appCacheMaxSize) { 441 this.appCacheMaxSize = appCacheMaxSize; 442 } 443 444 public long getAppCacheMaxSize() { 445 return appCacheMaxSize; 446 } 447 448 public String getAppCachePath() { 449 return appCachePath; 450 } 451 452 @Override 453 public void setAppCachePath(String appCachePath) { 454 this.appCachePath = appCachePath; 455 } 456 // End API 7 457 458 private boolean blockNetworkLoads = false; 459 private WebSettings.PluginState pluginState = WebSettings.PluginState.OFF; 460 461 @Override 462 public synchronized boolean getBlockNetworkLoads() { 463 return blockNetworkLoads; 464 } 465 466 @Override 467 public synchronized void setBlockNetworkLoads(boolean flag) { 468 blockNetworkLoads = flag; 469 } 470 471 @Override 472 public synchronized WebSettings.PluginState getPluginState() { 473 return pluginState; 474 } 475 476 @Override 477 public synchronized void setPluginState(WebSettings.PluginState state) { 478 pluginState = state; 479 } 480 // End API 8 481 482 private boolean useWebViewBackgroundForOverscrollBackground; 483 484 @Override 485 public boolean getUseWebViewBackgroundForOverscrollBackground() { 486 return useWebViewBackgroundForOverscrollBackground; 487 } 488 489 @Override 490 public void setUseWebViewBackgroundForOverscrollBackground(boolean useWebViewBackgroundForOverscrollBackground) { 491 this.useWebViewBackgroundForOverscrollBackground = useWebViewBackgroundForOverscrollBackground; 492 } 493 // End API 9 494 495 private boolean enableSmoothTransition; 496 private boolean allowContentAccess = true; 497 private boolean displayZoomControls; 498 499 @Override 500 public boolean enableSmoothTransition() { 501 return enableSmoothTransition; 502 } 503 504 @Override 505 public void setEnableSmoothTransition(boolean enableSmoothTransition) { 506 this.enableSmoothTransition = enableSmoothTransition; 507 } 508 509 @Override 510 public void setAllowContentAccess(boolean allow) { 511 allowContentAccess = allow; 512 } 513 514 @Override 515 public boolean getAllowContentAccess() { 516 return allowContentAccess; 517 } 518 519 @Override 520 public void setDisplayZoomControls(boolean enabled) { 521 displayZoomControls = enabled; 522 } 523 524 @Override 525 public boolean getDisplayZoomControls() { 526 return displayZoomControls; 527 } 528 // End API 11 529 530 private int textZoom = 100; 531 532 @Override 533 public int getTextZoom() { 534 return textZoom; 535 } 536 537 @Override 538 public void setTextZoom(int textZoom) { 539 this.textZoom = textZoom; 540 } 541 // End API 14 542 543 private boolean allowFileAccessFromFile = true; 544 private boolean allowUniversalAccessFromFile = true; 545 546 @Override 547 public boolean getAllowFileAccessFromFileURLs() { 548 return allowFileAccessFromFile; 549 } 550 551 @Override 552 public void setAllowFileAccessFromFileURLs(boolean allow) { 553 allowFileAccessFromFile = allow; 554 } 555 556 @Override 557 public boolean getAllowUniversalAccessFromFileURLs() { 558 return allowUniversalAccessFromFile; 559 } 560 561 @Override 562 public void setAllowUniversalAccessFromFileURLs(boolean allow) { 563 allowUniversalAccessFromFile = allow; 564 } 565 //End API 16 566 567 private boolean mediaPlaybackRequiresUserGesture = true; 568 569 @Override 570 public boolean getMediaPlaybackRequiresUserGesture() { 571 return mediaPlaybackRequiresUserGesture; 572 } 573 574 @Override 575 public void setMediaPlaybackRequiresUserGesture(boolean require) { 576 mediaPlaybackRequiresUserGesture = require; 577 } 578 //End API 17 579 580 private int mixedContentMode; 581 private boolean acceptThirdPartyCookies; 582 private boolean videoOverlayForEmbeddedEncryptedVideoEnabled; 583 584 @Override 585 public void setMixedContentMode(int mixedContentMode) { 586 this.mixedContentMode = mixedContentMode; 587 } 588 589 @Override 590 public int getMixedContentMode() { 591 return mixedContentMode; 592 } 593 594 @Override 595 public void setVideoOverlayForEmbeddedEncryptedVideoEnabled(boolean b) { 596 videoOverlayForEmbeddedEncryptedVideoEnabled = b; 597 } 598 599 @Override 600 public boolean getVideoOverlayForEmbeddedEncryptedVideoEnabled() { 601 return videoOverlayForEmbeddedEncryptedVideoEnabled; 602 } 603 604 @Override 605 public boolean getAcceptThirdPartyCookies() { 606 return acceptThirdPartyCookies; 607 } 608 609 @Override 610 public void setAcceptThirdPartyCookies(boolean acceptThirdPartyCookies) { 611 this.acceptThirdPartyCookies = acceptThirdPartyCookies; 612 } 613 // End API 21 614 615 @Override 616 public void setOffscreenPreRaster(boolean enabled) { 617 618 } 619 620 @Override public boolean getOffscreenPreRaster() { 621 return false; 622 } 623 624 // End API 23 625 626 @Override 627 public int getDisabledActionModeMenuItems() { 628 return 0; 629 } 630 631 @Override 632 public void setDisabledActionModeMenuItems(int menuItems) { 633 634 } 635 636 // End API 24. 637 638 @Override public boolean getSafeBrowsingEnabled() { 639 return false; 640 } 641 642 @Override public void setSafeBrowsingEnabled(boolean enabled) { 643 644 } 645 646 // End API 26 647 } 648