diff options
-rw-r--r-- | res/values/strings.xml | 24 | ||||
-rw-r--r-- | res/xml/browser_preferences.xml | 19 | ||||
-rw-r--r-- | src/com/android/browser/BrowserPreferencesPage.java | 29 | ||||
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 36 | ||||
-rw-r--r-- | src/com/android/browser/BrowserYesNoPreference.java | 3 | ||||
-rw-r--r-- | src/com/android/browser/WebsiteSettingsActivity.java | 36 |
6 files changed, 109 insertions, 38 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index b108bbc..6876409 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -333,15 +333,15 @@ <!-- Confirmation dialog message --> <string name="pref_privacy_clear_passwords_dlg">All saved passwords will be cleared.</string> <!-- Settings label --> - <string name="pref_privacy_request_location">Enable location</string> + <string name="pref_privacy_enable_geolocation">Enable location</string> <!-- Settings summary --> - <string name="pref_privacy_request_location_summary">Allow sites to request access to your location</string> + <string name="pref_privacy_enable_geolocation_summary">Allow sites to request access to your location</string> <!-- Settings label --> - <string name="pref_privacy_clear_location_requests">Clear location access</string> + <string name="pref_privacy_clear_geolocation_access">Clear location access</string> <!-- Settings summary --> - <string name="pref_privacy_clear_location_requests_summary">Clear location access for all websites</string> + <string name="pref_privacy_clear_geolocation_access_summary">Clear location access for all websites</string> <!-- Confirmation dialog message --> - <string name="pref_privacy_clear_location_requests_dlg">Clear all previous location requests</string> + <string name="pref_privacy_clear_geolocation_access_dlg">Clear location access for all websites</string> <!-- Settings screen, section title --> <string name="pref_security_title">Security settings</string> <!-- Settings label --> @@ -767,6 +767,8 @@ <string name="default_button">OK</string> <!-- HTML5 dialogs --> + + <!-- Database --> <!-- Used as a toast notification after the user close the html5 webstorage permission dialog --> <string name="webstorage_notification">The quota for this site can be changed in the Local Storage section of the Browser settings</string> <!-- Used in the Browser Settings --> @@ -780,6 +782,17 @@ <!-- Strings used in the summary of origins --> <string name="webstorage_origin_summary_mb_stored">MB stored on your phone</string> + <!-- Geolocation --> + <!-- Settings page, Advanced Settings -> Website settings -> <origin> --> + <string name="geolocation_settings_page_title">Clear location access</string> + <string name="geolocation_settings_page_summary_allowed">This site can currently access your location</string> + <string name="geolocation_settings_page_summary_not_allowed">This site cannot currently access your location</string> + <!-- Settings page dialog --> + <string name="geolocation_settings_page_dialog_title">Clear location access</string> + <string name="geolocation_settings_page_dialog_message">Location access for this website will be cleared</string> + <string name="geolocation_settings_page_dialog_ok_button">Clear access</string> + <string name="geolocation_settings_page_dialog_cancel_button">Cancel</string> + <!-- Zoom-related strings --><skip /> <!-- Caption for a button that is shown when the zoom widget is showing. The button's action will switch to the zoom overview mode. --> <string name="zoom_overview_button_text">Overview</string> @@ -788,4 +801,5 @@ <string name="error_console_header_text_maximized" translatable="false">JavaScript Console</string> <string name="error_console_eval_text_hint" translatable="false">Evaluate JavaScript</string> <string name="error_console_eval_button_text" translatable="false">Evaluate</string> + </resources> diff --git a/res/xml/browser_preferences.xml b/res/xml/browser_preferences.xml index dffb550..83c492e 100644 --- a/res/xml/browser_preferences.xml +++ b/res/xml/browser_preferences.xml @@ -134,23 +134,20 @@ android:dialogTitle="@string/clear" android:dialogIcon="@android:drawable/ic_dialog_alert"/> - <!-- below preferences will be shown when html5 location is implemented --> - <!-- - <CheckBoxPreference - android:key="request_location" + android:key="enable_geolocation" android:defaultValue="true" - android:title="@string/pref_privacy_request_location" - android:summary="@string/pref_privacy_request_location_summary" /> + android:title="@string/pref_privacy_enable_geolocation" + android:summary="@string/pref_privacy_enable_geolocation_summary" /> <com.android.browser.BrowserYesNoPreference - android:key="privacy_clear_location_requests" - android:title="@string/pref_privacy_clear_location_requests" - android:summary="@string/pref_privacy_clear_location_requests_summary" - android:dialogMessage="@string/pref_privacy_clear_location_requests_dlg" + android:key="privacy_clear_geolocation_access" + android:dependency="enable_geolocation" + android:title="@string/pref_privacy_clear_geolocation_access" + android:summary="@string/pref_privacy_clear_geolocation_access_summary" + android:dialogMessage="@string/pref_privacy_clear_geolocation_access_dlg" android:dialogTitle="@string/clear" android:dialogIcon="@android:drawable/ic_dialog_alert"/> - --> </PreferenceCategory> 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(); |