Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java |
| index d336d844287be3e034ac059142069e5c25009808..29793c26d71d5627c631df7b700c4861c5ae30f1 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java |
| @@ -6,6 +6,7 @@ package org.chromium.chrome.browser.preferences; |
| import android.content.Context; |
| import android.content.SharedPreferences; |
| +import android.net.Uri; |
| import android.preference.PreferenceManager; |
| import android.text.TextUtils; |
| import android.util.Log; |
| @@ -13,6 +14,7 @@ import android.util.Log; |
| import org.chromium.base.CalledByNative; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.chrome.browser.ContentSettingsType; |
| +import org.chromium.chrome.browser.UrlUtilities; |
| import org.chromium.chrome.browser.preferences.website.ContentSetting; |
| import org.chromium.chrome.browser.preferences.website.ContentSettingException; |
| import org.chromium.chrome.browser.preferences.website.GeolocationInfo; |
| @@ -21,6 +23,7 @@ import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| import java.util.ArrayList; |
| import java.util.List; |
| +import java.util.Locale; |
| /** |
| * PrefServiceBridge is a singleton which provides access to some native preferences. Ideally |
| @@ -44,6 +47,8 @@ public final class PrefServiceBridge { |
| private static String sProfilePath; |
| + private static final String HTTPS_SCHEME = "https"; |
| + |
| // Object to notify when "clear browsing data" completes. |
| private OnClearBrowsingDataListener mClearBrowsingDataListener; |
| private static final String LOG_TAG = "PrefServiceBridge"; |
| @@ -178,6 +183,52 @@ public final class PrefServiceBridge { |
| } |
| /** |
| + * Wheter to send a geo header for the current URL. |
|
newt (away)
2015/04/28 06:44:01
"Whether the geo header is allowed to be sent for
Finnur
2015/04/29 14:54:09
Done.
|
| + * @param context The Context used to get the device location. |
| + * @param url The URL of the request with which this header will be sent. |
| + * @param isIncognito Whether the request will happen in an incognito tab. |
| + */ |
| + public static boolean sendGeoHeader(Context context, String url, boolean isIncognito) { |
|
newt (away)
2015/04/28 06:44:01
sendGeoHeader() is a wildly misleading method name
Finnur
2015/04/29 14:54:09
Done.
|
| + // Only send the Geo header in normal mode. |
| + if (isIncognito) return false; |
| + |
| + // Only send the Geo header to Google domains. |
| + if (!UrlUtilities.nativeIsGoogleSearchUrl(url)) return false; |
| + |
| + Uri uri = Uri.parse(url); |
| + if (!HTTPS_SCHEME.equals(uri.getScheme())) return false; |
| + |
| + // Only send Geo header if the user hasn't disabled geolocation for url. |
| + if (isLocationDisabledForUrl(uri)) return false; |
| + |
| + return true; |
| + } |
| + |
| + /** |
| + * Returns true if the user has disabled sharing their location with url (e.g. via the |
| + * geolocation infobar). If the user has not chosen a preference for url and url uses the https |
| + * scheme, this considers the user's preference for url with the http scheme instead. |
| + */ |
| + public static boolean isLocationDisabledForUrl(Uri uri) { |
|
newt (away)
2015/04/28 06:44:01
Add a TODO to delete these methods after Geolocati
Finnur
2015/04/29 14:54:09
Done.
|
| + GeolocationInfo locationSettings = new GeolocationInfo(uri.toString(), null); |
| + ContentSetting locationPermission = locationSettings.getContentSetting(); |
| + |
| + // If no preference has been chosen and the scheme is https, fall back to the preference for |
| + // this same host over http with no explicit port number. |
| + if (locationPermission == null || locationPermission == ContentSetting.ASK) { |
| + String scheme = uri.getScheme(); |
| + if (scheme != null && scheme.toLowerCase(Locale.US).equals("https") |
| + && uri.getAuthority() != null && uri.getUserInfo() == null) { |
| + String urlWithHttp = "http://" + uri.getHost(); |
| + locationSettings = new GeolocationInfo(urlWithHttp, null); |
| + locationPermission = locationSettings.getContentSetting(); |
| + } |
| + } |
| + |
| + return locationPermission == ContentSetting.BLOCK; |
| + } |
| + |
| + /** |
| * Returns the path to the user's profile directory via a callback. The callback may be |
| * called synchronously or asynchronously. |
| */ |