+
/*
* Copyright (C) 2007 The Android Open Source Project
*
import com.google.android.providers.GoogleSettings.Partner;
+import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
-import android.os.StatFs;
import android.webkit.CookieManager;
+import android.webkit.GeolocationPermissions;
+import android.webkit.ValueCallback;
import android.webkit.WebView;
import android.webkit.WebViewDatabase;
import android.webkit.WebIconDatabase;
import android.provider.Browser;
import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
import java.util.Observable;
/*
private boolean loadsImagesAutomatically = true;
private boolean javaScriptEnabled = true;
private boolean pluginsEnabled = true;
- private String pluginsPath; // default value set in loadFromDb().
private boolean javaScriptCanOpenWindowsAutomatically = false;
private boolean showSecurityWarnings = true;
private boolean rememberPasswords = true;
private boolean loginInitialized = false;
private boolean autoFitPage = true;
private boolean landscapeOnly = false;
+ private boolean loadsPageInOverviewMode = true;
private boolean showDebugSettings = false;
- private String databasePath; // default value set in loadFromDb()
- private boolean databaseEnabled = true;
- private long webStorageDefaultQuota = 5 * 1024 * 1024;
- // The Browser always enables Application Caches.
+ // HTML5 API flags
private boolean appCacheEnabled = true;
- private String appCachePath; // default value set in loadFromDb().
- private long appCacheMaxSize = Long.MAX_VALUE;
+ private boolean databaseEnabled = true;
private boolean domStorageEnabled = true;
+ private boolean geolocationEnabled = true;
+ private boolean workersEnabled = true; // only affects V8. JSC does not have a similar setting
+ // HTML5 API configuration params
+ private long appCacheMaxSize = Long.MAX_VALUE;
+ private String appCachePath; // default value set in loadFromDb().
+ private String databasePath; // default value set in loadFromDb()
+ private String geolocationDatabasePath; // default value set in loadFromDb()
+ private WebStorageSizeManager webStorageSizeManager;
+
private String jsFlags = "";
private final static String TAG = "BrowserSettings";
// The setting can be then toggled from the settings menu.
private boolean showConsole = true;
- // Browser only settings
- private boolean doFlick = false;
-
// Private preconfigured values
private static int minimumFontSize = 8;
private static int minimumLogicalFontSize = 8;
WebSettings.TextSize.NORMAL;
private static WebSettings.ZoomDensity zoomDensity =
WebSettings.ZoomDensity.MEDIUM;
+ private static int pageCacheCapacity;
// Preference keys that are used outside this class
public final static String PREF_CLEAR_CACHE = "privacy_clear_cache";
"privacy_clear_form_data";
public final static String PREF_CLEAR_PASSWORDS =
"privacy_clear_passwords";
- public final static String PREF_DEFAULT_QUOTA =
- "webstorage_default_quota";
public final static String PREF_EXTRAS_RESET_DEFAULTS =
"reset_default_preferences";
public final static String PREF_DEBUG_SETTINGS = "debug_menu";
- public final static String PREF_GEARS_SETTINGS = "gears_settings";
public final static String PREF_WEBSITE_SETTINGS = "website_settings";
public final static String PREF_TEXT_SIZE = "text_size";
public final static String PREF_DEFAULT_ZOOM = "default_zoom";
public final static String PREF_DEFAULT_TEXT_ENCODING =
"default_text_encoding";
+ public final static String PREF_CLEAR_GEOLOCATION_ACCESS =
+ "privacy_clear_geolocation_access";
private static final String DESKTOP_USERAGENT = "Mozilla/5.0 (Macintosh; " +
"U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, " +
s.setLightTouchEnabled(b.lightTouch);
s.setSaveFormData(b.saveFormData);
s.setSavePassword(b.rememberPasswords);
+ s.setLoadWithOverviewMode(b.loadsPageInOverviewMode);
+ s.setPageCacheCapacity(pageCacheCapacity);
// WebView inside Browser doesn't want initial focus to be set.
s.setNeedInitialFocus(false);
// Browser supports multiple windows
s.setSupportMultipleWindows(true);
- // Turn off file access
- s.setAllowFileAccess(false);
- s.setDatabasePath(b.databasePath);
+ // HTML5 API flags
+ s.setAppCacheEnabled(b.appCacheEnabled);
s.setDatabaseEnabled(b.databaseEnabled);
s.setDomStorageEnabled(b.domStorageEnabled);
- s.setWebStorageDefaultQuota(b.webStorageDefaultQuota);
+ s.setWorkersEnabled(b.workersEnabled); // This only affects V8.
+ s.setGeolocationEnabled(b.geolocationEnabled);
- // Turn on Application Caches.
- s.setAppCachePath(b.appCachePath);
- s.setAppCacheEnabled(b.appCacheEnabled);
+ // HTML5 configuration parameters.
s.setAppCacheMaxSize(b.appCacheMaxSize);
+ s.setAppCachePath(b.appCachePath);
+ s.setDatabasePath(b.databasePath);
+ s.setGeolocationDatabasePath(b.geolocationDatabasePath);
// Enable/Disable the error console.
b.mTabControl.getBrowserActivity().setShouldShowErrorConsole(
public void loadFromDb(Context ctx) {
SharedPreferences p =
PreferenceManager.getDefaultSharedPreferences(ctx);
-
- // Set the default value for the plugins path to the application's
- // local directory.
- pluginsPath = ctx.getDir("plugins", 0).getPath();
// Set the default value for the Application Caches path.
appCachePath = ctx.getDir("appcache", 0).getPath();
// Determine the maximum size of the application cache.
- appCacheMaxSize = getAppCacheMaxSize();
+ webStorageSizeManager = new WebStorageSizeManager(
+ ctx,
+ new WebStorageSizeManager.StatFsDiskInfo(appCachePath),
+ new WebStorageSizeManager.WebKitAppCacheInfo(appCachePath));
+ appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
// Set the default value for the Database path.
databasePath = ctx.getDir("databases", 0).getPath();
+ // Set the default value for the Geolocation database path.
+ geolocationDatabasePath = ctx.getDir("geolocation", 0).getPath();
homeUrl = getFactoryResetHomeUrl(ctx);
+ // the cost of one cached page is ~3M (measured using nytimes.com). For
+ // low end devices, we only cache one page. For high end devices, we try
+ // to cache more pages, currently choose 5.
+ ActivityManager am = (ActivityManager) ctx
+ .getSystemService(Context.ACTIVITY_SERVICE);
+ if (am.getMemoryClass() > 16) {
+ pageCacheCapacity = 5;
+ } else {
+ pageCacheCapacity = 1;
+ }
+
// Load the defaults from the xml
// This call is TOO SLOW, need to manually keep the defaults
// in sync
javaScriptEnabled);
pluginsEnabled = p.getBoolean("enable_plugins",
pluginsEnabled);
- pluginsPath = p.getString("plugins_path", pluginsPath);
- databasePath = p.getString("database_path", databasePath);
- databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
- webStorageDefaultQuota = Long.parseLong(p.getString(PREF_DEFAULT_QUOTA,
- String.valueOf(webStorageDefaultQuota)));
- appCacheEnabled = p.getBoolean("enable_appcache",
- appCacheEnabled);
- domStorageEnabled = p.getBoolean("enable_domstorage",
- domStorageEnabled);
- appCachePath = p.getString("appcache_path", appCachePath);
javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
"block_popup_windows",
!javaScriptCanOpenWindowsAutomatically);
zoomDensity = WebSettings.ZoomDensity.valueOf(
p.getString(PREF_DEFAULT_ZOOM, zoomDensity.name()));
autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
+ loadsPageInOverviewMode = p.getBoolean("load_page",
+ loadsPageInOverviewMode);
boolean landscapeOnlyTemp =
p.getBoolean("landscape_only", landscapeOnly);
if (landscapeOnlyTemp != landscapeOnly) {
tracing = p.getBoolean("enable_tracing", tracing);
lightTouch = p.getBoolean("enable_light_touch", lightTouch);
navDump = p.getBoolean("enable_nav_dump", navDump);
- doFlick = p.getBoolean("enable_flick", doFlick);
userAgent = Integer.parseInt(p.getString("user_agent", "0"));
}
// JS flags is loaded from DB even if showDebugSettings is false,
mTabControl.getBrowserActivity().setShouldShowErrorConsole(
showDebugSettings && showConsole);
- update();
- }
+ // HTML5 API flags
+ appCacheEnabled = p.getBoolean("enable_appcache", appCacheEnabled);
+ databaseEnabled = p.getBoolean("enable_database", databaseEnabled);
+ domStorageEnabled = p.getBoolean("enable_domstorage", domStorageEnabled);
+ geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
+ workersEnabled = p.getBoolean("enable_workers", workersEnabled);
- public String getPluginsPath() {
- return pluginsPath;
+ update();
}
public String getHomePage() {
return jsFlags;
}
+ public WebStorageSizeManager getWebStorageSizeManager() {
+ return webStorageSizeManager;
+ }
+
public void setHomePage(Context context, String url) {
Editor ed = PreferenceManager.
getDefaultSharedPreferences(context).edit();
return navDump;
}
- public boolean doFlick() {
- return doFlick;
- }
-
public boolean showDebugSettings() {
return showDebugSettings;
}
db.clearHttpAuthUsernamePassword();
}
- /*package*/ void clearDatabases(Context context) {
- WebStorage.getInstance().deleteAllData();
- // Remove all listed databases from the preferences
+ private void maybeDisableWebsiteSettings(Context context) {
PreferenceActivity activity = (PreferenceActivity) context;
- PreferenceScreen screen = (PreferenceScreen)
+ final PreferenceScreen screen = (PreferenceScreen)
activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
- screen.removeAll();
screen.setEnabled(false);
+ WebStorage.getInstance().getOrigins(new ValueCallback<Map>() {
+ public void onReceiveValue(Map webStorageOrigins) {
+ if ((webStorageOrigins != null) && !webStorageOrigins.isEmpty()) {
+ screen.setEnabled(true);
+ }
+ }
+ });
+
+ GeolocationPermissions.getInstance().getOrigins(new ValueCallback<Set<String> >() {
+ public void onReceiveValue(Set<String> geolocationOrigins) {
+ if ((geolocationOrigins != null) && !geolocationOrigins.isEmpty()) {
+ screen.setEnabled(true);
+ }
+ }
+ });
+ }
+
+ /*package*/ void clearDatabases(Context context) {
+ WebStorage.getInstance().deleteAllData();
+ maybeDisableWebsiteSettings(context);
+ }
+
+ /*package*/ void clearLocationAccess(Context context) {
+ GeolocationPermissions.getInstance().clearAll();
+ maybeDisableWebsiteSettings(context);
}
/*package*/ void resetDefaultPreferences(Context ctx) {
true);
// reset homeUrl
setHomePage(ctx, getFactoryResetHomeUrl(ctx));
+ // reset appcache max size
+ appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
}
private String getFactoryResetHomeUrl(Context context) {
return url;
}
- private long getAppCacheMaxSize() {
- StatFs dataPartition = new StatFs(appCachePath);
- long freeSpace = dataPartition.getAvailableBlocks()
- * dataPartition.getBlockSize();
- long fileSystemSize = dataPartition.getBlockCount()
- * dataPartition.getBlockSize();
- return calculateAppCacheMaxSize(fileSystemSize, freeSpace);
- }
-
- /*package*/ static long calculateAppCacheMaxSize(long fileSystemSizeBytes,
- long freeSpaceBytes) {
- if (fileSystemSizeBytes <= 0
- || freeSpaceBytes <= 0
- || freeSpaceBytes > fileSystemSizeBytes) {
- return 0;
- }
-
- long fileSystemSizeRatio =
- 4 << ((int) Math.floor(Math.log10(fileSystemSizeBytes / (1024 * 1024))));
- long maxSizeBytes = (long) Math.min(Math.floor(fileSystemSizeBytes / fileSystemSizeRatio),
- Math.floor(freeSpaceBytes / 4));
- // Round maxSizeBytes up to a multiple of 512KB (except when freeSpaceBytes < 1MB).
- long maxSizeStepBytes = 512 * 1024;
- if (freeSpaceBytes < maxSizeStepBytes * 2) {
- return 0;
- }
- return (maxSizeStepBytes * ((maxSizeBytes / maxSizeStepBytes) + 1));
- }
-
// Private constructor that does nothing.
private BrowserSettings() {
}