BrowserSettings.java revision aaa1f375bc9d6a6a175819fac34d39202f69a166
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
19import android.app.ActivityManager;
20import android.content.ContentResolver;
21import android.content.Context;
22import android.content.SharedPreferences;
23import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
24import android.os.Build;
25import android.os.Looper;
26import android.os.Message;
27import android.preference.PreferenceManager;
28import android.provider.Browser;
29import android.webkit.CookieManager;
30import android.webkit.GeolocationPermissions;
31import android.webkit.WebIconDatabase;
32import android.webkit.WebSettings;
33import android.webkit.WebSettings.AutoFillProfile;
34import android.webkit.WebSettings.LayoutAlgorithm;
35import android.webkit.WebSettings.PluginState;
36import android.webkit.WebSettings.TextSize;
37import android.webkit.WebSettings.ZoomDensity;
38import android.webkit.WebStorage;
39import android.webkit.WebView;
40import android.webkit.WebViewDatabase;
41
42import com.android.browser.homepages.HomeProvider;
43import com.android.browser.provider.BrowserProvider;
44import com.android.browser.search.SearchEngine;
45import com.android.browser.search.SearchEngines;
46
47import java.lang.ref.WeakReference;
48import java.util.Iterator;
49import java.util.LinkedList;
50import java.util.WeakHashMap;
51
52/**
53 * Class for managing settings
54 */
55public class BrowserSettings implements OnSharedPreferenceChangeListener,
56        PreferenceKeys {
57
58    // TODO: Do something with this UserAgent stuff
59    private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (X11; " +
60        "Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) " +
61        "Chrome/11.0.696.34 Safari/534.24";
62
63    private static final String IPHONE_USERAGENT = "Mozilla/5.0 (iPhone; U; " +
64        "CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 " +
65        "(KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
66
67    private static final String IPAD_USERAGENT = "Mozilla/5.0 (iPad; U; " +
68        "CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 " +
69        "(KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10";
70
71    private static final String FROYO_USERAGENT = "Mozilla/5.0 (Linux; U; " +
72        "Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 " +
73        "(KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
74
75    private static final String HONEYCOMB_USERAGENT = "Mozilla/5.0 (Linux; U; " +
76        "Android 3.1; en-us; Xoom Build/HMJ25) AppleWebKit/534.13 " +
77        "(KHTML, like Gecko) Version/4.0 Safari/534.13";
78
79    private static final String USER_AGENTS[] = { null,
80            DESKTOP_USERAGENT,
81            IPHONE_USERAGENT,
82            IPAD_USERAGENT,
83            FROYO_USERAGENT,
84            HONEYCOMB_USERAGENT,
85    };
86
87    // The minimum min font size
88    // Aka, the lower bounds for the min font size range
89    // which is 1:5..24
90    private static final int MIN_FONT_SIZE_OFFSET = 5;
91    // The initial value in the text zoom range
92    // This is what represents 100% in the SeekBarPreference range
93    private static final int TEXT_ZOOM_START_VAL = 10;
94    // The size of a single step in the text zoom range, in percent
95    private static final int TEXT_ZOOM_STEP = 5;
96
97    private static BrowserSettings sInstance;
98
99    private Context mContext;
100    private SharedPreferences mPrefs;
101    private LinkedList<WeakReference<WebSettings>> mManagedSettings;
102    private Controller mController;
103    private WebStorageSizeManager mWebStorageSizeManager;
104    private AutofillHandler mAutofillHandler;
105    private WeakHashMap<WebSettings, String> mCustomUserAgents;
106    private static boolean sInitialized = false;
107    // Looper shared between some lightweight background operations
108    // Specifically, this is created on the thread that initializes browser settings
109    // and is then reused by CrashRecoveryHandler
110    private Looper mBackgroundLooper;
111
112    // Cached values
113    private int mPageCacheCapacity = 1;
114    private String mAppCachePath;
115
116    // Cached settings
117    private SearchEngine mSearchEngine;
118
119    private static String sFactoryResetUrl;
120
121    public static void initialize(final Context context) {
122        sInstance = new BrowserSettings(context);
123    }
124
125    public static BrowserSettings getInstance() {
126        return sInstance;
127    }
128
129    private BrowserSettings(Context context) {
130        mContext = context;
131        mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
132        mAutofillHandler = new AutofillHandler(mContext);
133        mManagedSettings = new LinkedList<WeakReference<WebSettings>>();
134        mCustomUserAgents = new WeakHashMap<WebSettings, String>();
135        mPrefs.registerOnSharedPreferenceChangeListener(this);
136        mAutofillHandler.asyncLoadFromDb();
137        new Thread(mSetupAndLoop, "BackgroundLooper").start();
138    }
139
140    public void setController(Controller controller) {
141        mController = controller;
142        syncSharedSettings();
143
144        if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
145             ((InstantSearchEngine) mSearchEngine).setController(mController);
146        }
147    }
148
149    public Looper getBackgroundLooper() {
150        requireInitialization();
151        return mBackgroundLooper;
152    }
153
154    public void startManagingSettings(WebSettings settings) {
155        synchronized (mManagedSettings) {
156            syncStaticSettings(settings);
157            syncSetting(settings);
158            mManagedSettings.add(new WeakReference<WebSettings>(settings));
159        }
160    }
161
162    private Runnable mSetupAndLoop = new Runnable() {
163
164        @Override
165        public void run() {
166            // the cost of one cached page is ~3M (measured using nytimes.com). For
167            // low end devices, we only cache one page. For high end devices, we try
168            // to cache more pages, currently choose 5.
169            if (ActivityManager.staticGetMemoryClass() > 16) {
170                mPageCacheCapacity = 5;
171            }
172            mWebStorageSizeManager = new WebStorageSizeManager(mContext,
173                    new WebStorageSizeManager.StatFsDiskInfo(getAppCachePath()),
174                    new WebStorageSizeManager.WebKitAppCacheInfo(getAppCachePath()));
175            if (Build.VERSION.CODENAME.equals("REL")) {
176                // This is a release build, always startup with debug disabled
177                setDebugEnabled(false);
178            }
179            if (mPrefs.contains(PREF_TEXT_SIZE)) {
180                /*
181                 * Update from TextSize enum to zoom percent
182                 * SMALLEST is 50%
183                 * SMALLER is 75%
184                 * NORMAL is 100%
185                 * LARGER is 150%
186                 * LARGEST is 200%
187                 */
188                switch (getTextSize()) {
189                case SMALLEST:
190                    setTextZoom(50);
191                    break;
192                case SMALLER:
193                    setTextZoom(75);
194                    break;
195                case LARGER:
196                    setTextZoom(150);
197                    break;
198                case LARGEST:
199                    setTextZoom(200);
200                    break;
201                }
202                mPrefs.edit().remove(PREF_TEXT_SIZE).apply();
203            }
204
205            sFactoryResetUrl = mContext.getResources().getString(R.string.homepage_base);
206            if (sFactoryResetUrl.indexOf("{CID}") != -1) {
207                sFactoryResetUrl = sFactoryResetUrl.replace("{CID}",
208                    BrowserProvider.getClientId(mContext.getContentResolver()));
209            }
210
211            Looper.prepare();
212            mBackgroundLooper = Looper.myLooper();
213            synchronized (BrowserSettings.class) {
214                sInitialized = true;
215                BrowserSettings.class.notifyAll();
216            }
217            Looper.loop();
218        }
219    };
220
221    private static void requireInitialization() {
222        synchronized (BrowserSettings.class) {
223            while (!sInitialized) {
224                try {
225                    BrowserSettings.class.wait();
226                } catch (InterruptedException e) {
227                }
228            }
229        }
230    }
231
232    /**
233     * Syncs all the settings that have a Preference UI
234     */
235    private void syncSetting(WebSettings settings) {
236        settings.setGeolocationEnabled(enableGeolocation());
237        settings.setJavaScriptEnabled(enableJavascript());
238        settings.setLightTouchEnabled(enableLightTouch());
239        settings.setNavDump(enableNavDump());
240        settings.setShowVisualIndicator(enableVisualIndicator());
241        settings.setDefaultTextEncodingName(getDefaultTextEncoding());
242        settings.setDefaultZoom(getDefaultZoom());
243        settings.setMinimumFontSize(getMinimumFontSize());
244        settings.setMinimumLogicalFontSize(getMinimumFontSize());
245        settings.setForceUserScalable(forceEnableUserScalable());
246        settings.setPluginState(getPluginState());
247        settings.setTextZoom(getTextZoom());
248        settings.setAutoFillEnabled(isAutofillEnabled());
249        settings.setLayoutAlgorithm(getLayoutAlgorithm());
250        settings.setJavaScriptCanOpenWindowsAutomatically(blockPopupWindows());
251        settings.setLoadsImagesAutomatically(loadImages());
252        settings.setLoadWithOverviewMode(loadPageInOverviewMode());
253        settings.setSavePassword(rememberPasswords());
254        settings.setSaveFormData(saveFormdata());
255        settings.setUseWideViewPort(isWideViewport());
256        settings.setAutoFillProfile(getAutoFillProfile());
257
258        String ua = mCustomUserAgents.get(settings);
259        if (ua != null) {
260            settings.setUserAgentString(ua);
261        } else {
262            settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
263        }
264
265        settings.setProperty("gfxInvertedScreen",
266                useInvertedRendering() ? "true" : "false");
267    }
268
269    /**
270     * Syncs all the settings that have no UI
271     * These cannot change, so we only need to set them once per WebSettings
272     */
273    private void syncStaticSettings(WebSettings settings) {
274        settings.setDefaultFontSize(16);
275        settings.setDefaultFixedFontSize(13);
276        settings.setPageCacheCapacity(getPageCacheCapacity());
277
278        // WebView inside Browser doesn't want initial focus to be set.
279        settings.setNeedInitialFocus(false);
280        // Browser supports multiple windows
281        settings.setSupportMultipleWindows(true);
282        // enable smooth transition for better performance during panning or
283        // zooming
284        settings.setEnableSmoothTransition(true);
285        // disable content url access
286        settings.setAllowContentAccess(false);
287
288        // HTML5 API flags
289        settings.setAppCacheEnabled(true);
290        settings.setDatabaseEnabled(true);
291        settings.setDomStorageEnabled(true);
292        settings.setWorkersEnabled(true);  // This only affects V8.
293
294        // HTML5 configuration parametersettings.
295        settings.setAppCacheMaxSize(getWebStorageSizeManager().getAppCacheMaxSize());
296        settings.setAppCachePath(getAppCachePath());
297        settings.setDatabasePath(mContext.getDir("databases", 0).getPath());
298        settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath());
299    }
300
301    private void syncSharedSettings() {
302        CookieManager.getInstance().setAcceptCookie(acceptCookies());
303        if (mController != null) {
304            mController.setShouldShowErrorConsole(enableJavascriptConsole());
305        }
306    }
307
308    private void syncManagedSettings() {
309        syncSharedSettings();
310        synchronized (mManagedSettings) {
311            Iterator<WeakReference<WebSettings>> iter = mManagedSettings.iterator();
312            while (iter.hasNext()) {
313                WeakReference<WebSettings> ref = iter.next();
314                WebSettings settings = ref.get();
315                if (settings == null) {
316                    iter.remove();
317                    continue;
318                }
319                syncSetting(settings);
320            }
321        }
322    }
323
324    @Override
325    public void onSharedPreferenceChanged(
326            SharedPreferences sharedPreferences, String key) {
327        syncManagedSettings();
328        if (PREF_SEARCH_ENGINE.equals(key)) {
329            updateSearchEngine(false);
330        }
331        if (PREF_USE_INSTANT_SEARCH.equals(key)) {
332            updateSearchEngine(true);
333        }
334        if (PREF_FULLSCREEN.equals(key)) {
335            if (mController.getUi() != null) {
336                mController.getUi().setFullscreen(useFullscreen());
337            }
338        } else if (PREF_ENABLE_QUICK_CONTROLS.equals(key)) {
339            if (mController.getUi() != null) {
340                mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
341            }
342        }
343    }
344
345    public static String getFactoryResetHomeUrl(Context context) {
346        requireInitialization();
347        return sFactoryResetUrl;
348    }
349
350    public LayoutAlgorithm getLayoutAlgorithm() {
351        LayoutAlgorithm layoutAlgorithm = LayoutAlgorithm.NORMAL;
352        if (autofitPages()) {
353            layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
354        }
355        if (isDebugEnabled()) {
356            if (isSmallScreen()) {
357                layoutAlgorithm = LayoutAlgorithm.SINGLE_COLUMN;
358            } else {
359                if (isNormalLayout()) {
360                    layoutAlgorithm = LayoutAlgorithm.NORMAL;
361                } else {
362                    layoutAlgorithm = LayoutAlgorithm.NARROW_COLUMNS;
363                }
364            }
365        }
366        return layoutAlgorithm;
367    }
368
369    public int getPageCacheCapacity() {
370        requireInitialization();
371        return mPageCacheCapacity;
372    }
373
374    public WebStorageSizeManager getWebStorageSizeManager() {
375        requireInitialization();
376        return mWebStorageSizeManager;
377    }
378
379    private String getAppCachePath() {
380        if (mAppCachePath == null) {
381            mAppCachePath = mContext.getDir("appcache", 0).getPath();
382        }
383        return mAppCachePath;
384    }
385
386    private void updateSearchEngine(boolean force) {
387        String searchEngineName = getSearchEngineName();
388        if (force || mSearchEngine == null ||
389                !mSearchEngine.getName().equals(searchEngineName)) {
390            if (mSearchEngine != null) {
391                if (mSearchEngine.supportsVoiceSearch()) {
392                     // One or more tabs could have been in voice search mode.
393                     // Clear it, since the new SearchEngine may not support
394                     // it, or may handle it differently.
395                     for (int i = 0; i < mController.getTabControl().getTabCount(); i++) {
396                         mController.getTabControl().getTab(i).revertVoiceSearchMode();
397                     }
398                 }
399                mSearchEngine.close();
400             }
401            mSearchEngine = SearchEngines.get(mContext, searchEngineName);
402
403             if (mController != null && (mSearchEngine instanceof InstantSearchEngine)) {
404                 ((InstantSearchEngine) mSearchEngine).setController(mController);
405             }
406         }
407    }
408
409    public SearchEngine getSearchEngine() {
410        if (mSearchEngine == null) {
411            updateSearchEngine(false);
412        }
413        return mSearchEngine;
414    }
415
416    public boolean isDebugEnabled() {
417        requireInitialization();
418        return mPrefs.getBoolean(PREF_DEBUG_MENU, false);
419    }
420
421    public void setDebugEnabled(boolean value) {
422        mPrefs.edit().putBoolean(PREF_DEBUG_MENU, value).apply();
423    }
424
425    public void clearCache() {
426        WebIconDatabase.getInstance().removeAllIcons();
427        if (mController != null) {
428            WebView current = mController.getCurrentWebView();
429            if (current != null) {
430                current.clearCache(true);
431            }
432        }
433    }
434
435    public void clearCookies() {
436        CookieManager.getInstance().removeAllCookie();
437    }
438
439    public void clearHistory() {
440        ContentResolver resolver = mContext.getContentResolver();
441        Browser.clearHistory(resolver);
442        Browser.clearSearches(resolver);
443    }
444
445    public void clearFormData() {
446        WebViewDatabase.getInstance(mContext).clearFormData();
447        if (mController!= null) {
448            WebView currentTopView = mController.getCurrentTopWebView();
449            if (currentTopView != null) {
450                currentTopView.clearFormData();
451            }
452        }
453    }
454
455    public void clearPasswords() {
456        WebViewDatabase db = WebViewDatabase.getInstance(mContext);
457        db.clearUsernamePassword();
458        db.clearHttpAuthUsernamePassword();
459    }
460
461    public void clearDatabases() {
462        WebStorage.getInstance().deleteAllData();
463    }
464
465    public void clearLocationAccess() {
466        GeolocationPermissions.getInstance().clearAll();
467    }
468
469    public void resetDefaultPreferences() {
470        mPrefs.edit().clear().apply();
471        syncManagedSettings();
472    }
473
474    public AutoFillProfile getAutoFillProfile() {
475        mAutofillHandler.waitForLoad();
476        return mAutofillHandler.getAutoFillProfile();
477    }
478
479    public void setAutoFillProfile(AutoFillProfile profile, Message msg) {
480        mAutofillHandler.waitForLoad();
481        mAutofillHandler.setAutoFillProfile(profile, msg);
482        // Auto-fill will reuse the same profile ID when making edits to the profile,
483        // so we need to force a settings sync (otherwise the SharedPreferences
484        // manager will optimise out the call to onSharedPreferenceChanged(), as
485        // it thinks nothing has changed).
486        syncManagedSettings();
487    }
488
489    public void toggleDebugSettings() {
490        setDebugEnabled(!isDebugEnabled());
491    }
492
493    public boolean hasDesktopUseragent(WebView view) {
494        return view != null && mCustomUserAgents.get(view.getSettings()) != null;
495    }
496
497    public void toggleDesktopUseragent(WebView view) {
498        if (view == null) {
499            return;
500        }
501        WebSettings settings = view.getSettings();
502        if (mCustomUserAgents.get(settings) != null) {
503            mCustomUserAgents.remove(settings);
504            settings.setUserAgentString(USER_AGENTS[getUserAgent()]);
505        } else {
506            mCustomUserAgents.put(settings, DESKTOP_USERAGENT);
507            settings.setUserAgentString(DESKTOP_USERAGENT);
508        }
509    }
510
511    public static int getAdjustedMinimumFontSize(int rawValue) {
512        rawValue++; // Preference starts at 0, min font at 1
513        if (rawValue > 1) {
514            rawValue += (MIN_FONT_SIZE_OFFSET - 2);
515        }
516        return rawValue;
517    }
518
519    public static int getAdjustedTextZoom(int rawValue) {
520        rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP;
521        return rawValue + 100;
522    }
523
524    static int getRawTextZoom(int percent) {
525        return (percent - 100) / TEXT_ZOOM_STEP + TEXT_ZOOM_START_VAL;
526    }
527
528    // -----------------------------
529    // getter/setters for accessibility_preferences.xml
530    // -----------------------------
531
532    @Deprecated
533    private TextSize getTextSize() {
534        String textSize = mPrefs.getString(PREF_TEXT_SIZE, "NORMAL");
535        return TextSize.valueOf(textSize);
536    }
537
538    public int getMinimumFontSize() {
539        int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0);
540        return getAdjustedMinimumFontSize(minFont);
541    }
542
543    public boolean forceEnableUserScalable() {
544        return mPrefs.getBoolean(PREF_FORCE_USERSCALABLE, false);
545    }
546
547    public int getTextZoom() {
548        requireInitialization();
549        int textZoom = mPrefs.getInt(PREF_TEXT_ZOOM, 10);
550        return getAdjustedTextZoom(textZoom);
551    }
552
553    public void setTextZoom(int percent) {
554        mPrefs.edit().putInt(PREF_TEXT_ZOOM, getRawTextZoom(percent)).apply();
555    }
556
557    // -----------------------------
558    // getter/setters for advanced_preferences.xml
559    // -----------------------------
560
561    public String getSearchEngineName() {
562        return mPrefs.getString(PREF_SEARCH_ENGINE, SearchEngine.GOOGLE);
563    }
564
565    public boolean openInBackground() {
566        return mPrefs.getBoolean(PREF_OPEN_IN_BACKGROUND, false);
567    }
568
569    public boolean enableJavascript() {
570        return mPrefs.getBoolean(PREF_ENABLE_JAVASCRIPT, true);
571    }
572
573    // TODO: Cache
574    public PluginState getPluginState() {
575        String state = mPrefs.getString(PREF_PLUGIN_STATE, "ON");
576        return PluginState.valueOf(state);
577    }
578
579    // TODO: Cache
580    public ZoomDensity getDefaultZoom() {
581        String zoom = mPrefs.getString(PREF_DEFAULT_ZOOM, "MEDIUM");
582        return ZoomDensity.valueOf(zoom);
583    }
584
585    public boolean loadPageInOverviewMode() {
586        return mPrefs.getBoolean(PREF_LOAD_PAGE, true);
587    }
588
589    public boolean autofitPages() {
590        return mPrefs.getBoolean(PREF_AUTOFIT_PAGES, true);
591    }
592
593    public boolean blockPopupWindows() {
594        return mPrefs.getBoolean(PREF_BLOCK_POPUP_WINDOWS, true);
595    }
596
597    public boolean loadImages() {
598        return mPrefs.getBoolean(PREF_LOAD_IMAGES, true);
599    }
600
601    public String getDefaultTextEncoding() {
602        return mPrefs.getString(PREF_DEFAULT_TEXT_ENCODING, null);
603    }
604
605    // -----------------------------
606    // getter/setters for general_preferences.xml
607    // -----------------------------
608
609    public String getHomePage() {
610        return mPrefs.getString(PREF_HOMEPAGE, getFactoryResetHomeUrl(mContext));
611    }
612
613    public void setHomePage(String value) {
614        mPrefs.edit().putString(PREF_HOMEPAGE, value).apply();
615    }
616
617    public boolean isAutofillEnabled() {
618        return mPrefs.getBoolean(PREF_AUTOFILL_ENABLED, true);
619    }
620
621    public void setAutofillEnabled(boolean value) {
622        mPrefs.edit().putBoolean(PREF_AUTOFILL_ENABLED, value).apply();
623    }
624
625    // -----------------------------
626    // getter/setters for debug_preferences.xml
627    // -----------------------------
628
629    public boolean isHardwareAccelerated() {
630        if (!isDebugEnabled()) {
631            return true;
632        }
633        return mPrefs.getBoolean(PREF_ENABLE_HARDWARE_ACCEL, true);
634    }
635
636    public int getUserAgent() {
637        if (!isDebugEnabled()) {
638            return 0;
639        }
640        return Integer.parseInt(mPrefs.getString(PREF_USER_AGENT, "0"));
641    }
642
643    // -----------------------------
644    // getter/setters for hidden_debug_preferences.xml
645    // -----------------------------
646
647    public boolean enableVisualIndicator() {
648        if (!isDebugEnabled()) {
649            return false;
650        }
651        return mPrefs.getBoolean(PREF_ENABLE_VISUAL_INDICATOR, false);
652    }
653
654    public boolean enableJavascriptConsole() {
655        if (!isDebugEnabled()) {
656            return false;
657        }
658        return mPrefs.getBoolean(PREF_JAVASCRIPT_CONSOLE, true);
659    }
660
661    public boolean isSmallScreen() {
662        if (!isDebugEnabled()) {
663            return false;
664        }
665        return mPrefs.getBoolean(PREF_SMALL_SCREEN, false);
666    }
667
668    public boolean isWideViewport() {
669        if (!isDebugEnabled()) {
670            return true;
671        }
672        return mPrefs.getBoolean(PREF_WIDE_VIEWPORT, true);
673    }
674
675    public boolean isNormalLayout() {
676        if (!isDebugEnabled()) {
677            return false;
678        }
679        return mPrefs.getBoolean(PREF_NORMAL_LAYOUT, false);
680    }
681
682    public boolean isTracing() {
683        if (!isDebugEnabled()) {
684            return false;
685        }
686        return mPrefs.getBoolean(PREF_ENABLE_TRACING, false);
687    }
688
689    public boolean enableLightTouch() {
690        if (!isDebugEnabled()) {
691            return false;
692        }
693        return mPrefs.getBoolean(PREF_ENABLE_LIGHT_TOUCH, false);
694    }
695
696    public boolean enableNavDump() {
697        if (!isDebugEnabled()) {
698            return false;
699        }
700        return mPrefs.getBoolean(PREF_ENABLE_NAV_DUMP, false);
701    }
702
703    public String getJsEngineFlags() {
704        if (!isDebugEnabled()) {
705            return "";
706        }
707        return mPrefs.getString(PREF_JS_ENGINE_FLAGS, "");
708    }
709
710    // -----------------------------
711    // getter/setters for lab_preferences.xml
712    // -----------------------------
713
714    public boolean useQuickControls() {
715        return mPrefs.getBoolean(PREF_ENABLE_QUICK_CONTROLS, false);
716    }
717
718    public boolean useMostVisitedHomepage() {
719        return HomeProvider.MOST_VISITED.equals(getHomePage());
720    }
721
722    public boolean useInstantSearch() {
723        return mPrefs.getBoolean(PREF_USE_INSTANT_SEARCH, false);
724    }
725
726    public boolean useFullscreen() {
727        return mPrefs.getBoolean(PREF_FULLSCREEN, false);
728    }
729
730    public boolean useInvertedRendering() {
731        return mPrefs.getBoolean(PREF_INVERTED, false);
732    }
733
734    // -----------------------------
735    // getter/setters for privacy_security_preferences.xml
736    // -----------------------------
737
738    public boolean showSecurityWarnings() {
739        return mPrefs.getBoolean(PREF_SHOW_SECURITY_WARNINGS, true);
740    }
741
742    public boolean acceptCookies() {
743        return mPrefs.getBoolean(PREF_ACCEPT_COOKIES, true);
744    }
745
746    public boolean saveFormdata() {
747        return mPrefs.getBoolean(PREF_SAVE_FORMDATA, true);
748    }
749
750    public boolean enableGeolocation() {
751        return mPrefs.getBoolean(PREF_ENABLE_GEOLOCATION, true);
752    }
753
754    public boolean rememberPasswords() {
755        return mPrefs.getBoolean(PREF_REMEMBER_PASSWORDS, true);
756    }
757
758    // -----------------------------
759    // getter/setters for bandwidth_preferences.xml
760    // -----------------------------
761
762    public boolean isPreloadEnabled() {
763        return mPrefs.getBoolean(PREF_DATA_PRELOAD, false);
764    }
765}
766