summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2009-07-30 10:50:45 +0100
committerSteve Block <steveblock@google.com>2009-07-30 11:46:08 +0100
commitf344d03c0b01d30575ba1ddd1ed340705c6f5a97 (patch)
tree1d5cd67145e899b91d144a592b20a6c76720d36b /src/com/android
parent734d07bb3ce3b65b51289143ca51013df01c1bd6 (diff)
downloadpackages_apps_Browser-f344d03c0b01d30575ba1ddd1ed340705c6f5a97.zip
packages_apps_Browser-f344d03c0b01d30575ba1ddd1ed340705c6f5a97.tar.gz
packages_apps_Browser-f344d03c0b01d30575ba1ddd1ed340705c6f5a97.tar.bz2
Adds browser settings menu entries for Geolocation permissions.
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/browser/BrowserPreferencesPage.java29
-rw-r--r--src/com/android/browser/BrowserSettings.java36
-rw-r--r--src/com/android/browser/BrowserYesNoPreference.java3
-rw-r--r--src/com/android/browser/WebsiteSettingsActivity.java36
4 files changed, 82 insertions, 22 deletions
diff --git a/src/com/android/browser/BrowserPreferencesPage.java b/src/com/android/browser/BrowserPreferencesPage.java
index 4536b2c..2348af0 100644
--- a/src/com/android/browser/BrowserPreferencesPage.java
+++ b/src/com/android/browser/BrowserPreferencesPage.java
@@ -29,10 +29,10 @@ import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.util.Log;
+import android.webkit.GeolocationPermissions;
import android.webkit.Plugin;
import android.webkit.WebStorage;
import android.webkit.WebView;
-import android.webkit.Plugin;
public class BrowserPreferencesPage extends PreferenceActivity
implements Preference.OnPreferenceChangeListener,
@@ -69,35 +69,36 @@ public class BrowserPreferencesPage extends PreferenceActivity
e = findPreference(BrowserSettings.PREF_DEFAULT_TEXT_ENCODING);
e.setOnPreferenceChangeListener(this);
-
+
if (BrowserSettings.getInstance().showDebugSettings()) {
addPreferencesFromResource(R.xml.debug_preferences);
}
-
+
e = findPreference(BrowserSettings.PREF_GEARS_SETTINGS);
e.setOnPreferenceClickListener(this);
- PreferenceScreen manageDatabases = (PreferenceScreen)
+ PreferenceScreen websiteSettings = (PreferenceScreen)
findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
Intent intent = new Intent(this, WebsiteSettingsActivity.class);
- manageDatabases.setIntent(intent);
+ websiteSettings.setIntent(intent);
}
/*
- * We need to set the manageDatabases PreferenceScreen state
- * in the onResume(), as the number of origins with databases
- * could have changed after calling the WebsiteSettingsActivity.
+ * We need to set the PreferenceScreen state in onResume(), as the number of
+ * origins with active features (WebStorage, Geolocation etc) could have
+ * changed after calling the WebsiteSettingsActivity.
*/
@Override
protected void onResume() {
super.onResume();
- PreferenceScreen manageDatabases = (PreferenceScreen)
+ PreferenceScreen websiteSettings = (PreferenceScreen)
findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
- manageDatabases.setEnabled(false);
- Set origins = WebStorage.getInstance().getOrigins();
- if ((origins != null) && (origins.size() > 0)) {
- manageDatabases.setEnabled(true);
- }
+ Set webStorageOrigins = WebStorage.getInstance().getOrigins();
+ Set geolocationOrigins =
+ GeolocationPermissions.getInstance().getOrigins();
+ websiteSettings.setEnabled(
+ ((webStorageOrigins != null) && !webStorageOrigins.isEmpty()) ||
+ ((geolocationOrigins != null) && !geolocationOrigins.isEmpty()));
}
@Override
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 79deb61..3ed6cf0 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -26,6 +26,7 @@ import android.content.SharedPreferences.Editor;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.webkit.CookieManager;
+import android.webkit.GeolocationPermissions;
import android.webkit.WebView;
import android.webkit.WebViewDatabase;
import android.webkit.WebIconDatabase;
@@ -34,6 +35,7 @@ import android.webkit.WebStorage;
import android.preference.PreferenceManager;
import android.provider.Browser;
+import java.util.Set;
import java.util.HashMap;
import java.util.Observable;
@@ -81,6 +83,7 @@ class BrowserSettings extends Observable {
private WebStorageSizeManager webStorageSizeManager;
private boolean domStorageEnabled = true;
private String jsFlags = "";
+ private boolean geolocationEnabled = true;
private final static String TAG = "BrowserSettings";
@@ -130,6 +133,8 @@ class BrowserSettings extends Observable {
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_LOCATION_ACCESS =
+ "privacy_clear_location_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, " +
@@ -216,6 +221,10 @@ class BrowserSettings extends Observable {
// Enable/Disable the error console.
b.mTabControl.getBrowserActivity().setShouldShowErrorConsole(
b.showDebugSettings && b.showConsole);
+
+ // Configure the Geolocation permissions manager to deny all
+ // permission requests if Geolocation is disabled in the browser.
+ // TODO(steveblock): Implement
}
}
@@ -352,6 +361,8 @@ class BrowserSettings extends Observable {
mTabControl.getBrowserActivity().setShouldShowErrorConsole(
showDebugSettings && showConsole);
+ geolocationEnabled = p.getBoolean("enable_geolocation", geolocationEnabled);
+
update();
}
@@ -522,14 +533,27 @@ class BrowserSettings extends Observable {
db.clearHttpAuthUsernamePassword();
}
+ private void maybeDisableWebsiteSettings(Context context) {
+ Set webStorageOrigins = WebStorage.getInstance().getOrigins();
+ Set geolocationOrigins =
+ GeolocationPermissions.getInstance().getOrigins();
+ if (((webStorageOrigins == null) || webStorageOrigins.isEmpty()) &&
+ ((geolocationOrigins == null) || geolocationOrigins.isEmpty())) {
+ PreferenceActivity activity = (PreferenceActivity) context;
+ PreferenceScreen screen = (PreferenceScreen)
+ activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
+ screen.setEnabled(false);
+ }
+ }
+
/*package*/ void clearDatabases(Context context) {
WebStorage.getInstance().deleteAllData();
- // Remove all listed databases from the preferences
- PreferenceActivity activity = (PreferenceActivity) context;
- PreferenceScreen screen = (PreferenceScreen)
- activity.findPreference(BrowserSettings.PREF_WEBSITE_SETTINGS);
- screen.removeAll();
- screen.setEnabled(false);
+ maybeDisableWebsiteSettings(context);
+ }
+
+ /*package*/ void clearLocationAccess(Context context) {
+ GeolocationPermissions.getInstance().clearAll();
+ maybeDisableWebsiteSettings(context);
}
/*package*/ void resetDefaultPreferences(Context ctx) {
diff --git a/src/com/android/browser/BrowserYesNoPreference.java b/src/com/android/browser/BrowserYesNoPreference.java
index ae93882..e380e57 100644
--- a/src/com/android/browser/BrowserYesNoPreference.java
+++ b/src/com/android/browser/BrowserYesNoPreference.java
@@ -51,6 +51,9 @@ class BrowserYesNoPreference extends YesNoPreference {
getKey())) {
BrowserSettings.getInstance().resetDefaultPreferences(context);
setEnabled(true);
+ } else if (BrowserSettings.PREF_CLEAR_LOCATION_ACCESS.equals(
+ getKey())) {
+ BrowserSettings.getInstance().clearLocationAccess(context);
}
}
}
diff --git a/src/com/android/browser/WebsiteSettingsActivity.java b/src/com/android/browser/WebsiteSettingsActivity.java
index fc21967..89e5963 100644
--- a/src/com/android/browser/WebsiteSettingsActivity.java
+++ b/src/com/android/browser/WebsiteSettingsActivity.java
@@ -31,6 +31,7 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.webkit.GeolocationPermissions;
import android.webkit.WebIconDatabase;
import android.webkit.WebStorage;
import android.widget.ArrayAdapter;
@@ -68,8 +69,9 @@ public class WebsiteSettingsActivity extends ListActivity {
// variable with value equal to the current value of FEATURE_COUNT, then
// increment FEATURE_COUNT.
private final static int FEATURE_WEB_STORAGE = 0;
+ private final static int FEATURE_GEOLOCATION = 1;
// The number of features available.
- private final static int FEATURE_COUNT = 1;
+ private final static int FEATURE_COUNT = 2;
public Site(String origin) {
mOrigin = origin;
@@ -102,7 +104,7 @@ public class WebsiteSettingsActivity extends ListActivity {
* The return value is a feature ID - one of the FEATURE_XXX values.
* This is required to determine which feature is displayed at a given
* position in the list of features for this site. This is used both
- * when populateing the view and when responding to clicks on the list.
+ * when populating the view and when responding to clicks on the list.
*/
public int getFeatureByIndex(int n) {
int j = -1;
@@ -195,6 +197,13 @@ public class WebsiteSettingsActivity extends ListActivity {
addFeatureToSite(sites, iter.next(), Site.FEATURE_WEB_STORAGE);
}
}
+ origins = GeolocationPermissions.getInstance().getOrigins();
+ if (origins != null) {
+ Iterator<String> iter = origins.iterator();
+ while (iter.hasNext()) {
+ addFeatureToSite(sites, iter.next(), Site.FEATURE_GEOLOCATION);
+ }
+ }
// Create a map from host to origin. This is used to add metadata
// (title, icon) for this origin from the bookmarks DB.
@@ -335,6 +344,13 @@ public class WebsiteSettingsActivity extends ListActivity {
title.setText(R.string.webstorage_clear_data_title);
subtitle.setText(usage);
break;
+ case Site.FEATURE_GEOLOCATION:
+ title.setText(R.string.geolocation_settings_page_title);
+ boolean allowed = GeolocationPermissions.getInstance().getAllowed(origin);
+ subtitle.setText(allowed ?
+ R.string.geolocation_settings_page_summary_allowed :
+ R.string.geolocation_settings_page_summary_not_allowed);
+ break;
}
}
@@ -363,6 +379,22 @@ public class WebsiteSettingsActivity extends ListActivity {
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
break;
+ case Site.FEATURE_GEOLOCATION:
+ new AlertDialog.Builder(getContext())
+ .setTitle(R.string.geolocation_settings_page_dialog_title)
+ .setMessage(R.string.geolocation_settings_page_dialog_message)
+ .setPositiveButton(R.string.geolocation_settings_page_dialog_ok_button,
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dlg, int which) {
+ GeolocationPermissions.getInstance().clear(mCurrentSite.getOrigin());
+ mCurrentSite = null;
+ populateOrigins();
+ notifyDataSetChanged();
+ }})
+ .setNegativeButton(R.string.geolocation_settings_page_dialog_cancel_button, null)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .show();
+ break;
}
} else {
mCurrentSite = (Site) view.getTag();