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